Skip to content

Commit

Permalink
Add endpoint to show artwork
Browse files Browse the repository at this point in the history
  • Loading branch information
jonallured committed Mar 5, 2024
1 parent f8da606 commit 638f524
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/controllers/api/using_nothing/artworks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ def index
artworks = Artwork.all
render json: artworks
end

def show
artwork = Artwork.find(params[:id])
render json: artwork
end
end
end
end
20 changes: 20 additions & 0 deletions spec/requests/using_nothing/show_artwork_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require "rails_helper"

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

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

context "with valid id" do
it "returns that artwork" do
get "/api/using_nothing/artworks/#{artwork.id}"
expect(response.status).to eq 200
expect(response.parsed_body).to eq artwork.as_json
end
end
end

0 comments on commit 638f524

Please sign in to comment.