Skip to content

Instantly share code, notes, and snippets.

@Fire-Dragon-DoL
Created February 14, 2013 03:06
Show Gist options
  • Save Fire-Dragon-DoL/4950295 to your computer and use it in GitHub Desktop.
Save Fire-Dragon-DoL/4950295 to your computer and use it in GitHub Desktop.
How to test sign_in method?
require 'spec_helper'
describe 'Users' do
describe 'Login' do
it 'should login the user and show logout link' do
user = FactoryGirl.create(:user)
visit new_user_session_path
fill_in 'Email', with: user.email
fill_in 'Password', with: user.password
click_button 'Sign in'
page.should have_content('Logout')
end
end
end
module ValidUserRequestHelper
def sign_in_as_a_valid_user(role = nil)
role = 'user' if role.nil?
@user ||= FactoryGirl.create(:user, role: role)
visit new_user_session_path
fill_in 'Email', with: @user.email
fill_in 'Password', with: @user.password
click_button 'Sign in'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment