Adding MultiPart Page Rendering scenario. Some refactoring also:

- page step language is a bit more readable
- avoid over using factories. objects created naturally are always preferred!
This commit is contained in:
Jacques Crocker 2010-08-01 14:36:11 -07:00
parent 08c0d270e0
commit ad38eb53a8
3 changed files with 85 additions and 26 deletions

View File

@ -6,7 +6,7 @@ Background:
Given I have the site: "test site" set up
Scenario: Simple Page
Given I have a simple page at "hello-world" with the body:
Given a simple page named "hello-world" with the body:
"""
Hello World
"""
@ -17,14 +17,14 @@ Scenario: Simple Page
"""
Scenario: Simple Page with layout
Given a layout named "above_and_below" with the body:
"""
<div class="up_above"></div>
{{ content_for_layout }}
<div class="down_below"></div>
"""
Given a layout named "above_and_below" with the source:
"""
<div class="header"></div>
{{ content_for_layout }}
<div class="footer"></div>
"""
And I have a simple page at "/hello-world-with-layout" with the layout "above_and_below" and the body:
And a page named "hello-world-with-layout" with the layout "above_and_below" and the body:
"""
Hello World
"""
@ -32,12 +32,42 @@ Scenario: Simple Page with layout
When I view the rendered page at "/hello-world-with-layout"
Then the rendered output should look like:
"""
<div class="up_above"></div>
<div class="header"></div>
Hello World
<div class="down_below"></div>
<div class="footer"></div>
"""
Scenario: Layout with Parts
Scenario: Page with Parts
Given a layout named "layout_with_sidebar" with the source:
"""
<div class="header"></div>
<div class="content">
<div class="sidebar">{{ content_for_sidebar }}</div>
<div class="body">
{{ content_for_layout }}
</div>
</div>
<div class="footer"></div>
"""
And a page named "hello-world-multipart" with the layout "layout_with_sidebar" and the body:
"""
IM IN UR BODY OUTPUTTING SUM CODEZ!!
"""
And the page named "hello-world-multipart" has the part "sidebar" with the content:
"""
IM IN UR SIDEBAR PUTTING OUT LINKZ
"""
When I view the rendered page at "/hello-world-multipart"
Then the rendered output should look like:
"""
<div class="header"></div>
<div class="content">
<div class="sidebar">IM IN UR SIDEBAR PUTTING OUT LINKZ</div>
<div class="body">
IM IN UR BODY OUTPUTTING SUM CODEZ!!
</div>
</div>
<div class="footer"></div>
"""

View File

@ -1,20 +1,56 @@
### Pages
Given /^I have a simple page at "([^"]*)" with the body:$/ do |page_slug, page_contents|
@page = Factory("content page", :slug => page_slug, :body => page_contents, :site => @site)
# helps create a simple content page (parent: "index") with a slug, contents, and layout
def create_content_page(page_slug, page_contents, layout = nil)
@home = @site.pages.where(:slug => "index").first || Factory(:page)
page = @site.pages.create(:slug => page_slug, :body => page_contents, :layout => layout, :parent => @home, :title => "some title", :published => true)
page.should be_valid
page
end
Given /^I have a simple page at "([^"]*)" with the layout "([^"]*)" and the body:$/ do |page_slug, layout_name, page_contents|
# creates a page
Given /^a simple page named "([^"]*)" with the body:$/ do |page_slug, page_contents|
@page = create_content_page(page_slug, page_contents)
end
# creates a page (that has a layout)
Given /^a page named "([^"]*)" with the layout "([^"]*)" and the body:$/ do |page_slug, layout_name, page_contents|
layout = @site.layouts.where(:name => layout_name).first
raise "Could not find layout: #{layout_name}" unless layout
@page = Factory("content page", :slug => page_slug, :layout => layout, :body => page_contents, :site => @site)
@page = create_content_page(page_slug, page_contents, layout)
end
When /^I view the rendered page at "([^"]*)"$/ do |slug|
visit "http://#{@site.domains.first}/#{slug}"
# creates a layout
Given /^a layout named "([^"]*)" with the source:$/ do |layout_name, layout_body|
@layout = Factory(:layout, :name => layout_name, :value => layout_body, :site => @site)
end
# creates a part within a page
Given /^the page named "([^"]*)" has the part "([^"]*)" with the content:$/ do |page_slug, part_slug, part_contents|
page = @site.pages.where(:slug => page_slug).first
raise "Could not find page: #{page_slug}" unless page
# find or crate page part
part = page.parts.where(:slug => part_slug).first
unless part
part = page.parts.build(:name => part_slug.titleize, :slug => part_slug)
end
# set part value
part.value = part_contents
part.should be_valid
# save page with embedded part
page.save
end
# try to render a page by slug
When /^I view the rendered page at "([^"]*)"$/ do |path|
visit "http://#{@site.domains.first}#{path}"
end
# checks to see if a string is in the slug
Then /^I should have "(.*)" in the (.*) page (.*)$/ do |content, page_slug, part_slug|
page = @site.pages.where(:slug => page_slug).first
raise "Could not find page: #{page_slug}" unless page
@ -25,11 +61,9 @@ Then /^I should have "(.*)" in the (.*) page (.*)$/ do |content, page_slug, part
part.value.should == content
end
# checks if the rendered body matches a string
Then /^the rendered output should look like:$/ do |body_contents|
page.body.should == body_contents
end
Given /^a layout named "([^"]*)" with the body:$/ do |layout_name, layout_body|
@layout = Factory(:layout, :name => layout_name, :value => layout_body, :site => @site)
end

View File

@ -55,11 +55,6 @@ Factory.define :page do |p|
p.site { Site.where(:subdomain => "acme").first || Factory(:site) }
end
Factory.define "content page", :parent => :page do |p|
p.parent { |p| p.site.pages.where(:slug => "index").first }
end
# Factory.define "unpub"