fixing a bug with refreshing page content on layout change
Oleg
committed Mar 22, 2011
commit 92685140dc8345c312957b4b23d555dfc0364922
Showing 3
changed files with
41 additions
and 9 deletions
app/models/cms_layout.rb
+2
-1
| @@ | @@ -109,9 +109,10 @@ protected |
| FileUtils.rm File.expand_path("cms-js/#{self.slug}.js", Rails.public_path), :force => true | |
| end | |
| - | # Forcing page content reload. This will happen in cascade due to #clear_cache mathod above. |
| + | # Forcing page content reload |
| def clear_cached_page_content | |
| self.cms_pages.each{ |page| page.save! } | |
| + | self.children.each{ |child_layout| child_layout.save! } |
| end | |
| end | |
test/functional/cms_content_controller_test.rb
+0
-2
| @@ | @@ -78,7 +78,6 @@ class CmsContentControllerTest < ActionController::TestCase |
| :is_published => '1', | |
| :cms_blocks_attributes => [ | |
| { :label => 'default_page_text', | |
| - | :type => 'CmsTag::PageText', |
| :content => 'text <%= 2 + 2 %> text' } | |
| ] | |
| ) | |
| @@ | @@ -98,7 +97,6 @@ class CmsContentControllerTest < ActionController::TestCase |
| :is_published => '1', | |
| :cms_blocks_attributes => [ | |
| { :label => 'default_page_text', | |
| - | :type => 'CmsTag::PageText', |
| :content => 'text <%= 2 + 2 %> text' } | |
| ] | |
| ) | |
test/unit/cms_layout_test.rb
+39
-6
| @@ | @@ -135,12 +135,45 @@ class CmsLayoutTest < ActiveSupport::TestCase |
| end | |
| def test_update_forces_page_content_reload | |
| - | layout = cms_layouts(:default) |
| - | page = cms_pages(:default) |
| - | assert_equal layout, page.cms_layout |
| - | layout.update_attribute(:content, 'updated {{cms:page:default_page_text:text}} updated') |
| - | page.reload |
| - | assert_equal "updated default_page_text_content_a\ndefault_snippet_content\ndefault_page_text_content_b updated", page.content |
| + | layout_1 = cms_layouts(:nested) |
| + | layout_2 = cms_layouts(:child) |
| + | page_1 = cms_sites(:default).cms_pages.create!( |
| + | :label => 'page_1', |
| + | :slug => 'page-1', |
| + | :parent_id => cms_pages(:default).id, |
| + | :cms_layout_id => layout_1.id, |
| + | :is_published => '1', |
| + | :cms_blocks_attributes => [ |
| + | { :label => 'header', |
| + | :content => 'header_content' }, |
| + | { :label => 'content', |
| + | :content => 'content_content' } |
| + | ] |
| + | ) |
| + | page_2 = cms_sites(:default).cms_pages.create!( |
| + | :label => 'page_2', |
| + | :slug => 'page-2', |
| + | :parent_id => cms_pages(:default).id, |
| + | :cms_layout_id => layout_2.id, |
| + | :is_published => '1', |
| + | :cms_blocks_attributes => [ |
| + | { :label => 'header', |
| + | :content => 'header_content' }, |
| + | { :label => 'left_column', |
| + | :content => 'left_column_content' }, |
| + | { :label => 'right_column', |
| + | :content => 'left_column_content' } |
| + | ] |
| + | ) |
| + | assert_equal "header_content\ncontent_content", page_1.content |
| + | assert_equal "header_content\nleft_column_content\nleft_column_content", page_2.content |
| + | |
| + | layout_1.update_attribute(:content, "Updated {{cms:page:content}}") |
| + | page_1.reload |
| + | page_2.reload |
| + | |
| + | assert_equal "Updated content_content", page_1.content |
| + | assert_equal "Updated left_column_content\nleft_column_content", page_2.content |
| end | |
| end | |