Add tests for UserMailer URL generation helpers

pull/1154/head
Rick Carlino 2019-04-15 15:55:10 -07:00
parent c21fb485bb
commit 323fd29a8e
2 changed files with 17 additions and 6 deletions

View File

@ -1,5 +1,4 @@
class UserMailer < ApplicationMailer
RESET_PATH = "/verify/%s"
NOTHING_TO_CONFIRM = "FAILED EMAIL CHANGE"
URI_KLASS = ENV["FORCE_SSL"] ? URI::HTTPS : URI::HTTP
@ -32,17 +31,14 @@ class UserMailer < ApplicationMailer
def self.reset_url(user)
x = UserMailer.url_object
x.path = RESET_PATH % [user.confirmation_token]
x.path = "/verify/#{user.confirmation_token}"
x.to_s
end
def self.url_object(host = ENV.fetch("API_HOST"), port = ENV.fetch("API_PORT"))
output = {}
output[:host] = host
unless [nil, "443", "80"].include?(port)
output[:port] = port
end
output
output[:port] = port unless [nil, "443", "80"].include?(port)
URI_KLASS.build(output)
end
end

View File

@ -0,0 +1,15 @@
require "spec_helper"
describe UserMailer, type: :mailer do
let(:device) { FactoryBot.create(:device) }
it "generates appropriate URLs" do
no_port = UserMailer.url_object("altavista.com", nil)
ssl = UserMailer.url_object("altavista.com", "443")
basic = UserMailer.url_object("altavista.com", "80")
default = UserMailer.url_object("altavista.com", "3000")
expect(no_port.to_s).to eq("http://altavista.com")
expect(ssl.to_s).to eq("http://altavista.com")
expect(basic.to_s).to eq("http://altavista.com")
expect(default.to_s).to eq("http://altavista.com:3000")
end
end