Skip to content

Commit 17f4a3a

Browse files
committed
Copy over context settings in after initialize
1 parent 3cbb388 commit 17f4a3a

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

lib/sprockets/railtie.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ def assets
3434
env.context_class.class_eval do
3535
include ::Sprockets::Rails::Helper
3636
end
37-
env.context_class.assets_prefix = config.assets.prefix
38-
env.context_class.digest_assets = config.assets.digest
39-
env.context_class.config = config.action_controller
4037
end
4138

4239
@assets
@@ -84,9 +81,16 @@ def configure(&block)
8481
ActiveSupport.on_load(:action_view) do
8582
include Sprockets::Rails::Helper
8683

87-
self.debug_assets = app.config.assets.debug
88-
self.digest_assets = app.config.assets.digest
89-
self.assets_prefix = app.config.assets.prefix
84+
# Copy relevant config to AV context
85+
self.debug_assets = app.config.assets.debug
86+
self.digest_assets = app.config.assets.digest
87+
self.assets_prefix = app.config.assets.prefix
88+
89+
# Copy over to Sprockets as well
90+
context = app.assets.context_class
91+
context.assets_prefix = app.config.assets.prefix
92+
context.digest_assets = app.config.assets.digest
93+
context.config = app.config.action_controller
9094

9195
if app.config.assets.compile
9296
self.assets_environment = app.assets

test/test_railtie.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,13 @@ def test_action_view_helper
131131
assert_equal "/javascripts/xmlhr.js", @view.javascript_path("xmlhr")
132132
assert_equal "/assets/foo.js", @view.javascript_path("foo")
133133
end
134+
135+
def test_sprockets_context_helper
136+
app.initialize!
137+
138+
assert env = app.assets
139+
assert_equal "/assets", env.context_class.assets_prefix
140+
assert_equal false, env.context_class.digest_assets
141+
assert_equal nil, env.context_class.config.asset_host
142+
end
134143
end

0 commit comments

Comments
 (0)