Skip to content
Browse files

Basic page spec passing, testing for entity preservation

  • Loading branch information...
1 parent e331f1d commit d51f57d1d1586ecf2157eec8f2b6380db5516493 @aceofspades committed May 25, 2012
View
2 lib/caloris/erb_string.rb
@@ -2,7 +2,7 @@ module Caloris
# Makes ERB into valid-ish, parseable HTML.
# Markup can therefore be processed without being interpolated into HTML until desired.
- # Nokogiri is used to parse HTML that may have embedded ERB, but it shouldn't be interpolated until the final
+ # HTML that may have embedded ERB will be parsed, but it shouldn't be interpolated until the final
# render, i.e. when view_assigns are available via the controller.
class ErbString < String
View
8 spec/fixtures/content/fixture_site/views/layouts/fixture_site_layout.html.erb
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ </head>
+ <body>
+ <%= yield :page_template %>
+ </body>
+</html>
View
5 spec/fixtures/content/fixture_site/views/page_templates/default_page_template.html.erb
@@ -0,0 +1,5 @@
+<div id="page_template_default">
+ <div id="content">
+ <%= yield :page %>
+ </div>
+</div>
View
26 spec/fixtures/content/fixture_site/views/pages/test_page.html
@@ -0,0 +1,26 @@
+<div>
+ <div id="caloris-metadata">
+ <div data-name="page_id" data-content="test_page_page_id"></div>
+ <div data-name="page_title" data-content="Test Page Page Title"></div>
+ <div data-name="description" data-content="Test Page description"></div>
+ <div data-name="published" data-scheme="boolean" data-content="true"></div>
+ <div data-name="page_template" data-content="default_page_template"></div>
+ </div>
+ <div class="caloris-content">
+ <div class="mercury-region" data-type="editable" id="edit-region-1">
+ plain text
+ </div>
+ <div class="mercury-region" data-type="editable" id="edit-region-2">
+ <ul>
+ <li>Bullet one</li>
+ <li><a href="#">Bullet two, link</a></li>
+ <li>
+ Bullet three, separate lines
+ </li>
+ <li>Bullet with a bunch of non-alpha characters "!@#$%^*()_+-=;':"[]\{}|`~,./?</li>
+ </ul>
+ <p>Ampersand & handled</p>
+ <span>&nbsp;</span>
+ </div>
+ </div>
+</div>
View
36 spec/fixtures/content/fixture_site/views/pages/test_page_rendered.txt
@@ -0,0 +1,36 @@
+<% content_for :page do %>
+<div class="mercury-region" data-type="editable" id="edit-region-1">
+ plain text
+</div>
+<div class="mercury-region" data-type="editable" id="edit-region-2">
+ <ul>
+ <li>Bullet one
+ </li>
+ <li>
+ <a href="#">Bullet two, link</a>
+ </li>
+ <li>Bullet three, separate lines
+ </li>
+ <li>Bullet with a bunch of non-alpha characters "!@#$%^*()_+-=;':"[]\{}|`~,./?
+ </li>
+ </ul>
+ <p>
+ Ampersand &amp; handled
+ </p><span>&nbsp;</span>
+</div>
+<% end %>
+<% content_for :page_template do %>
+<div id="page_template_default">
+ <div id="content">
+ <%= yield :page %>
+ </div>
+</div>
+<% end %>
+<!DOCTYPE html>
+<html>
+ <head>
+ </head>
+ <body>
+ <%= yield :page_template %>
+ </body>
+</html>
View
0 spec/fixtures/templates/simple.html → spec/fixtures/pages/simple.html
File renamed without changes.
View
0 spec/fixtures/templates/ugly.html → spec/fixtures/pages/ugly.html
File renamed without changes.
View
0 spec/fixtures/templates/ugly.tidied.html → spec/fixtures/pages/ugly.tidied.html
File renamed without changes.
View
48 spec/models/caloris/page_spec.rb
@@ -4,16 +4,50 @@ module Caloris
describe Page do
+ describe :render_tidy do
+ it "renders HTML" do
+ page = Page.new nil, {}, "test.html" do
+ File.read(File.join(Caloris.root, 'spec/fixtures/pages/simple.html'))
+ end
+ page.send(:render_tidy).should == "<p>\n Simple text\n</p>\n"
+ end
+
+ it "tidies ugly HTML" do
+ page = Page.new nil, {}, "ugly.html" do
+ File.read(File.join(Caloris.root, 'spec/fixtures/pages/ugly.html'))
+ end
+ page.send(:render_tidy).should == File.read(File.join(Caloris.root, 'spec/fixtures/pages/ugly.tidied.html'))
+ end
+ end
- it "renders HTML" do
- page = Page.new(nil, "test.html") { File.read(File.join(Caloris.root, 'spec/fixtures/templates/simple.html')) }
- page.send(:render_tidy).should == "<p>\n Simple text\n</p>\n"
- end
+ describe ContentPage do
+
+ context "for test_page.html" do
+
+ before do
+ @site = Caloris::Site.new do |config|
+ config.name = "fixture_site"
+ config.default_layout = "fixture_site_layout"
+ config.root = File.join(Caloris.root, 'spec/fixtures/content')
+ end
+
+ @page = @site.create_page({}, "test_page.html")
+ end
+
+ it "renders" do
+ html = File.read(File.join(Caloris.root, 'spec/fixtures/content/fixture_site/views/pages/test_page_rendered.txt'))
+ @page.render.should == html
+ end
+
+ it "renders the same after a null update" do
+ html = @page.render
+ @page.update({})
+ @page.render.should == html
+ end
+
+ end
- it "tidies ugly HTML" do
- page = Page.new(nil, "ugly.html") { File.read(File.join(Caloris.root, 'spec/fixtures/templates/ugly.html')) }
- page.send(:render_tidy).should == File.read(File.join(Caloris.root, 'spec/fixtures/templates/ugly.tidied.html'))
end
end

0 comments on commit d51f57d

Please sign in to comment.
Something went wrong with that request. Please try again.