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/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
- !response.body.is_a?(String) || response.body.empty?
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)
@@ -1,5 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Bullet
3
- VERSION = "4.0.0"
3
+ VERSION = "4.1.4"
4
4
  end
5
-
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
- if Rails.version =~ /\A3\.0/
8
- autoload :ActiveRecord, 'bullet/active_record3'
9
- elsif Rails.version =~ /\A3\.[12]/
10
- autoload :ActiveRecord, 'bullet/active_record31'
11
- else
12
- autoload :ActiveRecord, 'bullet/active_record2'
13
- autoload :ActionController, 'bullet/action_controller2'
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
- begin
45
- require 'mongoid'
45
+ if mongoid?
46
46
  Bullet::Mongoid.enable
47
- rescue LoadError
48
47
  end
49
- begin
50
- require 'active_record'
48
+ if active_record?
51
49
  Bullet::ActiveRecord.enable
52
- if Rails.version =~ /\A2./
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
- begin
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,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- if Rails.version.to_i > 2
3
+ if active_record3?
4
4
  describe Bullet::Detector::Association, 'has_many' do
5
5
  before(:each) do
6
6
  Bullet.clear
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- if Rails.version.to_i > 2
3
+ if active_record3?
4
4
  describe Bullet::Detector::Counter do
5
5
  before(:each) do
6
6
  Bullet.start_request
@@ -1,276 +1,251 @@
1
1
  require 'spec_helper'
2
2
 
3
- begin
4
- require 'mongoid'
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 "posts => comments" do
15
- it "should detect non preload posts => comments" do
16
- Mongoid::Post.all.each do |post|
17
- post.comments.map(&:name)
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
- Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Post, :comments)
23
- end
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
- it "should detect preload post => comments" do
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
- it "should detect unused preload post => comments" do
36
- Mongoid::Post.includes(:comments).map(&:name)
37
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
38
- Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Post, :comments)
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
- Bullet::Detector::Association.should be_completely_preloading_associations
41
- end
41
+ Bullet::Detector::Association.should be_completely_preloading_associations
42
+ end
42
43
 
43
- it "should not detect unused preload post => comments" do
44
- Mongoid::Post.all.map(&:name)
45
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
46
- Bullet::Detector::Association.should_not be_has_unused_preload_associations
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
- Bullet::Detector::Association.should be_completely_preloading_associations
49
+ Bullet::Detector::Association.should be_completely_preloading_associations
50
+ end
49
51
  end
50
- end
51
52
 
52
- context "category => posts, category => entries" do
53
- it "should detect non preload with category => [posts, entries]" do
54
- Mongoid::Category.all.each do |category|
55
- category.posts.map(&:name)
56
- category.entries.map(&:name)
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
- Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Category, :posts)
62
- Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Category, :entries)
63
- end
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
- it "should detect preload with category => posts, but not with category => entries" do
66
- Mongoid::Category.includes(:posts).each do |category|
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
- Bullet::Detector::Association.should_not be_detecting_unpreloaded_association_for(Mongoid::Category, :posts)
74
- Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Category, :entries)
75
- end
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
- it "should detect preload with category => [posts, entries]" do
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
- Bullet::Detector::Association.should be_completely_preloading_associations
86
- end
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
- it "should detect unused preload with category => [posts, entries]" do
89
- Mongoid::Category.includes([:posts, :entries]).map(&:name)
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
- Bullet::Detector::Association.should be_completely_preloading_associations
95
- end
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
- it "should detect unused preload with category => entries, but not with category => posts" do
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
- context "post => comment" do
110
- it "should detect unused preload with post => comments" do
111
- Mongoid::Post.includes(:comments).each do |post|
112
- post.comments.first.name
113
- end
114
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
115
- Bullet::Detector::Association.should_not be_unused_preload_associations_for(Mongoid::Post, :comments)
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
- Bullet::Detector::Association.should be_completely_preloading_associations
118
- end
118
+ Bullet::Detector::Association.should be_completely_preloading_associations
119
+ end
119
120
 
120
- it "should detect preload with post => commnets" do
121
- Mongoid::Post.first.comments.collect(&:name)
122
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
123
- Bullet::Detector::Association.should_not be_has_unused_preload_associations
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
- Bullet::Detector::Association.should be_completely_preloading_associations
126
+ Bullet::Detector::Association.should be_completely_preloading_associations
127
+ end
126
128
  end
127
- end
128
129
 
129
- context "scope preload_comments" do
130
- it "should detect preload post => comments with scope" do
131
- Mongoid::Post.preload_comments.each do |post|
132
- post.comments.map(&:name)
133
- end
134
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
135
- Bullet::Detector::Association.should_not be_has_unused_preload_associations
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
- Bullet::Detector::Association.should be_completely_preloading_associations
138
- end
138
+ Bullet::Detector::Association.should be_completely_preloading_associations
139
+ end
139
140
 
140
- it "should detect unused preload with scope" do
141
- Mongoid::Post.preload_comments.map(&:name)
142
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
143
- Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Post, :comments)
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
- Bullet::Detector::Association.should be_completely_preloading_associations
146
+ Bullet::Detector::Association.should be_completely_preloading_associations
147
+ end
146
148
  end
147
149
  end
148
- end
149
150
 
150
- describe Bullet::Detector::Association, 'belongs_to' do
151
- before(:each) do
152
- Bullet.clear
153
- Bullet.start_request
154
- end
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
- after(:each) do
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
- Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Comment, :post)
169
- end
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
- it "should detect preload with one comment => post" do
172
- Mongoid::Comment.first.post.name
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
- Bullet::Detector::Association.should be_completely_preloading_associations
177
- end
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
- it "should detect preload with comment => post" do
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
- Bullet::Detector::Association.should be_completely_preloading_associations
187
- end
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
- it "should not detect preload with comment => post" do
190
- Mongoid::Comment.all.collect(&:name)
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
- it "should detect unused preload with comments => post" do
198
- Mongoid::Comment.includes(:post).map(&:name)
199
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
200
- Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Comment, :post)
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
- Bullet::Detector::Association.should be_completely_preloading_associations
194
+ Bullet::Detector::Association.should be_completely_preloading_associations
195
+ end
203
196
  end
204
197
  end
205
- end
206
198
 
207
- describe Bullet::Detector::Association, "has_one" do
208
- before(:each) do
209
- Bullet.clear
210
- Bullet.start_request
211
- end
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
- after(:each) do
214
- Bullet.end_request
215
- end
208
+ Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Company, :address)
209
+ end
216
210
 
217
- context "company => address" do
218
- it "should detect non preload association" do
219
- Mongoid::Company.all.each do |company|
220
- company.address.name
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
- Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Company, :address)
226
- end
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
- it "should detect preload association" do
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
- Bullet::Detector::Association.should be_completely_preloading_associations
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::Company.all.collect(&:name)
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 Rails.version.to_i == 2
3
+ if active_record2?
4
4
  describe Bullet::Detector::Association, 'has_many' do
5
5
  before(:each) do
6
6
  Bullet.clear
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- if Rails.version.to_i > 2
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.where(:name => 'first').size
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 Rails.version.to_i == 2
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}