docbrown/spec/models/settings/smtp_spec.rb
Daniel Uber 3fb69eca20
Make smtp "domain" setting explicit (#14097)
When running tests locally (with an older version of the .env_sample
file as .env) I was seeing nil, rather than the empty string, when
running this spec. I determined the issue is that env vars
provided (but blank) are represented as empty strings, while env vars
not provided are returned as nil, and to avoid this dependence on the
environment file (at test time) it's better to provide the data you're
expecting (as we did for the other keys in the settings hash).
2021-07-12 09:22:37 -05:00

45 lines
1.8 KiB
Ruby

require "rails_helper"
RSpec.describe Settings::SMTP do
after do
described_class.clear_cache
end
describe "::settings" do
it "use default sendgrid config if SENDGRID_API_KEY is available" do
key = "something"
domain = "test.com"
allow(ApplicationConfig).to receive(:[]).with("SENDGRID_API_KEY").and_return(key)
ENV["SENDGRID_API_KEY"] = "something"
allow(Settings::General).to receive(:app_domain).and_return(domain)
expect(described_class.settings).to eq({
address: "smtp.sendgrid.net",
port: 587,
authentication: :plain,
user_name: "apikey",
password: key,
domain: domain
})
ENV["SENDGRID_API_KEY"] = nil
end
it "uses Settings::SMTP config if SENDGRID_API_KEY is not available" do
described_class.address = "smtp.google.com"
described_class.port = 25
described_class.authentication = "plain"
described_class.user_name = "username"
described_class.password = "password"
described_class.domain = "forem.local"
expect(described_class.settings).to eq({
address: "smtp.google.com",
port: 25,
authentication: "plain",
user_name: "username",
password: "password",
domain: "forem.local"
})
end
end
end