Refactor method to reply to comment in tests

We take the comment as a parameter instead of the user, since usually
people reply to comments and not to users.

We also remove one database query after the browser has started, since
we can use `debate_path(debate)`. It's also more clear why we're using
`debate_path` in the test; before these changes, we had to enter the
`reply_to` method to realize that we were replying on a debate.
This commit is contained in:
Javi Martín
2021-04-10 18:57:06 +02:00
parent 2458ca22c5
commit 9f926de54e
2 changed files with 9 additions and 9 deletions

View File

@@ -6,12 +6,10 @@ module Comments
CommentNotifier.new(comment: comment).process
end
def reply_to(original_user, replier: create(:user))
debate = create(:debate)
comment = create(:comment, commentable: debate, user: original_user)
def reply_to(comment, replier: create(:user))
login_as(replier)
visit debate_path(debate)
visit polymorphic_path(comment.commentable)
click_link "Reply"
within "#js-comment-form-comment_#{comment.id}" do

View File

@@ -177,27 +177,29 @@ describe "Emails" do
context "Comment replies" do
let(:user) { create(:user, email_on_comment_reply: true) }
let(:debate) { create(:debate) }
let!(:comment) { create(:comment, commentable: debate, user: user) }
scenario "Send email on comment reply" do
reply_to(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(debate_path(Comment.first.commentable))
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 stop receiving these emails change your settings in")
expect(email).to have_body_text(account_path)
end
scenario "Do not send email about own replies to own comments" do
reply_to(user, replier: user)
reply_to(comment, replier: user)
expect { open_last_email }.to raise_error("No email has been sent!")
end
scenario "Do not send email about comment reply unless set in preferences" do
user.update!(email_on_comment_reply: false)
reply_to(user)
reply_to(comment)
expect { open_last_email }.to raise_error("No email has been sent!")
end
end