refactors account's email config
This commit is contained in:
@@ -23,9 +23,9 @@ class AccountController < ApplicationController
|
||||
|
||||
def account_params
|
||||
if @account.organization?
|
||||
params.require(:account).permit(:phone_number, :email_on_debate_comment, :email_on_comment_reply, organization_attributes: [:name, :responsible_name])
|
||||
params.require(:account).permit(:phone_number, :email_on_comment, :email_on_comment_reply, organization_attributes: [:name, :responsible_name])
|
||||
else
|
||||
params.require(:account).permit(:username, :email_on_debate_comment, :email_on_comment_reply)
|
||||
params.require(:account).permit(:username, :email_on_comment, :email_on_comment_reply)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -12,16 +12,16 @@ class CommentNotifier
|
||||
private
|
||||
|
||||
def send_comment_email
|
||||
Mailer.comment(@comment).deliver_later if email_on_debate_comment?
|
||||
Mailer.comment(@comment).deliver_later if email_on_comment?
|
||||
end
|
||||
|
||||
def send_reply_email
|
||||
Mailer.reply(@comment).deliver_later if email_on_comment_reply?
|
||||
end
|
||||
|
||||
def email_on_debate_comment?
|
||||
def email_on_comment?
|
||||
commentable_author = @comment.commentable.author
|
||||
commentable_author != @author && commentable_author.email_on_debate_comment?
|
||||
commentable_author != @author && commentable_author.email_on_comment?
|
||||
end
|
||||
|
||||
def email_on_comment_reply?
|
||||
|
||||
@@ -45,9 +45,9 @@
|
||||
<h2><%= t("account.show.notifications")%></h2>
|
||||
|
||||
<div>
|
||||
<%= f.label :email_on_debate_comment do %>
|
||||
<%= f.check_box :email_on_debate_comment, label: false %>
|
||||
<span class="checkbox"><%= t("account.show.email_on_debate_comment_label") %></span>
|
||||
<%= f.label :email_on_comment do %>
|
||||
<%= f.check_box :email_on_comment, label: false %>
|
||||
<span class="checkbox"><%= t("account.show.email_on_comment_label") %></span>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -254,8 +254,7 @@ en:
|
||||
show:
|
||||
title: "My account"
|
||||
save_changes_submit: "Save changes"
|
||||
email_on_debate_comment_label: "Receive email when someone comments on my debates"
|
||||
email_on_proposal_comment_label: "Receive email when someone comments on my proposals"
|
||||
email_on_comment_label: "Receive email when someone comments on my debates or proposals"
|
||||
email_on_comment_reply_label: "Receive email when someone replies to my comments"
|
||||
change_credentials_link: "Change my credentials"
|
||||
avatar: "Avatar"
|
||||
|
||||
@@ -255,8 +255,7 @@ es:
|
||||
title: "Mi cuenta"
|
||||
save_changes_submit: "Guardar cambios"
|
||||
change_credentials_link: "Cambiar mis datos de acceso"
|
||||
email_on_debate_comment_label: "Recibir un email cuando alguien comenta en mis debates"
|
||||
email_on_proposal_comment_label: "Recibir un email cuando alguien comenta en mis propuestas"
|
||||
email_on_comment_label: "Recibir un email cuando alguien comenta en mis propuestas o debates"
|
||||
email_on_comment_reply_label: "Recibir un email cuando alguien contesta a mis comentarios"
|
||||
avatar: "Avatar"
|
||||
personal: "Datos personales"
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class ChangeEmailConfigFieldInUser < ActiveRecord::Migration
|
||||
def change
|
||||
rename_column :users, :email_on_debate_comment, :email_on_comment
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20150912145218) do
|
||||
ActiveRecord::Schema.define(version: 20150914114019) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -258,7 +258,7 @@ ActiveRecord::Schema.define(version: 20150912145218) do
|
||||
t.datetime "confirmed_at"
|
||||
t.datetime "confirmation_sent_at"
|
||||
t.string "unconfirmed_email"
|
||||
t.boolean "email_on_debate_comment", default: false
|
||||
t.boolean "email_on_comment", default: false
|
||||
t.boolean "email_on_comment_reply", default: false
|
||||
t.string "phone_number", limit: 30
|
||||
t.string "official_position"
|
||||
|
||||
@@ -33,7 +33,7 @@ feature 'Account' do
|
||||
visit account_path
|
||||
|
||||
fill_in 'account_username', with: 'Larry Bird'
|
||||
check 'account_email_on_debate_comment'
|
||||
check 'account_email_on_comment'
|
||||
check 'account_email_on_comment_reply'
|
||||
click_button 'Save changes'
|
||||
|
||||
@@ -42,7 +42,7 @@ 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_debate_comment'][value='1']")
|
||||
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']")
|
||||
end
|
||||
|
||||
@@ -51,7 +51,7 @@ feature 'Account' do
|
||||
visit account_path
|
||||
|
||||
fill_in 'account_organization_attributes_name', with: 'Google'
|
||||
check 'account_email_on_debate_comment'
|
||||
check 'account_email_on_comment'
|
||||
check 'account_email_on_comment_reply'
|
||||
click_button 'Save changes'
|
||||
|
||||
@@ -60,7 +60,7 @@ feature 'Account' do
|
||||
visit account_path
|
||||
|
||||
expect(page).to have_selector("input[value='Google']")
|
||||
expect(page).to have_selector("input[id='account_email_on_debate_comment'][value='1']")
|
||||
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']")
|
||||
end
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ feature 'Emails' do
|
||||
|
||||
context 'Debate comments' do
|
||||
scenario "Send email on debate comment", :js do
|
||||
user = create(:user, email_on_debate_comment: true)
|
||||
user = create(:user, email_on_comment: true)
|
||||
debate = create(:debate, author: user)
|
||||
comment_on(debate)
|
||||
|
||||
@@ -37,7 +37,7 @@ feature 'Emails' do
|
||||
end
|
||||
|
||||
scenario 'Do not send email about own debate comments', :js do
|
||||
user = create(:user, email_on_debate_comment: true)
|
||||
user = create(:user, email_on_comment: true)
|
||||
debate = create(:debate, author: user)
|
||||
comment_on(debate, user)
|
||||
|
||||
@@ -45,7 +45,7 @@ feature 'Emails' do
|
||||
end
|
||||
|
||||
scenario 'Do not send email about debate comment unless set in preferences', :js do
|
||||
user = create(:user, email_on_debate_comment: false)
|
||||
user = create(:user, email_on_comment: false)
|
||||
debate = create(:debate, author: user)
|
||||
comment_on(debate)
|
||||
|
||||
|
||||
@@ -66,9 +66,9 @@ describe User do
|
||||
end
|
||||
|
||||
describe 'preferences' do
|
||||
describe 'email_on_debate_comment' do
|
||||
describe 'email_on_comment' do
|
||||
it 'should be false by default' do
|
||||
expect(subject.email_on_debate_comment).to eq(false)
|
||||
expect(subject.email_on_comment).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user