bullet 5.7.6 → 5.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b32f7ec78bd32da2e77680a04a02aefb3cd6615f
4
- data.tar.gz: d946cc0ded11f343b047bb16145cc72c703d15c9
3
+ metadata.gz: 0b65855ae5365567a18d1fb6ffdee5046b8cec35
4
+ data.tar.gz: 8df6b7afd18400dd2fe9bf39ec4a537fa04228af
5
5
  SHA512:
6
- metadata.gz: 9c27d586ccdee749e304f57df64c7c17cc77ea88689d5e60b4ae53d19cf25447fe9758fc8c968ca0016a1bb8c5068af1cefd6a76bf07725bcb7c0ffc099ca345
7
- data.tar.gz: a864ff44451a06069e812bab6b41826cef78ceed6e25949fd630a0399271d7fb3b25e2b43b619ea74956f7ec58c5886045e5766f7ec9efb8e5f2f2e0c197acac
6
+ metadata.gz: 212cf02f1520dfaf752f794e42e9b2611fa0eca8b786bf5ef281c36c416ddf24016a524029614447c6241ebb734a2491ab554fa505544d7a7bc6f2e5b767527d
7
+ data.tar.gz: d2d71ceb54033f58cb6d675ea88268f130a0ea8bcfd7b4987486e374a2d2a3fc9169691ff20a9ca0fd9cf2787656dacc19649a8473879e9d1d68484597ccc18b
@@ -1,33 +1,19 @@
1
1
  ## Next Release
2
2
 
3
- ## 5.7.6 (08/15/2018)
3
+ ## 5.8.0 (10/29/2018)
4
4
 
5
- * Extend stacktrace matching for sub-file precision
6
- * Fix false positive in after_save/_create callbacks
5
+ * Fix through reflection for rails 5.x
6
+ * Fix false positive in after_save/after_create callbacks
7
7
  * Don't triger a preload error on "manual" preloads
8
-
9
- ## 5.7.5 (03/12/2018)
10
-
11
- * Fix duplicate logs in mongoid 4.x and 5.x version
12
- * Add magic comment frozen_string_literal: true
13
-
14
- ## 5.7.4 (03/10/2018)
15
-
16
8
  * Avoid Bullet from making extra queries in mongoid6
9
+ * Support option for #first and #last on mongoid6.x
10
+ * Fix duplicate logs in mongoid 4.x and 5.x version
17
11
  * Use caller for ruby 1.9 while caller_locations for 2.0+
18
-
19
- ## 5.7.3 (02/17/2018)
20
-
12
+ * Extend stacktrace matching for sub-file precision
21
13
  * Exclude configured bundler path in addition to '/vendor'
22
- * Support rails 5.1.5
23
-
24
- ## 5.7.2 (01/18/2018)
25
-
26
14
  * Fix `caller_path` in `excluded_stacktrace_path`
27
-
28
- ## 5.7.1 (07/01/2017)
29
-
30
15
  * Update `uniform_notifier` dependency to add Sentry support
16
+ * Integrate awesomecode.io and refactor code
31
17
 
32
18
  ## 5.7.0 (12/03/2017)
33
19
 
@@ -2,7 +2,7 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rails', '~> 5.2.0.beta2'
5
+ gem 'rails', '~> 5.2.0'
6
6
  gem 'sqlite3'
7
7
  gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
data/README.md CHANGED
@@ -2,7 +2,7 @@
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
- [![AwesomeCode Status](https://awesomecode.io/projects/6755235b-e2c1-459e-bf92-b8b13d0c0472/status)](https://awesomecode.io/projects/2)
5
+ [![AwesomeCode Status for flyerhzm/bullet](https://awesomecode.io/projects/6755235b-e2c1-459e-bf92-b8b13d0c0472/status)](https://awesomecode.io/repos/flyerhzm/bullet)
6
6
  [![Coderwall Endorse](http://api.coderwall.com/flyerhzm/endorsecount.png)](http://coderwall.com/flyerhzm)
7
7
 
8
8
  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.
@@ -128,7 +128,7 @@ class ApplicationController < ActionController::Base
128
128
  around_action :skip_bullet
129
129
 
130
130
  def skip_bullet
131
- previous_value = Bullet.enabled?
131
+ previous_value = Bullet.enable?
132
132
  Bullet.enable = false
133
133
  yield
134
134
  ensure
@@ -14,13 +14,17 @@ Gem::Specification.new do |s|
14
14
  s.homepage = 'https://github.com/flyerhzm/bullet'
15
15
  s.summary = 'help to kill N+1 queries and unused eager loading.'
16
16
  s.description = 'help to kill N+1 queries and unused eager loading.'
17
+ s.metadata = {
18
+ 'changelog_uri' => 'https://github.com/flyerhzm/bullet/blob/master/CHANGELOG.md',
19
+ 'source_code_uri' => 'https://github.com/flyerhzm/bullet'
20
+ }
17
21
 
18
- s.license = 'MIT'
22
+ s.license = 'MIT'
19
23
 
20
24
  s.required_rubygems_version = '>= 1.3.6'
21
25
 
22
26
  s.add_runtime_dependency 'activesupport', '>= 3.0.0'
23
- s.add_runtime_dependency 'uniform_notifier', '~> 1.11.0'
27
+ s.add_runtime_dependency 'uniform_notifier', '~> 1.11'
24
28
 
25
29
  s.files = `git ls-files`.split("\n")
26
30
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -19,8 +19,8 @@ module Bullet
19
19
  autoload :Registry, 'bullet/registry'
20
20
  autoload :NotificationCollector, 'bullet/notification_collector'
21
21
 
22
- BULLET_DEBUG = 'BULLET_DEBUG'.freeze
23
- TRUE = 'true'.freeze
22
+ BULLET_DEBUG = 'BULLET_DEBUG'
23
+ TRUE = 'true'
24
24
 
25
25
  if defined? Rails::Railtie
26
26
  class BulletRailtie < Rails::Railtie
@@ -163,6 +163,7 @@ module Bullet
163
163
 
164
164
  def notification?
165
165
  return unless start?
166
+
166
167
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
167
168
  notification_collector.notifications_present?
168
169
  end
@@ -65,6 +65,7 @@ module Bullet
65
65
  if Bullet.start?
66
66
  records = [records].flatten.compact.uniq
67
67
  return if records.empty?
68
+
68
69
  records.each do |record|
69
70
  Bullet::Detector::Association.add_object_associations(record, associations)
70
71
  end
@@ -80,6 +80,7 @@ module Bullet
80
80
  alias_method :origin_find_with_associations, :find_with_associations
81
81
  def find_with_associations
82
82
  return origin_find_with_associations { |r| yield r } if block_given?
83
+
83
84
  records = origin_find_with_associations
84
85
  if Bullet.start?
85
86
  associations = (eager_load_values + includes_values).uniq
@@ -95,6 +95,7 @@ module Bullet
95
95
  alias_method :origin_find_with_associations, :find_with_associations
96
96
  def find_with_associations
97
97
  return origin_find_with_associations { |r| yield r } if block_given?
98
+
98
99
  records = origin_find_with_associations
99
100
  if Bullet.start?
100
101
  associations = (eager_load_values + includes_values).uniq
@@ -132,6 +133,7 @@ module Bullet
132
133
  key = aliases.column_alias(node, node.primary_key)
133
134
  id = row[key]
134
135
  next unless id.nil?
136
+
135
137
  associations = node.reflection.name
136
138
  Bullet::Detector::Association.add_object_associations(ar_parent, associations)
137
139
  Bullet::Detector::NPlusOneQuery.call_association(ar_parent, associations)
@@ -75,6 +75,7 @@ module Bullet
75
75
  # add includes in scope
76
76
  def find_with_associations
77
77
  return super { |r| yield r } if block_given?
78
+
78
79
  records = super
79
80
  if Bullet.start?
80
81
  associations = (eager_load_values + includes_values).uniq
@@ -125,6 +126,7 @@ module Bullet
125
126
  key = aliases.column_alias(node, node.primary_key)
126
127
  id = row[key]
127
128
  next unless id.nil?
129
+
128
130
  associations = node.reflection.name
129
131
  Bullet::Detector::Association.add_object_associations(ar_parent, associations)
130
132
  Bullet::Detector::NPlusOneQuery.call_association(ar_parent, associations)
@@ -161,11 +163,20 @@ module Bullet
161
163
 
162
164
  if Bullet.start?
163
165
  if is_a? ::ActiveRecord::Associations::ThroughAssociation
164
- Bullet::Detector::NPlusOneQuery.call_association(owner, through_reflection.name)
165
- association = owner.association through_reflection.name
166
+ refl = reflection.through_reflection
167
+ Bullet::Detector::NPlusOneQuery.call_association(owner, refl.name)
168
+ association = owner.association refl.name
166
169
  Array(association.target).each do |through_record|
167
170
  Bullet::Detector::NPlusOneQuery.call_association(through_record, source_reflection.name)
168
171
  end
172
+
173
+ if refl.through_reflection?
174
+ while refl.through_reflection?
175
+ refl = refl.through_reflection
176
+ end
177
+
178
+ Bullet::Detector::NPlusOneQuery.call_association(owner, refl.name)
179
+ end
169
180
  end
170
181
  Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name) unless @inversed
171
182
  if records.first.class.name !~ /^HABTM_/
@@ -75,6 +75,7 @@ module Bullet
75
75
  # add includes in scope
76
76
  def find_with_associations
77
77
  return super { |r| yield r } if block_given?
78
+
78
79
  records = super
79
80
  if Bullet.start?
80
81
  associations = (eager_load_values + includes_values).uniq
@@ -108,6 +109,7 @@ module Bullet
108
109
  key = aliases.column_alias(node, node.primary_key)
109
110
  id = row[key]
110
111
  next unless id.nil?
112
+
111
113
  associations = node.reflection.name
112
114
  Bullet::Detector::Association.add_object_associations(ar_parent, associations)
113
115
  Bullet::Detector::NPlusOneQuery.call_association(ar_parent, associations)
@@ -144,11 +146,15 @@ module Bullet
144
146
 
145
147
  if Bullet.start?
146
148
  if is_a? ::ActiveRecord::Associations::ThroughAssociation
147
- Bullet::Detector::NPlusOneQuery.call_association(owner, through_reflection.name)
148
- association = owner.association through_reflection.name
149
+ Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.through_reflection.name)
150
+ association = owner.association reflection.through_reflection.name
149
151
  Array(association.target).each do |through_record|
150
152
  Bullet::Detector::NPlusOneQuery.call_association(through_record, source_reflection.name)
151
153
  end
154
+
155
+ if reflection.through_reflection != through_reflection
156
+ Bullet::Detector::NPlusOneQuery.call_association(owner, through_reflection.name)
157
+ end
152
158
  end
153
159
  Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.name) unless @inversed
154
160
  if records.first.class.name !~ /^HABTM_/
@@ -9,7 +9,7 @@ module Bullet
9
9
  return if !Bullet.n_plus_one_query_enable? && !Bullet.unused_eager_loading_enable?
10
10
  return unless object.primary_key_value
11
11
 
12
- Bullet.debug('Detector::Association#add_object_associations'.freeze, "object: #{object.bullet_key}, associations: #{associations}")
12
+ Bullet.debug('Detector::Association#add_object_associations', "object: #{object.bullet_key}, associations: #{associations}")
13
13
  object_associations.add(object.bullet_key, associations)
14
14
  end
15
15
 
@@ -18,7 +18,7 @@ module Bullet
18
18
  return if !Bullet.n_plus_one_query_enable? && !Bullet.unused_eager_loading_enable?
19
19
  return unless object.primary_key_value
20
20
 
21
- Bullet.debug('Detector::Association#add_call_object_associations'.freeze, "object: #{object.bullet_key}, associations: #{associations}")
21
+ Bullet.debug('Detector::Association#add_call_object_associations', "object: #{object.bullet_key}, associations: #{associations}")
22
22
  call_object_associations.add(object.bullet_key, associations)
23
23
  end
24
24
 
@@ -18,6 +18,7 @@ module Bullet
18
18
  def add_possible_objects(object_or_objects)
19
19
  return unless Bullet.start?
20
20
  return unless Bullet.counter_cache_enable?
21
+
21
22
  objects = Array(object_or_objects)
22
23
  return if objects.map(&:primary_key_value).compact.empty?
23
24
 
@@ -16,9 +16,10 @@ module Bullet
16
16
  return unless Bullet.n_plus_one_query_enable?
17
17
  return unless object.primary_key_value
18
18
  return if inversed_objects.include?(object.bullet_key, associations)
19
+
19
20
  add_call_object_associations(object, associations)
20
21
 
21
- Bullet.debug('Detector::NPlusOneQuery#call_association'.freeze, "object: #{object.bullet_key}, associations: #{associations}")
22
+ Bullet.debug('Detector::NPlusOneQuery#call_association', "object: #{object.bullet_key}, associations: #{associations}")
22
23
  if !excluded_stacktrace_path? && conditions_met?(object, associations)
23
24
  Bullet.debug('detect n + 1 query', "object: #{object.bullet_key}, associations: #{associations}")
24
25
  create_notification caller_in_project, object.class.to_s, associations
@@ -28,10 +29,11 @@ module Bullet
28
29
  def add_possible_objects(object_or_objects)
29
30
  return unless Bullet.start?
30
31
  return unless Bullet.n_plus_one_query_enable?
32
+
31
33
  objects = Array(object_or_objects)
32
34
  return if objects.map(&:primary_key_value).compact.empty?
33
35
 
34
- Bullet.debug('Detector::NPlusOneQuery#add_possible_objects'.freeze, "objects: #{objects.map(&:bullet_key).join(', '.freeze)}")
36
+ Bullet.debug('Detector::NPlusOneQuery#add_possible_objects', "objects: #{objects.map(&:bullet_key).join(', ')}")
35
37
  objects.each { |object| possible_objects.add object.bullet_key }
36
38
  end
37
39
 
@@ -40,7 +42,7 @@ module Bullet
40
42
  return unless Bullet.n_plus_one_query_enable?
41
43
  return unless object.primary_key_value
42
44
 
43
- Bullet.debug('Detector::NPlusOneQuery#add_impossible_object'.freeze, "object: #{object.bullet_key}")
45
+ Bullet.debug('Detector::NPlusOneQuery#add_impossible_object', "object: #{object.bullet_key}")
44
46
  impossible_objects.add object.bullet_key
45
47
  end
46
48
 
@@ -49,7 +51,7 @@ module Bullet
49
51
  return unless Bullet.n_plus_one_query_enable?
50
52
  return unless object.primary_key_value
51
53
 
52
- Bullet.debug('Detector::NPlusOneQuery#add_inversed_object'.freeze, "object: #{object.bullet_key}, association: #{association}")
54
+ Bullet.debug('Detector::NPlusOneQuery#add_inversed_object', "object: #{object.bullet_key}, association: #{association}")
53
55
  inversed_objects.add object.bullet_key, association
54
56
  end
55
57
 
@@ -69,14 +71,12 @@ module Bullet
69
71
  # check if object => associations already exists in object_associations.
70
72
  def association?(object, associations)
71
73
  value = object_associations[object.bullet_key]
72
- if value
73
- value.each do |v|
74
+ value&.each do |v|
74
75
  # associations == v comparison order is important here because
75
76
  # v variable might be a squeel node where :== method is redefined,
76
77
  # so it does not compare values at all and return unexpected results
77
- result = v.is_a?(Hash) ? v.key?(associations) : associations == v
78
- return true if result
79
- end
78
+ result = v.is_a?(Hash) ? v.key?(associations) : associations == v
79
+ return true if result
80
80
  end
81
81
 
82
82
  false
@@ -75,6 +75,7 @@ module Bullet
75
75
  eager_loadings.similarly_associated(bullet_key, associations).each do |related_bullet_key|
76
76
  coa = call_object_associations[related_bullet_key]
77
77
  next if coa.nil?
78
+
78
79
  all.merge coa
79
80
  end
80
81
  all.to_a
@@ -7,7 +7,7 @@ class Object
7
7
 
8
8
  def primary_key_value
9
9
  if self.class.respond_to?(:primary_keys) && self.class.primary_keys
10
- self.class.primary_keys.map { |primary_key| send primary_key }.join(','.freeze)
10
+ self.class.primary_keys.map { |primary_key| send primary_key }.join(',')
11
11
  elsif self.class.respond_to?(:primary_key) && self.class.primary_key
12
12
  send self.class.primary_key
13
13
  else
@@ -2,6 +2,6 @@
2
2
 
3
3
  class String
4
4
  def bullet_class_name
5
- sub(/:[^:]*?$/, ''.freeze)
5
+ sub(/:[^:]*?$/, '')
6
6
  end
7
7
  end
@@ -24,6 +24,7 @@ module Bullet
24
24
 
25
25
  def each(&block)
26
26
  return to_enum unless block_given?
27
+
27
28
  records = []
28
29
  origin_each { |record| records << record }
29
30
  if records.length > 1
@@ -24,6 +24,7 @@ module Bullet
24
24
 
25
25
  def each(&block)
26
26
  return to_enum unless block_given?
27
+
27
28
  records = []
28
29
  origin_each { |record| records << record }
29
30
  if records.length > 1
@@ -10,20 +10,21 @@ module Bullet
10
10
  alias_method :origin_each, :each
11
11
  alias_method :origin_eager_load, :eager_load
12
12
 
13
- def first
14
- result = origin_first
13
+ def first(opt = {})
14
+ result = origin_first(opt)
15
15
  Bullet::Detector::NPlusOneQuery.add_impossible_object(result) if result
16
16
  result
17
17
  end
18
18
 
19
- def last
20
- result = origin_last
19
+ def last(opt = {})
20
+ result = origin_last(opt)
21
21
  Bullet::Detector::NPlusOneQuery.add_impossible_object(result) if result
22
22
  result
23
23
  end
24
24
 
25
25
  def each(&block)
26
26
  return to_enum unless block_given?
27
+
27
28
  records = []
28
29
  origin_each { |record| records << record }
29
30
  if records.length > 1
@@ -73,7 +73,7 @@ module Bullet
73
73
  protected
74
74
 
75
75
  def klazz_associations_str
76
- " #{@base_class} => [#{@associations.map(&:inspect).join(', '.freeze)}]"
76
+ " #{@base_class} => [#{@associations.map(&:inspect).join(', ')}]"
77
77
  end
78
78
 
79
79
  def associations_str
@@ -10,6 +10,7 @@ module Bullet
10
10
 
11
11
  def call(env)
12
12
  return @app.call(env) unless Bullet.enable?
13
+
13
14
  Bullet.start_request
14
15
  status, headers, response = @app.call(env)
15
16
 
@@ -66,7 +67,7 @@ module Bullet
66
67
  end
67
68
 
68
69
  def html_request?(headers, response)
69
- headers['Content-Type'] && headers['Content-Type'].include?('text/html') && response_body(response).include?('<html')
70
+ headers['Content-Type']&.include?('text/html') && response_body(response).include?('<html')
70
71
  end
71
72
 
72
73
  def response_body(response)
@@ -80,13 +81,13 @@ module Bullet
80
81
  private
81
82
 
82
83
  def footer_div_attributes
83
- <<EOF
84
- data-is-bullet-footer ondblclick="this.parentNode.removeChild(this);" style="position: fixed; bottom: 0pt; left: 0pt; cursor: pointer; border-style: solid; border-color: rgb(153, 153, 153);
85
- -moz-border-top-colors: none; -moz-border-right-colors: none; -moz-border-bottom-colors: none;
86
- -moz-border-left-colors: none; -moz-border-image: none; border-width: 2pt 2pt 0px 0px;
87
- padding: 3px 5px; border-radius: 0pt 10pt 0pt 0px; background: none repeat scroll 0% 0% rgba(200, 200, 200, 0.8);
88
- color: rgb(119, 119, 119); font-size: 16px; font-family: 'Arial', sans-serif; z-index:9999;"
89
- EOF
84
+ <<~EOF
85
+ data-is-bullet-footer ondblclick="this.parentNode.removeChild(this);" style="position: fixed; bottom: 0pt; left: 0pt; cursor: pointer; border-style: solid; border-color: rgb(153, 153, 153);
86
+ -moz-border-top-colors: none; -moz-border-right-colors: none; -moz-border-bottom-colors: none;
87
+ -moz-border-left-colors: none; -moz-border-image: none; border-width: 2pt 2pt 0px 0px;
88
+ padding: 3px 5px; border-radius: 0pt 10pt 0pt 0px; background: none repeat scroll 0% 0% rgba(200, 200, 200, 0.8);
89
+ color: rgb(119, 119, 119); font-size: 16px; font-family: 'Arial', sans-serif; z-index:9999;"
90
+ EOF
90
91
  end
91
92
 
92
93
  def footer_close_button
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Bullet
4
4
  module StackTraceFilter
5
- VENDOR_PATH = '/vendor'.freeze
5
+ VENDOR_PATH = '/vendor'
6
6
 
7
7
  def caller_in_project
8
8
  app_root = rails? ? Rails.root.to_s : Dir.pwd
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bullet
4
- VERSION = '5.7.6'.freeze
4
+ VERSION = '5.8.0'
5
5
  end
@@ -3,9 +3,9 @@
3
3
  module Bullet
4
4
  module Generators
5
5
  class InstallGenerator < ::Rails::Generators::Base
6
- desc <<-DESC
7
- Description:
8
- Enable bullet in development/test for your application.
6
+ desc <<~DESC
7
+ Description:
8
+ Enable bullet in development/test for your application.
9
9
  DESC
10
10
 
11
11
  def enable_in_development
@@ -226,7 +226,7 @@ if active_record?
226
226
  context 'post => comment' do
227
227
  it 'should detect unused preload with post => comments' do
228
228
  Post.includes(:comments).each do |post|
229
- post.comments.first.name if post.comments.first
229
+ post.comments.first&.name
230
230
  end
231
231
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
232
232
  expect(Bullet::Detector::Association).not_to be_unused_preload_associations_for(Post, :comments)
@@ -550,6 +550,44 @@ if active_record?
550
550
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
551
551
  end
552
552
  end
553
+
554
+ context 'firm => clients => groups' do
555
+ it 'should detect non preload associations' do
556
+ Firm.all.each do |firm|
557
+ firm.groups.map(&:name)
558
+ end
559
+ Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
560
+ expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
561
+
562
+ expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Firm, :groups)
563
+ end
564
+
565
+ it 'should detect preload associations' do
566
+ Firm.includes(:groups).each do |firm|
567
+ firm.groups.map(&:name)
568
+ end
569
+ Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
570
+ expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
571
+
572
+ expect(Bullet::Detector::Association).to be_completely_preloading_associations
573
+ end
574
+
575
+ it 'should not detect preload associations' do
576
+ Firm.all.map(&:name)
577
+ Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
578
+ expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
579
+
580
+ expect(Bullet::Detector::Association).to be_completely_preloading_associations
581
+ end
582
+
583
+ it 'should detect unused preload associations' do
584
+ Firm.includes(:groups).map(&:name)
585
+ Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
586
+ expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Firm, :groups)
587
+
588
+ expect(Bullet::Detector::Association).to be_completely_preloading_associations
589
+ end
590
+ end
553
591
  end
554
592
 
555
593
  describe Bullet::Detector::Association, 'has_one' do
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Client < ActiveRecord::Base
4
+ belongs_to :group
5
+
4
6
  has_many :relationships
5
7
  has_many :firms, through: :relationships
6
8
  end
@@ -3,4 +3,5 @@
3
3
  class Firm < ActiveRecord::Base
4
4
  has_many :relationships
5
5
  has_many :clients, through: :relationships
6
+ has_many :groups, through: :clients
6
7
  end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Group < ActiveRecord::Base
4
+ end
@@ -45,8 +45,10 @@ module Support
45
45
 
46
46
  firm1 = Firm.create(name: 'first')
47
47
  firm2 = Firm.create(name: 'second')
48
- client1 = Client.create(name: 'first')
49
- client2 = Client.create(name: 'second')
48
+ group1 = Group.create(name: 'first')
49
+ group2 = Group.create(name: 'second')
50
+ client1 = Client.create(name: 'first', group: group1)
51
+ client2 = Client.create(name: 'second', group: group2)
50
52
  firm1.clients = [client1, client2]
51
53
  firm2.clients = [client1, client2]
52
54
  client1.firms << firm1
@@ -125,6 +127,7 @@ module Support
125
127
 
126
128
  create_table :clients do |t|
127
129
  t.column :name, :string
130
+ t.column :group_id, :integer
128
131
  end
129
132
 
130
133
  create_table :comments do |t|
@@ -171,6 +174,10 @@ module Support
171
174
  t.column :name, :string
172
175
  end
173
176
 
177
+ create_table :groups do |t|
178
+ t.column :name, :string
179
+ end
180
+
174
181
  create_table :hotels do |t|
175
182
  t.column :name, :string
176
183
  t.column :location_id, :integer
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.7.6
4
+ version: 5.8.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: 2018-08-15 00:00:00.000000000 Z
11
+ date: 2018-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.11.0
33
+ version: '1.11'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.11.0
40
+ version: '1.11'
41
41
  description: help to kill N+1 queries and unused eager loading.
42
42
  email:
43
43
  - flyerhzm@gmail.com
@@ -133,6 +133,7 @@ files:
133
133
  - spec/models/entry.rb
134
134
  - spec/models/firm.rb
135
135
  - spec/models/folder.rb
136
+ - spec/models/group.rb
136
137
  - spec/models/mongoid/address.rb
137
138
  - spec/models/mongoid/category.rb
138
139
  - spec/models/mongoid/comment.rb
@@ -163,7 +164,9 @@ files:
163
164
  homepage: https://github.com/flyerhzm/bullet
164
165
  licenses:
165
166
  - MIT
166
- metadata: {}
167
+ metadata:
168
+ changelog_uri: https://github.com/flyerhzm/bullet/blob/master/CHANGELOG.md
169
+ source_code_uri: https://github.com/flyerhzm/bullet
167
170
  post_install_message:
168
171
  rdoc_options: []
169
172
  require_paths:
@@ -218,6 +221,7 @@ test_files:
218
221
  - spec/models/entry.rb
219
222
  - spec/models/firm.rb
220
223
  - spec/models/folder.rb
224
+ - spec/models/group.rb
221
225
  - spec/models/mongoid/address.rb
222
226
  - spec/models/mongoid/category.rb
223
227
  - spec/models/mongoid/comment.rb