Module: Bouncer::TestHelpers

Defined in:
lib/bouncer-client/test_helpers.rb

Instance Method Summary collapse

Instance Method Details

#activation_token(device_id = SecureRandom.uuid) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/bouncer-client/test_helpers.rb', line 18

def activation_token device_id = SecureRandom.uuid
  token = valid_token
  activation = double("Bouncer::Activation")
  allow(activation).to receive(:id).and_return(SecureRandom.uuid)
  allow(activation).to receive(:device_id).and_return(device_id)
  allow(activation).to receive(:unit_id).and_return(SecureRandom.uuid)
  allow(activation).to receive(:user_id).and_return(SecureRandom.uuid)
  allow(token).to receive(:activation?).and_return(true)
  allow(token).to receive(:activation).and_return(activation)
  token
end

#super_admin_token(id = SecureRandom.uuid) ⇒ Object



3
4
5
6
7
# File 'lib/bouncer-client/test_helpers.rb', line 3

def super_admin_token id = SecureRandom.uuid
  token = user_token id
  allow(token.user).to receive(:super_admin?).and_return(true)
  token
end

#user_token(id = SecureRandom.uuid) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/bouncer-client/test_helpers.rb', line 9

def user_token id = SecureRandom.uuid
  token = valid_token
  allow(token).to receive(:user?).and_return(true)
  allow(token).to receive(:user).and_return(double "Bouncer::User")
  allow(token.user).to receive(:id).and_return(id)
  allow(token.user).to receive(:super_admin?).and_return(false)
  token
end

#valid_tokenObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/bouncer-client/test_helpers.rb', line 30

def valid_token
  token = double("Bouncer::Token")
  allow(token).to receive(:validate!).and_return(true)
  allow(token).to receive(:valid?).and_return(true)
  allow(token).to receive(:activation?)
  allow(token).to receive(:user?)
  allow(Bouncer::Token).to receive(:present?).and_return(true)
  allow(Bouncer::Token).to receive(:new).and_return(token)
  token
end