Skip to content

Commit e557a74

Browse files
authored
Merge pull request #3623 from nhsuk/filter-year-groups
Query full subset of year groups
2 parents aa93a0e + f277ffb commit e557a74

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

app/controllers/api/locations_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def index
1414

1515
if (year_groups = params[:year_groups]).present?
1616
@locations =
17-
@locations.where("year_groups && ARRAY[?]::integer[]", year_groups)
17+
@locations.where("ARRAY[?]::integer[] <@ year_groups", year_groups)
1818
end
1919

2020
if (

spec/requests/api/locations_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,22 @@
7575

7676
expect(locations).to eq([primary_school.as_json])
7777
end
78+
79+
context "with multiple year groups" do
80+
before { create(:school, year_groups: [8, 9]) }
81+
82+
let!(:secondary_school) { create(:school, year_groups: [8, 9, 10]) }
83+
84+
it "includes locations with all those year groups" do
85+
get "/api/locations", params: { year_groups: [8, 9, 10] }
86+
87+
expect(response).to have_http_status(:ok)
88+
89+
locations = JSON.parse(response.body)
90+
91+
expect(locations).to eq([secondary_school.as_json])
92+
end
93+
end
7894
end
7995

8096
context "when filtering by attached to organisation" do

0 commit comments

Comments
 (0)