Skip to content

Commit

Permalink
Add grape endpoint to delete an artwork
Browse files Browse the repository at this point in the history
  • Loading branch information
jonallured committed Mar 5, 2024
1 parent 3951e3a commit 50647e0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/api/using_grape/artworks_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ class ArtworksEndpoint < Grape::API
error! errors, 400
end
end

delete ":id" do
artwork = Artwork.find(params[:id])
if artwork
artwork.destroy
else
error!
end
end
end
end
end
20 changes: 20 additions & 0 deletions spec/requests/using_grape/delete_artwork_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require "rails_helper"

describe "DELETE /api/using_grape/artworks/:id" do
let(:artwork) { FactoryBot.create(:artwork) }

context "with an invalid id" do
it "returns a 404" do
delete "/api/using_grape/artworks/invalid"
expect(response.status).to eq 404
end
end

context "with a valid id" do
it "returns a 200" do
delete "/api/using_grape/artworks/#{artwork.id}"
expect(response.status).to eq 200
expect(Artwork.count).to eq 0
end
end
end

0 comments on commit 50647e0

Please sign in to comment.