Chris Mear wrote in post #996461:
> On 3 May 2011, at 15:05, Matt S. wrote:
>
>>>> @asset.build_owner
>> Here is the rendered content:
>>    <input id="asset_name" name="asset[name]" size="30" type="text"
>> </form>
>> a lot about other things!
>>
>> If you want to see everything you can do a 'git clone
>> git://github.com/matthewcalebsmith/asset_owner.git' to get the whole
>> mock project, in case I have left out any pertinent details.
>
> The following patch makes the example pass for me. The key change was to
> take out the #as_null_object call on your mock models. That seems to be
> interfering with Action View's detection of nested attributes
> acceptance, but I'm not sure exactly why.
>
> Chris
>
>>From 0829776dd45b3a0c57134f7af5d4f21feebe5fd7 Mon Sep 17 00:00:00 2001
> From: Chris Mear <ch...@feedmechocolate.com>
> Date: Tue, 3 May 2011 18:11:40 +0100
> Subject: [PATCH] Fix stubbing for nested form in assets/new.
>
> ---
>  spec/views/assets/new.html.erb_spec.rb |   11 ++++++++---
>  1 files changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/spec/views/assets/new.html.erb_spec.rb
> b/spec/views/assets/new.html.erb_spec.rb
> index b8845fe..9bf3b26 100644
> --- a/spec/views/assets/new.html.erb_spec.rb
> +++ b/spec/views/assets/new.html.erb_spec.rb
> @@ -1,13 +1,18 @@
>  require 'spec_helper'
>
>  describe "assets/new.html.erb" do
> -  let(:asset) { mock_model("Asset").as_new_record.as_null_object }
> -  let(:owner) { mock_model("Owner").as_new_record.as_null_object }
> +  let(:asset) { mock_model("Asset").as_new_record }
> +  let(:owner) { mock_model("Owner").as_new_record }
>
>    before(:each) do
>      asset.stub(:owner => owner)
> -    asset.accepts_nested_attributes_for :owner
> +    asset.stub(:name)
> +    asset.stub(:owner_attributes=)
> +
> +    owner.stub(:name)
> +
>      assign(:asset, asset)
> +
>    end
>
>    it "renders new asset form with owner attributes" do
> --
> 1.7.4.4

Thanks Chris,

I guess it ended up being like you said at the beginning. It is good to 
know about the as_null_object behavior, which seems a bit odd, but I 
have too much work to worry about it right now. Definitely reinforces 
the idea of writing as little code as possible to make it pass, and only 
then refactor. If I had truly done that I probably would have caught 
this.

Thank you for your time. I hope this also saves someone else a headache 
in the future.

Thanks again,

Matt Smith

-- 
Posted via http://www.ruby-forum.com/.
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to