|
492 | 492 | end |
493 | 493 | end |
494 | 494 | end |
| 495 | + |
| 496 | + describe "#teams_for_academic_year" do |
| 497 | + subject(:teams_for_academic_year) do |
| 498 | + location.teams_for_academic_year(target_year) |
| 499 | + end |
| 500 | + |
| 501 | + let(:location) { create(:school) } |
| 502 | + let(:team_a) { create(:team) } |
| 503 | + let(:team_b) { create(:team) } |
| 504 | + let(:team_c) { create(:team) } |
| 505 | + let(:current_year) { AcademicYear.current } |
| 506 | + let(:next_year) { AcademicYear.current + 1 } |
| 507 | + let(:target_year) { current_year } |
| 508 | + |
| 509 | + before do |
| 510 | + location.attach_to_team!(team_a, academic_year: current_year) |
| 511 | + location.attach_to_team!(team_b, academic_year: current_year) |
| 512 | + location.attach_to_team!(team_c, academic_year: next_year) |
| 513 | + end |
| 514 | + |
| 515 | + context "when requesting current academic year teams" do |
| 516 | + it "returns only teams for the current academic year" do |
| 517 | + expect(teams_for_academic_year).to contain_exactly(team_a, team_b) |
| 518 | + end |
| 519 | + |
| 520 | + it "does not return teams from other academic years" do |
| 521 | + expect(teams_for_academic_year).not_to include(team_c) |
| 522 | + end |
| 523 | + end |
| 524 | + |
| 525 | + context "when requesting next academic year teams" do |
| 526 | + let(:target_year) { next_year } |
| 527 | + |
| 528 | + it "returns only teams for the next academic year" do |
| 529 | + expect(teams_for_academic_year).to contain_exactly(team_c) |
| 530 | + end |
| 531 | + |
| 532 | + it "does not return teams from other academic years" do |
| 533 | + expect(teams_for_academic_year).not_to include(team_a, team_b) |
| 534 | + end |
| 535 | + end |
| 536 | + |
| 537 | + context "when the location has no teams for the specified year" do |
| 538 | + let(:location_without_teams) { create(:school) } |
| 539 | + let(:pending_year) { AcademicYear.pending } |
| 540 | + |
| 541 | + it "returns an empty array" do |
| 542 | + expect( |
| 543 | + location_without_teams.teams_for_academic_year(pending_year) |
| 544 | + ).to be_empty |
| 545 | + end |
| 546 | + end |
| 547 | + end |
495 | 548 | end |
0 commit comments