Error of testing redirect in controller

Hi,

I want to test the user controller, how can i do

the code is

if @user.save
redirect_to :action => “confirm”
else

test
user = User.new(:email => “[email protected]”,
:password => “12345”,
:name => “you”)
post :create
user.should_receive(:save).and_return(true)
response.should redirect_to(‘confirm’)

the error

  1. UsersController GET create should save redirect to confirm
    Failure/Error: response.should redirect_to(:action => ‘confirm’)
    Expected response to be a <:redirect>, but was <200>.
    Expected block to return true value.

please help

You have to send params along with call to post.
Since there are no params in post, it goes to the else section of you
controller, where you render a action, and response code for render is
200.
So the test fails saying that you expected a redirect but got render.

Chirag
http://sumeruonrails.com

On Jul 18, 9:57am, Chirag S. [email protected] wrote:

You have to send params along with call to post.
Since there are no params in post, it goes to the else section of you
controller, where you render a action, and response code for render is 200.
So the test fails saying that you expected a redirect but got render.

Can you give me an example that how to send the param to the post. I
am pretty new with testing controller in rails

Your test can be something like this:

post :create, :user => {:email => “[email protected]”, :password =>
“12345”, :name => “you”}
response.should redirect_to(‘confirm’)

Chirag
http://sumeruonrails.com

On Jul 19, 12:04am, Chirag S. [email protected] wrote:

Your test can be something like this:

post :create, :user => {:email => “[email protected]”, :password =>
“12345”, :name => “you”}
response.should redirect_to(‘confirm’)

Thank you Chirag, it s good now

You may also want to read through Rails guides on testing -

Chirag
http://sumeruonrails.com