diff --git a/app/models/user.rb b/app/models/user.rb index 83f09b605..c177acf90 100644 --- a/app/models/user.rb +++ b/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) diff --git a/spec/lib/tasks/onboarding_emails_spec.rb b/spec/lib/tasks/onboarding_emails_spec.rb index dc58a7944..c3848e0e0 100644 --- a/spec/lib/tasks/onboarding_emails_spec.rb +++ b/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