Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing check_unused_preload_associations call to spec #444

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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