removing caching things, tests for base controller
Oleg
committed Jun 23, 2011
commit e18d971a4b186ce55a526566b2bf77c6bca02c34
Showing 11
changed files with
38 additions
and 29 deletions
app/controllers/cms_admin/base_controller.rb
+8
-2
| @@ | @@ -7,18 +7,24 @@ class CmsAdmin::BaseController < ApplicationController |
| before_filter :authenticate, | |
| :load_admin_site, | |
| - | :load_fixtures |
| + | :load_fixtures, |
| + | :except => :jump |
| layout 'cms_admin' | |
| def jump | |
| - | |
| + | path = ComfortableMexicanSofa.config.admin_route_redirect |
| + | return redirect_to(path) unless path.blank? |
| + | load_admin_site |
| + | redirect_to cms_admin_site_pages_path(@site) |
| end | |
| protected | |
| def load_admin_site | |
| @site = Cms::Site.find(params[:site_id]) | |
| + | rescue ActiveRecord::RecordNotFound => e |
| + | raise e unless @site = Cms::Site.first |
| rescue ActiveRecord::RecordNotFound | |
| flash[:error] = 'Site not found' | |
| return redirect_to(cms_admin_sites_path) | |
app/controllers/cms_content_controller.rb
+0
-2
| @@ | @@ -5,8 +5,6 @@ class CmsContentController < ApplicationController |
| before_filter :load_cms_page, :only => :render_html | |
| before_filter :load_cms_layout, :only => [:render_css, :render_js] | |
| - | caches_page :render_css, :render_js, :if => Proc.new { |c| ComfortableMexicanSofa.config.enable_caching } |
| - | |
| def render_html(status = 200) | |
| if layout = @cms_page.layout | |
| app_layout = layout.app_layout.blank?? false : layout.app_layout | |
app/models/cms/layout.rb
+2
-9
| @@ | @@ -12,8 +12,8 @@ class Cms::Layout < ActiveRecord::Base |
| # -- Callbacks ------------------------------------------------------------ | |
| before_validation :assign_label | |
| - | after_save :clear_cache, :clear_cached_page_content |
| - | after_destroy :clear_cache, :clear_cached_page_content |
| + | after_save :clear_cached_page_content |
| + | after_destroy :clear_cached_page_content |
| # -- Validations ---------------------------------------------------------- | |
| validates :site_id, | |
| @@ | @@ -71,13 +71,6 @@ protected |
| self.label = self.label.blank?? self.slug.try(:titleize) : self.label | |
| end | |
| - | # After saving need to make sure that cached pages for css and js for this |
| - | # layout and its children are gone. Good enough to avoid using cache sweepers. |
| - | def clear_cache |
| - | FileUtils.rm File.expand_path("cms-css/#{self.slug}.css", Rails.public_path), :force => true |
| - | FileUtils.rm File.expand_path("cms-js/#{self.slug}.js", Rails.public_path), :force => true |
| - | end |
| - | |
| # Forcing page content reload | |
| def clear_cached_page_content | |
| self.pages.each{ |page| page.save! } | |
app/views/cms_admin/sites/_form.html.erb
+1
-0
| @@ | @@ -1,6 +1,7 @@ |
| <%= form.text_field :label %> | |
| <%= form.text_field :hostname %> | |
| <%= form.text_field :path %> | |
| + | <%= form.text_field :locale %> |
| <%= form.check_box :is_mirrored, :label => 'Mirrored'%> | |
| <%= form.simple_field nil, nil, :class => 'submit_element' do %> | |
config/initializers/comfortable_mexican_sofa.rb
+3
-7
| @@ | @@ -11,19 +11,15 @@ ComfortableMexicanSofa.configure do |config| |
| # entirely set this to '' or nil | |
| # config.admin_route_prefix = 'cms-admin' | |
| - | # Path: /cms-admin redirects to /cms-admin/pages but you can change it |
| - | # config.admin_route_redirect = 'pages' |
| + | # When arriving at /cms-admin you may chose to redirect to arbirtary path, |
| + | # for example '/cms-admin/users' |
| + | # config.admin_route_redirect = '' |
| # By default you cannot have irb code inside your layouts/pages/snippets. | |
| # Generally this is to prevent putting something like this: | |
| # <% User.delete_all %> but if you really want to allow it... | |
| # config.allow_irb = false | |
| - | # Asset caching for CSS and JS for admin layout. This setting also controls |
| - | # page caching for CMS Layout CSS and Javascript. Enabled by default. When deploying |
| - | # to an environment with read-only filesystem (like Heroku) turn this setting off. |
| - | # config.enable_caching = true |
| - | |
| # File uploads use Paperclip and can support filesystem or s3 uploads. Override | |
| # the upload method and appropriate settings based on Paperclip. For S3 see: | |
| # http://rdoc.info/gems/paperclip/2.3.8/Paperclip/Storage/S3, and for | |
migrate/01_create_cms.rb b/db/migrate/01_create_cms.rb
+1
-0
| @@ | @@ -6,6 +6,7 @@ class CreateCms < ActiveRecord::Migration |
| t.string :label | |
| t.string :hostname | |
| t.string :path | |
| + | t.string :locale, :null => false, :default => 'en' |
| t.boolean :is_mirrored, :null => false, :default => false | |
| end | |
| add_index :cms_sites, :hostname | |
migrate/upgrades/04_upgrade_to_1_3_0.rb b/db/migrate/upgrades/04_upgrade_to_1_3_0.rb
+2
-0
| @@ | @@ -2,6 +2,7 @@ class UpgradeTo130 < ActiveRecord::Migration |
| def self.up | |
| add_column :cms_sites, :is_mirrored, :boolean, :null => false, :default => false | |
| add_column :cms_sites, :path, :string | |
| + | add_column :cms_sites, :locale, :string, :null_false, :default => 'en' |
| add_index :cms_sites, :is_mirrored | |
| end | |
| @@ | @@ -9,5 +10,6 @@ class UpgradeTo130 < ActiveRecord::Migration |
| remove_index :cms_sites, :is_mirrored | |
| remove_column :cms_sites, :path | |
| remove_column :cms_sites, :is_mirrored | |
| + | remove_column :cms_sites, :locale |
| end | |
| end | |
| \ No newline at end of file | |
comfortable_mexican_sofa/configuration.rb b/lib/comfortable_mexican_sofa/configuration.rb
+1
-5
| @@ | @@ -17,9 +17,6 @@ class ComfortableMexicanSofa::Configuration |
| # Not allowing irb code to be run inside page content. False by default. | |
| attr_accessor :allow_irb | |
| - | # Caching for css/js. For admin layout and ones for cms content. Enabled by default. |
| - | attr_accessor :enable_caching |
| - | |
| # Upload settings | |
| attr_accessor :upload_file_options | |
| @@ | @@ -39,10 +36,9 @@ class ComfortableMexicanSofa::Configuration |
| @authentication = 'ComfortableMexicanSofa::HttpAuth' | |
| @seed_data_path = nil | |
| @admin_route_prefix = 'cms-admin' | |
| - | @admin_route_redirect = 'pages' |
| + | @admin_route_redirect = '' |
| @enable_multiple_sites = false | |
| @allow_irb = false | |
| - | @enable_caching = true |
| @upload_file_options = {} | |
| @enable_fixtures = false | |
| @fixtures_path = File.expand_path('db/cms_fixtures', Rails.root) | |
test/functional/cms_admin/base_controller_test.rb
+18
-0
| @@ | @@ -0,0 +1,18 @@ |
| + | require File.expand_path('../../test_helper', File.dirname(__FILE__)) |
| + | |
| + | class CmsAdmin::BaseControllerTest < ActionController::TestCase |
| + | |
| + | def test_get_jump |
| + | get :jump |
| + | assert_response :redirect |
| + | assert_redirected_to cms_admin_site_pages_path(cms_sites(:default)) |
| + | end |
| + | |
| + | def test_get_jump_with_redirect_setting |
| + | ComfortableMexicanSofa.config.admin_route_redirect = '/cms-admin/sites' |
| + | get :jump |
| + | assert_response :redirect |
| + | assert_redirected_to '/cms-admin/sites' |
| + | end |
| + | |
| + | end |
| \ No newline at end of file | |
test/test_helper.rb
+1
-2
| @@ | @@ -17,9 +17,8 @@ class ActiveSupport::TestCase |
| config.cms_title = 'ComfortableMexicanSofa MicroCMS' | |
| config.authentication = 'ComfortableMexicanSofa::HttpAuth' | |
| config.admin_route_prefix = 'cms-admin' | |
| - | config.admin_route_redirect = 'pages' |
| + | config.admin_route_redirect = '' |
| config.allow_irb = false | |
| - | config.enable_caching = true |
| config.enable_fixtures = false | |
| config.fixtures_path = File.expand_path('db/cms_fixtures', Rails.root) | |
| config.revisions_limit = 25 | |
test/unit/configuration_test.rb
+1
-2
| @@ | @@ -7,9 +7,8 @@ class ConfigurationTest < ActiveSupport::TestCase |
| assert_equal 'ComfortableMexicanSofa MicroCMS', config.cms_title | |
| assert_equal 'ComfortableMexicanSofa::HttpAuth', config.authentication | |
| assert_equal 'cms-admin', config.admin_route_prefix | |
| - | assert_equal 'pages', config.admin_route_redirect |
| + | assert_equal '', config.admin_route_redirect |
| 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 | |
| assert_equal 25, config.revisions_limit | |