adds preference to receive proposal notifications
This commit is contained in:
@@ -25,7 +25,7 @@ class AccountController < ApplicationController
|
||||
if @account.organization?
|
||||
params.require(:account).permit(:phone_number, :email_on_comment, :email_on_comment_reply, :newsletter, organization_attributes: [:name, :responsible_name])
|
||||
else
|
||||
params.require(:account).permit(:username, :public_activity, :email_on_comment, :email_on_comment_reply, :newsletter)
|
||||
params.require(:account).permit(:username, :public_activity, :email_on_comment, :email_on_comment_reply, :email_on_proposal_notification, :newsletter)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -11,8 +11,10 @@ class ProposalNotificationsController < ApplicationController
|
||||
@proposal = Proposal.find(notification_params[:proposal_id])
|
||||
if @notification.save
|
||||
@proposal.voters.each do |voter|
|
||||
if voter.email_on_proposal_notification?
|
||||
Mailer.proposal_notification(@notification, voter).deliver_later
|
||||
end
|
||||
end
|
||||
redirect_to @notification, notice: I18n.t("flash.actions.create.proposal_notification")
|
||||
else
|
||||
render :new
|
||||
|
||||
@@ -34,7 +34,9 @@
|
||||
<div>
|
||||
<%= f.label :public_activity do %>
|
||||
<%= f.check_box :public_activity, title: t('account.show.public_activity_label'), label: false %>
|
||||
<span class="checkbox"><%= t("account.show.public_activity_label") %></span>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.public_activity_label") %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -43,21 +45,36 @@
|
||||
<div>
|
||||
<%= f.label :email_on_comment do %>
|
||||
<%= f.check_box :email_on_comment, title: t('account.show.email_on_comment_label'), label: false %>
|
||||
<span class="checkbox"><%= t("account.show.email_on_comment_label") %></span>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.email_on_comment_label") %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= f.label :email_on_comment_reply do %>
|
||||
<%= f.check_box :email_on_comment_reply, title: t('account.show.email_on_comment_reply_label'), label: false %>
|
||||
<span class="checkbox"><%= t("account.show.email_on_comment_reply_label") %></span>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.email_on_comment_reply_label") %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= f.label :email_newsletter_subscribed do %>
|
||||
<%= f.check_box :newsletter, title: t('account.show.subscription_to_website_newsletter_label'), label: false %>
|
||||
<span class="checkbox"><%= t("account.show.subscription_to_website_newsletter_label") %></span>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.subscription_to_website_newsletter_label") %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= f.label :email_on_proposal_notification do %>
|
||||
<%= f.check_box :email_on_proposal_notification, title: t('account.show.email_on_proposal_notification_label'), label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.email_on_proposal_notification_label") %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ en:
|
||||
public_activity_label: Keep my list of activities public
|
||||
save_changes_submit: Save changes
|
||||
subscription_to_website_newsletter_label: Receive by email website relevant information
|
||||
email_on_proposal_notification_label: Receive by email notifications about proposals
|
||||
title: My account
|
||||
user_permission_debates: Participate on debates
|
||||
user_permission_info: With your account you can...
|
||||
|
||||
@@ -15,6 +15,7 @@ es:
|
||||
public_activity_label: Mostrar públicamente mi lista de actividades
|
||||
save_changes_submit: Guardar cambios
|
||||
subscription_to_website_newsletter_label: Recibir emails con información interesante sobre la web
|
||||
email_on_proposal_notification_label: Recibir emails con notificaciones sobre propuestas
|
||||
title: Mi cuenta
|
||||
user_permission_debates: Participar en debates
|
||||
user_permission_info: Con tu cuenta ya puedes...
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddEmailOnProposalNotificationToUsers < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :users, :email_on_proposal_notification, :boolean, default: true
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160601103338) do
|
||||
ActiveRecord::Schema.define(version: 20160606102427) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -450,6 +450,7 @@ ActiveRecord::Schema.define(version: 20160601103338) do
|
||||
t.string "redeemable_code"
|
||||
t.string "gender", limit: 10
|
||||
t.datetime "date_of_birth"
|
||||
t.boolean "email_on_proposal_notification", default: true
|
||||
end
|
||||
|
||||
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree
|
||||
|
||||
@@ -35,6 +35,7 @@ feature 'Account' do
|
||||
fill_in 'account_username', with: 'Larry Bird'
|
||||
check 'account_email_on_comment'
|
||||
check 'account_email_on_comment_reply'
|
||||
uncheck 'account_email_on_proposal_notification'
|
||||
click_button 'Save changes'
|
||||
|
||||
expect(page).to have_content "Changes saved"
|
||||
@@ -42,8 +43,9 @@ feature 'Account' do
|
||||
visit account_path
|
||||
|
||||
expect(page).to have_selector("input[value='Larry Bird']")
|
||||
expect(page).to have_selector("input[id='account_email_on_comment'][value='1']")
|
||||
expect(page).to have_selector("input[id='account_email_on_comment_reply'][value='1']")
|
||||
expect(find("#account_email_on_comment")).to be_checked
|
||||
expect(find("#account_email_on_comment_reply")).to be_checked
|
||||
expect(find("#account_email_on_proposal_notification")).to_not be_checked
|
||||
end
|
||||
|
||||
scenario 'Edit Organization' do
|
||||
@@ -53,6 +55,7 @@ feature 'Account' do
|
||||
fill_in 'account_organization_attributes_name', with: 'Google'
|
||||
check 'account_email_on_comment'
|
||||
check 'account_email_on_comment_reply'
|
||||
|
||||
click_button 'Save changes'
|
||||
|
||||
expect(page).to have_content "Changes saved"
|
||||
@@ -60,8 +63,8 @@ feature 'Account' do
|
||||
visit account_path
|
||||
|
||||
expect(page).to have_selector("input[value='Google']")
|
||||
expect(page).to have_selector("input[id='account_email_on_comment'][value='1']")
|
||||
expect(page).to have_selector("input[id='account_email_on_comment_reply'][value='1']")
|
||||
expect(find("#account_email_on_comment")).to be_checked
|
||||
expect(find("#account_email_on_comment_reply")).to be_checked
|
||||
end
|
||||
|
||||
scenario "Errors on edit" do
|
||||
|
||||
@@ -148,6 +148,8 @@ feature 'Emails' do
|
||||
expect(email).to have_body_text(spending_proposal.feasible_explanation)
|
||||
end
|
||||
|
||||
context "Proposal notifications" do
|
||||
|
||||
scenario "Proposal notification" do
|
||||
author = create(:user)
|
||||
|
||||
@@ -169,7 +171,7 @@ feature 'Emails' do
|
||||
|
||||
fill_in 'proposal_notification_title', with: "Thank you for supporting my proposal"
|
||||
fill_in 'proposal_notification_body', with: "Please share it with others so we can make it happen!"
|
||||
click_button "Send"
|
||||
click_button "Send message"
|
||||
|
||||
expect(page).to have_content "Your message has been sent correctly."
|
||||
|
||||
@@ -184,4 +186,22 @@ feature 'Emails' do
|
||||
expect(email).to have_body_text(proposal.title)
|
||||
end
|
||||
|
||||
scenario "Do not send email about proposal notifications unless set in preferences", :js do
|
||||
author = create(:user)
|
||||
voter = create(:user, email_on_proposal_notification: false)
|
||||
|
||||
proposal = create(:proposal)
|
||||
create(:vote, voter: voter, votable: proposal, vote_flag: true)
|
||||
|
||||
login_as(author)
|
||||
visit new_proposal_notification_path(proposal_id: proposal.id)
|
||||
|
||||
fill_in 'proposal_notification_title', with: "Thank you for supporting my proposal"
|
||||
fill_in 'proposal_notification_body', with: "Please share it with others so we can make it happen!"
|
||||
click_button "Send message"
|
||||
|
||||
expect { open_last_email }.to raise_error "No email has been sent!"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -83,6 +83,12 @@ describe User do
|
||||
expect(subject.newsletter).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'email_on_proposal_notification' do
|
||||
it 'should be true by default' do
|
||||
expect(subject.email_on_proposal_notification).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "administrator?" do
|
||||
|
||||
Reference in New Issue
Block a user