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
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
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:NilClassIf 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Robert Walker wrote in post #1012664:> 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).For an explanation of this see: http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.