Implement alerts index
This commit is contained in:
@@ -1,4 +1,9 @@
|
|||||||
module Api::V1::Parks
|
module Api::V1::Parks
|
||||||
class AlertsController < BaseController
|
class AlertsController < BaseController
|
||||||
|
before_action :set_park
|
||||||
|
|
||||||
|
def index
|
||||||
|
render json: @park.alerts
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ Rails.application.routes.draw do
|
|||||||
namespace :api do
|
namespace :api do
|
||||||
namespace :v1 do
|
namespace :v1 do
|
||||||
resources :parks, only: %i[index show], param: :code do
|
resources :parks, only: %i[index show], param: :code do
|
||||||
resources :alerts, only: %i[index]
|
resources :alerts, only: %i[index], module: :parks
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,6 +2,21 @@ require 'rails_helper'
|
|||||||
|
|
||||||
RSpec.describe "Api::V1::Parks::Alerts", type: :request do
|
RSpec.describe "Api::V1::Parks::Alerts", type: :request do
|
||||||
describe "GET /parks/:code/alerts" do
|
describe "GET /parks/:code/alerts" do
|
||||||
pending "add some examples (or delete) #{__FILE__}"
|
it "returns the alerts associated to a park" do
|
||||||
|
get api_v1_park_alerts_url(parks(:one).code)
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
expect(response.parsed_body.count).to eq(1)
|
||||||
|
expect(response.parsed_body).to include(
|
||||||
|
hash_including(
|
||||||
|
:description, park_code: "crla", title: "Fire Restrictions in Effect",
|
||||||
|
category: "caution", indexed_date: "2025-07-04T22:07:59.000Z"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns :not_found for unknown parks" do
|
||||||
|
get api_v1_park_alerts_url("foo")
|
||||||
|
expect(response).to have_http_status(:not_found)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ RSpec.describe "Api::V1::Parks", type: :request do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "returns the park" do
|
it "returns the park" do
|
||||||
get api_v1_park_url("crla")
|
get api_v1_park_url(parks(:one).code)
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
expect(response.parsed_body).to match(
|
expect(response.parsed_body).to match(
|
||||||
hash_including(
|
hash_including(
|
||||||
|
|||||||
Reference in New Issue
Block a user