removing fixture files will clear page block
Oleg
committed Feb 21, 2012
commit e0912a086df93e8260853e3ca19141c1fc366c2b
Showing 5
changed files with
70 additions
and 4 deletions
app/assets/stylesheets/comfortable_mexican_sofa/content.css
+23
-0
| @@ | @@ -175,6 +175,29 @@ |
| #cms_body ul.list li .item:hover { | |
| background-color: #fff; | |
| } | |
| + | /* -- Tables ------------------------------------------------------------ */ |
| + | #cms_body table.formatted { |
| + | width: 100%; |
| + | } |
| + | #cms_body table.formatted th, #cms_body table.formatted td { |
| + | white-space: nowrap; |
| + | padding: 6px; |
| + | background-color: #f1f1f1; |
| + | border-bottom: 2px solid #e6e6e6; |
| + | vertical-align: top; |
| + | } |
| + | #cms_body table.formatted th.main, #cms_body table.formatted td.main { |
| + | white-space: normal; |
| + | width: 100%; |
| + | } |
| + | #cms_body table.formatted th { |
| + | color: #000; |
| + | border-color: #9f9f9f; |
| + | } |
| + | #cms_body table.formatted tr:hover td { |
| + | background-color: #fff |
| + | } |
| + | |
| /* -- Missing Translations ---------------------------------------------- */ | |
| #cms_body .translation_missing { | |
| text-decoration: blink; | |
app/assets/stylesheets/comfortable_mexican_sofa/typography.css
+3
-0
| @@ | @@ -18,6 +18,9 @@ body#cms_body { |
| #cms_body h1 + h2 { | |
| margin-top: -15px; | |
| } | |
| + | #cms_body p { |
| + | margin-bottom: 15px; |
| + | } |
| #cms_body a { | |
| text-decoration: none; | |
| color: #384E66; | |
app/models/cms/page.rb
+1
-0
| @@ | @@ -157,6 +157,7 @@ protected |
| end | |
| end | |
| + | # NOTE: This can create 'phantom' page blocks as they are defined in the layout. This is normal. |
| def set_cached_content | |
| write_attribute(:content, self.content(true)) | |
| end | |
comfortable_mexican_sofa/fixtures.rb b/lib/comfortable_mexican_sofa/fixtures.rb
+11
-1
| @@ | @@ -110,10 +110,12 @@ module ComfortableMexicanSofa::Fixtures |
| end | |
| # updating content | |
| + | blocks_to_clear = page.blocks.collect(&:identifier) |
| blocks_attributes = [ ] | |
| Dir.glob("#{path}/*.html").each do |file_path| | |
| + | identifier = file_path.split('/').last.split('.').first |
| + | blocks_to_clear.delete(identifier) |
| if page.new_record? || File.mtime(file_path) > page.updated_at | |
| - | identifier = file_path.split('/').last.split('.').first |
| blocks_attributes << { | |
| :identifier => identifier, | |
| :content => File.open(file_path).read | |
| @@ | @@ -121,6 +123,14 @@ module ComfortableMexicanSofa::Fixtures |
| end | |
| end | |
| + | # clearing removed blocks |
| + | blocks_to_clear.each do |identifier| |
| + | blocks_attributes << { |
| + | :identifier => identifier, |
| + | :content => nil |
| + | } |
| + | end |
| + | |
| # saving | |
| page.blocks_attributes = blocks_attributes if blocks_attributes.present? | |
| if page.changed? || blocks_attributes.present? | |
test/unit/fixtures_test.rb
+32
-3
| @@ | @@ -124,7 +124,14 @@ class FixturesTest < ActiveSupport::TestCase |
| end | |
| def test_import_pages_ignoring | |
| - | page = cms_pages(:default) |
| + | Cms::Page.destroy_all |
| + | |
| + | page = cms_sites(:default).pages.create!( |
| + | :label => 'Test', |
| + | :layout => cms_layouts(:default), |
| + | :blocks_attributes => [ { :identifier => 'content', :content => 'test content' } ] |
| + | ) |
| + | |
| page_path = File.join(ComfortableMexicanSofa.config.fixtures_path, 'example.com', 'pages', 'index') | |
| attr_file_path = File.join(page_path, '_index.yml') | |
| content_file_path = File.join(page_path, 'content.html') | |
| @@ | @@ -134,9 +141,31 @@ class FixturesTest < ActiveSupport::TestCase |
| ComfortableMexicanSofa::Fixtures.import_pages('test.host', 'example.com') | |
| page.reload | |
| + | |
| assert_equal nil, page.slug | |
| - | assert_equal 'Default Page', page.label |
| - | assert_equal "\nlayout_content_a\ndefault_page_text_content_a\ndefault_snippet_content\ndefault_page_text_content_b\nlayout_content_b\ndefault_snippet_content\nlayout_content_c", page.content |
| + | assert_equal 'Test', page.label |
| + | block = page.blocks.where(:identifier => 'content').first |
| + | assert_equal 'test content', block.content |
| + | end |
| + | |
| + | def test_import_pages_removing_deleted_blocks |
| + | Cms::Page.destroy_all |
| + | |
| + | page = cms_sites(:default).pages.create!( |
| + | :label => 'Test', |
| + | :layout => cms_layouts(:default), |
| + | :blocks_attributes => [ { :identifier => 'to_delete', :content => 'test content' } ] |
| + | ) |
| + | page.update_attribute(:updated_at, 10.years.ago) |
| + | |
| + | ComfortableMexicanSofa::Fixtures.import_pages('test.host', 'example.com') |
| + | page.reload |
| + | |
| + | block = page.blocks.where(:identifier => 'content').first |
| + | assert_equal "Home Page Fixture Contént\n{{ cms:snippet:default }}", block.content |
| + | |
| + | block = page.blocks.where(:identifier => 'to_delete').first |
| + | assert_equal nil, block.content |
| end | |
| def test_import_snippets_creating | |