Skip to content

Commit

Permalink
Add 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 deacd47 commit a989fa6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/controllers/api/using_nothing/artworks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ def update
end
end

def destroy
artwork = Artwork.find(params[:id])
if artwork
artwork.destroy
head :ok
else
head :not_found
end
end

private

def artwork_params
Expand Down
20 changes: 20 additions & 0 deletions spec/requests/using_nothing/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_nothing/artworks/:id" do
let(:artwork) { FactoryBot.create(:artwork) }

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

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

0 comments on commit a989fa6

Please sign in to comment.