From 4fa2d25924284bd039d4b6b4c560c6420e5e7325 Mon Sep 17 00:00:00 2001 From: Jeremy Friesen Date: Mon, 31 Jan 2022 09:18:13 -0500 Subject: [PATCH] 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 --- config/environments/test.rb | 7 ++++--- spec/routing/all_routes_spec.rb | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/config/environments/test.rb b/config/environments/test.rb index d01e1be02..72ad06680 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -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 } diff --git a/spec/routing/all_routes_spec.rb b/spec/routing/all_routes_spec.rb index e25b7497b..3bc3c3ac9 100644 --- a/spec/routing/all_routes_spec.rb +++ b/spec/routing/all_routes_spec.rb @@ -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",