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 CHANGED
@@ -8,3 +8,5 @@ tags
8
8
  .bundle
9
9
  *.gem
10
10
  benchmark_profile*
11
+ /nbproject/private/
12
+ Gemfile*.lock
data/.travis.yml CHANGED
@@ -3,8 +3,8 @@ rvm:
3
3
  - 1.9.3
4
4
  gemfile:
5
5
  - Gemfile
6
- - Gemfile.rails-3.1.4
7
- - Gemfile.rails-3.0.12
6
+ - Gemfile.rails-3.1.5
7
+ - Gemfile.rails-3.0.13
8
8
  - Gemfile.rails-2.3.14
9
9
  env: DB=sqlite
10
10
  before_install:
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ source "http://rubygems.org"
4
4
 
5
5
  gemspec
6
6
 
7
- gem 'rails', '3.2.3'
7
+ gem 'rails', '3.2.5'
8
8
  gem 'sqlite3'
9
9
  gem 'mysql'
10
10
  gem 'activerecord-import'
@@ -4,7 +4,7 @@ source "http://rubygems.org"
4
4
 
5
5
  gemspec
6
6
 
7
- gem 'rails', '3.0.12'
7
+ gem 'rails', '3.0.13'
8
8
  gem 'sqlite3'
9
9
  gem 'mysql'
10
10
  gem 'activerecord-import'
@@ -4,7 +4,7 @@ source "http://rubygems.org"
4
4
 
5
5
  gemspec
6
6
 
7
- gem 'rails', '3.1.4'
7
+ gem 'rails', '3.1.5'
8
8
  gem 'sqlite3'
9
9
  gem 'mysql'
10
10
  gem 'activerecord-import'
@@ -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 !https://gemnasium.com/flyerhzm/bullet.png?travis(Dependency Status)!:https://gemnasium.com/flyerhzm/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 six of the Bullet notification systems:
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
- ruby-growl gem has an issue about md5 in ruby 1.9, if you use growl and ruby 1.9, check this gist http://gist.github.com/300184
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
@@ -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", "~> 1.0.0"
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 Rails.version =~ /\A2.3/
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 Rails.version =~ /\A2.[12]/
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
@@ -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
- Bullet::Detector::NPlusOneQuery.call_association(self, name)
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
@@ -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
- Bullet::Detector::NPlusOneQuery.call_association(self, name)
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
@@ -19,7 +19,12 @@ module Bullet
19
19
  end
20
20
 
21
21
  def whoami
22
- "user: " << `whoami`.chomp
22
+ user = `whoami`
23
+ if user
24
+ "user: #{user.chomp}"
25
+ else
26
+ ""
27
+ end
23
28
  end
24
29
 
25
30
  def body_with_caller
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.1.0"
3
+ VERSION = "4.2.0"
4
4
  end
5
-
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
- 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?
14
13
  end
15
- begin
16
- require 'mongoid'
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
- begin
53
- require 'mongoid'
45
+ if mongoid?
54
46
  Bullet::Mongoid.enable
55
- rescue LoadError
56
47
  end
57
- begin
58
- require 'active_record'
48
+ if active_record?
59
49
  Bullet::ActiveRecord.enable
60
- if Rails.version =~ /\A2./
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
- 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
@@ -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,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,7 +1,6 @@
1
- begin
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 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
@@ -4,5 +4,7 @@ class Mongoid::Post
4
4
  has_many :comments, :class_name => "Mongoid::Comment"
5
5
  belongs_to :category, :class_name => "Mongoid::Category"
6
6
 
7
+ embeds_many :users, :class_name => "Mongoid::User"
8
+
7
9
  scope :preload_comments, lambda { includes(:comments) }
8
10
  end
@@ -0,0 +1,3 @@
1
+ class Mongoid::User
2
+ include Mongoid::Document
3
+ 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}