creddit/spec/features/posts/new_post_spec.rb

62 lines
1.5 KiB
Ruby
Raw Normal View History

2015-07-14 16:29:22 -04:00
require 'rails_helper'
describe 'New 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!(:post) { build(:post, subcreddit: subcreddit) }
before(:each) { signin(user: user) }
context 'with valid data' do
before(:each) do
visit new_subcreddit_post_path(subcreddit)
fill_in :post_title, with: post.title
fill_in :post_link, with: post.link
fill_in :post_content, with: post.content
click_button 'Create Post'
end
it 'should notify that a new post was created' do
expect(page).to have_content('created')
end
it 'should display the new post' do
expect(page).to have_content(post.title)
end
end
context 'with invalid data' do
before(:each) do
visit new_subcreddit_post_path(subcreddit)
post.title = ''
fill_in :post_title, with: post.title
fill_in :post_link, with: post.link
fill_in :post_content, with: post.content
click_button 'Create Post'
end
it 'should display errors' do
expect(page).to have_content("can't be blank")
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 create' do
visit new_subcreddit_post_path(subcreddit)
expect(page).to have_content 'not authorized'
end
end
2015-07-14 16:29:22 -04:00
end