Ensuring that test's URL methods are similar (#16348)

Prior to this commit, in test, we had two different answers to "what is
the host of this application?"  For Rails generates
URLs (e.g. `root_url`) we would get one answer.  For our custom
`URL.url("/")` we got another answer.

This resolves and patches that up.

Closes #16347
This commit is contained in:
Jeremy Friesen 2022-01-31 09:18:13 -05:00 committed by GitHub
parent df34cbbd7e
commit 4fa2d25924
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View file

@ -7,6 +7,8 @@ require "active_support/core_ext/integer/time"
# rubocop:disable Metrics/BlockLength
Rails.application.configure do
config.app_domain = ENV["APP_DOMAIN"] || "test.host"
# Settings specified here will take precedence over those in config/application.rb.
# cache_classes should be false when Spring is enabled, and true when it's disabled
@ -46,7 +48,7 @@ Rails.application.configure do
config.action_mailer.delivery_method = :test
# Additional setting to make test work. This is possibly useless and can be deleted.
config.action_mailer.default_url_options = { host: "test.host" }
config.action_mailer.default_url_options = { host: config.app_domain }
# Randomize the order test cases are executed.
config.active_support.test_order = :random
@ -92,5 +94,4 @@ Rails.application.configure do
end
end
# rubocop:enable Metrics/BlockLength
Rails.application.routes.default_url_options = { host: "test.host" }
Rails.application.routes.default_url_options = { host: Rails.application.config.app_domain }

View file

@ -4,6 +4,12 @@ RSpec.describe "all routes", type: :routing do
let(:podcast) { create(:podcast) }
let(:user) { create(:user) }
describe "#root_url" do
it "matches URL.url('/')" do
expect(root_url).to eq(URL.url("/"))
end
end
it "renders a podcast index if there is a podcast with the slug successfully" do
expect(get: "/#{podcast.slug}").to route_to(
controller: "stories",