Hello Rubyists, I have this functional test which is failing, and I''m not sure why. def test_update #Grab the post we want to update get :edit, :id => @first_id assert_response :success assert_template ''edit'' #Post the changes we want to make post :update, :id => @first_id, :body => "New Body" assert_response :redirect assert_redirected_to :action => ''list'' #Verify that the changes were made successfully assert_equal "Post was successfully updated.", flash[:notice] post = BlogPost.find(@first_id) #My test fails on this next line assert_equal "New Body", post.body, "Expected bodies to match" end My "post :update" comes back successfully, but when I try and validate that the post was actually updated, my test fails. The test fails because the body wasn''t actually changed. Does anyone have any insight they could share on this? Thanks in advance! -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Bob Showalter
2007-Oct-13 17:21 UTC
Re: Not sure if I''m doing post :update correctly in test
On 10/12/07, One_ Mind <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hello Rubyists, > I have this functional test which is failing, and I''m not sure why. > > def test_update > #Grab the post we want to update > get :edit, :id => @first_id > assert_response :success > assert_template ''edit'' > > #Post the changes we want to make > post :update, :id => @first_id, :body => "New Body"What does your controller code look like? This would pass "New Body" as params[:body]. If you''re using form_for() or similar, you probably are doing something like this in your controller: ... @blog_post.attributes = params[:blog_post] In which case you would need to pass the body like this in your test: post :update, :id => @first_id, :blog_post => {:body => "New Body"} I''m just guessing, based on what is typically done. Show use your controller code and we''ll be able to give you a better answer. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Bob Showalter wrote:> #... > In which case you would need to pass the body like this in your test: > > post :update, :id => @first_id, :blog_post => {:body => "New Body"} > > I''m just guessing, based on what is typically done. Show use your > controller code and we''ll be able to give you a better answer.Bob, that worked! Thank you very much. I''m still very new to programming and Rails in general, so I still don''t fully understand how post, get, etc. work. I guess I need to read up more on HTTP protocol. Thanks again for your help! -- 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-/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 -~----------~----~----~----~------~----~------~--~---