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