creddit/spec/features/subcreddits/new_subcreddit_spec.rb

52 lines
1.2 KiB
Ruby
Raw Normal View History

require 'rails_helper'
describe 'New Subcreddit', type: :feature do
before(:each) { signout }
context 'when not signed in' do
2015-12-14 13:28:39 -05:00
it 'should not be able to create a new subcreddit' do
visit new_subcreddit_path
expect(page).to have_content('not authorized')
end
end
context 'when signed in' do
let(:user) { create(:user) }
let(:subcreddit) { build_stubbed(:subcreddit) }
before(:each) { signin(user: user) }
context 'with valid data' do
before(:each) do
visit new_subcreddit_path
fill_in :subcreddit_name, with: subcreddit.name
click_button 'Create Subcreddit'
end
it 'should notify that a new subcreddit was created' do
expect(page).to have_content('created')
end
it 'should forward you to the new subcreddit' do
expect(page).to have_content(subcreddit.name)
end
end
context 'with invalid data' do
before(:each) do
subcreddit.name = ''
visit new_subcreddit_path
fill_in :subcreddit_name, with: subcreddit.name
click_button 'Create Subcreddit'
end
it 'should display errors' do
expect(page).to have_content("can't be blank")
end
end
end
end