Skip to content

Commit

Permalink
20171004 - Refactored specs for polls comments
Browse files Browse the repository at this point in the history
 On branch mlucena-poll-comments
 Changes to be committed:
	modified:   app/views/comments/show.html.erb
	modified:   spec/features/polls/polls_spec.rb
  • Loading branch information
zamuro committed Oct 6, 2017
1 parent 63cbe2f commit c3d7d47
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/views/comments/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="row">
<div class="small-12 column margin-top">
<%= back_link_to commentable_path(@comment),
t("comments.show.return_to_commentable") + @comment.commentable.title %>
t("comments.show.return_to_commentable") + @comment.commentable.title unless @comment != "Poll" %>
</div>
</div>

Expand Down
52 changes: 48 additions & 4 deletions spec/features/polls/polls_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,23 +271,67 @@
end
end

scenario 'user can reply to comment' do
scenario 'user b can access to comments from user a' do
oliver = create(:user, username: 'Oliver Atom')
benji = create(:user, username: 'Benji Prince')
create(:comment, commentable: poll, user: oliver)

login_as(oliver)
login_as(benji)
visit poll_path(poll)

expect(page).to have_content oliver.username
end

scenario 'user can upvote a comment' do
scenario 'user b can reply to comments from user a', :js do
koji = create(:user, username: 'Koji Kabuto')
sayaka = create(:user, username: 'Sayaka')
comment = create(:comment, commentable: poll, user: koji)

login_as(sayaka)
visit poll_path(poll)

click_link "Reply"

within "#js-comment-form-comment_#{comment.id}" do
fill_in "comment-body-comment_#{comment.id}", with: 'MAZINGER!!.'
click_button 'Publish reply'
end

within "#comment_#{comment.id}" do
expect(page).to have_content 'MAZINGER!!.'
end

expect(page).to_not have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
end

scenario 'user can upvote a comment', :js do
goku = create(:user, username: 'Goku')
vegeta = create(:user, username: 'Vegeta')
comment = create(:comment, commentable: poll, user: goku)

login_as(vegeta)
visit poll_path(poll)

within("#comment_#{comment.id}_votes") do
find('.in_favor a').click

expect(page).to have_content "1 vote"
end
end

scenario 'user can downvote a comment' do
scenario 'user can downvote a comment', :js do
doraemon = create(:user, username: 'Doraemon')
nobita = create(:user, username: 'Nobi Nobita')
comment = create(:comment, commentable: poll, user: doraemon)

login_as(nobita)
visit poll_path(poll)

within("#comment_#{comment.id}_votes") do
find('.against a').click

expect(page).to have_content "1 vote"
end
end
end
end

0 comments on commit c3d7d47

Please sign in to comment.