diff --git a/spec/support/common_actions/comments.rb b/spec/support/common_actions/comments.rb index 0a0f55d86..c6c7bcbe8 100644 --- a/spec/support/common_actions/comments.rb +++ b/spec/support/common_actions/comments.rb @@ -1,14 +1,14 @@ module Comments - def reply_to(comment, replier: create(:user)) + def reply_to(comment, with: "I like what you say", replier: create(:user)) login_as(replier) visit polymorphic_path(comment.commentable) click_link "Reply" within "#js-comment-form-comment_#{comment.id}" do - fill_in "Leave your comment", with: "It will be done next week." + fill_in "Leave your comment", with: with click_button "Publish reply" end - expect(page).to have_content "It will be done next week." + expect(page).to have_content with end end diff --git a/spec/system/emails_spec.rb b/spec/system/emails_spec.rb index 8b7b504fe..abd911aa5 100644 --- a/spec/system/emails_spec.rb +++ b/spec/system/emails_spec.rb @@ -40,21 +40,25 @@ describe "Emails" do end context "Comment replies" do - let(:user) { create(:user, email_on_comment_reply: true) } - let(:debate) { create(:debate) } + let(:user) { create(:user, email_on_comment_reply: true, subscriptions_token: "commenter_token") } + let(:debate) { create(:debate, title: "Controversial topic") } let!(:comment) { create(:comment, commentable: debate, user: user) } scenario "Send email on comment reply" do - reply_to(comment) + reply_to(comment, with: "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(user) - expect(email).not_to have_body_text(debate_path(debate)) - expect(email).to have_body_text(comment_path(Comment.last)) - expect(email).to have_body_text("To unsubscribe from these emails, visit") - expect(email).to have_body_text(edit_subscriptions_path(token: user.subscriptions_token)) - expect(email).to have_body_text('and uncheck "Notify me by email when someone replies to my comments"') + expect(email).to have_subject "Someone has responded to your comment" + expect(email).to deliver_to user + expect(email).not_to have_body_text debate_path(debate) + expect(email).to have_body_text "It will be done next week" + expect(email).to have_link "Controversial topic" + expect(email).to have_body_text "To unsubscribe from these emails, visit" + expect(email).to have_link "Notifications", href: edit_subscriptions_url( + host: Mailer.default_url_options[:host], + token: "commenter_token" + ) + expect(email).to have_body_text 'and uncheck "Notify me by email when someone replies to my comments"' end scenario "Do not send email about own replies to own comments" do @@ -312,20 +316,23 @@ describe "Emails" do context "Polls" do scenario "Send email on poll comment reply" do - user = create(:user, email_on_comment_reply: true) - poll = create(:poll, author: create(:user)) + user = create(:user, email_on_comment_reply: true, subscriptions_token: "user_token") + poll = create(:poll, author: create(:user), name: "Important questions") comment = create(:comment, commentable: poll, author: user) reply_to(comment) email = open_last_email - expect(email).to have_subject("Someone has responded to your comment") - expect(email).to deliver_to(user) - expect(email).not_to have_body_text(poll_path(poll)) - expect(email).to have_body_text(comment_path(Comment.last)) - expect(email).to have_body_text("To unsubscribe from these emails, visit") - expect(email).to have_body_text(edit_subscriptions_path(token: user.subscriptions_token)) - expect(email).to have_body_text('and uncheck "Notify me by email when someone replies to my comments"') + expect(email).to have_subject "Someone has responded to your comment" + expect(email).to deliver_to user + expect(email).not_to have_body_text poll_path(poll) + expect(email).to have_body_text "Important questions" + expect(email).to have_body_text "To unsubscribe from these emails, visit" + expect(email).to have_link "Notifications", href: edit_subscriptions_url( + host: Mailer.default_url_options[:host], + token: "user_token" + ) + expect(email).to have_body_text 'and uncheck "Notify me by email when someone replies to my comments"' end end