2015-10-11 04:41:23 -05:00
|
|
|
require 'rails_helper'
|
2015-08-24 01:21:34 -05:00
|
|
|
|
|
|
|
describe UserActivator do
|
|
|
|
|
|
|
|
describe 'email_activator' do
|
|
|
|
|
|
|
|
it 'does not create new email token unless required' do
|
|
|
|
SiteSetting.email_token_valid_hours = 24
|
|
|
|
user = Fabricate(:user)
|
|
|
|
activator = EmailActivator.new(user, nil, nil, nil)
|
|
|
|
|
2016-04-06 23:38:43 -05:00
|
|
|
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :signup, email_token: user.email_tokens.first.token))
|
2015-08-24 01:21:34 -05:00
|
|
|
activator.activate
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates and send new email token if the existing token expired' do
|
|
|
|
SiteSetting.email_token_valid_hours = 24
|
|
|
|
user = Fabricate(:user)
|
|
|
|
email_token = user.email_tokens.first
|
|
|
|
email_token.update_column(:created_at, 48.hours.ago)
|
|
|
|
activator = EmailActivator.new(user, nil, nil, nil)
|
|
|
|
|
2016-04-06 23:38:43 -05:00
|
|
|
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :signup))
|
|
|
|
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :signup, email_token: email_token.token)).never
|
2015-08-24 01:21:34 -05:00
|
|
|
activator.activate
|
|
|
|
|
|
|
|
user.reload
|
|
|
|
expect(user.email_tokens.last.created_at).to be_within_one_second_of(Time.zone.now)
|
|
|
|
end
|
2016-08-05 11:01:16 -05:00
|
|
|
|
2015-08-24 01:21:34 -05:00
|
|
|
end
|
|
|
|
end
|