Merge pull request #83 from porecreat/rename-template
Rename link 'template' data attribute
This commit is contained in:
commit
c2a0be513d
|
@ -18,7 +18,7 @@
|
||||||
var $this = $(this),
|
var $this = $(this),
|
||||||
assoc = $this.data('association'),
|
assoc = $this.data('association'),
|
||||||
assocs = $this.data('associations'),
|
assocs = $this.data('associations'),
|
||||||
content = $this.data('template'),
|
content = $this.data('association-insertion-template'),
|
||||||
insertionMethod = $this.data('association-insertion-method') || $this.data('association-insertion-position') || 'before';
|
insertionMethod = $this.data('association-insertion-method') || $this.data('association-insertion-position') || 'before';
|
||||||
insertionNode = $this.data('association-insertion-node'),
|
insertionNode = $this.data('association-insertion-node'),
|
||||||
insertionTraversal = $this.data('association-insertion-traversal'),
|
insertionTraversal = $this.data('association-insertion-traversal'),
|
||||||
|
|
|
@ -73,7 +73,7 @@ module Cocoon
|
||||||
html_options[:'data-associations'] = association.to_s.pluralize
|
html_options[:'data-associations'] = association.to_s.pluralize
|
||||||
|
|
||||||
new_object = create_object(f, association)
|
new_object = create_object(f, association)
|
||||||
html_options[:'data-template'] = CGI.escapeHTML(render_association(association, f, new_object, render_options, override_partial)).html_safe
|
html_options[:'data-association-insertion-template'] = CGI.escapeHTML(render_association(association, f, new_object, render_options, override_partial)).html_safe
|
||||||
|
|
||||||
link_to(name, '#', html_options )
|
link_to(name, '#', html_options )
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,19 +21,19 @@ describe Cocoon do
|
||||||
context "without a block" do
|
context "without a block" do
|
||||||
it "accepts a name" do
|
it "accepts a name" do
|
||||||
result = @tester.link_to_add_association('add something', @form_obj, :comments)
|
result = @tester.link_to_add_association('add something', @form_obj, :comments)
|
||||||
result.to_s.should == '<a href="#" class="add_fields" data-association="comment" data-associations="comments" data-template="form<tag>">add something</a>'
|
result.to_s.should == '<a href="#" class="add_fields" data-association-insertion-template="form<tag>" data-association="comment" data-associations="comments">add something</a>'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "accepts html options and pass them to link_to" do
|
it "accepts html options and pass them to link_to" do
|
||||||
result = @tester.link_to_add_association('add something', @form_obj, :comments, {:class => 'something silly'})
|
result = @tester.link_to_add_association('add something', @form_obj, :comments, {:class => 'something silly'})
|
||||||
result.to_s.should == '<a href="#" class="something silly add_fields" data-association="comment" data-associations="comments" data-template="form<tag>">add something</a>'
|
result.to_s.should == '<a href="#" class="something silly add_fields" data-association-insertion-template="form<tag>" data-association="comment" data-associations="comments">add something</a>'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "allows to explicitly hand the wanted partial" do
|
it "allows to explicitly hand the wanted partial" do
|
||||||
@tester.unstub(:render_association)
|
@tester.unstub(:render_association)
|
||||||
@tester.should_receive(:render_association).with(anything(), anything(), anything(), anything(), "shared/partial").and_return('partiallll')
|
@tester.should_receive(:render_association).with(anything(), anything(), anything(), anything(), "shared/partial").and_return('partiallll')
|
||||||
result = @tester.link_to_add_association('add something', @form_obj, :comments, :partial => "shared/partial")
|
result = @tester.link_to_add_association('add something', @form_obj, :comments, :partial => "shared/partial")
|
||||||
result.to_s.should == '<a href="#" class="add_fields" data-association="comment" data-associations="comments" data-template="partiallll">add something</a>'
|
result.to_s.should == '<a href="#" class="add_fields" data-association-insertion-template="partiallll" data-association="comment" data-associations="comments">add something</a>'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -42,14 +42,14 @@ describe Cocoon do
|
||||||
result = @tester.link_to_add_association(@form_obj, :comments) do
|
result = @tester.link_to_add_association(@form_obj, :comments) do
|
||||||
"some long name"
|
"some long name"
|
||||||
end
|
end
|
||||||
result.to_s.should == '<a href="#" class="add_fields" data-association="comment" data-associations="comments" data-template="form<tag>">some long name</a>'
|
result.to_s.should == '<a href="#" class="add_fields" data-association-insertion-template="form<tag>" data-association="comment" data-associations="comments">some long name</a>'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "accepts html options and pass them to link_to" do
|
it "accepts html options and pass them to link_to" do
|
||||||
result = @tester.link_to_add_association(@form_obj, :comments, {:class => 'floppy disk'}) do
|
result = @tester.link_to_add_association(@form_obj, :comments, {:class => 'floppy disk'}) do
|
||||||
"some long name"
|
"some long name"
|
||||||
end
|
end
|
||||||
result.to_s.should == '<a href="#" class="floppy disk add_fields" data-association="comment" data-associations="comments" data-template="form<tag>">some long name</a>'
|
result.to_s.should == '<a href="#" class="floppy disk add_fields" data-association-insertion-template="form<tag>" data-association="comment" data-associations="comments">some long name</a>'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "allows to explicitly hand the wanted partial" do
|
it "allows to explicitly hand the wanted partial" do
|
||||||
|
@ -58,21 +58,21 @@ describe Cocoon do
|
||||||
result = @tester.link_to_add_association( @form_obj, :comments, :class => 'floppy disk', :partial => "shared/partial") do
|
result = @tester.link_to_add_association( @form_obj, :comments, :class => 'floppy disk', :partial => "shared/partial") do
|
||||||
"some long name"
|
"some long name"
|
||||||
end
|
end
|
||||||
result.to_s.should == '<a href="#" class="floppy disk add_fields" data-association="comment" data-associations="comments" data-template="partiallll">some long name</a>'
|
result.to_s.should == '<a href="#" class="floppy disk add_fields" data-association-insertion-template="partiallll" data-association="comment" data-associations="comments">some long name</a>'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with an irregular plural" do
|
context "with an irregular plural" do
|
||||||
it "uses the correct plural" do
|
it "uses the correct plural" do
|
||||||
result = @tester.link_to_add_association('add something', @form_obj, :people)
|
result = @tester.link_to_add_association('add something', @form_obj, :people)
|
||||||
result.to_s.should == '<a href="#" class="add_fields" data-association="person" data-associations="people" data-template="form<tag>">add something</a>'
|
result.to_s.should == '<a href="#" class="add_fields" data-association-insertion-template="form<tag>" data-association="person" data-associations="people">add something</a>'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when using aliased association and class-name" do
|
context "when using aliased association and class-name" do
|
||||||
it "uses the correct name" do
|
it "uses the correct name" do
|
||||||
result = @tester.link_to_add_association('add something', @form_obj, :admin_comments)
|
result = @tester.link_to_add_association('add something', @form_obj, :admin_comments)
|
||||||
result.to_s.should == '<a href="#" class="add_fields" data-association="admin_comment" data-associations="admin_comments" data-template="form<tag>">add something</a>'
|
result.to_s.should == '<a href="#" class="add_fields" data-association-insertion-template="form<tag>" data-association="admin_comment" data-associations="admin_comments">add something</a>'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ describe Cocoon do
|
||||||
it "uses the correct plural" do
|
it "uses the correct plural" do
|
||||||
@tester.should_receive(:render_association).with(:people, @form_obj, anything, {:wrapper => 'inline'}, nil)
|
@tester.should_receive(:render_association).with(:people, @form_obj, anything, {:wrapper => 'inline'}, nil)
|
||||||
result = @tester.link_to_add_association('add something', @form_obj, :people, :render_options => {:wrapper => 'inline'})
|
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="form<tag>">add something</a>'
|
result.to_s.should == '<a href="#" class="add_fields" data-association-insertion-template="form<tag>" data-association="person" data-associations="people">add something</a>'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -94,14 +94,14 @@ describe Cocoon do
|
||||||
@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-insertion-template="partiallll" data-association="person" data-associations="people">add something</a>'
|
||||||
end
|
end
|
||||||
it "if no locals are given it still works" do
|
it "if no locals are given it still works" 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}).and_return ("partiallll")
|
@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 = @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>'
|
result.to_s.should == '<a href="#" class="add_fields" data-association-insertion-template="partiallll" data-association="person" data-associations="people">add something</a>'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ describe Cocoon do
|
||||||
@form_obj.should_receive(:semantic_fields_for)
|
@form_obj.should_receive(:semantic_fields_for)
|
||||||
@form_obj.should_receive(:fields_for).never
|
@form_obj.should_receive(:fields_for).never
|
||||||
result = @tester.link_to_add_association('add something', @form_obj, :people)
|
result = @tester.link_to_add_association('add something', @form_obj, :people)
|
||||||
result.to_s.should == '<a href="#" class="add_fields" data-association="person" data-associations="people" data-template="form<tagzzz>">add something</a>'
|
result.to_s.should == '<a href="#" class="add_fields" data-association-insertion-template="form<tagzzz>" data-association="person" data-associations="people">add something</a>'
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -132,7 +132,7 @@ describe Cocoon do
|
||||||
@form_obj.should_receive(:simple_fields_for)
|
@form_obj.should_receive(:simple_fields_for)
|
||||||
@form_obj.should_receive(:fields_for).never
|
@form_obj.should_receive(:fields_for).never
|
||||||
result = @tester.link_to_add_association('add something', @form_obj, :people)
|
result = @tester.link_to_add_association('add something', @form_obj, :people)
|
||||||
result.to_s.should == '<a href="#" class="add_fields" data-association="person" data-associations="people" data-template="form<tagxxx>">add something</a>'
|
result.to_s.should == '<a href="#" class="add_fields" data-association-insertion-template="form<tagxxx>" data-association="person" data-associations="people">add something</a>'
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue