# Rspec - rails put :update any examples

**URL:** <https://www.ruby-forum.com/t/rspec-rails-put-update-any-examples/128130>\
**Category:** RSpec\
**Created:** [February 5, 2008, 7:53am UTC](https://www.ruby-forum.com/t/rspec-rails-put-update-any-examples/128130 "2008-02-05T07:53:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![circlefusion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ea666f/32.png) [@circlefusion](https://www.ruby-forum.com/u/circlefusion)\
**Post date:** [February 5, 2008, 7:53am UTC](https://www.ruby-forum.com/t/rspec-rails-put-update-any-examples/128130/1 "2008-02-05T07:53:52Z")

</div>

I’m looking for a working example of a put :update on a controller. The  
documentation online avoids the update function.

Any help pointing to this example would be great. Trying to get to 100%  
coverage…can’t make it without update 🙂

Brian

---

<div class="post-metadata">

**Author:** ![circlefusion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ea666f/32.png) [@circlefusion](https://www.ruby-forum.com/u/circlefusion)\
**Post date:** [February 5, 2008, 8:05am UTC](https://www.ruby-forum.com/t/rspec-rails-put-update-any-examples/128130/2 "2008-02-05T08:05:37Z")

</div>

On Feb 4, 2008 9:44 PM, Brian R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m looking for a working example of a put :update on a controller. The  
> documentation online avoids the update function.
> 
> Any help pointing to this example would be great. Trying to get to 100%  
> coverage…can’t make it without update 🙂

This is what I do:

it “should replace foo with bar partial” do  
page = mock(“page”)  
page.should\_receive(:replace\_html).with(‘foo’, :partial =\> ‘bar’)  
controller.expect\_render(:update).and\_yield(page)  
do\_post  
end

HTH,  
David

---

<div class="post-metadata">

**Author:** ![circlefusion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ea666f/32.png) [@circlefusion](https://www.ruby-forum.com/u/circlefusion)\
**Post date:** [February 6, 2008, 1:42am UTC](https://www.ruby-forum.com/t/rspec-rails-put-update-any-examples/128130/3 "2008-02-06T01:42:40Z")

</div>

David, I tried doing this, and I get an exception. Here’s a pastie of  
the  
error, controller, controller\_spec: [Parked at Loopia](http://pastie.caboo.se/148021)

---

<div class="post-metadata">

**Author:** ![circlefusion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ea666f/32.png) [@circlefusion](https://www.ruby-forum.com/u/circlefusion)\
**Post date:** [February 6, 2008, 1:44am UTC](https://www.ruby-forum.com/t/rspec-rails-put-update-any-examples/128130/4 "2008-02-06T01:44:25Z")

</div>

And, of course, here are my versions:

Ruby 1.8.6  
Rails 2.0.2  
Zentest 3.8  
RSpec (I believe 1.1.2)

---

<div class="post-metadata">

**Author:** ![circlefusion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ea666f/32.png) [@circlefusion](https://www.ruby-forum.com/u/circlefusion)\
**Post date:** [February 6, 2008, 3:30am UTC](https://www.ruby-forum.com/t/rspec-rails-put-update-any-examples/128130/5 "2008-02-06T03:30:33Z")

</div>

On Feb 5, 2008 6:42 PM, Corey H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> David, I tried doing this, and I get an exception. Here’s a pastie of the  
> error, controller, controller\_spec: [http://pastie.caboo.se/148021](http://pastie.caboo.se/148021)

You’ve got page[:coupon\_list], not just page. So what you need to mock  
is this:

page = mock(“page”)  
page.should\_receive(:).with(:coupon\_list).and\_return(page)  
page.should\_receive(:replace\_html).with(:partial =\> “coupon\_list”)

That’s starting to get a bit brittle, but that’s what you get for  
mixing all that view logic in your controllers. It’s the Rails Way,  
but it comes with a price if you want this level of coverage and  
isolation.

FWIW,  
David

---

<div class="post-metadata">

**Author:** ![circlefusion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ea666f/32.png) [@circlefusion](https://www.ruby-forum.com/u/circlefusion)\
**Post date:** [February 10, 2008, 2:03pm UTC](https://www.ruby-forum.com/t/rspec-rails-put-update-any-examples/128130/6 "2008-02-10T14:03:51Z")

</div>

Okay, I’ll try that. Thanks.

I don’t really like all the view stuff in the controllers, and I intend  
to  
eventually move them into RJS, but, while I’m learning, I’m keeping it  
there. 🙂

-Corey
