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:
parent
08c0d270e0
commit
ad38eb53a8
@ -6,7 +6,7 @@ Background:
|
|||||||
Given I have the site: "test site" set up
|
Given I have the site: "test site" set up
|
||||||
|
|
||||||
Scenario: Simple Page
|
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
|
Hello World
|
||||||
"""
|
"""
|
||||||
@ -17,14 +17,14 @@ Scenario: Simple Page
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
Scenario: Simple Page with layout
|
Scenario: Simple Page with layout
|
||||||
Given a layout named "above_and_below" with the body:
|
Given a layout named "above_and_below" with the source:
|
||||||
"""
|
"""
|
||||||
<div class="up_above"></div>
|
<div class="header"></div>
|
||||||
{{ content_for_layout }}
|
{{ content_for_layout }}
|
||||||
<div class="down_below"></div>
|
<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
|
Hello World
|
||||||
"""
|
"""
|
||||||
@ -32,12 +32,42 @@ Scenario: Simple Page with layout
|
|||||||
When I view the rendered page at "/hello-world-with-layout"
|
When I view the rendered page at "/hello-world-with-layout"
|
||||||
Then the rendered output should look like:
|
Then the rendered output should look like:
|
||||||
"""
|
"""
|
||||||
<div class="up_above"></div>
|
<div class="header"></div>
|
||||||
Hello World
|
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>
|
||||||
|
"""
|
||||||
|
@ -1,20 +1,56 @@
|
|||||||
### Pages
|
### Pages
|
||||||
|
|
||||||
Given /^I have a simple page at "([^"]*)" with the body:$/ do |page_slug, page_contents|
|
# helps create a simple content page (parent: "index") with a slug, contents, and layout
|
||||||
@page = Factory("content page", :slug => page_slug, :body => page_contents, :site => @site)
|
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
|
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
|
layout = @site.layouts.where(:name => layout_name).first
|
||||||
raise "Could not find layout: #{layout_name}" unless layout
|
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
|
end
|
||||||
|
|
||||||
When /^I view the rendered page at "([^"]*)"$/ do |slug|
|
# creates a layout
|
||||||
visit "http://#{@site.domains.first}/#{slug}"
|
Given /^a layout named "([^"]*)" with the source:$/ do |layout_name, layout_body|
|
||||||
|
@layout = Factory(:layout, :name => layout_name, :value => layout_body, :site => @site)
|
||||||
end
|
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|
|
Then /^I should have "(.*)" in the (.*) page (.*)$/ do |content, page_slug, part_slug|
|
||||||
page = @site.pages.where(:slug => page_slug).first
|
page = @site.pages.where(:slug => page_slug).first
|
||||||
raise "Could not find page: #{page_slug}" unless page
|
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
|
part.value.should == content
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# checks if the rendered body matches a string
|
||||||
Then /^the rendered output should look like:$/ do |body_contents|
|
Then /^the rendered output should look like:$/ do |body_contents|
|
||||||
page.body.should == body_contents
|
page.body.should == body_contents
|
||||||
end
|
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
|
|
||||||
|
|
||||||
|
@ -55,11 +55,6 @@ Factory.define :page do |p|
|
|||||||
p.site { Site.where(:subdomain => "acme").first || Factory(:site) }
|
p.site { Site.where(:subdomain => "acme").first || Factory(:site) }
|
||||||
end
|
end
|
||||||
|
|
||||||
Factory.define "content page", :parent => :page do |p|
|
|
||||||
p.parent { |p| p.site.pages.where(:slug => "index").first }
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Factory.define "unpub"
|
# Factory.define "unpub"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user