For some reason I can't figure out how to make the fields_for tags
render in the trivial example below; however, it works in the browser.
What does #build_association do that my stubbed method does not
replicate? (Or is that even the issue?)
I appreciate the insight. Thanks! Matt Smith
#spec/views/assets/new.html.erb_spec.rb
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 }
before(:each) do
asset.stub(:owner => owner)
assign(:asset, asset)
end
it "renders new asset form" do
render
assert_select "form", :action => assets_path, :method => "post" do
assert_select "input#asset_name", :name => "asset[name]" # passes
assert_select "input#asset_owner_attributes_name", :name =>
"asset[owner_attributes][name]" # fails!
end
end
end
#app/views/assets/_form.html.erb
<%= form_for(@asset) do |f| %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<%= f.fields_for :owner do |owner_fields| %>
<div class="field">
<%= owner_fields.label :name %>
<%= owner_fields.text_field :name %>
</div>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users