devise_g5_authenticatable 0.3.0 → 1.0.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rspec +1 -0
  4. data/.ruby-version +1 -1
  5. data/.travis.yml +29 -7
  6. data/Appraisals +21 -0
  7. data/CHANGELOG.md +24 -0
  8. data/Gemfile +11 -7
  9. data/README.md +6 -6
  10. data/Rakefile +6 -5
  11. data/app/controllers/devise_g5_authenticatable/registrations_controller.rb +3 -0
  12. data/app/controllers/devise_g5_authenticatable/sessions_controller.rb +9 -5
  13. data/config/initializers/devise_g5_authenticatable.rb +2 -0
  14. data/devise_g5_authenticatable.gemspec +6 -5
  15. data/gemfiles/rails_4.1.gemfile +26 -0
  16. data/gemfiles/rails_4.2.gemfile +26 -0
  17. data/gemfiles/rails_5.0.gemfile +26 -0
  18. data/gemfiles/rails_5.1.gemfile +26 -0
  19. data/lib/devise_g5_authenticatable/controllers/helpers.rb +5 -0
  20. data/lib/devise_g5_authenticatable/controllers/url_helpers.rb +3 -0
  21. data/lib/devise_g5_authenticatable/engine.rb +4 -1
  22. data/lib/devise_g5_authenticatable/g5/auth_password_validator.rb +6 -1
  23. data/lib/devise_g5_authenticatable/g5/auth_user_creator.rb +16 -15
  24. data/lib/devise_g5_authenticatable/g5/auth_user_updater.rb +11 -5
  25. data/lib/devise_g5_authenticatable/g5/user_exporter.rb +11 -6
  26. data/lib/devise_g5_authenticatable/g5.rb +2 -0
  27. data/lib/devise_g5_authenticatable/hooks/g5_authenticatable.rb +8 -3
  28. data/lib/devise_g5_authenticatable/models/g5_authenticatable.rb +38 -26
  29. data/lib/devise_g5_authenticatable/models/protected_attributes.rb +11 -2
  30. data/lib/devise_g5_authenticatable/omniauth.rb +8 -2
  31. data/lib/devise_g5_authenticatable/routes.rb +48 -35
  32. data/lib/devise_g5_authenticatable/version.rb +3 -1
  33. data/lib/devise_g5_authenticatable.rb +4 -1
  34. data/spec/controllers/helpers_spec.rb +54 -49
  35. data/spec/controllers/sessions_controller_spec.rb +67 -39
  36. data/spec/controllers/url_helpers_spec.rb +78 -78
  37. data/spec/dummy/app/views/{anonymous → devise}/new.html.erb +0 -0
  38. data/spec/dummy/config/environments/test.rb +20 -4
  39. data/spec/dummy/config/initializers/devise.rb +5 -1
  40. data/spec/dummy/config/initializers/rails_compatibility.rb +10 -0
  41. data/spec/dummy/db/migrate/20131230235849_devise_create_users.rb +3 -1
  42. data/spec/dummy/db/migrate/20140102213131_drop_database_authenticatable.rb +3 -1
  43. data/spec/dummy/db/migrate/20140103032308_drop_recoverable.rb +3 -1
  44. data/spec/dummy/db/migrate/20140103042329_drop_rememberable.rb +3 -1
  45. data/spec/dummy/db/migrate/20140103174810_add_omniauth_columns_to_users.rb +3 -1
  46. data/spec/dummy/db/migrate/20140103191601_add_email_back_to_user.rb +3 -1
  47. data/spec/dummy/db/migrate/20140113202948_devise_create_admins.rb +3 -1
  48. data/spec/dummy/db/migrate/20140113233821_add_provider_and_uid_to_admins.rb +3 -1
  49. data/spec/dummy/db/schema.rb +29 -29
  50. data/spec/factories/admin.rb +2 -0
  51. data/spec/factories/user.rb +2 -0
  52. data/spec/features/edit_registration_spec.rb +22 -13
  53. data/spec/features/registration_spec.rb +13 -8
  54. data/spec/features/sign_in_spec.rb +4 -2
  55. data/spec/features/sign_out_spec.rb +4 -2
  56. data/spec/features/token_validation_spec.rb +24 -14
  57. data/spec/g5/auth_password_validator_spec.rb +28 -15
  58. data/spec/g5/auth_user_creator_spec.rb +29 -22
  59. data/spec/g5/auth_user_updater_spec.rb +23 -16
  60. data/spec/g5/user_exporter_spec.rb +36 -31
  61. data/spec/models/g5_authenticatable_spec.rb +78 -38
  62. data/spec/models/protected_attributes_spec.rb +24 -19
  63. data/spec/rails_helper.rb +46 -0
  64. data/spec/routing/registrations_routing_spec.rb +43 -27
  65. data/spec/routing/sessions_routing_spec.rb +46 -29
  66. data/spec/spec_helper.rb +93 -27
  67. data/spec/support/controller_test_helpers.rb +15 -0
  68. data/spec/support/devise.rb +9 -1
  69. data/spec/support/shared_contexts/custom_router.rb +16 -0
  70. data/spec/support/shared_contexts/oauth_error.rb +4 -2
  71. data/spec/support/shared_contexts/rake.rb +10 -4
  72. data/spec/support/shared_examples/registration_error.rb +3 -1
  73. data/spec/support/{user_feature_methods.rb → user_omniauth_methods.rb} +9 -5
  74. data/spec/tasks/export_users_spec.rb +5 -3
  75. metadata +30 -26
  76. data/circle.yml +0 -4
  77. data/spec/support/omniauth.rb +0 -3
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Use this hook to configure devise mailer, warden hooks and so forth.
2
4
  # Many of these configuration options can be set straight in your model.
3
5
  Devise.setup do |config|
@@ -23,7 +25,9 @@ Devise.setup do |config|
23
25
 
24
26
  # Require optional support for protected_attributes in devise
25
27
  # models
26
- require 'devise_g5_authenticatable/models/protected_attributes'
28
+ if Rails.version.starts_with?('4')
29
+ require 'devise_g5_authenticatable/models/protected_attributes'
30
+ end
27
31
 
28
32
  # ==> Configuration for any authentication mechanism
29
33
  # Configure which keys are used when authenticating a user. The default is
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Support migration version syntax in rails 4
4
+ ActiveSupport.on_load(:active_record) do
5
+ unless ActiveRecord::Migration.respond_to?(:[])
6
+ ActiveRecord::Migration.define_singleton_method(:[]) do |version|
7
+ self if version.to_s.starts_with?('4')
8
+ end
9
+ end
10
+ end
@@ -1,4 +1,6 @@
1
- class DeviseCreateUsers < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class DeviseCreateUsers < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  create_table(:users) do |t|
4
6
  ## Database authenticatable
@@ -1,4 +1,6 @@
1
- class DropDatabaseAuthenticatable < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class DropDatabaseAuthenticatable < ActiveRecord::Migration[4.2]
2
4
  def up
3
5
  change_table(:users) do |t|
4
6
  t.remove :email
@@ -1,4 +1,6 @@
1
- class DropRecoverable < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class DropRecoverable < ActiveRecord::Migration[4.2]
2
4
  def up
3
5
  change_table(:users) do |t|
4
6
  t.remove :reset_password_token
@@ -1,4 +1,6 @@
1
- class DropRememberable < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class DropRememberable < ActiveRecord::Migration[4.2]
2
4
  def up
3
5
  change_table(:users) do |t|
4
6
  t.remove :remember_created_at
@@ -1,4 +1,6 @@
1
- class AddOmniauthColumnsToUsers < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class AddOmniauthColumnsToUsers < ActiveRecord::Migration[4.2]
2
4
  def up
3
5
  change_table(:users) do |t|
4
6
  t.string :uid
@@ -1,4 +1,6 @@
1
- class AddEmailBackToUser < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class AddEmailBackToUser < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  add_column :users, :email, :string,
4
6
  null: false,
@@ -1,4 +1,6 @@
1
- class DeviseCreateAdmins < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class DeviseCreateAdmins < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  create_table(:admins) do |t|
4
6
  ## Database authenticatable
@@ -1,4 +1,6 @@
1
- class AddProviderAndUidToAdmins < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class AddProviderAndUidToAdmins < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  add_column :admins, :provider, :string
4
6
  add_column :admins, :uid, :string
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  # This file is auto-generated from the current state of the database. Instead
3
2
  # of editing this file, please use the migrations feature of Active Record to
4
3
  # incrementally modify your database, and then regenerate this schema definition.
@@ -9,42 +8,43 @@
9
8
  # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
9
  # you'll amass, the slower it'll run and the greater likelihood for issues).
11
10
  #
12
- # It's strongly recommended to check this file into your version control system.
11
+ # It's strongly recommended that you check this file into your version control system.
13
12
 
14
- ActiveRecord::Schema.define(:version => 20140113233821) do
13
+ ActiveRecord::Schema.define(version: 20140113233821) do
15
14
 
16
- create_table "admins", :force => true do |t|
17
- t.string "email", :default => "", :null => false
18
- t.integer "sign_in_count", :default => 0, :null => false
15
+ # These are extensions that must be enabled in order to support this database
16
+ enable_extension "plpgsql"
17
+
18
+ create_table "admins", id: :serial, force: :cascade do |t|
19
+ t.string "email", default: "", null: false
20
+ t.integer "sign_in_count", default: 0, null: false
19
21
  t.datetime "current_sign_in_at"
20
22
  t.datetime "last_sign_in_at"
21
- t.string "current_sign_in_ip"
22
- t.string "last_sign_in_ip"
23
- t.datetime "created_at", :null => false
24
- t.datetime "updated_at", :null => false
25
- t.string "provider"
26
- t.string "uid"
27
- t.string "g5_access_token"
23
+ t.string "current_sign_in_ip"
24
+ t.string "last_sign_in_ip"
25
+ t.datetime "created_at"
26
+ t.datetime "updated_at"
27
+ t.string "provider"
28
+ t.string "uid"
29
+ t.string "g5_access_token"
30
+ t.index ["email"], name: "index_admins_on_email", unique: true
31
+ t.index ["provider", "uid"], name: "index_admins_on_provider_and_uid", unique: true
28
32
  end
29
33
 
30
- add_index "admins", ["email"], :name => "index_admins_on_email", :unique => true
31
- add_index "admins", ["provider", "uid"], :name => "index_admins_on_provider_and_uid", :unique => true
32
-
33
- create_table "users", :force => true do |t|
34
- t.integer "sign_in_count", :default => 0, :null => false
34
+ create_table "users", id: :serial, force: :cascade do |t|
35
+ t.integer "sign_in_count", default: 0, null: false
35
36
  t.datetime "current_sign_in_at"
36
37
  t.datetime "last_sign_in_at"
37
- t.string "current_sign_in_ip"
38
- t.string "last_sign_in_ip"
39
- t.datetime "created_at", :null => false
40
- t.datetime "updated_at", :null => false
41
- t.string "uid"
42
- t.string "provider"
43
- t.string "g5_access_token"
44
- t.string "email", :default => "", :null => false
38
+ t.string "current_sign_in_ip"
39
+ t.string "last_sign_in_ip"
40
+ t.datetime "created_at"
41
+ t.datetime "updated_at"
42
+ t.string "uid"
43
+ t.string "provider"
44
+ t.string "g5_access_token"
45
+ t.string "email", default: "", null: false
46
+ t.index ["email"], name: "index_users_on_email", unique: true
47
+ t.index ["provider", "uid"], name: "index_users_on_provider_and_uid", unique: true
45
48
  end
46
49
 
47
- add_index "users", ["email"], :name => "index_users_on_email", :unique => true
48
- add_index "users", ["provider", "uid"], :name => "index_users_on_provider_and_uid", :unique => true
49
-
50
50
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryGirl.define do
2
4
  factory :admin do
3
5
  sequence(:email) { |n| "admin.#{n}@test.host" }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryGirl.define do
2
4
  factory :user do
3
5
  sequence(:email) { |n| "user.#{n}@test.host" }
@@ -1,15 +1,20 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe 'Editing a user registration' do
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe 'Editing a user registration' do
4
6
  subject(:update_registration) { click_button 'Update' }
5
7
 
6
8
  let(:user) { create(:user) }
7
9
 
8
- let(:auth_client) { double(:auth_client, update_user: auth_user, me: auth_user) }
10
+ let(:auth_client) do
11
+ double(:auth_client, update_user: auth_user, me: auth_user)
12
+ end
9
13
 
10
14
  let(:auth_user) { double(:auth_user, id: user.uid, email: user.email) }
11
15
  before do
12
- allow(G5AuthenticationClient::Client).to receive(:new).and_return(auth_client)
16
+ allow(G5AuthenticationClient::Client).to receive(:new)
17
+ .and_return(auth_client)
13
18
  end
14
19
 
15
20
  before do
@@ -34,10 +39,11 @@ describe 'Editing a user registration' do
34
39
  end
35
40
 
36
41
  it 'should update the email on the auth server' do
37
- expect(auth_client).to receive(:update_user).with({id: user.uid,
38
- email: email,
39
- password: nil,
40
- password_confirmation: nil})
42
+ expect(auth_client).to receive(:update_user)
43
+ .with(id: user.uid,
44
+ email: email,
45
+ password: nil,
46
+ password_confirmation: nil)
41
47
  update_registration
42
48
  end
43
49
  end
@@ -46,10 +52,11 @@ describe 'Editing a user registration' do
46
52
  let(:password) { 'a brand new password' }
47
53
 
48
54
  it 'should update the password on the auth server' do
49
- expect(auth_client).to receive(:update_user).with({id: user.uid,
50
- email: email,
51
- password: password,
52
- password_confirmation: password_confirmation})
55
+ expect(auth_client).to receive(:update_user)
56
+ .with(id: user.uid,
57
+ email: email,
58
+ password: password,
59
+ password_confirmation: password_confirmation)
53
60
  update_registration
54
61
  end
55
62
  end
@@ -70,7 +77,9 @@ describe 'Editing a user registration' do
70
77
 
71
78
  context 'when the auth server returns an error' do
72
79
  include_context 'OAuth2::Error'
73
- before { allow(auth_client).to receive(:update_user).and_raise(oauth_error) }
80
+ before do
81
+ allow(auth_client).to receive(:update_user).and_raise(oauth_error)
82
+ end
74
83
 
75
84
  it 'should display an error message' do
76
85
  update_registration
@@ -1,12 +1,15 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe 'User registration' do
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe 'User registration' do
4
6
  subject(:register_user) { click_button 'Sign up' }
5
7
 
6
8
  let(:auth_client) { double(:auth_client, create_user: auth_user) }
7
9
  let(:auth_user) { double(:auth_user, id: uid, email: email) }
8
10
  before do
9
- allow(G5AuthenticationClient::Client).to receive(:new).and_return(auth_client)
11
+ allow(G5AuthenticationClient::Client).to receive(:new)
12
+ .and_return(auth_client)
10
13
  end
11
14
 
12
15
  before do
@@ -32,11 +35,11 @@ describe 'User registration' do
32
35
  end
33
36
 
34
37
  it 'should create the user on the auth server' do
35
- expect(auth_client).to receive(:create_user).
36
- with({email: email,
38
+ expect(auth_client).to receive(:create_user)
39
+ .with(email: email,
37
40
  password: password,
38
- password_confirmation: password_confirmation}).
39
- and_return(auth_user)
41
+ password_confirmation: password_confirmation)
42
+ .and_return(auth_user)
40
43
  register_user
41
44
  end
42
45
 
@@ -52,7 +55,9 @@ describe 'User registration' do
52
55
 
53
56
  context 'when there is an error on the auth server' do
54
57
  include_context 'OAuth2::Error'
55
- before { allow(auth_client).to receive(:create_user).and_raise(oauth_error) }
58
+ before do
59
+ allow(auth_client).to receive(:create_user).and_raise(oauth_error)
60
+ end
56
61
 
57
62
  it 'should display an error message' do
58
63
  register_user
@@ -1,6 +1,8 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe 'Signing in' do
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe 'Signing in' do
4
6
  context 'when visiting a protected page' do
5
7
  let(:protected_path) { edit_user_registration_path }
6
8
 
@@ -1,6 +1,8 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe 'Signing out' do
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe 'Signing out' do
4
6
  it 'should redirect to the auth server'
5
7
  it 'should pass the root url as a param to the redirect'
6
8
  it 'should not allow the user to access protected pages'
@@ -1,14 +1,18 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe 'Token validation per request' do
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe 'Token validation per request' do
4
6
  let(:user) { create(:user) }
5
7
  let(:protected_path) { edit_user_registration_path }
6
8
  let(:token_info_url) { 'http://auth.g5search.com/oauth/token/info' }
7
9
 
10
+ let(:auth_header) { { 'Authorization' => "Bearer #{user.g5_access_token}" } }
11
+
8
12
  before do
9
- stub_request(:get, token_info_url).
10
- with(headers: {'Authorization'=>"Bearer #{user.g5_access_token}"}).
11
- to_return(status: 200, body: '', headers: {})
13
+ stub_request(:get, token_info_url)
14
+ .with(headers: auth_header)
15
+ .to_return(status: 200, body: '', headers: {})
12
16
  end
13
17
 
14
18
  before do
@@ -42,8 +46,8 @@ describe 'Token validation per request' do
42
46
  before { visit protected_path }
43
47
 
44
48
  it 'should validate the token against the auth server' do
45
- expect(a_request(:get, token_info_url).
46
- with(headers: {'Authorization' => "Bearer #{user.g5_access_token}"})).to have_been_made
49
+ expect(a_request(:get, token_info_url).with(headers: auth_header))
50
+ .to have_been_made
47
51
  end
48
52
 
49
53
  it 'should allow the user to access the protected page' do
@@ -53,13 +57,19 @@ describe 'Token validation per request' do
53
57
 
54
58
  context 'when the access_token has been invalidated' do
55
59
  before do
56
- stub_request(:get, token_info_url).
57
- with(headers: {'Authorization'=>"Bearer #{user.g5_access_token}"}).
58
- to_return(status: 401,
59
- headers: {'Content-Type' => 'application/json; charset=utf-8',
60
- 'Cache-Control' => 'no-cache'},
61
- body: {'error' => 'invalid_token',
62
- 'error_description' => 'The access token expired'}.to_json)
60
+ response_headers = {
61
+ 'Content-Type' => 'application/json; charset=utf-8',
62
+ 'Cache-Control' => 'no-cache'
63
+ }
64
+ response_body = {
65
+ 'error' => 'invalid_token',
66
+ 'error_description' => 'The access token expired'
67
+ }
68
+ stub_request(:get, token_info_url)
69
+ .with(headers: auth_header)
70
+ .to_return(status: 401,
71
+ headers: response_headers,
72
+ body: response_body.to_json)
63
73
  visit protected_path
64
74
  end
65
75
 
@@ -1,6 +1,8 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe Devise::G5::AuthPasswordValidator do
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe Devise::G5::AuthPasswordValidator do
4
6
  let(:validator) { described_class.new(model) }
5
7
 
6
8
  let(:model) { build_stubbed(:user) }
@@ -14,24 +16,26 @@ describe Devise::G5::AuthPasswordValidator do
14
16
  let(:auth_user) { double(:auth_user, uid: model.uid, email: model.email) }
15
17
 
16
18
  let(:oauth_error) { OAuth2::Error.new(response) }
17
- let(:response) { double(:oauth_response, parsed: oauth_error_hash).as_null_object }
19
+ let(:response) do
20
+ double(:oauth_response, parsed: oauth_error_hash).as_null_object
21
+ end
18
22
 
19
23
  before do
20
- allow(G5AuthenticationClient::Client).to receive(:new).
21
- and_return(auth_client)
24
+ allow(G5AuthenticationClient::Client).to receive(:new)
25
+ .and_return(auth_client)
22
26
  end
23
27
 
24
28
  context 'with valid password' do
25
29
  before { valid_password? }
26
30
 
27
31
  it 'should initialize auth client with the username' do
28
- expect(G5AuthenticationClient::Client).to have_received(:new).
29
- with(hash_including(username: model.email))
32
+ expect(G5AuthenticationClient::Client).to have_received(:new)
33
+ .with(hash_including(username: model.email))
30
34
  end
31
35
 
32
36
  it 'should initialize auth client with the password' do
33
- expect(G5AuthenticationClient::Client).to have_received(:new).
34
- with(hash_including(password: password))
37
+ expect(G5AuthenticationClient::Client).to have_received(:new)
38
+ .with(hash_including(password: password))
35
39
  end
36
40
 
37
41
  it 'should retrieve the auth user associated with these credentials' do
@@ -47,8 +51,10 @@ describe Devise::G5::AuthPasswordValidator do
47
51
  before { allow(auth_client).to receive(:me).and_raise(oauth_error) }
48
52
 
49
53
  let(:oauth_error_hash) do
50
- {'error' => 'invalid_resource_owner',
51
- 'error_description' => 'The provided resource owner credentials are not valid, or resource owner cannot be found.'}
54
+ { 'error' => 'invalid_resource_owner',
55
+ 'error_description' => 'The provided resource owner credentials are' \
56
+ ' not valid, or resource owner cannot be' \
57
+ ' found.' }
52
58
  end
53
59
 
54
60
  it 'should return false' do
@@ -57,8 +63,14 @@ describe Devise::G5::AuthPasswordValidator do
57
63
  end
58
64
 
59
65
  context 'with blank password' do
60
- before { allow(auth_client).to receive(:me).and_raise(runtime_error) }
61
- let(:runtime_error) { RuntimeError.new('Insufficient credentials for access token. Supply a username/password or authentication code.') }
66
+ before do
67
+ allow(auth_client).to receive(:me)
68
+ .and_raise(RuntimeError, runtime_error)
69
+ end
70
+ let(:runtime_error) do
71
+ 'Insufficient credentials for access token. Supply a' \
72
+ ' username/password or authentication code.'
73
+ end
62
74
 
63
75
  it 'should return false' do
64
76
  expect(valid_password?).to be_falsey
@@ -69,8 +81,9 @@ describe Devise::G5::AuthPasswordValidator do
69
81
  before { allow(auth_client).to receive(:me).and_raise(oauth_error) }
70
82
 
71
83
  let(:oauth_error_hash) do
72
- {'error' => 'unauthorized_client',
73
- 'error_description' => 'The client is not authorized to perform this request using this method.'}
84
+ { 'error' => 'unauthorized_client',
85
+ 'error_description' => 'The client is not authorized to perform' \
86
+ ' this request using this method.' }
74
87
  end
75
88
 
76
89
  it 'should re-raise the error' do
@@ -1,6 +1,8 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe Devise::G5::AuthUserCreator do
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe Devise::G5::AuthUserCreator do
4
6
  let(:creator) { described_class.new(model) }
5
7
 
6
8
  describe '#create' do
@@ -19,23 +21,26 @@ describe Devise::G5::AuthUserCreator do
19
21
 
20
22
  let(:auth_client) { double(:g5_authentication_client) }
21
23
 
22
- let(:auth_user) { double(:auth_user,
23
- id: uid,
24
- email: model.email,
25
- password: other_password,
26
- clean_up_passwords: nil,
27
- to_hash: {}) }
24
+ let(:auth_user) do
25
+ double(:auth_user, id: uid,
26
+ email: model.email,
27
+ password: other_password,
28
+ clean_up_passwords: nil,
29
+ to_hash: {})
30
+ end
28
31
 
29
32
  let(:uid) { 'remote-auth-user-42' }
30
33
 
31
34
  before do
32
- allow(G5AuthenticationClient::Client).to receive(:new).and_return(auth_client)
35
+ allow(G5AuthenticationClient::Client).to receive(:new)
36
+ .and_return(auth_client)
33
37
  end
34
38
 
35
39
  context 'when there is an existing auth user' do
36
40
  before do
37
41
  model.uid = nil
38
- allow(auth_client).to receive(:create_user).and_raise(StandardError.new('Email has already been taken'))
42
+ allow(auth_client).to receive(:create_user)
43
+ .and_raise(StandardError, 'Email has already been taken')
39
44
  allow(auth_client).to receive(:find_user_by_email).and_return(auth_user)
40
45
  allow(auth_client).to receive(:update_user)
41
46
  end
@@ -43,7 +48,7 @@ describe Devise::G5::AuthUserCreator do
43
48
  it 'should create the local user with the existing uid' do
44
49
  allow(auth_user).to receive(:password=)
45
50
  allow(auth_user).to receive(:password_confirmation=)
46
- expect{ create }.to change(model, :uid).to uid
51
+ expect { create }.to change { model.uid }.to(uid)
47
52
  end
48
53
 
49
54
  it 'should reset the password' do
@@ -67,23 +72,25 @@ describe Devise::G5::AuthUserCreator do
67
72
  before { create }
68
73
 
69
74
  it 'should use the token for updated_by user to call g5 auth' do
70
- expect(G5AuthenticationClient::Client).to have_received(:new).
71
- with(access_token: updated_by.g5_access_token)
75
+ expect(G5AuthenticationClient::Client).to have_received(:new)
76
+ .with(access_token: updated_by.g5_access_token)
72
77
  end
73
78
 
74
79
  it 'should create a new auth user with the correct email' do
75
- expect(auth_client).to have_received(:create_user).
76
- with(hash_including(email: model.email))
80
+ expect(auth_client).to have_received(:create_user)
81
+ .with(hash_including(email: model.email))
77
82
  end
78
83
 
79
84
  it 'should create a new auth user with the correct password' do
80
- expect(auth_client).to have_received(:create_user).
81
- with(hash_including(password: password))
85
+ expect(auth_client).to have_received(:create_user)
86
+ .with(hash_including(password: password))
82
87
  end
83
88
 
84
- it 'should create a new auth user with the correct password confirmation' do
85
- expect(auth_client).to have_received(:create_user).
86
- with(hash_including(password_confirmation: password_confirmation))
89
+ it 'creates a new auth user with the correct password confirmation' do
90
+ expect(auth_client).to have_received(:create_user)
91
+ .with(
92
+ hash_including(password_confirmation: password_confirmation)
93
+ )
87
94
  end
88
95
 
89
96
  it 'should reset the password' do
@@ -109,8 +116,8 @@ describe Devise::G5::AuthUserCreator do
109
116
  before { create }
110
117
 
111
118
  it 'should use the user token to call g5 auth' do
112
- expect(G5AuthenticationClient::Client).to have_received(:new).
113
- with(access_token: model.g5_access_token)
119
+ expect(G5AuthenticationClient::Client).to have_received(:new)
120
+ .with(access_token: model.g5_access_token)
114
121
  end
115
122
  end
116
123
  end