Hi, I''m really struggling getting a controller test to pass while the form that uses the method operates correctly. I would really welcome a second pair of eyes to help me find out what I''m missing. The test def test_set_password @request.session[:user] = users(:admin) put :set_password, :id => users(:one).id, :user => {:password => "newpass", :password_confirmation => "newpass"} assert User.authenticate(users(:one).username, "newpass") assert_redirected_to user_path(assigns(:user)) end The controller method # POST def set_password @user = User.find(params[:id]) respond_to do |format| if @user.update_attributes(params[:user]) flash[:notice] = ''Password updated.'' format.html { redirect_to(@user) } format.xml { head :ok } else format.html { render :action => "edit_password" } format.xml { render :xml => @user.errors, :status => :unprocessable_entity } end end end The view: edit_password.html.erb <%= error_messages_for :user %> <h3><%= @user.username%></h3> <% form_for @user, :url => {:id => @user.id, :action => "set_password"} do |f| %> <p> <%= f.label :password %><br /> <%= f.password_field :password %> </p> <p> <%= f.label :password_confirmation, "Confirm Password" %><br /> <%= f.password_field :password_confirmation %> </p> <p> <%= submit_tag "Change" %> </p> <% end %> <%= link_to ''Back'', @user %> The view works but the test fails. Thanks in advance, Adam --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 5 Dec 2008, at 14:02, Adam wrote:> > > The view works but the test fails. >You need to work out why. stick a breakpoint in the action (or in whatever before filters may be relevant) and see what happens Fred> Thanks in advance, > > Adam > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
OK, thanks Fred. I guess it''s nothing obvious which is sort of reassuring. Adam On Dec 5, 3:27 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 5 Dec 2008, at 14:02, Adam wrote: > > > > > The view works but the test fails. > > You need to work out why. stick a breakpoint in the action (or in > whatever before filters may be relevant) and see what happens > > Fred > > > Thanks in advance, > > > Adam--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org 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 -~----------~----~----~----~------~----~------~--~---
On Dec 6, 12:59 pm, Adam <adam.b...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> OK, thanks Fred. I guess it''s nothing obvious which is sort of > reassuring. >Well there is one thing that I refrained from commenting upon because I''ve no idea how you do your authentication, but in my apps @request.session[:user] = users(:admin) would be @request.session[:user] = users(:admin).id But that should be quite obvious if you look at test.log (it would say that processing was halted because the authorization filter redirected or rendered) Fred> Adam > > On Dec 5, 3:27 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On 5 Dec 2008, at 14:02, Adam wrote: > > > > The view works but the test fails. > > > You need to work out why. stick a breakpoint in the action (or in > > whatever before filters may be relevant) and see what happens > > > Fred > > > > Thanks in advance, > > > > Adam--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org 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 -~----------~----~----~----~------~----~------~--~---
OK, thanks for that advice. It''s not the problem the test is railing on the first assertion. It''s the update of the user record that''s failing for some reason. Adam On Dec 6, 1:08 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Dec 6, 12:59 pm, Adam <adam.b...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> OK, thanks Fred. I guess it''s nothing obvious which is sort of > > reassuring. > > Well there is one thing that I refrained from commenting upon because > I''ve no idea how you do your authentication, but in my apps > > @request.session[:user] = users(:admin) > > would be > > @request.session[:user] = users(:admin).id > > But that should be quite obvious if you look at test.log (it would say > that processing was halted because the authorization filter redirected > or rendered) > > Fred > > > Adam > > > On Dec 5, 3:27 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > On 5 Dec 2008, at 14:02, Adam wrote: > > > > > The view works but the test fails. > > > > You need to work out why. stick a breakpoint in the action (or in > > > whatever before filters may be relevant) and see what happens > > > > Fred > > > > > Thanks in advance, > > > > > Adam--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org 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 -~----------~----~----~----~------~----~------~--~---