graphql_devise 0.12.3 → 0.13.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +54 -0
- data/Gemfile +2 -0
- data/README.md +116 -65
- 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 +6 -0
- 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 +16 -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/routes.rb +2 -0
- data/lib/generators/graphql_devise/install_generator.rb +3 -1
- data/lib/graphql_devise.rb +2 -0
- data/lib/graphql_devise/concerns/controller_methods.rb +2 -0
- data/lib/graphql_devise/default_operations/mutations.rb +2 -0
- data/lib/graphql_devise/default_operations/resolvers.rb +2 -0
- data/lib/graphql_devise/engine.rb +2 -0
- data/lib/graphql_devise/errors/authentication_error.rb +2 -0
- data/lib/graphql_devise/errors/detailed_user_error.rb +2 -0
- data/lib/graphql_devise/errors/error_codes.rb +2 -0
- data/lib/graphql_devise/errors/execution_error.rb +2 -0
- data/lib/graphql_devise/errors/user_error.rb +2 -0
- 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 +2 -0
- data/lib/graphql_devise/mount_method/operation_preparers/gql_name_setter.rb +2 -0
- data/lib/graphql_devise/mount_method/operation_preparers/mutation_field_setter.rb +2 -0
- data/lib/graphql_devise/mount_method/operation_preparers/resolver_type_setter.rb +2 -0
- data/lib/graphql_devise/mount_method/operation_preparers/resource_name_setter.rb +2 -0
- 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 +16 -6
- data/lib/graphql_devise/mutations/send_password_reset.rb +3 -1
- data/lib/graphql_devise/mutations/sign_up.rb +12 -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 +7 -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 +8 -0
- 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 +3 -1
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/graphql/dummy_schema.rb +4 -1
- 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/confirm_admin_account.rb +13 -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/admin_type.rb +8 -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.rb +1 -1
- 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 +5 -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 +28 -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 +29 -4
- data/spec/requests/mutations/send_password_reset_spec.rb +2 -0
- 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 +102 -42
- data/spec/requests/user_controller_spec.rb +57 -8
- data/spec/services/mount_method/operation_preparer_spec.rb +2 -0
- 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 +2 -0
- 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 +2 -0
- 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 +19 -2
data/spec/dummy/config/puma.rb
CHANGED
data/spec/dummy/config/routes.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
Rails.application.routes.draw do
|
2
4
|
mount_graphql_devise_for 'User', at: '/api/v1/graphql_auth', operations: {
|
3
5
|
login: Mutations::Login,
|
@@ -12,6 +14,9 @@ Rails.application.routes.draw do
|
|
12
14
|
'Admin',
|
13
15
|
authenticatable_type: Types::CustomAdminType,
|
14
16
|
skip: [:sign_up, :check_password_token],
|
17
|
+
operations: {
|
18
|
+
confirm_account: Resolvers::ConfirmAdminAccount
|
19
|
+
},
|
15
20
|
at: '/api/v1/admin/graphql_auth'
|
16
21
|
)
|
17
22
|
|
data/spec/dummy/config/spring.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CreateSchemaUsers < ActiveRecord::Migration[6.0]
|
4
|
+
def change
|
5
|
+
create_table :schema_users do |t|
|
6
|
+
## Required
|
7
|
+
t.string :provider, null: false, default: 'email'
|
8
|
+
t.string :uid, null: false, default: ''
|
9
|
+
|
10
|
+
## Database authenticatable
|
11
|
+
t.string :encrypted_password, null: false, default: ''
|
12
|
+
|
13
|
+
## Recoverable
|
14
|
+
t.string :reset_password_token
|
15
|
+
t.datetime :reset_password_sent_at
|
16
|
+
t.boolean :allow_password_change, default: false
|
17
|
+
|
18
|
+
## Confirmable
|
19
|
+
t.string :confirmation_token
|
20
|
+
t.datetime :confirmed_at
|
21
|
+
t.datetime :confirmation_sent_at
|
22
|
+
|
23
|
+
# Trackable
|
24
|
+
t.datetime :current_sign_in_at
|
25
|
+
t.datetime :last_sign_in_at
|
26
|
+
t.string :last_sign_in_ip
|
27
|
+
t.string :current_sign_in_ip
|
28
|
+
t.integer :sign_in_count
|
29
|
+
|
30
|
+
## User Info
|
31
|
+
t.string :name
|
32
|
+
t.string :email
|
33
|
+
|
34
|
+
## Tokens
|
35
|
+
t.text :tokens
|
36
|
+
|
37
|
+
t.timestamps
|
38
|
+
end
|
39
|
+
|
40
|
+
add_index :schema_users, :email, unique: true
|
41
|
+
add_index :schema_users, [:uid, :provider], unique: true
|
42
|
+
add_index :schema_users, :reset_password_token, unique: true
|
43
|
+
add_index :schema_users, :confirmation_token, unique: true
|
44
|
+
add_index :schema_users, :unlock_token, unique: true
|
45
|
+
end
|
46
|
+
end
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
#
|
11
11
|
# It's strongly recommended that you check this file into your version control system.
|
12
12
|
|
13
|
-
ActiveRecord::Schema.define(version:
|
13
|
+
ActiveRecord::Schema.define(version: 2020_06_23_003142) do
|
14
14
|
|
15
15
|
create_table "admins", force: :cascade do |t|
|
16
16
|
t.string "provider", default: "email", null: false
|
@@ -22,7 +22,6 @@ ActiveRecord::Schema.define(version: 2020_03_21_121807) do
|
|
22
22
|
t.string "confirmation_token"
|
23
23
|
t.datetime "confirmed_at"
|
24
24
|
t.datetime "confirmation_sent_at"
|
25
|
-
t.string "unconfirmed_email"
|
26
25
|
t.string "email"
|
27
26
|
t.text "tokens"
|
28
27
|
t.datetime "created_at", null: false
|
@@ -54,6 +53,33 @@ ActiveRecord::Schema.define(version: 2020_03_21_121807) do
|
|
54
53
|
t.index ["uid", "provider"], name: "index_guests_on_uid_and_provider", unique: true
|
55
54
|
end
|
56
55
|
|
56
|
+
create_table "schema_users", force: :cascade do |t|
|
57
|
+
t.string "provider", default: "email", null: false
|
58
|
+
t.string "uid", default: "", null: false
|
59
|
+
t.string "encrypted_password", default: "", null: false
|
60
|
+
t.string "reset_password_token"
|
61
|
+
t.datetime "reset_password_sent_at"
|
62
|
+
t.boolean "allow_password_change", default: false
|
63
|
+
t.string "confirmation_token"
|
64
|
+
t.datetime "confirmed_at"
|
65
|
+
t.datetime "confirmation_sent_at"
|
66
|
+
t.datetime "current_sign_in_at"
|
67
|
+
t.datetime "last_sign_in_at"
|
68
|
+
t.string "last_sign_in_ip"
|
69
|
+
t.string "current_sign_in_ip"
|
70
|
+
t.integer "sign_in_count"
|
71
|
+
t.string "name"
|
72
|
+
t.string "email"
|
73
|
+
t.text "tokens"
|
74
|
+
t.datetime "created_at", precision: 6, null: false
|
75
|
+
t.datetime "updated_at", precision: 6, null: false
|
76
|
+
t.index "\"unlock_token\"", name: "index_schema_users_on_unlock_token", unique: true
|
77
|
+
t.index ["confirmation_token"], name: "index_schema_users_on_confirmation_token", unique: true
|
78
|
+
t.index ["email"], name: "index_schema_users_on_email", unique: true
|
79
|
+
t.index ["reset_password_token"], name: "index_schema_users_on_reset_password_token", unique: true
|
80
|
+
t.index ["uid", "provider"], name: "index_schema_users_on_uid_and_provider", unique: true
|
81
|
+
end
|
82
|
+
|
57
83
|
create_table "users", force: :cascade do |t|
|
58
84
|
t.string "provider", default: "email", null: false
|
59
85
|
t.string "uid", default: "", null: false
|
data/spec/dummy/db/seeds.rb
CHANGED
data/spec/factories/admins.rb
CHANGED
data/spec/factories/guests.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
FactoryBot.define do
|
4
|
+
factory :schema_user do
|
5
|
+
name { Faker::FunnyName.two_word_name }
|
6
|
+
email { Faker::Internet.unique.email }
|
7
|
+
password { Faker::Internet.password }
|
8
|
+
|
9
|
+
trait :confirmed do
|
10
|
+
confirmed_at { Time.zone.now }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/spec/factories/users.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Generators are not automatically loaded by Rails
|
2
4
|
require 'rails_helper'
|
3
5
|
require 'generators/graphql_devise/install_generator'
|
@@ -39,7 +41,7 @@ RSpec.describe GraphqlDevise::InstallGenerator, type: :generator do
|
|
39
41
|
let(:args) { [] }
|
40
42
|
|
41
43
|
it 'creates and updated required files' do
|
42
|
-
assert_file 'config/routes.rb', /^\s{2}mount_graphql_devise_for 'User', at: '
|
44
|
+
assert_file 'config/routes.rb', /^\s{2}mount_graphql_devise_for 'User', at: 'graphql_auth'/
|
43
45
|
expect(routes_content).not_to match(dta_route)
|
44
46
|
|
45
47
|
assert_file 'config/initializers/devise.rb'
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
RSpec.describe GraphqlDevise::Model::WithEmailUpdater do
|
6
|
+
describe '#call' do
|
7
|
+
subject(:updater) { described_class.new(resource, attributes).call }
|
8
|
+
|
9
|
+
context 'when the model does not have an unconfirmed_email column' do
|
10
|
+
let(:resource) { create(:admin, :confirmed) }
|
11
|
+
|
12
|
+
context 'when attributes contain email' do
|
13
|
+
let(:attributes) { { email: 'new@gmail.com', schema_url: 'http://localhost/test', confirmation_success_url: 'https://google.com' } }
|
14
|
+
|
15
|
+
it 'does not postpone email update' do
|
16
|
+
expect do
|
17
|
+
updater
|
18
|
+
resource.reload
|
19
|
+
end.to change(resource, :email).from(resource.email).to('new@gmail.com').and(
|
20
|
+
change(resource, :uid).from(resource.uid).to('new@gmail.com')
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when the model has an unconfirmed_email column' do
|
27
|
+
let(:resource) { create(:user, :confirmed) }
|
28
|
+
|
29
|
+
context 'when attributes do not contain email' do
|
30
|
+
let(:attributes) { { name: 'Updated Name', schema_url: 'http://localhost/test', confirmation_success_url: 'https://google.com' } }
|
31
|
+
|
32
|
+
it 'updates resource, ignores url params' do
|
33
|
+
expect do
|
34
|
+
updater
|
35
|
+
resource.reload
|
36
|
+
end.to change(resource, :name).from(resource.name).to('Updated Name')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when attributes contain email' do
|
41
|
+
context 'when schema_url is missing' do
|
42
|
+
let(:attributes) { { email: 'new@gmail.com', name: 'Updated Name' } }
|
43
|
+
|
44
|
+
it 'raises an error' do
|
45
|
+
expect { updater }.to raise_error(
|
46
|
+
GraphqlDevise::Error,
|
47
|
+
'Method `update_with_email` requires attributes `confirmation_success_url` and `schema_url` for email reconfirmation to work'
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when email will not change' do
|
52
|
+
let(:attributes) { { email: resource.email, name: 'changed' } }
|
53
|
+
|
54
|
+
it 'updates name and does not raise an error' do
|
55
|
+
expect do
|
56
|
+
updater
|
57
|
+
resource.reload
|
58
|
+
end.to change(resource, :name).from(resource.name).to('changed').and(
|
59
|
+
not_change(resource, :email).from(resource.email)
|
60
|
+
).and(
|
61
|
+
not_change(ActionMailer::Base.deliveries, :count).from(0)
|
62
|
+
)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when only confirmation_success_url is missing' do
|
68
|
+
let(:attributes) { { email: 'new@gmail.com', name: 'Updated Name', schema_url: 'http://localhost/test' } }
|
69
|
+
|
70
|
+
it 'uses DTA default_confirm_success_url on the email' do
|
71
|
+
expect { updater }.to change(ActionMailer::Base.deliveries, :count).by(1)
|
72
|
+
|
73
|
+
email = ActionMailer::Base.deliveries.first
|
74
|
+
expect(email.body.decoded).to include(CGI.escape('https://google.com'))
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'when both required urls are provided' do
|
79
|
+
let(:attributes) { { email: 'new@gmail.com', name: 'Updated Name', schema_url: 'http://localhost/test', confirmation_success_url: 'https://google.com' } }
|
80
|
+
|
81
|
+
it 'postpones email update' do
|
82
|
+
expect do
|
83
|
+
updater
|
84
|
+
resource.reload
|
85
|
+
end.to not_change(resource, :email).from(resource.email).and(
|
86
|
+
not_change(resource, :uid).from(resource.uid)
|
87
|
+
).and(
|
88
|
+
change(resource, :unconfirmed_email).from(nil).to('new@gmail.com')
|
89
|
+
).and(
|
90
|
+
change(resource, :name).from(resource.name).to('Updated Name')
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'sends out a confirmation email to the unconfirmed_email' do
|
95
|
+
expect { updater }.to change(ActionMailer::Base.deliveries, :count).by(1)
|
96
|
+
|
97
|
+
email = ActionMailer::Base.deliveries.first
|
98
|
+
expect(email.to).to contain_exactly('new@gmail.com')
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'when email value is the same on the DB' do
|
102
|
+
let(:attributes) { { email: resource.email, name: 'changed', schema_url: 'http://localhost/test', confirmation_success_url: 'https://google.com' } }
|
103
|
+
|
104
|
+
it 'updates attributes and does not send confirmation email' do
|
105
|
+
expect do
|
106
|
+
updater
|
107
|
+
resource.reload
|
108
|
+
end.to change(resource, :name).from(resource.name).to('changed').and(
|
109
|
+
not_change(resource, :email).from(resource.email)
|
110
|
+
).and(
|
111
|
+
not_change(ActionMailer::Base.deliveries, :count).from(0)
|
112
|
+
)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'when provided params are invalid' do
|
117
|
+
let(:attributes) { { email: 'newgmail.com', name: '', schema_url: 'http://localhost/test', confirmation_success_url: 'https://google.com' } }
|
118
|
+
|
119
|
+
it 'returns false and adds errors to the model' do
|
120
|
+
expect(updater).to be_falsey
|
121
|
+
expect(resource.errors.full_messages).to contain_exactly(
|
122
|
+
'Email is not an email',
|
123
|
+
"Name can't be blank"
|
124
|
+
)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
data/spec/graphql_devise_spec.rb
CHANGED
data/spec/models/user_spec.rb
CHANGED
data/spec/rails_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
ENV['RAILS_ENV'] ||= 'test'
|
@@ -42,4 +44,5 @@ RSpec.configure do |config|
|
|
42
44
|
config.before(:suite) do
|
43
45
|
ActionController::Base.allow_forgery_protection = true
|
44
46
|
end
|
47
|
+
config.before { ActionMailer::Base.deliveries.clear }
|
45
48
|
end
|