RAILS INTEGRATION TEST WITH SHOULDA, FACTORY_GIRL, WEBRAT, AND AUTHLOGIC

Rails Integration Test with shoulda, factory_girl, webrat, and authlogic

I had some issues trying to use a symbol

session[:user_credentials_id]

vs. a string

session["user_credentials_id"]

Here is my solution:

require 'test_helper'

class LoginTest < ActionController::IntegrationTest
  context 'A user' do
    setup do
      @user = Factory(:user)
      # puts @user.inspect    
    end

    should 'be able to login with a valid username and password' do
      visit '/user_session/new'
      assert_equal '/user_session/new', path
      fill_in 'Login', :with => @user.login
      fill_in 'Password', :with => @user.password
      click_button 'Login'
      # puts "user.id: #{@user.id}" 
      # puts "session: #{session.inspect}"
      # puts "session[:user_credentials_id] #{session["user_credentials_id"]}"
      assert_equal @user.id, session["user_credentials_id"]
    end

    should 'be denied access with an invalid username or password' do
      visit '/user_session/new'
      assert_equal '/user_session/new', path
      fill_in 'Login', :with => @user.login
      fill_in 'Password', :with => 'wrongpassord'
      click_button 'Login'
      assert_nil session["user_credentials_id"]
    end

  end
end

Comments

comments powered by Disqus