bullet 5.1.1 → 5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0158f6af4990b365de2859cea97877e5b290ea83
4
- data.tar.gz: cd8914938d74645ae75d01ee8feaf23e38f8d028
3
+ metadata.gz: dbcef4cb1e9b0db722674cc600a456767eb5d2dd
4
+ data.tar.gz: 27107041da317defb0433329dc55375b305cc7b8
5
5
  SHA512:
6
- metadata.gz: 9e92c13202832afaaf604072c06e695cfe552d5626318d6c625cebacdfdc13ecc14aeed8c64d6df483b4c05caa090ecee01e613228dae6466edbe66803e7333a
7
- data.tar.gz: 7d365b32c075a00733e4c70daedcfbca042cb2334a77c6e132fc31b33e9dd23aaca8a65eaa1578ffba2f106303cf572e84e41b7fd6c7c61a239b2dbea9fcaabe
6
+ metadata.gz: ea8208a3a4f1a1ef3f4f247667f9485b951a00ba5036cc87b8049005813e8f7452a5d340c1fdb09ea525fd5996b0050587a758afc8ff2a421f93acb21424f605
7
+ data.tar.gz: 456466364914301c30c4622bba947888bd16d92dad0603759c8b1108c4bc11ed417a8fca5a8ee2c983f119fa16e587cc140498393d2ec31f1a79c410082f1874
data/.travis.yml CHANGED
@@ -5,7 +5,7 @@ rvm:
5
5
  - 2.0
6
6
  - 2.1
7
7
  - 2.2
8
- - 2.2.3
8
+ - 2.3.0
9
9
  gemfile:
10
10
  - Gemfile.rails-5.0
11
11
  - Gemfile.rails-4.2
@@ -63,14 +63,14 @@ matrix:
63
63
  gemfile: Gemfile.rails-3.0
64
64
  - rvm: 2.1
65
65
  gemfile: Gemfile.rails-5.0
66
- - rvm: 2.2
67
- gemfile: Gemfile.rails-5.0
68
66
  - rvm: 2.2
69
67
  gemfile: Gemfile.rails-3.0
70
68
  - rvm: 2.2
71
69
  gemfile: Gemfile.rails-3.1
72
70
  - rvm: 2.2
73
71
  gemfile: Gemfile.rails-3.2
72
+ - rvm: 2.2
73
+ gemfile: Gemfile.rails-5.0
74
74
  - rvm: 2.2
75
75
  gemfile: Gemfile.mongoid-3.1
76
76
  - rvm: 2.2
@@ -85,23 +85,23 @@ matrix:
85
85
  gemfile: Gemfile.mongoid-2.5
86
86
  - rvm: 2.2
87
87
  gemfile: Gemfile.mongoid-2.4
88
- - rvm: 2.2.3
88
+ - rvm: 2.3.0
89
89
  gemfile: Gemfile.rails-3.0
90
- - rvm: 2.2.3
90
+ - rvm: 2.3.0
91
91
  gemfile: Gemfile.rails-3.1
92
- - rvm: 2.2.3
92
+ - rvm: 2.3.0
93
93
  gemfile: Gemfile.rails-3.2
94
- - rvm: 2.2.3
94
+ - rvm: 2.3.0
95
95
  gemfile: Gemfile.mongoid-3.1
96
- - rvm: 2.2.3
96
+ - rvm: 2.3.0
97
97
  gemfile: Gemfile.mongoid-3.0
98
- - rvm: 2.2.3
98
+ - rvm: 2.3.0
99
99
  gemfile: Gemfile.mongoid-2.8
100
- - rvm: 2.2.3
100
+ - rvm: 2.3.0
101
101
  gemfile: Gemfile.mongoid-2.7
102
- - rvm: 2.2.3
102
+ - rvm: 2.3.0
103
103
  gemfile: Gemfile.mongoid-2.6
104
- - rvm: 2.2.3
104
+ - rvm: 2.3.0
105
105
  gemfile: Gemfile.mongoid-2.5
106
- - rvm: 2.2.3
106
+ - rvm: 2.3.0
107
107
  gemfile: Gemfile.mongoid-2.4
data/CHANGELOG.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # Next Release
2
2
 
3
- ## 5.1.1
3
+ ## 5.2.0 (07/26/2016)
4
4
 
5
5
  * Fix `has_cached_counter?` is not defined in HABTM #297
6
6
  * Fix false alert if preloaded association has no records #260
7
+ * Support Rails 5.0.0
7
8
 
8
9
  ## 5.1.0 (05/21/2016)
9
10
 
data/Gemfile.mongoid-2.4 CHANGED
@@ -9,8 +9,6 @@ gem 'mongoid', '~> 2.4.0'
9
9
 
10
10
  gem "rspec"
11
11
 
12
- gem 'coveralls', require: false
13
-
14
12
  platforms :rbx do
15
13
  gem 'rubysl', '~> 2.0'
16
14
  gem 'rubinius-developer_tools'
data/Gemfile.mongoid-2.5 CHANGED
@@ -9,8 +9,6 @@ gem 'mongoid', '~> 2.5.0'
9
9
 
10
10
  gem "rspec"
11
11
 
12
- gem 'coveralls', require: false
13
-
14
12
  platforms :rbx do
15
13
  gem 'rubysl', '~> 2.0'
16
14
  gem 'rubinius-developer_tools'
data/Gemfile.mongoid-2.6 CHANGED
@@ -9,8 +9,6 @@ gem 'mongoid', '~> 2.6.0'
9
9
 
10
10
  gem "rspec"
11
11
 
12
- gem 'coveralls', require: false
13
-
14
12
  platforms :rbx do
15
13
  gem 'rubysl', '~> 2.0'
16
14
  gem 'rubinius-developer_tools'
data/Gemfile.mongoid-2.7 CHANGED
@@ -9,8 +9,6 @@ gem 'mongoid', '~> 2.7.0'
9
9
 
10
10
  gem "rspec"
11
11
 
12
- gem 'coveralls', require: false
13
-
14
12
  platforms :rbx do
15
13
  gem 'rubysl', '~> 2.0'
16
14
  gem 'rubinius-developer_tools'
data/Gemfile.mongoid-2.8 CHANGED
@@ -9,8 +9,6 @@ gem 'mongoid', '~> 2.8.0'
9
9
 
10
10
  gem "rspec"
11
11
 
12
- gem 'coveralls', require: false
13
-
14
12
  platforms :rbx do
15
13
  gem 'rubysl', '~> 2.0'
16
14
  gem 'rubinius-developer_tools'
data/Gemfile.mongoid-3.0 CHANGED
@@ -9,8 +9,6 @@ gem 'mongoid', '~> 3.0.0'
9
9
 
10
10
  gem "rspec"
11
11
 
12
- gem 'coveralls', require: false
13
-
14
12
  platforms :rbx do
15
13
  gem 'rubysl', '~> 2.0'
16
14
  gem 'rubinius-developer_tools'
data/Gemfile.mongoid-3.1 CHANGED
@@ -9,8 +9,6 @@ gem 'mongoid', '~> 3.1.0'
9
9
 
10
10
  gem "rspec"
11
11
 
12
- gem 'coveralls', require: false
13
-
14
12
  platforms :rbx do
15
13
  gem 'rubysl', '~> 2.0'
16
14
  gem 'rubinius-developer_tools'
data/Gemfile.mongoid-4.0 CHANGED
@@ -9,8 +9,6 @@ gem 'mongoid', '~> 4.0.0'
9
9
 
10
10
  gem "rspec"
11
11
 
12
- gem 'coveralls', require: false
13
-
14
12
  platforms :rbx do
15
13
  gem 'rubysl', '~> 2.0'
16
14
  gem 'rubinius-developer_tools'
data/Gemfile.mongoid-5.0 CHANGED
@@ -9,8 +9,6 @@ gem 'mongoid', '~> 5.0.0'
9
9
 
10
10
  gem "rspec"
11
11
 
12
- gem 'coveralls', require: false
13
-
14
12
  platforms :rbx do
15
13
  gem 'rubysl', '~> 2.0'
16
14
  gem 'rubinius-developer_tools'
data/Gemfile.rails-3.0 CHANGED
@@ -10,8 +10,6 @@ gem 'tins', '~> 1.6.0', platforms: [:ruby_19]
10
10
 
11
11
  gem "rspec"
12
12
 
13
- gem 'coveralls', require: false
14
-
15
13
  platforms :rbx do
16
14
  gem 'rubysl', '~> 2.0'
17
15
  gem 'rubinius-developer_tools'
data/Gemfile.rails-3.1 CHANGED
@@ -10,8 +10,6 @@ gem 'tins', '~> 1.6.0', platforms: [:ruby_19]
10
10
 
11
11
  gem "rspec"
12
12
 
13
- gem 'coveralls', require: false
14
-
15
13
  platforms :rbx do
16
14
  gem 'rubysl', '~> 2.0'
17
15
  gem 'rubinius-developer_tools'
data/Gemfile.rails-3.2 CHANGED
@@ -10,8 +10,6 @@ gem 'tins', '~> 1.6.0', platforms: [:ruby_19]
10
10
 
11
11
  gem "rspec"
12
12
 
13
- gem 'coveralls', require: false
14
-
15
13
  platforms :rbx do
16
14
  gem 'rubysl', '~> 2.0'
17
15
  gem 'rubinius-developer_tools'
data/Gemfile.rails-4.0 CHANGED
@@ -10,8 +10,6 @@ gem 'tins', '~> 1.6.0', platforms: [:ruby_19]
10
10
 
11
11
  gem "rspec"
12
12
 
13
- gem 'coveralls', require: false
14
-
15
13
  platforms :rbx do
16
14
  gem 'rubysl', '~> 2.0'
17
15
  gem 'rubinius-developer_tools'
data/Gemfile.rails-4.1 CHANGED
@@ -10,8 +10,6 @@ gem 'tins', '~> 1.6.0', platforms: [:ruby_19]
10
10
 
11
11
  gem "rspec"
12
12
 
13
- gem 'coveralls', require: false
14
-
15
13
  platforms :rbx do
16
14
  gem 'rubysl', '~> 2.0'
17
15
  gem 'rubinius-developer_tools'
data/Gemfile.rails-4.2 CHANGED
@@ -10,8 +10,6 @@ gem 'tins', '~> 1.6.0', platforms: [:ruby_19]
10
10
 
11
11
  gem "rspec"
12
12
 
13
- gem 'coveralls', require: false
14
-
15
13
  platforms :rbx do
16
14
  gem 'rubysl', '~> 2.0'
17
15
  gem 'rubinius-developer_tools'
data/Gemfile.rails-5.0 CHANGED
@@ -2,15 +2,13 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rails', '5.0.0.beta1'
5
+ gem 'rails', '5.0.0'
6
6
  gem 'sqlite3'
7
7
  gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
9
9
 
10
10
  gem "rspec"
11
11
 
12
- gem 'coveralls', require: false
13
-
14
12
  platforms :rbx do
15
13
  gem 'rubysl', '~> 2.0'
16
14
  gem 'rubinius-developer_tools'
data/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/bullet.png)](http://badge.fury.io/rb/bullet)
4
4
  [![Build Status](https://secure.travis-ci.org/flyerhzm/bullet.png)](http://travis-ci.org/flyerhzm/bullet)
5
- [![Coverage Status](https://coveralls.io/repos/flyerhzm/bullet/badge.png?branch=master)](https://coveralls.io/r/flyerhzm/bullet)
6
5
  <a href="https://codeclimate.com/github/flyerhzm/bullet"><img src="https://codeclimate.com/github/flyerhzm/bullet.png" /></a>
7
6
  [![Coderwall Endorse](http://api.coderwall.com/flyerhzm/endorsecount.png)](http://coderwall.com/flyerhzm)
8
7
 
@@ -63,7 +62,7 @@ config.after_initialize do
63
62
  Bullet.add_footer = true
64
63
  Bullet.stacktrace_includes = [ 'your_gem', 'your_middleware' ]
65
64
  Bullet.stacktrace_excludes = [ 'their_gem', 'their_middleware' ]
66
- Bullet.slack = { webhook_url: 'http://some.slack.url', foo: 'bar' }
65
+ Bullet.slack = { webhook_url: 'http://some.slack.url', channel: '#default', username: 'notifier' }
67
66
  end
68
67
  ```
69
68
 
@@ -40,38 +40,30 @@ module Bullet
40
40
  ::ActiveRecord::Base.prepend(SaveWithBulletSupport)
41
41
 
42
42
  ::ActiveRecord::Relation.class_eval do
43
- alias_method :origin_to_a, :to_a
43
+ alias_method :origin_records, :records
44
44
  # if select a collection of objects, then these objects have possible to cause N+1 query.
45
45
  # if select only one object, then the only one object has impossible to cause N+1 query.
46
- def to_a
47
- records = origin_to_a
46
+ def records
47
+ result = origin_records
48
48
  if Bullet.start?
49
- if records.first.class.name !~ /^HABTM_/
50
- if records.size > 1
51
- Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
52
- Bullet::Detector::CounterCache.add_possible_objects(records)
53
- elsif records.size == 1
54
- Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
55
- Bullet::Detector::CounterCache.add_impossible_object(records.first)
49
+ if result.first.class.name !~ /^HABTM_/
50
+ if result.size > 1
51
+ Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
52
+ Bullet::Detector::CounterCache.add_possible_objects(result)
53
+ elsif result.size == 1
54
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(result.first)
55
+ Bullet::Detector::CounterCache.add_impossible_object(result.first)
56
56
  end
57
57
  end
58
58
  end
59
- records
60
- end
61
- end
62
-
63
- ::ActiveRecord::Associations::Association.class_eval do
64
- alias_method :origin_initialize, :initialize
65
- def initialize(owner, reflection)
66
- origin_initialize(owner, reflection)
67
- reflection.set_owner owner
59
+ result
68
60
  end
69
61
  end
70
62
 
71
63
  ::ActiveRecord::Associations::Preloader.class_eval do
72
- alias_method :origin_preloaders_on, :preloaders_on
64
+ alias_method :origin_preloaders_for_one, :preloaders_for_one
73
65
 
74
- def preloaders_on(association, records, scope)
66
+ def preloaders_for_one(association, records, scope)
75
67
  if Bullet.start?
76
68
  records.compact!
77
69
  if records.first.class.name !~ /^HABTM_/
@@ -81,7 +73,7 @@ module Bullet
81
73
  Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, association)
82
74
  end
83
75
  end
84
- origin_preloaders_on(association, records, scope)
76
+ origin_preloaders_for_one(association, records, scope)
85
77
  end
86
78
  end
87
79
 
@@ -144,7 +136,14 @@ module Bullet
144
136
 
145
137
  if Bullet.start?
146
138
  if records.size > 1
147
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
139
+ if self.is_a? ::ActiveRecord::Associations::ThroughAssociation
140
+ Bullet::Detector::NPlusOneQuery.call_association(owner, through_reflection.name)
141
+ association = self.owner.association self.through_reflection.name
142
+ association.target.each do |through_record|
143
+ Bullet::Detector::NPlusOneQuery.call_association(through_record, source_reflection.name)
144
+ end
145
+ end
146
+ Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name) unless @inversed
148
147
  end
149
148
  if records.first.class.name !~ /^HABTM_/
150
149
  if records.size > 1
@@ -161,8 +160,8 @@ module Bullet
161
160
 
162
161
  alias_method :origin_empty?, :empty?
163
162
  def empty?
164
- if Bullet.start? && !@reflection.has_cached_counter?
165
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
163
+ if Bullet.start? && !reflection.has_cached_counter?
164
+ Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name)
166
165
  end
167
166
  origin_empty?
168
167
  end
@@ -170,7 +169,7 @@ module Bullet
170
169
  alias_method :origin_include?, :include?
171
170
  def include?(object)
172
171
  if Bullet.start?
173
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
172
+ Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name)
174
173
  end
175
174
  origin_include?(object)
176
175
  end
@@ -182,9 +181,9 @@ module Bullet
182
181
  def reader(force_reload = false)
183
182
  result = origin_reader(force_reload)
184
183
  if Bullet.start?
185
- if @owner.class.name !~ /^HABTM_/ && !@inversed
186
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
187
- if Bullet::Detector::NPlusOneQuery.impossible?(@owner)
184
+ if owner.class.name !~ /^HABTM_/ && !@inversed
185
+ Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name)
186
+ if Bullet::Detector::NPlusOneQuery.impossible?(owner)
188
187
  Bullet::Detector::NPlusOneQuery.add_impossible_object(result) if result
189
188
  else
190
189
  Bullet::Detector::NPlusOneQuery.add_possible_objects(result) if result
@@ -198,28 +197,20 @@ module Bullet
198
197
  ::ActiveRecord::Associations::HasManyAssociation.class_eval do
199
198
  alias_method :origin_many_empty?, :empty?
200
199
  def empty?
201
- Thread.current[:bullet_collection_empty] = true
202
200
  result = origin_many_empty?
203
- Thread.current[:bullet_collection_empty] = nil
204
- if Bullet.start? && !@reflection.has_cached_counter?
205
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
201
+ if Bullet.start? && !reflection.has_cached_counter?
202
+ Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name)
206
203
  end
207
204
  result
208
205
  end
209
- end
210
-
211
- ::ActiveRecord::Reflection::AbstractReflection.class_eval do
212
- def set_owner(owner)
213
- @owner = owner
214
- end
215
206
 
216
- alias_method :origin_has_cached_counter?, :has_cached_counter?
217
- def has_cached_counter?
218
- result = origin_has_cached_counter?
219
- if Bullet.start? && !result && !Thread.current[:bullet_collection_empty]
220
- Bullet::Detector::CounterCache.add_counter_cache(@owner, @name)
207
+ alias_method :origin_count_records, :count_records
208
+ def count_records
209
+ result = reflection.has_cached_counter?
210
+ if Bullet.start? && !result && !self.is_a?(::ActiveRecord::Associations::ThroughAssociation)
211
+ Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name)
221
212
  end
222
- result
213
+ origin_count_records
223
214
  end
224
215
  end
225
216
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Bullet
3
- VERSION = "5.1.1"
3
+ VERSION = "5.2.0"
4
4
  end
data/spec/spec_helper.rb CHANGED
@@ -30,9 +30,6 @@ $LOAD_PATH.unshift(MODELS)
30
30
  SUPPORT = File.join(File.dirname(__FILE__), "support")
31
31
  Dir[ File.join(SUPPORT, "*.rb") ].reject { |filename| filename =~ /_seed.rb$/ }.sort.each { |file| require file }
32
32
 
33
- require 'coveralls'
34
- Coveralls.wear!
35
-
36
33
  RSpec.configure do |config|
37
34
  config.extend Bullet::Dependency
38
35
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bullet
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.1
4
+ version: 5.2.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: 2016-06-30 00:00:00.000000000 Z
11
+ date: 2016-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport