Created
November 8, 2013 04:41
-
-
Save osiro/7366359 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
feature 'Existing users can sign in to the site' do | |
let(:user) { FactoryGirl.create :user } | |
background do | |
visit root_path | |
click_link 'Sign in' | |
end | |
shared_examples_for 'sign in scenarios' do | |
scenario 'User provides valid credentials' do | |
fill_in 'user[email]', with: user.email | |
fill_in 'user[password]', with: user.password | |
submit_form | |
current_path.should eq expected_path | |
page.should have_flash :notice, /Signed in/ | |
end | |
scenario 'User provides invalid credentials' do | |
fill_in 'user[email]', with: 'not my email!' | |
fill_in 'user[password]', with: user.password | |
submit_form | |
page.should have_flash :alert, /Invalid email/ | |
end | |
end | |
context 'when logging in as an administrator' do | |
let(:user) { FactoryGirl.create :user, :administrator } | |
let(:expected_path) { administrator_dashboard_path } | |
it_behaves_like 'sign in scenarios' | |
end | |
context 'when logging in as a public user' do | |
let(:user) { FactoryGirl.create :user, :public_user } | |
let(:expected_path) { public_user_dashboard_path } | |
it_behaves_like 'sign in scenarios' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment