bullet 4.10.0 → 4.11.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: e3badf3b077a980eaa5aff1923f4e73d702f5b91
4
- data.tar.gz: f62fd9855dca76718f1abd484052e8b9ec841088
3
+ metadata.gz: db6af7eda5d3f19441a8e60b5aae5bf09d4dd3f8
4
+ data.tar.gz: 94510322d9e3190c200e5b18351c9b11c255e19a
5
5
  SHA512:
6
- metadata.gz: cd79339a18313dd651739d819f59d33ceee240ec595ff53a49b27133010d8a83e9274292907ccd99bd9b894b7d975c54e4a65b49f0907b08f0b70a4a994dc9e1
7
- data.tar.gz: 3dbb60cf0426b5cfb0d1fc5ac1bed620d139aafbf798eae0a7ebe94915a8b17fcc0a745b587313007a2922826f0b396f4be290dc353832f0c5e2618bedb29c50
6
+ metadata.gz: 2f1be7c449021b691ba83e2ea42c39d0701ce5c89f6517c9218dc563eaac0d6a18e626025e113470d30a7d8ce9c77ab7da784b030f983b32784079dba3312bd1
7
+ data.tar.gz: 0306d0092a4c164e5b650f7c3e5b42b4e3b16d3359bd82ff20e9b5b1cd2414af1e236f91a07a147ed374d4d9bf6d98a1eedb50b1dd4bf09e9922a222568bdfb1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Next Release
2
2
 
3
+ ## 4.11.0
4
+
5
+ * Support empty? call on ar associations
6
+ * Skip detecting if object is a new record
7
+
8
+ ## 4.10.0 (06/06/2014)
9
+
10
+ * Handle join query smarter
11
+ * Support mongoid 4.0
12
+ * Thread safe
13
+ * Add debug mode
14
+
3
15
  ## 4.9.0 (04/30/2014)
4
16
 
5
17
  * Add Bullet.stacktrace_includes option
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
@@ -7,9 +7,9 @@ gem 'sqlite3', platforms: [:ruby]
7
7
  gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
9
9
 
10
- gem "rspec"
11
- gem "guard"
12
- gem "guard-rspec"
10
+ gem 'rspec'
11
+ gem 'guard'
12
+ gem 'guard-rspec'
13
13
 
14
14
  gem 'coveralls', require: false
15
15
 
@@ -97,6 +97,12 @@ module Bullet
97
97
  Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
98
98
  origin_last(*args)
99
99
  end
100
+
101
+ alias_method :origin_empty?, :empty?
102
+ def empty?
103
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
104
+ origin_empty?
105
+ end
100
106
  end
101
107
 
102
108
  ::ActiveRecord::Associations::AssociationProxy.class_eval do
@@ -85,6 +85,12 @@ module Bullet
85
85
  Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
86
86
  origin_load_target
87
87
  end
88
+
89
+ alias_method :origin_empty?, :empty?
90
+ def empty?
91
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
92
+ origin_empty?
93
+ end
88
94
  end
89
95
 
90
96
  ::ActiveRecord::Associations::SingularAssociation.class_eval do
@@ -85,6 +85,12 @@ module Bullet
85
85
  Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
86
86
  origin_load_target
87
87
  end
88
+
89
+ alias_method :origin_empty?, :empty?
90
+ def empty?
91
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
92
+ origin_empty?
93
+ end
88
94
  end
89
95
 
90
96
  ::ActiveRecord::Associations::SingularAssociation.class_eval do
@@ -86,6 +86,12 @@ module Bullet
86
86
  Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
87
87
  origin_load_target
88
88
  end
89
+
90
+ alias_method :origin_empty?, :empty?
91
+ def empty?
92
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
93
+ origin_empty?
94
+ end
89
95
  end
90
96
 
91
97
  ::ActiveRecord::Associations::SingularAssociation.class_eval do
@@ -5,6 +5,7 @@ module Bullet
5
5
  def add_object_associations(object, associations)
6
6
  return unless Bullet.start?
7
7
  return if !Bullet.n_plus_one_query_enable? && !Bullet.unused_eager_loading_enable?
8
+ return unless object.id
8
9
 
9
10
  Bullet.debug("Detector::Association#add_object_associations", "object: #{object.bullet_ar_key}, associations: #{associations}")
10
11
  object_associations.add(object.bullet_ar_key, associations)
@@ -13,6 +14,7 @@ module Bullet
13
14
  def add_call_object_associations(object, associations)
14
15
  return unless Bullet.start?
15
16
  return if !Bullet.n_plus_one_query_enable? && !Bullet.unused_eager_loading_enable?
17
+ return unless object.id
16
18
 
17
19
  Bullet.debug("Detector::Association#add_call_object_associations", "object: #{object.bullet_ar_key}, associations: #{associations}")
18
20
  call_object_associations.add(object.bullet_ar_key, associations)
@@ -5,6 +5,7 @@ module Bullet
5
5
  def add_counter_cache(object, associations)
6
6
  return unless Bullet.start?
7
7
  return unless Bullet.counter_cache_enable?
8
+ return unless object.id
8
9
 
9
10
  Bullet.debug("Detector::CounterCache#add_counter_cache", "object: #{object.bullet_ar_key}, associations: #{associations}")
10
11
  if conditions_met?(object.bullet_ar_key, associations)
@@ -15,8 +16,9 @@ module Bullet
15
16
  def add_possible_objects(object_or_objects)
16
17
  return unless Bullet.start?
17
18
  return unless Bullet.counter_cache_enable?
18
-
19
19
  objects = Array(object_or_objects)
20
+ return if objects.map(&:id).compact.empty?
21
+
20
22
  Bullet.debug("Detector::CounterCache#add_possible_objects", "objects: #{objects.map(&:bullet_ar_key).join(', ')}")
21
23
  objects.each { |object| possible_objects.add object.bullet_ar_key }
22
24
  end
@@ -24,6 +26,7 @@ module Bullet
24
26
  def add_impossible_object(object)
25
27
  return unless Bullet.start?
26
28
  return unless Bullet.counter_cache_enable?
29
+ return unless object.id
27
30
 
28
31
  Bullet.debug("Detector::CounterCache#add_impossible_object", "object: #{object.bullet_ar_key}")
29
32
  impossible_objects.add object.bullet_ar_key
@@ -10,6 +10,7 @@ module Bullet
10
10
  # if it is, keeps this unpreload associations and caller.
11
11
  def call_association(object, associations)
12
12
  return unless Bullet.start?
13
+ return unless object.id
13
14
  add_call_object_associations(object, associations)
14
15
 
15
16
  Bullet.debug("Detector::NPlusOneQuery#call_association", "object: #{object.bullet_ar_key}, associations: #{associations}")
@@ -22,8 +23,9 @@ module Bullet
22
23
  def add_possible_objects(object_or_objects)
23
24
  return unless Bullet.start?
24
25
  return unless Bullet.n_plus_one_query_enable?
25
-
26
26
  objects = Array(object_or_objects)
27
+ return if objects.map(&:id).compact.empty?
28
+
27
29
  Bullet.debug("Detector::NPlusOneQuery#add_possible_objects", "objects: #{objects.map(&:bullet_ar_key).join(', ')}")
28
30
  objects.each { |object| possible_objects.add object.bullet_ar_key }
29
31
  end
@@ -31,6 +33,7 @@ module Bullet
31
33
  def add_impossible_object(object)
32
34
  return unless Bullet.start?
33
35
  return unless Bullet.n_plus_one_query_enable?
36
+ return unless object.id
34
37
 
35
38
  Bullet.debug("Detector::NPlusOneQuery#add_impossible_object", "object: #{object.bullet_ar_key}")
36
39
  impossible_objects.add object.bullet_ar_key
@@ -22,6 +22,7 @@ module Bullet
22
22
  def add_eager_loadings(objects, associations)
23
23
  return unless Bullet.start?
24
24
  return unless Bullet.unused_eager_loading_enable?
25
+ return if objects.map(&:id).compact.empty?
25
26
 
26
27
  Bullet.debug("Detector::UnusedEagerLoading#add_eager_loadings", "objects: #{objects.map(&:bullet_ar_key).join(', ')}, associations: #{associations}")
27
28
  bullet_ar_keys = objects.map(&:bullet_ar_key)
@@ -1,5 +1,9 @@
1
1
  class Object
2
2
  def bullet_ar_key
3
- "#{self.class}:#{self.id}"
3
+ if self.is_a? ActiveRecord::Base
4
+ "#{self.class}:#{self.send self.class.primary_key}"
5
+ else
6
+ "#{self.class}:#{self.id}"
7
+ end
4
8
  end
5
9
  end
data/lib/bullet/rack.rb CHANGED
@@ -10,7 +10,7 @@ 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) || empty?(response)
13
+ return [status, headers, response] if file?(headers) || sse?(response) || empty?(response)
14
14
 
15
15
  response_body = nil
16
16
  if Bullet.notification?
@@ -19,10 +19,13 @@ module Bullet
19
19
  add_footer_note(response_body) if Bullet.add_footer
20
20
  headers['Content-Length'] = response_body.bytesize.to_s
21
21
  end
22
+ end
23
+ [status, headers, response_body ? [response_body] : response]
24
+ ensure
25
+ if Bullet.enable? && Bullet.notification?
22
26
  Bullet.perform_out_of_channel_notifications(env)
23
27
  end
24
28
  Bullet.end_request
25
- [status, headers, response_body ? [response_body] : response]
26
29
  end
27
30
 
28
31
  # fix issue if response's body is a Proc
@@ -43,11 +46,14 @@ module Bullet
43
46
  response_body << "<div #{footer_div_style}>" + Bullet.footer_info.uniq.join("<br>") + "</div>"
44
47
  end
45
48
 
46
- # if send file?
47
49
  def file?(headers)
48
50
  headers["Content-Transfer-Encoding"] == "binary"
49
51
  end
50
52
 
53
+ def sse?(response)
54
+ response.respond_to? :stream
55
+ end
56
+
51
57
  def html_request?(headers, response)
52
58
  headers['Content-Type'] && headers['Content-Type'].include?('text/html') && response_body(response).include?("<html")
53
59
  end
@@ -67,7 +73,7 @@ style="position: fixed; bottom: 0pt; left: 0pt; cursor: pointer; border-style: s
67
73
  -moz-border-top-colors: none; -moz-border-right-colors: none; -moz-border-bottom-colors: none;
68
74
  -moz-border-left-colors: none; -moz-border-image: none; border-width: 2pt 2pt 0px 0px;
69
75
  padding: 5px; border-radius: 0pt 10pt 0pt 0px; background: none repeat scroll 0% 0% rgba(200, 200, 200, 0.8);
70
- color: rgb(119, 119, 119); font-size: 18px;"
76
+ color: rgb(119, 119, 119); font-size: 18px; font-family: 'Arial', sans-serif; z-index:9999;"
71
77
  EOF
72
78
  end
73
79
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Bullet
3
- VERSION = "4.10.0"
3
+ VERSION = "4.11.0"
4
4
  end
@@ -65,7 +65,7 @@ module Bullet
65
65
  end
66
66
 
67
67
  it "should change response body if notification is active" do
68
- expect(Bullet).to receive(:notification?).and_return(true)
68
+ expect(Bullet).to receive(:notification?).and_return(true).twice
69
69
  expect(Bullet).to receive(:gather_inline_notifications).and_return("<bullet></bullet>")
70
70
  expect(Bullet).to receive(:perform_out_of_channel_notifications)
71
71
  status, headers, response = middleware.call([200, {"Content-Type" => "text/html"}])
@@ -77,7 +77,7 @@ module Bullet
77
77
  response = Support::ResponseDouble.new
78
78
  response.body = "<html><head></head><body>é</body></html>"
79
79
  app.response = response
80
- expect(Bullet).to receive(:notification?).and_return(true)
80
+ expect(Bullet).to receive(:notification?).and_return(true).twice
81
81
  expect(Bullet).to receive(:gather_inline_notifications).and_return("<bullet></bullet>")
82
82
  status, headers, response = middleware.call([200, {"Content-Type" => "text/html"}])
83
83
  expect(headers["Content-Length"]).to eq("58")
@@ -51,6 +51,16 @@ if !mongoid? && active_record3?
51
51
 
52
52
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
53
53
  end
54
+
55
+ it "should detect non preload post => comments with empty?" do
56
+ Post.all.each do |post|
57
+ post.comments.empty?
58
+ end
59
+ Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
60
+ expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
61
+
62
+ expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Post, :comments)
63
+ end
54
64
  end
55
65
 
56
66
  context "category => posts => comments" do
@@ -51,6 +51,16 @@ if !mongoid? && active_record4?
51
51
 
52
52
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
53
53
  end
54
+
55
+ it "should detect non preload post => comments with empty?" do
56
+ Post.all.each do |post|
57
+ post.comments.empty?
58
+ end
59
+ Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
60
+ expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
61
+
62
+ expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Post, :comments)
63
+ end
54
64
  end
55
65
 
56
66
  context "category => posts => comments" do
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: 4.10.0
4
+ version: 4.11.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: 2014-06-06 00:00:00.000000000 Z
11
+ date: 2014-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport