Created
May 1, 2010 07:25
-
-
Save patrick99e99/386125 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
include ActionView::Helpers | |
describe Content do | |
def rendered_contents | |
ContentRenderer.new(nil, {:contents => @contents, :skip_ids => true}).render_contents | |
end | |
def filter(markup) | |
markup.squeeze(" ").strip.gsub("\n ", "") | |
end | |
before(:each) do | |
Content.all.map(&:destroy) | |
end | |
it "should insert nested content inside a non-self-closing element" do | |
@contents = Content.create!(:html_tag => 'div') | |
@contents.children << Content.create!(:html_tag => 'p', :data => 'inside a div!') | |
rendered_contents.should == filter("<div> | |
<p>inside a div!</p> | |
</div>") | |
end | |
it "should insert nested content ordered by position" do | |
@contents = Content.create!(:html_tag => 'ul') | |
@contents.children << Content.create!(:html_tag => 'li', :data => 'item 1', :position => 2) | |
@contents.children << Content.create!(:html_tag => 'li', :data => 'item 2', :position => 0) | |
@contents.children << Content.create!(:html_tag => 'li', :data => 'item 3', :position => 1) | |
rendered_contents.should == filter("<ul> | |
<li>item 2</li> | |
<li>item 3</li> | |
<li>item 1</li> | |
</ul>") | |
end | |
it "should insert nested content at a start position if specified" do | |
@contents = Content.create!(:html_tag => 'p', :data => 'something special') | |
@contents.children << Content.create!(:html_tag => 'span', :data => 'very', :start_position => 10) | |
rendered_contents.should == "<p>something <span>very</span> special</p>" | |
end | |
it "should insert nested contents at multiple start positions" do | |
@contents = Content.create!(:html_tag => 'div') | |
@contents.children << Content.create!(:html_tag => 'p', :data => 'hello there.') | |
@contents.children << Content.create!(:html_tag => 'div') | |
inner_div = Content.last | |
inner_div.children << Content.create!(:html_tag => 'p', :data => 'foo bar fish!') | |
inner_div.children << Content.create!(:html_tag => 'p', :data => 'this is the sentence that will have added spans!') | |
for_spans = Content.last | |
for_spans.children << Content.create!(:html_tag => 'span', :data => ', in my opinion,', :start_position => 4) | |
for_spans.children << Content.create!(:html_tag => 'span', :data => 'two', :start_position => 36) | |
inner_div.children << Content.create!(:html_tag => 'p', :data => 'baz!') | |
@contents.children << Content.create!(:html_tag => 'p', :data => 'thank you.') | |
@contents.children << Content.create!(:html_tag => 'p', :data => 'goodbye.') | |
rendered_contents.should == filter("<div> | |
<p>hello there.</p> | |
<div> | |
<p>foo bar fish!</p> | |
<p>this<span>, in my opinion,</span> is the sentence that will have <span>two</span>added spans!</p> | |
<p>baz!</p> | |
</div> | |
<p>thank you.</p> | |
<p>goodbye.</p> | |
</div>") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment