adds preference to receive proposal notifications

This commit is contained in:
rgarcia
2016-06-06 12:55:33 +02:00
parent fc6cc090f8
commit ad697cd2c1
10 changed files with 107 additions and 51 deletions

View File

@@ -25,7 +25,7 @@ class AccountController < ApplicationController
if @account.organization? if @account.organization?
params.require(:account).permit(:phone_number, :email_on_comment, :email_on_comment_reply, :newsletter, organization_attributes: [:name, :responsible_name]) params.require(:account).permit(:phone_number, :email_on_comment, :email_on_comment_reply, :newsletter, organization_attributes: [:name, :responsible_name])
else 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
end end

View File

@@ -11,8 +11,10 @@ class ProposalNotificationsController < ApplicationController
@proposal = Proposal.find(notification_params[:proposal_id]) @proposal = Proposal.find(notification_params[:proposal_id])
if @notification.save if @notification.save
@proposal.voters.each do |voter| @proposal.voters.each do |voter|
if voter.email_on_proposal_notification?
Mailer.proposal_notification(@notification, voter).deliver_later Mailer.proposal_notification(@notification, voter).deliver_later
end end
end
redirect_to @notification, notice: I18n.t("flash.actions.create.proposal_notification") redirect_to @notification, notice: I18n.t("flash.actions.create.proposal_notification")
else else
render :new render :new

View File

@@ -34,7 +34,9 @@
<div> <div>
<%= f.label :public_activity do %> <%= f.label :public_activity do %>
<%= f.check_box :public_activity, title: t('account.show.public_activity_label'), label: false %> <%= 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 %> <% end %>
</div> </div>
@@ -43,21 +45,36 @@
<div> <div>
<%= f.label :email_on_comment do %> <%= f.label :email_on_comment do %>
<%= f.check_box :email_on_comment, title: t('account.show.email_on_comment_label'), label: false %> <%= 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 %> <% end %>
</div> </div>
<div> <div>
<%= f.label :email_on_comment_reply do %> <%= 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 %> <%= 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 %> <% end %>
</div> </div>
<div> <div>
<%= f.label :email_newsletter_subscribed do %> <%= f.label :email_newsletter_subscribed do %>
<%= f.check_box :newsletter, title: t('account.show.subscription_to_website_newsletter_label'), label: false %> <%= 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 %> <% end %>
</div> </div>

View File

@@ -15,6 +15,7 @@ en:
public_activity_label: Keep my list of activities public public_activity_label: Keep my list of activities public
save_changes_submit: Save changes save_changes_submit: Save changes
subscription_to_website_newsletter_label: Receive by email website relevant information 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 title: My account
user_permission_debates: Participate on debates user_permission_debates: Participate on debates
user_permission_info: With your account you can... user_permission_info: With your account you can...

View File

@@ -15,6 +15,7 @@ es:
public_activity_label: Mostrar públicamente mi lista de actividades public_activity_label: Mostrar públicamente mi lista de actividades
save_changes_submit: Guardar cambios save_changes_submit: Guardar cambios
subscription_to_website_newsletter_label: Recibir emails con información interesante sobre la web 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 title: Mi cuenta
user_permission_debates: Participar en debates user_permission_debates: Participar en debates
user_permission_info: Con tu cuenta ya puedes... user_permission_info: Con tu cuenta ya puedes...

View File

@@ -0,0 +1,5 @@
class AddEmailOnProposalNotificationToUsers < ActiveRecord::Migration
def change
add_column :users, :email_on_proposal_notification, :boolean, default: true
end
end

View File

@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@@ -450,6 +450,7 @@ ActiveRecord::Schema.define(version: 20160601103338) do
t.string "redeemable_code" t.string "redeemable_code"
t.string "gender", limit: 10 t.string "gender", limit: 10
t.datetime "date_of_birth" t.datetime "date_of_birth"
t.boolean "email_on_proposal_notification", default: true
end end
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree

View File

@@ -35,6 +35,7 @@ feature 'Account' do
fill_in 'account_username', with: 'Larry Bird' fill_in 'account_username', with: 'Larry Bird'
check 'account_email_on_comment' check 'account_email_on_comment'
check 'account_email_on_comment_reply' check 'account_email_on_comment_reply'
uncheck 'account_email_on_proposal_notification'
click_button 'Save changes' click_button 'Save changes'
expect(page).to have_content "Changes saved" expect(page).to have_content "Changes saved"
@@ -42,8 +43,9 @@ feature 'Account' do
visit account_path visit account_path
expect(page).to have_selector("input[value='Larry Bird']") expect(page).to have_selector("input[value='Larry Bird']")
expect(page).to have_selector("input[id='account_email_on_comment'][value='1']") expect(find("#account_email_on_comment")).to be_checked
expect(page).to have_selector("input[id='account_email_on_comment_reply'][value='1']") expect(find("#account_email_on_comment_reply")).to be_checked
expect(find("#account_email_on_proposal_notification")).to_not be_checked
end end
scenario 'Edit Organization' do scenario 'Edit Organization' do
@@ -53,6 +55,7 @@ feature 'Account' do
fill_in 'account_organization_attributes_name', with: 'Google' fill_in 'account_organization_attributes_name', with: 'Google'
check 'account_email_on_comment' check 'account_email_on_comment'
check 'account_email_on_comment_reply' check 'account_email_on_comment_reply'
click_button 'Save changes' click_button 'Save changes'
expect(page).to have_content "Changes saved" expect(page).to have_content "Changes saved"
@@ -60,8 +63,8 @@ feature 'Account' do
visit account_path visit account_path
expect(page).to have_selector("input[value='Google']") expect(page).to have_selector("input[value='Google']")
expect(page).to have_selector("input[id='account_email_on_comment'][value='1']") expect(find("#account_email_on_comment")).to be_checked
expect(page).to have_selector("input[id='account_email_on_comment_reply'][value='1']") expect(find("#account_email_on_comment_reply")).to be_checked
end end
scenario "Errors on edit" do scenario "Errors on edit" do

View File

@@ -148,6 +148,8 @@ feature 'Emails' do
expect(email).to have_body_text(spending_proposal.feasible_explanation) expect(email).to have_body_text(spending_proposal.feasible_explanation)
end end
context "Proposal notifications" do
scenario "Proposal notification" do scenario "Proposal notification" do
author = create(:user) 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_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!" 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." 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) expect(email).to have_body_text(proposal.title)
end 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 end

View File

@@ -83,6 +83,12 @@ describe User do
expect(subject.newsletter).to eq(true) expect(subject.newsletter).to eq(true)
end end
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 end
describe "administrator?" do describe "administrator?" do