bullet 4.0.0 → 4.13.1
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 +7 -0
- data/.gitignore +4 -0
- data/.rspec +1 -1
- data/.travis.yml +17 -6
- data/CHANGELOG.md +86 -0
- data/Gemfile +13 -12
- data/Gemfile.mongoid +14 -0
- data/Gemfile.mongoid-2.4 +19 -0
- data/Gemfile.mongoid-2.5 +19 -0
- data/Gemfile.mongoid-2.6 +19 -0
- data/Gemfile.mongoid-2.7 +19 -0
- data/Gemfile.mongoid-2.8 +19 -0
- data/Gemfile.mongoid-3.0 +19 -0
- data/Gemfile.mongoid-3.1 +19 -0
- data/Gemfile.mongoid-4.0 +19 -0
- data/Gemfile.rails-3.0 +19 -0
- data/Gemfile.rails-3.1 +19 -0
- data/Gemfile.rails-3.2 +19 -0
- data/Gemfile.rails-4.0 +19 -0
- data/Gemfile.rails-4.1 +19 -0
- data/{Hacking.textile → Hacking.md} +10 -5
- data/README.md +432 -0
- data/Rakefile +13 -6
- data/bullet.gemspec +6 -3
- data/lib/bullet/active_record3.rb +49 -11
- data/lib/bullet/active_record3x.rb +134 -0
- data/lib/bullet/{active_record31.rb → active_record4.rb} +45 -15
- data/lib/bullet/active_record41.rb +128 -0
- data/lib/bullet/dependency.rb +81 -0
- data/lib/bullet/detector/association.rb +24 -68
- data/lib/bullet/detector/base.rb +0 -6
- data/lib/bullet/detector/counter_cache.rb +59 -0
- data/lib/bullet/detector/n_plus_one_query.rb +56 -15
- data/lib/bullet/detector/unused_eager_loading.rb +84 -0
- data/lib/bullet/detector.rb +2 -2
- data/lib/bullet/ext/object.rb +10 -2
- data/lib/bullet/{mongoid.rb → mongoid2x.rb} +18 -18
- data/lib/bullet/mongoid3x.rb +56 -0
- data/lib/bullet/mongoid4x.rb +56 -0
- data/lib/bullet/notification/base.rb +22 -4
- data/lib/bullet/notification/n_plus_one_query.rb +1 -1
- data/lib/bullet/notification.rb +2 -0
- data/lib/bullet/rack.rb +51 -17
- data/lib/bullet/registry/base.rb +1 -1
- data/lib/bullet/registry/object.rb +4 -4
- data/lib/bullet/version.rb +1 -2
- data/lib/bullet.rb +119 -39
- data/perf/benchmark.rb +1 -4
- data/spec/bullet/detector/association_spec.rb +2 -70
- data/spec/bullet/detector/base_spec.rb +0 -6
- data/spec/bullet/detector/counter_cache_spec.rb +56 -0
- data/spec/bullet/detector/n_plus_one_query_spec.rb +78 -34
- data/spec/bullet/detector/unused_eager_loading_spec.rb +88 -0
- data/spec/bullet/ext/object_spec.rb +18 -7
- data/spec/bullet/ext/string_spec.rb +2 -2
- data/spec/bullet/notification/base_spec.rb +68 -15
- data/spec/bullet/notification/counter_cache_spec.rb +2 -2
- data/spec/bullet/notification/n_plus_one_query_spec.rb +4 -3
- data/spec/bullet/notification/unused_eager_loading_spec.rb +2 -2
- data/spec/bullet/notification_collector_spec.rb +4 -4
- data/spec/bullet/rack_spec.rb +40 -39
- data/spec/bullet/registry/association_spec.rb +3 -3
- data/spec/bullet/registry/base_spec.rb +6 -6
- data/spec/bullet/registry/object_spec.rb +4 -5
- data/spec/bullet_spec.rb +41 -0
- data/spec/integration/active_record3/association_spec.rb +662 -0
- data/spec/integration/active_record4/association_spec.rb +660 -0
- data/spec/integration/counter_cache_spec.rb +63 -0
- data/spec/integration/mongoid/association_spec.rb +190 -208
- data/spec/models/category.rb +1 -1
- data/spec/models/client.rb +1 -1
- data/spec/models/comment.rb +2 -2
- data/spec/models/document.rb +2 -2
- data/spec/models/firm.rb +1 -1
- data/spec/models/mongoid/address.rb +2 -0
- data/spec/models/mongoid/category.rb +2 -0
- data/spec/models/mongoid/comment.rb +2 -0
- data/spec/models/mongoid/company.rb +2 -0
- data/spec/models/mongoid/entry.rb +2 -0
- data/spec/models/mongoid/post.rb +4 -0
- data/spec/models/mongoid/user.rb +5 -0
- data/spec/models/newspaper.rb +1 -1
- data/spec/models/pet.rb +1 -1
- data/spec/models/post.rb +6 -13
- data/spec/spec_helper.rb +60 -25
- data/spec/support/bullet_ext.rb +1 -1
- data/spec/support/mongo_seed.rb +26 -2
- data/spec/support/sqlite_seed.rb +0 -6
- data/test.sh +15 -0
- metadata +77 -54
- data/.rvmrc +0 -2
- data/.rvmrc.example +0 -2
- data/Gemfile.lock +0 -132
- data/Gemfile.rails-2.3.14 +0 -16
- data/Gemfile.rails-2.3.14.lock +0 -65
- data/Gemfile.rails-3.0.12 +0 -17
- data/Gemfile.rails-3.0.12.lock +0 -116
- data/Gemfile.rails-3.1.4 +0 -18
- data/Gemfile.rails-3.1.4.lock +0 -134
- data/README.textile +0 -395
- data/README_for_rails2.textile +0 -400
- data/lib/bullet/action_controller2.rb +0 -49
- data/lib/bullet/active_record2.rb +0 -121
- data/lib/bullet/detector/counter.rb +0 -48
- data/lib/bullet/detector/unused_eager_association.rb +0 -42
- data/spec/bullet/detector/counter_spec.rb +0 -64
- data/spec/bullet/detector/unused_eager_association_spec.rb +0 -62
- data/spec/integration/association_spec.rb +0 -593
- data/spec/integration/counter_spec.rb +0 -39
- data/spec/integration/rails2/association_spec.rb +0 -593
- data/spec/integration/rails2/counter_spec.rb +0 -39
- data/test.result +0 -2293
|
@@ -1,20 +1,31 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Object do
|
|
4
|
-
context "
|
|
4
|
+
context "bullet_key" do
|
|
5
5
|
it "should return class and id composition" do
|
|
6
6
|
post = Post.first
|
|
7
|
-
post.
|
|
7
|
+
expect(post.bullet_key).to eq("Post:#{post.id}")
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
require 'mongoid'
|
|
12
|
-
|
|
10
|
+
if mongoid?
|
|
13
11
|
it "should return class with namesapce and id composition" do
|
|
14
12
|
post = Mongoid::Post.first
|
|
15
|
-
post.
|
|
13
|
+
expect(post.bullet_key).to eq("Mongoid::Post:#{post.id}")
|
|
16
14
|
end
|
|
17
|
-
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context "primary_key_value" do
|
|
19
|
+
it "should return id" do
|
|
20
|
+
post = Post.first
|
|
21
|
+
expect(post.primary_key_value).to eq(post.id)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "should return primary key value" do
|
|
25
|
+
post = Post.first
|
|
26
|
+
Post.primary_key = 'name'
|
|
27
|
+
expect(post.primary_key_value).to eq(post.name)
|
|
28
|
+
Post.primary_key = 'id'
|
|
18
29
|
end
|
|
19
30
|
end
|
|
20
31
|
end
|
|
@@ -3,11 +3,11 @@ require 'spec_helper'
|
|
|
3
3
|
describe String do
|
|
4
4
|
context "bullet_class_name" do
|
|
5
5
|
it "should only return class name" do
|
|
6
|
-
"Post:1".bullet_class_name.
|
|
6
|
+
expect("Post:1".bullet_class_name).to eq("Post")
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
it "should return class name with namespace" do
|
|
10
|
-
"Mongoid::Post:1234567890".bullet_class_name.
|
|
10
|
+
expect("Mongoid::Post:1234567890".bullet_class_name).to eq("Mongoid::Post")
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
end
|
|
@@ -7,58 +7,111 @@ module Bullet
|
|
|
7
7
|
|
|
8
8
|
context "#title" do
|
|
9
9
|
it "should raise NoMethodError" do
|
|
10
|
-
|
|
10
|
+
expect { subject.title }.to raise_error(NoMethodError)
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
context "#body" do
|
|
15
15
|
it "should raise NoMethodError" do
|
|
16
|
-
|
|
16
|
+
expect { subject.body }.to raise_error(NoMethodError)
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
context "#whoami" do
|
|
21
21
|
it "should display user name" do
|
|
22
22
|
user = `whoami`.chomp
|
|
23
|
-
subject.whoami.
|
|
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
|
|
28
57
|
it "should return body" do
|
|
29
|
-
subject.
|
|
30
|
-
subject.body_with_caller.
|
|
58
|
+
allow(subject).to receive(:body).and_return("body")
|
|
59
|
+
expect(subject.body_with_caller).to eq("body")
|
|
31
60
|
end
|
|
32
61
|
end
|
|
33
62
|
|
|
34
63
|
context "#standard_notice" do
|
|
35
64
|
it "should return title + body" do
|
|
36
|
-
subject.
|
|
37
|
-
subject.
|
|
65
|
+
allow(subject).to receive(:title).and_return("title")
|
|
66
|
+
allow(subject).to receive(:body).and_return("body")
|
|
67
|
+
expect(subject.standard_notice).to eq("title\nbody")
|
|
38
68
|
end
|
|
39
69
|
end
|
|
40
70
|
|
|
41
71
|
context "#full_notice" do
|
|
42
72
|
it "should return whoami + url + title + body_with_caller" do
|
|
43
|
-
subject.
|
|
44
|
-
subject.
|
|
73
|
+
allow(subject).to receive(:whoami).and_return("whoami")
|
|
74
|
+
allow(subject).to receive(:url).and_return("url")
|
|
75
|
+
allow(subject).to receive(:title).and_return("title")
|
|
76
|
+
allow(subject).to receive(:body_with_caller).and_return("body_with_caller")
|
|
77
|
+
expect(subject.full_notice).to eq("whoami\nurl\ntitle\nbody_with_caller")
|
|
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
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
context "#notification_data" do
|
|
90
|
+
it "should return notification data" do
|
|
91
|
+
allow(subject).to receive(:whoami).and_return("whoami")
|
|
92
|
+
allow(subject).to receive(:url).and_return("url")
|
|
93
|
+
allow(subject).to receive(:title).and_return("title")
|
|
94
|
+
allow(subject).to receive(:body_with_caller).and_return("body_with_caller")
|
|
95
|
+
expect(subject.notification_data).to eq(:user => "whoami", :url => "url", :title => "title", :body => "body_with_caller")
|
|
45
96
|
end
|
|
46
97
|
end
|
|
47
98
|
|
|
48
99
|
context "#notify_inline" do
|
|
49
100
|
it "should send full_notice to notifier" do
|
|
50
|
-
notifier =
|
|
51
|
-
subject.
|
|
52
|
-
|
|
101
|
+
notifier = double
|
|
102
|
+
allow(subject).to receive(:notifier).and_return(notifier)
|
|
103
|
+
allow(subject).to receive(:notification_data).and_return(:foo => :bar)
|
|
104
|
+
expect(notifier).to receive(:inline_notify).with(:foo => :bar)
|
|
53
105
|
subject.notify_inline
|
|
54
106
|
end
|
|
55
107
|
end
|
|
56
108
|
|
|
57
109
|
context "#notify_out_of_channel" do
|
|
58
110
|
it "should send full_out_of_channel to notifier" do
|
|
59
|
-
notifier =
|
|
60
|
-
subject.
|
|
61
|
-
|
|
111
|
+
notifier = double
|
|
112
|
+
allow(subject).to receive(:notifier).and_return(notifier)
|
|
113
|
+
allow(subject).to receive(:notification_data).and_return(:foo => :bar)
|
|
114
|
+
expect(notifier).to receive(:out_of_channel_notify).with(:foo => :bar)
|
|
62
115
|
subject.notify_out_of_channel
|
|
63
116
|
end
|
|
64
117
|
end
|
|
@@ -5,8 +5,8 @@ module Bullet
|
|
|
5
5
|
describe CounterCache do
|
|
6
6
|
subject { CounterCache.new(Post, [:comments, :votes]) }
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
it { expect(subject.body).to eq(" Post => [:comments, :votes]") }
|
|
9
|
+
it { expect(subject.title).to eq("Need Counter Cache") }
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
end
|
|
@@ -5,9 +5,10 @@ module Bullet
|
|
|
5
5
|
describe NPlusOneQuery do
|
|
6
6
|
subject { NPlusOneQuery.new([["caller1", "caller2"]], Post, [:comments, :votes], "path") }
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
it { expect(subject.body_with_caller).to eq(" Post => [:comments, :votes]\n Add to your finder: :include => [:comments, :votes]\nN+1 Query method call stack\n caller1\n caller2") }
|
|
9
|
+
it { expect([ subject.body_with_caller, subject.body_with_caller]).to eq([ " Post => [:comments, :votes]\n Add to your finder: :include => [:comments, :votes]\nN+1 Query method call stack\n caller1\n caller2", " Post => [:comments, :votes]\n Add to your finder: :include => [:comments, :votes]\nN+1 Query method call stack\n caller1\n caller2" ]) }
|
|
10
|
+
it { expect(subject.body).to eq(" Post => [:comments, :votes]\n Add to your finder: :include => [:comments, :votes]") }
|
|
11
|
+
it { expect(subject.title).to eq("N+1 Query in path") }
|
|
11
12
|
end
|
|
12
13
|
end
|
|
13
14
|
end
|
|
@@ -5,8 +5,8 @@ module Bullet
|
|
|
5
5
|
describe UnusedEagerLoading do
|
|
6
6
|
subject { UnusedEagerLoading.new(Post, [:comments, :votes], "path") }
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
it { expect(subject.body).to eq(" Post => [:comments, :votes]\n Remove from your finder: :include => [:comments, :votes]") }
|
|
9
|
+
it { expect(subject.title).to eq("Unused Eager Loading in path") }
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
end
|
|
@@ -7,25 +7,25 @@ module Bullet
|
|
|
7
7
|
context "#add" do
|
|
8
8
|
it "should add a value" do
|
|
9
9
|
subject.add("value1")
|
|
10
|
-
subject.collection.
|
|
10
|
+
expect(subject.collection).to be_include("value1")
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
context "#reset" do
|
|
15
15
|
it "should reset collector" do
|
|
16
16
|
subject.reset
|
|
17
|
-
subject.collection.
|
|
17
|
+
expect(subject.collection).to be_empty
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
context "#notifications_present?" do
|
|
22
22
|
it "should be true if collection is not empty" do
|
|
23
|
-
subject.
|
|
23
|
+
expect(subject).to be_notifications_present
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
it "should be false if collection is empty" do
|
|
27
27
|
subject.reset
|
|
28
|
-
subject.
|
|
28
|
+
expect(subject).not_to be_notifications_present
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
end
|
data/spec/bullet/rack_spec.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
1
2
|
require 'spec_helper'
|
|
2
3
|
|
|
3
4
|
module Bullet
|
|
@@ -5,89 +6,89 @@ module Bullet
|
|
|
5
6
|
let(:middleware) { Bullet::Rack.new app }
|
|
6
7
|
let(:app) { Support::AppDouble.new }
|
|
7
8
|
|
|
8
|
-
context "#no_browser_cache" do
|
|
9
|
-
it "should add no cache meta in http headers" do
|
|
10
|
-
headers = {}
|
|
11
|
-
middleware.no_browser_cache(headers)
|
|
12
|
-
headers["Cache-Control"].should == "no-cache, no-store, max-age=0, must-revalidate"
|
|
13
|
-
headers["Pragma"].should == "no-cache"
|
|
14
|
-
headers["Expires"].should == "Wed, 09 Sep 2009 09:09:09 GMT"
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
9
|
context "#html_request?" do
|
|
19
10
|
it "should be true if Content-Type is text/html and http body contains html tag" do
|
|
20
11
|
headers = {"Content-Type" => "text/html"}
|
|
21
|
-
response =
|
|
22
|
-
middleware.
|
|
12
|
+
response = double(:body => "<html><head></head><body></body></html>")
|
|
13
|
+
expect(middleware).to be_html_request(headers, response)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should be true if Content-Type is text/html and http body contains html tag with attributes" do
|
|
17
|
+
headers = {"Content-Type" => "text/html"}
|
|
18
|
+
response = double(:body => "<html attr='hello'><head></head><body></body></html>")
|
|
19
|
+
expect(middleware).to be_html_request(headers, response)
|
|
23
20
|
end
|
|
24
21
|
|
|
25
22
|
it "should be false if there is no Content-Type header" do
|
|
26
23
|
headers = {}
|
|
27
|
-
response =
|
|
28
|
-
middleware.
|
|
24
|
+
response = double(:body => "<html><head></head><body></body></html>")
|
|
25
|
+
expect(middleware).not_to be_html_request(headers, response)
|
|
29
26
|
end
|
|
30
27
|
|
|
31
28
|
it "should be false if Content-Type is javascript" do
|
|
32
29
|
headers = {"Content-Type" => "text/javascript"}
|
|
33
|
-
response =
|
|
34
|
-
middleware.
|
|
30
|
+
response = double(:body => "<html><head></head><body></body></html>")
|
|
31
|
+
expect(middleware).not_to be_html_request(headers, response)
|
|
35
32
|
end
|
|
36
33
|
|
|
37
34
|
it "should be false if response body doesn't contain html tag" do
|
|
38
35
|
headers = {"Content-Type" => "text/html"}
|
|
39
|
-
response =
|
|
40
|
-
middleware.
|
|
36
|
+
response = double(:body => "<div>Partial</div>")
|
|
37
|
+
expect(middleware).not_to be_html_request(headers, response)
|
|
41
38
|
end
|
|
42
39
|
end
|
|
43
40
|
|
|
44
41
|
context "empty?" do
|
|
45
42
|
it "should be false if response is a string and not empty" do
|
|
46
|
-
response =
|
|
47
|
-
middleware.
|
|
43
|
+
response = double(:body => "<html><head></head><body></body></html>")
|
|
44
|
+
expect(middleware).not_to be_empty(response)
|
|
48
45
|
end
|
|
49
46
|
|
|
50
|
-
it "should be
|
|
47
|
+
it "should be true if response is not found" do
|
|
51
48
|
response = ["Not Found"]
|
|
52
|
-
middleware.
|
|
49
|
+
expect(middleware).to be_empty(response)
|
|
53
50
|
end
|
|
54
51
|
|
|
55
52
|
it "should be true if response body is empty" do
|
|
56
|
-
response =
|
|
57
|
-
middleware.
|
|
53
|
+
response = double(:body => "")
|
|
54
|
+
expect(middleware).to be_empty(response)
|
|
58
55
|
end
|
|
59
56
|
end
|
|
60
57
|
|
|
61
58
|
context "#call" do
|
|
62
59
|
context "when Bullet is enabled" do
|
|
63
|
-
it "should invoke Bullet.start_request and Bullet.end_request" do
|
|
64
|
-
Bullet.should_receive(:start_request)
|
|
65
|
-
Bullet.should_receive(:end_request)
|
|
66
|
-
middleware.call([])
|
|
67
|
-
end
|
|
68
|
-
|
|
69
60
|
it "should return original response body" do
|
|
70
61
|
expected_response = Support::ResponseDouble.new "Actual body"
|
|
71
62
|
app.response = expected_response
|
|
72
|
-
|
|
73
|
-
response.
|
|
63
|
+
_, _, response = middleware.call([])
|
|
64
|
+
expect(response).to eq(expected_response)
|
|
74
65
|
end
|
|
75
66
|
|
|
76
67
|
it "should change response body if notification is active" do
|
|
77
|
-
Bullet.
|
|
78
|
-
Bullet.
|
|
79
|
-
Bullet.
|
|
68
|
+
expect(Bullet).to receive(:notification?).and_return(true).twice
|
|
69
|
+
expect(Bullet).to receive(:gather_inline_notifications).and_return("<bullet></bullet>")
|
|
70
|
+
expect(Bullet).to receive(:perform_out_of_channel_notifications)
|
|
71
|
+
status, headers, response = middleware.call([200, {"Content-Type" => "text/html"}])
|
|
72
|
+
expect(headers["Content-Length"]).to eq("56")
|
|
73
|
+
expect(response).to eq(["<html><head></head><body></body></html><bullet></bullet>"])
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "should set the right Content-Length if response body contains accents" do
|
|
77
|
+
response = Support::ResponseDouble.new
|
|
78
|
+
response.body = "<html><head></head><body>é</body></html>"
|
|
79
|
+
app.response = response
|
|
80
|
+
expect(Bullet).to receive(:notification?).and_return(true).twice
|
|
81
|
+
expect(Bullet).to receive(:gather_inline_notifications).and_return("<bullet></bullet>")
|
|
80
82
|
status, headers, response = middleware.call([200, {"Content-Type" => "text/html"}])
|
|
81
|
-
headers["Content-Length"].
|
|
82
|
-
response.should == ["<html><head></head><body></body></html><bullet></bullet>"]
|
|
83
|
+
expect(headers["Content-Length"]).to eq("58")
|
|
83
84
|
end
|
|
84
85
|
end
|
|
85
86
|
|
|
86
87
|
context "when Bullet is disabled" do
|
|
87
|
-
before(:each) { Bullet.
|
|
88
|
+
before(:each) { allow(Bullet).to receive(:enable?).and_return(false) }
|
|
88
89
|
|
|
89
90
|
it "should not call Bullet.start_request" do
|
|
90
|
-
Bullet.
|
|
91
|
+
expect(Bullet).not_to receive(:start_request)
|
|
91
92
|
middleware.call([])
|
|
92
93
|
end
|
|
93
94
|
end
|
|
@@ -8,17 +8,17 @@ module Bullet
|
|
|
8
8
|
context "#merge" do
|
|
9
9
|
it "should merge key/value" do
|
|
10
10
|
subject.merge("key0", "value0")
|
|
11
|
-
subject["key0"].
|
|
11
|
+
expect(subject["key0"]).to be_include("value0")
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
context "#similarly_associated" do
|
|
16
16
|
it "should return similarly associated keys" do
|
|
17
|
-
subject.similarly_associated("key1", Set.new(["value"])).
|
|
17
|
+
expect(subject.similarly_associated("key1", Set.new(["value"]))).to eq(["key1", "key2"])
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
it "should return empty if key does not exist" do
|
|
21
|
-
subject.similarly_associated("key3", Set.new(["value"])).
|
|
21
|
+
expect(subject.similarly_associated("key3", Set.new(["value"]))).to be_empty
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
end
|
|
@@ -7,36 +7,36 @@ module Bullet
|
|
|
7
7
|
|
|
8
8
|
context "#[]" do
|
|
9
9
|
it "should get value by key" do
|
|
10
|
-
subject["key"].
|
|
10
|
+
expect(subject["key"]).to eq(Set.new(["value"]))
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
context "#delete" do
|
|
15
15
|
it "should delete key" do
|
|
16
16
|
subject.delete("key")
|
|
17
|
-
subject["key"].
|
|
17
|
+
expect(subject["key"]).to be_nil
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
context "#add" do
|
|
22
22
|
it "should add value with string" do
|
|
23
23
|
subject.add("key", "new_value")
|
|
24
|
-
subject["key"].
|
|
24
|
+
expect(subject["key"]).to eq(Set.new(["value", "new_value"]))
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
it "should add value with array" do
|
|
28
28
|
subject.add("key", ["value1", "value2"])
|
|
29
|
-
subject["key"].
|
|
29
|
+
expect(subject["key"]).to eq(Set.new(["value", "value1", "value2"]))
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
context "#include?" do
|
|
34
34
|
it "should include key/value" do
|
|
35
|
-
subject.include?("key", "value").
|
|
35
|
+
expect(subject.include?("key", "value")).to eq true
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
it "should not include wrong key/value" do
|
|
39
|
-
subject.include?("key", "val").
|
|
39
|
+
expect(subject.include?("key", "val")).to eq false
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
42
|
end
|
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
|
|
4
3
|
module Bullet
|
|
5
4
|
module Registry
|
|
6
5
|
describe Object do
|
|
7
6
|
let(:post) { Post.first }
|
|
8
7
|
let(:another_post) { Post.last }
|
|
9
|
-
subject { Object.new.tap { |object| object.add(post.
|
|
8
|
+
subject { Object.new.tap { |object| object.add(post.bullet_key) } }
|
|
10
9
|
|
|
11
10
|
context "#include?" do
|
|
12
11
|
it "should include the object" do
|
|
13
|
-
subject.
|
|
12
|
+
expect(subject).to be_include(post.bullet_key)
|
|
14
13
|
end
|
|
15
14
|
end
|
|
16
15
|
|
|
17
16
|
context "#add" do
|
|
18
17
|
it "should add an object" do
|
|
19
|
-
subject.add(another_post.
|
|
20
|
-
subject.
|
|
18
|
+
subject.add(another_post.bullet_key)
|
|
19
|
+
expect(subject).to be_include(another_post.bullet_key)
|
|
21
20
|
end
|
|
22
21
|
end
|
|
23
22
|
end
|
data/spec/bullet_spec.rb
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Bullet, focused: true do
|
|
4
|
+
subject { Bullet }
|
|
5
|
+
|
|
6
|
+
describe '#enable' do
|
|
7
|
+
|
|
8
|
+
context 'enable Bullet' do
|
|
9
|
+
before do
|
|
10
|
+
# Bullet.enable
|
|
11
|
+
# Do nothing. Bullet has already been enabled for the whole test suite.
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'should be enabled' do
|
|
15
|
+
expect(subject).to be_enable
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context 'disable Bullet' do
|
|
19
|
+
before do
|
|
20
|
+
Bullet.enable = false
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'should be disabled' do
|
|
24
|
+
expect(subject).to_not be_enable
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context 'enable Bullet again without patching again the orms' do
|
|
28
|
+
before do
|
|
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
|
+
Bullet.enable = true
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'should be enabled again' do
|
|
35
|
+
expect(subject).to be_enable
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|