Permalink
Browse files

Increment the `env.version` with `asset_host` and `relative_url_root`

This way such configurations will affect the asset fingerprints and
the environment cache, since they might affect the assets contents.
  • Loading branch information...
lucasmazza committed Jan 30, 2014
1 parent f7576e0 commit efb405fd9ddef355e4fb7461a69f23f20d5c815e
Showing with 22 additions and 2 deletions.
  1. +10 −2 lib/sprockets/railtie.rb
  2. +12 −0 test/test_railtie.rb
View
@@ -66,8 +66,16 @@ def configure(&block)
manifest_path = File.join(app.root, 'public', config.assets.prefix)
- unless config.assets.version.blank?
- app.assets.version += "-#{config.assets.version}"
+ # Configuration options that should invalidate
+ # the Sprockets cache when changed.
+ version_fragments = [
+ config.assets.version,
+ config.action_controller.relative_url_root,
+ config.action_controller.asset_host
+ ].compact.join('-')
+
+ if version_fragments.present?
+ app.assets.version += "-#{version_fragments}"
end
# Copy config.assets.paths to Sprockets
View
@@ -109,6 +109,18 @@ def test_version
assert_equal "test-v2", env.version
end
+ def test_version_fragments
+ app.configure do
+ config.assets.version = 'v2'
+ config.action_controller.asset_host = 'http://some-cdn.com'
+ config.action_controller.relative_url_root = 'some-path'
+ end
+ app.initialize!
+
+ assert env = app.assets
+ assert_equal "test-v2-some-path-http://some-cdn.com", env.version
+ end
+
def test_configure
app.configure do
config.assets.configure do |env|

0 comments on commit efb405f

Please sign in to comment.