first posting on this helpful community, but have been using it since the start of my programming journey. I'm new to rails and have trouble writing tests. So far, I've been trying to write a controller test based on the Authlogic perishable token guide .
But during the test, it keeps getting stuck on the line
#controller
@user = User.find_using_perishable_token(params[:activation_code], 1.week) || (redirect_to new_user_session_url and return)
and here's the line in the test that gets into trouble:
#test
User.any_instance.stub(:find_using_perishable_token) {mock_model(User, stubs(:active => true)) }
get :create, :activation_code => 'valid'
response.should render_template 'new'
response.code.should == "200"
#the test response is 302, not 200
response.should redirect_to("/")
#the test shows the path as user_sessions/new,
#meaning it didn't pass the condition in the controller with the find_using_pt method
Heres the test output:
Failure/Error: response.should render_template 'new' expecting <"new"> but rendering with <"">
# ./spec/controllers/activations_controller_spec.rb:18:in `block (3 levels) in <top (required)>'
After reading one of the posted answers ,it seems that I'm not creating the stub/mock correctly and that's why it keeps getting the redirect_to (302) rather than continuing with the test. (the find_using_pt is a method from Authlogic). Hence, the trouble is with the redirect_to line as it never continues with the controller/page render
Any advice would be greatly appreciated. Thanks.