Add specs for /parks/:code

This commit is contained in:
2025-10-07 23:12:34 -07:00
parent c3851592a7
commit 2e3c6006ae
2 changed files with 19 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
Rails.application.routes.draw do
namespace :api do
namespace :v1 do
resources :parks, only: %i[index]
resources :parks, only: %i[index show], param: :code
end
end
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html

View File

@@ -1,7 +1,7 @@
require 'rails_helper'
RSpec.describe "Api::V1::Parks", type: :request do
describe "GET /index" do
describe "GET /parks" do
it "returns parks" do
get api_v1_parks_url
expect(response).to have_http_status(:success)
@@ -34,4 +34,21 @@ RSpec.describe "Api::V1::Parks", type: :request do
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