docbrown/spec/requests/api_secrets_destroy_spec.rb
Timothy Ng 84bd3a69d7 ApiSecret model for Developer API (#1369)
* Add ApiSecret model scaffold

* Add relationships between ApiSecret, User, Organization

* Add placeholder template to account tab

* Add description column to ApiSecrets

* Add very basic access token generation

* Add basic access token deletion

* Show access token on success flash

* Add placeholder message when user has no secrets

* Use cta style on token generation button

* Add presence validation for ApiSecret description

* Add ApiSecrets factory

* Add pundit policy for ApiSecret

* Nest form field within api_secret hash to allow rails strong params

* Use pundit to authorize ApiSecretController actions

* Add error message flash for ApiSecretsController actions

* Add specs for ApiSecretsController

* Add length validation to api secret description

* Flash model error instead of generic message on save failure

* Truncate ApiSecret factory objects descriptions to prevent validation error

* Remove length restriction on ApiSecret.description

* Use darker font color for token creation date

* Consolidate ApiSecret migrations
2019-01-08 12:30:54 -05:00

41 lines
1.2 KiB
Ruby

require "rails_helper"
RSpec.describe "ApiSecretsDestroy", type: :request do
let(:api_secret) { create(:api_secret) }
let(:user) { api_secret.user }
before { sign_in user }
describe "DELETE /users/api_secrets" do
context "when delete succeeds" do
it "deletes the ApiSecret for the user" do
expect { delete "/users/api_secrets", params: { id: api_secret.id } }.
to change { user.api_secrets.count }.by -1
end
it "flashes a notice" do
delete "/users/api_secrets", params: { id: api_secret.id }
expect(flash[:notice]).to be_truthy
expect(flash[:error]).to be_nil
end
end
context "when delete fails" do
before do
allow(ApiSecret).to receive(:find_by_id).and_return api_secret
allow(api_secret).to receive(:destroy).and_return false
end
it "does not delete the ApiSecret" do
expect { delete "/users/api_secrets", params: { id: api_secret.id } }.
not_to (change { user.api_secrets.count })
end
it "flashes an error message" do
delete "/users/api_secrets", params: { id: api_secret.id }
expect(flash[:error]).to be_truthy
expect(flash[:notice]).to be_nil
end
end
end
end