-
Notifications
You must be signed in to change notification settings - Fork 234
/
two_factor_authenticatable_spec.rb
57 lines (45 loc) · 1.35 KB
/
two_factor_authenticatable_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require 'spec_helper'
require 'active_model'
class TwoFactorAuthenticatableDouble
extend ::ActiveModel::Callbacks
include ::ActiveModel::Validations::Callbacks
extend ::Devise::Models
# stub out the ::ActiveRecord::Encryption::EncryptableRecord API
attr_accessor :otp_secret
def self.encrypts(*attrs)
nil
end
define_model_callbacks :update
devise :two_factor_authenticatable
attr_accessor :consumed_timestep
def save(validate)
# noop for testing
true
end
end
describe ::Devise::Models::TwoFactorAuthenticatable do
it 'should be inserted prior to other devise modules' do
expect(Devise::ALL.first).to eq(:two_factor_authenticatable)
end
context 'When included in a class' do
subject { TwoFactorAuthenticatableDouble.new }
it_behaves_like 'two_factor_authenticatable'
end
end
describe ::Devise::Models::TwoFactorAuthenticatable do
context 'When clean_up_passwords is called ' do
subject { TwoFactorAuthenticatableDouble.new }
before :each do
subject.otp_attempt = 'foo'
subject.password_confirmation = 'foo'
end
it 'otp_attempt should be nill' do
subject.clean_up_passwords
expect(subject.otp_attempt).to be_nil
end
it 'password_confirmation should be nill' do
subject.clean_up_passwords
expect(subject.password_confirmation).to be_nil
end
end
end