File tree Expand file tree Collapse file tree
app/models/graphql_devise/concerns
lib/graphql_devise/mutations Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,8 +11,6 @@ def update_with_email(attributes = {})
1111 GraphqlDevise ::Model ::WithEmailUpdater . new ( self , attributes ) . call
1212 end
1313
14- private
15-
1614 def pending_reconfirmation?
1715 devise_modules . include? ( :confirmable ) && try ( :unconfirmed_email ) . present?
1816 end
Original file line number Diff line number Diff line change @@ -9,15 +9,14 @@ class ResendConfirmation < Base
99 field :message , String , null : false
1010
1111 def resolve ( email :, redirect_url :)
12- resource = find_resource (
13- :email ,
14- get_case_insensitive_field ( :email , email )
15- )
12+ resource = find_confirmable_resource ( email )
1613
1714 if resource
1815 yield resource if block_given?
1916
20- raise_user_error ( I18n . t ( 'graphql_devise.confirmations.already_confirmed' ) ) if resource . confirmed?
17+ if resource . confirmed? && !resource . pending_reconfirmation?
18+ raise_user_error ( I18n . t ( 'graphql_devise.confirmations.already_confirmed' ) )
19+ end
2120
2221 resource . send_confirmation_instructions (
2322 redirect_url : redirect_url ,
@@ -30,6 +29,15 @@ def resolve(email:, redirect_url:)
3029 raise_user_error ( I18n . t ( 'graphql_devise.confirmations.user_not_found' , email : email ) )
3130 end
3231 end
32+
33+ private
34+
35+ def find_confirmable_resource ( email )
36+ email_insensitive = get_case_insensitive_field ( :email , email )
37+ resource = find_resource ( :unconfirmed_email , email_insensitive ) if resource_class . reconfirmable
38+ resource ||= find_resource ( :email , email_insensitive )
39+ resource
40+ end
3341 end
3442 end
3543end
Original file line number Diff line number Diff line change 9898 end
9999 end
100100
101+ context 'when the email was changed' do
102+ let ( :email ) { 'new-email@wallaceinc.com' }
103+ let ( :new_email ) { email }
104+
105+ before do
106+ user . class . reconfirmable = true
107+ user . confirm
108+ user . update_with_email (
109+ email : new_email ,
110+ schema_url : 'http://localhost/test' ,
111+ confirmation_success_url : 'https://google.com'
112+ )
113+ end
114+
115+ it 'sends new confirmation email' do
116+ expect { post_request } . to change ( ActionMailer ::Base . deliveries , :count ) . by ( 1 )
117+ expect ( ActionMailer ::Base . deliveries . first . to ) . to contain_exactly ( new_email )
118+ expect ( json_response [ :data ] [ :userResendConfirmation ] ) . to include (
119+ message : 'You will receive an email with instructions for how to confirm your email address in a few minutes.'
120+ )
121+ end
122+ end
123+
101124 context "when the email isn't in the system" do
102125 let ( :email ) { 'nothere@gmail.com' }
103126
You can’t perform that action at this time.
0 commit comments