fixing a recursive save bug with page_files
Oleg
committed Oct 28, 2011
commit ed44d1d7dbd86b7b20aa62f4255c71d201a0cad1
Showing 4
changed files with
36 additions
and 4 deletions
app/models/cms/file.rb
+2
-1
| @@ | @@ -50,7 +50,8 @@ protected |
| # FIX: Terrible, but no way of creating cached page content overwise | |
| def reload_page_cache | |
| return unless self.block | |
| - | self.block.page.save! |
| + | p = self.block.page |
| + | p.update_column(:content, p.content(true)) |
| end | |
| end | |
app/models/cms/page.rb
+2
-2
| @@ | @@ -18,8 +18,8 @@ class Cms::Page < ActiveRecord::Base |
| belongs_to :target_page, | |
| :class_name => 'Cms::Page' | |
| has_many :blocks, | |
| - | :dependent => :destroy, |
| - | :autosave => true |
| + | :autosave => true, |
| + | :dependent => :destroy |
| # -- Callbacks ------------------------------------------------------------ | |
| before_validation :assigns_label, | |
test/test_helper.rb
+1
-1
| @@ | @@ -6,7 +6,7 @@ require 'rails/test_help' |
| class ActiveSupport::TestCase | |
| - | # Shut the fuck up |
| + | # Disabling the noise |
| $stdout_orig = $stdout | |
| $stderr_orig = $stderr | |
| $stdout = StringIO.new | |
test/unit/models/block_test.rb
+31
-0
| @@ | @@ -171,4 +171,35 @@ class CmsBlockTest < ActiveSupport::TestCase |
| end | |
| end | |
| + | def test_creation_via_nested_attributes_with_file |
| + | layout = cms_layouts(:default) |
| + | layout.update_attribute(:content, '{{cms:page:header}}{{cms:page_file:file}}{{cms:page:footer}}') |
| + | |
| + | assert_difference 'Cms::Page.count' do |
| + | assert_difference 'Cms::Block.count', 3 do |
| + | page = Cms::Page.create!( |
| + | :site => cms_sites(:default), |
| + | :layout => layout, |
| + | :label => 'test page', |
| + | :slug => 'test_page', |
| + | :parent_id => cms_pages(:default).id, |
| + | :blocks_attributes => { |
| + | '0' => { |
| + | :label => 'header', |
| + | :content => 'header content' |
| + | }, |
| + | '1' => { |
| + | :label => 'file', |
| + | :content => fixture_file_upload('files/document.pdf') |
| + | }, |
| + | '2' => { |
| + | :label => 'footer', |
| + | :content => 'footer content' |
| + | } |
| + | } |
| + | ) |
| + | end |
| + | end |
| + | end |
| + | |
| end | |