Merge pull request #2126 from wairbut-m2c/aperez-email-specs-for-commentables
Email specs for commentable models
This commit is contained in:
@@ -17,6 +17,7 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
|
||||
end
|
||||
|
||||
def create
|
||||
@poll = Poll.new(poll_params.merge(author: current_user))
|
||||
if @poll.save
|
||||
redirect_to [:admin, @poll], notice: t("flash.actions.create.poll")
|
||||
else
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
module MailerHelper
|
||||
|
||||
def commentable_url(commentable)
|
||||
return poll_url(commentable) if commentable.is_a?(Poll)
|
||||
return debate_url(commentable) if commentable.is_a?(Debate)
|
||||
return proposal_url(commentable) if commentable.is_a?(Proposal)
|
||||
return community_topic_url(commentable.community_id, commentable) if commentable.is_a?(Topic)
|
||||
return budget_investment_url(commentable.budget_id, commentable) if commentable.is_a?(Budget::Investment)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -22,7 +22,6 @@ class CommentNotifier
|
||||
end
|
||||
|
||||
def email_on_comment?
|
||||
return false if @comment.commentable.is_a?(Poll)
|
||||
commentable_author = @comment.commentable.author
|
||||
commentable_author != @author && commentable_author.email_on_comment?
|
||||
end
|
||||
|
||||
@@ -88,6 +88,12 @@ en:
|
||||
images:
|
||||
one: "Image"
|
||||
other: "Images"
|
||||
topic:
|
||||
one: "Topic"
|
||||
other: "Topics"
|
||||
poll:
|
||||
one: "Poll"
|
||||
other: "Polls"
|
||||
attributes:
|
||||
budget:
|
||||
name: "Name"
|
||||
@@ -286,4 +292,4 @@ en:
|
||||
record_invalid: "Validation failed: %{errors}"
|
||||
restrict_dependent_destroy:
|
||||
has_one: "Cannot delete record because a dependent %{record} exists"
|
||||
has_many: "Cannot delete record because dependent %{record} exist"
|
||||
has_many: "Cannot delete record because dependent %{record} exist"
|
||||
|
||||
@@ -88,6 +88,12 @@ es:
|
||||
images:
|
||||
one: "Imagen"
|
||||
other: "Imágenes"
|
||||
topic:
|
||||
one: "Tema"
|
||||
other: "Temas"
|
||||
poll:
|
||||
one: "Votación"
|
||||
other: "Votaciones"
|
||||
attributes:
|
||||
budget:
|
||||
name: "Nombre"
|
||||
|
||||
@@ -3,7 +3,7 @@ include ActionView::Helpers::DateHelper
|
||||
|
||||
feature 'Commenting polls' do
|
||||
let(:user) { create :user }
|
||||
let(:poll) { create :poll }
|
||||
let(:poll) { create(:poll, author: create(:user)) }
|
||||
|
||||
scenario 'Index' do
|
||||
3.times { create(:comment, commentable: poll) }
|
||||
|
||||
@@ -84,6 +84,103 @@ feature 'Emails' do
|
||||
end
|
||||
end
|
||||
|
||||
context 'Budget investments comments' do
|
||||
scenario 'Send email on budget investment comment', :js do
|
||||
user = create(:user, email_on_comment: true)
|
||||
investment = create(:budget_investment, author: user, budget: create(:budget))
|
||||
comment_on(investment)
|
||||
|
||||
email = open_last_email
|
||||
expect(email).to have_subject('Someone has commented on your investment')
|
||||
expect(email).to deliver_to(investment.author)
|
||||
expect(email).to have_body_text(budget_investment_path(investment, budget_id: investment.budget_id))
|
||||
expect(email).to have_body_text(I18n.t('mailers.config.manage_email_subscriptions'))
|
||||
expect(email).to have_body_text(account_path)
|
||||
end
|
||||
|
||||
scenario 'Do not send email about own budget investments comments', :js do
|
||||
user = create(:user, email_on_comment: true)
|
||||
investment = create(:budget_investment, author: user, budget: create(:budget))
|
||||
comment_on(investment, user)
|
||||
|
||||
expect { open_last_email }.to raise_error 'No email has been sent!'
|
||||
end
|
||||
|
||||
scenario 'Do not send email about budget investment comment unless set in preferences', :js do
|
||||
user = create(:user, email_on_comment: false)
|
||||
investment = create(:budget_investment, author: user, budget: create(:budget))
|
||||
comment_on(investment)
|
||||
|
||||
expect { open_last_email }.to raise_error 'No email has been sent!'
|
||||
end
|
||||
end
|
||||
|
||||
context 'Topic comments' do
|
||||
before(:each) do
|
||||
@proposal = create(:proposal)
|
||||
end
|
||||
|
||||
scenario 'Send email on topic comment', :js do
|
||||
user = create(:user, email_on_comment: true)
|
||||
topic = create(:topic, author: user, community: @proposal.community)
|
||||
comment_on(topic)
|
||||
|
||||
email = open_last_email
|
||||
expect(email).to have_subject('Someone has commented on your topic')
|
||||
expect(email).to deliver_to(topic.author)
|
||||
expect(email).to have_body_text(community_topic_path(topic, community_id: topic.community_id))
|
||||
expect(email).to have_body_text(I18n.t('mailers.config.manage_email_subscriptions'))
|
||||
expect(email).to have_body_text(account_path)
|
||||
end
|
||||
|
||||
scenario 'Do not send email about own topic comments', :js do
|
||||
user = create(:user, email_on_comment: true)
|
||||
topic = create(:topic, author: user, community: @proposal.community)
|
||||
comment_on(topic, user)
|
||||
|
||||
expect { open_last_email }.to raise_error 'No email has been sent!'
|
||||
end
|
||||
|
||||
scenario 'Do not send email about topic comment unless set in preferences', :js do
|
||||
user = create(:user, email_on_comment: false)
|
||||
topic = create(:topic, author: user, community: @proposal.community)
|
||||
comment_on(topic)
|
||||
|
||||
expect { open_last_email }.to raise_error 'No email has been sent!'
|
||||
end
|
||||
end
|
||||
|
||||
context 'Poll comments' do
|
||||
scenario 'Send email on poll comment', :js do
|
||||
user = create(:user, email_on_comment: true)
|
||||
poll = create(:poll, author: user)
|
||||
comment_on(poll)
|
||||
|
||||
email = open_last_email
|
||||
expect(email).to have_subject('Someone has commented on your poll')
|
||||
expect(email).to deliver_to(poll.author)
|
||||
expect(email).to have_body_text(poll_path(poll))
|
||||
expect(email).to have_body_text(I18n.t('mailers.config.manage_email_subscriptions'))
|
||||
expect(email).to have_body_text(account_path)
|
||||
end
|
||||
|
||||
scenario 'Do not send email about own poll comments', :js do
|
||||
user = create(:user, email_on_comment: true)
|
||||
poll = create(:poll, author: user)
|
||||
comment_on(poll, user)
|
||||
|
||||
expect { open_last_email }.to raise_error 'No email has been sent!'
|
||||
end
|
||||
|
||||
scenario 'Do not send email about poll question comment unless set in preferences', :js do
|
||||
user = create(:user, email_on_comment: false)
|
||||
poll = create(:poll, author: user)
|
||||
comment_on(poll)
|
||||
|
||||
expect { open_last_email }.to raise_error 'No email has been sent!'
|
||||
end
|
||||
end
|
||||
|
||||
context 'Comment replies' do
|
||||
scenario "Send email on comment reply", :js do
|
||||
user = create(:user, email_on_comment_reply: true)
|
||||
@@ -373,40 +470,25 @@ feature 'Emails' do
|
||||
|
||||
context "Polls" do
|
||||
|
||||
scenario "Do not send email on poll comment", :js do
|
||||
user1 = create(:user, email_on_comment: true)
|
||||
user2 = create(:user)
|
||||
|
||||
poll = create(:poll, author: user1)
|
||||
reset_mailer
|
||||
|
||||
login_as(user2)
|
||||
visit poll_path(poll)
|
||||
|
||||
fill_in "comment-body-poll_#{poll.id}", with: 'Have you thought about...?'
|
||||
click_button 'Publish comment'
|
||||
|
||||
expect(page).to have_content 'Have you thought about...?'
|
||||
|
||||
expect { open_last_email }.to raise_error "No email has been sent!"
|
||||
end
|
||||
|
||||
scenario "Send email on poll comment reply", :js do
|
||||
user1 = create(:user, email_on_comment_reply: true)
|
||||
user2 = create(:user)
|
||||
|
||||
poll = create(:poll)
|
||||
poll = create(:poll, author: create(:user))
|
||||
comment = create(:comment, commentable: poll, author: user1)
|
||||
|
||||
login_as(user2)
|
||||
visit poll_path(poll)
|
||||
|
||||
click_link "Reply"
|
||||
|
||||
within "#js-comment-form-comment_#{comment.id}" do
|
||||
fill_in "comment-body-comment_#{comment.id}", with: 'It will be done next week.'
|
||||
click_button 'Publish reply'
|
||||
end
|
||||
expect(page).to have_content 'It will be done next week.'
|
||||
|
||||
within "#comment_#{comment.id}" do
|
||||
expect(page).to have_content 'It will be done next week.'
|
||||
end
|
||||
|
||||
email = open_last_email
|
||||
expect(email).to have_subject('Someone has responded to your comment')
|
||||
|
||||
@@ -77,10 +77,20 @@ module CommonActions
|
||||
user ||= create(:user)
|
||||
|
||||
login_as(user)
|
||||
commentable_path = commentable.is_a?(Proposal) ? proposal_path(commentable) : debate_path(commentable)
|
||||
commentable_path = if commentable.is_a?(Proposal)
|
||||
proposal_path(commentable)
|
||||
elsif commentable.is_a?(Debate)
|
||||
debate_path(commentable)
|
||||
elsif commentable.is_a?(Topic)
|
||||
community_topic_path(commentable, community_id: commentable.community_id)
|
||||
elsif commentable.is_a?(Poll)
|
||||
poll_path(commentable)
|
||||
else
|
||||
budget_investment_path(commentable, budget_id: commentable.budget_id)
|
||||
end
|
||||
visit commentable_path
|
||||
|
||||
fill_in "comment-body-#{commentable.class.name.underscore}_#{commentable.id}", with: 'Have you thought about...?'
|
||||
fill_in "comment-body-#{commentable.class.name.gsub(/::/, '_').downcase}_#{commentable.id}", with: 'Have you thought about...?'
|
||||
click_button 'Publish comment'
|
||||
|
||||
expect(page).to have_content 'Have you thought about...?'
|
||||
|
||||
Reference in New Issue
Block a user