Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def run
all_records = []

owners.each do |owner|
owned_records = records_by_owner[owner] || []
owned_records = records_by_owner[owner]&.uniq || []
all_records.concat(Array(owned_records)) if owner.jit_preloader || JitPreloader.globally_enabled?
associate_records_to_owner(owner, owned_records)
end
Expand Down
19 changes: 19 additions & 0 deletions spec/lib/jit_preloader/preloader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -439,4 +439,23 @@
end
end

context "duplicate records" do
let!(:contact1) { Contact.new(name: "1 contact, 1 phone number", phone_numbers: [phone_number]) }
let!(:contact2) { nil }
let!(:contact3) { nil }
let!(:contact_owner) { nil }

let(:phone_number) { PhoneNumber.new(phone: "123") }
let!(:email_adresses) do
[
EmailAddress.create!(address: "[email protected]", contact: contact1),
EmailAddress.create!(address: "[email protected]", contact: contact1),
]
end

it "does not assign duplicate records" do
expect(EmailAddress.jit_preload.to_a.map{|e| e.contact.phone_numbers.length }).to eql([1, 1])
end
end

end