Forum: Ruby on Rails Accessing the params hash in a functional test not working

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9e44fa55e7078bff7c3dab8404913928?d=identicon&s=25 Dan Venkitachalam (Guest)
on 2006-05-03 19:06
(Received via mailing list)
I am having problems reading params in a functional test (Rails 1.1.2).
My
test looks like this:

  fixtures :users

  def test_auth_bob
    @request.session[:return_to] = "/bogus/location"
    post :login, :user => { :email => "bob@example.com", :password =>
"test"
}

    assert_session_has :user
    assert_equal @bob, @response.session[:user]
    assert_redirected_to "/bogus/location"
  end

And the login action looks like:

  def login
    session[:debug_params] = params
    case @request.method
      when :post
      if session[:user] = User.authenticate(params[:user_email],
params[:user_password])
        flash[:notice]  = "You are now logged in as
"+session[:user].fullname
        redirect_back_or_default :action => "welcome"
      else
        flash[:error]  = "The email address and/or password you entered
is
invalid.".t
        redirect_back_or_default :action => "login"
      end
    end
  end

The test fails as follows.  Note that session[:debug_params] is missing
the
parameters sent by post.

  7) Failure:
test_auth_bob(UserControllerTest)
    [c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1
/lib/action_controller/depr
ecated_assertions.rb:23:in `assert_session_has'
     ./test/functional/user_controller_test.rb:25:in `test_auth_bob']:
<:user> is not in the session <#<ActionController::TestSession:0x36a8380
 @attributes=
  {:user=>nil,
   :debug_params=>{"action"=>"login"},
   "flash"=>
    {:error=>"The email address and/or password you entered is
invalid."},
   :return_to=>nil}>>


I am stumped figuring out why the params are not being passed through -
any
help appreciated!


Cheers,

Dan.
This topic is locked and can not be replied to.