Writing some capybara integration/feature tests for my Rails 5 app & they keep failing b/c none of the JS loads. When I looked into it, I saw that in my test env, the script looks like this:
<script src="/assets/application.debug-c0cceddfe5721264a37a27717e21b167d46fd27617e66e210764c0dfd36b5992.js"></script>
But when it's loaded with selenium, the script looks like this:
<script src="http://127.0.0.1/assets_test/application-5c233b506cd224705939cbe7104615eba3c0f51d572dba60e074395a6346472a.js"></script>
Notice how it now has the host explicit. However, the test runs on a separate port, for example :56789, so the test JS doesn't load since the port isn't specified.
When I go to the link in the above src in the test environment, I get nothing. However, when I add the port number being used for this test, I see the JS file just fine.
What gives? To properly run my integration test, I need to be able to load this JS, and I'm at a complete loss on how to do that.
Here is my configuration:
test.rb
Rails.application.configure do
config.action_controller.asset_host = "file://#{::Rails.root}/public"
config.assets.prefix = 'assets_test'
config.action_controller.asset_host = "127.0.0.1"
config.serve_static_assets = true
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.cache_classes = false
config.action_view.cache_template_loading = true
config.eager_load = false
config.public_file_server.enabled = true
config.public_file_server.headers = {
'Cache-Control' => "public, max-age=#{1.hour.to_i}"
}
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.cache_store = :null_store
config.action_dispatch.show_exceptions = false
config.action_controller.allow_forgery_protection = false
config.active_storage.service = :test
config.action_mailer.perform_caching = false
config.action_mailer.delivery_method = :test
config.active_support.deprecation = :stderr
end
Figured it out. Commented these lines out and it works:
#config.action_controller.asset_host = "file://#{::Rails.root}/public"
#config.assets.prefix = 'assets_test'
#config.action_controller.asset_host = "127.0.0.1"
#config.serve_static_assets = true
Not sure how they ended up in my code in the first place.