Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple config.asset_host assignment from rails: #415

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/sprockets/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ def self.build_manifest(app)
Sprockets::Manifest.new(app.assets, path, config.assets.manifest)
end

config.after_initialize do |app|
config.action_controller.asset_host ||= app.config.asset_host
config.action_controller.relative_url_root ||= app.config.relative_url_root
end

config.after_initialize do |app|
config = app.config

Expand Down
14 changes: 14 additions & 0 deletions test/test_railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,18 @@ def test_quiet_assets_inserts_middleware
assert middleware.include?(Sprockets::Rails::QuietAssets)
assert middleware.each_cons(2).include?([Sprockets::Rails::QuietAssets, Rails::Rack::Logger])
end

def test_config_asset_host_can_be_set_inside_an_initializer
app.configure do
initializer 'asset_host_and_relative_url_root' do |app|
app.config.asset_host = 'https://example.com'
app.config.relative_url_root = '/myassets'
end
end
app.initialize!
context_class = Sprockets::Railtie.build_environment(app).context_class

assert_equal 'https://example.com', context_class.config.asset_host
assert_equal '/myassets', context_class.config.relative_url_root
end
end