Move welcome emails placement

This commit is contained in:
Eugene Burmakin 2025-08-26 16:37:21 +02:00
parent b9c1a5ccdb
commit 22daed7291
2 changed files with 10 additions and 1 deletions

View file

@ -18,7 +18,7 @@ class User < ApplicationRecord # rubocop:disable Metrics/ClassLength
after_create :create_api_key
after_commit :activate, on: :create, if: -> { DawarichSettings.self_hosted? }
after_commit :start_trial, on: :create, if: -> { !DawarichSettings.self_hosted? }
after_commit :schedule_welcome_emails, on: :create, if: -> { !DawarichSettings.self_hosted? }
before_save :sanitize_input
validates :email, presence: true
@ -140,6 +140,7 @@ class User < ApplicationRecord # rubocop:disable Metrics/ClassLength
def start_trial
update(status: :trial, active_until: 7.days.from_now)
schedule_welcome_emails
Users::TrialWebhookJob.perform_later(id)
end

View file

@ -75,6 +75,14 @@ RSpec.describe User, type: :model do
expect(Users::TrialWebhookJob).to receive(:perform_later).with(user.id)
user.send(:start_trial)
end
it 'schedules welcome emails' do
allow(user).to receive(:schedule_welcome_emails)
user.send(:start_trial)
expect(user).to have_received(:schedule_welcome_emails)
end
end
describe '#schedule_welcome_emails' do