[Rails] Re: Error of Testing index (undefined)
Yennie wrote in post #1011712:
> Hi,
>
> I follow the tutorial of testing the params then i got the error when
> i test..
> can someone help me
>
>
> Thanks for your help
>
>
> Yennie
>
> code
> def disable
> if !(@user = User.find_by_id(params[:id]))
> render :action => "common/error_notfound"
> else
> @user.save
> @users = User.find(:all)
> redirect_to( {:action=>"index"}
> end
> end
>
> test
> it "should not go to index" do
> get :index, :user => {:email => "testing",
> :password => "12345",
> :name => "you"}
> assigns[:user].name.should == "you"
> response.should redirect_to('index')
> end
>
> error
> undefined method `name' for nil:NilClass
If you're trying to test the disable action/method then why are you
getting index (get :index, :user => ...)?
And, besides that your disable action is probably not safe nor
idempotent so you should not be sending a GET request to it. You should
use PUT (or at least POST).
put :disable, :user => ....
Also make sure you have a valid route defined for the disable action on
that controller.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home