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

**URL:** <https://www.ruby-forum.com/t/not-sure-if-im-doing-post-update-correctly-in-test/117107>\
**Category:** Rails\
**Created:** [October 13, 2007, 2:00am UTC](https://www.ruby-forum.com/t/not-sure-if-im-doing-post-update-correctly-in-test/117107 "2007-10-13T02:00:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![onemind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@onemind](https://www.ruby-forum.com/u/onemind)\
**Post date:** [October 13, 2007, 2:00am UTC](https://www.ruby-forum.com/t/not-sure-if-im-doing-post-update-correctly-in-test/117107/1 "2007-10-13T02:00:40Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![onemind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@onemind](https://www.ruby-forum.com/u/onemind)\
**Post date:** [October 13, 2007, 11:12pm UTC](https://www.ruby-forum.com/t/not-sure-if-im-doing-post-update-correctly-in-test/117107/2 "2007-10-13T23:12:06Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![onemind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@onemind](https://www.ruby-forum.com/u/onemind)\
**Post date:** [October 13, 2007, 7:23pm UTC](https://www.ruby-forum.com/t/not-sure-if-im-doing-post-update-correctly-in-test/117107/3 "2007-10-13T19:23:59Z")

</div>

On 10/12/07, One\_ Mind [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.
