20171004 - Refactored specs for polls comments

On branch mlucena-poll-comments
 Changes to be committed:
	modified:   app/views/comments/show.html.erb
	modified:   spec/features/polls/polls_spec.rb
This commit is contained in:
Manuel Lucena
2017-10-04 15:23:24 +02:00
parent 63cbe2f7c1
commit c3d7d47c3f
2 changed files with 49 additions and 5 deletions

View File

@@ -1,7 +1,7 @@
<div class="row"> <div class="row">
<div class="small-12 column margin-top"> <div class="small-12 column margin-top">
<%= back_link_to commentable_path(@comment), <%= 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>
</div> </div>

View File

@@ -271,23 +271,67 @@ feature 'Polls' do
end end
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') oliver = create(:user, username: 'Oliver Atom')
benji = create(:user, username: 'Benji Prince') benji = create(:user, username: 'Benji Prince')
create(:comment, commentable: poll, user: oliver) create(:comment, commentable: poll, user: oliver)
login_as(oliver) login_as(benji)
visit poll_path(poll) visit poll_path(poll)
expect(page).to have_content oliver.username expect(page).to have_content oliver.username
end 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 end
scenario 'user can downvote a comment' do 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', :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 end
end end