app: fix exception during password reset when the token has expired

This commit is contained in:
Pierre de La Morinerie 2021-09-16 11:42:18 -05:00
parent 326956b002
commit eef90efd49
3 changed files with 35 additions and 7 deletions

View file

@ -17,12 +17,27 @@ describe DevisePopulatedResource, type: :controller do
end
context 'when initiating a password reset' do
subject { get :edit, params: { reset_password_token: @token } }
subject { get :edit, params: { reset_password_token: token } }
it 'returns the fully populated resource' do
subject
expect(controller.populated_resource.id).to eq(user.id)
expect(controller.populated_resource.email).to eq(user.email)
context 'with a valid token' do
let(:token) { @token }
it 'returns the fully populated resource' do
subject
expect(controller.populated_resource.id).to eq(user.id)
expect(controller.populated_resource.email).to eq(user.email)
end
end
context 'with an expired token' do
let(:token) { 'invalid-token' }
it 'returns a new blank resource' do
subject
expect(controller.populated_resource).to be_present
expect(controller.populated_resource.new_record?).to be(true)
expect(controller.populated_resource.email).to be_blank
end
end
end