Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes exception when sending a poll comment's email #2039

Merged
merged 1 commit into from
Oct 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fixes exception when sending email about comment reply
  • Loading branch information
voodoorai2000 committed Oct 10, 2017
commit 89f81bf7a4026b8439cf192e2fba3dcd7847e55c
4 changes: 4 additions & 0 deletions app/models/poll.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class Poll < ActiveRecord::Base

scope :sort_for_list, -> { order(:geozone_restricted, :starts_at, :name) }

def title
name
end

def current?(timestamp = Date.current.beginning_of_day)
starts_at <= timestamp && timestamp <= ends_at
end
Expand Down
49 changes: 49 additions & 0 deletions spec/features/emails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,55 @@

end

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)
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.'


email = open_last_email
expect(email).to have_subject('Someone has responded to your comment')
expect(email).to deliver_to(user1)
expect(email).to_not have_body_text(poll_path(poll))
expect(email).to have_body_text(comment_path(Comment.last))
expect(email).to have_body_text(I18n.t("mailers.config.manage_email_subscriptions"))
expect(email).to have_body_text(account_path)
end

end

context "Users without email" do
scenario "should not receive emails", :js do
user = create(:user, :verified, email_on_comment: true)
Expand Down