Renamed helpers to correspond to renamed Controller classes.
[merb_radiant.git] / radiant_specs / spec / scenarios / .svn / text-base / home_page_scenario.rb.svn-base
blob6ec8e6ea5356fc2411eeec38e312b7b1a68f4e14
1 class HomePageScenario < Scenario::Base
2   
3   def load
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 />"
9     end
10   end
11   
12   helpers do
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
18       if block_given?
19         old_page_id = @current_page_id
20         @current_page_id = page_id(symbol)
21         yield
22         @current_page_id = old_page_id
23       end
24       if pages(symbol).parts.empty?
25         create_page_part "#{name}_body".symbolize, :name => "body", :content => body + ' body.', :page_id => page_id(symbol)
26       end
27     end
28     def page_params(attributes={})
29       title = attributes[:title] || unique_page_title
30       attributes = {
31         :title => title,
32         :breadcrumb => title,
33         :slug => title.symbolize.to_s.gsub("_", "-"),
34         :class_name => nil,
35         :status_id => Status[:published].id,
36         :published_at => Time.now.to_s(:db)
37       }.update(attributes)
38       attributes[:parent_id] = @current_page_id || page_id(:home) unless attributes.has_key?(:parent_id)
39       attributes
40     end
41     
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
45     end
46     def page_part_params(attributes={})
47       name = attributes[:name] || "unnamed"
48       attributes = {
49         :name => name,
50         :content => name,
51         :page_id => @current_page_id
52       }.update(attributes)
53     end
54     
55     private
56       @@unique_page_title_call_count = 0
57       def unique_page_title
58         @@unique_page_title_call_count += 1
59         "Page #{@@unique_page_title_call_count}"
60       end
61   end
62 end