creddit/spec/features/comments/edit_comment_spec.rb

57 lines
1.5 KiB
Ruby
Raw Normal View History

2015-07-16 11:57:27 -04:00
require 'rails_helper'
describe 'Edit Comment', type: :feature do
let!(:user) { create(:user) }
let!(:post) { create(:post) }
context 'when signed in' do
2015-12-14 13:28:39 -05:00
let!(:comment) { create(:comment, post: post, user: user) }
2015-07-16 11:57:27 -04:00
before(:each) { signin(user: user) }
2015-12-14 13:28:39 -05:00
context 'when owner' do
let(:content) { 'Some different data' }
2015-07-16 11:57:27 -04:00
2015-12-14 13:28:39 -05:00
context 'with valid data' do
before(:each) do
visit edit_subcreddit_post_comment_path(post.subcreddit,
post,
comment)
2015-07-16 11:57:27 -04:00
2015-12-14 13:28:39 -05:00
fill_in :comment_content, with: content
click_button 'Update Comment'
end
2015-07-16 11:57:27 -04:00
2015-12-14 13:28:39 -05:00
it 'should notify that the comment was edited' do
expect(page).to have_content('updated')
end
it 'should update the comment' do
expect(page).to have_content(content)
end
2015-07-16 11:57:27 -04:00
end
2015-12-14 13:28:39 -05:00
end
context 'when not owner' do
let!(:comment) { create(:comment, post: post) }
2015-07-16 11:57:27 -04:00
2015-12-14 13:28:39 -05:00
it 'should not allow editing of comment' do
visit edit_subcreddit_post_comment_path(post.subcreddit, post, comment)
expect(page).to have_content('not authorized')
2015-07-16 11:57:27 -04:00
end
end
end
2015-12-14 13:28:39 -05:00
context 'when not signed in' do
let!(:comment) { create(:comment, post: post) }
it 'should not allow editing of comment' do
visit edit_subcreddit_post_comment_path(post.subcreddit, post, comment)
expect(page).to have_content('not authorized')
end
end
2015-07-16 11:57:27 -04:00
end