2019-04-10 10:53:52 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe Jobs::ActivationReminderEmails do
|
2019-04-10 11:40:11 -04:00
|
|
|
before { Jobs.run_immediately! }
|
|
|
|
|
|
|
|
# should be between 2 and 3 days
|
|
|
|
let(:created_at) { 50.hours.ago }
|
2019-04-10 10:53:52 -04:00
|
|
|
|
|
|
|
it 'should email inactive users' do
|
2019-04-10 11:40:11 -04:00
|
|
|
user = Fabricate(:user, active: false, created_at: created_at)
|
2019-04-10 10:53:52 -04:00
|
|
|
|
|
|
|
expect { described_class.new.execute({}) }
|
|
|
|
.to change { ActionMailer::Base.deliveries.size }.by(1)
|
|
|
|
.and change { user.email_tokens.count }.by(1)
|
|
|
|
|
|
|
|
expect(user.custom_fields['activation_reminder']).to eq("t")
|
|
|
|
expect { described_class.new.execute({}) }.to change { ActionMailer::Base.deliveries.size }.by(0)
|
|
|
|
|
|
|
|
user.activate
|
|
|
|
expect(user.reload.custom_fields['activation_reminder']).to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not email active users' do
|
2019-04-10 11:40:11 -04:00
|
|
|
user = Fabricate(:user, active: true, created_at: created_at)
|
|
|
|
|
|
|
|
expect { described_class.new.execute({}) }
|
|
|
|
.to change { ActionMailer::Base.deliveries.size }.by(0)
|
|
|
|
.and change { user.email_tokens.count }.by(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not email staged users' do
|
|
|
|
user = Fabricate(:user, active: false, staged: true, created_at: created_at)
|
2019-04-10 10:53:52 -04:00
|
|
|
|
|
|
|
expect { described_class.new.execute({}) }
|
|
|
|
.to change { ActionMailer::Base.deliveries.size }.by(0)
|
|
|
|
.and change { user.email_tokens.count }.by(0)
|
|
|
|
end
|
|
|
|
end
|