Skip to content

Commit

Permalink
Merge pull request #444 from darren987469/fail_spec_for_unused_preloa…
Browse files Browse the repository at this point in the history
…d_associations

Add missing `check_unused_preload_associations` call to spec
  • Loading branch information
flyerhzm committed Mar 3, 2019
2 parents 11ef24f + a9d52a2 commit 58f8f4f
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 51 deletions.
8 changes: 0 additions & 8 deletions lib/bullet/active_record4.rb
Expand Up @@ -191,14 +191,6 @@ def has_cached_counter?(reflection = reflection())
end
# rubocop:enable Style/MethodCallWithoutArgsParentheses
end

::ActiveRecord::Associations::BelongsToAssociation.class_eval do
def writer_with_bullet(record)
Bullet::Detector::Association.add_object_associations(owner, reflection.name) if Bullet.start?
writer_without_bullet(record)
end
alias_method_chain :writer, :bullet
end
end
end
end
8 changes: 0 additions & 8 deletions lib/bullet/active_record41.rb
Expand Up @@ -179,14 +179,6 @@ def count_records
origin_count_records
end
end

::ActiveRecord::Associations::BelongsToAssociation.class_eval do
def writer_with_bullet(record)
Bullet::Detector::Association.add_object_associations(owner, reflection.name) if Bullet.start?
writer_without_bullet(record)
end
alias_method_chain :writer, :bullet
end
end
end
end
8 changes: 0 additions & 8 deletions lib/bullet/active_record42.rb
Expand Up @@ -240,14 +240,6 @@ def count_records
origin_count_records
end
end

::ActiveRecord::Associations::BelongsToAssociation.class_eval do
def writer_with_bullet(record)
Bullet::Detector::Association.add_object_associations(owner, reflection.name) if Bullet.start?
writer_without_bullet(record)
end
alias_method_chain :writer, :bullet
end
end
end
end
7 changes: 0 additions & 7 deletions lib/bullet/active_record5.rb
Expand Up @@ -240,13 +240,6 @@ def count_records
super
end
end)

::ActiveRecord::Associations::BelongsToAssociation.prepend(Module.new do
def writer(record)
Bullet::Detector::Association.add_object_associations(owner, reflection.name) if Bullet.start?
super
end
end)
end
end
end
7 changes: 0 additions & 7 deletions lib/bullet/active_record52.rb
Expand Up @@ -220,13 +220,6 @@ def count_records
super
end
end)

::ActiveRecord::Associations::BelongsToAssociation.prepend(Module.new do
def writer(record)
Bullet::Detector::Association.add_object_associations(owner, reflection.name) if Bullet.start?
super
end
end)
end
end
end
15 changes: 2 additions & 13 deletions spec/integration/active_record/association_spec.rb
Expand Up @@ -331,7 +331,7 @@
expect(Bullet::Detector::Association).to be_completely_preloading_associations
end

it 'should dtect preload with comment => post' do
it 'should detect preload with comment => post' do
Comment.includes(:post).each do |comment|
comment.post.name
end
Expand Down Expand Up @@ -362,22 +362,11 @@

new_post.trigger_after_save = true
new_post.save!
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations

expect(Bullet::Detector::Association).to be_completely_preloading_associations
end

it 'should not detect "manual" preload' do
comment = Comment.all.to_a.first
post = Post.find(comment.post_id)
# "manually" preload with out-of-band data
comment.post = post
# loading it should not trigger anything
comment.post

expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
expect(Bullet::Detector::Association).to be_completely_preloading_associations
end
end

context 'comment => post => category' do
Expand Down

0 comments on commit 58f8f4f

Please sign in to comment.