1 class HomePageScenario < Scenario::Base
4 create_page "Home", :slug => "/", :parent_id => nil do
5 create_page_part "body", :content => "Hello world!"
6 create_page_part "sidebar", :content => "<r:title /> sidebar."
7 create_page_part "extended", :content => "Just a test."
8 create_page_part "titles", :content => "<r:title /> <r:page:title />"
13 def create_page(name, attributes={})
14 attributes = page_params(attributes.reverse_merge(:title => name))
15 body = attributes.delete(:body) || name
16 symbol = name.symbolize
17 create_record :page, symbol, attributes
19 old_page_id = @current_page_id
20 @current_page_id = page_id(symbol)
22 @current_page_id = old_page_id
24 if pages(symbol).parts.empty?
25 create_page_part "#{name}_body".symbolize, :name => "body", :content => body + ' body.', :page_id => page_id(symbol)
28 def page_params(attributes={})
29 title = attributes[:title] || unique_page_title
33 :slug => title.symbolize.to_s.gsub("_", "-"),
35 :status_id => Status[:published].id,
36 :published_at => Time.now.to_s(:db)
38 attributes[:parent_id] = @current_page_id || page_id(:home) unless attributes.has_key?(:parent_id)
42 def create_page_part(name, attributes={})
43 attributes = page_part_params(attributes.reverse_merge(:name => name))
44 create_record :page_part, name.symbolize, attributes
46 def page_part_params(attributes={})
47 name = attributes[:name] || "unnamed"
51 :page_id => @current_page_id
56 @@unique_page_title_call_count = 0
58 @@unique_page_title_call_count += 1
59 "Page #{@@unique_page_title_call_count}"