Skip to content

Commit 47074a3

Browse files
authored
Merge branch 'master' into EDM-480/async-upload-refactor
2 parents e54e3b5 + 25c1780 commit 47074a3

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ gem 'base64', '~> 0.2.0' # ruby 3.4.0 warning said to add
1111
gem 'bcrypt', '~> 3.1.20'
1212
gem 'bootsnap', require: false
1313
gem 'cancancan', '~> 1.13', '>= 1.13.1' # Use cancancan for authorization
14+
gem 'cgi', '>= 0.4.2'
1415
gem 'config'
1516
gem 'csv', '~> 3.3' # ruby 3.4.0 warning said to add
1617
gem 'devise' # Use devise for authentication

Gemfile.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ GEM
142142
xpath (~> 3.2)
143143
case_transform (0.2)
144144
activesupport
145-
cgi (0.4.1)
145+
cgi (0.4.2)
146146
coderay (1.1.3)
147147
coercible (1.0.0)
148148
descendants_tracker (~> 0.0.1)
@@ -552,6 +552,7 @@ DEPENDENCIES
552552
byebug
553553
cancancan (~> 1.13, >= 1.13.1)
554554
capybara (= 3.40.0)
555+
cgi (>= 0.4.2)
555556
config
556557
csv (~> 3.3)
557558
database_cleaner

app/models/complaint.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ def self.rollup_sums(on_column, version_id)
100100

101101
set_clause = []
102102
sum_clause = []
103+
# some ope codes are placeholders (e.g. 'VA000200', 'VA000300') and are assigned while
104+
# an institution is in the process of being assigned a 'real' ope id. These temporary
105+
# ope ids _should not_ be used to roll up complaints, since it will inevitably result
106+
# in complaints being attributed to institutions that have nothing to do with the offending
107+
# location. So, when doing ope6 rollups, we ignore anything that start with an 'A'. This
108+
# seems to be a reliable enough pattern to filter out these ephemeral ope ids.
109+
ope6_format_clause = on_column == :ope6 ? "AND NOT institutions.#{on_column} LIKE 'A%'" : ''
103110

104111
rollup_sums.each_pair do |sum_column, complaint_column|
105112
set_clause << %("#{sum_column}" = sums.#{sum_column})
@@ -112,6 +119,7 @@ def self.rollup_sums(on_column, version_id)
112119
(SELECT "#{on_column}", #{sum_clause.join(', ')} FROM complaints GROUP BY #{on_column}) AS sums
113120
WHERE institutions.#{on_column} = sums.#{on_column} AND
114121
institutions.version_id = #{version_id} AND institutions.#{on_column} IS NOT NULL
122+
#{ope6_format_clause}
115123
SQL
116124

117125
Complaint.connection.update(str)

spec/models/complaint_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,22 @@
118118
end
119119
end
120120
end
121+
122+
describe 'by ope6 with temporary ope ids' do
123+
before do
124+
create :version, :production
125+
institution = create :institution, :institution_builder, version_id: Version.last.id, ope: 'VA000200', ope6: 'A0002'
126+
127+
create :complaint, :all_issues, ope: 'VA000200'
128+
described_class.rollup_sums(:ope6, institution.version_id)
129+
end
130+
131+
it 'ignores the temporary ope id complaint(s)' do
132+
institution = Institution.first
133+
Complaint::OPE6_ROLL_UP_SUMS.each_key do |ope6_sum|
134+
expect(institution[ope6_sum]).to be_nil
135+
end
136+
end
137+
end
121138
end
122139
end

0 commit comments

Comments
 (0)