Dan Venkitachalam
2006-May-03 03:15 UTC
[Rails] Accessing the params hash in a functional test not working
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.
--
Dan Venkitachalam
expandingbrain.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060503/40ec407a/attachment.html
