bullet 4.0.0 → 4.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rspec +1 -1
- data/.travis.yml +17 -6
- data/CHANGELOG.md +86 -0
- data/Gemfile +13 -12
- data/Gemfile.mongoid +14 -0
- data/Gemfile.mongoid-2.4 +19 -0
- data/Gemfile.mongoid-2.5 +19 -0
- data/Gemfile.mongoid-2.6 +19 -0
- data/Gemfile.mongoid-2.7 +19 -0
- data/Gemfile.mongoid-2.8 +19 -0
- data/Gemfile.mongoid-3.0 +19 -0
- data/Gemfile.mongoid-3.1 +19 -0
- data/Gemfile.mongoid-4.0 +19 -0
- data/Gemfile.rails-3.0 +19 -0
- data/Gemfile.rails-3.1 +19 -0
- data/Gemfile.rails-3.2 +19 -0
- data/Gemfile.rails-4.0 +19 -0
- data/Gemfile.rails-4.1 +19 -0
- data/{Hacking.textile → Hacking.md} +10 -5
- data/README.md +432 -0
- data/Rakefile +13 -6
- data/bullet.gemspec +6 -3
- data/lib/bullet/active_record3.rb +49 -11
- data/lib/bullet/active_record3x.rb +134 -0
- data/lib/bullet/{active_record31.rb → active_record4.rb} +45 -15
- data/lib/bullet/active_record41.rb +128 -0
- data/lib/bullet/dependency.rb +81 -0
- data/lib/bullet/detector/association.rb +24 -68
- data/lib/bullet/detector/base.rb +0 -6
- data/lib/bullet/detector/counter_cache.rb +59 -0
- data/lib/bullet/detector/n_plus_one_query.rb +56 -15
- data/lib/bullet/detector/unused_eager_loading.rb +84 -0
- data/lib/bullet/detector.rb +2 -2
- data/lib/bullet/ext/object.rb +10 -2
- data/lib/bullet/{mongoid.rb → mongoid2x.rb} +18 -18
- data/lib/bullet/mongoid3x.rb +56 -0
- data/lib/bullet/mongoid4x.rb +56 -0
- data/lib/bullet/notification/base.rb +22 -4
- data/lib/bullet/notification/n_plus_one_query.rb +1 -1
- data/lib/bullet/notification.rb +2 -0
- data/lib/bullet/rack.rb +51 -17
- data/lib/bullet/registry/base.rb +1 -1
- data/lib/bullet/registry/object.rb +4 -4
- data/lib/bullet/version.rb +1 -2
- data/lib/bullet.rb +119 -39
- data/perf/benchmark.rb +1 -4
- data/spec/bullet/detector/association_spec.rb +2 -70
- data/spec/bullet/detector/base_spec.rb +0 -6
- data/spec/bullet/detector/counter_cache_spec.rb +56 -0
- data/spec/bullet/detector/n_plus_one_query_spec.rb +78 -34
- data/spec/bullet/detector/unused_eager_loading_spec.rb +88 -0
- data/spec/bullet/ext/object_spec.rb +18 -7
- data/spec/bullet/ext/string_spec.rb +2 -2
- data/spec/bullet/notification/base_spec.rb +68 -15
- data/spec/bullet/notification/counter_cache_spec.rb +2 -2
- data/spec/bullet/notification/n_plus_one_query_spec.rb +4 -3
- data/spec/bullet/notification/unused_eager_loading_spec.rb +2 -2
- data/spec/bullet/notification_collector_spec.rb +4 -4
- data/spec/bullet/rack_spec.rb +40 -39
- data/spec/bullet/registry/association_spec.rb +3 -3
- data/spec/bullet/registry/base_spec.rb +6 -6
- data/spec/bullet/registry/object_spec.rb +4 -5
- data/spec/bullet_spec.rb +41 -0
- data/spec/integration/active_record3/association_spec.rb +662 -0
- data/spec/integration/active_record4/association_spec.rb +660 -0
- data/spec/integration/counter_cache_spec.rb +63 -0
- data/spec/integration/mongoid/association_spec.rb +190 -208
- data/spec/models/category.rb +1 -1
- data/spec/models/client.rb +1 -1
- data/spec/models/comment.rb +2 -2
- data/spec/models/document.rb +2 -2
- data/spec/models/firm.rb +1 -1
- data/spec/models/mongoid/address.rb +2 -0
- data/spec/models/mongoid/category.rb +2 -0
- data/spec/models/mongoid/comment.rb +2 -0
- data/spec/models/mongoid/company.rb +2 -0
- data/spec/models/mongoid/entry.rb +2 -0
- data/spec/models/mongoid/post.rb +4 -0
- data/spec/models/mongoid/user.rb +5 -0
- data/spec/models/newspaper.rb +1 -1
- data/spec/models/pet.rb +1 -1
- data/spec/models/post.rb +6 -13
- data/spec/spec_helper.rb +60 -25
- data/spec/support/bullet_ext.rb +1 -1
- data/spec/support/mongo_seed.rb +26 -2
- data/spec/support/sqlite_seed.rb +0 -6
- data/test.sh +15 -0
- metadata +77 -54
- data/.rvmrc +0 -2
- data/.rvmrc.example +0 -2
- data/Gemfile.lock +0 -132
- data/Gemfile.rails-2.3.14 +0 -16
- data/Gemfile.rails-2.3.14.lock +0 -65
- data/Gemfile.rails-3.0.12 +0 -17
- data/Gemfile.rails-3.0.12.lock +0 -116
- data/Gemfile.rails-3.1.4 +0 -18
- data/Gemfile.rails-3.1.4.lock +0 -134
- data/README.textile +0 -395
- data/README_for_rails2.textile +0 -400
- data/lib/bullet/action_controller2.rb +0 -49
- data/lib/bullet/active_record2.rb +0 -121
- data/lib/bullet/detector/counter.rb +0 -48
- data/lib/bullet/detector/unused_eager_association.rb +0 -42
- data/spec/bullet/detector/counter_spec.rb +0 -64
- data/spec/bullet/detector/unused_eager_association_spec.rb +0 -62
- data/spec/integration/association_spec.rb +0 -593
- data/spec/integration/counter_spec.rb +0 -39
- data/spec/integration/rails2/association_spec.rb +0 -593
- data/spec/integration/rails2/counter_spec.rb +0 -39
- data/test.result +0 -2293
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
if !mongoid? && active_record?
|
|
4
|
+
describe Bullet::Detector::CounterCache do
|
|
5
|
+
before(:each) do
|
|
6
|
+
Bullet.start_request
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
after(:each) do
|
|
10
|
+
Bullet.end_request
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "should need counter cache with all cities" do
|
|
14
|
+
Country.all.each do |country|
|
|
15
|
+
country.cities.size
|
|
16
|
+
end
|
|
17
|
+
expect(Bullet.collected_counter_cache_notifications).not_to be_empty
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should not need counter cache if already define counter_cache" do
|
|
21
|
+
Person.all.each do |person|
|
|
22
|
+
person.pets.size
|
|
23
|
+
end
|
|
24
|
+
expect(Bullet.collected_counter_cache_notifications).to be_empty
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "should not need counter cache with only one object" do
|
|
28
|
+
Country.first.cities.size
|
|
29
|
+
expect(Bullet.collected_counter_cache_notifications).to be_empty
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "should not need counter cache with part of cities" do
|
|
33
|
+
Country.all.each do |country|
|
|
34
|
+
country.cities.where(:name => 'first').size
|
|
35
|
+
end
|
|
36
|
+
expect(Bullet.collected_counter_cache_notifications).to be_empty
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
context "disable" do
|
|
40
|
+
before { Bullet.counter_cache_enable = false }
|
|
41
|
+
after { Bullet.counter_cache_enable = true }
|
|
42
|
+
|
|
43
|
+
it "should not detect counter cache" do
|
|
44
|
+
Country.all.each do |country|
|
|
45
|
+
country.cities.size
|
|
46
|
+
end
|
|
47
|
+
expect(Bullet.collected_counter_cache_notifications).to be_empty
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
context "whitelist" do
|
|
52
|
+
before { Bullet.add_whitelist :type => :counter_cache, :class_name => "Country", :association => :cities }
|
|
53
|
+
after { Bullet.reset_whitelist }
|
|
54
|
+
|
|
55
|
+
it "should not detect counter cache" do
|
|
56
|
+
Country.all.each do |country|
|
|
57
|
+
country.cities.size
|
|
58
|
+
end
|
|
59
|
+
expect(Bullet.collected_counter_cache_notifications).to be_empty
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -1,276 +1,258 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
if mongoid?
|
|
4
|
+
describe Bullet::Detector::Association do
|
|
5
|
+
context 'embeds_many' do
|
|
6
|
+
context "posts => users" do
|
|
7
|
+
it "should detect nothing" do
|
|
8
|
+
Mongoid::Post.all.each do |post|
|
|
9
|
+
post.users.map(&:name)
|
|
10
|
+
end
|
|
11
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
12
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
13
|
+
|
|
14
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
15
|
+
end
|
|
16
|
+
end
|
|
12
17
|
end
|
|
13
18
|
|
|
14
|
-
context
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
context 'has_many' do
|
|
20
|
+
context "posts => comments" do
|
|
21
|
+
it "should detect non preload posts => comments" do
|
|
22
|
+
Mongoid::Post.all.each do |post|
|
|
23
|
+
post.comments.map(&:name)
|
|
24
|
+
end
|
|
25
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
26
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
27
|
+
|
|
28
|
+
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Mongoid::Post, :comments)
|
|
18
29
|
end
|
|
19
|
-
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
20
|
-
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
21
30
|
|
|
22
|
-
|
|
23
|
-
|
|
31
|
+
it "should detect preload post => comments" do
|
|
32
|
+
Mongoid::Post.includes(:comments).each do |post|
|
|
33
|
+
post.comments.map(&:name)
|
|
34
|
+
end
|
|
35
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
36
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
24
37
|
|
|
25
|
-
|
|
26
|
-
Mongoid::Post.includes(:comments).each do |post|
|
|
27
|
-
post.comments.map(&:name)
|
|
38
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
28
39
|
end
|
|
29
|
-
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
30
|
-
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
31
|
-
|
|
32
|
-
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
33
|
-
end
|
|
34
40
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
it "should detect unused preload post => comments" do
|
|
42
|
+
Mongoid::Post.includes(:comments).map(&:name)
|
|
43
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
44
|
+
expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Post, :comments)
|
|
39
45
|
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
47
|
+
end
|
|
42
48
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
it "should not detect unused preload post => comments" do
|
|
50
|
+
Mongoid::Post.all.map(&:name)
|
|
51
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
52
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
47
53
|
|
|
48
|
-
|
|
54
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
55
|
+
end
|
|
49
56
|
end
|
|
50
|
-
end
|
|
51
57
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
context "category => posts, category => entries" do
|
|
59
|
+
it "should detect non preload with category => [posts, entries]" do
|
|
60
|
+
Mongoid::Category.all.each do |category|
|
|
61
|
+
category.posts.map(&:name)
|
|
62
|
+
category.entries.map(&:name)
|
|
63
|
+
end
|
|
64
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
65
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
66
|
+
|
|
67
|
+
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Mongoid::Category, :posts)
|
|
68
|
+
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Mongoid::Category, :entries)
|
|
57
69
|
end
|
|
58
|
-
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
59
|
-
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
60
70
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
71
|
+
it "should detect preload with category => posts, but not with category => entries" do
|
|
72
|
+
Mongoid::Category.includes(:posts).each do |category|
|
|
73
|
+
category.posts.map(&:name)
|
|
74
|
+
category.entries.map(&:name)
|
|
75
|
+
end
|
|
76
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
77
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
64
78
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
category.posts.collect(&:name)
|
|
68
|
-
category.entries.collect(&:name)
|
|
79
|
+
expect(Bullet::Detector::Association).not_to be_detecting_unpreloaded_association_for(Mongoid::Category, :posts)
|
|
80
|
+
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Mongoid::Category, :entries)
|
|
69
81
|
end
|
|
70
|
-
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
71
|
-
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
72
82
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
83
|
+
it "should detect preload with category => [posts, entries]" do
|
|
84
|
+
Mongoid::Category.includes(:posts, :entries).each do |category|
|
|
85
|
+
category.posts.map(&:name)
|
|
86
|
+
category.entries.map(&:name)
|
|
87
|
+
end
|
|
88
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
89
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
76
90
|
|
|
77
|
-
|
|
78
|
-
Mongoid::Category.includes([:posts, :entries]).each do |category|
|
|
79
|
-
category.posts.map(&:name)
|
|
80
|
-
category.entries.map(&:name)
|
|
91
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
81
92
|
end
|
|
82
|
-
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
83
|
-
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
84
93
|
|
|
85
|
-
|
|
86
|
-
|
|
94
|
+
it "should detect unused preload with category => [posts, entries]" do
|
|
95
|
+
Mongoid::Category.includes(:posts, :entries).map(&:name)
|
|
96
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
97
|
+
expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Category, :posts)
|
|
98
|
+
expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Category, :entries)
|
|
87
99
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
91
|
-
Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Category, :posts)
|
|
92
|
-
Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Category, :entries)
|
|
100
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
101
|
+
end
|
|
93
102
|
|
|
94
|
-
|
|
95
|
-
|
|
103
|
+
it "should detect unused preload with category => entries, but not with category => posts" do
|
|
104
|
+
Mongoid::Category.includes(:posts, :entries).each do |category|
|
|
105
|
+
category.posts.map(&:name)
|
|
106
|
+
end
|
|
107
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
108
|
+
expect(Bullet::Detector::Association).not_to be_unused_preload_associations_for(Mongoid::Category, :posts)
|
|
109
|
+
expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Category, :entries)
|
|
96
110
|
|
|
97
|
-
|
|
98
|
-
Mongoid::Category.includes([:posts, :entries]).each do |category|
|
|
99
|
-
category.posts.map(&:name)
|
|
111
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
100
112
|
end
|
|
101
|
-
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
102
|
-
Bullet::Detector::Association.should_not be_unused_preload_associations_for(Mongoid::Category, :posts)
|
|
103
|
-
Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Category, :entries)
|
|
104
|
-
|
|
105
|
-
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
106
113
|
end
|
|
107
|
-
end
|
|
108
114
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
context "post => comment" do
|
|
116
|
+
it "should detect unused preload with post => comments" do
|
|
117
|
+
Mongoid::Post.includes(:comments).each do |post|
|
|
118
|
+
post.comments.first.name
|
|
119
|
+
end
|
|
120
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
121
|
+
expect(Bullet::Detector::Association).not_to be_unused_preload_associations_for(Mongoid::Post, :comments)
|
|
116
122
|
|
|
117
|
-
|
|
118
|
-
|
|
123
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
124
|
+
end
|
|
119
125
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
126
|
+
it "should detect preload with post => commnets" do
|
|
127
|
+
Mongoid::Post.first.comments.map(&:name)
|
|
128
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
129
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
124
130
|
|
|
125
|
-
|
|
131
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
132
|
+
end
|
|
126
133
|
end
|
|
127
|
-
end
|
|
128
134
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
135
|
+
context "scope preload_comments" do
|
|
136
|
+
it "should detect preload post => comments with scope" do
|
|
137
|
+
Mongoid::Post.preload_comments.each do |post|
|
|
138
|
+
post.comments.map(&:name)
|
|
139
|
+
end
|
|
140
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
141
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
136
142
|
|
|
137
|
-
|
|
138
|
-
|
|
143
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
144
|
+
end
|
|
139
145
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
146
|
+
it "should detect unused preload with scope" do
|
|
147
|
+
Mongoid::Post.preload_comments.map(&:name)
|
|
148
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
149
|
+
expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Post, :comments)
|
|
144
150
|
|
|
145
|
-
|
|
151
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
152
|
+
end
|
|
146
153
|
end
|
|
147
154
|
end
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
describe Bullet::Detector::Association, 'belongs_to' do
|
|
151
|
-
before(:each) do
|
|
152
|
-
Bullet.clear
|
|
153
|
-
Bullet.start_request
|
|
154
|
-
end
|
|
155
155
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
context 'belongs_to' do
|
|
157
|
+
context "comment => post" do
|
|
158
|
+
it "should detect non preload with comment => post" do
|
|
159
|
+
Mongoid::Comment.all.each do |comment|
|
|
160
|
+
comment.post.name
|
|
161
|
+
end
|
|
162
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
163
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
159
164
|
|
|
160
|
-
|
|
161
|
-
it "should detect non preload with comment => post" do
|
|
162
|
-
Mongoid::Comment.all.each do |comment|
|
|
163
|
-
comment.post.name
|
|
165
|
+
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Mongoid::Comment, :post)
|
|
164
166
|
end
|
|
165
|
-
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
166
|
-
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
167
167
|
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
it "should detect preload with one comment => post" do
|
|
169
|
+
Mongoid::Comment.first.post.name
|
|
170
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
171
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
170
172
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
174
|
-
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
173
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
174
|
+
end
|
|
175
175
|
|
|
176
|
-
|
|
177
|
-
|
|
176
|
+
it "should detect preload with comment => post" do
|
|
177
|
+
Mongoid::Comment.includes(:post).each do |comment|
|
|
178
|
+
comment.post.name
|
|
179
|
+
end
|
|
180
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
181
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
178
182
|
|
|
179
|
-
|
|
180
|
-
Mongoid::Comment.includes(:post).each do |comment|
|
|
181
|
-
comment.post.name
|
|
183
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
182
184
|
end
|
|
183
|
-
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
184
|
-
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
185
|
-
|
|
186
|
-
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
187
|
-
end
|
|
188
185
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
186
|
+
it "should not detect preload with comment => post" do
|
|
187
|
+
Mongoid::Comment.all.map(&:name)
|
|
188
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
189
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
193
190
|
|
|
194
|
-
|
|
195
|
-
|
|
191
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
192
|
+
end
|
|
196
193
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
194
|
+
it "should detect unused preload with comments => post" do
|
|
195
|
+
Mongoid::Comment.includes(:post).map(&:name)
|
|
196
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
197
|
+
expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Comment, :post)
|
|
201
198
|
|
|
202
|
-
|
|
199
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
200
|
+
end
|
|
203
201
|
end
|
|
204
202
|
end
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
describe Bullet::Detector::Association, "has_one" do
|
|
208
|
-
before(:each) do
|
|
209
|
-
Bullet.clear
|
|
210
|
-
Bullet.start_request
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
after(:each) do
|
|
214
|
-
Bullet.end_request
|
|
215
|
-
end
|
|
216
203
|
|
|
217
|
-
context "
|
|
218
|
-
|
|
219
|
-
Mongoid::
|
|
220
|
-
|
|
204
|
+
context "has_one" do
|
|
205
|
+
context "company => address" do
|
|
206
|
+
if Mongoid::VERSION !~ /\A3.0/
|
|
207
|
+
it "should detect non preload association" do
|
|
208
|
+
Mongoid::Company.all.each do |company|
|
|
209
|
+
company.address.name
|
|
210
|
+
end
|
|
211
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
212
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
213
|
+
|
|
214
|
+
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Mongoid::Company, :address)
|
|
215
|
+
end
|
|
221
216
|
end
|
|
222
|
-
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
223
|
-
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
224
217
|
|
|
225
|
-
|
|
226
|
-
|
|
218
|
+
it "should detect preload association" do
|
|
219
|
+
Mongoid::Company.includes(:address).each do |company|
|
|
220
|
+
company.address.name
|
|
221
|
+
end
|
|
222
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
223
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
227
224
|
|
|
228
|
-
|
|
229
|
-
Mongoid::Company.includes(:address).each do |company|
|
|
230
|
-
company.address.name
|
|
225
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
231
226
|
end
|
|
232
|
-
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
233
|
-
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
234
|
-
|
|
235
|
-
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
236
|
-
end
|
|
237
227
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
228
|
+
it "should not detect preload association" do
|
|
229
|
+
Mongoid::Company.all.map(&:name)
|
|
230
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
231
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
242
232
|
|
|
243
|
-
|
|
244
|
-
|
|
233
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
234
|
+
end
|
|
245
235
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
236
|
+
it "should detect unused preload association" do
|
|
237
|
+
criteria = Mongoid::Company.includes(:address)
|
|
238
|
+
criteria.map(&:name)
|
|
239
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
240
|
+
expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Company, :address)
|
|
250
241
|
|
|
251
|
-
|
|
242
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
243
|
+
end
|
|
252
244
|
end
|
|
253
245
|
end
|
|
254
|
-
end
|
|
255
|
-
|
|
256
|
-
describe Bullet::Detector::Association, "call one association that in possible objects" do
|
|
257
|
-
before(:each) do
|
|
258
|
-
Bullet.clear
|
|
259
|
-
Bullet.start_request
|
|
260
|
-
end
|
|
261
246
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
Mongoid::Post.first.comments.map(&:name)
|
|
269
|
-
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
270
|
-
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
247
|
+
context "call one association that in possible objects" do
|
|
248
|
+
it "should not detect preload association" do
|
|
249
|
+
Mongoid::Post.all
|
|
250
|
+
Mongoid::Post.first.comments.map(&:name)
|
|
251
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
252
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
271
253
|
|
|
272
|
-
|
|
254
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
255
|
+
end
|
|
273
256
|
end
|
|
274
257
|
end
|
|
275
|
-
rescue LoadError
|
|
276
258
|
end
|
data/spec/models/category.rb
CHANGED
data/spec/models/client.rb
CHANGED
data/spec/models/comment.rb
CHANGED
data/spec/models/document.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
class Document < ActiveRecord::Base
|
|
2
|
-
has_many :children, :
|
|
3
|
-
belongs_to :parent, :
|
|
2
|
+
has_many :children, class_name: "Document", foreign_key: 'parent_id'
|
|
3
|
+
belongs_to :parent, class_name: "Document", foreign_key: 'parent_id'
|
|
4
4
|
belongs_to :author
|
|
5
5
|
end
|
data/spec/models/firm.rb
CHANGED
data/spec/models/mongoid/post.rb
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
class Mongoid::Post
|
|
2
2
|
include Mongoid::Document
|
|
3
3
|
|
|
4
|
+
field :name
|
|
5
|
+
|
|
4
6
|
has_many :comments, :class_name => "Mongoid::Comment"
|
|
5
7
|
belongs_to :category, :class_name => "Mongoid::Category"
|
|
6
8
|
|
|
9
|
+
embeds_many :users, :class_name => "Mongoid::User"
|
|
10
|
+
|
|
7
11
|
scope :preload_comments, lambda { includes(:comments) }
|
|
8
12
|
end
|
data/spec/models/newspaper.rb
CHANGED
data/spec/models/pet.rb
CHANGED