We were duplicating the asset host and the URL host in all environments, but we can make it so the asset host uses the URL host unless we specifically set it. Note that, inside the `ApplicationMailer`, the `root_url` method already uses `default_url_options` to generate the URL. In the rare case of CONSUL installations who have changed the asset host, this change has no effect since they'll get a conflict in the environment files when upgrading and they'll choose to use their own asset host.
42 lines
1.1 KiB
Ruby
42 lines
1.1 KiB
Ruby
require "rails_helper"
|
|
|
|
describe ApplicationMailer do
|
|
describe "#set_asset_host" do
|
|
let(:mailer) { ApplicationMailer.new }
|
|
|
|
it "returns a host based on the default_url_options by default" do
|
|
allow(ActionMailer::Base).to receive(:default_url_options).and_return(host: "consul.dev")
|
|
|
|
mailer.set_asset_host
|
|
|
|
expect(mailer.asset_host).to eq "http://consul.dev"
|
|
end
|
|
|
|
it "considers options like port and protocol" do
|
|
allow(ActionMailer::Base).to receive(:default_url_options).and_return(
|
|
host: "localhost",
|
|
protocol: "https",
|
|
port: 3000
|
|
)
|
|
|
|
mailer.set_asset_host
|
|
|
|
expect(mailer.asset_host).to eq "https://localhost:3000"
|
|
end
|
|
|
|
it "returns the asset host when set manually" do
|
|
default_asset_host = ActionMailer::Base.asset_host
|
|
|
|
begin
|
|
ActionMailer::Base.asset_host = "http://consulassets.dev"
|
|
|
|
mailer.set_asset_host
|
|
|
|
expect(mailer.asset_host).to eq "http://consulassets.dev"
|
|
ensure
|
|
ActionMailer::Base.asset_host = default_asset_host
|
|
end
|
|
end
|
|
end
|
|
end
|