Skip to content

Commit

Permalink
Use the url where the schema is mounted in the reset password email link
Browse files Browse the repository at this point in the history
  • Loading branch information
00dav00 committed Jun 16, 2020
1 parent 55ec2a1 commit 7f62372
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 15 deletions.
Expand Up @@ -2,7 +2,7 @@

<p><%= t('.request_reset_link_msg') %></p>

<p><%= link_to t('.password_change_link'), url_for(controller: 'graphql_devise/graphql', action: :auth, **password_reset_query(token: @token, redirect_url: message['redirect-url'], resource_name: @resource.class.to_s)) %></p>
<p><%= link_to t('.password_change_link'), url_for(controller: message['controller'], action: message['action'], **password_reset_query(token: @token, redirect_url: message['redirect-url'], resource_name: @resource.class.to_s)) %></p>

<p><%= t('.ignore_mail_msg') %></p>
<p><%= t('.no_changes_msg') %></p>
3 changes: 2 additions & 1 deletion lib/graphql_devise/mutations/send_password_reset.rb
Expand Up @@ -16,7 +16,8 @@ def resolve(email:, redirect_url:)
email: email,
provider: 'email',
redirect_url: redirect_url,
template_path: ['graphql_devise/mailer']
template_path: ['graphql_devise/mailer'],
**controller.params.permit('controller', 'action').to_h.symbolize_keys
)

if resource.errors.empty?
Expand Down
5 changes: 4 additions & 1 deletion spec/dummy/app/graphql/dummy_schema.rb
Expand Up @@ -3,7 +3,10 @@ class DummySchema < GraphQL::Schema
query: Types::QueryType,
mutation: Types::MutationType,
resource_loaders: [
GraphqlDevise::ResourceLoader.new('User', only: [:login, :confirm_account]),
GraphqlDevise::ResourceLoader.new(
'User',
only: [:login, :confirm_account, :send_password_reset, :check_password_token]
),
GraphqlDevise::ResourceLoader.new('Guest', only: [:logout])
]
)
Expand Down
1 change: 1 addition & 0 deletions spec/dummy/config/routes.rb
Expand Up @@ -27,6 +27,7 @@
at: '/api/v1/user_customer/graphql_auth'
)

get '/api/v1/graphql', to: 'api/v1/graphql#graphql'
post '/api/v1/graphql', to: 'api/v1/graphql#graphql'
post '/api/v1/interpreter', to: 'api/v1/graphql#interpreter'
end
49 changes: 37 additions & 12 deletions spec/requests/mutations/send_password_reset_spec.rb
Expand Up @@ -20,21 +20,46 @@
end

context 'when params are correct' do
it 'sends password reset email' do
expect { post_request }.to change(ActionMailer::Base.deliveries, :count).by(1)
context 'when using gem' do
it 'sends password reset email' do
expect { post_request }.to change(ActionMailer::Base.deliveries, :count).by(1)

expect(json_response[:data][:userSendPasswordReset]).to include(
message: 'You will receive an email with instructions on how to reset your password in a few minutes.'
)
expect(json_response[:data][:userSendPasswordReset]).to include(
message: 'You will receive an email with instructions on how to reset your password in a few minutes.'
)

email = Nokogiri::HTML(ActionMailer::Base.deliveries.last.body.encoded)
link = email.css('a').first
expect(link['href']).to include('/api/v1/graphql_auth?')

# TODO: Move to feature spec
expect do
get link['href']
user.reload
end.to change(user, :allow_password_change).from(false).to(true)
end
end

context 'when using a custom schema' do
let(:custom_path) { '/api/v1/graphql' }

it 'sends password reset email' do
expect { post_request(custom_path) }.to change(ActionMailer::Base.deliveries, :count).by(1)

expect(json_response[:data][:userSendPasswordReset]).to include(
message: 'You will receive an email with instructions on how to reset your password in a few minutes.'
)

email = Nokogiri::HTML(ActionMailer::Base.deliveries.last.body.encoded)
link = email.css('a').first
email = Nokogiri::HTML(ActionMailer::Base.deliveries.last.body.encoded)
link = email.css('a').first
expect(link['href']).to include("#{custom_path}?")

# TODO: Move to feature spec
expect do
get link['href']
user.reload
end.to change(user, :allow_password_change).from(false).to(true)
# TODO: Move to feature spec
expect do
get link['href']
user.reload
end.to change(user, :allow_password_change).from(false).to(true)
end
end
end

Expand Down

0 comments on commit 7f62372

Please sign in to comment.