devise_g5_authenticatable 0.3.0 → 1.0.0.pre.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -1
- data/.travis.yml +29 -7
- data/Appraisals +21 -0
- data/CHANGELOG.md +24 -0
- data/Gemfile +11 -7
- data/README.md +6 -6
- data/Rakefile +6 -5
- data/app/controllers/devise_g5_authenticatable/registrations_controller.rb +3 -0
- data/app/controllers/devise_g5_authenticatable/sessions_controller.rb +9 -5
- data/config/initializers/devise_g5_authenticatable.rb +2 -0
- data/devise_g5_authenticatable.gemspec +6 -5
- data/gemfiles/rails_4.1.gemfile +26 -0
- data/gemfiles/rails_4.2.gemfile +26 -0
- data/gemfiles/rails_5.0.gemfile +26 -0
- data/gemfiles/rails_5.1.gemfile +26 -0
- data/lib/devise_g5_authenticatable/controllers/helpers.rb +5 -0
- data/lib/devise_g5_authenticatable/controllers/url_helpers.rb +3 -0
- data/lib/devise_g5_authenticatable/engine.rb +4 -1
- data/lib/devise_g5_authenticatable/g5/auth_password_validator.rb +6 -1
- data/lib/devise_g5_authenticatable/g5/auth_user_creator.rb +16 -15
- data/lib/devise_g5_authenticatable/g5/auth_user_updater.rb +11 -5
- data/lib/devise_g5_authenticatable/g5/user_exporter.rb +11 -6
- data/lib/devise_g5_authenticatable/g5.rb +2 -0
- data/lib/devise_g5_authenticatable/hooks/g5_authenticatable.rb +8 -3
- data/lib/devise_g5_authenticatable/models/g5_authenticatable.rb +38 -26
- data/lib/devise_g5_authenticatable/models/protected_attributes.rb +11 -2
- data/lib/devise_g5_authenticatable/omniauth.rb +8 -2
- data/lib/devise_g5_authenticatable/routes.rb +48 -35
- data/lib/devise_g5_authenticatable/version.rb +3 -1
- data/lib/devise_g5_authenticatable.rb +4 -1
- data/spec/controllers/helpers_spec.rb +54 -49
- data/spec/controllers/sessions_controller_spec.rb +67 -39
- data/spec/controllers/url_helpers_spec.rb +78 -78
- data/spec/dummy/app/views/{anonymous → devise}/new.html.erb +0 -0
- data/spec/dummy/config/environments/test.rb +20 -4
- data/spec/dummy/config/initializers/devise.rb +5 -1
- data/spec/dummy/config/initializers/rails_compatibility.rb +10 -0
- data/spec/dummy/db/migrate/20131230235849_devise_create_users.rb +3 -1
- data/spec/dummy/db/migrate/20140102213131_drop_database_authenticatable.rb +3 -1
- data/spec/dummy/db/migrate/20140103032308_drop_recoverable.rb +3 -1
- data/spec/dummy/db/migrate/20140103042329_drop_rememberable.rb +3 -1
- data/spec/dummy/db/migrate/20140103174810_add_omniauth_columns_to_users.rb +3 -1
- data/spec/dummy/db/migrate/20140103191601_add_email_back_to_user.rb +3 -1
- data/spec/dummy/db/migrate/20140113202948_devise_create_admins.rb +3 -1
- data/spec/dummy/db/migrate/20140113233821_add_provider_and_uid_to_admins.rb +3 -1
- data/spec/dummy/db/schema.rb +29 -29
- data/spec/factories/admin.rb +2 -0
- data/spec/factories/user.rb +2 -0
- data/spec/features/edit_registration_spec.rb +22 -13
- data/spec/features/registration_spec.rb +13 -8
- data/spec/features/sign_in_spec.rb +4 -2
- data/spec/features/sign_out_spec.rb +4 -2
- data/spec/features/token_validation_spec.rb +24 -14
- data/spec/g5/auth_password_validator_spec.rb +28 -15
- data/spec/g5/auth_user_creator_spec.rb +29 -22
- data/spec/g5/auth_user_updater_spec.rb +23 -16
- data/spec/g5/user_exporter_spec.rb +36 -31
- data/spec/models/g5_authenticatable_spec.rb +78 -38
- data/spec/models/protected_attributes_spec.rb +24 -19
- data/spec/rails_helper.rb +46 -0
- data/spec/routing/registrations_routing_spec.rb +43 -27
- data/spec/routing/sessions_routing_spec.rb +46 -29
- data/spec/spec_helper.rb +93 -27
- data/spec/support/controller_test_helpers.rb +15 -0
- data/spec/support/devise.rb +9 -1
- data/spec/support/shared_contexts/custom_router.rb +16 -0
- data/spec/support/shared_contexts/oauth_error.rb +4 -2
- data/spec/support/shared_contexts/rake.rb +10 -4
- data/spec/support/shared_examples/registration_error.rb +3 -1
- data/spec/support/{user_feature_methods.rb → user_omniauth_methods.rb} +9 -5
- data/spec/tasks/export_users_spec.rb +5 -3
- metadata +30 -26
- data/circle.yml +0 -4
- data/spec/support/omniauth.rb +0 -3
@@ -1,68 +1,82 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
RSpec.describe 'Registrations controller' do
|
4
6
|
describe 'routing' do
|
5
7
|
context 'with user scope' do
|
6
8
|
it 'should route GET /users/sign_up' do
|
7
|
-
expect(get
|
8
|
-
|
9
|
+
expect(get('/users/sign_up'))
|
10
|
+
.to route_to(controller: 'devise_g5_authenticatable/registrations',
|
11
|
+
action: 'new')
|
9
12
|
end
|
10
13
|
|
11
14
|
it 'should route POST /users' do
|
12
|
-
expect(post
|
13
|
-
|
15
|
+
expect(post('/users'))
|
16
|
+
.to route_to(controller: 'devise_g5_authenticatable/registrations',
|
17
|
+
action: 'create')
|
14
18
|
end
|
15
19
|
|
16
20
|
it 'should route GET /users/edit' do
|
17
|
-
expect(get
|
18
|
-
|
21
|
+
expect(get('/users/edit'))
|
22
|
+
.to route_to(controller: 'devise_g5_authenticatable/registrations',
|
23
|
+
action: 'edit')
|
19
24
|
end
|
20
25
|
|
21
26
|
it 'should route PUT /users' do
|
22
|
-
expect(put
|
27
|
+
expect(put('/users'))
|
28
|
+
.to route_to(controller: 'devise_g5_authenticatable/registrations',
|
23
29
|
action: 'update')
|
24
30
|
end
|
25
31
|
|
26
32
|
it 'should route DELETE /users' do
|
27
|
-
expect(delete
|
28
|
-
|
33
|
+
expect(delete('/users'))
|
34
|
+
.to route_to(controller: 'devise_g5_authenticatable/registrations',
|
35
|
+
action: 'destroy')
|
29
36
|
end
|
30
37
|
|
31
38
|
it 'should route GET /users/cancel' do
|
32
|
-
expect(get
|
33
|
-
|
39
|
+
expect(get('/users/cancel'))
|
40
|
+
.to route_to(controller: 'devise_g5_authenticatable/registrations',
|
41
|
+
action: 'cancel')
|
34
42
|
end
|
35
43
|
end
|
36
44
|
|
37
45
|
context 'with admin scope' do
|
38
46
|
it 'should route GET /registered/admins/custom_sign_up' do
|
39
|
-
expect(get
|
40
|
-
|
47
|
+
expect(get('/registered/admins/custom_sign_up'))
|
48
|
+
.to route_to(controller: 'custom_registrations',
|
49
|
+
action: 'new')
|
41
50
|
end
|
42
51
|
|
43
52
|
it 'should route POST /registered/admins' do
|
44
|
-
expect(post
|
45
|
-
|
53
|
+
expect(post('/registered/admins'))
|
54
|
+
.to route_to(controller: 'custom_registrations',
|
55
|
+
action: 'create')
|
46
56
|
end
|
47
57
|
|
48
58
|
it 'should route GET /registered/admins/edit' do
|
49
|
-
expect(get
|
50
|
-
|
59
|
+
expect(get('/registered/admins/edit'))
|
60
|
+
.to route_to(controller: 'custom_registrations',
|
61
|
+
action: 'edit')
|
51
62
|
end
|
52
63
|
|
53
64
|
it 'should route PUT /registered/admins' do
|
54
|
-
expect(put
|
55
|
-
|
65
|
+
expect(put('/registered/admins'))
|
66
|
+
.to route_to(controller: 'custom_registrations',
|
67
|
+
action: 'update')
|
56
68
|
end
|
57
69
|
|
58
70
|
it 'should route DELETE /registered/admins' do
|
59
|
-
expect(delete
|
60
|
-
|
71
|
+
expect(delete('/registered/admins'))
|
72
|
+
.to route_to(controller: 'custom_registrations',
|
73
|
+
action: 'destroy')
|
61
74
|
end
|
62
75
|
|
63
76
|
it 'should route GET /registered/admins/custom_cancel' do
|
64
|
-
expect(get
|
65
|
-
|
77
|
+
expect(get('/registered/admins/custom_cancel'))
|
78
|
+
.to route_to(controller: 'custom_registrations',
|
79
|
+
action: 'cancel')
|
66
80
|
end
|
67
81
|
end
|
68
82
|
end
|
@@ -88,7 +102,8 @@ describe 'Registrations controller' do
|
|
88
102
|
|
89
103
|
context 'with admin scope' do
|
90
104
|
it 'should generate new_admin_registration_path' do
|
91
|
-
expect(new_admin_registration_path)
|
105
|
+
expect(new_admin_registration_path)
|
106
|
+
.to eq('/registered/admins/custom_sign_up')
|
92
107
|
end
|
93
108
|
|
94
109
|
it 'should generate admin_registration_path' do
|
@@ -100,7 +115,8 @@ describe 'Registrations controller' do
|
|
100
115
|
end
|
101
116
|
|
102
117
|
it 'should generate cancel_admin_registration_path' do
|
103
|
-
expect(cancel_admin_registration_path)
|
118
|
+
expect(cancel_admin_registration_path)
|
119
|
+
.to eq('/registered/admins/custom_cancel')
|
104
120
|
end
|
105
121
|
end
|
106
122
|
end
|
@@ -1,36 +1,44 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
RSpec.describe 'Sessions controller' do
|
4
6
|
describe 'routing' do
|
5
7
|
context 'with user scope' do
|
6
8
|
it 'should route GET /users/sign_in' do
|
7
|
-
expect(get
|
8
|
-
|
9
|
+
expect(get('/users/sign_in'))
|
10
|
+
.to route_to(controller: 'devise_g5_authenticatable/sessions',
|
11
|
+
action: 'new')
|
9
12
|
end
|
10
13
|
|
11
14
|
it 'should route DELETE /users/sign_out' do
|
12
|
-
expect(delete
|
13
|
-
|
15
|
+
expect(delete('/users/sign_out'))
|
16
|
+
.to route_to(controller: 'devise_g5_authenticatable/sessions',
|
17
|
+
action: 'destroy')
|
14
18
|
end
|
15
19
|
|
16
20
|
it 'should route GET /users/auth/g5' do
|
17
|
-
expect(get
|
18
|
-
|
21
|
+
expect(get('/users/auth/g5'))
|
22
|
+
.to route_to(controller: 'devise_g5_authenticatable/sessions',
|
23
|
+
action: 'omniauth_passthru')
|
19
24
|
end
|
20
25
|
|
21
26
|
it 'should route POST /users/auth/g5' do
|
22
|
-
expect(post
|
23
|
-
|
27
|
+
expect(post('/users/auth/g5'))
|
28
|
+
.to route_to(controller: 'devise_g5_authenticatable/sessions',
|
29
|
+
action: 'omniauth_passthru')
|
24
30
|
end
|
25
31
|
|
26
32
|
it 'should route GET /users/auth/g5/callback' do
|
27
|
-
expect(get
|
28
|
-
|
33
|
+
expect(get('/users/auth/g5/callback'))
|
34
|
+
.to route_to(controller: 'devise_g5_authenticatable/sessions',
|
35
|
+
action: 'create')
|
29
36
|
end
|
30
37
|
|
31
38
|
it 'should route POST /users/auth/g5/callback' do
|
32
|
-
expect(post
|
33
|
-
|
39
|
+
expect(post('/users/auth/g5/callback'))
|
40
|
+
.to route_to(controller: 'devise_g5_authenticatable/sessions',
|
41
|
+
action: 'create')
|
34
42
|
end
|
35
43
|
|
36
44
|
it 'should set the OmniAuth path prefix' do
|
@@ -40,33 +48,39 @@ describe 'Sessions controller' do
|
|
40
48
|
|
41
49
|
context 'with admin scope' do
|
42
50
|
it 'should route GET /registered/admins/custom_sign_in' do
|
43
|
-
expect(get
|
44
|
-
|
51
|
+
expect(get('/registered/admins/custom_sign_in'))
|
52
|
+
.to route_to(controller: 'custom_sessions',
|
53
|
+
action: 'new')
|
45
54
|
end
|
46
55
|
|
47
56
|
it 'should route DELETE /registered/admins/custom_sign_out' do
|
48
|
-
expect(delete
|
49
|
-
|
57
|
+
expect(delete('/registered/admins/custom_sign_out'))
|
58
|
+
.to route_to(controller: 'custom_sessions',
|
59
|
+
action: 'destroy')
|
50
60
|
end
|
51
61
|
|
52
62
|
it 'should route GET /registered/admins/auth/g5' do
|
53
|
-
expect(get
|
54
|
-
|
63
|
+
expect(get('/registered/admins/auth/g5'))
|
64
|
+
.to route_to(controller: 'custom_sessions',
|
65
|
+
action: 'omniauth_passthru')
|
55
66
|
end
|
56
67
|
|
57
68
|
it 'should route POST /registered/admins/auth/g5' do
|
58
|
-
expect(post
|
59
|
-
|
69
|
+
expect(post('/registered/admins/auth/g5'))
|
70
|
+
.to route_to(controller: 'custom_sessions',
|
71
|
+
action: 'omniauth_passthru')
|
60
72
|
end
|
61
73
|
|
62
74
|
it 'should route GET /registered/admins/auth/g5/callback' do
|
63
|
-
expect(get
|
64
|
-
|
75
|
+
expect(get('/registered/admins/auth/g5/callback'))
|
76
|
+
.to route_to(controller: 'custom_sessions',
|
77
|
+
action: 'create')
|
65
78
|
end
|
66
79
|
|
67
80
|
it 'should route POST /registered/admins/auth/g5/callback' do
|
68
|
-
expect(post
|
69
|
-
|
81
|
+
expect(post('/registered/admins/auth/g5/callback'))
|
82
|
+
.to route_to(controller: 'custom_sessions',
|
83
|
+
action: 'create')
|
70
84
|
end
|
71
85
|
end
|
72
86
|
end
|
@@ -92,11 +106,13 @@ describe 'Sessions controller' do
|
|
92
106
|
|
93
107
|
context 'with admin scope' do
|
94
108
|
it 'should route new_admin_session_path' do
|
95
|
-
expect(new_admin_session_path)
|
109
|
+
expect(new_admin_session_path)
|
110
|
+
.to eq('/registered/admins/custom_sign_in')
|
96
111
|
end
|
97
112
|
|
98
113
|
it 'should route destroy_admin_session_path' do
|
99
|
-
expect(destroy_admin_session_path)
|
114
|
+
expect(destroy_admin_session_path)
|
115
|
+
.to eq('/registered/admins/custom_sign_out')
|
100
116
|
end
|
101
117
|
|
102
118
|
it 'should generate admin_g5_authorize_path' do
|
@@ -104,7 +120,8 @@ describe 'Sessions controller' do
|
|
104
120
|
end
|
105
121
|
|
106
122
|
it 'should generate admin_g5_callback_path' do
|
107
|
-
expect(admin_g5_callback_path)
|
123
|
+
expect(admin_g5_callback_path)
|
124
|
+
.to eq('/registered/admins/auth/g5/callback')
|
108
125
|
end
|
109
126
|
end
|
110
127
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,46 +1,112 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
|
4
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
5
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
6
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
7
|
+
# files.
|
8
|
+
#
|
9
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
10
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
11
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
12
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
13
|
+
# a separate helper file that requires the additional dependencies and performs
|
14
|
+
# the additional setup, and require it from the spec files that actually need
|
15
|
+
# it.
|
16
|
+
#
|
17
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
18
|
+
# users commonly want.
|
19
|
+
#
|
20
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
21
|
+
|
1
22
|
# Setup for test coverage instrumentation (e.g. simplecov, codeclimate)
|
2
23
|
# MUST happen before any other code is loaded
|
3
24
|
require 'simplecov'
|
4
|
-
SimpleCov.start 'test_frameworks'
|
5
25
|
|
6
|
-
|
7
|
-
|
26
|
+
# save to CircleCI's artifacts directory if we're on CircleCI
|
27
|
+
if ENV['CIRCLE_ARTIFACTS']
|
28
|
+
dir = File.join(ENV['CIRCLE_ARTIFACTS'], 'coverage')
|
29
|
+
SimpleCov.coverage_dir(dir)
|
30
|
+
end
|
31
|
+
|
32
|
+
SimpleCov.start('rails')
|
8
33
|
|
9
34
|
require 'pry'
|
10
35
|
|
11
|
-
|
12
|
-
|
13
|
-
|
36
|
+
RSpec.configure do |config|
|
37
|
+
# rspec-expectations config goes here. You can use an alternate
|
38
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
39
|
+
# assertions if you prefer.
|
40
|
+
config.expect_with :rspec do |expectations|
|
41
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
42
|
+
# and `failure_message` of custom matchers include text for helper methods
|
43
|
+
# defined using `chain`, e.g.:
|
44
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
45
|
+
# # => "be bigger than 2 and smaller than 4"
|
46
|
+
# ...rather than:
|
47
|
+
# # => "be bigger than 2"
|
48
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
49
|
+
end
|
50
|
+
|
51
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
52
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
53
|
+
config.mock_with :rspec do |mocks|
|
54
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
55
|
+
# a real object. This is generally recommended, and will default to
|
56
|
+
# `true` in RSpec 4.
|
57
|
+
mocks.verify_partial_doubles = true
|
58
|
+
end
|
14
59
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
60
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
61
|
+
# have no way to turn it off -- the option exists only for backwards
|
62
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
63
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
64
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
65
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
20
66
|
|
21
|
-
#
|
22
|
-
|
67
|
+
# This allows you to limit a spec run to individual examples or groups
|
68
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
69
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
70
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
71
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
72
|
+
config.filter_run_when_matching :focus
|
23
73
|
|
24
|
-
RSpec
|
25
|
-
|
74
|
+
# Allows RSpec to persist some state between runs in order to support
|
75
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
76
|
+
# you configure your source control system to ignore this file.
|
77
|
+
# config.example_status_persistence_file_path = 'spec/examples.txt'
|
78
|
+
|
79
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
80
|
+
# recommended. For more details, see:
|
81
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
82
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
83
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
84
|
+
config.disable_monkey_patching!
|
26
85
|
|
27
|
-
|
86
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
87
|
+
# file, and it's useful to allow more verbose output when running an
|
88
|
+
# individual spec file.
|
89
|
+
if config.files_to_run.one?
|
90
|
+
# Use the documentation formatter for detailed output,
|
91
|
+
# unless a formatter has already been configured
|
92
|
+
# (e.g. via a command-line flag).
|
93
|
+
config.default_formatter = 'doc'
|
94
|
+
end
|
28
95
|
|
29
|
-
|
30
|
-
|
31
|
-
|
96
|
+
# Print the 10 slowest examples and example groups at the
|
97
|
+
# end of the spec run, to help surface which specs are running
|
98
|
+
# particularly slow.
|
99
|
+
# config.profile_examples = 10
|
32
100
|
|
33
101
|
# Run specs in random order to surface order dependencies. If you find an
|
34
102
|
# order dependency and want to debug it, you can fix the order by providing
|
35
103
|
# the seed, which is printed after each run.
|
36
104
|
# --seed 1234
|
37
|
-
config.order =
|
38
|
-
|
39
|
-
# The integration tests can be run with:
|
40
|
-
# rspec -t type:feature
|
41
|
-
# config.filter_run_excluding type: 'feature'
|
42
|
-
|
43
|
-
config.after(:suite) { WebMock.disable! }
|
105
|
+
config.order = :random
|
44
106
|
|
45
|
-
|
107
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
108
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
109
|
+
# test failures related to randomization by passing the same `--seed` value
|
110
|
+
# as the one that triggered the failure.
|
111
|
+
Kernel.srand config.seed
|
46
112
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ControllerTestHelpers
|
4
|
+
def build_params(hash)
|
5
|
+
if Rails.version.starts_with?('4')
|
6
|
+
hash
|
7
|
+
else
|
8
|
+
{ params: hash }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.include ControllerTestHelpers, type: :controller
|
15
|
+
end
|
data/spec/support/devise.rb
CHANGED
@@ -1,4 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.configure do |config|
|
2
4
|
config.before(:each) { Devise.g5_strict_token_validation = false }
|
3
|
-
|
5
|
+
|
6
|
+
config.include Devise::Test::ControllerHelpers, type: :controller
|
7
|
+
config.include Devise::Test::ControllerHelpers, type: :view
|
8
|
+
|
9
|
+
# We're only adding the integration test helpers to request specs
|
10
|
+
# because the feature specs use the omniauth helpers instead
|
11
|
+
config.include Devise::Test::IntegrationHelpers, type: :request
|
4
12
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.shared_context 'custom router' do
|
4
|
+
before { Devise.router_name = :my_engine }
|
5
|
+
after { Devise.router_name = nil }
|
6
|
+
|
7
|
+
let(:custom_router) { double(:my_engine_router) }
|
8
|
+
|
9
|
+
controller do
|
10
|
+
def my_engine; end
|
11
|
+
end
|
12
|
+
|
13
|
+
before do
|
14
|
+
allow(controller).to receive(:my_engine).and_return(custom_router)
|
15
|
+
end
|
16
|
+
end
|
@@ -1,8 +1,10 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.shared_context 'OAuth2::Error' do
|
2
4
|
let(:oauth_error) { OAuth2::Error.new(oauth_response) }
|
3
5
|
let(:oauth_response) do
|
4
6
|
double(:oauth_response,
|
5
|
-
parsed: {'error' => error_message}).as_null_object
|
7
|
+
parsed: { 'error' => error_message }).as_null_object
|
6
8
|
end
|
7
9
|
|
8
10
|
let(:error_message) { 'Validation failed: Email is already taken' }
|
@@ -1,21 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Based on: http://robots.thoughtbot.com/test-rake-tasks-like-a-boss
|
2
4
|
# Modified for a non-Rails environment
|
3
5
|
require 'rake'
|
4
6
|
|
5
|
-
shared_context 'rake' do
|
7
|
+
RSpec.shared_context 'rake' do
|
6
8
|
let(:rake) { Rake::Application.new }
|
7
9
|
let(:task_name) { self.class.top_level_description }
|
8
|
-
let(:task_path)
|
10
|
+
let(:task_path) do
|
11
|
+
"lib/tasks/#{task_name.split(':').first}/#{task_name.split(':').last}"
|
12
|
+
end
|
9
13
|
let(:root_path) { File.expand_path('../../../..', __FILE__) }
|
10
14
|
subject(:task) { rake[task_name] }
|
11
15
|
|
12
16
|
def loaded_files_excluding_current_rake_file
|
13
|
-
$
|
17
|
+
$LOADED_FEATURES.reject { |file| file =~ /#{task_path}\.rake$/ }
|
14
18
|
end
|
15
19
|
|
16
20
|
before do
|
17
21
|
Rake.application = rake
|
18
|
-
Rake.application.rake_require(task_path,
|
22
|
+
Rake.application.rake_require(task_path,
|
23
|
+
[root_path],
|
24
|
+
loaded_files_excluding_current_rake_file)
|
19
25
|
Rake::Task.define_task(:environment)
|
20
26
|
end
|
21
27
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UserOmniauthMethods
|
4
|
+
def stub_g5_omniauth(user, options = {})
|
3
5
|
OmniAuth.config.mock_auth[:g5] = OmniAuth::AuthHash.new({
|
4
6
|
uid: user.uid,
|
5
7
|
provider: 'g5',
|
6
|
-
info: {email: user.email},
|
7
|
-
credentials: {token: user.g5_access_token}
|
8
|
+
info: { email: user.email },
|
9
|
+
credentials: { token: user.g5_access_token }
|
8
10
|
}.merge(options))
|
9
11
|
end
|
10
12
|
|
@@ -19,11 +21,13 @@ module UserFeatureMethods
|
|
19
21
|
end
|
20
22
|
|
21
23
|
RSpec.configure do |config|
|
24
|
+
config.before(:all) { OmniAuth.config.logger = Logger.new('/dev/null') }
|
25
|
+
|
22
26
|
config.before(:each) do
|
23
27
|
OmniAuth.config.test_mode = true
|
24
28
|
OmniAuth.config.mock_auth[:g5] = nil
|
25
29
|
end
|
26
30
|
config.after(:each) { OmniAuth.config.test_mode = false }
|
27
31
|
|
28
|
-
config.include
|
32
|
+
config.include UserOmniauthMethods, type: :feature
|
29
33
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
RSpec.describe 'g5:export_users' do
|
4
6
|
include_context 'rake'
|
5
7
|
|
6
8
|
let(:user_exporter) { double(:user_exporter, export: nil) }
|
@@ -43,7 +45,7 @@ describe 'g5:export_users' do
|
|
43
45
|
task.invoke
|
44
46
|
end
|
45
47
|
|
46
|
-
it '
|
48
|
+
it 'allows the default authorization code to be overridden by an argument' do
|
47
49
|
auth_code_arg = 'some new auth code'
|
48
50
|
expect_init_user_exporter_with(:authorization_code, auth_code_arg)
|
49
51
|
task.invoke(auth_code_arg)
|