Files
grecia/spec/support/common_actions/comments.rb
Javi Martín 9f926de54e 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.
2021-04-16 14:25:34 +02:00

26 lines
670 B
Ruby

module Comments
def comment_on(commentable, user = nil)
user ||= create(:user)
comment = create(:comment, commentable: commentable, user: user)
CommentNotifier.new(comment: comment).process
end
def reply_to(comment, 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."
click_button "Publish reply"
end
expect(page).to have_content "It will be done next week."
end
def avatar(name)
"img.initialjs-avatar[data-name='#{name}']"
end
end