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
|
# File 'lib/softwear/auth/spec.rb', line 8
def stub_authentication!(config, *a)
config.before(:each, *a) do
User.instance_variable_set(:@_spec_users, [])
allow(User).to receive(:all) { spec_users }
allow(User).to receive(:find) { |n| spec_users.find { |u| u.id.to_s == n.to_s } }
allow(User).to receive(:auth) { @_signed_in_user or false }
allow(User).to receive(:raw_query) { |q| raise "Unstubbed authentication query \"#{q}\"" }
allow(Figaro.env).to receive(:softwear_hub_url).and_return 'http://hub.example.com'
allow_any_instance_of(Softwear::Library::ControllerAuthentication)
.to receive(:user_token)
.and_return('')
if (controller rescue false)
controller.class_eval { helper Softwear::Auth::Helper }
allow(controller).to receive(:current_user) { @_signed_in_user }
controller.class_eval { helper_method :current_user }
allow(controller).to receive(:user_signed_in?) { !!@_signed_in_user }
controller.class_eval { helper_method :user_signed_in? }
allow(controller).to receive(:destroy_user_session_path) { '#' }
controller.class_eval { helper_method :destroy_user_session_path }
allow(controller).to receive(:users_path) { '#' }
controller.class_eval { helper_method :users_path }
allow(controller).to receive(:edit_user_path) { '#' }
controller.class_eval { protected; helper_method :edit_user_path }
end
end
config.after(:each, *a) do
User.instance_variable_set(:@_spec_users, nil)
end
end
|