bullet 4.0.0 → 4.1.4
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.
- data/.gitignore +1 -0
- data/.travis.yml +4 -2
- data/Gemfile +2 -3
- data/Gemfile.lock +36 -39
- data/Gemfile.rails-2.3.14.lock +1 -1
- data/{Gemfile.rails-3.0.12 → Gemfile.rails-3.0.13} +1 -1
- data/{Gemfile.rails-3.0.12.lock → Gemfile.rails-3.0.13.lock} +27 -27
- data/{Gemfile.rails-3.1.4 → Gemfile.rails-3.1.5} +2 -2
- data/{Gemfile.rails-3.1.4.lock → Gemfile.rails-3.1.5.lock} +34 -34
- data/README.textile +3 -1
- data/README_for_rails2.textile +4 -0
- data/lib/bullet/action_controller2.rb +5 -4
- data/lib/bullet/dependency.rb +83 -0
- data/lib/bullet/{mongoid.rb → mongoid24.rb} +13 -15
- data/lib/bullet/mongoid3.rb +53 -0
- data/lib/bullet/rack.rb +8 -6
- data/lib/bullet/version.rb +1 -2
- data/lib/bullet.rb +12 -17
- data/spec/bullet/ext/object_spec.rb +1 -4
- data/spec/integration/association_spec.rb +1 -1
- data/spec/integration/counter_spec.rb +1 -1
- data/spec/integration/mongoid/association_spec.rb +174 -199
- data/spec/integration/rails2/association_spec.rb +1 -1
- data/spec/integration/rails2/counter_spec.rb +2 -2
- data/spec/models/post.rb +3 -1
- data/spec/spec_helper.rb +26 -22
- data/spec/support/mongo_seed.rb +10 -2
- data/test.sh +4 -0
- metadata +14 -12
- data/test.result +0 -2293
data/lib/bullet/rack.rb
CHANGED
|
@@ -9,7 +9,7 @@ module Bullet
|
|
|
9
9
|
|
|
10
10
|
Bullet.start_request
|
|
11
11
|
status, headers, response = @app.call(env)
|
|
12
|
-
return [status, headers, response] if empty?(response)
|
|
12
|
+
return [status, headers, response] if file?(headers) || empty?(response)
|
|
13
13
|
|
|
14
14
|
response_body = nil
|
|
15
15
|
if Bullet.notification?
|
|
@@ -28,14 +28,16 @@ module Bullet
|
|
|
28
28
|
def empty?(response)
|
|
29
29
|
# response may be ["Not Found"], ["Move Permanently"], etc.
|
|
30
30
|
(response.is_a?(Array) && response.size <= 1) ||
|
|
31
|
-
|
|
31
|
+
!response.respond_to?(:body) || response.body.empty?
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# if send file?
|
|
35
|
+
def file?(headers)
|
|
36
|
+
headers["Content-Transfer-Encoding"] == "binary"
|
|
32
37
|
end
|
|
33
38
|
|
|
34
39
|
def html_request?(headers, response)
|
|
35
|
-
headers['Content-Type'] &&
|
|
36
|
-
headers['Content-Type'].include?('text/html') &&
|
|
37
|
-
response.body.include?("<html>") &&
|
|
38
|
-
response.body.include?("</html>")
|
|
40
|
+
headers['Content-Type'] && headers['Content-Type'].include?('text/html') && response.body.include?("<html>")
|
|
39
41
|
end
|
|
40
42
|
|
|
41
43
|
def no_browser_cache(headers)
|
data/lib/bullet/version.rb
CHANGED
data/lib/bullet.rb
CHANGED
|
@@ -2,17 +2,18 @@ require 'set'
|
|
|
2
2
|
require 'uniform_notifier'
|
|
3
3
|
require 'bullet/ext/object'
|
|
4
4
|
require 'bullet/ext/string'
|
|
5
|
+
require 'bullet/dependency'
|
|
5
6
|
|
|
6
7
|
module Bullet
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
autoload :ActiveRecord,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
extend Dependency
|
|
9
|
+
|
|
10
|
+
if active_record?
|
|
11
|
+
autoload :ActiveRecord, "bullet/#{active_record_version}"
|
|
12
|
+
autoload :ActionController, 'bullet/action_controller2' if active_record2?
|
|
13
|
+
end
|
|
14
|
+
if mongoid?
|
|
15
|
+
autoload :Mongoid, "bullet/#{mongoid_version}"
|
|
14
16
|
end
|
|
15
|
-
autoload :Mongoid, 'bullet/mongoid'
|
|
16
17
|
autoload :Rack, 'bullet/rack'
|
|
17
18
|
autoload :BulletLogger, 'bullet/logger'
|
|
18
19
|
autoload :Notification, 'bullet/notification'
|
|
@@ -41,18 +42,12 @@ module Bullet
|
|
|
41
42
|
def enable=(enable)
|
|
42
43
|
@enable = enable
|
|
43
44
|
if enable?
|
|
44
|
-
|
|
45
|
-
require 'mongoid'
|
|
45
|
+
if mongoid?
|
|
46
46
|
Bullet::Mongoid.enable
|
|
47
|
-
rescue LoadError
|
|
48
47
|
end
|
|
49
|
-
|
|
50
|
-
require 'active_record'
|
|
48
|
+
if active_record?
|
|
51
49
|
Bullet::ActiveRecord.enable
|
|
52
|
-
|
|
53
|
-
Bullet::ActionController.enable
|
|
54
|
-
end
|
|
55
|
-
rescue LoadError
|
|
50
|
+
Bullet::ActionController.enable if active_record2?
|
|
56
51
|
end
|
|
57
52
|
end
|
|
58
53
|
end
|
|
@@ -7,14 +7,11 @@ describe Object do
|
|
|
7
7
|
post.bullet_ar_key.should == "Post:#{post.id}"
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
require 'mongoid'
|
|
12
|
-
|
|
10
|
+
if mongoid?
|
|
13
11
|
it "should return class with namesapce and id composition" do
|
|
14
12
|
post = Mongoid::Post.first
|
|
15
13
|
post.bullet_ar_key.should == "Mongoid::Post:#{post.id}"
|
|
16
14
|
end
|
|
17
|
-
rescue LoadError
|
|
18
15
|
end
|
|
19
16
|
end
|
|
20
17
|
end
|
|
@@ -1,276 +1,251 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
describe Bullet::Detector::Association, 'has_many' do
|
|
3
|
+
if mongoid?
|
|
4
|
+
describe Bullet::Detector::Association do
|
|
6
5
|
before(:each) do
|
|
7
6
|
Bullet.clear
|
|
8
7
|
Bullet.start_request
|
|
9
8
|
end
|
|
10
9
|
after(:each) do
|
|
11
10
|
Bullet.end_request
|
|
11
|
+
Mongoid::IdentityMap.clear
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
context
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
context 'has_many' do
|
|
15
|
+
context "posts => comments" do
|
|
16
|
+
it "should detect non preload posts => comments" do
|
|
17
|
+
Mongoid::Post.all.each do |post|
|
|
18
|
+
post.comments.map(&:name)
|
|
19
|
+
end
|
|
20
|
+
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
21
|
+
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
22
|
+
|
|
23
|
+
Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Post, :comments)
|
|
18
24
|
end
|
|
19
|
-
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
20
|
-
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
21
25
|
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
it "should detect preload post => comments" do
|
|
27
|
+
Mongoid::Post.includes(:comments).each do |post|
|
|
28
|
+
post.comments.map(&:name)
|
|
29
|
+
end
|
|
30
|
+
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
31
|
+
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
24
32
|
|
|
25
|
-
|
|
26
|
-
Mongoid::Post.includes(:comments).each do |post|
|
|
27
|
-
post.comments.map(&:name)
|
|
33
|
+
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
28
34
|
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
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
it "should detect unused preload post => comments" do
|
|
37
|
+
Mongoid::Post.includes(:comments).map(&:name)
|
|
38
|
+
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
39
|
+
Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Post, :comments)
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
42
|
+
end
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
it "should not detect unused preload post => comments" do
|
|
45
|
+
Mongoid::Post.all.map(&:name)
|
|
46
|
+
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
47
|
+
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
47
48
|
|
|
48
|
-
|
|
49
|
+
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
50
|
+
end
|
|
49
51
|
end
|
|
50
|
-
end
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
context "category => posts, category => entries" do
|
|
54
|
+
it "should detect non preload with category => [posts, entries]" do
|
|
55
|
+
Mongoid::Category.all.each do |category|
|
|
56
|
+
category.posts.map(&:name)
|
|
57
|
+
category.entries.map(&:name)
|
|
58
|
+
end
|
|
59
|
+
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
60
|
+
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
61
|
+
|
|
62
|
+
Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Category, :posts)
|
|
63
|
+
Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Category, :entries)
|
|
57
64
|
end
|
|
58
|
-
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
59
|
-
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
60
65
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
it "should detect preload with category => posts, but not with category => entries" do
|
|
67
|
+
Mongoid::Category.includes(:posts).each do |category|
|
|
68
|
+
category.posts.map(&:name)
|
|
69
|
+
category.entries.map(&:name)
|
|
70
|
+
end
|
|
71
|
+
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
72
|
+
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
64
73
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
category.posts.collect(&:name)
|
|
68
|
-
category.entries.collect(&:name)
|
|
74
|
+
Bullet::Detector::Association.should_not be_detecting_unpreloaded_association_for(Mongoid::Category, :posts)
|
|
75
|
+
Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Category, :entries)
|
|
69
76
|
end
|
|
70
|
-
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
71
|
-
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
72
77
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
it "should detect preload with category => [posts, entries]" do
|
|
79
|
+
Mongoid::Category.includes(:posts, :entries).each do |category|
|
|
80
|
+
category.posts.map(&:name)
|
|
81
|
+
category.entries.map(&:name)
|
|
82
|
+
end
|
|
83
|
+
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
84
|
+
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
76
85
|
|
|
77
|
-
|
|
78
|
-
Mongoid::Category.includes([:posts, :entries]).each do |category|
|
|
79
|
-
category.posts.map(&:name)
|
|
80
|
-
category.entries.map(&:name)
|
|
86
|
+
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
81
87
|
end
|
|
82
|
-
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
83
|
-
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
84
88
|
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
it "should detect unused preload with category => [posts, entries]" do
|
|
90
|
+
Mongoid::Category.includes(:posts, :entries).map(&:name)
|
|
91
|
+
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
92
|
+
Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Category, :posts)
|
|
93
|
+
Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Category, :entries)
|
|
87
94
|
|
|
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)
|
|
95
|
+
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
96
|
+
end
|
|
93
97
|
|
|
94
|
-
|
|
95
|
-
|
|
98
|
+
it "should detect unused preload with category => entries, but not with category => posts" do
|
|
99
|
+
Mongoid::Category.includes(:posts, :entries).each do |category|
|
|
100
|
+
category.posts.map(&:name)
|
|
101
|
+
end
|
|
102
|
+
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
103
|
+
Bullet::Detector::Association.should_not be_unused_preload_associations_for(Mongoid::Category, :posts)
|
|
104
|
+
Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Category, :entries)
|
|
96
105
|
|
|
97
|
-
|
|
98
|
-
Mongoid::Category.includes([:posts, :entries]).each do |category|
|
|
99
|
-
category.posts.map(&:name)
|
|
106
|
+
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
100
107
|
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
108
|
end
|
|
107
|
-
end
|
|
108
109
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
110
|
+
context "post => comment" do
|
|
111
|
+
it "should detect unused preload with post => comments" do
|
|
112
|
+
Mongoid::Post.includes(:comments).each do |post|
|
|
113
|
+
post.comments.first.name
|
|
114
|
+
end
|
|
115
|
+
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
116
|
+
Bullet::Detector::Association.should_not be_unused_preload_associations_for(Mongoid::Post, :comments)
|
|
116
117
|
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
119
|
+
end
|
|
119
120
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
it "should detect preload with post => commnets" do
|
|
122
|
+
Mongoid::Post.first.comments.map(&:name)
|
|
123
|
+
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
124
|
+
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
124
125
|
|
|
125
|
-
|
|
126
|
+
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
127
|
+
end
|
|
126
128
|
end
|
|
127
|
-
end
|
|
128
129
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
130
|
+
context "scope preload_comments" do
|
|
131
|
+
it "should detect preload post => comments with scope" do
|
|
132
|
+
Mongoid::Post.preload_comments.each do |post|
|
|
133
|
+
post.comments.map(&:name)
|
|
134
|
+
end
|
|
135
|
+
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
136
|
+
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
136
137
|
|
|
137
|
-
|
|
138
|
-
|
|
138
|
+
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
139
|
+
end
|
|
139
140
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
141
|
+
it "should detect unused preload with scope" do
|
|
142
|
+
Mongoid::Post.preload_comments.map(&:name)
|
|
143
|
+
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
144
|
+
Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Post, :comments)
|
|
144
145
|
|
|
145
|
-
|
|
146
|
+
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
147
|
+
end
|
|
146
148
|
end
|
|
147
149
|
end
|
|
148
|
-
end
|
|
149
150
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
context 'belongs_to' do
|
|
152
|
+
context "comment => post" do
|
|
153
|
+
it "should detect non preload with comment => post" do
|
|
154
|
+
Mongoid::Comment.all.each do |comment|
|
|
155
|
+
comment.post.name
|
|
156
|
+
end
|
|
157
|
+
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
158
|
+
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
155
159
|
|
|
156
|
-
|
|
157
|
-
Bullet.end_request
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
context "comment => post" do
|
|
161
|
-
it "should detect non preload with comment => post" do
|
|
162
|
-
Mongoid::Comment.all.each do |comment|
|
|
163
|
-
comment.post.name
|
|
160
|
+
Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Comment, :post)
|
|
164
161
|
end
|
|
165
|
-
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
166
|
-
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
167
162
|
|
|
168
|
-
|
|
169
|
-
|
|
163
|
+
it "should detect preload with one comment => post" do
|
|
164
|
+
Mongoid::Comment.first.post.name
|
|
165
|
+
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
166
|
+
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
170
167
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
174
|
-
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
168
|
+
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
169
|
+
end
|
|
175
170
|
|
|
176
|
-
|
|
177
|
-
|
|
171
|
+
it "should detect preload with comment => post" do
|
|
172
|
+
Mongoid::Comment.includes(:post).each do |comment|
|
|
173
|
+
comment.post.name
|
|
174
|
+
end
|
|
175
|
+
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
176
|
+
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
178
177
|
|
|
179
|
-
|
|
180
|
-
Mongoid::Comment.includes(:post).each do |comment|
|
|
181
|
-
comment.post.name
|
|
178
|
+
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
182
179
|
end
|
|
183
|
-
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
184
|
-
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
185
180
|
|
|
186
|
-
|
|
187
|
-
|
|
181
|
+
it "should not detect preload with comment => post" do
|
|
182
|
+
Mongoid::Comment.all.map(&:name)
|
|
183
|
+
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
184
|
+
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
188
185
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
192
|
-
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
193
|
-
|
|
194
|
-
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
195
|
-
end
|
|
186
|
+
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
187
|
+
end
|
|
196
188
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
189
|
+
it "should detect unused preload with comments => post" do
|
|
190
|
+
Mongoid::Comment.includes(:post).map(&:name)
|
|
191
|
+
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
192
|
+
Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Comment, :post)
|
|
201
193
|
|
|
202
|
-
|
|
194
|
+
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
195
|
+
end
|
|
203
196
|
end
|
|
204
197
|
end
|
|
205
|
-
end
|
|
206
198
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
199
|
+
context "has_one" do
|
|
200
|
+
context "company => address" do
|
|
201
|
+
it "should detect non preload association" do
|
|
202
|
+
Mongoid::Company.all.each do |company|
|
|
203
|
+
company.address.name
|
|
204
|
+
end
|
|
205
|
+
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
206
|
+
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
212
207
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
end
|
|
208
|
+
Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Company, :address)
|
|
209
|
+
end
|
|
216
210
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
211
|
+
it "should detect preload association" do
|
|
212
|
+
Mongoid::Company.includes(:address).each do |company|
|
|
213
|
+
company.address.name
|
|
214
|
+
end
|
|
215
|
+
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
216
|
+
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
217
|
+
|
|
218
|
+
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
221
219
|
end
|
|
222
|
-
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
223
|
-
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
224
220
|
|
|
225
|
-
|
|
226
|
-
|
|
221
|
+
it "should not detect preload association" do
|
|
222
|
+
Mongoid::Company.all.map(&:name)
|
|
223
|
+
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
224
|
+
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
227
225
|
|
|
228
|
-
|
|
229
|
-
Mongoid::Company.includes(:address).each do |company|
|
|
230
|
-
company.address.name
|
|
226
|
+
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
231
227
|
end
|
|
232
|
-
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
233
|
-
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
234
228
|
|
|
235
|
-
|
|
229
|
+
it "should detect unused preload association" do
|
|
230
|
+
criteria = Mongoid::Company.includes(:address)
|
|
231
|
+
criteria.map(&:name)
|
|
232
|
+
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
233
|
+
Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Company, :address)
|
|
234
|
+
|
|
235
|
+
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
236
|
+
end
|
|
236
237
|
end
|
|
238
|
+
end
|
|
237
239
|
|
|
240
|
+
context "call one association that in possible objects" do
|
|
238
241
|
it "should not detect preload association" do
|
|
239
|
-
Mongoid::
|
|
242
|
+
Mongoid::Post.all
|
|
243
|
+
Mongoid::Post.first.comments.map(&:name)
|
|
240
244
|
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
241
245
|
Bullet::Detector::Association.should_not be_has_unused_preload_associations
|
|
242
246
|
|
|
243
247
|
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
244
248
|
end
|
|
245
|
-
|
|
246
|
-
it "should detect unused preload association" do
|
|
247
|
-
Mongoid::Company.includes(:address).collect(&:name)
|
|
248
|
-
Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
|
|
249
|
-
Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Company, :address)
|
|
250
|
-
|
|
251
|
-
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
252
|
-
end
|
|
253
|
-
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
|
-
|
|
262
|
-
after(:each) do
|
|
263
|
-
Bullet.end_request
|
|
264
|
-
end
|
|
265
|
-
|
|
266
|
-
it "should not detect preload association" do
|
|
267
|
-
Mongoid::Post.all
|
|
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
|
|
271
|
-
|
|
272
|
-
Bullet::Detector::Association.should be_completely_preloading_associations
|
|
273
249
|
end
|
|
274
250
|
end
|
|
275
|
-
rescue LoadError
|
|
276
251
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
if
|
|
3
|
+
if active_record2?
|
|
4
4
|
describe Bullet::Detector::Counter do
|
|
5
5
|
before(:each) do
|
|
6
6
|
Bullet.start_request
|
|
@@ -31,7 +31,7 @@ if Rails.version.to_i > 2
|
|
|
31
31
|
|
|
32
32
|
it "should not need counter cache with part of cities" do
|
|
33
33
|
Country.all.each do |country|
|
|
34
|
-
country.cities.
|
|
34
|
+
country.cities.find(:all, :conditions => {:name => 'first'}).size
|
|
35
35
|
end
|
|
36
36
|
Bullet.collected_counter_cache_notifications.should be_empty
|
|
37
37
|
end
|
data/spec/models/post.rb
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
class Post < ActiveRecord::Base
|
|
2
|
+
extend Bullet::Dependency
|
|
3
|
+
|
|
2
4
|
belongs_to :category
|
|
3
5
|
belongs_to :writer
|
|
4
6
|
has_many :comments
|
|
5
7
|
|
|
6
|
-
if
|
|
8
|
+
if active_record2?
|
|
7
9
|
named_scope :preload_comments, lambda { {:include => :comments} }
|
|
8
10
|
named_scope :in_category_name, lambda { |name|
|
|
9
11
|
{:conditions => ['categories.name = ?', name], :include => :category}
|