Skip to content
Extraits de code Groupes Projets
Valider 8be3be3e rédigé par theworldbright's avatar theworldbright
Parcourir les fichiers

Refactor authorizations controller destroy action

parent 4dae744a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -18,11 +18,11 @@ module Api ...@@ -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
......
...@@ -3,6 +3,7 @@ require "spec_helper" ...@@ -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 ...@@ -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
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter