bullet 4.14.2 → 4.14.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/lib/bullet/active_record4.rb +4 -2
- data/lib/bullet/active_record41.rb +2 -2
- data/lib/bullet/active_record42.rb +2 -2
- data/lib/bullet/version.rb +1 -1
- data/spec/integration/active_record4/association_spec.rb +15 -1
- data/spec/models/category.rb +4 -0
- data/spec/models/comment.rb +2 -0
- data/spec/models/post.rb +7 -0
- data/spec/spec_helper.rb +2 -2
- data/spec/support/sqlite_seed.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbe02316f8b3e0b61718c940420f189423c3f5f0
|
4
|
+
data.tar.gz: 93db165a6618fb9c470081013e4b2f5fe002c602
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c9ec0b4e3c23e6de5f59f74cb9378f5db7c32a448a42d4304b2399c3762308bab649dffc7f86bd04aaf175946391df9658994a1a190fb2a64fb8ec5bd21dbb3
|
7
|
+
data.tar.gz: 47451dec206f2d05aaa11466d8f6c063bbb9e3e9c03929d7dc8867b11e77be6871ee6a58f1f2b52435db3bb6854e913228dc9b310bf7dd78f5b968de5f042932
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -430,4 +430,4 @@ Meanwhile, there's a line appended to `log/bullet.log`
|
|
430
430
|
Post => [:comments]
|
431
431
|
```
|
432
432
|
|
433
|
-
Copyright (c) 2009 -
|
433
|
+
Copyright (c) 2009 - 2015 Richard Huang (flyerhzm@gmail.com), released under the MIT license
|
@@ -104,8 +104,10 @@ module Bullet
|
|
104
104
|
alias_method :origin_reader, :reader
|
105
105
|
def reader(force_reload = false)
|
106
106
|
result = origin_reader(force_reload)
|
107
|
-
|
108
|
-
|
107
|
+
unless @inversed
|
108
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
109
|
+
Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
|
110
|
+
end
|
109
111
|
result
|
110
112
|
end
|
111
113
|
end
|
@@ -106,8 +106,8 @@ module Bullet
|
|
106
106
|
alias_method :origin_reader, :reader
|
107
107
|
def reader(force_reload = false)
|
108
108
|
result = origin_reader(force_reload)
|
109
|
-
if @owner.class.name !~ /^HABTM_/
|
110
|
-
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
109
|
+
if @owner.class.name !~ /^HABTM_/ && !@inversed
|
110
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
111
111
|
Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
|
112
112
|
end
|
113
113
|
result
|
@@ -117,8 +117,8 @@ module Bullet
|
|
117
117
|
alias_method :origin_reader, :reader
|
118
118
|
def reader(force_reload = false)
|
119
119
|
result = origin_reader(force_reload)
|
120
|
-
if @owner.class.name !~ /^HABTM_/
|
121
|
-
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
120
|
+
if @owner.class.name !~ /^HABTM_/ && !@inversed
|
121
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
122
122
|
Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
|
123
123
|
end
|
124
124
|
if ::ActiveRecord::Reflection::HasOneReflection === @reflection && result
|
data/lib/bullet/version.rb
CHANGED
@@ -219,6 +219,20 @@ if !mongoid? && active_record4?
|
|
219
219
|
|
220
220
|
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
221
221
|
end
|
222
|
+
|
223
|
+
it "should not detect unused preload with category => posts" do
|
224
|
+
category = Category.first
|
225
|
+
category.draft_post.destroy!
|
226
|
+
post = category.draft_post
|
227
|
+
post.update_attributes!(link: true)
|
228
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
229
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
230
|
+
|
231
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
232
|
+
|
233
|
+
Support::SqliteSeed.setup_db
|
234
|
+
Support::SqliteSeed.seed_db
|
235
|
+
end
|
222
236
|
end
|
223
237
|
|
224
238
|
context "category => posts => writer" do
|
@@ -313,7 +327,7 @@ if !mongoid? && active_record4?
|
|
313
327
|
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
314
328
|
end
|
315
329
|
|
316
|
-
it "should detect unused preload with
|
330
|
+
it "should detect unused preload with comment => post" do
|
317
331
|
Comment.includes(:post).map(&:name)
|
318
332
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
319
333
|
expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Comment, :post)
|
data/spec/models/category.rb
CHANGED
data/spec/models/comment.rb
CHANGED
data/spec/models/post.rb
CHANGED
@@ -3,6 +3,13 @@ class Post < ActiveRecord::Base
|
|
3
3
|
belongs_to :writer
|
4
4
|
has_many :comments, inverse_of: :post
|
5
5
|
|
6
|
+
validates :category, presence: true
|
7
|
+
|
6
8
|
scope :preload_comments, -> { includes(:comments) }
|
7
9
|
scope :in_category_name, ->(name) { where(['categories.name = ?', name]).includes(:category) }
|
10
|
+
scope :draft, -> { where(active: false) }
|
11
|
+
|
12
|
+
def link=(*)
|
13
|
+
comments.new
|
14
|
+
end
|
8
15
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/sqlite_seed.rb
CHANGED
@@ -14,7 +14,7 @@ module Support
|
|
14
14
|
category2 = Category.create(:name => 'second')
|
15
15
|
|
16
16
|
post1 = category1.posts.create(:name => 'first', :writer => writer1)
|
17
|
-
post1a = category1.posts.create(:name => 'like first', :writer => writer2)
|
17
|
+
post1a = category1.posts.create(:name => 'like first', :writer => writer2, active: false)
|
18
18
|
post2 = category2.posts.create(:name => 'second', :writer => writer2)
|
19
19
|
|
20
20
|
comment1 = post1.comments.create(:name => 'first', :author => writer1)
|
@@ -194,6 +194,7 @@ module Support
|
|
194
194
|
t.column :name, :string
|
195
195
|
t.column :category_id, :integer
|
196
196
|
t.column :writer_id, :integer
|
197
|
+
t.column :active, :boolean, :default => true
|
197
198
|
end
|
198
199
|
|
199
200
|
create_table :relationships do |t|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bullet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.14.
|
4
|
+
version: 4.14.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01
|
11
|
+
date: 2015-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|