Skip to content

Commit

Permalink
Merge pull request consuldemocracy#1961 from AyuntamientoMadrid/upstr…
Browse files Browse the repository at this point in the history
…eam-fix_exception_with_wrong_token

Fix exception when confirming an invalid token
  • Loading branch information
javierm committed Apr 11, 2019
2 parents 4f75637 + 4afb9fe commit dd0f12f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/users/confirmations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def update
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?

Expand Down
13 changes: 13 additions & 0 deletions spec/controllers/users/confirmations_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit dd0f12f

Please sign in to comment.