Add specs for /parks/:code
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
namespace :api do
|
namespace :api do
|
||||||
namespace :v1 do
|
namespace :v1 do
|
||||||
resources :parks, only: %i[index]
|
resources :parks, only: %i[index show], param: :code
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
|
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe "Api::V1::Parks", type: :request do
|
RSpec.describe "Api::V1::Parks", type: :request do
|
||||||
describe "GET /index" do
|
describe "GET /parks" do
|
||||||
it "returns parks" do
|
it "returns parks" do
|
||||||
get api_v1_parks_url
|
get api_v1_parks_url
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
@@ -34,4 +34,21 @@ RSpec.describe "Api::V1::Parks", type: :request do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "GET /parks/:code" do
|
||||||
|
it "returns :not_found for unknown codes" do
|
||||||
|
get api_v1_park_url("foo")
|
||||||
|
expect(response).to have_http_status(:not_found)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the park" do
|
||||||
|
get api_v1_park_url("crla")
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
expect(response.parsed_body).to match(
|
||||||
|
hash_including(
|
||||||
|
code: "crla", name: "Crater Lake National Park", states: "OR"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user