Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Password reset #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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: 2 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,6 @@
# config.active_record.database_selector = { delay: 2.seconds }
# config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
# config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session

config.action_mailer.default_url_options = { host: 'rails-api-learning-camp.herokuapp.com' }
end
2 changes: 1 addition & 1 deletion config/initializers/devise_token_auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
# By default DeviseTokenAuth will not send confirmation email, even when including
# devise confirmable module. If you want to use devise confirmable module and
# send email, set it to true. (This is a setting for compatibility)
# config.send_confirmation_email = true
config.send_confirmation_email = true

# config.default_confirm_success_url = 'confirmed'
end
50 changes: 50 additions & 0 deletions spec/requests/passwords_reset_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require 'rails_helper'

RSpec.describe 'POST registration/password', type: :request do
let(:user) { create(:user) }

subject(:send_reset_instructions) { post user_password_path, params: params, as: :json }

context 'with valid params' do
let(:params) do
{
email: user.email,
redirect_url: 'registration/password'
}
end

it 'returns a successful response' do
send_reset_instructions
expect(response).to be_successful
end

it 'send an email' do
expect { send_reset_instructions }.to change { ActionMailer::Base.deliveries.count }.by(1)
end

it 'check email account and subject' do
send_reset_instructions
email = ActionMailer::Base.deliveries.last
expect(email.to).to include(user.email)
expect(email.subject).to eq('Reset password instructions')
end
end

context 'with invalid params' do
let(:params) do
{
email: '[email protected]',
redirect_url: 'registration/password'
}
end

it 'returns a not found response' do
send_reset_instructions
expect(response).to be_not_found
end

it 'does not send an email' do
expect { send_reset_instructions }.to_not change { ActionMailer::Base.deliveries.count }
end
end
end