Make sure that we will not regress: when not passing locals to the partial, it should still work. This was reported in #54, but first fixed in #53.

This commit is contained in:
nathanvda 2012-04-08 00:56:02 +02:00
parent 700c239c26
commit a0c2d6db53
1 changed files with 9 additions and 2 deletions

View File

@ -81,14 +81,21 @@ describe Cocoon do
end end
end end
context "with extra render-options to pass locals to the partial" do context "passing locals to the partial" do
it "uses the correct plural" do it "when given: passes the locals to the partials" do
@tester.unstub(:render_association) @tester.unstub(:render_association)
@form_obj.should_receive(:fields_for) { | association, new_object, options_hash, &block| block.call } @form_obj.should_receive(:fields_for) { | association, new_object, options_hash, &block| block.call }
@tester.should_receive(:render).with("person_fields", {:f=>nil, :dynamic=>true, :alfred=>"Judoka"}).and_return ("partiallll") @tester.should_receive(:render).with("person_fields", {:f=>nil, :dynamic=>true, :alfred=>"Judoka"}).and_return ("partiallll")
result = @tester.link_to_add_association('add something', @form_obj, :people, :render_options => {:wrapper => 'inline', :locals => {:alfred => 'Judoka'}}) result = @tester.link_to_add_association('add something', @form_obj, :people, :render_options => {:wrapper => 'inline', :locals => {:alfred => 'Judoka'}})
result.to_s.should == '<a href="#" class="add_fields" data-association="person" data-associations="people" data-template="partiallll">add something</a>' result.to_s.should == '<a href="#" class="add_fields" data-association="person" data-associations="people" data-template="partiallll">add something</a>'
end end
it "if no locals are given it still works" do
@tester.unstub(:render_association)
@form_obj.should_receive(:fields_for) { | association, new_object, options_hash, &block| block.call }
@tester.should_receive(:render).with("person_fields", {:f=>nil, :dynamic=>true}).and_return ("partiallll")
result = @tester.link_to_add_association('add something', @form_obj, :people, :render_options => {:wrapper => 'inline'})
result.to_s.should == '<a href="#" class="add_fields" data-association="person" data-associations="people" data-template="partiallll">add something</a>'
end
end end