Add email specs for Poll
This commit is contained in:
@@ -17,6 +17,7 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
@poll = Poll.new(poll_params.merge(author: current_user))
|
||||||
if @poll.save
|
if @poll.save
|
||||||
redirect_to [:admin, @poll], notice: t("flash.actions.create.poll")
|
redirect_to [:admin, @poll], notice: t("flash.actions.create.poll")
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
module MailerHelper
|
module MailerHelper
|
||||||
|
|
||||||
def commentable_url(commentable)
|
def commentable_url(commentable)
|
||||||
|
return poll_url(commentable) if commentable.is_a?(Poll)
|
||||||
return debate_url(commentable) if commentable.is_a?(Debate)
|
return debate_url(commentable) if commentable.is_a?(Debate)
|
||||||
return proposal_url(commentable) if commentable.is_a?(Proposal)
|
return proposal_url(commentable) if commentable.is_a?(Proposal)
|
||||||
return community_topic_url(commentable.community_id, commentable) if commentable.is_a?(Topic)
|
return community_topic_url(commentable.community_id, commentable) if commentable.is_a?(Topic)
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ class CommentNotifier
|
|||||||
end
|
end
|
||||||
|
|
||||||
def email_on_comment?
|
def email_on_comment?
|
||||||
return false if @comment.commentable.is_a?(Poll)
|
|
||||||
commentable_author = @comment.commentable.author
|
commentable_author = @comment.commentable.author
|
||||||
commentable_author != @author && commentable_author.email_on_comment?
|
commentable_author != @author && commentable_author.email_on_comment?
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -91,6 +91,9 @@ en:
|
|||||||
topic:
|
topic:
|
||||||
one: "Topic"
|
one: "Topic"
|
||||||
other: "Topics"
|
other: "Topics"
|
||||||
|
poll:
|
||||||
|
one: "Poll"
|
||||||
|
other: "Polls"
|
||||||
attributes:
|
attributes:
|
||||||
budget:
|
budget:
|
||||||
name: "Name"
|
name: "Name"
|
||||||
|
|||||||
@@ -91,6 +91,9 @@ es:
|
|||||||
topic:
|
topic:
|
||||||
one: "Tema"
|
one: "Tema"
|
||||||
other: "Temas"
|
other: "Temas"
|
||||||
|
poll:
|
||||||
|
one: "Votación"
|
||||||
|
other: "Votaciones"
|
||||||
attributes:
|
attributes:
|
||||||
budget:
|
budget:
|
||||||
name: "Nombre"
|
name: "Nombre"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ include ActionView::Helpers::DateHelper
|
|||||||
|
|
||||||
feature 'Commenting polls' do
|
feature 'Commenting polls' do
|
||||||
let(:user) { create :user }
|
let(:user) { create :user }
|
||||||
let(:poll) { create :poll }
|
let(:poll) { create(:poll, author: create(:user)) }
|
||||||
|
|
||||||
scenario 'Index' do
|
scenario 'Index' do
|
||||||
3.times { create(:comment, commentable: poll) }
|
3.times { create(:comment, commentable: poll) }
|
||||||
|
|||||||
@@ -150,6 +150,37 @@ feature 'Emails' do
|
|||||||
end
|
end
|
||||||
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
|
context 'Comment replies' do
|
||||||
scenario "Send email on comment reply", :js do
|
scenario "Send email on comment reply", :js do
|
||||||
user = create(:user, email_on_comment_reply: true)
|
user = create(:user, email_on_comment_reply: true)
|
||||||
@@ -439,40 +470,25 @@ feature 'Emails' do
|
|||||||
|
|
||||||
context "Polls" 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
|
scenario "Send email on poll comment reply", :js do
|
||||||
user1 = create(:user, email_on_comment_reply: true)
|
user1 = create(:user, email_on_comment_reply: true)
|
||||||
user2 = create(:user)
|
user2 = create(:user)
|
||||||
|
poll = create(:poll, author: create(:user))
|
||||||
poll = create(:poll)
|
|
||||||
comment = create(:comment, commentable: poll, author: user1)
|
comment = create(:comment, commentable: poll, author: user1)
|
||||||
|
|
||||||
login_as(user2)
|
login_as(user2)
|
||||||
visit poll_path(poll)
|
visit poll_path(poll)
|
||||||
|
|
||||||
click_link "Reply"
|
click_link "Reply"
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
within "#js-comment-form-comment_#{comment.id}" do
|
||||||
fill_in "comment-body-comment_#{comment.id}", with: 'It will be done next week.'
|
fill_in "comment-body-comment_#{comment.id}", with: 'It will be done next week.'
|
||||||
click_button 'Publish reply'
|
click_button 'Publish reply'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
within "#comment_#{comment.id}" do
|
||||||
expect(page).to have_content 'It will be done next week.'
|
expect(page).to have_content 'It will be done next week.'
|
||||||
|
end
|
||||||
|
|
||||||
email = open_last_email
|
email = open_last_email
|
||||||
expect(email).to have_subject('Someone has responded to your comment')
|
expect(email).to have_subject('Someone has responded to your comment')
|
||||||
|
|||||||
@@ -83,6 +83,8 @@ module CommonActions
|
|||||||
debate_path(commentable)
|
debate_path(commentable)
|
||||||
elsif commentable.is_a?(Topic)
|
elsif commentable.is_a?(Topic)
|
||||||
community_topic_path(commentable, community_id: commentable.community_id)
|
community_topic_path(commentable, community_id: commentable.community_id)
|
||||||
|
elsif commentable.is_a?(Poll)
|
||||||
|
poll_path(commentable)
|
||||||
else
|
else
|
||||||
budget_investment_path(commentable, budget_id: commentable.budget_id)
|
budget_investment_path(commentable, budget_id: commentable.budget_id)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user