diff --git a/config/environments/production.rb b/config/environments/production.rb index 44964fd..642f8c8 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -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 diff --git a/config/initializers/devise_token_auth.rb b/config/initializers/devise_token_auth.rb index dfdb32d..3875021 100644 --- a/config/initializers/devise_token_auth.rb +++ b/config/initializers/devise_token_auth.rb @@ -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 diff --git a/spec/requests/passwords_reset_spec.rb b/spec/requests/passwords_reset_spec.rb new file mode 100644 index 0000000..ce915b4 --- /dev/null +++ b/spec/requests/passwords_reset_spec.rb @@ -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: 'testemail@railsapi.uy', + 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