Skip to content

Commit 3698e1b

Browse files
committed
Only append custom version if given
1 parent 21bd2aa commit 3698e1b

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/sprockets/railtie.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def assets
1919
return @assets if defined? @assets
2020

2121
@assets = Sprockets::Environment.new(root.to_s) do |env|
22-
env.version = ::Rails.env + "-#{config.assets.version}"
22+
env.version = ::Rails.env
2323

2424
path = "#{config.root}/tmp/cache/assets/#{::Rails.env}"
2525
env.cache = Sprockets::Cache::FileStore.new(path)
@@ -50,7 +50,7 @@ def configure(&block)
5050
config.assets.paths = []
5151
config.assets.prefix = "/assets"
5252
config.assets.precompile = [LOOSE_APP_ASSETS, /(?:\/|\\|\A)application\.(css|js)$/]
53-
config.assets.version = ''
53+
config.assets.version = ""
5454
config.assets.debug = false
5555
config.assets.compile = true
5656
config.assets.digest = false
@@ -71,6 +71,10 @@ def configure(&block)
7171

7272
manifest_path = File.join(app.root, 'public', config.assets.prefix)
7373

74+
unless config.assets.version.blank?
75+
app.assets.version += "-#{config.assets.version}"
76+
end
77+
7478
# Copy config.assets.paths to Sprockets
7579
config.assets.paths.each do |path|
7680
app.assets.append_path path

test/test_railtie.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_defaults
4848
assert_kind_of Sprockets::Environment, env
4949

5050
assert_equal ROOT, env.root
51-
assert_equal "test-", env.version
51+
assert_equal "test", env.version
5252
assert env.cache
5353
assert_equal [], env.paths
5454
assert_nil env.js_compressor
@@ -99,6 +99,16 @@ def test_compressors
9999
assert_equal Sprockets::SassCompressor, env.css_compressor
100100
end
101101

102+
def test_version
103+
app.configure do
104+
config.assets.version = 'v2'
105+
end
106+
app.initialize!
107+
108+
assert env = app.assets
109+
assert_equal "test-v2", env.version
110+
end
111+
102112
def test_configure
103113
app.configure do
104114
config.assets.configure do |env|

0 commit comments

Comments
 (0)