bullet 4.1.0 → 4.2.0
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 +2 -0
- data/.travis.yml +2 -2
- data/Gemfile +1 -1
- data/{Gemfile.rails-3.0.12 → Gemfile.rails-3.0.13} +1 -1
- data/{Gemfile.rails-3.1.4 → Gemfile.rails-3.1.5} +1 -1
- data/Gemfile.rails-4-beta +19 -0
- data/README.textile +17 -35
- data/README_for_rails2.textile +4 -0
- data/bullet.gemspec +1 -1
- data/lib/bullet/action_controller2.rb +5 -4
- data/lib/bullet/dependency.rb +87 -0
- data/lib/bullet/mongoid24.rb +5 -3
- data/lib/bullet/mongoid3.rb +5 -3
- data/lib/bullet/notification/base.rb +6 -1
- data/lib/bullet/rack.rb +8 -6
- data/lib/bullet/version.rb +1 -2
- data/lib/bullet.rb +13 -26
- data/spec/bullet/ext/object_spec.rb +1 -4
- data/spec/bullet/rack_spec.rb +6 -0
- data/spec/integration/association_spec.rb +1 -1
- data/spec/integration/counter_spec.rb +1 -1
- data/spec/integration/mongoid/association_spec.rb +16 -4
- data/spec/integration/rails2/association_spec.rb +1 -1
- data/spec/integration/rails2/counter_spec.rb +2 -2
- data/spec/models/mongoid/post.rb +2 -0
- data/spec/models/mongoid/user.rb +3 -0
- data/spec/models/post.rb +3 -1
- data/spec/spec_helper.rb +26 -22
- data/spec/support/mongo_seed.rb +4 -0
- data/test.sh +3 -2
- metadata +13 -14
- data/Gemfile.lock +0 -129
- data/Gemfile.rails-2.3.14.lock +0 -65
- data/Gemfile.rails-3.0.12.lock +0 -116
- data/Gemfile.rails-3.1.4.lock +0 -134
- data/test.result +0 -2293
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Use `bundle install` in order to install these gems
|
|
2
|
+
# Use `bundle exec rake` in order to run the specs using the bundle
|
|
3
|
+
source "http://rubygems.org"
|
|
4
|
+
|
|
5
|
+
gemspec
|
|
6
|
+
|
|
7
|
+
gem 'rails', github: 'rails/rails'
|
|
8
|
+
gem 'journey', github: 'rails/journey'
|
|
9
|
+
gem 'activerecord-deprecated_finders', github: 'rails/activerecord-deprecated_finders'
|
|
10
|
+
gem 'sqlite3'
|
|
11
|
+
gem 'mysql'
|
|
12
|
+
gem 'activerecord-import'
|
|
13
|
+
gem 'mongoid', github: 'slbug/mongoid'
|
|
14
|
+
|
|
15
|
+
gem "rspec"
|
|
16
|
+
gem "guard"
|
|
17
|
+
gem "guard-rspec"
|
|
18
|
+
|
|
19
|
+
gem "perftools.rb"
|
data/README.textile
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
h1. Bullet
|
|
1
|
+
h1. Bullet
|
|
2
2
|
|
|
3
3
|
!https://secure.travis-ci.org/flyerhzm/bullet.png!:http://travis-ci.org/flyerhzm/bullet
|
|
4
4
|
|
|
5
|
+
!http://api.coderwall.com/flyerhzm/endorsecount.png!:http://coderwall.com/flyerhzm
|
|
6
|
+
|
|
5
7
|
The Bullet gem is designed to help you increase your application's performance by reducing the number of queries it makes. It will watch your queries while you develop your application and notify you when you should add eager loading (N+1 queries), when you're using eager loading that isn't necessary and when you should use counter cache.
|
|
6
8
|
|
|
7
9
|
Best practice is to use Bullet in development mode or custom mode (staging, profile, etc.). The last thing you want is your clients getting alerts about how lazy you are.
|
|
@@ -10,6 +12,15 @@ The Bullet gem now supports **activerecord** 2.1, 2.2, 2.3, 3.0, 3.1, 3.2 and **
|
|
|
10
12
|
|
|
11
13
|
****************************************************************************
|
|
12
14
|
|
|
15
|
+
h2. External Introduction
|
|
16
|
+
|
|
17
|
+
* "http://railscasts.com/episodes/372-bullet":http://railscasts.com/episodes/372-bullet
|
|
18
|
+
* "http://ruby5.envylabs.com/episodes/9-episode-8-september-8-2009":http://ruby5.envylabs.com/episodes/9-episode-8-september-8-2009
|
|
19
|
+
* "http://railslab.newrelic.com/2009/10/23/episode-19-on-the-edge-part-1":http://railslab.newrelic.com/2009/10/23/episode-19-on-the-edge-part-1
|
|
20
|
+
* "http://weblog.rubyonrails.org/2009/10/22/community-highlights":http://weblog.rubyonrails.org/2009/10/22/community-highlights
|
|
21
|
+
|
|
22
|
+
****************************************************************************
|
|
23
|
+
|
|
13
24
|
h2. Install
|
|
14
25
|
|
|
15
26
|
You can install it as a gem:
|
|
@@ -39,17 +50,19 @@ config.after_initialize do
|
|
|
39
50
|
:receiver => 'your_account@jabber.org',
|
|
40
51
|
:show_online_status => true }
|
|
41
52
|
Bullet.rails_logger = true
|
|
53
|
+
Bullet.airbrake = true
|
|
42
54
|
Bullet.disable_browser_cache = true
|
|
43
55
|
end
|
|
44
56
|
</code></pre>
|
|
45
57
|
|
|
46
58
|
The notifier of bullet is a wrap of "uniform_notifier":https://github.com/flyerhzm/uniform_notifier
|
|
47
59
|
|
|
48
|
-
The code above will enable all
|
|
60
|
+
The code above will enable all seven of the Bullet notification systems:
|
|
49
61
|
* <code>Bullet.enable</code>: enable Bullet gem, otherwise do nothing
|
|
50
62
|
* <code>Bullet.alert</code>: pop up a JavaScript alert in the browser
|
|
51
63
|
* <code>Bullet.bullet_logger</code>: log to the Bullet log file (Rails.root/log/bullet.log)
|
|
52
64
|
* <code>Bullet.rails_logger</code>: add warnings directly to the Rails log
|
|
65
|
+
* <code>Bullet.airbrake</code>: add notifications to airbrake
|
|
53
66
|
* <code>Bullet.console</code>: log warnings to your browser's console.log (Safari/Webkit browsers or Firefox w/Firebug installed)
|
|
54
67
|
* <code>Bullet.growl</code>: pop up Growl warnings if your system has Growl installed. Requires a little bit of configuration
|
|
55
68
|
* <code>Bullet.xmpp</code>: send XMPP/Jabber notifications to the receiver indicated. Note that the code will currently not handle the adding of contacts, so you will need to make both accounts indicated know each other manually before you will receive any notifications. If you restart the development server frequently, the 'coming online' sound for the bullet account may start to annoy - in this case set :show_online_status to false; you will still get notifications, but the bullet account won't announce it's online status anymore.
|
|
@@ -90,32 +103,9 @@ These two lines are notifications that unused eager loadings have been encounter
|
|
|
90
103
|
|
|
91
104
|
****************************************************************************
|
|
92
105
|
|
|
93
|
-
h2. Growl Support
|
|
94
|
-
|
|
95
|
-
To get Growl support up-and-running for Bullet, follow the steps below:
|
|
96
|
-
* Install the ruby-growl gem: <code>gem install ruby-growl</code>
|
|
97
|
-
* Open the Growl preference pane in Systems Preferences
|
|
98
|
-
* Click the "Network" tab
|
|
99
|
-
* Make sure both "Listen for incoming notifications" and "Allow remote application registration" are checked. *Note*: If you set a password, you will need to set <code>Bullet.growl = { :password => 'growl password' }</code> in the config file.
|
|
100
|
-
* Restart Growl ("General" tab -> Stop Growl -> Start Growl)
|
|
101
|
-
* Boot up your application. Bullet will automatically send a Growl notification when Growl is turned on. If you do not see it when your application loads, make sure it is enabled in your initializer and double-check the steps above.
|
|
102
|
-
|
|
103
|
-
****************************************************************************
|
|
104
|
-
|
|
105
|
-
h2. Ruby 1.9 issue
|
|
106
|
+
h2. Growl, XMPP/Jabber and Airbrake Support
|
|
106
107
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
****************************************************************************
|
|
110
|
-
|
|
111
|
-
h2. XMPP/Jabber Support
|
|
112
|
-
|
|
113
|
-
To get XMPP support up-and-running for Bullet, follow the steps below:
|
|
114
|
-
* Install the xmpp4r gem: <code>sudo gem install xmpp4r</code>
|
|
115
|
-
* Make both the bullet and the receipient account add each other as contacts.
|
|
116
|
-
This will require you to manually log into both accounts, add each other
|
|
117
|
-
as contact and confirm each others contact request.
|
|
118
|
-
* Boot up your application. Bullet will automatically send an XMPP notification when XMPP is turned on.
|
|
108
|
+
see "https://github.com/flyerhzm/uniform_notifier":https://github.com/flyerhzm/uniform_notifier
|
|
119
109
|
|
|
120
110
|
****************************************************************************
|
|
121
111
|
|
|
@@ -158,14 +148,6 @@ Don't forget enabling bullet in test environment.
|
|
|
158
148
|
|
|
159
149
|
****************************************************************************
|
|
160
150
|
|
|
161
|
-
h2. Links
|
|
162
|
-
|
|
163
|
-
* "http://weblog.rubyonrails.org/2009/10/22/community-highlights":http://weblog.rubyonrails.org/2009/10/22/community-highlights
|
|
164
|
-
* "http://ruby5.envylabs.com/episodes/9-episode-8-september-8-2009":http://ruby5.envylabs.com/episodes/9-episode-8-september-8-2009
|
|
165
|
-
* "http://railslab.newrelic.com/2009/10/23/episode-19-on-the-edge-part-1":http://railslab.newrelic.com/2009/10/23/episode-19-on-the-edge-part-1
|
|
166
|
-
|
|
167
|
-
****************************************************************************
|
|
168
|
-
|
|
169
151
|
h2. Contributors
|
|
170
152
|
|
|
171
153
|
"https://github.com/flyerhzm/bullet/contributors":https://github.com/flyerhzm/bullet/contributors
|
data/README_for_rails2.textile
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
h1. Bullet
|
|
2
2
|
|
|
3
|
+
!https://secure.travis-ci.org/flyerhzm/bullet.png!:http://travis-ci.org/flyerhzm/bullet
|
|
4
|
+
|
|
5
|
+
!http://api.coderwall.com/flyerhzm/endorsecount.png!:http://coderwall.com/flyerhzm
|
|
6
|
+
|
|
3
7
|
The Bullet plugin/gem is designed to help you increase your application's performance by reducing the number of queries it makes. It will watch your queries while you develop your application and notify you when you should add eager loading (N+1 queries), when you're using eager loading that isn't necessary and when you should use counter cache.
|
|
4
8
|
|
|
5
9
|
Best practice is to use Bullet in development mode or custom mode (staging, profile, etc.). The last thing you want is your clients getting alerts about how lazy you are.
|
data/bullet.gemspec
CHANGED
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
|
15
15
|
|
|
16
16
|
s.required_rubygems_version = ">= 1.3.6"
|
|
17
17
|
|
|
18
|
-
s.add_dependency "uniform_notifier"
|
|
18
|
+
s.add_dependency "uniform_notifier"
|
|
19
19
|
|
|
20
20
|
s.files = `git ls-files`.split("\n")
|
|
21
21
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
module Bullet
|
|
2
2
|
class ActionController
|
|
3
|
+
extend Dependency
|
|
4
|
+
|
|
3
5
|
def self.enable
|
|
4
6
|
require 'action_controller'
|
|
5
|
-
if
|
|
7
|
+
if active_record23?
|
|
6
8
|
::ActionController::Dispatcher.middleware.use Bullet::Rack
|
|
7
9
|
::ActionController::Dispatcher.class_eval do
|
|
8
10
|
class <<self
|
|
@@ -13,7 +15,7 @@ module Bullet
|
|
|
13
15
|
end
|
|
14
16
|
end
|
|
15
17
|
end
|
|
16
|
-
elsif
|
|
18
|
+
elsif active_record21? || active_record22?
|
|
17
19
|
::ActionController::Dispatcher.class_eval do
|
|
18
20
|
alias_method :origin_reload_application, :reload_application
|
|
19
21
|
def reload_application
|
|
@@ -29,8 +31,7 @@ module Bullet
|
|
|
29
31
|
response = origin_process(request, response, method = :perform_action, *arguments)
|
|
30
32
|
|
|
31
33
|
if Bullet.notification?
|
|
32
|
-
if response.headers["type"] && response.headers["type"].include?('text/html') &&
|
|
33
|
-
response.body.include?("<html>") && response.body.include?("</html>")
|
|
34
|
+
if response.headers["type"] && response.headers["type"].include?('text/html') && response.body.include?("<html>")
|
|
34
35
|
response.body <<= Bullet.gather_inline_notifications
|
|
35
36
|
response.headers["Content-Length"] = response.body.length.to_s
|
|
36
37
|
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
module Bullet
|
|
2
|
+
module Dependency
|
|
3
|
+
def mongoid?
|
|
4
|
+
@mongoid ||= begin
|
|
5
|
+
require 'mongoid'
|
|
6
|
+
true
|
|
7
|
+
rescue LoadError
|
|
8
|
+
false
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def active_record?
|
|
13
|
+
@active_record ||= begin
|
|
14
|
+
require 'active_record'
|
|
15
|
+
true
|
|
16
|
+
rescue LoadError
|
|
17
|
+
false
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def active_record_version
|
|
22
|
+
@active_record_version ||= begin
|
|
23
|
+
if active_record2?
|
|
24
|
+
'active_record2'
|
|
25
|
+
elsif active_record30?
|
|
26
|
+
'active_record3'
|
|
27
|
+
elsif active_record31? || active_record32? || active_record4?
|
|
28
|
+
'active_record31'
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def mongoid_version
|
|
34
|
+
@mongoid_version ||= begin
|
|
35
|
+
if mongoid24?
|
|
36
|
+
'mongoid24'
|
|
37
|
+
elsif mongoid3?
|
|
38
|
+
'mongoid3'
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def active_record2?
|
|
44
|
+
::ActiveRecord::VERSION::MAJOR == 2
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def active_record23?
|
|
48
|
+
active_record2? && ::ActiveRecord::VERSION::MINOR == 3
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def active_record22?
|
|
52
|
+
active_record2? && ::ActiveRecord::VERSION::MINOR == 2
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def active_record21?
|
|
56
|
+
active_record2? && ::ActiveRecord::VERSION::MINOR == 1
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def active_record3?
|
|
60
|
+
::ActiveRecord::VERSION::MAJOR == 3
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def active_record4?
|
|
64
|
+
::ActiveRecord::VERSION::MAJOR == 4
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def active_record30?
|
|
68
|
+
active_record3? && ::ActiveRecord::VERSION::MINOR == 0
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def active_record31?
|
|
72
|
+
active_record3? && ::ActiveRecord::VERSION::MINOR == 1
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def active_record32?
|
|
76
|
+
active_record3? && ::ActiveRecord::VERSION::MINOR == 2
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def mongoid24?
|
|
80
|
+
::Mongoid::VERSION =~ /\A2\.4/
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def mongoid3?
|
|
84
|
+
::Mongoid::VERSION =~ /\A3/
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
data/lib/bullet/mongoid24.rb
CHANGED
|
@@ -11,13 +11,13 @@ module Bullet
|
|
|
11
11
|
|
|
12
12
|
def first
|
|
13
13
|
result = origin_first
|
|
14
|
-
Bullet::Detector::Association.add_impossible_object(result)
|
|
14
|
+
Bullet::Detector::Association.add_impossible_object(result) if result
|
|
15
15
|
result
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def last
|
|
19
19
|
result = origin_last
|
|
20
|
-
Bullet::Detector::Association.add_impossible_object(result)
|
|
20
|
+
Bullet::Detector::Association.add_impossible_object(result) if result
|
|
21
21
|
result
|
|
22
22
|
end
|
|
23
23
|
|
|
@@ -45,7 +45,9 @@ module Bullet
|
|
|
45
45
|
alias_method :origin_set_relation, :set_relation
|
|
46
46
|
|
|
47
47
|
def set_relation(name, relation)
|
|
48
|
-
|
|
48
|
+
if relation && relation.metadata.macro !~ /embed/
|
|
49
|
+
Bullet::Detector::NPlusOneQuery.call_association(self, name)
|
|
50
|
+
end
|
|
49
51
|
origin_set_relation(name, relation)
|
|
50
52
|
end
|
|
51
53
|
end
|
data/lib/bullet/mongoid3.rb
CHANGED
|
@@ -10,13 +10,13 @@ module Bullet
|
|
|
10
10
|
|
|
11
11
|
def first
|
|
12
12
|
result = origin_first
|
|
13
|
-
Bullet::Detector::Association.add_impossible_object(result)
|
|
13
|
+
Bullet::Detector::Association.add_impossible_object(result) if result
|
|
14
14
|
result
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def last
|
|
18
18
|
result = origin_last
|
|
19
|
-
Bullet::Detector::Association.add_impossible_object(result)
|
|
19
|
+
Bullet::Detector::Association.add_impossible_object(result) if result
|
|
20
20
|
result
|
|
21
21
|
end
|
|
22
22
|
|
|
@@ -44,7 +44,9 @@ module Bullet
|
|
|
44
44
|
alias_method :origin_set_relation, :set_relation
|
|
45
45
|
|
|
46
46
|
def set_relation(name, relation)
|
|
47
|
-
|
|
47
|
+
if relation && relation.metadata.macro !~ /embed/
|
|
48
|
+
Bullet::Detector::NPlusOneQuery.call_association(self, name)
|
|
49
|
+
end
|
|
48
50
|
origin_set_relation(name, relation)
|
|
49
51
|
end
|
|
50
52
|
end
|
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,24 +2,17 @@ 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
|
-
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?
|
|
14
13
|
end
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if Mongoid::VERSION =~ /\A2\.4/
|
|
18
|
-
autoload :Mongoid, 'bullet/mongoid24'
|
|
19
|
-
elsif Mongoid::VERSION =~ /\A3/
|
|
20
|
-
autoload :Mongoid, 'bullet/mongoid3'
|
|
21
|
-
end
|
|
22
|
-
rescue LoadError
|
|
14
|
+
if mongoid?
|
|
15
|
+
autoload :Mongoid, "bullet/#{mongoid_version}"
|
|
23
16
|
end
|
|
24
17
|
autoload :Rack, 'bullet/rack'
|
|
25
18
|
autoload :BulletLogger, 'bullet/logger'
|
|
@@ -40,7 +33,7 @@ module Bullet
|
|
|
40
33
|
attr_accessor :enable, :disable_browser_cache
|
|
41
34
|
attr_reader :notification_collector
|
|
42
35
|
|
|
43
|
-
delegate :alert=, :console=, :growl=, :rails_logger=, :xmpp=, :to => UniformNotifier
|
|
36
|
+
delegate :alert=, :console=, :growl=, :rails_logger=, :xmpp=, :airbrake=, :to => UniformNotifier
|
|
44
37
|
|
|
45
38
|
DETECTORS = [ Bullet::Detector::NPlusOneQuery,
|
|
46
39
|
Bullet::Detector::UnusedEagerAssociation,
|
|
@@ -49,18 +42,12 @@ module Bullet
|
|
|
49
42
|
def enable=(enable)
|
|
50
43
|
@enable = enable
|
|
51
44
|
if enable?
|
|
52
|
-
|
|
53
|
-
require 'mongoid'
|
|
45
|
+
if mongoid?
|
|
54
46
|
Bullet::Mongoid.enable
|
|
55
|
-
rescue LoadError
|
|
56
47
|
end
|
|
57
|
-
|
|
58
|
-
require 'active_record'
|
|
48
|
+
if active_record?
|
|
59
49
|
Bullet::ActiveRecord.enable
|
|
60
|
-
|
|
61
|
-
Bullet::ActionController.enable
|
|
62
|
-
end
|
|
63
|
-
rescue LoadError
|
|
50
|
+
Bullet::ActionController.enable if active_record2?
|
|
64
51
|
end
|
|
65
52
|
end
|
|
66
53
|
end
|
|
@@ -72,7 +59,7 @@ module Bullet
|
|
|
72
59
|
def bullet_logger=(active)
|
|
73
60
|
if active
|
|
74
61
|
bullet_log_file = File.open('log/bullet.log', 'a+')
|
|
75
|
-
bullet_log_file.sync
|
|
62
|
+
bullet_log_file.sync = true
|
|
76
63
|
UniformNotifier.customized_logger = bullet_log_file
|
|
77
64
|
end
|
|
78
65
|
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
|
data/spec/bullet/rack_spec.rb
CHANGED
|
@@ -22,6 +22,12 @@ module Bullet
|
|
|
22
22
|
middleware.should be_html_request(headers, response)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
it "should be true if Content-Type is text/html and http body contains html tag with attributes" do
|
|
26
|
+
headers = {"Content-Type" => "text/html"}
|
|
27
|
+
response = stub(:body => "<html attr='hello'><head></head><body></body></html>")
|
|
28
|
+
middleware.should be_html_request(headers, response)
|
|
29
|
+
end
|
|
30
|
+
|
|
25
31
|
it "should be false if there is no Content-Type header" do
|
|
26
32
|
headers = {}
|
|
27
33
|
response = stub(:body => "<html><head></head><body></body></html>")
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
require 'mongoid'
|
|
3
|
-
require 'spec_helper'
|
|
1
|
+
require 'spec_helper'
|
|
4
2
|
|
|
3
|
+
if mongoid?
|
|
5
4
|
describe Bullet::Detector::Association do
|
|
6
5
|
before(:each) do
|
|
7
6
|
Bullet.clear
|
|
@@ -12,6 +11,20 @@ begin
|
|
|
12
11
|
Mongoid::IdentityMap.clear
|
|
13
12
|
end
|
|
14
13
|
|
|
14
|
+
context 'embeds_many' do
|
|
15
|
+
context "posts => users" do
|
|
16
|
+
it "should detect nothing" do
|
|
17
|
+
Mongoid::Post.all.each do |post|
|
|
18
|
+
post.users.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_completely_preloading_associations
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
15
28
|
context 'has_many' do
|
|
16
29
|
context "posts => comments" do
|
|
17
30
|
it "should detect non preload posts => comments" do
|
|
@@ -249,5 +262,4 @@ begin
|
|
|
249
262
|
end
|
|
250
263
|
end
|
|
251
264
|
end
|
|
252
|
-
rescue LoadError
|
|
253
265
|
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/mongoid/post.rb
CHANGED
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}
|