page fixtures are working
Oleg
committed Apr 30, 2011
commit b91a0f3932a93f2f52e9271b35c313202a864070
Showing 2
changed files with
22 additions
and 7 deletions
comfortable_mexican_sofa/fixtures.rb b/lib/comfortable_mexican_sofa/fixtures.rb
+4
-4
| @@ | @@ -48,7 +48,7 @@ module ComfortableMexicanSofa::Fixtures |
| end | |
| # removing all db entries that are not in fixtures | |
| - | Cms::Layout.where('id NOT IN (?)', layout_ids.uniq).each{ |l| l.destroy } if root |
| + | site.layouts.where('id NOT IN (?)', layout_ids.uniq).each{ |l| l.destroy } if root |
| # returning ids of layouts in fixtures | |
| layout_ids | |
| @@ | @@ -62,7 +62,7 @@ module ComfortableMexicanSofa::Fixtures |
| page = if parent | |
| parent.children.find_by_slug(slug) || parent.children.new(:slug => slug, :site => site) | |
| else | |
| - | site.pages.find_by_slug(slug) || site.pages.new(:slug => slug) |
| + | site.pages.root || site.pages.new(:slug => slug) |
| end | |
| # updating attributes | |
| @@ | @@ -99,7 +99,7 @@ module ComfortableMexicanSofa::Fixtures |
| end | |
| # removing all db entries that are not in fixtures | |
| - | Cms::Page.where('id NOT IN (?)', page_ids.uniq).each{ |p| p.destroy } if root |
| + | site.pages.where('id NOT IN (?)', page_ids.uniq).each{ |p| p.destroy } if root |
| # returning ids of layouts in fixtures | |
| page_ids | |
| @@ | @@ -136,7 +136,7 @@ module ComfortableMexicanSofa::Fixtures |
| end | |
| # removing all db entries that are not in fixtures | |
| - | Cms::Snippet.where('id NOT IN (?)', snippet_ids).each{ |s| s.destroy } |
| + | site.snippets.where('id NOT IN (?)', snippet_ids).each{ |s| s.destroy } |
| end | |
| def self.find_path(site, dir) | |
test/unit/fixtures_test.rb
+18
-3
| @@ | @@ -111,13 +111,28 @@ class ViewMethodsTest < ActiveSupport::TestCase |
| assert_no_difference 'Cms::Page.count' do | |
| ComfortableMexicanSofa::Fixtures.sync_pages(@site) | |
| - | raise Cms::Page.all.to_yaml |
| + | |
| + | page.reload |
| + | assert_equal 'Home Fixture Page', page.label |
| + | |
| + | assert_nil Cms::Page.find_by_slug('old') |
| end | |
| - | |
| end | |
| def test_sync_pages_ignoring | |
| - | flunk |
| + | page = cms_pages(:default) |
| + | page_path = File.join(ComfortableMexicanSofa.config.fixtures_path, @site.hostname, 'pages', 'index') |
| + | attr_file_path = File.join(page_path, '_index.yml') |
| + | content_file_path = File.join(page_path, 'content.html') |
| + | |
| + | assert page.updated_at >= File.mtime(attr_file_path) |
| + | assert page.updated_at >= File.mtime(content_file_path) |
| + | |
| + | ComfortableMexicanSofa::Fixtures.sync_pages(@site) |
| + | 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 |
| end | |
| def test_sync_snippets_creating | |