Skip to content

Commit 5370346

Browse files
rafaelfrancaRafael Mendonça França
authored and
Rafael Mendonça França
committed
Merge pull request #140 from pomnikita/fix-assets-version
assets version doesn't depend on asset host if it's a Proc
1 parent 567d7bb commit 5370346

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/sprockets/railtie.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ def configure(&block)
7474
app.assets.version,
7575
config.assets.version,
7676
config.action_controller.relative_url_root,
77-
config.action_controller.asset_host,
78-
Sprockets::Rails::VERSION,
77+
(config.action_controller.asset_host unless config.action_controller.asset_host.respond_to?(:call)),
78+
Sprockets::Rails::VERSION
7979
].compact.join('-')
8080

8181
# Copy config.assets.paths to Sprockets

test/test_railtie.rb

+15-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def test_version
112112
assert_equal "test-v2-#{Sprockets::Rails::VERSION}", env.version
113113
end
114114

115-
def test_version_fragments
115+
def test_version_fragments_with_string_asset_host
116116
app.configure do
117117
config.assets.version = 'v2'
118118
config.action_controller.asset_host = 'http://some-cdn.com'
@@ -124,6 +124,20 @@ def test_version_fragments
124124
assert_equal "test-v2-some-path-http://some-cdn.com-#{Sprockets::Rails::VERSION}", env.version
125125
end
126126

127+
def test_version_fragments_with_proc_asset_host
128+
app.configure do
129+
config.assets.version = 'v2'
130+
config.action_controller.asset_host = ->(path, request) {
131+
'http://some-cdn.com'
132+
}
133+
config.action_controller.relative_url_root = 'some-path'
134+
end
135+
app.initialize!
136+
137+
assert env = app.assets
138+
assert_equal "test-v2-some-path-#{Sprockets::Rails::VERSION}", env.version
139+
end
140+
127141
def test_configure
128142
app.configure do
129143
config.assets.configure do |env|

0 commit comments

Comments
 (0)