Browse Source

Wrap host lookup so it's easily stubbable

pull/566/head
baarkerlounger 3 years ago
parent
commit
4dcdc45a64
  1. 6
      app/models/user.rb
  2. 2
      spec/lib/tasks/onboarding_emails_spec.rb

6
app/models/user.rb

@ -83,11 +83,15 @@ class User < ApplicationRecord
DeviseNotifyMailer.new.send_email(email, template_id, personalisation)
end
def host
ENV["APP_HOST"]
end
def send_beta_onboarding_email
return unless URI::MailTo::EMAIL_REGEXP.match?(email)
template_id = BETA_ONBOARDING_TEMPLATE_ID
url = edit_user_password_url({ host: ENV["APP_HOST"] })
url = edit_user_password_url({ host: })
token = Devise.token_generator.generate(User, :reset_password_token)
personalisation = { name: name || email, link: "#{url}?reset_password_token=#{token}" }
DeviseNotifyMailer.new.send_email(email, template_id, personalisation)

2
spec/lib/tasks/onboarding_emails_spec.rb

@ -17,7 +17,7 @@ describe "rake onboarding_emails:send", type: task do
allow(devise_notify_mailer).to receive(:notify_client).and_return(notify_client)
allow(notify_client).to receive(:send_email).and_return(true)
allow(Devise.token_generator).to receive(:generate).and_return(reset_password_token)
allow(ENV).to receive(:[]).with("APP_HOST").and_return("http://localhost:3000")
allow(user).to receive(:host).and_return("http://localhost:3000")
end
context "when onboarding a new organisation to private beta" do

Loading…
Cancel
Save