graphql_devise 0.11.4 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.travis.yml +7 -0
- data/Appraisals +14 -0
- data/CHANGELOG.md +56 -0
- data/Gemfile +2 -0
- data/README.md +219 -20
- data/Rakefile +2 -0
- data/app/controllers/graphql_devise/application_controller.rb +6 -5
- data/app/controllers/graphql_devise/concerns/set_user_by_token.rb +31 -0
- data/app/controllers/graphql_devise/graphql_controller.rb +4 -0
- data/app/helpers/graphql_devise/application_helper.rb +2 -0
- data/app/helpers/graphql_devise/mailer_helper.rb +4 -2
- 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 +4 -0
- data/graphql_devise.gemspec +6 -4
- data/lib/generators/graphql_devise/install_generator.rb +30 -5
- data/lib/graphql_devise.rb +26 -10
- 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 +4 -2
- 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 +4 -2
- 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 +5 -6
- data/lib/graphql_devise/mutations/update_password.rb +2 -0
- data/lib/graphql_devise/rails/routes.rb +7 -72
- 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 +89 -0
- data/lib/graphql_devise/schema.rb +2 -0
- data/lib/graphql_devise/schema_plugin.rb +114 -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 +38 -3
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/graphql/dummy_schema.rb +21 -0
- data/spec/dummy/app/graphql/interpreter_schema.rb +11 -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 +4 -1
- data/spec/dummy/app/graphql/types/query_type.rb +12 -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 +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 +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 +23 -0
- 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 -1
- data/spec/requests/graphql_controller_spec.rb +82 -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 +2 -0
- 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 +237 -23
- data/spec/services/mount_method/operation_preparer_spec.rb +10 -3
- data/spec/services/mount_method/operation_preparers/custom_operation_preparer_spec.rb +3 -1
- data/spec/services/mount_method/operation_preparers/default_operation_preparer_spec.rb +17 -8
- 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 +3 -1
- 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 +84 -0
- data/spec/services/schema_plugin_spec.rb +28 -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 +120 -87
- data/lib/graphql_devise/error_codes.rb +0 -5
- data/spec/support/generators/file_helpers.rb +0 -12
@@ -37,6 +37,8 @@ DeviseTokenAuth.setup do |config|
|
|
37
37
|
# password is updated.
|
38
38
|
config.check_current_password_before_update = :password
|
39
39
|
|
40
|
+
config.default_confirm_success_url = 'https://google.com'
|
41
|
+
|
40
42
|
# By default we will use callbacks for single omniauth.
|
41
43
|
# It depends on fields like email, provider and uid.
|
42
44
|
# config.default_callbacks = true
|
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,
|
@@ -27,5 +29,8 @@ Rails.application.routes.draw do
|
|
27
29
|
at: '/api/v1/user_customer/graphql_auth'
|
28
30
|
)
|
29
31
|
|
32
|
+
get '/api/v1/graphql', to: 'api/v1/graphql#graphql'
|
30
33
|
post '/api/v1/graphql', to: 'api/v1/graphql#graphql'
|
34
|
+
post '/api/v1/interpreter', to: 'api/v1/graphql#interpreter'
|
35
|
+
post '/api/v1/failing', to: 'api/v1/graphql#failing_resource_name'
|
31
36
|
end
|
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
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This file is auto-generated from the current state of the database. Instead
|
2
4
|
# of editing this file, please use the migrations feature of Active Record to
|
3
5
|
# incrementally modify your database, and then regenerate this schema definition.
|
@@ -10,7 +12,7 @@
|
|
10
12
|
#
|
11
13
|
# It's strongly recommended that you check this file into your version control system.
|
12
14
|
|
13
|
-
ActiveRecord::Schema.define(version:
|
15
|
+
ActiveRecord::Schema.define(version: 2020_06_23_003142) do
|
14
16
|
|
15
17
|
create_table "admins", force: :cascade do |t|
|
16
18
|
t.string "provider", default: "email", null: false
|
@@ -22,7 +24,6 @@ ActiveRecord::Schema.define(version: 2020_03_21_121807) do
|
|
22
24
|
t.string "confirmation_token"
|
23
25
|
t.datetime "confirmed_at"
|
24
26
|
t.datetime "confirmation_sent_at"
|
25
|
-
t.string "unconfirmed_email"
|
26
27
|
t.string "email"
|
27
28
|
t.text "tokens"
|
28
29
|
t.datetime "created_at", null: false
|
@@ -54,6 +55,33 @@ ActiveRecord::Schema.define(version: 2020_03_21_121807) do
|
|
54
55
|
t.index ["uid", "provider"], name: "index_guests_on_uid_and_provider", unique: true
|
55
56
|
end
|
56
57
|
|
58
|
+
create_table "schema_users", force: :cascade do |t|
|
59
|
+
t.string "provider", default: "email", null: false
|
60
|
+
t.string "uid", default: "", null: false
|
61
|
+
t.string "encrypted_password", default: "", null: false
|
62
|
+
t.string "reset_password_token"
|
63
|
+
t.datetime "reset_password_sent_at"
|
64
|
+
t.boolean "allow_password_change", default: false
|
65
|
+
t.string "confirmation_token"
|
66
|
+
t.datetime "confirmed_at"
|
67
|
+
t.datetime "confirmation_sent_at"
|
68
|
+
t.datetime "current_sign_in_at"
|
69
|
+
t.datetime "last_sign_in_at"
|
70
|
+
t.string "last_sign_in_ip"
|
71
|
+
t.string "current_sign_in_ip"
|
72
|
+
t.integer "sign_in_count"
|
73
|
+
t.string "name"
|
74
|
+
t.string "email"
|
75
|
+
t.text "tokens"
|
76
|
+
t.datetime "created_at", precision: 6, null: false
|
77
|
+
t.datetime "updated_at", precision: 6, null: false
|
78
|
+
t.index "\"unlock_token\"", name: "index_schema_users_on_unlock_token", unique: true
|
79
|
+
t.index ["confirmation_token"], name: "index_schema_users_on_confirmation_token", unique: true
|
80
|
+
t.index ["email"], name: "index_schema_users_on_email", unique: true
|
81
|
+
t.index ["reset_password_token"], name: "index_schema_users_on_reset_password_token", unique: true
|
82
|
+
t.index ["uid", "provider"], name: "index_schema_users_on_uid_and_provider", unique: true
|
83
|
+
end
|
84
|
+
|
57
85
|
create_table "users", force: :cascade do |t|
|
58
86
|
t.string "provider", default: "email", null: false
|
59
87
|
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'
|
@@ -17,6 +19,24 @@ RSpec.describe GraphqlDevise::InstallGenerator, type: :generator do
|
|
17
19
|
run_generator(args)
|
18
20
|
end
|
19
21
|
|
22
|
+
context 'when mount option is schema' do
|
23
|
+
let(:args) { ['Admin', '--mount', 'GqldDummySchema'] }
|
24
|
+
|
25
|
+
it 'mounts the SchemaPlugin' do
|
26
|
+
assert_file 'config/initializers/devise.rb'
|
27
|
+
assert_file 'config/initializers/devise_token_auth.rb', /^\s{2}#{Regexp.escape('config.change_headers_on_each_request = false')}/
|
28
|
+
assert_file 'config/locales/devise.en.yml'
|
29
|
+
|
30
|
+
assert_migration 'db/migrate/devise_token_auth_create_admins.rb'
|
31
|
+
|
32
|
+
assert_file 'app/models/admin.rb', /^\s{2}devise :.+include GraphqlDevise::Concerns::Model/m
|
33
|
+
|
34
|
+
assert_file 'app/controllers/application_controller.rb', /^\s{2}include GraphqlDevise::Concerns::SetUserByToken/
|
35
|
+
|
36
|
+
assert_file 'app/graphql/gqld_dummy_schema.rb', /\s+#{Regexp.escape("GraphqlDevise::ResourceLoader.new('Admin')")}/
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
20
40
|
context 'when passing no params to the generator' do
|
21
41
|
let(:args) { [] }
|
22
42
|
|
@@ -59,5 +79,8 @@ RSpec.describe GraphqlDevise::InstallGenerator, type: :generator do
|
|
59
79
|
FileUtils.cd(File.join(destination_root, '..')) do
|
60
80
|
`rails new gqld_dummy -S -C --skip-action-mailbox --skip-action-text -T --skip-spring --skip-bundle --skip-keeps -G --skip-active-storage -J --skip-listen --skip-bootsnap`
|
61
81
|
end
|
82
|
+
FileUtils.cd(File.join(destination_root, '../gqld_dummy')) do
|
83
|
+
`rails generate graphql:install`
|
84
|
+
end
|
62
85
|
end
|
63
86
|
end
|
@@ -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
|