diff --git a/app/models/user.rb b/app/models/user.rb index a6cdc146..6e1097c9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 852d6141..94c225c5 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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