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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -0
- data/Gemfile +4 -4
- data/Gemfile.mongoid-4.0 +1 -1
- data/Gemfile.rails-3.2 +1 -1
- data/Gemfile.rails-4.0 +1 -1
- data/Gemfile.rails-4.1 +1 -1
- data/README.md +52 -46
- data/bullet.gemspec +2 -2
- data/lib/bullet/active_record3.rb +7 -1
- data/lib/bullet/active_record3x.rb +7 -1
- data/lib/bullet/active_record4.rb +7 -11
- data/lib/bullet/active_record41.rb +7 -0
- data/lib/bullet/detector/association.rb +13 -5
- data/lib/bullet/detector/counter_cache.rb +12 -9
- data/lib/bullet/detector/n_plus_one_query.rb +29 -16
- data/lib/bullet/detector/unused_eager_loading.rb +16 -15
- data/lib/bullet/ext/object.rb +10 -2
- data/lib/bullet/notification/base.rb +5 -5
- data/lib/bullet/rack.rb +10 -4
- data/lib/bullet/registry/object.rb +4 -4
- data/lib/bullet/version.rb +1 -1
- data/lib/bullet.rb +5 -2
- data/spec/bullet/detector/association_spec.rb +2 -2
- data/spec/bullet/detector/counter_cache_spec.rb +8 -8
- data/spec/bullet/detector/n_plus_one_query_spec.rb +27 -27
- data/spec/bullet/detector/unused_eager_loading_spec.rb +15 -15
- data/spec/bullet/ext/object_spec.rb +17 -3
- data/spec/bullet/notification/base_spec.rb +37 -0
- data/spec/bullet/rack_spec.rb +2 -2
- data/spec/bullet/registry/object_spec.rb +4 -4
- data/spec/bullet_spec.rb +2 -2
- data/spec/integration/active_record3/association_spec.rb +12 -2
- data/spec/integration/active_record4/association_spec.rb +11 -1
- data/spec/models/category.rb +1 -1
- data/spec/models/post.rb +1 -1
- data/spec/spec_helper.rb +2 -2
- data/spec/support/bullet_ext.rb +1 -1
- 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
|
data/spec/bullet/rack_spec.rb
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
19
|
-
expect(subject).to be_include(another_post.
|
|
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.
|
|
30
|
-
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.
|
|
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.
|
|
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
|
data/spec/models/category.rb
CHANGED
data/spec/models/post.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
|
@@ -65,7 +65,7 @@ if active_record?
|
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
-
if ENV["
|
|
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["
|
|
99
|
+
if ENV["BULLET_LOG"]
|
|
100
100
|
Mongoid.logger = Logger.new(STDOUT)
|
|
101
101
|
Moped.logger = Logger.new(STDOUT)
|
|
102
102
|
end
|
data/spec/support/bullet_ext.rb
CHANGED
|
@@ -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.
|
|
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.
|
|
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-
|
|
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:
|
|
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:
|
|
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.
|