|  | 
| 14 | 14 |       PhoneNumber.new(phone: '4445556666'), | 
| 15 | 15 |       PhoneNumber.new(phone: '2223333444') | 
| 16 | 16 |     ] | 
| 17 |  | -    Contact.create(name: 'Only Addresses', addresses: addresses, phone_numbers: phones) | 
|  | 17 | +    Contact.create(name: 'Only Addresses', addresses:, phone_numbers: phones) | 
| 18 | 18 |   end | 
| 19 | 19 | 
 | 
| 20 | 20 |   let!(:contact2) do | 
|  | 
| 28 | 28 |     ] | 
| 29 | 29 |     Contact.create( | 
| 30 | 30 |       name: 'Both!', | 
| 31 |  | -      addresses: addresses, | 
|  | 31 | +      addresses:, | 
| 32 | 32 |       email_address: EmailAddress.new(address : '[email protected]'), | 
| 33 | 33 |       phone_numbers: [PhoneNumber.new(phone: '1234567890')] | 
| 34 | 34 |     ) | 
|  | 
| 54 | 54 |   context 'for single table inheritance' do | 
| 55 | 55 |     context 'when preloading an aggregate for a child model' do | 
| 56 | 56 |       let!(:contact_book) { ContactBook.create(name: 'The Yellow Pages') } | 
| 57 |  | -      let!(:company1) { Company.create(name: 'Company1', contact_book: contact_book) } | 
| 58 |  | -      let!(:company2) { Company.create(name: 'Company2', contact_book: contact_book) } | 
|  | 57 | +      let!(:company1) { Company.create(name: 'Company1', contact_book:) } | 
|  | 58 | +      let!(:company2) { Company.create(name: 'Company2', contact_book:) } | 
| 59 | 59 | 
 | 
| 60 | 60 |       it 'can handle queries' do | 
| 61 | 61 |         contact_books = ContactBook.jit_preload.to_a | 
|  | 
| 65 | 65 | 
 | 
| 66 | 66 |     context 'when preloading an aggregate of a child model through its base model' do | 
| 67 | 67 |       let!(:contact_book) { ContactBook.create(name: 'The Yellow Pages') } | 
| 68 |  | -      let!(:contact) { Contact.create(name: 'Contact', contact_book: contact_book) } | 
| 69 |  | -      let!(:company1) { Company.create(name: 'Company1', contact_book: contact_book) } | 
| 70 |  | -      let!(:company2) { Company.create(name: 'Company2', contact_book: contact_book) } | 
| 71 |  | -      let!(:contact_employee1) { Employee.create(name: 'Contact Employee1', contact: contact) } | 
| 72 |  | -      let!(:contact_employee2) { Employee.create(name: 'Contact Employee2', contact: contact) } | 
|  | 68 | +      let!(:contact) { Contact.create(name: 'Contact', contact_book:) } | 
|  | 69 | +      let!(:company1) { Company.create(name: 'Company1', contact_book:) } | 
|  | 70 | +      let!(:company2) { Company.create(name: 'Company2', contact_book:) } | 
|  | 71 | +      let!(:contact_employee1) { Employee.create(name: 'Contact Employee1', contact:) } | 
|  | 72 | +      let!(:contact_employee2) { Employee.create(name: 'Contact Employee2', contact:) } | 
| 73 | 73 |       let!(:company_employee1) { Employee.create(name: 'Company Employee1', contact: company1) } | 
| 74 | 74 |       let!(:company_employee2) { Employee.create(name: 'Company Employee2', contact: company2) } | 
| 75 | 75 | 
 | 
|  | 
| 81 | 81 | 
 | 
| 82 | 82 |     context 'when preloading an aggregate of a nested child model through another child model' do | 
| 83 | 83 |       let!(:contact_book) { ContactBook.create(name: 'The Yellow Pages') } | 
| 84 |  | -      let!(:contact) { Contact.create(name: 'Contact', contact_book: contact_book) } | 
| 85 |  | -      let!(:company1) { Company.create(name: 'Company1', contact_book: contact_book) } | 
| 86 |  | -      let!(:company2) { Company.create(name: 'Company2', contact_book: contact_book) } | 
| 87 |  | -      let!(:contact_employee1) { Employee.create(name: 'Contact Employee1', contact: contact) } | 
| 88 |  | -      let!(:contact_employee2) { Employee.create(name: 'Contact Employee2', contact: contact) } | 
|  | 84 | +      let!(:contact) { Contact.create(name: 'Contact', contact_book:) } | 
|  | 85 | +      let!(:company1) { Company.create(name: 'Company1', contact_book:) } | 
|  | 86 | +      let!(:company2) { Company.create(name: 'Company2', contact_book:) } | 
|  | 87 | +      let!(:contact_employee1) { Employee.create(name: 'Contact Employee1', contact:) } | 
|  | 88 | +      let!(:contact_employee2) { Employee.create(name: 'Contact Employee2', contact:) } | 
| 89 | 89 |       let!(:company_employee1) { Employee.create(name: 'Company Employee1', contact: company1) } | 
| 90 | 90 |       let!(:company_employee2) { Employee.create(name: 'Company Employee2', contact: company2) } | 
| 91 | 91 | 
 | 
|  | 
| 100 | 100 |       let!(:child1) { Child.create(name: 'Child1') } | 
| 101 | 101 |       let!(:child2) { Child.create(name: 'Child2') } | 
| 102 | 102 |       let!(:child3) { Child.create(name: 'Child3') } | 
| 103 |  | -      let!(:parent1) { Parent.create(name: 'Parent1', contact_book: contact_book, children: [child1, child2]) } | 
| 104 |  | -      let!(:parent2) { Parent.create(name: 'Parent2', contact_book: contact_book, children: [child2, child3]) } | 
|  | 103 | +      let!(:parent1) { Parent.create(name: 'Parent1', contact_book:, children: [child1, child2]) } | 
|  | 104 | +      let!(:parent2) { Parent.create(name: 'Parent2', contact_book:, children: [child2, child3]) } | 
| 105 | 105 | 
 | 
| 106 | 106 |       it 'can handle queries' do | 
| 107 | 107 |         contact_books = ContactBook.jit_preload.to_a | 
|  | 
| 112 | 112 | 
 | 
| 113 | 113 |     context 'when preloading an aggregate for a child model scoped by another join table' do | 
| 114 | 114 |       let!(:contact_book) { ContactBook.create(name: 'The Yellow Pages') } | 
| 115 |  | -      let!(:contact1) { Company.create(name: 'Without Email', contact_book: contact_book) } | 
| 116 |  | -      let!(:contact2) { Company.create(name: 'With Blank Email', email_address: EmailAddress.new(address: ''), contact_book: contact_book) } | 
| 117 |  | -      let!(:contact3) { Company.create(name: 'With Email', email_address : EmailAddress.new(address : '[email protected]'), contact_book :contact_book) } | 
|  | 115 | +      let!(:contact1) { Company.create(name: 'Without Email', contact_book:) } | 
|  | 116 | +      let!(:contact2) { Company.create(name: 'With Blank Email', email_address: EmailAddress.new(address: ''), contact_book:) } | 
|  | 117 | +      let!(:contact3) { Company.create(name: 'With Email', email_address : EmailAddress.new(address : '[email protected]'), contact_book :) } | 
| 118 | 118 | 
 | 
| 119 | 119 |       it 'can handle queries' do | 
| 120 | 120 |         contact_books = ContactBook.jit_preload.to_a | 
|  | 
| 230 | 230 | 
 | 
| 231 | 231 |   context 'when accessing an association with a scope that has a parameter' do | 
| 232 | 232 |     let!(:contact_book) { ContactBook.create(name: 'The Yellow Pages') } | 
| 233 |  | -    let!(:contact) { Contact.create(name: 'Contact', contact_book: contact_book) } | 
| 234 |  | -    let!(:company1) { Company.create(name: 'Company1', contact_book: contact_book) } | 
|  | 233 | +    let!(:contact) { Contact.create(name: 'Contact', contact_book:) } | 
|  | 234 | +    let!(:company1) { Company.create(name: 'Company1', contact_book:) } | 
| 235 | 235 | 
 | 
| 236 | 236 |     it 'is unable to be preloaded' do | 
| 237 | 237 |       ActiveSupport::Notifications.subscribed(callback, 'n_plus_one_query') do | 
|  | 
0 commit comments