-
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.
- Loading branch information
1 parent
b1e0865
commit dbf076c
Showing
3 changed files
with
124 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "Movies", type: :request do | ||
describe "DELETE /api/movies/:id" do | ||
context "when movie exists" do | ||
let!(:movie) { | ||
Movies::Create.new( | ||
params: { | ||
director: "George Lucas", | ||
writer: "George Lucas", | ||
title: "Star Wars", | ||
producer: "George Lucas", | ||
production_company: "Lucasfilm", | ||
cast: ["Han Solo", "Princess Leia"], | ||
year: 1977 | ||
} | ||
).call | ||
} | ||
|
||
it "responds with 204" do | ||
expect { delete "/api/movies/#{movie.id}" } | ||
.to change { MoviesRepository.count }.by(-1) | ||
|
||
expect(response).to have_http_status(:no_content) | ||
end | ||
end | ||
|
||
context "when movie does not exist" do | ||
it "responds with 204" do | ||
delete "/api/movies/123" | ||
|
||
expect(response).to have_http_status(:no_content) | ||
end | ||
end | ||
end | ||
end |
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,43 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "Movies", type: :request do | ||
let(:response_json) { JSON.parse(response.body) } | ||
|
||
describe "GET /api/movies/:id" do | ||
context "when there is a movie" do | ||
let!(:game) { | ||
Movies::Create.new( | ||
params: { | ||
director: "George Lucas", | ||
writer: "George Lucas", | ||
title: "Star Wars", | ||
producer: "George Lucas", | ||
production_company: "Lucasfilm", | ||
cast: ["Han Solo", "Princess Leia"], | ||
year: 1977 | ||
} | ||
).call | ||
} | ||
|
||
it "responds with a movie" do | ||
get "/api/movies/#{game.id}" | ||
|
||
expect(response_json).to include({ | ||
"title" => "Star Wars", | ||
"cast" => ["Han Solo", "Princess Leia"], | ||
"year" => 1977 | ||
}) | ||
expect(response).to have_http_status(:ok) | ||
end | ||
end | ||
|
||
context "when there is no movie" do | ||
it "responds with an error" do | ||
get "/api/movies/1" | ||
|
||
expect(response_json).to eq({ "error" => "Movie not found" }) | ||
expect(response).to have_http_status(:not_found) | ||
end | ||
end | ||
end | ||
end |
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,45 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "Movies", type: :request do | ||
let(:response_json) { JSON.parse(response.body) } | ||
|
||
let(:params) do | ||
{ | ||
"movie" => { | ||
"title": "Star Wars 2" | ||
} | ||
} | ||
end | ||
|
||
describe "PATCH /api/movies/:id" do | ||
context "when movie exists" do | ||
let!(:movie) { | ||
Movies::Create.new( | ||
params: { | ||
director: "George Lucas", | ||
writer: "George Lucas", | ||
title: "Star Wars", | ||
producer: "George Lucas", | ||
production_company: "Lucasfilm", | ||
cast: ["Han Solo", "Princess Leia"], | ||
year: 1977 | ||
} | ||
).call | ||
} | ||
|
||
it "responds with 200" do | ||
patch "/api/movies/#{movie.id}", params: params | ||
|
||
expect(response).to have_http_status(:no_content) | ||
end | ||
end | ||
|
||
context "when movie does not exist" do | ||
it "responds with 404" do | ||
patch "/api/movies/1", params: params | ||
|
||
expect(response).to have_http_status(:not_found) | ||
end | ||
end | ||
end | ||
end |