Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions app/models/graphql_devise/concerns/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ def update_with_email(attributes = {})
GraphqlDevise::Model::WithEmailUpdater.new(self, attributes).call
end

private

def pending_reconfirmation?
devise_modules.include?(:confirmable) && try(:unconfirmed_email).present?
end
Expand Down
18 changes: 13 additions & 5 deletions lib/graphql_devise/mutations/resend_confirmation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ class ResendConfirmation < Base
field :message, String, null: false

def resolve(email:, redirect_url:)
resource = find_resource(
:email,
get_case_insensitive_field(:email, email)
)
resource = find_confirmable_resource(email)

if resource
yield resource if block_given?

raise_user_error(I18n.t('graphql_devise.confirmations.already_confirmed')) if resource.confirmed?
if resource.confirmed? && !resource.pending_reconfirmation?
raise_user_error(I18n.t('graphql_devise.confirmations.already_confirmed'))
end

resource.send_confirmation_instructions(
redirect_url: redirect_url,
Expand All @@ -30,6 +29,15 @@ def resolve(email:, redirect_url:)
raise_user_error(I18n.t('graphql_devise.confirmations.user_not_found', email: email))
end
end

private

def find_confirmable_resource(email)
email_insensitive = get_case_insensitive_field(:email, email)
resource = find_resource(:unconfirmed_email, email_insensitive) if resource_class.reconfirmable
resource ||= find_resource(:email, email_insensitive)
resource
end
end
end
end
23 changes: 23 additions & 0 deletions spec/requests/mutations/resend_confirmation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,29 @@
end
end

context 'when the email was changed' do
let(:email) { 'new-email@wallaceinc.com' }
let(:new_email) { email }

before do
user.class.reconfirmable = true
user.confirm
user.update_with_email(
email: new_email,
schema_url: 'http://localhost/test',
confirmation_success_url: 'https://google.com'
)
end

it 'sends new confirmation email' do
expect { post_request }.to change(ActionMailer::Base.deliveries, :count).by(1)
expect(ActionMailer::Base.deliveries.first.to).to contain_exactly(new_email)
expect(json_response[:data][:userResendConfirmation]).to include(
message: 'You will receive an email with instructions for how to confirm your email address in a few minutes.'
)
end
end

context "when the email isn't in the system" do
let(:email) { 'nothere@gmail.com' }

Expand Down