graphql_devise 0.18.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +7 -2
  3. data/.gitignore +3 -0
  4. data/.rubocop.yml +9 -10
  5. data/Appraisals +70 -18
  6. data/CHANGELOG.md +53 -0
  7. data/README.md +71 -142
  8. data/app/controllers/graphql_devise/graphql_controller.rb +3 -3
  9. data/app/views/graphql_devise/mailer/confirmation_instructions.html.erb +1 -5
  10. data/config/routes.rb +0 -2
  11. data/graphql_devise.gemspec +7 -5
  12. data/lib/graphql_devise/concerns/additional_controller_methods.rb +48 -0
  13. data/lib/graphql_devise/concerns/additional_model_methods.rb +17 -0
  14. data/lib/graphql_devise/concerns/authenticatable.rb +1 -1
  15. data/lib/graphql_devise/concerns/controller_methods.rb +70 -93
  16. data/lib/graphql_devise/concerns/field_authentication.rb +14 -0
  17. data/lib/graphql_devise/concerns/set_user_by_token.rb +1 -1
  18. data/lib/graphql_devise/default_operations.rb +16 -0
  19. data/lib/graphql_devise/engine.rb +0 -2
  20. data/lib/graphql_devise/model/with_email_updater.rb +5 -30
  21. data/lib/graphql_devise/mount_method/operation_preparer.rb +0 -7
  22. data/lib/graphql_devise/mount_method/operation_preparers/custom_operation_preparer.rb +1 -1
  23. data/lib/graphql_devise/mount_method/operation_preparers/default_operation_preparer.rb +1 -1
  24. data/lib/graphql_devise/mount_method/operation_sanitizer.rb +0 -12
  25. data/lib/graphql_devise/mount_method/option_sanitizer.rb +0 -2
  26. data/lib/graphql_devise/mount_method/option_sanitizers/array_checker.rb +2 -2
  27. data/lib/graphql_devise/mount_method/option_sanitizers/class_checker.rb +2 -2
  28. data/lib/graphql_devise/mount_method/option_sanitizers/hash_checker.rb +1 -1
  29. data/lib/graphql_devise/mount_method/option_sanitizers/string_checker.rb +1 -1
  30. data/lib/graphql_devise/mount_method/option_validators/provided_operations_validator.rb +0 -2
  31. data/lib/graphql_devise/mount_method/option_validators/skip_only_validator.rb +1 -1
  32. data/lib/graphql_devise/mount_method/option_validators/supported_operations_validator.rb +1 -1
  33. data/lib/graphql_devise/mount_method/options_validator.rb +0 -3
  34. data/lib/graphql_devise/mount_method/supported_options.rb +0 -5
  35. data/lib/graphql_devise/mutations/base.rb +1 -1
  36. data/lib/graphql_devise/mutations/confirm_registration_with_token.rb +1 -1
  37. data/lib/graphql_devise/mutations/login.rb +1 -1
  38. data/lib/graphql_devise/mutations/register.rb +1 -1
  39. data/lib/graphql_devise/mutations/update_password_with_token.rb +1 -1
  40. data/lib/graphql_devise/resolvers/base.rb +1 -1
  41. data/lib/graphql_devise/resource_loader.rb +71 -39
  42. data/lib/graphql_devise/route_mounter.rb +13 -0
  43. data/lib/graphql_devise/schema_plugin.rb +7 -40
  44. data/lib/graphql_devise/types/authenticatable_type.rb +1 -1
  45. data/lib/graphql_devise/types/base_field.rb +9 -0
  46. data/lib/graphql_devise/types/base_type.rb +8 -0
  47. data/lib/graphql_devise/types/credential_type.rb +1 -1
  48. data/lib/graphql_devise/types/mutation_type.rb +1 -0
  49. data/lib/graphql_devise/types/query_type.rb +1 -0
  50. data/lib/graphql_devise/version.rb +1 -1
  51. data/lib/graphql_devise.rb +21 -29
  52. data/spec/dummy/app/controllers/api/v1/graphql_controller.rb +1 -16
  53. data/spec/dummy/app/graphql/dummy_schema.rb +1 -5
  54. data/spec/dummy/app/graphql/interpreter_schema.rb +6 -2
  55. data/spec/dummy/app/graphql/mutations/base_mutation.rb +6 -0
  56. data/spec/dummy/app/graphql/mutations/update_user.rb +2 -4
  57. data/spec/dummy/app/graphql/types/admin_type.rb +1 -1
  58. data/spec/dummy/app/graphql/types/custom_admin_type.rb +1 -1
  59. data/spec/dummy/app/graphql/types/mutation_type.rb +3 -1
  60. data/spec/dummy/app/graphql/types/query_type.rb +3 -1
  61. data/spec/dummy/app/graphql/types/user_type.rb +1 -1
  62. data/spec/dummy/config/environments/test.rb +1 -1
  63. data/spec/dummy/config/routes.rb +5 -9
  64. data/spec/graphql_devise/model/with_email_updater_spec.rb +17 -35
  65. data/spec/rails_helper.rb +5 -5
  66. data/spec/requests/mutations/resend_confirmation_with_token_spec.rb +2 -3
  67. data/spec/requests/user_controller_spec.rb +1 -33
  68. data/spec/services/resource_loader_spec.rb +14 -3
  69. metadata +55 -48
  70. data/app/controllers/graphql_devise/concerns/additional_controller_methods.rb +0 -72
  71. data/app/controllers/graphql_devise/concerns/set_user_by_token.rb +0 -21
  72. data/app/helpers/graphql_devise/mailer_helper.rb +0 -37
  73. data/app/models/graphql_devise/concerns/additional_model_methods.rb +0 -21
  74. data/app/models/graphql_devise/concerns/model.rb +0 -25
  75. data/lib/graphql_devise/default_operations/mutations.rb +0 -32
  76. data/lib/graphql_devise/default_operations/resolvers.rb +0 -14
  77. data/lib/graphql_devise/mutations/resend_confirmation.rb +0 -45
  78. data/lib/graphql_devise/mutations/send_password_reset.rb +0 -38
  79. data/lib/graphql_devise/mutations/sign_up.rb +0 -61
  80. data/lib/graphql_devise/mutations/update_password.rb +0 -46
  81. data/lib/graphql_devise/rails/routes.rb +0 -15
  82. data/lib/graphql_devise/resolvers/check_password_token.rb +0 -43
  83. data/lib/graphql_devise/resolvers/confirm_account.rb +0 -42
  84. data/spec/dummy/app/graphql/mutations/sign_up.rb +0 -14
  85. data/spec/dummy/app/graphql/resolvers/confirm_admin_account.rb +0 -13
  86. data/spec/requests/mutations/resend_confirmation_spec.rb +0 -153
  87. data/spec/requests/mutations/send_password_reset_spec.rb +0 -103
  88. data/spec/requests/mutations/sign_up_spec.rb +0 -170
  89. data/spec/requests/mutations/update_password_spec.rb +0 -116
  90. data/spec/requests/queries/check_password_token_spec.rb +0 -149
  91. data/spec/requests/queries/confirm_account_spec.rb +0 -137
@@ -3,6 +3,7 @@
3
3
  module GraphqlDevise
4
4
  module Types
5
5
  class QueryType < GraphQL::Schema::Object
6
+ field_class GraphqlDevise::Types::BaseField if Gem::Version.new(GraphQL::VERSION) >= Gem::Version.new('2.0')
6
7
  end
7
8
  end
8
9
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GraphqlDevise
4
- VERSION = '0.18.2'.freeze
4
+ VERSION = '1.0.0'
5
5
  end
@@ -1,13 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rails'
4
+ require 'rails/generators'
4
5
  require 'graphql'
5
6
  require 'devise_token_auth'
7
+ require 'zeitwerk'
8
+
9
+ if Gem::Version.new(GraphQL::VERSION) < Gem::Version.new('2.0')
10
+ GraphQL::Field.accepts_definitions(authenticate: GraphQL::Define.assign_metadata_key(:authenticate))
11
+ GraphQL::Schema::Field.accepts_definition(:authenticate)
12
+ end
13
+
14
+ loader = Zeitwerk::Loader.for_gem
15
+
16
+ loader.collapse("#{__dir__}/graphql_devise/concerns")
17
+ loader.collapse("#{__dir__}/graphql_devise/errors")
18
+ loader.collapse("#{__dir__}/generators")
19
+
20
+ loader.inflector.inflect('error_codes' => 'ERROR_CODES')
21
+ loader.inflector.inflect('supported_options' => 'SUPPORTED_OPTIONS')
22
+
23
+ loader.setup
6
24
 
7
25
  module GraphqlDevise
8
26
  class Error < StandardError; end
9
27
 
10
- class InvalidMountOptionsError < GraphqlDevise::Error; end
28
+ class InvalidMountOptionsError < ::GraphqlDevise::Error; end
11
29
 
12
30
  @schema_loaded = false
13
31
  @mounted_resources = []
@@ -52,32 +70,6 @@ module GraphqlDevise
52
70
  end
53
71
  end
54
72
 
73
+ ActionDispatch::Routing::Mapper.include(GraphqlDevise::RouteMounter)
74
+
55
75
  require 'graphql_devise/engine'
56
- require 'graphql_devise/version'
57
- require 'graphql_devise/errors/error_codes'
58
- require 'graphql_devise/errors/execution_error'
59
- require 'graphql_devise/errors/user_error'
60
- require 'graphql_devise/errors/authentication_error'
61
- require 'graphql_devise/errors/detailed_user_error'
62
-
63
- # TODO: Remove when merged into master
64
- require 'graphql_devise/concerns/authenticatable'
65
- require 'graphql_devise/concerns/set_user_by_token.rb'
66
-
67
- require 'graphql_devise/concerns/controller_methods'
68
- require 'graphql_devise/schema'
69
- require 'graphql_devise/types/authenticatable_type'
70
- require 'graphql_devise/types/credential_type'
71
- require 'graphql_devise/types/mutation_type'
72
- require 'graphql_devise/types/query_type'
73
- require 'graphql_devise/default_operations/mutations'
74
- require 'graphql_devise/default_operations/resolvers'
75
- require 'graphql_devise/resolvers/dummy'
76
-
77
- require 'graphql_devise/mount_method/option_sanitizer'
78
- require 'graphql_devise/mount_method/options_validator'
79
- require 'graphql_devise/mount_method/operation_preparer'
80
- require 'graphql_devise/mount_method/operation_sanitizer'
81
-
82
- require 'graphql_devise/resource_loader'
83
- require 'graphql_devise/schema_plugin'
@@ -15,28 +15,13 @@ module Api
15
15
  render json: InterpreterSchema.execute(params[:query], **execute_params(params))
16
16
  end
17
17
 
18
- def failing_resource_name
19
- render json: DummySchema.execute(params[:query], context: graphql_context([:user, :fail]))
20
- end
21
-
22
- def controller_auth
23
- result = DummySchema.execute(
24
- params[:query],
25
- operation_name: params[:operationName],
26
- variables: ensure_hash(params[:variables]),
27
- context: gql_devise_context(SchemaUser, User)
28
- )
29
-
30
- render json: result unless performed?
31
- end
32
-
33
18
  private
34
19
 
35
20
  def execute_params(item)
36
21
  {
37
22
  operation_name: item[:operationName],
38
23
  variables: ensure_hash(item[:variables]),
39
- context: graphql_context([:user, :schema_user])
24
+ context: gql_devise_context(SchemaUser, User)
40
25
  }
41
26
  end
42
27
 
@@ -10,11 +10,7 @@ class DummySchema < GraphQL::Schema
10
10
  User,
11
11
  only: [
12
12
  :login,
13
- :confirm_account,
14
- :send_password_reset,
15
- :resend_confirmation,
16
- :resend_confirmation_with_token,
17
- :check_password_token
13
+ :resend_confirmation_with_token
18
14
  ]
19
15
  ),
20
16
  GraphqlDevise::ResourceLoader.new(Guest, only: [:logout]),
@@ -1,8 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class InterpreterSchema < GraphQL::Schema
4
- use GraphQL::Execution::Interpreter if Gem::Version.new(GraphQL::VERSION) >= Gem::Version.new('1.9.0')
5
- use GraphQL::Analysis::AST if Gem::Version.new(GraphQL::VERSION) >= Gem::Version.new('1.10.0')
4
+ if Gem::Version.new(GraphQL::VERSION) >= Gem::Version.new('1.9.0') && Gem::Version.new(GraphQL::VERSION) < Gem::Version.new('2.0')
5
+ use GraphQL::Execution::Interpreter
6
+ end
7
+ if Gem::Version.new(GraphQL::VERSION) >= Gem::Version.new('1.10.0') && Gem::Version.new(GraphQL::VERSION) < Gem::Version.new('2.0')
8
+ use GraphQL::Analysis::AST
9
+ end
6
10
 
7
11
  use GraphqlDevise::SchemaPlugin.new(query: Types::QueryType, authenticate_default: false)
8
12
 
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mutations
4
+ class BaseMutation < GraphQL::Schema::Mutation
5
+ end
6
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mutations
4
- class UpdateUser < GraphQL::Schema::Mutation
4
+ class UpdateUser < BaseMutation
5
5
  field :user, Types::UserType, null: false
6
6
 
7
7
  argument :email, String, required: false
@@ -10,10 +10,8 @@ module Mutations
10
10
  def resolve(**attrs)
11
11
  user = context[:current_resource]
12
12
 
13
- schema_url = context[:controller].full_url_without_params
14
-
15
13
  user.update_with_email(
16
- attrs.merge(schema_url: schema_url, confirmation_success_url: 'https://google.com')
14
+ attrs.merge(confirmation_url: 'https://google.com')
17
15
  )
18
16
 
19
17
  { user: user }
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Types
4
- class AdminType < GraphQL::Schema::Object
4
+ class AdminType < BaseObject
5
5
  field :id, Int, null: false
6
6
  field :email, String, null: false
7
7
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Types
4
- class CustomAdminType < GraphQL::Schema::Object
4
+ class CustomAdminType < BaseObject
5
5
  field :email, String, null: false
6
6
  field :custom_field, String, null: false
7
7
 
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Types
4
- class MutationType < Types::BaseObject
4
+ class MutationType < BaseObject
5
+ field_class GraphqlDevise::Types::BaseField if Gem::Version.new(GraphQL::VERSION) >= Gem::Version.new('2.0')
6
+
5
7
  field :dummy_mutation, String, null: false, authenticate: true
6
8
  field :update_user, mutation: Mutations::UpdateUser
7
9
 
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Types
4
- class QueryType < Types::BaseObject
4
+ class QueryType < BaseObject
5
+ field_class GraphqlDevise::Types::BaseField if Gem::Version.new(GraphQL::VERSION) >= Gem::Version.new('2.0')
6
+
5
7
  field :user, resolver: Resolvers::UserShow
6
8
  field :public_field, String, null: false, authenticate: false
7
9
  field :private_field, String, null: false, authenticate: true
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Types
4
- class UserType < GraphQL::Schema::Object
4
+ class UserType < BaseObject
5
5
  field :id, Int, null: false
6
6
  field :email, String, null: false
7
7
  field :name, String, null: false
@@ -43,5 +43,5 @@ Rails.application.configure do
43
43
  config.active_support.deprecation = :stderr
44
44
 
45
45
  # Raises error for missing translations
46
- config.action_view.raise_on_missing_translations = true
46
+ config.action_view.raise_on_missing_translations = true if Rails::VERSION::MAJOR < 7
47
47
  end
@@ -1,9 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Rails.application.routes.draw do
4
- mount_graphql_devise_for 'User', at: '/api/v1/graphql_auth', operations: {
4
+ mount_graphql_devise_for User, at: '/api/v1/graphql_auth', operations: {
5
5
  login: Mutations::Login,
6
- sign_up: Mutations::SignUp,
7
6
  register: Mutations::Register
8
7
  }, additional_mutations: {
9
8
  register_confirmed_user: Mutations::RegisterConfirmedUser
@@ -14,22 +13,21 @@ Rails.application.routes.draw do
14
13
  mount_graphql_devise_for(
15
14
  Admin,
16
15
  authenticatable_type: Types::CustomAdminType,
17
- skip: [:sign_up, :register, :check_password_token],
16
+ skip: [:register],
18
17
  operations: {
19
- confirm_account: Resolvers::ConfirmAdminAccount,
20
18
  update_password_with_token: Mutations::ResetAdminPasswordWithToken
21
19
  },
22
20
  at: '/api/v1/admin/graphql_auth'
23
21
  )
24
22
 
25
23
  mount_graphql_devise_for(
26
- 'Guest',
27
- only: [:login, :logout, :sign_up, :register],
24
+ Guest,
25
+ only: [:login, :logout, :register],
28
26
  at: '/api/v1/guest/graphql_auth'
29
27
  )
30
28
 
31
29
  mount_graphql_devise_for(
32
- 'Users::Customer',
30
+ Users::Customer,
33
31
  only: [:login],
34
32
  at: '/api/v1/user_customer/graphql_auth'
35
33
  )
@@ -37,6 +35,4 @@ Rails.application.routes.draw do
37
35
  get '/api/v1/graphql', to: 'api/v1/graphql#graphql'
38
36
  post '/api/v1/graphql', to: 'api/v1/graphql#graphql'
39
37
  post '/api/v1/interpreter', to: 'api/v1/graphql#interpreter'
40
- post '/api/v1/failing', to: 'api/v1/graphql#failing_resource_name'
41
- post '/api/v1/controller_auth', to: 'api/v1/graphql#controller_auth'
42
38
  end
@@ -61,7 +61,7 @@ RSpec.describe GraphqlDevise::Model::WithEmailUpdater do
61
61
  let(:resource) { create(:admin, :confirmed) }
62
62
 
63
63
  context 'when attributes contain email' do
64
- let(:attributes) { { email: 'new@gmail.com', schema_url: 'http://localhost/test', confirmation_success_url: 'https://google.com' } }
64
+ let(:attributes) { { email: 'new@gmail.com', confirmation_url: 'https://google.com' } }
65
65
 
66
66
  it 'does not postpone email update' do
67
67
  expect do
@@ -78,7 +78,7 @@ RSpec.describe GraphqlDevise::Model::WithEmailUpdater do
78
78
  let(:resource) { create(:user, :confirmed) }
79
79
 
80
80
  context 'when attributes do not contain email' do
81
- let(:attributes) { { name: 'Updated Name', schema_url: 'http://localhost/test', confirmation_success_url: 'https://google.com' } }
81
+ let(:attributes) { { name: 'Updated Name', confirmation_url: 'https://google.com' } }
82
82
 
83
83
  it 'updates resource, ignores url params' do
84
84
  expect do
@@ -89,11 +89,15 @@ RSpec.describe GraphqlDevise::Model::WithEmailUpdater do
89
89
  end
90
90
 
91
91
  context 'when attributes contain email' do
92
- context 'when confirmation_success_url is used' do
93
- it_behaves_like 'all required arguments are provided', schema_url: 'http://localhost/test', confirmation_success_url: 'https://google.com'
92
+ context 'when confirmation_url is used' do
93
+ it_behaves_like 'all required arguments are provided', confirmation_url: 'https://google.com'
94
+
95
+ context 'when arguments hash has strings as keys' do
96
+ it_behaves_like 'all required arguments are provided', 'confirmation_url' => 'https://google.com'
97
+ end
94
98
 
95
- context 'when confirmation_success_url is missing and no default is set' do
96
- let(:attributes) { { email: 'new@gmail.com', name: 'Updated Name', schema_url: 'http://localhost/test' } }
99
+ context 'when confirmation_url is missing and no default is set' do
100
+ let(:attributes) { { email: 'new@gmail.com', name: 'Updated Name' } }
97
101
 
98
102
  before { allow(DeviseTokenAuth).to receive(:default_confirm_success_url).and_return(nil) }
99
103
 
@@ -105,7 +109,7 @@ RSpec.describe GraphqlDevise::Model::WithEmailUpdater do
105
109
  end
106
110
 
107
111
  context 'when email will not change' do
108
- let(:attributes) { { email: resource.email, name: 'changed', confirmation_success_url: 'https://google.com' } }
112
+ let(:attributes) { { email: resource.email, name: 'changed' } }
109
113
 
110
114
  it 'updates name and does not raise an error' do
111
115
  expect do
@@ -121,37 +125,15 @@ RSpec.describe GraphqlDevise::Model::WithEmailUpdater do
121
125
  end
122
126
  end
123
127
 
124
- context 'when confirm_url is used' do
125
- it_behaves_like 'all required arguments are provided', confirmation_url: 'https://google.com'
126
-
127
- context 'when arguments hash has strings as keys' do
128
- it_behaves_like 'all required arguments are provided', 'confirmation_url' => 'https://google.com'
129
- end
130
- end
131
-
132
128
  context 'when no confirmation url is provided is provided' do
133
- context 'when schema_url is provided' do
134
- let(:attributes) { { email: 'new@gmail.com', name: 'Updated Name', schema_url: 'http://localhost/test' } }
135
-
136
- it 'uses DTA default_confirm_success_url on the email with redirect flow' do
137
- expect { updater }.to change(ActionMailer::Base.deliveries, :count).by(1)
138
-
139
- email = ActionMailer::Base.deliveries.first
140
- expect(email.body.decoded).to include(CGI.escape('https://google.com'))
141
- expect(email.body.decoded).to include(CGI.escape('ConfirmAccount('))
142
- end
143
- end
129
+ let(:attributes) { { email: 'new@gmail.com', name: 'Updated Name' } }
144
130
 
145
- context 'when schema_url is not provided' do
146
- let(:attributes) { { email: 'new@gmail.com', name: 'Updated Name' } }
131
+ it 'uses DTA default_confirm_success_url on the email and new confirmation flow' do
132
+ expect { updater }.to change(ActionMailer::Base.deliveries, :count).by(1)
147
133
 
148
- it 'uses DTA default_confirm_success_url on the email and new confirmation flow' do
149
- expect { updater }.to change(ActionMailer::Base.deliveries, :count).by(1)
150
-
151
- email = ActionMailer::Base.deliveries.first
152
- expect(email.body.decoded).to include(CGI.escape('https://google.com'))
153
- expect(email.body.decoded).to include('?confirmationToken=')
154
- end
134
+ email = ActionMailer::Base.deliveries.first
135
+ expect(email.body.decoded).to include('https://google.com')
136
+ expect(email.body.decoded).to include('?confirmationToken=')
155
137
  end
156
138
  end
157
139
  end
data/spec/rails_helper.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  ENV['RAILS_ENV'] ||= 'test'
6
- ENGINE_ROOT = File.join(File.dirname(__FILE__), '../')
6
+ GQL_DEVISE_ROOT = File.join(File.dirname(__FILE__), '../')
7
7
 
8
8
  require File.expand_path('dummy/config/environment.rb', __dir__)
9
9
 
@@ -16,12 +16,12 @@ require 'faker'
16
16
  require 'generator_spec'
17
17
 
18
18
  # Load RSpec helpers.
19
- Dir[File.join(ENGINE_ROOT, 'spec/support/**/*.rb')].each { |f| require f }
19
+ Dir[File.join(GQL_DEVISE_ROOT, 'spec/support/**/*.rb')].each { |f| require f }
20
20
 
21
21
  begin
22
22
  ActiveRecord::Migrator.migrations_paths = [
23
- File.join(ENGINE_ROOT, 'spec/dummy/db/migrate'),
24
- File.join(ENGINE_ROOT, 'spec/db/migrate')
23
+ File.join(GQL_DEVISE_ROOT, 'spec/dummy/db/migrate'),
24
+ File.join(GQL_DEVISE_ROOT, 'spec/db/migrate')
25
25
  ]
26
26
  ActiveRecord::Migration.maintain_test_schema!
27
27
  rescue ActiveRecord::PendingMigrationError => e
@@ -29,7 +29,7 @@ rescue ActiveRecord::PendingMigrationError => e
29
29
  exit 1
30
30
  end
31
31
  RSpec.configure do |config|
32
- config.fixture_path = "#{ENGINE_ROOT}/spec/fixtures"
32
+ config.fixture_path = "#{GQL_DEVISE_ROOT}/spec/fixtures"
33
33
 
34
34
  config.use_transactional_fixtures = true
35
35
 
@@ -105,9 +105,8 @@ RSpec.describe 'Resend confirmation with token' do
105
105
 
106
106
  before do
107
107
  user.update_with_email(
108
- email: new_email,
109
- schema_url: 'http://localhost/test',
110
- confirmation_success_url: 'https://google.com'
108
+ email: new_email,
109
+ confirmation_url: 'https://google.com'
111
110
  )
112
111
  end
113
112
 
@@ -50,22 +50,6 @@ RSpec.describe "Integrations with the user's controller" do
50
50
  GRAPHQL
51
51
  end
52
52
 
53
- context 'when authenticating before using the GQL schema' do
54
- before { post_request('/api/v1/controller_auth') }
55
-
56
- context 'when user is authenticated' do
57
- let(:headers) { create(:schema_user).create_new_auth_token }
58
-
59
- it 'allows authentication at the controller level' do
60
- expect(json_response[:data][:privateField]).to eq('Field will always require authentication')
61
- end
62
- end
63
-
64
- context 'when user is not authenticated' do
65
- it_behaves_like 'returns a must authenticate error', 'privateField'
66
- end
67
- end
68
-
69
53
  context 'when using a regular schema' do
70
54
  before { post_request('/api/v1/graphql') }
71
55
 
@@ -88,15 +72,6 @@ RSpec.describe "Integrations with the user's controller" do
88
72
  context 'when user is not authenticated' do
89
73
  it_behaves_like 'returns a must authenticate error', 'privateField'
90
74
  end
91
-
92
- context 'when using the failing route' do
93
- it 'raises an invalid resource_name error' do
94
- expect { post_request('/api/v1/failing') }.to raise_error(
95
- GraphqlDevise::Error,
96
- 'Invalid resource_name `fail` provided to `graphql_context`. Possible values are: [:user, :admin, :guest, :users_customer, :schema_user].'
97
- )
98
- end
99
- end
100
75
  end
101
76
 
102
77
  context 'when using an interpreter schema' do
@@ -245,14 +220,7 @@ RSpec.describe "Integrations with the user's controller" do
245
220
 
246
221
  email = Nokogiri::HTML(ActionMailer::Base.deliveries.last.body.encoded)
247
222
  link = email.css('a').first
248
- expect(link['href']).to include('/api/v1/graphql')
249
-
250
- expect do
251
- get link['href']
252
- user.reload
253
- end.to change(user, :email).from(original_email).to('updated@gmail.com').and(
254
- change(user, :uid).from(original_email).to('updated@gmail.com')
255
- )
223
+ expect(link['href']).to include('https://google.com')
256
224
  end
257
225
  end
258
226
 
@@ -10,8 +10,8 @@ RSpec.describe GraphqlDevise::ResourceLoader do
10
10
  let(:mutation) { class_double(GraphQL::Schema::Object) }
11
11
  let(:routing) { false }
12
12
  let(:mounted) { false }
13
- let(:resource) { 'User' }
14
- let(:options) { { only: [:login, :confirm_account] } }
13
+ let(:resource) { User }
14
+ let(:options) { { only: [:login], additional_queries: { public_user: Class.new(GraphQL::Schema::Resolver) } } }
15
15
 
16
16
  before do
17
17
  allow(GraphqlDevise).to receive(:add_mapping).with(:user, resource)
@@ -20,7 +20,7 @@ RSpec.describe GraphqlDevise::ResourceLoader do
20
20
  end
21
21
 
22
22
  it 'loads operations into the provided types' do
23
- expect(query).to receive(:field).with(:user_confirm_account, resolver: instance_of(Class), authenticate: false)
23
+ expect(query).to receive(:field).with(:public_user, resolver: instance_of(Class), authenticate: false)
24
24
  expect(mutation).to receive(:field).with(:user_login, mutation: instance_of(Class), authenticate: false)
25
25
  expect(GraphqlDevise).to receive(:add_mapping).with(:user, resource)
26
26
  expect(GraphqlDevise).not_to receive(:mount_resource)
@@ -30,6 +30,17 @@ RSpec.describe GraphqlDevise::ResourceLoader do
30
30
  expect(returned).to be_a(Struct)
31
31
  end
32
32
 
33
+ context 'when resource is not class' do
34
+ let(:resource) { 'User' }
35
+
36
+ it 'raises an error' do
37
+ expect { loader }.to raise_error(
38
+ GraphqlDevise::Error,
39
+ 'A class must be provided when mounting a model. String values are no longer supported.'
40
+ )
41
+ end
42
+ end
43
+
33
44
  context 'when mutation is nil' do
34
45
  let(:mutation) { nil }
35
46