Skip to content

Commit

Permalink
Merge branch 'master' into EDM-480/async-upload-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jefftmarks authored Mar 5, 2025
2 parents e54e3b5 + 25c1780 commit 47074a3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gem 'base64', '~> 0.2.0' # ruby 3.4.0 warning said to add
gem 'bcrypt', '~> 3.1.20'
gem 'bootsnap', require: false
gem 'cancancan', '~> 1.13', '>= 1.13.1' # Use cancancan for authorization
gem 'cgi', '>= 0.4.2'
gem 'config'
gem 'csv', '~> 3.3' # ruby 3.4.0 warning said to add
gem 'devise' # Use devise for authentication
Expand Down
3 changes: 2 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ GEM
xpath (~> 3.2)
case_transform (0.2)
activesupport
cgi (0.4.1)
cgi (0.4.2)
coderay (1.1.3)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
Expand Down Expand Up @@ -552,6 +552,7 @@ DEPENDENCIES
byebug
cancancan (~> 1.13, >= 1.13.1)
capybara (= 3.40.0)
cgi (>= 0.4.2)
config
csv (~> 3.3)
database_cleaner
Expand Down
8 changes: 8 additions & 0 deletions app/models/complaint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ def self.rollup_sums(on_column, version_id)

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

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

Complaint.connection.update(str)
Expand Down
17 changes: 17 additions & 0 deletions spec/models/complaint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,22 @@
end
end
end

describe 'by ope6 with temporary ope ids' do
before do
create :version, :production
institution = create :institution, :institution_builder, version_id: Version.last.id, ope: 'VA000200', ope6: 'A0002'

create :complaint, :all_issues, ope: 'VA000200'
described_class.rollup_sums(:ope6, institution.version_id)
end

it 'ignores the temporary ope id complaint(s)' do
institution = Institution.first
Complaint::OPE6_ROLL_UP_SUMS.each_key do |ope6_sum|
expect(institution[ope6_sum]).to be_nil
end
end
end
end
end

0 comments on commit 47074a3

Please sign in to comment.