Add email specs for Poll

This commit is contained in:
Angel Perez
2017-11-13 16:05:10 -04:00
parent 4c110e8100
commit 2bdc2c27d7
8 changed files with 48 additions and 23 deletions

View File

@@ -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

View File

@@ -1,6 +1,7 @@
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)

View File

@@ -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

View File

@@ -91,6 +91,9 @@ en:
topic:
one: "Topic"
other: "Topics"
poll:
one: "Poll"
other: "Polls"
attributes:
budget:
name: "Name"

View File

@@ -91,6 +91,9 @@ es:
topic:
one: "Tema"
other: "Temas"
poll:
one: "Votación"
other: "Votaciones"
attributes:
budget:
name: "Nombre"

View File

@@ -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) }

View File

@@ -150,6 +150,37 @@ feature 'Emails' do
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)
@@ -439,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')

View File

@@ -83,6 +83,8 @@ module CommonActions
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