-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add grape endpoint to update an artwork
- Loading branch information
1 parent
ec90d09
commit 3951e3a
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require "rails_helper" | ||
|
||
describe "PUT /api/using_grape/artworks/:id" do | ||
let(:artwork) { FactoryBot.create(:artwork, title: "Fooncy cup") } | ||
|
||
context "with invalid update" do | ||
it "returns 400 and the errors" do | ||
params = {title: ""} | ||
|
||
put "/api/using_grape/artworks/#{artwork.id}", params: params | ||
|
||
expect(response.status).to eq 400 | ||
expect(response.parsed_body.key?("errors")).to eq true | ||
end | ||
end | ||
|
||
context "with partial update" do | ||
it "returns 200 and that updated artwork" do | ||
params = {title: "Fancy cup"} | ||
|
||
put "/api/using_grape/artworks/#{artwork.id}", params: params | ||
|
||
expect(response.status).to eq 200 | ||
expect(response.parsed_body["title"]).to eq "Fancy cup" | ||
end | ||
end | ||
|
||
context "with full update" do | ||
it "returns a 200 and that updated artwork" do | ||
params = { | ||
amount_cents: 100_000, | ||
artist_name: "Sally Sculptor", | ||
medium: "Clay", | ||
title: "Fancy cup" | ||
} | ||
|
||
put "/api/using_grape/artworks/#{artwork.id}", params: params | ||
|
||
expect(response.status).to eq 200 | ||
expect(response.parsed_body["amount_cents"]).to eq 100_000 | ||
expect(response.parsed_body["artist_name"]).to eq "Sally Sculptor" | ||
expect(response.parsed_body["medium"]).to eq "Clay" | ||
expect(response.parsed_body["title"]).to eq "Fancy cup" | ||
end | ||
end | ||
end |