spec/unit/arbre/html_spec.rb in andrewroth_activeadmin-0.3.4.3 vs spec/unit/arbre/html_spec.rb in andrewroth_activeadmin-0.3.4.4

- old
+ new

@@ -4,20 +4,20 @@ setup_arbre_context! it "should render a single element" do content = span("Hello World") - content.to_html.should == <<-HTML + content.to_s.should == <<-HTML <span>Hello World</span> HTML end it "should render a child element" do content = span do span "Hello World" end - content.to_html.should == <<-HTML + content.to_s.should == <<-HTML <span> <span>Hello World</span> </span> HTML end @@ -26,11 +26,11 @@ content = ul do li "First" li "Second" li "Third" end - content.to_html.should == <<-HTML + content.to_s.should == <<-HTML <ul> <li>First</li> <li>Second</li> <li>Third</li> </ul> @@ -49,11 +49,11 @@ second = "Second" content = ul do li first li second end - content.to_html.should == <<-EOS + content.to_s.should == <<-EOS <ul> <li>First</li> <li>Second</li> </ul> EOS @@ -64,11 +64,11 @@ ul li do li end end - content.to_html.should == <<-HTML + content.to_s.should == <<-HTML <div> <ul></ul> <li> <li></li> </li> @@ -80,11 +80,11 @@ content = div do |d| d.ul do li end end - content.to_html.should == <<-HTML + content.to_s.should == <<-HTML <div> <ul> <li></li> </ul> </div> @@ -93,11 +93,11 @@ it "should move content tags between parents" do content = div do span(ul(li)) end - content.to_html.should == <<-HTML + content.to_s.should == <<-HTML <div> <span> <ul> <li></li> </ul> @@ -111,11 +111,11 @@ d.id = "my-tag" ul do li end end - content.to_html.should == <<-HTML + content.to_s.should == <<-HTML <div id="my-tag"> <ul> <li></li> </ul> </div> @@ -129,18 +129,28 @@ item = li "World" end item.parent.should == list end - it "should set a string content return value with no children" do - li do - "Hello World" - end.to_html.should == <<-HTML -<li>Hello World</li> -HTML + + ["Hello World", 1, 1.5].each do |value| + it "should append the return value of '#{value}' when no other children added to the DOM" do + li do + value + end.to_s.should == "<li>#{value}</li>\n" + end end + ["Hello World", 1, 1.5].each do |value| + it "should not append the return value of '#{value}' when children have been added to the DOM" do + li do + text_node("Already Added") + value + end.to_s.should == "<li>Already Added</li>\n" + end + end + describe "text nodes" do it "should turn strings into text nodes" do li do "Hello World" end.children.first.should be_instance_of(Arbre::HTML::TextNode) @@ -148,41 +158,41 @@ end describe "self-closing nodes" do it "should not self-close script tags" do tag = script :type => 'text/javascript' - tag.to_html.should == <<-HTML + tag.to_s.should == <<-HTML <script type="text/javascript"></script> HTML end it "should self-close meta tags" do tag = meta :content => "text/html; charset=utf-8" - tag.to_html.should == <<-HTML + tag.to_s.should == <<-HTML <meta content="text/html; charset=utf-8\"/> HTML end it "should self-close link tags" do tag = link :rel => "stylesheet" - tag.to_html.should == <<-HTML + tag.to_s.should == <<-HTML <link rel="stylesheet"/> HTML end end describe "html safe" do it "should escape the contents" do - span("<br />").to_html.should == <<-HTML + span("<br />").to_s.should == <<-HTML <span>&lt;br /&gt;</span> HTML end it "should return html safe strings" do - span("<br />").to_html.should be_html_safe + span("<br />").to_s.should be_html_safe end it "should not escape html passed in" do - span(span("<br />")).to_html.should == <<-HTML + span(span("<br />")).to_s.should == <<-HTML <span> <span>&lt;br /&gt;</span> </span> HTML end @@ -190,18 +200,18 @@ it "should escape string contents when passed in block" do span { span { "<br />" } - }.to_html.should == <<-HTML + }.to_s.should == <<-HTML <span> <span>&lt;br /&gt;</span> </span> HTML end it "should escape the contents of attributes" do - span(:class => "<br />").to_html.should == <<-HTML + span(:class => "<br />").to_s.should == <<-HTML <span class="&lt;br /&gt;"></span> HTML end end