Refactor authorizations controller destroy action

This commit is contained in:
theworldbright 2015-08-06 15:59:09 +09:00
parent 4dae744a4a
commit 8be3be3e10
2 changed files with 24 additions and 5 deletions

View file

@ -18,11 +18,11 @@ module Api
end
def destroy
# TODO: Specs
begin
Api::OpenidConnect::Authorization.find_by(id: params[:id]).destroy
rescue
logger.error "Error while trying revoke inexistant authorization #{params[:id]}"
authorization = Api::OpenidConnect::Authorization.find_by(id: params[:id])
if authorization
authorization.destroy
else
raise ArgumentError, "Error while trying revoke non-existent authorization with ID #{params[:id]}"
end
redirect_to user_applications_url
end

View file

@ -3,6 +3,7 @@ require "spec_helper"
describe Api::OpenidConnect::AuthorizationsController, type: :controller do
let!(:client) { FactoryGirl.create(:o_auth_application) }
let!(:client_with_multiple_redirects) { FactoryGirl.create(:o_auth_application_with_multiple_redirects) }
let!(:auth_with_read) { FactoryGirl.create(:auth_with_read) }
before do
sign_in :user, alice
@ -218,4 +219,22 @@ describe Api::OpenidConnect::AuthorizationsController, type: :controller do
end
end
end
describe "#destroy" do
context "with existent authorization" do
before do
delete :destroy, id: auth_with_read.id
end
it "removes the authorization" do
expect(Api::OpenidConnect::Authorization.find_by(id: auth_with_read.id)).to be_nil
end
end
context "with non-existent authorization" do
it "raises an error" do
expect{ delete :destroy, id: 123456789 }.to raise_error(ArgumentError)
end
end
end
end