Return not_found error if org is not found (#5179) [deploy]

This commit is contained in:
Molly Struve 2019-12-19 10:53:50 -06:00 committed by GitHub
parent 36aed0458e
commit ac8e5b4fb0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View file

@ -79,6 +79,7 @@ class OrganizationsController < ApplicationController
def set_organization
@organization = Organization.find_by(id: organization_params[:id])
not_found unless @organization
authorize @organization
end
end

View file

@ -30,4 +30,11 @@ RSpec.describe "OrganizationsUpdate", type: :request do
put "/organizations/#{org_id}", params: { organization: { id: org_id, text_color_hex: "#111111" } }
expect(Organization.last.profile_updated_at).to be > 2.minutes.ago
end
it "returns not_found if organization is missing" do
invalid_id = org_id + 100
expect do
put "/organizations/#{invalid_id}", params: { organization: { id: invalid_id, text_color_hex: "#111111" } }
end.to raise_error(ActiveRecord::RecordNotFound)
end
end