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 end
def destroy def destroy
# TODO: Specs authorization = Api::OpenidConnect::Authorization.find_by(id: params[:id])
begin if authorization
Api::OpenidConnect::Authorization.find_by(id: params[:id]).destroy authorization.destroy
rescue else
logger.error "Error while trying revoke inexistant authorization #{params[:id]}" raise ArgumentError, "Error while trying revoke non-existent authorization with ID #{params[:id]}"
end end
redirect_to user_applications_url redirect_to user_applications_url
end end

View file

@ -3,6 +3,7 @@ require "spec_helper"
describe Api::OpenidConnect::AuthorizationsController, type: :controller do describe Api::OpenidConnect::AuthorizationsController, type: :controller do
let!(:client) { FactoryGirl.create(:o_auth_application) } let!(:client) { FactoryGirl.create(:o_auth_application) }
let!(:client_with_multiple_redirects) { FactoryGirl.create(:o_auth_application_with_multiple_redirects) } let!(:client_with_multiple_redirects) { FactoryGirl.create(:o_auth_application_with_multiple_redirects) }
let!(:auth_with_read) { FactoryGirl.create(:auth_with_read) }
before do before do
sign_in :user, alice sign_in :user, alice
@ -218,4 +219,22 @@ describe Api::OpenidConnect::AuthorizationsController, type: :controller do
end end
end 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 end