fixtures are complete
Oleg
committed Apr 30, 2011
commit fa027c06f719ac13b04004f1d037dc28a1c4b007
Showing 6
changed files with
58 additions
and 10 deletions
app/controllers/cms_content_controller.rb
+1
-1
| @@ | @@ -24,7 +24,7 @@ protected |
| def load_fixtures | |
| return unless ComfortableMexicanSofa.config.enable_fixtures | |
| - | ComfortableMexicanSofa::Fixtures.sync! |
| + | ComfortableMexicanSofa::Fixtures.sync(@cms_site) |
| end | |
| def load_cms_site | |
config/initializers/comfortable_mexican_sofa.rb
+8
-5
| @@ | @@ -14,11 +14,6 @@ ComfortableMexicanSofa.configure do |config| |
| # You don't need to change it when changing admin_route_prefix | |
| # config.admin_route_redirect = '/cms-admin/pages' | |
| - | # Location of YAML files that can be used to render pages instead of pulling |
| - | # data from the database. Not active if not specified. Containing folder name |
| - | # should be the hostname of the site. Example: my-app.local |
| - | # config.seed_data_path = File.expand_path('db/cms_seeds', Rails.root) |
| - | |
| # If you enable this setting you'll be able to serve completely different set | |
| # of sites with their own layouts and pages. | |
| # config.enable_multiple_sites = false | |
| @@ | @@ -39,6 +34,14 @@ ComfortableMexicanSofa.configure do |config| |
| # filesystem see: http://rdoc.info/gems/paperclip/2.3.8/Paperclip/Storage/S3 | |
| # config.upload_file_options = {:storage => :filesystem} | |
| + | # Sofa allows you to setup entire site from files. Database is updated with each |
| + | # request (if nessesary). Please note that database entries are destroyed if there's |
| + | # no corresponding file. Fixtures are disabled by default. |
| + | config.enable_fixtures = false |
| + | |
| + | # Path where fixtures can be located. |
| + | config.fixtures_path = File.expand_path('db/cms_fixtures', Rails.root) |
| + | |
| end | |
| # Default credentials for ComfortableMexicanSofa::HttpAuth | |
cms_fixtures/example.com/pages/index/content.html b/db/cms_fixtures/example.com/pages/index/content.html
+1
-1
| @@ | @@ -1,2 +1,2 @@ |
| Home Page Fixture Content | |
| - | {{ cms:snippet:example }} |
| \ No newline at end of file | |
| + | {{ cms:snippet:default }} |
| \ No newline at end of file | |
comfortable_mexican_sofa/fixtures.rb b/lib/comfortable_mexican_sofa/fixtures.rb
+4
-2
| @@ | @@ -1,7 +1,9 @@ |
| module ComfortableMexicanSofa::Fixtures | |
| - | def self.sync |
| - | |
| + | def self.sync(site) |
| + | sync_layouts(site) |
| + | sync_pages(site) |
| + | sync_snippets(site) |
| end | |
| def self.sync_layouts(site, path = nil, root = true, parent = nil, layout_ids = []) | |
test/integration/fixtures_test.rb
+43
-0
| @@ | @@ -0,0 +1,43 @@ |
| + | require File.expand_path('../test_helper', File.dirname(__FILE__)) |
| + | |
| + | class FixturesTest < ActionDispatch::IntegrationTest |
| + | |
| + | def setup |
| + | host! 'example.com' |
| + | cms_sites(:default).update_attribute(:hostname, 'example.com') |
| + | end |
| + | |
| + | def test_fixtures_disabled |
| + | assert_no_difference ['Cms::Layout.count', 'Cms::Page.count', 'Cms::Snippet.count'] do |
| + | get '/' |
| + | assert_response :success |
| + | |
| + | assert_equal 'Default Page', Cms::Page.root.label |
| + | assert_equal 'Default Layout', Cms::Layout.find_by_slug('default').label |
| + | assert_equal 'Default Snippet', Cms::Snippet.find_by_slug('default').label |
| + | end |
| + | end |
| + | |
| + | def test_fixtures_enabled |
| + | ComfortableMexicanSofa.config.enable_fixtures = true |
| + | Cms::Layout.destroy_all |
| + | Cms::Page.destroy_all |
| + | Cms::Snippet.destroy_all |
| + | |
| + | assert_difference 'Cms::Page.count', 2 do |
| + | assert_difference 'Cms::Layout.count', 2 do |
| + | assert_difference 'Cms::Snippet.count', 1 do |
| + | get '/' |
| + | assert_response :success |
| + | |
| + | assert_equal 'Home Fixture Page', Cms::Page.root.label |
| + | assert_equal 'Default Fixture Layout', Cms::Layout.find_by_slug('default').label |
| + | assert_equal 'Default Fixture Snippet', Cms::Snippet.find_by_slug('default').label |
| + | |
| + | assert_equal "<html>\n <body>\n Home Page Fixture Content\nFixture Content for Default Snippet\n </body>\n</html>", response.body |
| + | end |
| + | end |
| + | end |
| + | end |
| + | |
| + | end |
| \ No newline at end of file | |
test/unit/fixtures_test.rb
+1
-1
| @@ | @@ -92,7 +92,7 @@ class ViewMethodsTest < ActiveSupport::TestCase |
| assert page = Cms::Page.find_by_full_path('/') | |
| assert_equal 'index', page.slug | |
| - | assert_equal "<html>Home Page Fixture Content\n</html>", page.content |
| + | assert_equal "<html>Home Page Fixture Content\ndefault_snippet_content</html>", page.content |
| assert child_page = Cms::Page.find_by_full_path('/child') | |
| assert_equal page, child_page.parent | |