Not sure if I'm doing post :update correctly in test

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!

Bob S. 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!

On 10/12/07, One_ Mind [email protected] wrote:

#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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs