bullet 4.6.0 → 4.7.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.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +10 -4
  6. data/Gemfile +4 -5
  7. data/Gemfile.lock +160 -0
  8. data/Gemfile.mongoid +15 -0
  9. data/Gemfile.mongoid-2.4.12 +15 -0
  10. data/Gemfile.mongoid-2.4.12.lock +163 -0
  11. data/Gemfile.mongoid-2.5.2 +15 -0
  12. data/Gemfile.mongoid-2.5.2.lock +163 -0
  13. data/Gemfile.mongoid-2.6.0 +15 -0
  14. data/Gemfile.mongoid-2.6.0.lock +163 -0
  15. data/Gemfile.mongoid-2.7.1 +15 -0
  16. data/Gemfile.mongoid-2.7.1.lock +163 -0
  17. data/Gemfile.mongoid-2.8.1 +15 -0
  18. data/Gemfile.mongoid-2.8.1.lock +166 -0
  19. data/Gemfile.mongoid-3.0.23 +15 -0
  20. data/Gemfile.mongoid-3.0.23.lock +163 -0
  21. data/Gemfile.mongoid-3.1.5 +15 -0
  22. data/Gemfile.mongoid-3.1.5.lock +163 -0
  23. data/Gemfile.mongoid.lock +167 -0
  24. data/Gemfile.rails-3.0.20 +3 -4
  25. data/Gemfile.rails-3.0.20.lock +147 -0
  26. data/Gemfile.rails-3.1.12 +14 -0
  27. data/Gemfile.rails-3.1.12.lock +157 -0
  28. data/Gemfile.rails-3.2.15 +14 -0
  29. data/Gemfile.rails-3.2.15.lock +155 -0
  30. data/Gemfile.rails-4.0.1 +14 -0
  31. data/Gemfile.rails-4.0.1.lock +150 -0
  32. data/README.md +16 -16
  33. data/bullet.gemspec +2 -1
  34. data/lib/bullet.rb +26 -2
  35. data/lib/bullet/dependency.rb +14 -23
  36. data/lib/bullet/mongoid4x.rb +55 -0
  37. data/lib/bullet/notification.rb +2 -0
  38. data/lib/bullet/notification/base.rb +4 -0
  39. data/lib/bullet/rack.rb +24 -3
  40. data/lib/bullet/version.rb +1 -1
  41. data/spec/bullet/detector/unused_eager_loading_spec.rb +1 -1
  42. data/spec/bullet/notification/base_spec.rb +2 -2
  43. data/spec/bullet/rack_spec.rb +9 -9
  44. data/spec/integration/{association_spec.rb → active_record3/association_spec.rb} +1 -1
  45. data/spec/integration/active_record4/association_spec.rb +698 -0
  46. data/spec/integration/mongoid/association_spec.rb +10 -7
  47. data/spec/models/client.rb +1 -1
  48. data/spec/models/comment.rb +2 -2
  49. data/spec/models/document.rb +2 -2
  50. data/spec/models/firm.rb +1 -1
  51. data/spec/models/mongoid/address.rb +2 -0
  52. data/spec/models/mongoid/category.rb +2 -0
  53. data/spec/models/mongoid/comment.rb +2 -0
  54. data/spec/models/mongoid/company.rb +2 -0
  55. data/spec/models/mongoid/entry.rb +2 -0
  56. data/spec/models/mongoid/post.rb +2 -0
  57. data/spec/models/mongoid/user.rb +2 -0
  58. data/spec/models/newspaper.rb +1 -1
  59. data/spec/models/pet.rb +1 -1
  60. data/spec/models/post.rb +3 -5
  61. data/spec/spec_helper.rb +21 -0
  62. data/spec/support/mongo_seed.rb +13 -1
  63. data/test.sh +12 -4
  64. metadata +49 -11
  65. data/.rvmrc +0 -2
  66. data/.rvmrc.example +0 -2
  67. data/Gemfile.rails-3.1.11 +0 -16
  68. data/Gemfile.rails-3.2.12 +0 -16
  69. data/Gemfile.rails-4-beta +0 -14
@@ -212,14 +212,17 @@ if mongoid?
212
212
 
213
213
  context "has_one" do
214
214
  context "company => address" do
215
- it "should detect non preload association" do
216
- Mongoid::Company.all.each do |company|
217
- company.address.name
215
+ if Mongoid::VERSION !~ /\A3.0/
216
+ # mongodid 3.0.x doesn't set relation properly, it will query company for each address which causes n+1 query.
217
+ it "should detect non preload association" do
218
+ Mongoid::Company.all.each do |company|
219
+ company.address.name
220
+ end
221
+ Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
222
+ Bullet::Detector::Association.should_not be_has_unused_preload_associations
223
+
224
+ Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Company, :address)
218
225
  end
219
- Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
220
- Bullet::Detector::Association.should_not be_has_unused_preload_associations
221
-
222
- Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Company, :address)
223
226
  end
224
227
 
225
228
  it "should detect preload association" do
@@ -1,4 +1,4 @@
1
1
  class Client < ActiveRecord::Base
2
2
  has_many :relationships
3
- has_many :firms, :through => :relationships
3
+ has_many :firms, through: :relationships
4
4
  end
@@ -1,4 +1,4 @@
1
1
  class Comment < ActiveRecord::Base
2
- belongs_to :post, :inverse_of => :comments
3
- belongs_to :author, :class_name => "BaseUser"
2
+ belongs_to :post, inverse_of: :comments
3
+ belongs_to :author, class_name: "BaseUser"
4
4
  end
@@ -1,5 +1,5 @@
1
1
  class Document < ActiveRecord::Base
2
- has_many :children, :class_name => "Document", :foreign_key => 'parent_id'
3
- belongs_to :parent, :class_name => "Document", :foreign_key => 'parent_id'
2
+ has_many :children, class_name: "Document", foreign_key: 'parent_id'
3
+ belongs_to :parent, class_name: "Document", foreign_key: 'parent_id'
4
4
  belongs_to :author
5
5
  end
@@ -1,4 +1,4 @@
1
1
  class Firm < ActiveRecord::Base
2
2
  has_many :relationships
3
- has_many :clients, :through => :relationships
3
+ has_many :clients, through: :relationships
4
4
  end
@@ -1,5 +1,7 @@
1
1
  class Mongoid::Address
2
2
  include Mongoid::Document
3
3
 
4
+ field :name
5
+
4
6
  belongs_to :company, :class_name => "Mongoid::Company"
5
7
  end
@@ -1,6 +1,8 @@
1
1
  class Mongoid::Category
2
2
  include Mongoid::Document
3
3
 
4
+ field :name
5
+
4
6
  has_many :posts, :class_name => "Mongoid::Post"
5
7
  has_many :entries, :class_name => "Mongoid::Entry"
6
8
  end
@@ -1,5 +1,7 @@
1
1
  class Mongoid::Comment
2
2
  include Mongoid::Document
3
3
 
4
+ field :name
5
+
4
6
  belongs_to :post, :class_name => "Mongoid::Post"
5
7
  end
@@ -1,5 +1,7 @@
1
1
  class Mongoid::Company
2
2
  include Mongoid::Document
3
3
 
4
+ field :name
5
+
4
6
  has_one :address, :class_name => "Mongoid::Address"
5
7
  end
@@ -1,5 +1,7 @@
1
1
  class Mongoid::Entry
2
2
  include Mongoid::Document
3
3
 
4
+ field :name
5
+
4
6
  belongs_to :category, :class_name => "Mongoid::Category"
5
7
  end
@@ -1,6 +1,8 @@
1
1
  class Mongoid::Post
2
2
  include Mongoid::Document
3
3
 
4
+ field :name
5
+
4
6
  has_many :comments, :class_name => "Mongoid::Comment"
5
7
  belongs_to :category, :class_name => "Mongoid::Category"
6
8
 
@@ -1,3 +1,5 @@
1
1
  class Mongoid::User
2
2
  include Mongoid::Document
3
+
4
+ field :name
3
5
  end
@@ -1,3 +1,3 @@
1
1
  class Newspaper < ActiveRecord::Base
2
- has_many :writers, :class_name => "BaseUser"
2
+ has_many :writers, class_name: "BaseUser"
3
3
  end
@@ -1,3 +1,3 @@
1
1
  class Pet < ActiveRecord::Base
2
- belongs_to :person, :counter_cache => true
2
+ belongs_to :person, counter_cache: true
3
3
  end
@@ -3,10 +3,8 @@ class Post < ActiveRecord::Base
3
3
 
4
4
  belongs_to :category
5
5
  belongs_to :writer
6
- has_many :comments, :inverse_of => :post
6
+ has_many :comments, inverse_of: :post
7
7
 
8
- scope :preload_comments, lambda { includes(:comments) }
9
- scope :in_category_name, lambda { |name|
10
- where(['categories.name = ?', name]).includes(:category)
11
- }
8
+ scope :preload_comments, -> { includes(:comments) }
9
+ scope :in_category_name, ->(name) { where(['categories.name = ?', name]).includes(:category) }
12
10
  end
@@ -1,5 +1,13 @@
1
1
  require 'rspec'
2
2
  require 'rails'
3
+ begin
4
+ require 'active_record'
5
+ rescue LoadError
6
+ end
7
+ begin
8
+ require 'mongoid'
9
+ rescue LoadError
10
+ end
3
11
 
4
12
  module Rails
5
13
  class <<self
@@ -19,6 +27,9 @@ $LOAD_PATH.unshift(MODELS)
19
27
  SUPPORT = File.join(File.dirname(__FILE__), "support")
20
28
  Dir[ File.join(SUPPORT, "*.rb") ].reject { |filename| filename =~ /_seed.rb$/ }.sort.each { |file| require file }
21
29
 
30
+ require 'coveralls'
31
+ Coveralls.wear!
32
+
22
33
  RSpec.configure do |config|
23
34
  config.extend Bullet::Dependency
24
35
 
@@ -46,6 +57,10 @@ if active_record?
46
57
  Support::SqliteSeed.teardown_db
47
58
  end
48
59
  end
60
+
61
+ if ENV["LOG"]
62
+ ActiveRecord::Base.logger = Logger.new(STDOUT)
63
+ end
49
64
  end
50
65
 
51
66
  if mongoid?
@@ -60,7 +75,13 @@ if mongoid?
60
75
  end
61
76
 
62
77
  config.after(:suite) do
78
+ Support::MongoSeed.setup_db
63
79
  Support::MongoSeed.teardown_db
64
80
  end
65
81
  end
82
+
83
+ if ENV["LOG"]
84
+ Mongoid.logger = Logger.new(STDOUT)
85
+ Moped.logger = Logger.new(STDOUT)
86
+ end
66
87
  end
@@ -33,7 +33,7 @@ module Support
33
33
  end
34
34
 
35
35
  def setup_db
36
- if Mongoid::VERSION =~ /\A2\.[4|5]/
36
+ if Mongoid::VERSION =~ /\A2\.[4-8]/
37
37
  Mongoid.configure do |config|
38
38
  config.master = Mongo::Connection.new.db("bullet")
39
39
  end
@@ -41,11 +41,23 @@ module Support
41
41
  Mongoid.configure do |config|
42
42
  config.connect_to("bullet")
43
43
  end
44
+ elsif Mongoid::VERSION =~ /\A4/
45
+ Mongoid.configure do |config|
46
+ config.load_configuration(
47
+ sessions: {
48
+ default: {
49
+ database: "bullet",
50
+ hosts: [ "localhost:27017" ]
51
+ }
52
+ }
53
+ )
54
+ end
44
55
  end
45
56
  end
46
57
 
47
58
  def teardown_db
48
59
  Mongoid.purge!
60
+ Mongoid::IdentityMap.clear
49
61
  end
50
62
 
51
63
  extend self
data/test.sh CHANGED
@@ -1,5 +1,13 @@
1
- bundle && bundle exec rspec spec
2
- BUNDLE_GEMFILE=Gemfile.rails-3.2.12 bundle && BUNDLE_GEMFILE=Gemfile.rails-3.2.12 bundle exec rspec spec
3
- BUNDLE_GEMFILE=Gemfile.rails-3.1.11 bundle && BUNDLE_GEMFILE=Gemfile.rails-3.1.11 bundle exec rspec spec
1
+ #bundle update rails && bundle exec rspec spec
2
+ #BUNDLE_GEMFILE=Gemfile.mongoid bundle update mongoid && BUNDLE_GEMFILE=Gemfile.mongoid bundle exec rspec spec
3
+ BUNDLE_GEMFILE=Gemfile.rails-4.0.1 bundle && BUNDLE_GEMFILE=Gemfile.rails-4.0.1 bundle exec rspec spec
4
+ BUNDLE_GEMFILE=Gemfile.rails-3.2.15 bundle && BUNDLE_GEMFILE=Gemfile.rails-3.2.15 bundle exec rspec spec
5
+ BUNDLE_GEMFILE=Gemfile.rails-3.1.12 bundle && BUNDLE_GEMFILE=Gemfile.rails-3.1.12 bundle exec rspec spec
4
6
  BUNDLE_GEMFILE=Gemfile.rails-3.0.20 bundle && BUNDLE_GEMFILE=Gemfile.rails-3.0.20 bundle exec rspec spec
5
- BUNDLE_GEMFILE=Gemfile.rails-4-beta bundle && BUNDLE_GEMFILE=Gemfile.rails-4-beta bundle exec rspec spec
7
+ BUNDLE_GEMFILE=Gemfile.mongoid-3.1.5 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-3.1.5 bundle exec rspec spec
8
+ BUNDLE_GEMFILE=Gemfile.mongoid-3.0.23 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-3.0.23 bundle exec rspec spec
9
+ BUNDLE_GEMFILE=Gemfile.mongoid-2.8.1 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-2.8.1 bundle exec rspec spec
10
+ BUNDLE_GEMFILE=Gemfile.mongoid-2.7.1 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-2.7.1 bundle exec rspec spec
11
+ BUNDLE_GEMFILE=Gemfile.mongoid-2.6.0 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-2.6.0 bundle exec rspec spec
12
+ BUNDLE_GEMFILE=Gemfile.mongoid-2.5.2 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-2.5.2 bundle exec rspec spec
13
+ BUNDLE_GEMFILE=Gemfile.mongoid-2.4.12 bundle && BUNDLE_GEMFILE=Gemfile.mongoid-2.4.12 bundle exec rspec spec
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bullet
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.6.0
4
+ version: 4.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-17 00:00:00.000000000 Z
11
+ date: 2013-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: uniform_notifier
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - '>='
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: uniform_notifier
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.3.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.3.0
27
41
  description: help to kill N+1 queries and unused eager loading.
28
42
  email:
29
43
  - flyerhzm@gmail.com
@@ -33,15 +47,36 @@ extra_rdoc_files: []
33
47
  files:
34
48
  - .gitignore
35
49
  - .rspec
36
- - .rvmrc
37
- - .rvmrc.example
50
+ - .ruby-gemset
51
+ - .ruby-version
38
52
  - .travis.yml
39
53
  - CHANGELOG.md
40
54
  - Gemfile
55
+ - Gemfile.lock
56
+ - Gemfile.mongoid
57
+ - Gemfile.mongoid-2.4.12
58
+ - Gemfile.mongoid-2.4.12.lock
59
+ - Gemfile.mongoid-2.5.2
60
+ - Gemfile.mongoid-2.5.2.lock
61
+ - Gemfile.mongoid-2.6.0
62
+ - Gemfile.mongoid-2.6.0.lock
63
+ - Gemfile.mongoid-2.7.1
64
+ - Gemfile.mongoid-2.7.1.lock
65
+ - Gemfile.mongoid-2.8.1
66
+ - Gemfile.mongoid-2.8.1.lock
67
+ - Gemfile.mongoid-3.0.23
68
+ - Gemfile.mongoid-3.0.23.lock
69
+ - Gemfile.mongoid-3.1.5
70
+ - Gemfile.mongoid-3.1.5.lock
71
+ - Gemfile.mongoid.lock
41
72
  - Gemfile.rails-3.0.20
42
- - Gemfile.rails-3.1.11
43
- - Gemfile.rails-3.2.12
44
- - Gemfile.rails-4-beta
73
+ - Gemfile.rails-3.0.20.lock
74
+ - Gemfile.rails-3.1.12
75
+ - Gemfile.rails-3.1.12.lock
76
+ - Gemfile.rails-3.2.15
77
+ - Gemfile.rails-3.2.15.lock
78
+ - Gemfile.rails-4.0.1
79
+ - Gemfile.rails-4.0.1.lock
45
80
  - Guardfile
46
81
  - Hacking.md
47
82
  - MIT-LICENSE
@@ -63,6 +98,7 @@ files:
63
98
  - lib/bullet/ext/string.rb
64
99
  - lib/bullet/mongoid2x.rb
65
100
  - lib/bullet/mongoid3x.rb
101
+ - lib/bullet/mongoid4x.rb
66
102
  - lib/bullet/notification.rb
67
103
  - lib/bullet/notification/base.rb
68
104
  - lib/bullet/notification/counter_cache.rb
@@ -93,7 +129,8 @@ files:
93
129
  - spec/bullet/registry/association_spec.rb
94
130
  - spec/bullet/registry/base_spec.rb
95
131
  - spec/bullet/registry/object_spec.rb
96
- - spec/integration/association_spec.rb
132
+ - spec/integration/active_record3/association_spec.rb
133
+ - spec/integration/active_record4/association_spec.rb
97
134
  - spec/integration/counter_cache_spec.rb
98
135
  - spec/integration/mongoid/association_spec.rb
99
136
  - spec/models/address.rb
@@ -153,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
190
  version: 1.3.6
154
191
  requirements: []
155
192
  rubyforge_project:
156
- rubygems_version: 2.0.3
193
+ rubygems_version: 2.0.6
157
194
  signing_key:
158
195
  specification_version: 4
159
196
  summary: help to kill N+1 queries and unused eager loading.
@@ -174,7 +211,8 @@ test_files:
174
211
  - spec/bullet/registry/association_spec.rb
175
212
  - spec/bullet/registry/base_spec.rb
176
213
  - spec/bullet/registry/object_spec.rb
177
- - spec/integration/association_spec.rb
214
+ - spec/integration/active_record3/association_spec.rb
215
+ - spec/integration/active_record4/association_spec.rb
178
216
  - spec/integration/counter_cache_spec.rb
179
217
  - spec/integration/mongoid/association_spec.rb
180
218
  - spec/models/address.rb
data/.rvmrc DELETED
@@ -1,2 +0,0 @@
1
- rvm_gemset_create_on_use_flag=1
2
- rvm gemset use bullet
@@ -1,2 +0,0 @@
1
- rvm_gemset_create_on_use_flag=1
2
- rvm gemset use bullet
@@ -1,16 +0,0 @@
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', '3.1.11'
8
- gem 'sqlite3'
9
- gem 'mysql2'
10
- gem 'activerecord-import'
11
- gem 'mongoid', '2.4.12'
12
- gem 'bson_ext'
13
-
14
- gem "rspec"
15
- gem "guard"
16
- gem "guard-rspec"
@@ -1,16 +0,0 @@
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', '3.2.12'
8
- gem 'sqlite3'
9
- gem 'mysql2'
10
- gem 'activerecord-import'
11
- gem 'mongoid', '2.5.1'
12
- gem 'bson_ext'
13
-
14
- gem "rspec"
15
- gem "guard"
16
- gem "guard-rspec"
@@ -1,14 +0,0 @@
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', '4.0.0.beta1'
8
- gem 'sqlite3'
9
- gem 'mysql2'
10
- gem 'activerecord-import'
11
-
12
- gem "rspec"
13
- gem "guard"
14
- gem "guard-rspec"