Merge pull request #3432 from consul/fix_exception_with_wrong_token

Fix exception when confirming an invalid token
This commit is contained in:
Javier Martín
2019-04-10 18:55:44 +02:00
committed by GitHub
2 changed files with 14 additions and 1 deletions

View File

@@ -27,7 +27,7 @@ class Users::ConfirmationsController < Devise::ConfirmationsController
def show
# In the default implementation, this already confirms the resource:
# self.resource = self.resource = resource_class.confirm_by_token(params[:confirmation_token])
self.resource = resource_class.find_by(confirmation_token: params[:confirmation_token])
self.resource = resource_class.find_by!(confirmation_token: params[:confirmation_token])
yield resource if block_given?

View File

@@ -0,0 +1,13 @@
require "rails_helper"
describe Users::ConfirmationsController do
before do
@request.env["devise.mapping"] = Devise.mappings[:user]
end
describe "GET show" do
it "returns a 404 code with a wrong token" do
expect { get :show, token: "non_existent" }.to raise_error ActiveRecord::RecordNotFound
end
end
end