Skip to content

Commit ce8bc2e

Browse files
committed
Apply code review changes
1 parent b6fac21 commit ce8bc2e

6 files changed

Lines changed: 13 additions & 7 deletions

File tree

app/graphql/graphql_devise/mutations/update_password.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def resolve(current_password: nil, **attrs)
1414
)
1515
end
1616

17-
if update_cresource_password(current_password, attrs)
17+
if update_resource_password(current_password, attrs)
1818
current_resource.allow_password_change = false if recoverable_enabled?
1919
current_resource.save!
2020

@@ -31,7 +31,7 @@ def resolve(current_password: nil, **attrs)
3131

3232
private
3333

34-
def update_cresource_password(current_password, attrs)
34+
def update_resource_password(current_password, attrs)
3535
allow_password_change = recoverable_enabled? && current_resource.allow_password_change == true
3636
if DeviseTokenAuth.check_current_password_before_update == false || allow_password_change
3737
current_resource.public_send(:update, attrs)

lib/graphql_devise.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
require 'devise_token_auth'
44
require 'graphql'
55
require 'graphql_devise/version'
6+
require 'graphql_devise/error_codes'
7+
require 'graphql_devise/user_error'
8+
require 'graphql_devise/detailed_user_error'
69

710
module GraphqlDevise
811
class Error < StandardError; end
912
end
10-
11-
require 'graphql_devise/user_error'
12-
require 'graphql_devise/detailed_user_error'

lib/graphql_devise/detailed_user_error.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def initialize(message, errors:)
88
end
99

1010
def to_h
11-
super.merge(extensions: { code: 'USER_ERROR', detailed_errors: @errors })
11+
super.merge(extensions: { code: ERROR_CODES.fetch(:user_error), detailed_errors: @errors })
1212
end
1313
end
1414
end

lib/graphql_devise/error_codes.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module GraphqlDevise
2+
ERROR_CODES = {
3+
user_error: 'USER_ERROR'
4+
}.freeze
5+
end

lib/graphql_devise/user_error.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module GraphqlDevise
22
class UserError < GraphQL::ExecutionError
33
def to_h
4-
super.merge(extensions: { code: 'USER_ERROR' })
4+
super.merge(extensions: { code: ERROR_CODES.fetch(:user_error) })
55
end
66
end
77
end

spec/requests/mutations/update_password_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
authenticable: { email: user.email }
1414
)
1515
expect(json_response[:errors]).to be_nil
16+
expect(user).to be_valid_password(password)
1617
end
1718
end
1819

0 commit comments

Comments
 (0)