starting on new fixtures

Oleg committed Apr 17, 2011
commit 291ab95fb44d51b0d8300889e1b9b7161109ca25
Showing 7 changed files with 86 additions and 7 deletions
app/controllers/cms_content_controller.rb +6 -0
@@ @@ -1,6 +1,7 @@
class CmsContentController < ApplicationController
before_filter :load_cms_site
+ before_filter :load_fixtures
before_filter :load_cms_page, :only => :render_html
before_filter :load_cms_layout, :only => [:render_css, :render_js]
@@ @@ -21,6 +22,11 @@ class CmsContentController < ApplicationController
protected
+ def load_fixtures
+ return unless ComfortableMexicanSofa.config.enable_fixtures
+ ComfortableMexicanSofa::Fixtures.sync!
+ end
+
def load_cms_site
@cms_site = if ComfortableMexicanSofa.config.enable_multiple_sites
Cms::Site.find_by_hostname!(request.host.downcase)
comfortable_mexican_sofa.rb b/lib/comfortable_mexican_sofa.rb +2 -1
@@ @@ -7,7 +7,8 @@
'comfortable_mexican_sofa/view_methods',
'comfortable_mexican_sofa/form_builder',
'comfortable_mexican_sofa/acts_as_tree',
- 'comfortable_mexican_sofa/cms_tag'
+ 'comfortable_mexican_sofa/cms_tag',
+ 'comfortable_mexican_sofa/fixtures'
].each do |path|
require File.expand_path(path, File.dirname(__FILE__))
end
comfortable_mexican_sofa/configuration.rb b/lib/comfortable_mexican_sofa/configuration.rb +9 -4
@@ @@ -6,10 +6,6 @@ class ComfortableMexicanSofa::Configuration
# Module that will handle authentication to access cms-admin area
attr_accessor :authentication
- # Location of YAML files that can be used to render pages instead of pulling
- # data from the database. Not active if not specified.
- attr_accessor :seed_data_path
-
# Default url to access admin area is http://yourhost/cms-admin/
# You can change 'cms-admin' to 'admin', for example.
attr_accessor :admin_route_prefix
@@ @@ -30,6 +26,13 @@ class ComfortableMexicanSofa::Configuration
# Upload settings
attr_accessor :upload_file_options
+ # With each page load, files will be synched with the database. Database entries are
+ # destroyed if there's no corresponding file. Fixtures are disabled by default.
+ attr_accessor :enable_fixtures
+
+ # Path where fixtures can be located.
+ attr_accessor :fixtures_path
+
# Configuration defaults
def initialize
@cms_title = 'ComfortableMexicanSofa MicroCMS'
@@ @@ -41,6 +44,8 @@ class ComfortableMexicanSofa::Configuration
@allow_irb = false
@enable_caching = true
@upload_file_options = {}
+ @enable_fixtures = false
+ @fixtures_path = File.expand_path('db/cms_fixtures', Rails.root)
end
end
comfortable_mexican_sofa/fixtures.rb b/lib/comfortable_mexican_sofa/fixtures.rb +7 -0
@@ @@ -0,0 +1,7 @@
+ module ComfortableMexicanSofa::Fixtures
+
+ def self.sync!
+ raise 'hello'
+ end
+
+ end
\ No newline at end of file
test/integration/fixtures_test.rb +58 -0
@@ @@ -0,0 +1,58 @@
+ require File.expand_path('../test_helper', File.dirname(__FILE__))
+
+ class FixturesTest < ActionDispatch::IntegrationTest
+
+ def test_inactivity
+ assert_equal false, ComfortableMexicanSofa.config.enable_fixtures
+ assert_no_difference ['Cms::Layout.count', 'Cms::Page.count', 'Cms::Block.count', 'Cms::Snippet.count'] do
+ get '/'
+ assert_response :success
+ end
+ end
+
+ def test_initialization
+ ComfortableMexicanSofa.config.enable_fixtures = true
+ get '/'
+ end
+
+ def test_layout_file_update
+ flunk
+ end
+
+ def test_page_file_update
+ flunk
+ end
+
+ def test_snippet_file_update
+ flunk
+ end
+
+ def test_layout_file_removal
+ flunk
+ end
+
+ def test_page_file_removal
+ flunk
+ end
+
+ def test_snippet_file_removal
+ flunk
+ end
+
+ def test_layout_creation_failure
+ flunk
+ end
+
+ def test_page_creation_failure
+ flunk
+ end
+
+ def test_snippet_creation_failure
+ flunk
+ end
+
+ def test_single_site_path_option
+ flunk
+ end
+
+ end
\ No newline at end of file
test/test_helper.rb +2 -1
@@ @@ -16,12 +16,13 @@ class ActiveSupport::TestCase
ComfortableMexicanSofa.configure do |config|
config.cms_title = 'ComfortableMexicanSofa MicroCMS'
config.authentication = 'ComfortableMexicanSofa::HttpAuth'
- config.seed_data_path = nil
config.admin_route_prefix = 'cms-admin'
config.admin_route_redirect = "/cms-admin/pages"
config.enable_multiple_sites = false
config.allow_irb = false
config.enable_caching = true
+ config.enable_fixtures = false
+ config.fixtures_path = File.expand_path('db/cms_fixtures', Rails.root)
end
ComfortableMexicanSofa::HttpAuth.username = 'username'
ComfortableMexicanSofa::HttpAuth.password = 'password'
test/unit/cms_configuration_test.rb +2 -1
@@ @@ -6,12 +6,13 @@ class CmsConfigurationTest < ActiveSupport::TestCase
assert config = ComfortableMexicanSofa.configuration
assert_equal 'ComfortableMexicanSofa MicroCMS', config.cms_title
assert_equal 'ComfortableMexicanSofa::HttpAuth', config.authentication
- assert_equal nil, config.seed_data_path
assert_equal 'cms-admin', config.admin_route_prefix
assert_equal '/cms-admin/pages', config.admin_route_redirect
assert_equal false, config.enable_multiple_sites
assert_equal false, config.allow_irb
assert_equal true, config.enable_caching
+ assert_equal false, config.enable_fixtures
+ assert_equal File.expand_path('db/cms_fixtures', Rails.root), config.fixtures_path
end
def test_initialization_overrides