Skip to content

Commit

Permalink
Merge pull request #1284 from SplitTime/oveson/fix-vmulti-duplicates
Browse files Browse the repository at this point in the history
Fix historical fact vmulti duplicates
  • Loading branch information
moveson authored Dec 1, 2024
2 parents 35cadaf + f6c5f93 commit 8c22397
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def record_volunteer_reported(struct)

if years_count.present? && years_count.positive?
proto_record = base_proto_record.deep_dup
proto_record[:kind] = :volunteer_multi
proto_record[:kind] = :volunteer_multi_reported
proto_record[:quantity] = years_count
proto_record[:comments] = struct[:Volunteer_description]

Expand Down
23 changes: 23 additions & 0 deletions lib/tasks/temp/historical_facts_fix_vmulti_duplicates.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

namespace :temp do
desc "Changes imported volunteer_multi records to volunteer_multi_reported"
task historical_facts_fix_vmulti_duplicates: :environment do
puts "Changing volunteer_multi records to volunteer_multi_reported"

historical_facts = HistoricalFact.where(kind: :volunteer_multi, year: 2024)
hf_count = historical_facts.count

puts "Found #{hf_count} historical facts to update"

progress_bar = ::ProgressBar.new(hf_count)

historical_facts.find_each do |fact|
progress_bar.increment!
fact.update(kind: :volunteer_multi_reported)
rescue ActiveRecordError => e
puts "Could not update record for HistoricalFact id: #{fact.id}"
puts e
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
end

it "returns one proto_record for each multi-year volunteer fact" do
volunteer_multi_proto_records = proto_records.select { |proto_record| proto_record.attributes[:kind] == :volunteer_multi }
volunteer_multi_proto_records = proto_records.select { |proto_record| proto_record.attributes[:kind] == :volunteer_multi_reported }
expect(volunteer_multi_proto_records.count).to eq(1)
proto_record = volunteer_multi_proto_records.first
expect(proto_record[:quantity]).to eq(3)
Expand Down

0 comments on commit 8c22397

Please sign in to comment.