bullet 4.14.5 → 4.14.7

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.
@@ -8,13 +8,15 @@ module Bullet
8
8
  # if select only one object, then the only one object has impossible to cause N+1 query.
9
9
  def to_a
10
10
  records = origin_to_a
11
- if records.first.class.name !~ /^HABTM_/
12
- if records.size > 1
13
- Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
14
- Bullet::Detector::CounterCache.add_possible_objects(records)
15
- elsif records.size == 1
16
- Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
17
- Bullet::Detector::CounterCache.add_impossible_object(records.first)
11
+ if Bullet.start?
12
+ if records.first.class.name !~ /^HABTM_/
13
+ if records.size > 1
14
+ Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
15
+ Bullet::Detector::CounterCache.add_possible_objects(records)
16
+ elsif records.size == 1
17
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
18
+ Bullet::Detector::CounterCache.add_impossible_object(records.first)
19
+ end
18
20
  end
19
21
  end
20
22
  records
@@ -25,12 +27,14 @@ module Bullet
25
27
  alias_method :origin_preloaders_on, :preloaders_on
26
28
 
27
29
  def preloaders_on(association, records, scope)
28
- records.compact!
29
- if records.first.class.name !~ /^HABTM_/
30
- records.each do |record|
31
- Bullet::Detector::Association.add_object_associations(record, association)
30
+ if Bullet.start?
31
+ records.compact!
32
+ if records.first.class.name !~ /^HABTM_/
33
+ records.each do |record|
34
+ Bullet::Detector::Association.add_object_associations(record, association)
35
+ end
36
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, association)
32
37
  end
33
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, association)
34
38
  end
35
39
  origin_preloaders_on(association, records, scope)
36
40
  end
@@ -42,11 +46,13 @@ module Bullet
42
46
  def find_with_associations
43
47
  return origin_find_with_associations { |r| yield r } if block_given?
44
48
  records = origin_find_with_associations
45
- associations = (eager_load_values + includes_values).uniq
46
- records.each do |record|
47
- Bullet::Detector::Association.add_object_associations(record, associations)
49
+ if Bullet.start?
50
+ associations = (eager_load_values + includes_values).uniq
51
+ records.each do |record|
52
+ Bullet::Detector::Association.add_object_associations(record, associations)
53
+ end
54
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
48
55
  end
49
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
50
56
  records
51
57
  end
52
58
  end
@@ -59,9 +65,11 @@ module Bullet
59
65
  @bullet_eager_loadings = {}
60
66
  records = origin_instantiate(result_set, aliases)
61
67
 
62
- @bullet_eager_loadings.each do |klazz, eager_loadings_hash|
63
- objects = eager_loadings_hash.keys
64
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
68
+ if Bullet.start?
69
+ @bullet_eager_loadings.each do |klazz, eager_loadings_hash|
70
+ objects = eager_loadings_hash.keys
71
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
72
+ end
65
73
  end
66
74
  records
67
75
  end
@@ -70,12 +78,14 @@ module Bullet
70
78
  def construct_model(record, node, row, model_cache, id, aliases)
71
79
  result = origin_construct_model(record, node, row, model_cache, id, aliases)
72
80
 
73
- associations = node.reflection.name
74
- Bullet::Detector::Association.add_object_associations(record, associations)
75
- Bullet::Detector::NPlusOneQuery.call_association(record, associations)
76
- @bullet_eager_loadings[record.class] ||= {}
77
- @bullet_eager_loadings[record.class][record] ||= Set.new
78
- @bullet_eager_loadings[record.class][record] << associations
81
+ if Bullet.start?
82
+ associations = node.reflection.name
83
+ Bullet::Detector::Association.add_object_associations(record, associations)
84
+ Bullet::Detector::NPlusOneQuery.call_association(record, associations)
85
+ @bullet_eager_loadings[record.class] ||= {}
86
+ @bullet_eager_loadings[record.class][record] ||= Set.new
87
+ @bullet_eager_loadings[record.class][record] << associations
88
+ end
79
89
 
80
90
  result
81
91
  end
@@ -85,19 +95,25 @@ module Bullet
85
95
  # call one to many associations
86
96
  alias_method :origin_load_target, :load_target
87
97
  def load_target
88
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
98
+ if Bullet.start?
99
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
100
+ end
89
101
  origin_load_target
90
102
  end
91
103
 
92
104
  alias_method :origin_empty?, :empty?
93
105
  def empty?
94
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
106
+ if Bullet.start?
107
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
108
+ end
95
109
  origin_empty?
96
110
  end
97
111
 
98
112
  alias_method :origin_include?, :include?
99
113
  def include?(object)
100
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
114
+ if Bullet.start?
115
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
116
+ end
101
117
  origin_include?(object)
102
118
  end
103
119
  end
@@ -107,9 +123,11 @@ module Bullet
107
123
  alias_method :origin_reader, :reader
108
124
  def reader(force_reload = false)
109
125
  result = origin_reader(force_reload)
110
- if @owner.class.name !~ /^HABTM_/ && !@inversed
111
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
112
- Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
126
+ if Bullet.start?
127
+ if @owner.class.name !~ /^HABTM_/ && !@inversed
128
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
129
+ Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
130
+ end
113
131
  end
114
132
  result
115
133
  end
@@ -120,7 +138,9 @@ module Bullet
120
138
 
121
139
  def has_cached_counter?(reflection = reflection())
122
140
  result = origin_has_cached_counter?(reflection)
123
- Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name) unless result
141
+ if Bullet.start?
142
+ Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name) unless result
143
+ end
124
144
  result
125
145
  end
126
146
  end
@@ -7,12 +7,14 @@ module Bullet
7
7
  alias_method :origin_find, :find
8
8
  def find(*args)
9
9
  result = origin_find(*args)
10
- if result.is_a? Array
11
- Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
12
- Bullet::Detector::CounterCache.add_possible_objects(result)
13
- elsif result.is_a? ::ActiveRecord::Base
14
- Bullet::Detector::NPlusOneQuery.add_impossible_object(result)
15
- Bullet::Detector::CounterCache.add_impossible_object(result)
10
+ if Bullet.start?
11
+ if result.is_a? Array
12
+ Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
13
+ Bullet::Detector::CounterCache.add_possible_objects(result)
14
+ elsif result.is_a? ::ActiveRecord::Base
15
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(result)
16
+ Bullet::Detector::CounterCache.add_impossible_object(result)
17
+ end
16
18
  end
17
19
  result
18
20
  end
@@ -25,13 +27,15 @@ module Bullet
25
27
  # if select only one object, then the only one object has impossible to cause N+1 query.
26
28
  def to_a
27
29
  records = origin_to_a
28
- if records.first.class.name !~ /^HABTM_/
29
- if records.size > 1
30
- Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
31
- Bullet::Detector::CounterCache.add_possible_objects(records)
32
- elsif records.size == 1
33
- Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
34
- Bullet::Detector::CounterCache.add_impossible_object(records.first)
30
+ if Bullet.start?
31
+ if records.first.class.name !~ /^HABTM_/
32
+ if records.size > 1
33
+ Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
34
+ Bullet::Detector::CounterCache.add_possible_objects(records)
35
+ elsif records.size == 1
36
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
37
+ Bullet::Detector::CounterCache.add_impossible_object(records.first)
38
+ end
35
39
  end
36
40
  end
37
41
  records
@@ -42,12 +46,14 @@ module Bullet
42
46
  alias_method :origin_preloaders_on, :preloaders_on
43
47
 
44
48
  def preloaders_on(association, records, scope)
45
- records.compact!
46
- if records.first.class.name !~ /^HABTM_/
47
- records.each do |record|
48
- Bullet::Detector::Association.add_object_associations(record, association)
49
+ if Bullet.start?
50
+ records.compact!
51
+ if records.first.class.name !~ /^HABTM_/
52
+ records.each do |record|
53
+ Bullet::Detector::Association.add_object_associations(record, association)
54
+ end
55
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, association)
49
56
  end
50
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, association)
51
57
  end
52
58
  origin_preloaders_on(association, records, scope)
53
59
  end
@@ -59,11 +65,13 @@ module Bullet
59
65
  def find_with_associations
60
66
  return origin_find_with_associations { |r| yield r } if block_given?
61
67
  records = origin_find_with_associations
62
- associations = (eager_load_values + includes_values).uniq
63
- records.each do |record|
64
- Bullet::Detector::Association.add_object_associations(record, associations)
68
+ if Bullet.start?
69
+ associations = (eager_load_values + includes_values).uniq
70
+ records.each do |record|
71
+ Bullet::Detector::Association.add_object_associations(record, associations)
72
+ end
73
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
65
74
  end
66
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
67
75
  records
68
76
  end
69
77
  end
@@ -76,9 +84,11 @@ module Bullet
76
84
  @bullet_eager_loadings = {}
77
85
  records = origin_instantiate(result_set, aliases)
78
86
 
79
- @bullet_eager_loadings.each do |klazz, eager_loadings_hash|
80
- objects = eager_loadings_hash.keys
81
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
87
+ if Bullet.start?
88
+ @bullet_eager_loadings.each do |klazz, eager_loadings_hash|
89
+ objects = eager_loadings_hash.keys
90
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
91
+ end
82
92
  end
83
93
  records
84
94
  end
@@ -87,12 +97,14 @@ module Bullet
87
97
  def construct_model(record, node, row, model_cache, id, aliases)
88
98
  result = origin_construct_model(record, node, row, model_cache, id, aliases)
89
99
 
90
- associations = node.reflection.name
91
- Bullet::Detector::Association.add_object_associations(record, associations)
92
- Bullet::Detector::NPlusOneQuery.call_association(record, associations)
93
- @bullet_eager_loadings[record.class] ||= {}
94
- @bullet_eager_loadings[record.class][record] ||= Set.new
95
- @bullet_eager_loadings[record.class][record] << associations
100
+ if Bullet.start?
101
+ associations = node.reflection.name
102
+ Bullet::Detector::Association.add_object_associations(record, associations)
103
+ Bullet::Detector::NPlusOneQuery.call_association(record, associations)
104
+ @bullet_eager_loadings[record.class] ||= {}
105
+ @bullet_eager_loadings[record.class][record] ||= Set.new
106
+ @bullet_eager_loadings[record.class][record] << associations
107
+ end
96
108
 
97
109
  result
98
110
  end
@@ -102,16 +114,18 @@ module Bullet
102
114
  # call one to many associations
103
115
  alias_method :origin_load_target, :load_target
104
116
  def load_target
105
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
106
117
  records = origin_load_target
107
118
 
108
- if records.first.class.name !~ /^HABTM_/
109
- if records.size > 1
110
- Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
111
- Bullet::Detector::CounterCache.add_possible_objects(records)
112
- elsif records.size == 1
113
- Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
114
- Bullet::Detector::CounterCache.add_impossible_object(records.first)
119
+ if Bullet.start?
120
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
121
+ if records.first.class.name !~ /^HABTM_/
122
+ if records.size > 1
123
+ Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
124
+ Bullet::Detector::CounterCache.add_possible_objects(records)
125
+ elsif records.size == 1
126
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
127
+ Bullet::Detector::CounterCache.add_impossible_object(records.first)
128
+ end
115
129
  end
116
130
  end
117
131
  records
@@ -119,13 +133,17 @@ module Bullet
119
133
 
120
134
  alias_method :origin_empty?, :empty?
121
135
  def empty?
122
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
136
+ if Bullet.start?
137
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
138
+ end
123
139
  origin_empty?
124
140
  end
125
141
 
126
142
  alias_method :origin_include?, :include?
127
143
  def include?(object)
128
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
144
+ if Bullet.start?
145
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
146
+ end
129
147
  origin_include?(object)
130
148
  end
131
149
  end
@@ -135,12 +153,15 @@ module Bullet
135
153
  alias_method :origin_reader, :reader
136
154
  def reader(force_reload = false)
137
155
  result = origin_reader(force_reload)
138
- if @owner.class.name !~ /^HABTM_/ && !@inversed
139
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
140
- Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
141
- end
142
- if ::ActiveRecord::Reflection::HasOneReflection === @reflection && result
143
- Bullet::Detector::NPlusOneQuery.add_impossible_object(result)
156
+ if Bullet.start?
157
+ if @owner.class.name !~ /^HABTM_/ && !@inversed
158
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
159
+ if Bullet::Detector::NPlusOneQuery.impossible?(@owner)
160
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(result) if result
161
+ else
162
+ Bullet::Detector::NPlusOneQuery.add_possible_objects(result) if result
163
+ end
164
+ end
144
165
  end
145
166
  result
146
167
  end
@@ -152,15 +173,19 @@ module Bullet
152
173
  Thread.current[:bullet_collection_empty] = true
153
174
  result = origin_many_empty?
154
175
  Thread.current[:bullet_collection_empty] = nil
155
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
176
+ if Bullet.start?
177
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
178
+ end
156
179
  result
157
180
  end
158
181
 
159
182
  alias_method :origin_has_cached_counter?, :has_cached_counter?
160
183
  def has_cached_counter?(reflection = reflection())
161
184
  result = origin_has_cached_counter?(reflection)
162
- if !result && !Thread.current[:bullet_collection_empty]
163
- Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name)
185
+ if Bullet.start?
186
+ if !result && !Thread.current[:bullet_collection_empty]
187
+ Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name)
188
+ end
164
189
  end
165
190
  result
166
191
  end
@@ -20,6 +20,22 @@ module Bullet
20
20
  call_object_associations.add(object.bullet_key, associations)
21
21
  end
22
22
 
23
+ # possible_objects keep the class to object relationships
24
+ # that the objects may cause N+1 query.
25
+ # e.g. { Post => ["Post:1", "Post:2"] }
26
+ def possible_objects
27
+ Thread.current[:bullet_possible_objects]
28
+ end
29
+
30
+ # impossible_objects keep the class to objects relationships
31
+ # that the objects may not cause N+1 query.
32
+ # e.g. { Post => ["Post:1", "Post:2"] }
33
+ # if find collection returns only one object, then the object is impossible object,
34
+ # impossible_objects are used to avoid treating 1+1 query to N+1 query.
35
+ def impossible_objects
36
+ Thread.current[:bullet_impossible_objects]
37
+ end
38
+
23
39
  private
24
40
  # object_associations keep the object relationships
25
41
  # that the object has many associations.
@@ -38,22 +54,6 @@ module Bullet
38
54
  Thread.current[:bullet_call_object_associations]
39
55
  end
40
56
 
41
- # possible_objects keep the class to object relationships
42
- # that the objects may cause N+1 query.
43
- # e.g. { Post => ["Post:1", "Post:2"] }
44
- def possible_objects
45
- Thread.current[:bullet_possible_objects]
46
- end
47
-
48
- # impossible_objects keep the class to objects relationships
49
- # that the objects may not cause N+1 query.
50
- # e.g. { Post => ["Post:1", "Post:2"] }
51
- # if find collection returns only one object, then the object is impossible object,
52
- # impossible_objects are used to avoid treating 1+1 query to N+1 query.
53
- def impossible_objects
54
- Thread.current[:bullet_impossible_objects]
55
- end
56
-
57
57
  # inversed_objects keeps object relationships
58
58
  # that association is inversed.
59
59
  # e.g. { "Comment:1" => ["post"] }
@@ -8,7 +8,7 @@ module Bullet
8
8
  return unless object.primary_key_value
9
9
 
10
10
  Bullet.debug("Detector::CounterCache#add_counter_cache", "object: #{object.bullet_key}, associations: #{associations}")
11
- if conditions_met?(object.bullet_key, associations)
11
+ if conditions_met?(object, associations)
12
12
  create_notification object.class.to_s, associations
13
13
  end
14
14
  end
@@ -32,6 +32,18 @@ module Bullet
32
32
  impossible_objects.add object.bullet_key
33
33
  end
34
34
 
35
+ def conditions_met?(object, associations)
36
+ possible_objects.include?(object.bullet_key) && !impossible_objects.include?(object.bullet_key)
37
+ end
38
+
39
+ def possible_objects
40
+ Thread.current[:bullet_counter_possible_objects]
41
+ end
42
+
43
+ def impossible_objects
44
+ Thread.current[:bullet_counter_impossible_objects]
45
+ end
46
+
35
47
  private
36
48
  def create_notification(klazz, associations)
37
49
  notify_associations = Array(associations) - Bullet.get_whitelist_associations(:counter_cache, klazz)
@@ -41,18 +53,6 @@ module Bullet
41
53
  Bullet.notification_collector.add notice
42
54
  end
43
55
  end
44
-
45
- def possible_objects
46
- Thread.current[:bullet_counter_possible_objects]
47
- end
48
-
49
- def impossible_objects
50
- Thread.current[:bullet_counter_impossible_objects]
51
- end
52
-
53
- def conditions_met?(bullet_key, associations)
54
- possible_objects.include?(bullet_key) && !impossible_objects.include?(bullet_key)
55
- end
56
56
  end
57
57
  end
58
58
  end
@@ -15,7 +15,7 @@ module Bullet
15
15
  add_call_object_associations(object, associations)
16
16
 
17
17
  Bullet.debug("Detector::NPlusOneQuery#call_association", "object: #{object.bullet_key}, associations: #{associations}")
18
- if conditions_met?(object.bullet_key, associations)
18
+ if conditions_met?(object, associations)
19
19
  Bullet.debug("detect n + 1 query", "object: #{object.bullet_key}, associations: #{associations}")
20
20
  create_notification caller_in_project, object.class.to_s, associations
21
21
  end
@@ -49,6 +49,35 @@ module Bullet
49
49
  inversed_objects.add object.bullet_key, association
50
50
  end
51
51
 
52
+ # decide whether the object.associations is unpreloaded or not.
53
+ def conditions_met?(object, associations)
54
+ possible?(object) && !impossible?(object) && !association?(object, associations)
55
+ end
56
+
57
+ def possible?(object)
58
+ possible_objects.include? object.bullet_key
59
+ end
60
+
61
+ def impossible?(object)
62
+ impossible_objects.include? object.bullet_key
63
+ end
64
+
65
+ # check if object => associations already exists in object_associations.
66
+ def association?(object, associations)
67
+ value = object_associations[object.bullet_key]
68
+ if value
69
+ value.each do |v|
70
+ # associations == v comparision order is important here because
71
+ # v variable might be a squeel node where :== method is redefined,
72
+ # so it does not compare values at all and return unexpected results
73
+ result = v.is_a?(Hash) ? v.has_key?(associations) : associations == v
74
+ return true if result
75
+ end
76
+ end
77
+
78
+ false
79
+ end
80
+
52
81
  private
53
82
  def create_notification(callers, klazz, associations)
54
83
  notify_associations = Array(associations) - Bullet.get_whitelist_associations(:n_plus_one_query, klazz)
@@ -59,11 +88,6 @@ module Bullet
59
88
  end
60
89
  end
61
90
 
62
- # decide whether the object.associations is unpreloaded or not.
63
- def conditions_met?(bullet_key, associations)
64
- possible?(bullet_key) && !impossible?(bullet_key) && !association?(bullet_key, associations)
65
- end
66
-
67
91
  def caller_in_project
68
92
  app_root = rails? ? Rails.root.to_s : Dir.pwd
69
93
  vendor_root = app_root + "/vendor"
@@ -72,30 +96,6 @@ module Bullet
72
96
  Bullet.stacktrace_includes.any? { |include| c.include?(include) }
73
97
  end
74
98
  end
75
-
76
- def possible?(bullet_key)
77
- possible_objects.include? bullet_key
78
- end
79
-
80
- def impossible?(bullet_key)
81
- impossible_objects.include? bullet_key
82
- end
83
-
84
- # check if object => associations already exists in object_associations.
85
- def association?(bullet_key, associations)
86
- value = object_associations[bullet_key]
87
- if value
88
- value.each do |v|
89
- # associations == v comparision order is important here because
90
- # v variable might be a squeel node where :== method is redefined,
91
- # so it does not compare values at all and return unexpected results
92
- result = v.is_a?(Hash) ? v.has_key?(associations) : associations == v
93
- return true if result
94
- end
95
- end
96
-
97
- return false
98
- end
99
99
  end
100
100
  end
101
101
  end
data/lib/bullet/rack.rb CHANGED
@@ -10,11 +10,11 @@ module Bullet
10
10
  return @app.call(env) unless Bullet.enable?
11
11
  Bullet.start_request
12
12
  status, headers, response = @app.call(env)
13
- return [status, headers, response] if file?(headers) || sse?(headers) || empty?(response)
14
13
 
15
14
  response_body = nil
16
15
  if Bullet.notification?
17
- if status == 200 && !response_body(response).frozen? && html_request?(headers, response)
16
+ if !file?(headers) && !sse?(headers) && !empty?(response) &&
17
+ status == 200 && !response_body(response).frozen? && html_request?(headers, response)
18
18
  response_body = response_body(response)
19
19
  append_to_html_body(response_body, footer_note) if Bullet.add_footer
20
20
  append_to_html_body(response_body, Bullet.gather_inline_notifications)
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Bullet
3
- VERSION = "4.14.5"
3
+ VERSION = "4.14.7"
4
4
  end
data/lib/bullet.rb CHANGED
@@ -29,7 +29,9 @@ module Bullet
29
29
  attr_reader :notification_collector, :whitelist
30
30
  attr_accessor :add_footer, :orm_pathches_applied
31
31
 
32
- delegate *UniformNotifier::AVAILABLE_NOTIFIERS.map { |notifier| "#{notifier}=" }, :to => UniformNotifier
32
+ available_notifiers = UniformNotifier::AVAILABLE_NOTIFIERS.map { |notifier| "#{notifier}=" }
33
+ available_notifiers << { :to => UniformNotifier }
34
+ delegate *available_notifiers
33
35
 
34
36
  def raise=(should_raise)
35
37
  UniformNotifier.raise=(should_raise ? Notification::UnoptimizedQueryError : false)
@@ -10,13 +10,13 @@ module Bullet
10
10
 
11
11
  context ".add_counter_cache" do
12
12
  it "should create notification if conditions met" do
13
- expect(CounterCache).to receive(:conditions_met?).with(@post1.bullet_key, [:comments]).and_return(true)
13
+ expect(CounterCache).to receive(:conditions_met?).with(@post1, [:comments]).and_return(true)
14
14
  expect(CounterCache).to receive(:create_notification).with("Post", [:comments])
15
15
  CounterCache.add_counter_cache(@post1, [:comments])
16
16
  end
17
17
 
18
18
  it "should not create notification if conditions not met" do
19
- expect(CounterCache).to receive(:conditions_met?).with(@post1.bullet_key, [:comments]).and_return(false)
19
+ expect(CounterCache).to receive(:conditions_met?).with(@post1, [:comments]).and_return(false)
20
20
  expect(CounterCache).to receive(:create_notification).never
21
21
  CounterCache.add_counter_cache(@post1, [:comments])
22
22
  end
@@ -25,30 +25,30 @@ module Bullet
25
25
  context ".add_possible_objects" do
26
26
  it "should add possible objects" do
27
27
  CounterCache.add_possible_objects([@post1, @post2])
28
- expect(CounterCache.send(:possible_objects)).to be_include(@post1.bullet_key)
29
- expect(CounterCache.send(:possible_objects)).to be_include(@post2.bullet_key)
28
+ expect(CounterCache.possible_objects).to be_include(@post1.bullet_key)
29
+ expect(CounterCache.possible_objects).to be_include(@post2.bullet_key)
30
30
  end
31
31
 
32
32
  it "should add impossible object" do
33
33
  CounterCache.add_impossible_object(@post1)
34
- expect(CounterCache.send(:impossible_objects)).to be_include(@post1.bullet_key)
34
+ expect(CounterCache.impossible_objects).to be_include(@post1.bullet_key)
35
35
  end
36
36
  end
37
37
 
38
38
  context ".conditions_met?" do
39
39
  it "should be true when object is possible, not impossible" do
40
40
  CounterCache.add_possible_objects(@post1)
41
- expect(CounterCache.send(:conditions_met?, @post1.bullet_key, :associations)).to eq true
41
+ expect(CounterCache.conditions_met?(@post1, :associations)).to eq true
42
42
  end
43
43
 
44
44
  it "should be false when object is not possible" do
45
- expect(CounterCache.send(:conditions_met?, @post1.bullet_key, :associations)).to eq false
45
+ expect(CounterCache.conditions_met?(@post1, :associations)).to eq false
46
46
  end
47
47
 
48
48
  it "should be true when object is possible, and impossible" do
49
49
  CounterCache.add_possible_objects(@post1)
50
50
  CounterCache.add_impossible_object(@post1)
51
- expect(CounterCache.send(:conditions_met?, @post1.bullet_key, :associations)).to eq false
51
+ expect(CounterCache.conditions_met?(@post1, :associations)).to eq false
52
52
  end
53
53
  end
54
54
  end