adding config for auto tagging and disabling by default

Oleg committed Sep 21, 2011
commit 828cbd9aa6e295ffe90c66b8f5ee85b41ab19f8e
Showing 7 changed files with 53 additions and 26 deletions
app/models/cms/file.rb +1 -0
@@ @@ -34,6 +34,7 @@ protected
end
def categorize_file
+ return unless ComfortableMexicanSofa.config.auto_file_categorization
category = if layout_id && layout = site.layouts.find_by_id(layout_id)
Cms::Category.find_or_create_by_label_and_categorized_type("[layout] #{layout.slug}", 'Cms::File')
elsif page_id && page = site.pages.find_by_id(page_id)
config/initializers/comfortable_mexican_sofa.rb +4 -0
@@ @@ -59,6 +59,10 @@ ComfortableMexicanSofa.configure do |config|
# definition in your database.yml file
# config.database_config = nil
+ # When enabled files upload via the side widget will get automatically categorized for
+ # the current layout/page/snippet (as long as it's already saved). It's disabled by default.
+ # config.file_categorization = false
+
end
# Default credentials for ComfortableMexicanSofa::HttpAuth
comfortable_mexican_sofa/configuration.rb b/lib/comfortable_mexican_sofa/configuration.rb +19 -15
@@ @@ -49,23 +49,27 @@ class ComfortableMexicanSofa::Configuration
# in your database.yml file
attr_accessor :database_config
+ # When enabled files upload via the side widget will get automatically categorized for
+ # the current layout/page/snippet (as long as it's already saved). It's disabled by default.
+ attr_accessor :auto_file_categorization
+
# Configuration defaults
def initialize
- @cms_title = 'ComfortableMexicanSofa MicroCMS'
- @admin_auth = 'ComfortableMexicanSofa::HttpAuth'
- @public_auth = 'ComfortableMexicanSofa::DummyAuth'
- @seed_data_path = nil
- @admin_route_prefix = 'cms-admin'
- @admin_route_redirect = ''
- @enable_multiple_sites = false
- @allow_irb = false
- @upload_file_options = {}
- @enable_fixtures = false
- @fixtures_path = File.expand_path('db/cms_fixtures', Rails.root)
- @revisions_limit = 25
- @locales = { :en => 'English', :es => 'Español' }
- @admin_locale = nil
- @database_config = nil
+ @cms_title = 'ComfortableMexicanSofa MicroCMS'
+ @admin_auth = 'ComfortableMexicanSofa::HttpAuth'
+ @public_auth = 'ComfortableMexicanSofa::DummyAuth'
+ @seed_data_path = nil
+ @admin_route_prefix = 'cms-admin'
+ @admin_route_redirect = ''
+ @allow_irb = false
+ @upload_file_options = {}
+ @enable_fixtures = false
+ @fixtures_path = File.expand_path('db/cms_fixtures', Rails.root)
+ @revisions_limit = 25
+ @locales = { :en => 'English', :es => 'Español' }
+ @admin_locale = nil
+ @database_config = nil
+ @auto_file_categorization = false
end
end
test/functional/cms_admin/files_controller_test.rb +1 -0
@@ @@ -124,6 +124,7 @@ class CmsAdmin::FilesControllerTest < ActionController::TestCase
end
def test_create_as_xhr_with_page_id
+ ComfortableMexicanSofa.config.auto_file_categorization = true
request.env['HTTP_X_FILE_NAME'] = 'test.pdf'
request.env['CONTENT_TYPE'] = 'application/pdf'
test/test_helper.rb +12 -11
@@ @@ -16,17 +16,18 @@ class ActiveSupport::TestCase
# resetting default configuration
def reset_config
ComfortableMexicanSofa.configure do |config|
- config.cms_title = 'ComfortableMexicanSofa MicroCMS'
- config.admin_auth = 'ComfortableMexicanSofa::HttpAuth'
- config.public_auth = 'ComfortableMexicanSofa::DummyAuth'
- config.admin_route_prefix = 'cms-admin'
- config.admin_route_redirect = ''
- config.allow_irb = false
- config.enable_fixtures = false
- config.fixtures_path = File.expand_path('db/cms_fixtures', Rails.root)
- config.revisions_limit = 25
- config.locales = { :en => 'English', :es => 'Español' }
- config.admin_locale = nil
+ config.cms_title = 'ComfortableMexicanSofa MicroCMS'
+ config.admin_auth = 'ComfortableMexicanSofa::HttpAuth'
+ config.public_auth = 'ComfortableMexicanSofa::DummyAuth'
+ config.admin_route_prefix = 'cms-admin'
+ config.admin_route_redirect = ''
+ config.allow_irb = false
+ config.enable_fixtures = false
+ config.fixtures_path = File.expand_path('db/cms_fixtures', Rails.root)
+ config.revisions_limit = 25
+ config.locales = { :en => 'English', :es => 'Español' }
+ config.admin_locale = nil
+ config.auto_file_categorization = false
end
ComfortableMexicanSofa::HttpAuth.username = 'username'
ComfortableMexicanSofa::HttpAuth.password = 'password'
test/unit/configuration_test.rb +1 -0
@@ @@ -18,6 +18,7 @@ class ConfigurationTest < ActiveSupport::TestCase
assert_equal ({:en => 'English', :es => 'Español'}), config.locales
assert_equal nil, config.admin_locale
assert_equal nil, config.database_config
+ assert_equal false, config.auto_file_categorization
end
def test_initialization_overrides
test/unit/models/file_test.rb +15 -0
@@ @@ -25,7 +25,20 @@ class CmsFileTest < ActiveSupport::TestCase
end
end
+ def test_creation_with_layout_link_and_config_disabled
+ assert !ComfortableMexicanSofa.config.auto_file_categorization
+ assert_difference 'Cms::File.count' do
+ assert_no_difference ['Cms::Category.count', 'Cms::Categorization.count'] do
+ file = cms_sites(:default).files.create(
+ :file => fixture_file_upload('files/valid_image.jpg'),
+ :layout_id => cms_layouts(:default)
+ )
+ end
+ end
+ end
+
def test_creation_with_layout_link
+ ComfortableMexicanSofa.config.auto_file_categorization = true
assert_difference ['Cms::File.count', 'Cms::Category.count', 'Cms::Categorization.count'] do
file = cms_sites(:default).files.create(
:file => fixture_file_upload('files/valid_image.jpg'),
@@ @@ -38,6 +51,7 @@ class CmsFileTest < ActiveSupport::TestCase
end
def test_creation_with_page_link
+ ComfortableMexicanSofa.config.auto_file_categorization = true
assert_difference ['Cms::File.count', 'Cms::Category.count', 'Cms::Categorization.count'] do
file = cms_sites(:default).files.create(
:file => fixture_file_upload('files/valid_image.jpg'),
@@ @@ -50,6 +64,7 @@ class CmsFileTest < ActiveSupport::TestCase
end
def test_creation_with_snippet_link
+ ComfortableMexicanSofa.config.auto_file_categorization = true
assert_difference ['Cms::File.count', 'Cms::Category.count', 'Cms::Categorization.count'] do
file = cms_sites(:default).files.create(
:file => fixture_file_upload('files/valid_image.jpg'),