File tree Expand file tree Collapse file tree 2 files changed +25
-8
lines changed Expand file tree Collapse file tree 2 files changed +25
-8
lines changed Original file line number Diff line number Diff line change @@ -20,8 +20,8 @@ def school
20
20
@school ||=
21
21
if ( urn = school_urn &.to_s ) . present? &&
22
22
![ SCHOOL_URN_HOME_EDUCATED , SCHOOL_URN_UNKNOWN ] . include? ( urn )
23
- Location . school . find_by_urn_and_site ( urn ) ||
24
- Location . school . find_by ( systm_one_code : urn )
23
+ schools . find_by_urn_and_site ( urn ) ||
24
+ schools . find_by ( systm_one_code : urn )
25
25
end
26
26
end
27
27
@@ -35,6 +35,10 @@ def home_educated
35
35
36
36
private
37
37
38
+ def schools
39
+ Location . school . eager_load ( :team ) . where ( subteam : { team : } )
40
+ end
41
+
38
42
def stage_registration?
39
43
true
40
44
end
@@ -56,8 +60,8 @@ def validate_school_urn
56
60
errors . add ( school_urn . header , "is required but missing" )
57
61
elsif !school_urn . to_s . in? (
58
62
[ SCHOOL_URN_HOME_EDUCATED , SCHOOL_URN_UNKNOWN ]
59
- ) && !Location . school . where_urn_and_site ( school_urn . to_s ) . exists? &&
60
- !Location . school . exists? ( systm_one_code : school_urn . to_s )
63
+ ) && !schools . where_urn_and_site ( school_urn . to_s ) . exists? &&
64
+ !schools . exists? ( systm_one_code : school_urn . to_s )
61
65
errors . add (
62
66
school_urn . header ,
63
67
"The school URN is not recognised. If you’ve checked the URN, " \
Original file line number Diff line number Diff line change 58
58
}
59
59
end
60
60
61
- before { create ( :school , urn : "123456" , team :) }
61
+ let! ( :school ) { create ( :school , urn : "123456" , team :) }
62
62
63
63
describe "validations" do
64
64
let ( :data ) { valid_data }
112
112
end
113
113
end
114
114
115
+ context "with a school for a different team" do
116
+ let ( :data ) { valid_data }
117
+
118
+ before { school . update! ( subteam : nil ) }
119
+
120
+ it "is invalid" do
121
+ expect ( cohort_import_row ) . to be_invalid
122
+ expect ( cohort_import_row . errors [ "CHILD_SCHOOL_URN" ] . first ) . to include (
123
+ "The school URN is not recognised."
124
+ )
125
+ end
126
+ end
127
+
115
128
context "with an invalid year group" do
116
129
let ( :data ) { valid_data . merge ( "CHILD_YEAR_GROUP" => "abc" ) }
117
130
661
674
end
662
675
663
676
describe "#school" do
664
- subject ( :school ) { school_move . school }
677
+ subject { school_move . school }
665
678
666
679
context "with a school location" do
667
680
let ( :school_urn ) { "123456" }
668
681
669
- it { should eq ( Location . first ) }
682
+ it { should eq ( school ) }
670
683
end
671
684
672
685
context "with an unknown school" do
683
696
end
684
697
685
698
describe "#home_educated" do
686
- subject ( :home_educated ) { school_move . home_educated }
699
+ subject { school_move . home_educated }
687
700
688
701
context "with a school location" do
689
702
let ( :school_urn ) { "123456" }
You can’t perform that action at this time.
0 commit comments