graphql_devise 0.12.0 → 0.13.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/.travis.yml +7 -0
- data/Appraisals +14 -0
- data/CHANGELOG.md +62 -1
- data/Gemfile +2 -0
- data/README.md +125 -82
- data/Rakefile +2 -0
- data/app/controllers/graphql_devise/application_controller.rb +2 -0
- data/app/controllers/graphql_devise/concerns/set_user_by_token.rb +12 -4
- data/app/controllers/graphql_devise/graphql_controller.rb +2 -0
- data/app/helpers/graphql_devise/application_helper.rb +2 -0
- data/app/helpers/graphql_devise/mailer_helper.rb +2 -0
- data/app/models/graphql_devise/concerns/model.rb +10 -0
- data/app/views/graphql_devise/mailer/confirmation_instructions.html.erb +1 -1
- data/app/views/graphql_devise/mailer/reset_password_instructions.html.erb +1 -1
- data/config/locales/en.yml +1 -0
- data/config/routes.rb +2 -0
- data/graphql_devise.gemspec +4 -2
- data/lib/generators/graphql_devise/install_generator.rb +3 -1
- data/lib/graphql_devise.rb +10 -6
- data/lib/graphql_devise/concerns/controller_methods.rb +2 -0
- data/lib/graphql_devise/default_operations/mutations.rb +8 -6
- data/lib/graphql_devise/default_operations/resolvers.rb +4 -2
- data/lib/graphql_devise/engine.rb +2 -0
- data/lib/graphql_devise/errors/authentication_error.rb +9 -0
- data/lib/graphql_devise/{detailed_user_error.rb → errors/detailed_user_error.rb} +3 -1
- data/lib/graphql_devise/errors/error_codes.rb +8 -0
- data/lib/graphql_devise/errors/execution_error.rb +6 -0
- data/lib/graphql_devise/{user_error.rb → errors/user_error.rb} +3 -1
- data/lib/graphql_devise/model/with_email_updater.rb +74 -0
- data/lib/graphql_devise/mount_method/operation_preparer.rb +2 -0
- data/lib/graphql_devise/mount_method/operation_preparers/custom_operation_preparer.rb +2 -0
- data/lib/graphql_devise/mount_method/operation_preparers/default_operation_preparer.rb +8 -2
- data/lib/graphql_devise/mount_method/operation_preparers/gql_name_setter.rb +3 -1
- data/lib/graphql_devise/mount_method/operation_preparers/mutation_field_setter.rb +5 -2
- data/lib/graphql_devise/mount_method/operation_preparers/resolver_type_setter.rb +3 -1
- data/lib/graphql_devise/mount_method/operation_preparers/resource_name_setter.rb +3 -1
- data/lib/graphql_devise/mount_method/operation_sanitizer.rb +2 -0
- data/lib/graphql_devise/mount_method/option_sanitizer.rb +2 -0
- data/lib/graphql_devise/mount_method/option_sanitizers/array_checker.rb +2 -0
- data/lib/graphql_devise/mount_method/option_sanitizers/class_checker.rb +2 -0
- data/lib/graphql_devise/mount_method/option_sanitizers/hash_checker.rb +2 -0
- data/lib/graphql_devise/mount_method/option_sanitizers/string_checker.rb +2 -0
- data/lib/graphql_devise/mount_method/option_validators/provided_operations_validator.rb +2 -0
- data/lib/graphql_devise/mount_method/option_validators/skip_only_validator.rb +2 -0
- data/lib/graphql_devise/mount_method/option_validators/supported_operations_validator.rb +2 -0
- data/lib/graphql_devise/mount_method/options_validator.rb +2 -0
- data/lib/graphql_devise/mount_method/supported_options.rb +2 -0
- data/lib/graphql_devise/mutations/base.rb +2 -0
- data/lib/graphql_devise/mutations/login.rb +2 -0
- data/lib/graphql_devise/mutations/logout.rb +2 -0
- data/lib/graphql_devise/mutations/resend_confirmation.rb +5 -5
- data/lib/graphql_devise/mutations/send_password_reset.rb +7 -2
- data/lib/graphql_devise/mutations/sign_up.rb +13 -3
- data/lib/graphql_devise/mutations/update_password.rb +2 -0
- data/lib/graphql_devise/rails/routes.rb +2 -0
- data/lib/graphql_devise/resolvers/base.rb +2 -0
- data/lib/graphql_devise/resolvers/check_password_token.rb +2 -0
- data/lib/graphql_devise/resolvers/confirm_account.rb +4 -2
- data/lib/graphql_devise/resolvers/dummy.rb +2 -0
- data/lib/graphql_devise/resource_loader.rb +2 -0
- data/lib/graphql_devise/schema.rb +2 -0
- data/lib/graphql_devise/schema_plugin.rb +31 -4
- data/lib/graphql_devise/types/authenticatable_type.rb +2 -0
- data/lib/graphql_devise/types/credential_type.rb +2 -0
- data/lib/graphql_devise/types/mutation_type.rb +2 -0
- data/lib/graphql_devise/types/query_type.rb +2 -0
- data/lib/graphql_devise/version.rb +3 -1
- data/spec/dummy/Rakefile +2 -0
- data/spec/dummy/app/controllers/api/v1/graphql_controller.rb +35 -4
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/graphql/dummy_schema.rb +14 -2
- data/spec/dummy/app/graphql/interpreter_schema.rb +2 -0
- data/spec/dummy/app/graphql/mutations/login.rb +2 -0
- data/spec/dummy/app/graphql/mutations/register_confirmed_user.rb +2 -0
- data/spec/dummy/app/graphql/mutations/sign_up.rb +2 -0
- data/spec/dummy/app/graphql/mutations/update_user.rb +22 -0
- data/spec/dummy/app/graphql/resolvers/public_user.rb +2 -0
- data/spec/dummy/app/graphql/resolvers/user_show.rb +2 -0
- data/spec/dummy/app/graphql/types/base_object.rb +2 -0
- data/spec/dummy/app/graphql/types/custom_admin_type.rb +2 -0
- data/spec/dummy/app/graphql/types/mutation_type.rb +3 -0
- data/spec/dummy/app/graphql/types/query_type.rb +2 -0
- data/spec/dummy/app/graphql/types/user_type.rb +2 -0
- data/spec/dummy/app/jobs/application_job.rb +2 -0
- data/spec/dummy/app/mailers/application_mailer.rb +2 -0
- data/spec/dummy/app/models/admin.rb +2 -0
- data/spec/dummy/app/models/application_record.rb +2 -0
- data/spec/dummy/app/models/guest.rb +2 -0
- data/spec/dummy/app/models/schema_user.rb +13 -0
- data/spec/dummy/app/models/user.rb +2 -0
- data/spec/dummy/app/models/users.rb +2 -0
- data/spec/dummy/app/models/users/customer.rb +2 -0
- data/spec/dummy/config.ru +2 -0
- data/spec/dummy/config/application.rb +2 -0
- data/spec/dummy/config/environment.rb +2 -0
- data/spec/dummy/config/environments/development.rb +2 -0
- data/spec/dummy/config/environments/production.rb +2 -0
- data/spec/dummy/config/environments/test.rb +2 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +2 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +2 -0
- data/spec/dummy/config/initializers/cors.rb +2 -0
- data/spec/dummy/config/initializers/devise_token_auth.rb +2 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +2 -0
- data/spec/dummy/config/initializers/i18n.rb +2 -0
- data/spec/dummy/config/initializers/inflections.rb +2 -0
- data/spec/dummy/config/initializers/mime_types.rb +2 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +2 -0
- data/spec/dummy/config/puma.rb +2 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config/spring.rb +2 -0
- data/spec/dummy/db/migrate/20190815114303_create_users.rb +2 -0
- data/spec/dummy/db/migrate/20190824215150_add_auth_available_to_users.rb +2 -0
- data/spec/dummy/db/migrate/20190916012505_create_admins.rb +2 -0
- data/spec/dummy/db/migrate/20191013213045_create_guests.rb +2 -0
- data/spec/dummy/db/migrate/20200321121807_create_users_customers.rb +2 -0
- data/spec/dummy/db/migrate/20200621182414_remove_uncofirmed_email_from_admins.rb +7 -0
- data/spec/dummy/db/migrate/20200623003142_create_schema_users.rb +46 -0
- data/spec/dummy/db/schema.rb +30 -2
- data/spec/dummy/db/seeds.rb +2 -0
- data/spec/factories/admins.rb +2 -0
- data/spec/factories/guests.rb +2 -0
- data/spec/factories/schema_users.rb +13 -0
- data/spec/factories/users.rb +2 -0
- data/spec/factories/users_customers.rb +2 -0
- data/spec/generators/graphql_devise/install_generator_spec.rb +3 -1
- data/spec/graphql_devise/model/with_email_updater_spec.rb +131 -0
- data/spec/graphql_devise_spec.rb +2 -0
- data/spec/models/user_spec.rb +2 -0
- data/spec/rails_helper.rb +3 -0
- data/spec/requests/graphql_controller_spec.rb +2 -0
- data/spec/requests/mutations/additional_mutations_spec.rb +2 -0
- data/spec/requests/mutations/additional_queries_spec.rb +2 -0
- data/spec/requests/mutations/login_spec.rb +2 -0
- data/spec/requests/mutations/logout_spec.rb +2 -0
- data/spec/requests/mutations/resend_confirmation_spec.rb +46 -29
- data/spec/requests/mutations/send_password_reset_spec.rb +42 -12
- data/spec/requests/mutations/sign_up_spec.rb +15 -2
- data/spec/requests/mutations/update_password_spec.rb +2 -0
- data/spec/requests/queries/check_password_token_spec.rb +2 -0
- data/spec/requests/queries/confirm_account_spec.rb +9 -1
- data/spec/requests/user_controller_spec.rb +70 -12
- data/spec/services/mount_method/operation_preparer_spec.rb +8 -1
- data/spec/services/mount_method/operation_preparers/custom_operation_preparer_spec.rb +2 -0
- data/spec/services/mount_method/operation_preparers/default_operation_preparer_spec.rb +16 -7
- data/spec/services/mount_method/operation_preparers/gql_name_setter_spec.rb +2 -0
- data/spec/services/mount_method/operation_preparers/mutation_field_setter_spec.rb +20 -4
- data/spec/services/mount_method/operation_preparers/resolver_type_setter_spec.rb +2 -0
- data/spec/services/mount_method/operation_preparers/resource_name_setter_spec.rb +2 -0
- data/spec/services/mount_method/operation_sanitizer_spec.rb +2 -0
- data/spec/services/mount_method/option_sanitizer_spec.rb +2 -0
- data/spec/services/mount_method/option_sanitizers/array_checker_spec.rb +2 -0
- data/spec/services/mount_method/option_sanitizers/class_checker_spec.rb +2 -0
- data/spec/services/mount_method/option_sanitizers/hash_checker_spec.rb +2 -0
- data/spec/services/mount_method/option_sanitizers/string_checker_spec.rb +2 -0
- data/spec/services/mount_method/option_validators/provided_operations_validator_spec.rb +2 -0
- data/spec/services/mount_method/option_validators/skip_only_validator_spec.rb +2 -0
- data/spec/services/mount_method/option_validators/supported_operations_validator_spec.rb +2 -0
- data/spec/services/mount_method/options_validator_spec.rb +2 -0
- data/spec/services/resource_loader_spec.rb +2 -0
- data/spec/services/schema_plugin_spec.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/contexts/graphql_request.rb +2 -0
- data/spec/support/factory_bot.rb +2 -0
- data/spec/support/matchers/auth_headers_matcher.rb +2 -0
- data/spec/support/matchers/not_change_matcher.rb +2 -0
- data/spec/support/requests/auth_helpers.rb +2 -0
- data/spec/support/requests/json_helpers.rb +2 -0
- metadata +94 -87
- data/lib/graphql_devise/error_codes.rb +0 -5
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rails_helper'
|
2
4
|
|
3
5
|
RSpec.describe 'Account confirmation' do
|
@@ -22,7 +24,13 @@ RSpec.describe 'Account confirmation' do
|
|
22
24
|
context 'when confirmation token is correct' do
|
23
25
|
let(:token) { user.confirmation_token }
|
24
26
|
|
25
|
-
before
|
27
|
+
before do
|
28
|
+
user.send_confirmation_instructions(
|
29
|
+
template_path: ['graphql_devise/mailer'],
|
30
|
+
controller: 'graphql_devise/graphql',
|
31
|
+
schema_url: 'http://not-using-this-value.com/gql'
|
32
|
+
)
|
33
|
+
end
|
26
34
|
|
27
35
|
it 'confirms the resource and redirects to the sent url' do
|
28
36
|
expect do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rails_helper'
|
2
4
|
|
3
5
|
RSpec.describe "Integrations with the user's controller" do
|
@@ -29,6 +31,15 @@ RSpec.describe "Integrations with the user's controller" do
|
|
29
31
|
expect(json_response[:data][:publicField]).to eq('Field does not require authentication')
|
30
32
|
end
|
31
33
|
end
|
34
|
+
|
35
|
+
context 'when using the failing route' do
|
36
|
+
it 'raises an invalid resource_name error' do
|
37
|
+
expect { post_request('/api/v1/failing') }.to raise_error(
|
38
|
+
GraphqlDevise::Error,
|
39
|
+
'Invalid resource_name `fail` provided to `graphql_context`. Possible values are: [:user, :admin, :guest, :users_customer, :schema_user].'
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
32
43
|
end
|
33
44
|
|
34
45
|
describe 'privateField' do
|
@@ -46,15 +57,23 @@ RSpec.describe "Integrations with the user's controller" do
|
|
46
57
|
context 'when user is authenticated' do
|
47
58
|
let(:headers) { user.create_new_auth_token }
|
48
59
|
|
49
|
-
it '
|
60
|
+
it 'allows to perform the query' do
|
50
61
|
expect(json_response[:data][:privateField]).to eq('Field will always require authentication')
|
51
62
|
end
|
63
|
+
|
64
|
+
context 'when using a SchemaUser' do
|
65
|
+
let(:headers) { create(:schema_user, :confirmed).create_new_auth_token }
|
66
|
+
|
67
|
+
it 'allows to perform the query' do
|
68
|
+
expect(json_response[:data][:privateField]).to eq('Field will always require authentication')
|
69
|
+
end
|
70
|
+
end
|
52
71
|
end
|
53
72
|
|
54
73
|
context 'when user is not authenticated' do
|
55
74
|
it 'returns a must sign in error' do
|
56
75
|
expect(json_response[:errors]).to contain_exactly(
|
57
|
-
hash_including(message: 'privateField field requires authentication', extensions: { code: '
|
76
|
+
hash_including(message: 'privateField field requires authentication', extensions: { code: 'AUTHENTICATION_ERROR' })
|
58
77
|
)
|
59
78
|
end
|
60
79
|
end
|
@@ -66,7 +85,7 @@ RSpec.describe "Integrations with the user's controller" do
|
|
66
85
|
context 'when user is authenticated' do
|
67
86
|
let(:headers) { user.create_new_auth_token }
|
68
87
|
|
69
|
-
it '
|
88
|
+
it 'allows to perform the query' do
|
70
89
|
expect(json_response[:data][:privateField]).to eq('Field will always require authentication')
|
71
90
|
end
|
72
91
|
end
|
@@ -74,7 +93,7 @@ RSpec.describe "Integrations with the user's controller" do
|
|
74
93
|
context 'when user is not authenticated' do
|
75
94
|
it 'returns a must sign in error' do
|
76
95
|
expect(json_response[:errors]).to contain_exactly(
|
77
|
-
hash_including(message: 'privateField field requires authentication', extensions: { code: '
|
96
|
+
hash_including(message: 'privateField field requires authentication', extensions: { code: 'AUTHENTICATION_ERROR' })
|
78
97
|
)
|
79
98
|
end
|
80
99
|
end
|
@@ -96,7 +115,7 @@ RSpec.describe "Integrations with the user's controller" do
|
|
96
115
|
context 'when user is authenticated' do
|
97
116
|
let(:headers) { user.create_new_auth_token }
|
98
117
|
|
99
|
-
it '
|
118
|
+
it 'allows to perform the query' do
|
100
119
|
expect(json_response[:data][:dummyMutation]).to eq('Necessary so GraphQL gem does not complain about empty mutation type')
|
101
120
|
end
|
102
121
|
end
|
@@ -104,7 +123,7 @@ RSpec.describe "Integrations with the user's controller" do
|
|
104
123
|
context 'when user is not authenticated' do
|
105
124
|
it 'returns a must sign in error' do
|
106
125
|
expect(json_response[:errors]).to contain_exactly(
|
107
|
-
hash_including(message: 'dummyMutation field requires authentication', extensions: { code: '
|
126
|
+
hash_including(message: 'dummyMutation field requires authentication', extensions: { code: 'AUTHENTICATION_ERROR' })
|
108
127
|
)
|
109
128
|
end
|
110
129
|
end
|
@@ -116,7 +135,7 @@ RSpec.describe "Integrations with the user's controller" do
|
|
116
135
|
context 'when user is authenticated' do
|
117
136
|
let(:headers) { user.create_new_auth_token }
|
118
137
|
|
119
|
-
it '
|
138
|
+
it 'allows to perform the query' do
|
120
139
|
expect(json_response[:data][:dummyMutation]).to eq('Necessary so GraphQL gem does not complain about empty mutation type')
|
121
140
|
end
|
122
141
|
end
|
@@ -124,7 +143,7 @@ RSpec.describe "Integrations with the user's controller" do
|
|
124
143
|
context 'when user is not authenticated' do
|
125
144
|
it 'returns a must sign in error' do
|
126
145
|
expect(json_response[:errors]).to contain_exactly(
|
127
|
-
hash_including(message: 'dummyMutation field requires authentication', extensions: { code: '
|
146
|
+
hash_including(message: 'dummyMutation field requires authentication', extensions: { code: 'AUTHENTICATION_ERROR' })
|
128
147
|
)
|
129
148
|
end
|
130
149
|
end
|
@@ -151,7 +170,7 @@ RSpec.describe "Integrations with the user's controller" do
|
|
151
170
|
context 'when user is authenticated' do
|
152
171
|
let(:headers) { user.create_new_auth_token }
|
153
172
|
|
154
|
-
it '
|
173
|
+
it 'allows to perform the query' do
|
155
174
|
expect(json_response[:data][:user]).to match(
|
156
175
|
email: user.email,
|
157
176
|
id: user.id
|
@@ -162,7 +181,7 @@ RSpec.describe "Integrations with the user's controller" do
|
|
162
181
|
context 'when user is not authenticated' do
|
163
182
|
it 'returns a must sign in error' do
|
164
183
|
expect(json_response[:errors]).to contain_exactly(
|
165
|
-
hash_including(message: 'user field requires authentication', extensions: { code: '
|
184
|
+
hash_including(message: 'user field requires authentication', extensions: { code: 'AUTHENTICATION_ERROR' })
|
166
185
|
)
|
167
186
|
end
|
168
187
|
end
|
@@ -174,7 +193,7 @@ RSpec.describe "Integrations with the user's controller" do
|
|
174
193
|
context 'when user is authenticated' do
|
175
194
|
let(:headers) { user.create_new_auth_token }
|
176
195
|
|
177
|
-
it '
|
196
|
+
it 'allows to perform the query' do
|
178
197
|
expect(json_response[:data][:user]).to match(
|
179
198
|
email: user.email,
|
180
199
|
id: user.id
|
@@ -184,7 +203,7 @@ RSpec.describe "Integrations with the user's controller" do
|
|
184
203
|
|
185
204
|
context 'when user is not authenticated' do
|
186
205
|
# Interpreter schema fields are public unless specified otherwise (plugin setting)
|
187
|
-
it '
|
206
|
+
it 'allows to perform the query' do
|
188
207
|
expect(json_response[:data][:user]).to match(
|
189
208
|
email: user.email,
|
190
209
|
id: user.id
|
@@ -193,4 +212,43 @@ RSpec.describe "Integrations with the user's controller" do
|
|
193
212
|
end
|
194
213
|
end
|
195
214
|
end
|
215
|
+
|
216
|
+
describe 'updateUser' do
|
217
|
+
let(:headers) { user.create_new_auth_token }
|
218
|
+
let(:query) do
|
219
|
+
<<-GRAPHQL
|
220
|
+
mutation {
|
221
|
+
updateUser(email: "updated@gmail.com", name: "updated name") {
|
222
|
+
user { email name }
|
223
|
+
}
|
224
|
+
}
|
225
|
+
GRAPHQL
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'requires new email confirmation' do
|
229
|
+
original_email = user.email
|
230
|
+
|
231
|
+
expect do
|
232
|
+
post_request('/api/v1/graphql?test=value')
|
233
|
+
user.reload
|
234
|
+
end.to not_change(user, :email).from(original_email).and(
|
235
|
+
change(user, :unconfirmed_email).from(nil).to('updated@gmail.com')
|
236
|
+
).and(
|
237
|
+
not_change(user, :uid).from(original_email)
|
238
|
+
).and(
|
239
|
+
change(user, :name).from(user.name).to('updated name')
|
240
|
+
)
|
241
|
+
|
242
|
+
email = Nokogiri::HTML(ActionMailer::Base.deliveries.last.body.encoded)
|
243
|
+
link = email.css('a').first
|
244
|
+
expect(link['href']).to include('/api/v1/graphql')
|
245
|
+
|
246
|
+
expect do
|
247
|
+
get link['href']
|
248
|
+
user.reload
|
249
|
+
end.to change(user, :email).from(original_email).to('updated@gmail.com').and(
|
250
|
+
change(user, :uid).from(original_email).to('updated@gmail.com')
|
251
|
+
)
|
252
|
+
end
|
253
|
+
end
|
196
254
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
RSpec.describe GraphqlDevise::MountMethod::OperationPreparer do
|
@@ -14,10 +16,15 @@ RSpec.describe GraphqlDevise::MountMethod::OperationPreparer do
|
|
14
16
|
|
15
17
|
let(:logout_class) { Class.new(GraphQL::Schema::Resolver) }
|
16
18
|
let(:mapping) { :user }
|
17
|
-
let(:selected) { { login: double(:login_default), logout: logout_class } }
|
18
19
|
let(:preparer) { double(:preparer, call: logout_class) }
|
19
20
|
let(:custom) { { login: double(:custom_login, graphql_name: nil) } }
|
20
21
|
let(:additional) { { user_additional: double(:user_additional) } }
|
22
|
+
let(:selected) do
|
23
|
+
{
|
24
|
+
login: { klass: double(:login_default) },
|
25
|
+
logout:{ klass: logout_class }
|
26
|
+
}
|
27
|
+
end
|
21
28
|
|
22
29
|
it 'is expected to return all provided operation keys' do
|
23
30
|
expect(prepared_operations.keys).to contain_exactly(
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
RSpec.describe GraphqlDevise::MountMethod::OperationPreparers::DefaultOperationPreparer do
|
@@ -11,18 +13,25 @@ RSpec.describe GraphqlDevise::MountMethod::OperationPreparers::DefaultOperationP
|
|
11
13
|
let(:logout_operation) { double(:sign_up_operation, graphql_name: nil) }
|
12
14
|
let(:mapping_name) { :user }
|
13
15
|
let(:preparer) { double(:preparer) }
|
14
|
-
let(:operations) { { login: login_operation, logout: logout_operation, sign_up: sign_up_operation, confirm: confirm_operation } }
|
15
16
|
let(:custom_keys) { [:login, :logout] }
|
17
|
+
let(:operations) do
|
18
|
+
{
|
19
|
+
confirm: { klass: confirm_operation, authenticatable: false },
|
20
|
+
sign_up: { klass: sign_up_operation, authenticatable: true },
|
21
|
+
login: { klass: login_operation, authenticatable: true },
|
22
|
+
logout: { klass: logout_operation, authenticatable: true }
|
23
|
+
}
|
24
|
+
end
|
16
25
|
|
17
26
|
before do
|
18
27
|
allow(default_preparer).to receive(:child_class).with(confirm_operation).and_return(confirm_operation)
|
19
28
|
allow(default_preparer).to receive(:child_class).with(sign_up_operation).and_return(sign_up_operation)
|
20
29
|
allow(default_preparer).to receive(:child_class).with(login_operation).and_return(login_operation)
|
21
30
|
allow(default_preparer).to receive(:child_class).with(logout_operation).and_return(logout_operation)
|
22
|
-
allow(preparer).to receive(:call).with(confirm_operation).and_return(confirm_operation)
|
23
|
-
allow(preparer).to receive(:call).with(sign_up_operation).and_return(sign_up_operation)
|
24
|
-
allow(preparer).to receive(:call).with(login_operation).and_return(login_operation)
|
25
|
-
allow(preparer).to receive(:call).with(logout_operation).and_return(logout_operation)
|
31
|
+
allow(preparer).to receive(:call).with(confirm_operation, authenticatable: false).and_return(confirm_operation)
|
32
|
+
allow(preparer).to receive(:call).with(sign_up_operation, authenticatable: true).and_return(sign_up_operation)
|
33
|
+
allow(preparer).to receive(:call).with(login_operation, authenticatable: true).and_return(login_operation)
|
34
|
+
allow(preparer).to receive(:call).with(logout_operation, authenticatable: true).and_return(logout_operation)
|
26
35
|
end
|
27
36
|
|
28
37
|
it 'returns only those operations with no custom operation provided' do
|
@@ -32,8 +41,8 @@ RSpec.describe GraphqlDevise::MountMethod::OperationPreparers::DefaultOperationP
|
|
32
41
|
it 'prepares default operations' do
|
33
42
|
expect(confirm_operation).to receive(:graphql_name).with('UserConfirm')
|
34
43
|
expect(sign_up_operation).to receive(:graphql_name).with('UserSignUp')
|
35
|
-
expect(preparer).to receive(:call).with(confirm_operation)
|
36
|
-
expect(preparer).to receive(:call).with(sign_up_operation)
|
44
|
+
expect(preparer).to receive(:call).with(confirm_operation, authenticatable: false)
|
45
|
+
expect(preparer).to receive(:call).with(sign_up_operation, authenticatable: true)
|
37
46
|
|
38
47
|
prepared
|
39
48
|
|
@@ -1,16 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
RSpec.describe GraphqlDevise::MountMethod::OperationPreparers::MutationFieldSetter do
|
4
6
|
describe '#call' do
|
5
|
-
subject(:prepared_operation) { described_class.new(field_type).call(operation) }
|
7
|
+
subject(:prepared_operation) { described_class.new(field_type).call(operation, authenticatable: authenticatable) }
|
6
8
|
|
7
9
|
let(:operation) { double(:operation) }
|
8
10
|
let(:field_type) { double(:type) }
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
+
context 'when resource is authtenticable' do
|
13
|
+
let(:authenticatable) { true }
|
14
|
+
|
15
|
+
it 'sets a field for the mutation' do
|
16
|
+
expect(operation).to receive(:field).with(:authenticatable, field_type, null: false)
|
17
|
+
|
18
|
+
prepared_operation
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'when resource is *NOT* authtenticable' do
|
23
|
+
let(:authenticatable) { false }
|
24
|
+
|
25
|
+
it 'does *NOT* set a field for the mutation' do
|
26
|
+
expect(operation).not_to receive(:field)
|
12
27
|
|
13
|
-
|
28
|
+
prepared_operation
|
29
|
+
end
|
14
30
|
end
|
15
31
|
end
|
16
32
|
end
|
data/spec/spec_helper.rb
CHANGED