2010-08-01 11:14:00 +00:00
|
|
|
### Pages
|
|
|
|
|
2010-08-21 22:48:24 +00:00
|
|
|
# helps create a simple content page (parent: "index") with a slug, contents, and template
|
2010-08-16 22:07:54 +00:00
|
|
|
def create_content_page(page_slug, page_contents, template = nil)
|
2010-08-01 21:36:11 +00:00
|
|
|
@home = @site.pages.where(:slug => "index").first || Factory(:page)
|
2010-08-21 22:48:24 +00:00
|
|
|
page = @site.pages.create(:slug => page_slug, :body => page_contents, :parent => @home, :title => "some title", :published => true, :raw_template => template)
|
2010-08-01 21:36:11 +00:00
|
|
|
page.should be_valid
|
|
|
|
page
|
2010-08-01 20:52:24 +00:00
|
|
|
end
|
|
|
|
|
2010-08-01 21:36:11 +00:00
|
|
|
# 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
|
|
|
|
|
2010-08-08 11:30:27 +00:00
|
|
|
Given /^a page named "([^"]*)" with the template:$/ do |page_slug, template|
|
2010-08-16 22:07:54 +00:00
|
|
|
@page = create_content_page(page_slug, '', template)
|
2010-08-08 11:30:27 +00:00
|
|
|
end
|
|
|
|
|
2010-08-20 15:56:15 +00:00
|
|
|
# # 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
|
2010-08-01 21:36:11 +00:00
|
|
|
|
2010-08-26 11:06:44 +00:00
|
|
|
|
|
|
|
# update a page
|
|
|
|
When /^I update the "([^"]*)" page with the template:$/ do |page_slug, template|
|
|
|
|
page = @site.pages.where(:slug => page_slug).first
|
2010-08-27 15:40:03 +00:00
|
|
|
page.raw_template = template
|
|
|
|
page.save!
|
2010-08-26 11:06:44 +00:00
|
|
|
end
|
|
|
|
|
2010-08-01 21:36:11 +00:00
|
|
|
# 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
|
2010-08-20 16:24:59 +00:00
|
|
|
Then /^I should have "(.*)" in the (.*) page$/ do |content, page_slug|
|
2010-08-01 11:14:00 +00:00
|
|
|
page = @site.pages.where(:slug => page_slug).first
|
2010-08-01 20:52:24 +00:00
|
|
|
raise "Could not find page: #{page_slug}" unless page
|
|
|
|
|
2010-08-21 22:48:24 +00:00
|
|
|
page.raw_template.should == content
|
2010-08-01 11:14:00 +00:00
|
|
|
end
|
|
|
|
|
2010-08-01 21:36:11 +00:00
|
|
|
# checks if the rendered body matches a string
|
2010-08-01 11:14:00 +00:00
|
|
|
Then /^the rendered output should look like:$/ do |body_contents|
|
|
|
|
page.body.should == body_contents
|
|
|
|
end
|
2010-08-01 20:52:24 +00:00
|
|
|
|
|
|
|
|