Permalink
Browse files

Page cache is no longer a cvar, it uses the environment settings inst…

…ead. Closes #15
  • Loading branch information...
augustl committed Oct 8, 2009
1 parent 972dbaf commit 3b42d87c6c7b7711d18ae1b2f80d9e1aa4334816
Showing with 28 additions and 14 deletions.
  1. +0 −4 README.markdown
  2. +7 −4 lib/more.rb
  3. +21 −6 test/more_test.rb
View
@@ -83,10 +83,6 @@ More can compress your files by removing extra line breaks. This is enabled by d
Less::More.compression = true
-If you're on a read-only file system, you can turn page caching off and use Cache-Control headers. This option is on by default on Heroku (see separate section).
-
- Less::More.page_cache = false
-
More inserts headers in the generated CSS files, letting people know that the file is in fact generated and shouldn't be edited directly. This is by default only enabled in development mode. You can disable this behavior if you want to.
Less::More.header = false
View
@@ -12,13 +12,11 @@ class Less::More
"production" => {
:compression => true,
:header => false,
- :page_cache => true,
:destination_path => "stylesheets"
},
"development" => {
:compression => false,
:header => true,
- :page_cache => false,
:destination_path => "stylesheets"
}
}
@@ -38,9 +36,14 @@ def compression?
get_cvar(:compression)
end
- # TODO: Use controllers and page cache to generate the files.
+ # Check wether or not we should page cache the generated CSS
def page_cache?
- (not heroku?) && get_cvar(:page_cache)
+ (not heroku?) && page_cache_enabled_in_environment_configuration?
+ end
+
+ # For easy mocking.
+ def page_cache_enabled_in_environment_configuration?
+ Rails.configuration.action_controller.perform_caching
end
# Tells the plugin to prepend HEADER to all generated CSS, informing users
View
@@ -2,8 +2,10 @@
class MoreTest < Test::Unit::TestCase
def setup
- class << Less::More
- [:@compression, :@header, :@page_cache].each {|v| remove_instance_variable(v) if instance_variable_defined?(v) }
+ Less::More.class_eval do
+ ["@compression", "@header"].each {|v|
+ remove_instance_variable(v) if instance_variable_defined?(v)
+ }
end
end
@@ -22,12 +24,25 @@ def test_getting_config_from_current_environment_or_defaults_to_production
assert_equal 10, Less::More.get_cvar("foo")
end
- def test_cvar_gets_predesence_for_user_values
- Less::More::DEFAULTS["development"][:page_cache] = false
- assert_equal false, Less::More.page_cache?
+ def test_user_settings_wins_over_defaults
+ Less::More::DEFAULTS["development"][:compression] = true
+ assert_equal true, Less::More.compression?
- Less::More.page_cache = true
+ Less::More::DEFAULTS["development"][:compression] = false
+ assert_equal false, Less::More.compression?
+
+ Less::More.compression = true
+ assert_equal true, Less::More.compression?
+ end
+
+ def test_page_cache_is_read_from_environment_configs
+ Less::More.expects(:heroku?).returns(false).times(2)
+
+ Less::More.expects(:page_cache_enabled_in_environment_configuration?).returns(true)
assert_equal true, Less::More.page_cache?
+
+ Less::More.expects(:page_cache_enabled_in_environment_configuration?).returns(false)
+ assert_equal false, Less::More.page_cache?
end
def test_page_cache_off_on_heroku

0 comments on commit 3b42d87

Please sign in to comment.