I am sorry I posted wrong tester calling method. The correct calling
method for testing is:
def test_bad_signup
#check we can’t signup without all required fields
post :signup, :user => { :login => “newbob”, :password =>
“newpassword”, :password_confirmation => “wrong” , :email =>
“[email protected]”}
assert_response :success
assert_invalid_column_on_record “user”, “password”
assert_template “user/signup”
assert_nil session[:user]
post :signup, :user => { :login => "yo", :password => "newpassword",
:password_confirmation => “newpassword” , :email => “[email protected]”}
assert_response :success
assert_invalid_column_on_record “user”, “login”
assert_template “user/signup”
assert_nil session[:user]
post :signup, :user => { :login => "yo", :password => "newpassword",
:password_confirmation => “wrong” , :email => “[email protected]”}
assert_response :success
assert_invalid_column_on_record “user”, [“login”, “password”]
assert_template “user/signup”
assert_nil session[:user]
end
Vishwa R. wrote:
Thank you. Yes ‘assert_session_has’ and ‘assert_session_has_no’ has
been replaced by ‘assert_nil session’
Now I am getting another error:
Error:
test_bad_signup(UserControllerTest):
NoMethodError: You have a nil object when you didn’t expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]
C:/VR/RailsPrograms/health/app/controllers/user_controller.rb:5:in
signup' C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/action_controller/ba se.rb:1331:in
perform_action’
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/action_controller/fi
lters.rb:617:in call_filters' C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/action_controller/fi lters.rb:610:in
perform_action_with_filters’
C:/Ruby19/lib/ruby/gems/1.9.1/gems/actionpack-2.3.5/lib/action_controller/be
nchmarking.rb:68:in block in perform_action_with_benchmark' C:/Ruby19/lib/ruby/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/co re_ext/benchmark.rb:17:in
block in ms’
The ‘signup’ method is defined as:
def signup
@user = User.new(@params[:user])
if request.post?
if @user.save
session[:user] = User.authenticate(@user.login, @user.password)
flash[:message] = “Signup successful”
redirect_to :action => “welcome”
else
flash[:warning] = “Signup unsuccessful”
end
end
end
The tester is calling ‘signup’ as
def test_signup
#check we can signup and then login
post :signup, :user => { :login => “newbob”, :password =>
“newpassword”, :password_confirmation => “newpassword”, :email =>
“[email protected]” }
assert_response :redirect
assert_not_nil session[:user]
assert_session_has :user
assert_redirected_to :action=>‘welcome’
end
Please tell me, what I am doing wrong?
Colin L. wrote:
2010/1/26 Vishwa R. [email protected]:
I get this Error:
test_auth_bob(UserControllerTest):
NoMethodError: undefined method `assert_session_has’ for
#<UserControllerTest:0x
28772e0>
A quick google search shows assert_session_has as being deprecated in
2006, so presumably it is now gone. You will have to do it a
different way.
Colin