creddit/spec/features/posts/edit_post_spec.rb

59 lines
1.5 KiB
Ruby
Raw Normal View History

2015-07-14 16:29:22 -04:00
require 'rails_helper'
describe 'Edit Post', type: :feature do
2015-12-14 13:28:39 -05:00
let!(:subcreddit) { create(:subcreddit) }
2015-07-14 16:29:22 -04:00
context 'when signed in' do
let!(:user) { create(:user) }
let(:new_post) { build_stubbed(:post) }
before(:each) { signin(user: user) }
2015-12-14 13:28:39 -05:00
context 'when owner' do
let!(:post) { create(:post, subcreddit: subcreddit, user: user) }
2015-07-14 16:29:22 -04:00
2015-12-14 13:28:39 -05:00
context 'with valid data' do
before(:each) do
visit edit_subcreddit_post_path(subcreddit, post)
2015-07-14 16:29:22 -04:00
2015-12-14 13:28:39 -05:00
fill_in :post_title, with: new_post.title
fill_in :post_link, with: new_post.link
fill_in :post_content, with: new_post.content
click_button 'Update Post'
end
2015-07-14 16:29:22 -04:00
2015-12-14 13:28:39 -05:00
it 'should notify that the post was edited' do
expect(page).to have_content('updated')
end
it 'should show the updated post' do
expect(page).to have_content(new_post.title)
expect(page).to have_content(new_post.content)
end
2015-07-14 16:29:22 -04:00
end
2015-12-14 13:28:39 -05:00
end
context 'when not owner' do
let!(:post) { create(:post, subcreddit: subcreddit) }
2015-07-14 16:29:22 -04:00
2015-12-14 13:28:39 -05:00
it 'should notify user that they cannot edit' do
visit edit_subcreddit_post_path(subcreddit, post)
expect(page).to have_content 'not authorized'
2015-07-14 16:29:22 -04:00
end
end
end
2015-12-14 13:28:39 -05:00
context 'when not signed in' do
let!(:user) { GuestUser.new }
let!(:post) { create(:post, subcreddit: subcreddit) }
it 'should notify user they cannot edit' do
visit edit_subcreddit_post_path(subcreddit, post)
expect(page).to have_content 'not authorized'
end
end
2015-07-14 16:29:22 -04:00
end