Changeset 126
- Timestamp:
- 09/27/06 16:32:28 (2 years ago)
- Files:
-
- branches/mental/radiant/app/behaviors (deleted)
- branches/mental/radiant/app/controllers/admin/page_controller.rb (modified) (1 diff)
- branches/mental/radiant/app/models/archive_day_index_page.rb (added)
- branches/mental/radiant/app/models/archive_month_index_page.rb (added)
- branches/mental/radiant/app/models/archive_page.rb (added)
- branches/mental/radiant/app/models/archive_year_index_page.rb (added)
- branches/mental/radiant/app/models/behavior.rb (deleted)
- branches/mental/radiant/app/models/env_dump_page.rb (added)
- branches/mental/radiant/app/models/file_not_found_page.rb (added)
- branches/mental/radiant/app/models/page.rb (modified) (6 diffs)
- branches/mental/radiant/app/models/page_context.rb (modified) (5 diffs)
- branches/mental/radiant/app/views/admin/page/_node.rhtml (modified) (2 diffs)
- branches/mental/radiant/app/views/admin/page/new.rhtml (modified) (1 diff)
- branches/mental/radiant/config/environment.rb (modified) (1 diff)
- branches/mental/radiant/db/development_structure.sql (modified) (3 diffs)
- branches/mental/radiant/db/migrate/010_merge_behaviors_and_pages.rb (added)
- branches/mental/radiant/db/schema.rb (modified) (2 diffs)
- branches/mental/radiant/lib/annotatable.rb (added)
- branches/mental/radiant/lib/archive_index_behavior_tags_and_methods.rb (deleted)
- branches/mental/radiant/lib/archive_index_tags_and_methods.rb (added)
- branches/mental/radiant/lib/inheritable_class_attributes.rb (modified) (1 diff)
- branches/mental/radiant/test/fixtures/pages.yml (modified) (7 diffs)
- branches/mental/radiant/test/functional/site_controller_test.rb (modified) (1 diff)
- branches/mental/radiant/test/helpers/archive_index_test_helper.rb (modified) (2 diffs)
- branches/mental/radiant/test/helpers/behavior_render_test_helper.rb (deleted)
- branches/mental/radiant/test/helpers/behavior_test_helper.rb (deleted)
- branches/mental/radiant/test/helpers/page_test_helper.rb (modified) (2 diffs)
- branches/mental/radiant/test/helpers/render_test_helper.rb (added)
- branches/mental/radiant/test/unit/annotatable_test.rb (added)
- branches/mental/radiant/test/unit/archive_day_index_page_test.rb (added)
- branches/mental/radiant/test/unit/archive_month_index_page_test.rb (added)
- branches/mental/radiant/test/unit/archive_page_test.rb (added)
- branches/mental/radiant/test/unit/archive_year_index_page_test.rb (added)
- branches/mental/radiant/test/unit/behavior_test.rb (deleted)
- branches/mental/radiant/test/unit/behaviors (deleted)
- branches/mental/radiant/test/unit/file_not_found_page_test.rb (added)
- branches/mental/radiant/test/unit/page_context_test.rb (modified) (2 diffs)
- branches/mental/radiant/test/unit/page_test.rb (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/mental/radiant/app/controllers/admin/page_controller.rb
r57 r126 1 1 class Admin::PageController < ApplicationController 2 2 3 model :page 3 4 branches/mental/radiant/app/models/page.rb
r64 r126 1 require_dependency 'a dvanced_delegation'1 require_dependency 'annotatable' 2 2 3 3 class Page < ActiveRecord::Base … … 8 8 9 9 # Callbacks 10 before_save :update_published_at, :update_virtual 10 before_save :update_published_at, :update_virtual, :update_type 11 11 12 12 # Associations … … 23 23 validates_length_of :slug, :maximum => 100, :message => '%d-character limit' 24 24 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'26 25 27 26 validates_format_of :slug, :with => %r{^([-_.A-Za-z0-9]*|/)$}, :message => 'invalid format' … … 29 28 validates_numericality_of :id, :status_id, :parent_id, :allow_nil => true, :only_integer => true, :message => 'must be a number' 30 29 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 35 40 36 41 def after_initialize … … 42 47 end 43 48 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 44 70 def part(name) 45 71 parts.find_by_name name.to_s 46 72 end 47 73 74 def ptype 75 @ptype ||= read_attribute('type').to_s 76 end 77 78 def published? 79 status == Status[:published] 80 end 81 48 82 def status 49 83 Status.find(self.status_id) 50 84 end 51 52 85 def status=(value) 53 86 self.status_id = value.id 54 87 end 55 88 56 def published?57 status == Status[:published]58 end59 60 def behavior61 if @behavior.nil? or (@old_behavior_id != behavior_id)62 @old_behavior_id = behavior_id63 @behavior = Behavior[behavior_id].new(self)64 else65 @behavior66 end67 end68 69 def self.find_by_url(url, live = true)70 root = find_by_parent_id(nil)71 raise MissingRootPageError unless root72 root.find_by_url(url, live)73 end74 75 89 def virtual 76 90 !(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 77 199 end 78 200 … … 83 205 true 84 206 end 85 207 86 208 def update_virtual 87 209 write_attribute('virtual', virtual?) 88 210 true 89 211 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 90 253 91 254 end branches/mental/radiant/app/models/page_context.rb
r105 r126 10 10 globals.page = @page 11 11 12 # 12 13 # <r:page>...</r:page> 13 14 # … … 24 25 # etc... 25 26 # 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| 27 28 define_tag(method.to_s) do |tag| 28 29 tag.locals.page.send(method) … … 210 211 if inherit and contextual 211 212 part = part_page.part(part_name) 212 page. behavior.render_snippet(part) unless part.nil?213 page.render_snippet(part) unless part.nil? 213 214 else 214 part_page. behavior.render_page_part(part_name)215 part_page.render_part(part_name) 215 216 end 216 217 end … … 346 347 if snippet = Snippet.find_by_name(name.strip) 347 348 page = tag.locals.page 348 page. behavior.render_snippet(snippet)349 page.render_snippet(snippet) 349 350 else 350 351 raise TagError.new('snippet not found') … … 516 517 ActiveRecord::Base.connection.adapter_name =~ /postgres/i 517 518 end 519 518 520 def build_regexp_for(tag,attribute_name) 519 521 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 15 15 title = %{<span class="title">#{ page.title }</span>} 16 16 17 behavior_id = page.behavior_id.to_s.strip 18 behavior = behavior_id.empty? ? '' : %{<small class="info">(#{ behavior_id})</small>}17 display_name = page.class.display_name 18 page_type = display_name == 'Page' ? '' : %{<small class="info">(#{ display_name })</small>} 19 19 20 20 spinner = image_tag("spinner.gif", :class => 'busy', :id => "busy-#{page.id}", :alt => "", :title => "", :align => "center", :style => 'display: none;') … … 28 28 <% else -%> 29 29 <%= expander %><a href="<%= page_edit_url(:id => page) %>"><%= icon %> <%= title %></a> 30 <%= behavior%>30 <%= page_type %> 31 31 <%= spinner %> 32 32 <% end -%> branches/mental/radiant/app/views/admin/page/new.rhtml
r61 r126 127 127 <p><label for="page_layout_id">Layout</label> 128 128 <%= 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> 131 131 <p><label for="page_status_id">Status</label> 132 132 <%= select "page", "status_id", Status.find_all.map { |s| [s.name, s.id] } %></p> branches/mental/radiant/config/environment.rb
r98 r126 65 65 66 66 # Auto-require behaviors 67 Dir["#{RADIANT_ROOT}/app/behaviors/*_behavior.rb"].each do |behavior| 68 require_dependency behavior 67 Dir["#{RADIANT_ROOT}/app/models/*_page.rb"].each do |page| 68 page = $1 if page =~ %r{/([^/]*)\.rb} 69 require_dependency page 69 70 end 70 71 branches/mental/radiant/db/development_structure.sql
r19 r126 11 11 `name` varchar(100) default NULL, 12 12 `content` text, 13 `content_type` varchar(40) default NULL, 13 14 `created_at` datetime default NULL, 14 15 `updated_at` datetime default NULL, … … 34 35 `parent_id` int(11) default NULL, 35 36 `layout_id` int(11) default NULL, 36 ` behavior_id` varchar(25) default NULL,37 `type` varchar(25) default NULL, 37 38 `status_id` int(11) NOT NULL default '1', 38 39 `created_at` datetime default NULL, … … 78 79 ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 79 80 80 INSERT INTO schema_info (version) VALUES ( 8)81 INSERT INTO schema_info (version) VALUES (10) branches/mental/radiant/db/schema.rb
r95 r126 3 3 # then regenerate this schema definition. 4 4 5 ActiveRecord::Schema.define(:version => 9) do5 ActiveRecord::Schema.define(:version => 10) do 6 6 7 7 create_table "config", :force => true do |t| … … 35 35 t.column "parent_id", :integer 36 36 t.column "layout_id", :integer 37 t.column " behavior_id", :string, :limit => 2537 t.column "type", :string, :limit => 25 38 38 t.column "status_id", :integer, :default => 1, :null => false 39 39 t.column "created_at", :datetime branches/mental/radiant/lib/inheritable_class_attributes.rb
r1 r126 49 49 50 50 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) 52 52 53 53 readers = inheritable_cattr_readers.dup branches/mental/radiant/test/fixtures/pages.yml
r91 r126 99 99 breadcrumb: Parent 100 100 slug: archive 101 behavior_id: Archive101 type: ArchivePage 102 102 status_id: 100 103 103 parent_id: 1 … … 107 107 title: %Y Archive 108 108 slug: year 109 behavior_id: Archive Year Index109 type: ArchiveYearIndexPage 110 110 status_id: 101 111 111 parent_id: 12 … … 116 116 title: %B %Y Archive 117 117 slug: month 118 behavior_id: Archive Month Index118 type: ArchiveMonthIndexPage 119 119 status_id: 101 120 120 parent_id: 12 … … 125 125 title: %B %d, %Y Archive 126 126 slug: day 127 behavior_id: Archive Day Index127 type: ArchiveDayIndexPage 128 128 status_id: 101 129 129 parent_id: 12 … … 198 198 status_id: 100 199 199 parent_id: 1 200 behavior_id: No Cache200 type: NoCachePage 201 201 assorted: 202 202 id: 19 … … 262 262 parent_id: 33 263 263 published_at: 2006-02-05 08:44:07 264 custom_tags:264 test_page: 265 265 id: 35 266 title: Custom Tags267 slug: custom-tags268 behavior_id: Test Behavior266 title: Test Page 267 slug: test-page 268 type: TestPage 269 269 status_id: 100 270 270 parent_id: 1 … … 319 319 parent_id: 1 320 320 published_at: 2006-02-05 08:44:07 321 missing:321 file_not_found: 322 322 id: 51 323 323 title: File Not Found 324 324 slug: missing 325 behavior_id: Page Missing325 type: FileNotFoundPage 326 326 status_id: 100 327 327 parent_id: 50 branches/mental/radiant/test/functional/site_controller_test.rb
r93 r126 7 7 class SiteControllerTest < Test::Unit::TestCase 8 8 fixtures :pages, :page_parts 9 test_helper : behavior9 test_helper :pages 10 10 11 11 def setup branches/mental/radiant/test/helpers/archive_index_test_helper.rb
r51 r126 1 1 module ArchiveIndexTestHelper 2 2 module ArchiveIndexTests 3 3 4 def test_page_virtual? 4 5 assert_equal true, @page.virtual? … … 32 33 assert_renders 'Friday', '<r:archive:day_of_week />', '/archive/2000/06/09/' 33 34 end 35 34 36 end 35 37 end branches/mental/radiant/test/helpers/page_test_helper.rb
r1 r126 1 class NoCachePage < Page 2 description 'Turns caching off for testing.' 3 4 def cache? 5 false 6 end 7 end 8 9 class 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 32 end 33 1 34 module PageTestHelper 35 2 36 VALID_PAGE_PARAMS = { 3 37 :title => 'New Page', … … 27 61 def create_test_page(options = {}) 28 62 options[:title] ||= @page_title 29 page = Page.new page_params(options) 63 klass = options.delete(:type) || Page 64 page = klass.new page_params(options) 30 65 if page.save 31 66 page branches/mental/radiant/test/unit/page_context_test.rb
r92 r126 3 3 class PageContextTest < Test::Unit::TestCase 4 4 fixtures :pages, :page_parts, :layouts, :snippets, :users 5 test_helper :pages 5 6 6 7 def setup … … 19 20 def test_tags_page_attributes 20 21 @page.attributes.keys.each do |attr| 21 value = @page.send(attr)22 unless [:created_by, :updated_by].include? attr.to_s.intern22 unless [:type, :created_by, :updated_by].include? attr.to_s.intern 23 value = @page.send(attr) 23 24 assert_parse_output value.to_s, "<r:#{attr} />" 24 25 end branches/mental/radiant/test/unit/page_test.rb
r69 r126 2 2 3 3 class PageTest < Test::Unit::TestCase 4 fixtures :users, :pages, :page_parts, : layouts5 test_helper :pages, :page_parts, :validations 4 fixtures :users, :pages, :page_parts, :snippets, :layouts 5 test_helper :pages, :page_parts, :validations, :render 6 6 7 7 def setup … … 13 13 14 14 @page = @model = Page.new(VALID_PAGE_PARAMS) 15 16 @request = ActionController::TestRequest.new :url => '/page/' 17 @response = ActionController::TestResponse.new 15 18 end 16 19 … … 19 22 :title => 255, 20 23 :slug => 100, 21 :breadcrumb => 160, 22 :behavior_id => 25 24 :breadcrumb => 160 23 25 }.each do |field, max| 24 26 assert_invalid field, ('%d-character limit' % max), 'x' * (max + 1) … … 53 55 end 54 56 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 55 67 def test_parts 56 68 @homepage = pages(:homepage) … … 70 82 assert_nil PagePart.find_by_page_id_and_name(id, @part_name) 71 83 end 72 84 73 85 def test_part 74 part = radius_page.part('body')86 part = pages(:radius).part('body') 75 87 assert_equal 'body', part.name 76 88 end 77 89 def test_part__lookup_by_symbol 78 part = radius_page.part(:body)90 part = pages(:radius).part(:body) 79 91 assert_equal 'body', part.name 80 92 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 100 94 def test_published_at 101 95 @page = create_test_page(:status_id => '1') 102 96 assert_nil @page.published_at 103 97 104 @page.status_id = status(:published).id98 @page.status_id = Status[:published].id 105 99 @page.save 106 100 assert_not_nil @page.published_at 107 101 assert_equal Time.now.day, @page.published_at.day 108 end 109 102 end 110 103 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) 112 105 assert_kind_of Time, @page.published_at 113 106 … … 118 111 119 112 def test_published 120 @page.status = status(:published)113 @page.status = Status[:published] 121 114 assert_equal true, @page.published? 122 115 end 123 124 116 def test_published__not_published 125 @page.status = status(:draft)117 @page.status = Status[:draft] 126 118 assert_equal false, @page.published? 127 119 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 130 147 @page = pages(:homepage) 131 148 assert_equal pages(:article), @page.find_by_url('/archive/2000/05/01/article/') 132 149 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 145 172 def test_find_by_url_class_method 146 173 @root = pages(:homepage) … … 154 181 assert_equal 'Gallery Draft', Page.find_by_url('/gallery/gallery_draft/', false).title 155 182 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 156 194 157 195 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' 160 220 end 161 221 162 222 def test_process 163 @page = create_test_page 164 @request = ActionController::TestRequest.new :url => '/page/' 165 @response = ActionController::TestResponse.new 223 @page = pages(:textile) 166 224 @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'] 168 239 end 169 240 … … 195 266 end 196 267 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 197 280 def test_before_save 198 @page = create_test_page(: behavior_id => 'Archive Month Index')281 @page = create_test_page(:type => ArchiveMonthIndexPage) 199 282 assert_equal true, @page.virtual? 200 283 assert_equal true, @page.virtual 201 284 end 202 285 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 224 328 end
