Changeset 126

Show
Ignore:
Timestamp:
09/27/06 16:32:28 (2 years ago)
Author:
jlong
Message:

mental branch: removed behaviors

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/mental/radiant/app/controllers/admin/page_controller.rb

    r57 r126  
    11class Admin::PageController < ApplicationController 
     2   
    23  model :page 
    34   
  • branches/mental/radiant/app/models/page.rb

    r64 r126  
    1 require_dependency 'advanced_delegation
     1require_dependency 'annotatable
    22 
    33class Page < ActiveRecord::Base 
     
    88   
    99  # Callbacks 
    10   before_save :update_published_at, :update_virtual 
     10  before_save :update_published_at, :update_virtual, :update_type 
    1111   
    1212  # Associations 
     
    2323  validates_length_of :slug, :maximum => 100, :message => '%d-character limit' 
    2424  validates_length_of :breadcrumb, :maximum => 160, :message => '%d-character limit' 
    25   validates_length_of :behavior_id, :maximum => 25, :allow_nil => true, :message => '%d-character limit' 
    2625   
    2726  validates_format_of :slug, :with => %r{^([-_.A-Za-z0-9]*|/)$}, :message => 'invalid format'   
     
    2928  validates_numericality_of :id, :status_id, :parent_id, :allow_nil => true, :only_integer => true, :message => 'must be a number' 
    3029   
    31   delegate_to :behavior, :url => :page_url, :cache? => :cache_page?, :find_by_url => :find_page_by_url, 
    32      :render => :render_page, :virtual? => :page_virtual? 
    33    
    34   delegate_to :behavior, :process, :child_url 
     30  include Annotatable 
     31  annotate :description 
     32   
     33  include InheritableClassAttributes 
     34  cattr_inheritable_reader :additional_tag_definition_blocks 
     35  @additional_tag_definition_blocks = [] 
     36  cattr_inheritable_reader :additional_child_tag_definition_blocks 
     37  @additional_child_tag_definition_blocks = [] 
     38   
     39  attr_accessor :request, :response, :ptype 
    3540   
    3641  def after_initialize 
     
    4247  end 
    4348   
     49  def cache? 
     50    true 
     51  end 
     52   
     53  def child_url(child) 
     54    clean_url(url + '/' + child.slug) 
     55  end 
     56   
     57  def config 
     58    string = render_part(:config) 
     59    unless string.empty? 
     60      YAML::load(string) 
     61    else 
     62      {} 
     63    end 
     64  end 
     65   
     66  def headers 
     67    { 'Status' => ActionController::Base::DEFAULT_RENDER_STATUS_CODE } 
     68  end 
     69   
    4470  def part(name) 
    4571    parts.find_by_name name.to_s 
    4672  end 
    4773   
     74  def ptype 
     75    @ptype ||= read_attribute('type').to_s 
     76  end 
     77   
     78  def published? 
     79    status == Status[:published] 
     80  end 
     81   
    4882  def status 
    4983    Status.find(self.status_id) 
    5084  end 
    51    
    5285  def status=(value) 
    5386    self.status_id = value.id 
    5487  end 
    5588   
    56   def published? 
    57     status == Status[:published] 
    58   end 
    59    
    60   def behavior 
    61     if @behavior.nil? or (@old_behavior_id != behavior_id) 
    62       @old_behavior_id = behavior_id 
    63       @behavior = Behavior[behavior_id].new(self) 
    64     else 
    65       @behavior 
    66     end 
    67   end 
    68    
    69   def self.find_by_url(url, live = true) 
    70     root = find_by_parent_id(nil) 
    71     raise MissingRootPageError unless root 
    72     root.find_by_url(url, live) 
    73   end 
    74    
    7589  def virtual 
    7690    !(read_attribute('virtual').to_s =~ /^(false|f|0|)$/) 
     91  end 
     92   
     93  def url 
     94    if parent? 
     95      parent.child_url(self) 
     96    else 
     97      clean_url(slug) 
     98    end 
     99  end 
     100   
     101  def process(request, response) 
     102    @request, @response = request, response 
     103    if layout 
     104      content_type = layout.content_type.to_s.strip 
     105      @response.headers['Content-Type'] = content_type unless content_type.empty? 
     106    end 
     107    headers.each { |k,v| @response.headers[k] = v } 
     108    @response.body = render 
     109    @request, @response = nil, nil 
     110  end 
     111   
     112  def render 
     113    lazy_initialize_parser_and_context 
     114    if layout 
     115      parse_object(layout) 
     116    else 
     117      render_part(:body) 
     118    end 
     119  end 
     120   
     121  def render_part(part_name) 
     122    lazy_initialize_parser_and_context 
     123    part = part(part_name) 
     124    if part 
     125      parse_object(part) 
     126    else 
     127      '' 
     128    end 
     129  end 
     130   
     131  def render_snippet(snippet) 
     132    lazy_initialize_parser_and_context 
     133    parse_object(snippet) 
     134  end 
     135   
     136  def render_text(text) 
     137    lazy_initialize_parser_and_context 
     138    parse(text) 
     139  end 
     140   
     141  def find_by_url(url, live = true, clean = true) 
     142    url = clean_url(url) if clean 
     143    if (self.url == url) && (not live or published?) 
     144      self 
     145    else 
     146      children.each do |child| 
     147        if (url =~ Regexp.compile( '^' + Regexp.quote(child.url))) and (not child.virtual?) 
     148          found = child.find_by_url(url, live, clean) 
     149          return found if found 
     150        end 
     151      end 
     152      children.find(:first, :conditions => "type = 'FileNotFoundPage'") 
     153    end 
     154  end 
     155   
     156  class << self 
     157    def find_by_url(url, live = true) 
     158      root = find_by_parent_id(nil) 
     159      raise MissingRootPageError unless root 
     160      root.find_by_url(url, live) 
     161    end 
     162 
     163    def define_tags(&block) 
     164      @additional_tag_definition_blocks << block 
     165    end 
     166     
     167    # def define_child_tags(&block) 
     168    #   @additional_child_tag_definition_blocks << block 
     169    # end 
     170     
     171    def display_name(string = nil) 
     172      if string 
     173        @display_name = string 
     174      else 
     175        @display_name ||= begin 
     176          n = name.to_s 
     177          n.sub!(/^(.+?)Page$/, '\1') 
     178          n.gsub!(/([A-Z])/, ' \1') 
     179          n.strip 
     180        end 
     181      end 
     182    end 
     183    def display_name=(string) 
     184      display_name(string) 
     185    end 
     186     
     187    @@descendants = [] 
     188    def descendants 
     189      @@descendants.dup 
     190    end 
     191     
     192    def inherited_with_descendants(subclass) 
     193      inherited_without_descendants(subclass) 
     194      @@descendants << subclass 
     195    end 
     196    alias :inherited_without_descendants :inherited 
     197    alias :inherited :inherited_with_descendants 
     198     
    77199  end 
    78200   
     
    83205      true 
    84206    end 
    85    
     207     
    86208    def update_virtual 
    87209      write_attribute('virtual', virtual?) 
    88210      true 
    89211    end 
     212     
     213    def update_type 
     214      write_attribute('type', ptype) 
     215      true 
     216    end 
     217     
     218    # def update_file_not_found 
     219    #   write_attribute('file_not_found', file_not_found?) 
     220    #   true 
     221    # end 
     222     
     223    def clean_url(url) 
     224      "/#{ url.strip }/".gsub(%r{//+}, '/')  
     225    end 
     226     
     227    def parent? 
     228      !parent.nil? 
     229    end 
     230     
     231    def lazy_initialize_parser_and_context 
     232      unless @context and @parser 
     233        @context = PageContext.new(self) 
     234        self.class.additional_tag_definition_blocks.each { |block| instance_eval &block } 
     235        @parser = Radius::Parser.new(@context, :tag_prefix => 'r') 
     236      end 
     237    end 
     238     
     239    def parse(text) 
     240      @parser.parse(text) 
     241    end 
     242     
     243    def parse_object(object) 
     244      text = object.content 
     245      text = parse(text) 
     246      text = object.filter.filter(text) if object.respond_to? :filter_id 
     247      text 
     248    end 
     249     
     250    def tag(*args, &block) 
     251      @context.define_tag(*args, &block) 
     252    end 
    90253   
    91254end 
  • branches/mental/radiant/app/models/page_context.rb

    r105 r126  
    1010    globals.page = @page 
    1111 
     12    # 
    1213    # <r:page>...</r:page> 
    1314    # 
     
    2425    # etc... 
    2526    # 
    26     ((@page.attributes.symbolize_keys.keys + [:url]) - [:created_by, :updated_by]).each do |method| 
     27    ((@page.attributes.symbolize_keys.keys + [:url]) - [:type, :created_by, :updated_by]).each do |method| 
    2728      define_tag(method.to_s) do |tag| 
    2829        tag.locals.page.send(method) 
     
    210211      if inherit and contextual 
    211212        part = part_page.part(part_name) 
    212         page.behavior.render_snippet(part) unless part.nil? 
     213        page.render_snippet(part) unless part.nil? 
    213214      else 
    214         part_page.behavior.render_page_part(part_name) 
     215        part_page.render_part(part_name) 
    215216      end 
    216217    end 
     
    346347        if snippet = Snippet.find_by_name(name.strip) 
    347348          page = tag.locals.page 
    348           page.behavior.render_snippet(snippet) 
     349          page.render_snippet(snippet) 
    349350        else 
    350351          raise TagError.new('snippet not found') 
     
    516517      ActiveRecord::Base.connection.adapter_name =~ /postgres/i 
    517518    end 
     519     
    518520    def build_regexp_for(tag,attribute_name) 
    519521      ignore_case = tag.attr.has_key?('ignore_case') && tag.attr['ignore_case']=='false' ? nil : true 
  • branches/mental/radiant/app/views/admin/page/_node.rhtml

    r84 r126  
    1515title = %{<span class="title">#{ page.title }</span>} 
    1616 
    17 behavior_id = page.behavior_id.to_s.strip 
    18 behavior = behavior_id.empty? ? '' : %{<small class="info">(#{ behavior_id })</small>} 
     17display_name = page.class.display_name 
     18page_type = display_name == 'Page' ? '' : %{<small class="info">(#{ display_name })</small>} 
    1919 
    2020spinner = image_tag("spinner.gif", :class => 'busy', :id => "busy-#{page.id}", :alt => "", :title => "", :align => "center", :style => 'display: none;') 
     
    2828<% else -%> 
    2929          <%= expander %><a href="<%= page_edit_url(:id => page) %>"><%= icon %> <%= title %></a>  
    30           <%= behavior %> 
     30          <%= page_type %> 
    3131          <%= spinner %> 
    3232<% end -%> 
  • branches/mental/radiant/app/views/admin/page/new.rhtml

    r61 r126  
    127127      <p><label for="page_layout_id">Layout</label> 
    128128        <%= select "page", "layout_id", [['<inherit>', '']] + Layout.find_all.map { |s| [s.name, s.id] } %></p> 
    129       <p><label for="page_behavior">Behavior</label> 
    130         <%= select "page", "behavior_id", [['<none>', '']] + Behavior.find_all.map { |s| s.registered_id } %></p> 
     129      <p><label for="page_ptype">Page Type</label> 
     130        <%= select "page", "ptype", [['<normal>', 'Page']] + Page.descendants.map { |p| [p.display_name, p.name] }.sort_by { |p| p.first } %></p> 
    131131      <p><label for="page_status_id">Status</label> 
    132132        <%= select "page", "status_id", Status.find_all.map { |s| [s.name, s.id] } %></p> 
  • branches/mental/radiant/config/environment.rb

    r98 r126  
    6565 
    6666# Auto-require behaviors 
    67 Dir["#{RADIANT_ROOT}/app/behaviors/*_behavior.rb"].each do |behavior| 
    68   require_dependency behavior 
     67Dir["#{RADIANT_ROOT}/app/models/*_page.rb"].each do |page| 
     68  page = $1 if page =~ %r{/([^/]*)\.rb} 
     69  require_dependency page 
    6970end 
    7071 
  • branches/mental/radiant/db/development_structure.sql

    r19 r126  
    1111  `name` varchar(100) default NULL, 
    1212  `content` text, 
     13  `content_type` varchar(40) default NULL, 
    1314  `created_at` datetime default NULL, 
    1415  `updated_at` datetime default NULL, 
     
    3435  `parent_id` int(11) default NULL, 
    3536  `layout_id` int(11) default NULL, 
    36   `behavior_id` varchar(25) default NULL, 
     37  `type` varchar(25) default NULL, 
    3738  `status_id` int(11) NOT NULL default '1', 
    3839  `created_at` datetime default NULL, 
     
    7879) ENGINE=InnoDB DEFAULT CHARSET=latin1; 
    7980 
    80 INSERT INTO schema_info (version) VALUES (8
     81INSERT INTO schema_info (version) VALUES (10
  • branches/mental/radiant/db/schema.rb

    r95 r126  
    33# then regenerate this schema definition. 
    44 
    5 ActiveRecord::Schema.define(:version => 9) do 
     5ActiveRecord::Schema.define(:version => 10) do 
    66 
    77  create_table "config", :force => true do |t| 
     
    3535    t.column "parent_id", :integer 
    3636    t.column "layout_id", :integer 
    37     t.column "behavior_id", :string, :limit => 25 
     37    t.column "type", :string, :limit => 25 
    3838    t.column "status_id", :integer, :default => 1, :null => false 
    3939    t.column "created_at", :datetime 
  • branches/mental/radiant/lib/inheritable_class_attributes.rb

    r1 r126  
    4949     
    5050    def inherited_with_inheritable_class_attributes(klass) 
    51       inherited_without_inheritable_class_attributes(child) if respond_to?(:inherited_without_inheritable_class_attributes) 
     51      inherited_without_inheritable_class_attributes(klass) if respond_to?(:inherited_without_inheritable_class_attributes) 
    5252       
    5353      readers = inheritable_cattr_readers.dup 
  • branches/mental/radiant/test/fixtures/pages.yml

    r91 r126  
    9999  breadcrumb: Parent 
    100100  slug: archive 
    101   behavior_id: Archiv
     101  type: ArchivePag
    102102  status_id: 100 
    103103  parent_id: 1 
     
    107107  title: %Y Archive 
    108108  slug: year 
    109   behavior_id: Archive Year Index 
     109  type: ArchiveYearIndexPage 
    110110  status_id: 101 
    111111  parent_id: 12 
     
    116116  title: %B %Y Archive 
    117117  slug: month 
    118   behavior_id: Archive Month Index 
     118  type: ArchiveMonthIndexPage 
    119119  status_id: 101 
    120120  parent_id: 12 
     
    125125  title: %B %d, %Y Archive 
    126126  slug: day 
    127   behavior_id: Archive Day Index 
     127  type: ArchiveDayIndexPage 
    128128  status_id: 101 
    129129  parent_id: 12 
     
    198198  status_id: 100 
    199199  parent_id: 1 
    200   behavior_id: No Cach
     200  type: NoCachePag
    201201assorted: 
    202202  id: 19 
     
    262262  parent_id: 33 
    263263  published_at: 2006-02-05 08:44:07  
    264 custom_tags
     264test_page
    265265  id: 35 
    266   title: Custom Tags 
    267   slug: custom-tags 
    268   behavior_id: Test Behavior 
     266  title: Test Page 
     267  slug: test-page 
     268  type: TestPage 
    269269  status_id: 100 
    270270  parent_id: 1 
     
    319319  parent_id: 1 
    320320  published_at: 2006-02-05 08:44:07  
    321 missing
     321file_not_found
    322322  id: 51 
    323323  title: File Not Found 
    324324  slug: missing 
    325   behavior_id: Page Missing 
     325  type: FileNotFoundPage 
    326326  status_id: 100 
    327327  parent_id: 50 
  • branches/mental/radiant/test/functional/site_controller_test.rb

    r93 r126  
    77class SiteControllerTest < Test::Unit::TestCase 
    88  fixtures :pages, :page_parts 
    9   test_helper :behavior 
     9  test_helper :pages 
    1010   
    1111  def setup 
  • branches/mental/radiant/test/helpers/archive_index_test_helper.rb

    r51 r126  
    11module ArchiveIndexTestHelper 
    22  module ArchiveIndexTests 
     3     
    34    def test_page_virtual? 
    45      assert_equal true, @page.virtual? 
     
    3233      assert_renders 'Friday', '<r:archive:day_of_week />', '/archive/2000/06/09/' 
    3334    end 
     35     
    3436  end 
    3537end 
  • branches/mental/radiant/test/helpers/page_test_helper.rb

    r1 r126  
     1class NoCachePage < Page 
     2  description 'Turns caching off for testing.' 
     3   
     4  def cache? 
     5    false 
     6  end 
     7end 
     8 
     9class TestPage < Page 
     10  description 'this is just a test page' 
     11   
     12  define_tags do 
     13    tag 'test1' do 
     14      'Hello world!' 
     15    end 
     16  end 
     17   
     18  define_tags do 
     19    tag 'test2' do 
     20      'Another test.' 
     21    end 
     22  end 
     23   
     24  def headers 
     25    { 
     26      'cool' => 'beans', 
     27      'request' => @request.inspect[20..30], 
     28      'response' => @response.inspect[20..31] 
     29    } 
     30  end 
     31   
     32end 
     33 
    134module PageTestHelper 
     35   
    236  VALID_PAGE_PARAMS = { 
    337    :title => 'New Page', 
     
    2761  def create_test_page(options = {}) 
    2862    options[:title] ||= @page_title 
    29     page = Page.new page_params(options) 
     63    klass = options.delete(:type) || Page 
     64    page = klass.new page_params(options) 
    3065    if page.save 
    3166      page 
  • branches/mental/radiant/test/unit/page_context_test.rb

    r92 r126  
    33class PageContextTest < Test::Unit::TestCase 
    44  fixtures :pages, :page_parts, :layouts, :snippets, :users 
     5  test_helper :pages 
    56   
    67  def setup 
     
    1920  def test_tags_page_attributes 
    2021    @page.attributes.keys.each do |attr| 
    21       value = @page.send(attr) 
    22       unless [:created_by, :updated_by].include? attr.to_s.intern 
     22      unless [:type, :created_by, :updated_by].include? attr.to_s.intern 
     23        value = @page.send(attr) 
    2324        assert_parse_output value.to_s, "<r:#{attr} />" 
    2425      end 
  • branches/mental/radiant/test/unit/page_test.rb

    r69 r126  
    22 
    33class PageTest < Test::Unit::TestCase 
    4   fixtures :users, :pages, :page_parts, :layouts 
    5   test_helper :pages, :page_parts, :validations 
     4  fixtures :users, :pages, :page_parts, :snippets, :layouts 
     5  test_helper :pages, :page_parts, :validations, :render 
    66 
    77  def setup 
     
    1313     
    1414    @page = @model = Page.new(VALID_PAGE_PARAMS) 
     15     
     16    @request = ActionController::TestRequest.new :url => '/page/' 
     17    @response = ActionController::TestResponse.new 
    1518  end 
    1619   
     
    1922      :title => 255, 
    2023      :slug => 100, 
    21       :breadcrumb => 160, 
    22       :behavior_id => 25 
     24      :breadcrumb => 160 
    2325    }.each do |field, max| 
    2426      assert_invalid field, ('%d-character limit' % max), 'x' * (max + 1) 
     
    5355  end 
    5456 
     57  def test_included_modules 
     58    assert Page.included_modules.include?(Annotatable), 'Annotatable is not included' 
     59  end 
     60 
     61  def test_layout 
     62    @page = pages(:page_with_layout) 
     63    assert_equal 1, @page.layout_id 
     64    assert_kind_of Layout, @page.layout 
     65  end 
     66 
    5567  def test_parts 
    5668    @homepage = pages(:homepage) 
     
    7082    assert_nil PagePart.find_by_page_id_and_name(id, @part_name) 
    7183  end 
    72    
     84 
    7385  def test_part 
    74     part = radius_page.part('body') 
     86    part = pages(:radius).part('body') 
    7587    assert_equal 'body', part.name 
    7688  end 
    7789  def test_part__lookup_by_symbol 
    78     part = radius_page.part(:body) 
     90    part = pages(:radius).part(:body) 
    7991    assert_equal 'body', part.name 
    8092  end 
    81    
    82   def test_child_url 
    83     @page = pages(:parent) 
    84     @child = pages(:child) 
    85     assert_equal '/parent/child/', @page.child_url(@child) 
    86   end 
    87    
    88   def test_url 
    89     page = pages(:parent) 
    90     assert_equal '/parent/', page.url 
    91     assert_equal '/parent/child/', page.children.first.url 
    92   end 
    93    
    94   def test_layout 
    95     page = pages(:page_with_layout) 
    96     assert_equal 1, page.layout_id 
    97     assert_kind_of Layout, page.layout 
    98   end 
    99    
     93 
    10094  def test_published_at 
    10195    @page = create_test_page(:status_id => '1') 
    10296    assert_nil @page.published_at 
    10397     
    104     @page.status_id = status(:published).id 
     98    @page.status_id = Status[:published].id 
    10599    @page.save 
    106100    assert_not_nil @page.published_at 
    107101    assert_equal Time.now.day, @page.published_at.day 
    108   end 
    109    
     102  end   
    110103  def test_published_at__not_updated_on_save_because_already_published 
    111     @page = create_test_page(:status_id => status(:published).id) 
     104    @page = create_test_page(:status_id => Status[:published].id) 
    112105    assert_kind_of Time, @page.published_at 
    113106     
     
    118111   
    119112  def test_published 
    120     @page.status = status(:published) 
     113    @page.status = Status[:published] 
    121114    assert_equal true, @page.published? 
    122115  end 
    123    
    124116  def test_published__not_published 
    125     @page.status = status(:draft) 
     117    @page.status = Status[:draft] 
    126118    assert_equal false, @page.published? 
    127119  end 
    128    
    129   def test_find_by_url 
     120 
     121  def test_url 
     122    @page = pages(:parent) 
     123    assert_equal '/parent/', @page.url 
     124    assert_equal '/parent/child/', @page.children.first.url 
     125     
     126    grandchild = pages(:grandchild) 
     127    assert_equal '/parent/child/grandchild/', grandchild.url 
     128  end 
     129   
     130  def test_child_url 
     131    @page = pages(:parent) 
     132    child = pages(:child) 
     133    assert_equal '/parent/child/', @page.child_url(child) 
     134  end 
     135   
     136  def test_find_by_url_1 
     137    @page = pages(:homepage) 
     138    assert_equal @page, @page.find_by_url('/')  
     139  end 
     140  def test_find_by_url_2 
     141    @page = pages(:homepage) 
     142    expected = pages(:great_grandchild) 
     143    found = @page.find_by_url('/parent/child/grandchild/great-grandchild/') 
     144    assert_equal expected, found  
     145  end 
     146  def test_find_by_url_3 
    130147    @page = pages(:homepage) 
    131148    assert_equal pages(:article), @page.find_by_url('/archive/2000/05/01/article/') 
    132149  end 
    133    
    134   def test_find_by_url__raises_exception_when_root_missing 
    135     pages(:homepage).destroy 
    136      
    137     # This shouldn't raise an error when there's no root... 
    138     assert_nil Page.find_by_parent_id(nil) 
    139      
    140     # ...but this should 
    141     e = assert_raises(Page::MissingRootPageError) { Page.find_by_url "/" } 
    142     assert_equal 'Database missing root page', e.message 
    143   end 
    144    
     150  def test_find_by_url__when_virtual 
     151    @page = pages(:homepage) 
     152    found = @page.find_by_url('/archive/2006/02/05/month/') 
     153    assert_equal nil, found 
     154  end 
     155  def test_find_by_url__when_not_found_and_missing_page_defined 
     156    @page = pages(:homepage) 
     157    found = @page.find_by_url('/gallery/asdf/') 
     158    assert_instance_of FileNotFoundPage, found 
     159  end 
     160  def test_find_by_url__when_not_found_on_live 
     161    @page = pages(:homepage) 
     162    found = @page.find_by_url('/gallery/gallery_draft/') 
     163    assert_instance_of FileNotFoundPage, found 
     164  end 
     165  def test_find_by_url__when_not_found_on_dev 
     166    @page = pages(:homepage) 
     167    expected = pages(:gallery_draft) 
     168    found = @page.find_by_url('/gallery/gallery_draft/', false) 
     169    assert_equal expected, found 
     170  end   
     171 
    145172  def test_find_by_url_class_method 
    146173    @root = pages(:homepage) 
     
    154181    assert_equal 'Gallery Draft', Page.find_by_url('/gallery/gallery_draft/', false).title 
    155182  end 
     183  def test_find_by_url_class_method__raises_exception_when_root_missing 
     184    pages(:homepage).destroy 
     185    assert_nil Page.find_by_parent_id(nil) 
     186    e = assert_raises(Page::MissingRootPageError) { Page.find_by_url "/" } 
     187    assert_equal 'Database missing root page', e.message 
     188  end 
     189   
     190  def test_headers 
     191    expected = { 'Status' => ActionController::Base::DEFAULT_RENDER_STATUS_CODE } 
     192    assert_equal expected, @page.headers 
     193  end 
    156194   
    157195  def test_render 
    158     @page = pages(:small_test) 
    159     assert_equal 'test', @page.render 
     196    expected = 'This is the body portion of the Ruby home page.' 
     197    assert_page_renders :homepage, expected 
     198  end 
     199  def test_render__with_filter 
     200    expected = '<p>Some <strong>Textile</strong> content.</p>' 
     201    assert_page_renders :textile, expected 
     202  end 
     203  def test_render__with_tags 
     204    expected = "<h1>Radius Test Page</h1>\n\n\n\t<ul>\n\t<li>Radius Test Child 1</li>\n\t\t<li>Radius Test Child 2</li>\n\t\t<li>Radius Test Child 3</li>\n\t</ul>" 
     205    assert_page_renders :radius, expected 
     206  end 
     207  def test_render__with_layout 
     208    expected = "<html>\n  <head>\n    <title>Page With Layout</title>\n  </head>\n  <body>\n    Page With Layout\n  </body>\n</html>\n" 
     209    assert_page_renders :page_with_layout, expected 
     210  end 
     211   
     212  def test_render_snippet 
     213    assert_snippet_renders :first, 'test' 
     214  end 
     215  def test_render_snippet_with_filter 
     216    assert_snippet_renders :markdown, '<p><strong>markdown</strong></p>' 
     217  end 
     218  def test_render_snippet_with_tag 
     219    assert_snippet_renders :snippet_with_tag, 'New Page' 
    160220  end 
    161221   
    162222  def test_process 
    163     @page = create_test_page 
    164     @request = ActionController::TestRequest.new :url => '/page/' 
    165     @response = ActionController::TestResponse.new 
     223    @page = pages(:textile) 
    166224    @page.process(@request, @response) 
    167     assert_equal 'test', @response.body 
     225    assert_match %r{Some <strong>Textile</strong> content.}, @response.body 
     226  end 
     227  def test_process_with_headers 
     228    @page = pages(:test_page) 
     229    @page.process(@request, @response) 
     230    assert_equal 'beans', @response.headers['cool'] 
     231    assert_equal 'TestRequest', @response.headers['request'] 
     232    assert_equal 'TestResponse', @response.headers['response'] 
     233  end 
     234  def test_process__page_with_content_type_set_on_layot 
     235    @page = pages(:page_with_content_type_set_on_layout) 
     236    @page.process(@request, @response) 
     237    assert_response :success 
     238    assert_equal 'text/html;charset=utf8', @response.headers['Content-Type'] 
    168239  end 
    169240 
     
    195266  end 
    196267   
     268  def test_config 
     269    @page = pages(:page_with_yaml_config) 
     270    config = @page.config 
     271    assert_equal true, config['test'] 
     272    assert_equal 'beans', config['cool'] 
     273  end 
     274  def test_page_config__nil_part 
     275    @page = pages(:homepage) 
     276    config = @page.config 
     277    assert_equal Hash.new, @page.config 
     278  end 
     279   
    197280  def test_before_save 
    198     @page = create_test_page(:behavior_id => 'Archive Month Index'
     281    @page = create_test_page(:type => ArchiveMonthIndexPage
    199282    assert_equal true, @page.virtual? 
    200283    assert_equal true, @page.virtual 
    201284  end 
    202285   
    203   def test_behavior 
    204     @page = pages(:homepage) 
    205     original = @page.behavior 
    206      
    207     assert_kind_of Behavior::Base, original 
    208      
    209     assert_same original, @page.behavior 
    210      
    211     @page.behavior_id = 'Archive' 
    212     assert_kind_of ArchiveBehavior, @page.behavior 
    213   end 
    214    
    215   private 
    216    
    217     def radius_page 
    218       pages(:radius) 
    219     end 
    220      
    221     def status(name) 
    222       Status[name] 
    223     end 
     286  def test_annotations 
     287    assert_equal 'this is just a test page', TestPage.description 
     288  end 
     289   
     290  def test_define_tags 
     291    assert_page_renders :test_page, 'Hello world! Another test.' 
     292  end 
     293  def test_define_tags__is_unique_for_each_behavior 
     294    assert_render_match %r{undefined tag `test1'}, '<r:test1 />' 
     295  end 
     296   
     297  def test_render_part 
     298    @page = pages(:test_page) 
     299    assert_equal "Hello world! Another test.", @page.render_part(:body) 
     300  end 
     301 
     302  def test_render_text 
     303    @page = pages(:homepage) 
     304    assert_equal "/", @page.render_text( "<r:slug />") 
     305  end 
     306   
     307  def test_display_name_class_method 
     308    assert_equal "Page", Page.display_name 
     309     
     310    assert_equal "Test", TestPage.display_name 
     311     
     312    TestPage.display_name = "New Name" 
     313    assert_equal "New Name", TestPage.display_name 
     314     
     315    assert_equal "File Not Found", FileNotFoundPage.display_name 
     316  end 
     317   
     318  def test_decendants_class_method 
     319    descendants = Page.descendants 
     320    assert_kind_of Array, descendants 
     321    assert_match /TestPage/, descendants.inspect 
     322  end 
     323 
     324  # def test_child_defaults 
     325  #   # TODO: allow behaviors to define child page defaults 
     326  # end 
     327     
    224328end