bullet 4.10.0 → 4.12.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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  3. data/Gemfile +4 -4
  4. data/Gemfile.mongoid-4.0 +1 -1
  5. data/Gemfile.rails-3.2 +1 -1
  6. data/Gemfile.rails-4.0 +1 -1
  7. data/Gemfile.rails-4.1 +1 -1
  8. data/README.md +52 -46
  9. data/bullet.gemspec +2 -2
  10. data/lib/bullet/active_record3.rb +7 -1
  11. data/lib/bullet/active_record3x.rb +7 -1
  12. data/lib/bullet/active_record4.rb +7 -11
  13. data/lib/bullet/active_record41.rb +7 -0
  14. data/lib/bullet/detector/association.rb +13 -5
  15. data/lib/bullet/detector/counter_cache.rb +12 -9
  16. data/lib/bullet/detector/n_plus_one_query.rb +29 -16
  17. data/lib/bullet/detector/unused_eager_loading.rb +16 -15
  18. data/lib/bullet/ext/object.rb +10 -2
  19. data/lib/bullet/notification/base.rb +5 -5
  20. data/lib/bullet/rack.rb +10 -4
  21. data/lib/bullet/registry/object.rb +4 -4
  22. data/lib/bullet/version.rb +1 -1
  23. data/lib/bullet.rb +5 -2
  24. data/spec/bullet/detector/association_spec.rb +2 -2
  25. data/spec/bullet/detector/counter_cache_spec.rb +8 -8
  26. data/spec/bullet/detector/n_plus_one_query_spec.rb +27 -27
  27. data/spec/bullet/detector/unused_eager_loading_spec.rb +15 -15
  28. data/spec/bullet/ext/object_spec.rb +17 -3
  29. data/spec/bullet/notification/base_spec.rb +37 -0
  30. data/spec/bullet/rack_spec.rb +2 -2
  31. data/spec/bullet/registry/object_spec.rb +4 -4
  32. data/spec/bullet_spec.rb +2 -2
  33. data/spec/integration/active_record3/association_spec.rb +12 -2
  34. data/spec/integration/active_record4/association_spec.rb +11 -1
  35. data/spec/models/category.rb +1 -1
  36. data/spec/models/post.rb +1 -1
  37. data/spec/spec_helper.rb +2 -2
  38. data/spec/support/bullet_ext.rb +1 -1
  39. metadata +6 -6
@@ -22,6 +22,35 @@ module Bullet
22
22
  user = `whoami`.chomp
23
23
  expect(subject.whoami).to eq("user: #{user}")
24
24
  end
25
+
26
+ it "should leverage ENV parameter" do
27
+ temp_env_variable("USER", "bogus") do
28
+ expect(subject.whoami).to eq("user: bogus")
29
+ end
30
+ end
31
+
32
+ it "should return blank if no user available" do
33
+ temp_env_variable("USER","") do
34
+ expect(subject).to receive(:`).with("whoami").and_return("")
35
+ expect(subject.whoami).to eq("")
36
+ end
37
+ end
38
+
39
+ it "should return blank if whoami is not available" do
40
+ temp_env_variable("USER","") do
41
+ expect(subject).to receive(:`).with("whoami").and_raise(Errno::ENOENT)
42
+ expect(subject.whoami).to eq("")
43
+ end
44
+ end
45
+
46
+ def temp_env_variable(name, value)
47
+ old_value = ENV[name]
48
+ ENV[name] = value
49
+ yield
50
+ ensure
51
+ ENV[name] = old_value
52
+ end
53
+
25
54
  end
26
55
 
27
56
  context "#body_with_caller" do
@@ -47,6 +76,14 @@ module Bullet
47
76
  allow(subject).to receive(:body_with_caller).and_return("body_with_caller")
48
77
  expect(subject.full_notice).to eq("whoami\nurl\ntitle\nbody_with_caller")
49
78
  end
79
+
80
+ it "should return url + title + body_with_caller" do
81
+ allow(subject).to receive(:whoami).and_return("")
82
+ allow(subject).to receive(:url).and_return("url")
83
+ allow(subject).to receive(:title).and_return("title")
84
+ allow(subject).to receive(:body_with_caller).and_return("body_with_caller")
85
+ expect(subject.full_notice).to eq("url\ntitle\nbody_with_caller")
86
+ end
50
87
  end
51
88
 
52
89
  context "#notification_data" do
@@ -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")
@@ -5,18 +5,18 @@ module Bullet
5
5
  describe Object do
6
6
  let(:post) { Post.first }
7
7
  let(:another_post) { Post.last }
8
- subject { Object.new.tap { |object| object.add(post.bullet_ar_key) } }
8
+ subject { Object.new.tap { |object| object.add(post.bullet_key) } }
9
9
 
10
10
  context "#include?" do
11
11
  it "should include the object" do
12
- expect(subject).to be_include(post.bullet_ar_key)
12
+ expect(subject).to be_include(post.bullet_key)
13
13
  end
14
14
  end
15
15
 
16
16
  context "#add" do
17
17
  it "should add an object" do
18
- subject.add(another_post.bullet_ar_key)
19
- expect(subject).to be_include(another_post.bullet_ar_key)
18
+ subject.add(another_post.bullet_key)
19
+ expect(subject).to be_include(another_post.bullet_key)
20
20
  end
21
21
  end
22
22
  end
data/spec/bullet_spec.rb CHANGED
@@ -26,8 +26,8 @@ describe Bullet, focused: true do
26
26
 
27
27
  context 'enable Bullet again without patching again the orms' do
28
28
  before do
29
- Bullet::Mongoid.should_not_receive(:enable) if defined? Bullet::Mongoid
30
- Bullet::ActiveRecord.should_not_receive(:enable) if defined? Bullet::ActiveRecord
29
+ expect(Bullet::Mongoid).not_to receive(:enable) if defined? Bullet::Mongoid
30
+ expect(Bullet::ActiveRecord).not_to receive(:enable) if defined? Bullet::ActiveRecord
31
31
  Bullet.enable = true
32
32
  end
33
33
 
@@ -39,7 +39,7 @@ if !mongoid? && active_record3?
39
39
  expect(Bullet::Detector::Association).to be_completely_preloading_associations
40
40
  end
41
41
 
42
- it "should detect non preload comment => post with inverse_of" do
42
+ it "should not detect non preload comment => post with inverse_of" do
43
43
  Post.includes(:comments).each do |post|
44
44
  post.comments.each do |comment|
45
45
  comment.name
@@ -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
@@ -361,7 +371,7 @@ if !mongoid? && active_record3?
361
371
  comment.post.writer.newspaper.name
362
372
  end
363
373
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
364
- Bullet::Detector::Association.should_not be_has_unused_preload_associations
374
+ expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
365
375
 
366
376
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Writer, :newspaper)
367
377
  end
@@ -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
@@ -359,7 +369,7 @@ if !mongoid? && active_record4?
359
369
  comment.post.writer.newspaper.name
360
370
  end
361
371
  Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
362
- Bullet::Detector::Association.should_not be_has_unused_preload_associations
372
+ expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
363
373
 
364
374
  expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Writer, :newspaper)
365
375
  end
@@ -1,5 +1,5 @@
1
1
  class Category < ActiveRecord::Base
2
- has_many :posts
2
+ has_many :posts, inverse_of: :category
3
3
  has_many :entries
4
4
 
5
5
  has_many :submissions
data/spec/models/post.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  class Post < ActiveRecord::Base
2
2
  extend Bullet::Dependency
3
3
 
4
- belongs_to :category
4
+ belongs_to :category, inverse_of: :posts
5
5
  belongs_to :writer
6
6
  has_many :comments, inverse_of: :post
7
7
 
data/spec/spec_helper.rb CHANGED
@@ -65,7 +65,7 @@ if active_record?
65
65
  end
66
66
  end
67
67
 
68
- if ENV["LOG"]
68
+ if ENV["BULLET_LOG"]
69
69
  require 'logger'
70
70
  ActiveRecord::Base.logger = Logger.new(STDOUT)
71
71
  end
@@ -96,7 +96,7 @@ if mongoid?
96
96
  end
97
97
  end
98
98
 
99
- if ENV["LOG"]
99
+ if ENV["BULLET_LOG"]
100
100
  Mongoid.logger = Logger.new(STDOUT)
101
101
  Moped.logger = Logger.new(STDOUT)
102
102
  end
@@ -33,7 +33,7 @@ module Bullet
33
33
 
34
34
  # returns true if a given object has a specific association
35
35
  def creating_object_association_for?(object, association)
36
- object_associations[object.bullet_ar_key].present? && object_associations[object.bullet_ar_key].include?(association)
36
+ object_associations[object.bullet_key].present? && object_associations[object.bullet_key].include?(association)
37
37
  end
38
38
 
39
39
  # returns true if a given class includes the specific unpreloaded association
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.12.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-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,26 +16,26 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 3.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 3.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: uniform_notifier
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.6.0
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
40
  version: 1.6.0
41
41
  description: help to kill N+1 queries and unused eager loading.