bullet 5.5.0 → 6.1.5
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 +5 -5
- data/.github/workflows/main.yml +66 -0
- data/CHANGELOG.md +83 -1
- data/Gemfile +6 -1
- data/Gemfile.mongoid-7.0 +15 -0
- data/Gemfile.rails-4.0 +1 -1
- data/Gemfile.rails-4.1 +1 -1
- data/Gemfile.rails-4.2 +1 -1
- data/Gemfile.rails-5.0 +2 -2
- data/Gemfile.rails-5.1 +15 -0
- data/Gemfile.rails-5.2 +15 -0
- data/Gemfile.rails-6.0 +15 -0
- data/Gemfile.rails-6.1 +15 -0
- data/Guardfile +2 -2
- data/Hacking.md +1 -1
- data/README.md +58 -37
- data/Rakefile +20 -21
- data/bullet.gemspec +21 -15
- data/lib/bullet/active_job.rb +13 -0
- data/lib/bullet/active_record4.rb +15 -34
- data/lib/bullet/active_record41.rb +14 -31
- data/lib/bullet/active_record42.rb +23 -36
- data/lib/bullet/active_record5.rb +178 -158
- data/lib/bullet/active_record52.rb +251 -0
- data/lib/bullet/active_record60.rb +278 -0
- data/lib/bullet/active_record61.rb +278 -0
- data/lib/bullet/bullet_xhr.js +64 -0
- data/lib/bullet/dependency.rb +60 -32
- data/lib/bullet/detector/association.rb +41 -32
- data/lib/bullet/detector/base.rb +2 -0
- data/lib/bullet/detector/counter_cache.rb +25 -17
- data/lib/bullet/detector/n_plus_one_query.rb +38 -24
- data/lib/bullet/detector/unused_eager_loading.rb +35 -26
- data/lib/bullet/detector.rb +2 -0
- data/lib/bullet/ext/object.rb +9 -5
- data/lib/bullet/ext/string.rb +3 -1
- data/lib/bullet/mongoid4x.rb +9 -8
- data/lib/bullet/mongoid5x.rb +9 -8
- data/lib/bullet/mongoid6x.rb +13 -12
- data/lib/bullet/mongoid7x.rb +57 -0
- data/lib/bullet/notification/base.rb +28 -25
- data/lib/bullet/notification/counter_cache.rb +3 -1
- data/lib/bullet/notification/n_plus_one_query.rb +8 -7
- data/lib/bullet/notification/unused_eager_loading.rb +8 -7
- data/lib/bullet/notification.rb +4 -1
- data/lib/bullet/notification_collector.rb +2 -1
- data/lib/bullet/rack.rb +66 -35
- data/lib/bullet/registry/association.rb +2 -0
- data/lib/bullet/registry/base.rb +2 -0
- data/lib/bullet/registry/object.rb +2 -0
- data/lib/bullet/registry.rb +2 -0
- data/lib/bullet/stack_trace_filter.rb +50 -20
- data/lib/bullet/version.rb +3 -2
- data/lib/bullet.rb +136 -55
- data/lib/generators/bullet/install_generator.rb +48 -0
- data/perf/benchmark.rb +19 -22
- data/rails/init.rb +2 -0
- data/spec/bullet/detector/association_spec.rb +6 -4
- data/spec/bullet/detector/base_spec.rb +2 -0
- data/spec/bullet/detector/counter_cache_spec.rb +17 -15
- data/spec/bullet/detector/n_plus_one_query_spec.rb +75 -46
- data/spec/bullet/detector/unused_eager_loading_spec.rb +45 -26
- data/spec/bullet/ext/object_spec.rb +18 -11
- data/spec/bullet/ext/string_spec.rb +7 -5
- data/spec/bullet/notification/base_spec.rb +38 -39
- data/spec/bullet/notification/counter_cache_spec.rb +5 -3
- data/spec/bullet/notification/n_plus_one_query_spec.rb +20 -5
- data/spec/bullet/notification/unused_eager_loading_spec.rb +9 -3
- data/spec/bullet/notification_collector_spec.rb +12 -10
- data/spec/bullet/rack_spec.rb +200 -48
- data/spec/bullet/registry/association_spec.rb +12 -10
- data/spec/bullet/registry/base_spec.rb +22 -20
- data/spec/bullet/registry/object_spec.rb +6 -4
- data/spec/bullet_spec.rb +64 -33
- data/spec/integration/{active_record4 → active_record}/association_spec.rb +238 -223
- data/spec/integration/counter_cache_spec.rb +26 -44
- data/spec/integration/mongoid/association_spec.rb +53 -65
- data/spec/models/address.rb +2 -0
- data/spec/models/attachment.rb +5 -0
- data/spec/models/author.rb +2 -0
- data/spec/models/base_user.rb +2 -0
- data/spec/models/category.rb +2 -0
- data/spec/models/city.rb +2 -0
- data/spec/models/client.rb +4 -0
- data/spec/models/comment.rb +3 -1
- data/spec/models/company.rb +2 -0
- data/spec/models/country.rb +2 -0
- data/spec/models/deal.rb +5 -0
- data/spec/models/document.rb +4 -2
- data/spec/models/entry.rb +2 -0
- data/spec/models/firm.rb +3 -0
- data/spec/models/folder.rb +2 -0
- data/spec/models/group.rb +4 -0
- data/spec/models/mongoid/address.rb +3 -1
- data/spec/models/mongoid/category.rb +4 -2
- data/spec/models/mongoid/comment.rb +3 -1
- data/spec/models/mongoid/company.rb +3 -1
- data/spec/models/mongoid/entry.rb +3 -1
- data/spec/models/mongoid/post.rb +6 -4
- data/spec/models/mongoid/user.rb +2 -0
- data/spec/models/newspaper.rb +3 -1
- data/spec/models/page.rb +2 -0
- data/spec/models/person.rb +2 -0
- data/spec/models/pet.rb +2 -0
- data/spec/models/post.rb +19 -0
- data/spec/models/relationship.rb +2 -0
- data/spec/models/reply.rb +2 -0
- data/spec/models/student.rb +2 -0
- data/spec/models/submission.rb +3 -0
- data/spec/models/teacher.rb +2 -0
- data/spec/models/user.rb +3 -0
- data/spec/models/writer.rb +2 -0
- data/spec/spec_helper.rb +19 -23
- data/spec/support/bullet_ext.rb +10 -9
- data/spec/support/mongo_seed.rb +38 -57
- data/spec/support/rack_double.rb +13 -19
- data/spec/support/sqlite_seed.rb +104 -76
- data/tasks/bullet_tasks.rake +4 -2
- data/test.sh +5 -0
- data/update.sh +3 -0
- metadata +34 -17
- data/.travis.yml +0 -16
- data/spec/integration/active_record5/association_spec.rb +0 -768
|
@@ -1,29 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
module Bullet
|
|
4
6
|
describe NotificationCollector do
|
|
5
|
-
subject { NotificationCollector.new.tap { |collector| collector.add(
|
|
7
|
+
subject { NotificationCollector.new.tap { |collector| collector.add('value') } }
|
|
6
8
|
|
|
7
|
-
context
|
|
8
|
-
it
|
|
9
|
-
subject.add(
|
|
10
|
-
expect(subject.collection).to be_include(
|
|
9
|
+
context '#add' do
|
|
10
|
+
it 'should add a value' do
|
|
11
|
+
subject.add('value1')
|
|
12
|
+
expect(subject.collection).to be_include('value1')
|
|
11
13
|
end
|
|
12
14
|
end
|
|
13
15
|
|
|
14
|
-
context
|
|
15
|
-
it
|
|
16
|
+
context '#reset' do
|
|
17
|
+
it 'should reset collector' do
|
|
16
18
|
subject.reset
|
|
17
19
|
expect(subject.collection).to be_empty
|
|
18
20
|
end
|
|
19
21
|
end
|
|
20
22
|
|
|
21
|
-
context
|
|
22
|
-
it
|
|
23
|
+
context '#notifications_present?' do
|
|
24
|
+
it 'should be true if collection is not empty' do
|
|
23
25
|
expect(subject).to be_notifications_present
|
|
24
26
|
end
|
|
25
27
|
|
|
26
|
-
it
|
|
28
|
+
it 'should be false if collection is empty' do
|
|
27
29
|
subject.reset
|
|
28
30
|
expect(subject).not_to be_notifications_present
|
|
29
31
|
end
|
data/spec/bullet/rack_spec.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
require 'spec_helper'
|
|
3
4
|
|
|
4
5
|
module Bullet
|
|
@@ -6,123 +7,274 @@ module Bullet
|
|
|
6
7
|
let(:middleware) { Bullet::Rack.new app }
|
|
7
8
|
let(:app) { Support::AppDouble.new }
|
|
8
9
|
|
|
9
|
-
context
|
|
10
|
-
it
|
|
11
|
-
headers = {
|
|
12
|
-
response = double(:
|
|
10
|
+
context '#html_request?' do
|
|
11
|
+
it 'should be true if Content-Type is text/html and http body contains html tag' do
|
|
12
|
+
headers = { 'Content-Type' => 'text/html' }
|
|
13
|
+
response = double(body: '<html><head></head><body></body></html>')
|
|
13
14
|
expect(middleware).to be_html_request(headers, response)
|
|
14
15
|
end
|
|
15
16
|
|
|
16
|
-
it
|
|
17
|
-
headers = {
|
|
18
|
-
response = double(:
|
|
17
|
+
it 'should be true if Content-Type is text/html and http body contains html tag with attributes' do
|
|
18
|
+
headers = { 'Content-Type' => 'text/html' }
|
|
19
|
+
response = double(body: "<html attr='hello'><head></head><body></body></html>")
|
|
19
20
|
expect(middleware).to be_html_request(headers, response)
|
|
20
21
|
end
|
|
21
22
|
|
|
22
|
-
it
|
|
23
|
+
it 'should be false if there is no Content-Type header' do
|
|
23
24
|
headers = {}
|
|
24
|
-
response = double(:
|
|
25
|
+
response = double(body: '<html><head></head><body></body></html>')
|
|
25
26
|
expect(middleware).not_to be_html_request(headers, response)
|
|
26
27
|
end
|
|
27
28
|
|
|
28
|
-
it
|
|
29
|
-
headers = {
|
|
30
|
-
response = double(:
|
|
29
|
+
it 'should be false if Content-Type is javascript' do
|
|
30
|
+
headers = { 'Content-Type' => 'text/javascript' }
|
|
31
|
+
response = double(body: '<html><head></head><body></body></html>')
|
|
31
32
|
expect(middleware).not_to be_html_request(headers, response)
|
|
32
33
|
end
|
|
33
34
|
|
|
34
35
|
it "should be false if response body doesn't contain html tag" do
|
|
35
|
-
headers = {
|
|
36
|
-
response = double(:
|
|
36
|
+
headers = { 'Content-Type' => 'text/html' }
|
|
37
|
+
response = double(body: '<div>Partial</div>')
|
|
37
38
|
expect(middleware).not_to be_html_request(headers, response)
|
|
38
39
|
end
|
|
39
40
|
end
|
|
40
41
|
|
|
41
|
-
context
|
|
42
|
-
it
|
|
43
|
-
response = double(:
|
|
42
|
+
context 'empty?' do
|
|
43
|
+
it 'should be false if response is a string and not empty' do
|
|
44
|
+
response = double(body: '<html><head></head><body></body></html>')
|
|
44
45
|
expect(middleware).not_to be_empty(response)
|
|
45
46
|
end
|
|
46
47
|
|
|
47
|
-
it
|
|
48
|
-
response = [
|
|
49
|
-
expect(middleware).
|
|
48
|
+
it 'should be false if response is not found' do
|
|
49
|
+
response = ['Not Found']
|
|
50
|
+
expect(middleware).not_to be_empty(response)
|
|
50
51
|
end
|
|
51
52
|
|
|
52
|
-
it
|
|
53
|
-
response = double(:
|
|
53
|
+
it 'should be true if response body is empty' do
|
|
54
|
+
response = double(body: '')
|
|
54
55
|
expect(middleware).to be_empty(response)
|
|
55
56
|
end
|
|
56
57
|
end
|
|
57
58
|
|
|
58
|
-
context
|
|
59
|
-
context
|
|
60
|
-
it
|
|
61
|
-
expected_response = Support::ResponseDouble.new
|
|
59
|
+
context '#call' do
|
|
60
|
+
context 'when Bullet is enabled' do
|
|
61
|
+
it 'should return original response body' do
|
|
62
|
+
expected_response = Support::ResponseDouble.new 'Actual body'
|
|
62
63
|
app.response = expected_response
|
|
63
64
|
_, _, response = middleware.call({})
|
|
64
65
|
expect(response).to eq(expected_response)
|
|
65
66
|
end
|
|
66
67
|
|
|
67
|
-
it
|
|
68
|
+
it 'should change response body if notification is active' do
|
|
68
69
|
expect(Bullet).to receive(:notification?).and_return(true)
|
|
69
|
-
expect(Bullet).to receive(:
|
|
70
|
+
expect(Bullet).to receive(:console_enabled?).and_return(true)
|
|
71
|
+
expect(Bullet).to receive(:gather_inline_notifications).and_return('<bullet></bullet>')
|
|
70
72
|
expect(Bullet).to receive(:perform_out_of_channel_notifications)
|
|
71
|
-
|
|
72
|
-
expect(headers[
|
|
73
|
-
expect(response).to eq([
|
|
73
|
+
_, headers, response = middleware.call('Content-Type' => 'text/html')
|
|
74
|
+
expect(headers['Content-Length']).to eq('56')
|
|
75
|
+
expect(response).to eq(%w[<html><head></head><body><bullet></bullet></body></html>])
|
|
74
76
|
end
|
|
75
77
|
|
|
76
|
-
it
|
|
78
|
+
it 'should set the right Content-Length if response body contains accents' do
|
|
77
79
|
response = Support::ResponseDouble.new
|
|
78
|
-
response.body =
|
|
80
|
+
response.body = '<html><head></head><body>é</body></html>'
|
|
79
81
|
app.response = response
|
|
80
82
|
expect(Bullet).to receive(:notification?).and_return(true)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
allow(Bullet).to receive(:console_enabled?).and_return(true)
|
|
84
|
+
expect(Bullet).to receive(:gather_inline_notifications).and_return('<bullet></bullet>')
|
|
85
|
+
_, headers, response = middleware.call('Content-Type' => 'text/html')
|
|
86
|
+
expect(headers['Content-Length']).to eq('58')
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
context 'with injection notifiers' do
|
|
90
|
+
before do
|
|
91
|
+
expect(Bullet).to receive(:notification?).and_return(true)
|
|
92
|
+
allow(Bullet).to receive(:gather_inline_notifications).and_return('<bullet></bullet>')
|
|
93
|
+
allow(middleware).to receive(:xhr_script).and_return('<script></script>')
|
|
94
|
+
allow(middleware).to receive(:footer_note).and_return('footer')
|
|
95
|
+
expect(Bullet).to receive(:perform_out_of_channel_notifications)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it 'should change response body if add_footer is true' do
|
|
99
|
+
expect(Bullet).to receive(:add_footer).exactly(3).times.and_return(true)
|
|
100
|
+
_, headers, response = middleware.call('Content-Type' => 'text/html')
|
|
101
|
+
|
|
102
|
+
expect(headers['Content-Length']).to eq((73 + middleware.send(:footer_note).length).to_s)
|
|
103
|
+
expect(response).to eq(%w[<html><head></head><body>footer<bullet></bullet><script></script></body></html>])
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
it 'should change response body for html safe string if add_footer is true' do
|
|
107
|
+
expect(Bullet).to receive(:add_footer).exactly(3).times.and_return(true)
|
|
108
|
+
app.response =
|
|
109
|
+
Support::ResponseDouble.new.tap do |response|
|
|
110
|
+
response.body = ActiveSupport::SafeBuffer.new('<html><head></head><body></body></html>')
|
|
111
|
+
end
|
|
112
|
+
_, headers, response = middleware.call('Content-Type' => 'text/html')
|
|
113
|
+
|
|
114
|
+
expect(headers['Content-Length']).to eq((73 + middleware.send(:footer_note).length).to_s)
|
|
115
|
+
expect(response).to eq(%w[<html><head></head><body>footer<bullet></bullet><script></script></body></html>])
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it 'should add the footer-text header for non-html requests when add_footer is true' do
|
|
119
|
+
allow(Bullet).to receive(:add_footer).at_least(:once).and_return(true)
|
|
120
|
+
allow(Bullet).to receive(:footer_info).and_return(['footer text'])
|
|
121
|
+
app.headers = { 'Content-Type' => 'application/json' }
|
|
122
|
+
_, headers, _response = middleware.call({})
|
|
123
|
+
expect(headers).to include('X-bullet-footer-text' => '["footer text"]')
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it 'should change response body if console_enabled is true' do
|
|
127
|
+
expect(Bullet).to receive(:console_enabled?).and_return(true)
|
|
128
|
+
_, headers, response = middleware.call('Content-Type' => 'text/html')
|
|
129
|
+
expect(headers['Content-Length']).to eq('56')
|
|
130
|
+
expect(response).to eq(%w[<html><head></head><body><bullet></bullet></body></html>])
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it 'should change response body for html safe string if console_enabled is true' do
|
|
134
|
+
expect(Bullet).to receive(:console_enabled?).and_return(true)
|
|
135
|
+
app.response =
|
|
136
|
+
Support::ResponseDouble.new.tap do |response|
|
|
137
|
+
response.body = ActiveSupport::SafeBuffer.new('<html><head></head><body></body></html>')
|
|
138
|
+
end
|
|
139
|
+
_, headers, response = middleware.call('Content-Type' => 'text/html')
|
|
140
|
+
expect(headers['Content-Length']).to eq('56')
|
|
141
|
+
expect(response).to eq(%w[<html><head></head><body><bullet></bullet></body></html>])
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it 'should add headers for non-html requests when console_enabled is true' do
|
|
145
|
+
allow(Bullet).to receive(:console_enabled?).at_least(:once).and_return(true)
|
|
146
|
+
allow(Bullet).to receive(:text_notifications).and_return(['text notifications'])
|
|
147
|
+
app.headers = { 'Content-Type' => 'application/json' }
|
|
148
|
+
_, headers, _response = middleware.call({})
|
|
149
|
+
expect(headers).to include('X-bullet-console-text' => '["text notifications"]')
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it "shouldn't change response body unnecessarily" do
|
|
153
|
+
expected_response = Support::ResponseDouble.new 'Actual body'
|
|
154
|
+
app.response = expected_response
|
|
155
|
+
_, _, response = middleware.call({})
|
|
156
|
+
expect(response).to eq(expected_response)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
it "shouldn't add headers unnecessarily" do
|
|
160
|
+
app.headers = { 'Content-Type' => 'application/json' }
|
|
161
|
+
_, headers, _response = middleware.call({})
|
|
162
|
+
expect(headers).not_to include('X-bullet-footer-text')
|
|
163
|
+
expect(headers).not_to include('X-bullet-console-text')
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
context 'when skip_http_headers is enabled' do
|
|
167
|
+
before do
|
|
168
|
+
allow(Bullet).to receive(:skip_http_headers).and_return(true)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
it 'should include the footer but not the xhr script tag if add_footer is true' do
|
|
172
|
+
expect(Bullet).to receive(:add_footer).at_least(:once).and_return(true)
|
|
173
|
+
_, headers, response = middleware.call({})
|
|
174
|
+
|
|
175
|
+
expect(headers['Content-Length']).to eq((56 + middleware.send(:footer_note).length).to_s)
|
|
176
|
+
expect(response).to eq(%w[<html><head></head><body>footer<bullet></bullet></body></html>])
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
it 'should not include the xhr script tag if console_enabled is true' do
|
|
180
|
+
expect(Bullet).to receive(:console_enabled?).and_return(true)
|
|
181
|
+
_, headers, response = middleware.call({})
|
|
182
|
+
expect(headers['Content-Length']).to eq('56')
|
|
183
|
+
expect(response).to eq(%w[<html><head></head><body><bullet></bullet></body></html>])
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
it 'should not add the footer-text header for non-html requests when add_footer is true' do
|
|
187
|
+
allow(Bullet).to receive(:add_footer).at_least(:once).and_return(true)
|
|
188
|
+
app.headers = { 'Content-Type' => 'application/json' }
|
|
189
|
+
_, headers, _response = middleware.call({})
|
|
190
|
+
expect(headers).not_to include('X-bullet-footer-text')
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
it 'should not add headers for non-html requests when console_enabled is true' do
|
|
194
|
+
allow(Bullet).to receive(:console_enabled?).at_least(:once).and_return(true)
|
|
195
|
+
app.headers = { 'Content-Type' => 'application/json' }
|
|
196
|
+
_, headers, _response = middleware.call({})
|
|
197
|
+
expect(headers).not_to include('X-bullet-console-text')
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
context 'when skip_html_injection is enabled' do
|
|
203
|
+
it 'should not try to inject html' do
|
|
204
|
+
expected_response = Support::ResponseDouble.new 'Actual body'
|
|
205
|
+
app.response = expected_response
|
|
206
|
+
allow(Bullet).to receive(:notification?).and_return(true)
|
|
207
|
+
allow(Bullet).to receive(:skip_html_injection?).and_return(true)
|
|
208
|
+
expect(Bullet).to receive(:gather_inline_notifications).never
|
|
209
|
+
expect(middleware).to receive(:xhr_script).never
|
|
210
|
+
expect(Bullet).to receive(:perform_out_of_channel_notifications)
|
|
211
|
+
_, _, response = middleware.call('Content-Type' => 'text/html')
|
|
212
|
+
expect(response).to eq(expected_response)
|
|
213
|
+
end
|
|
84
214
|
end
|
|
85
215
|
end
|
|
86
216
|
|
|
87
|
-
context
|
|
217
|
+
context 'when Bullet is disabled' do
|
|
88
218
|
before(:each) { allow(Bullet).to receive(:enable?).and_return(false) }
|
|
89
219
|
|
|
90
|
-
it
|
|
220
|
+
it 'should not call Bullet.start_request' do
|
|
91
221
|
expect(Bullet).not_to receive(:start_request)
|
|
92
222
|
middleware.call({})
|
|
93
223
|
end
|
|
94
224
|
end
|
|
95
225
|
end
|
|
96
226
|
|
|
97
|
-
|
|
227
|
+
context '#set_header' do
|
|
228
|
+
it 'should truncate headers to under 8kb' do
|
|
229
|
+
long_header = ['a' * 1_024] * 10
|
|
230
|
+
expected_res = (['a' * 1_024] * 7).to_json
|
|
231
|
+
expect(middleware.set_header({}, 'Dummy-Header', long_header)).to eq(expected_res)
|
|
232
|
+
end
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
describe '#response_body' do
|
|
98
236
|
let(:response) { double }
|
|
99
|
-
let(:body_string) {
|
|
237
|
+
let(:body_string) { '<html><body>My Body</body></html>' }
|
|
100
238
|
|
|
101
|
-
context
|
|
239
|
+
context 'when `response` responds to `body`' do
|
|
102
240
|
before { allow(response).to receive(:body).and_return(body) }
|
|
103
241
|
|
|
104
|
-
context
|
|
242
|
+
context 'when `body` returns an Array' do
|
|
105
243
|
let(:body) { [body_string, 'random string'] }
|
|
106
|
-
it
|
|
244
|
+
it 'should return the plain body string' do
|
|
107
245
|
expect(middleware.response_body(response)).to eq body_string
|
|
108
246
|
end
|
|
109
247
|
end
|
|
110
248
|
|
|
111
|
-
context
|
|
249
|
+
context 'when `body` does not return an Array' do
|
|
112
250
|
let(:body) { body_string }
|
|
113
|
-
it
|
|
251
|
+
it 'should return the plain body string' do
|
|
114
252
|
expect(middleware.response_body(response)).to eq body_string
|
|
115
253
|
end
|
|
116
254
|
end
|
|
117
255
|
end
|
|
118
256
|
|
|
119
|
-
context
|
|
257
|
+
context 'when `response` does not respond to `body`' do
|
|
120
258
|
before { allow(response).to receive(:first).and_return(body_string) }
|
|
121
259
|
|
|
122
|
-
it
|
|
260
|
+
it 'should return the plain body string' do
|
|
123
261
|
expect(middleware.response_body(response)).to eq body_string
|
|
124
262
|
end
|
|
125
263
|
end
|
|
264
|
+
|
|
265
|
+
begin
|
|
266
|
+
require 'rack/files'
|
|
267
|
+
|
|
268
|
+
context 'when `response` is a Rack::Files::Iterator' do
|
|
269
|
+
let(:response) { instance_double(::Rack::Files::Iterator) }
|
|
270
|
+
before { allow(response).to receive(:is_a?).with(::Rack::Files::Iterator) { true } }
|
|
271
|
+
|
|
272
|
+
it 'should return nil' do
|
|
273
|
+
expect(middleware.response_body(response)).to be_nil
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
rescue LoadError
|
|
277
|
+
end
|
|
126
278
|
end
|
|
127
279
|
end
|
|
128
280
|
end
|
|
@@ -1,24 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
module Bullet
|
|
4
6
|
module Registry
|
|
5
7
|
describe Association do
|
|
6
|
-
subject { Association.new.tap { |association| association.add([
|
|
8
|
+
subject { Association.new.tap { |association| association.add(%w[key1 key2], 'value') } }
|
|
7
9
|
|
|
8
|
-
context
|
|
9
|
-
it
|
|
10
|
-
subject.merge(
|
|
11
|
-
expect(subject[
|
|
10
|
+
context '#merge' do
|
|
11
|
+
it 'should merge key/value' do
|
|
12
|
+
subject.merge('key0', 'value0')
|
|
13
|
+
expect(subject['key0']).to be_include('value0')
|
|
12
14
|
end
|
|
13
15
|
end
|
|
14
16
|
|
|
15
|
-
context
|
|
16
|
-
it
|
|
17
|
-
expect(subject.similarly_associated(
|
|
17
|
+
context '#similarly_associated' do
|
|
18
|
+
it 'should return similarly associated keys' do
|
|
19
|
+
expect(subject.similarly_associated('key1', Set.new(%w[value]))).to eq(%w[key1 key2])
|
|
18
20
|
end
|
|
19
21
|
|
|
20
|
-
it
|
|
21
|
-
expect(subject.similarly_associated(
|
|
22
|
+
it 'should return empty if key does not exist' do
|
|
23
|
+
expect(subject.similarly_associated('key3', Set.new(%w[value]))).to be_empty
|
|
22
24
|
end
|
|
23
25
|
end
|
|
24
26
|
end
|
|
@@ -1,42 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
module Bullet
|
|
4
6
|
module Registry
|
|
5
7
|
describe Base do
|
|
6
|
-
subject { Base.new.tap { |base| base.add(
|
|
8
|
+
subject { Base.new.tap { |base| base.add('key', 'value') } }
|
|
7
9
|
|
|
8
|
-
context
|
|
9
|
-
it
|
|
10
|
-
expect(subject[
|
|
10
|
+
context '#[]' do
|
|
11
|
+
it 'should get value by key' do
|
|
12
|
+
expect(subject['key']).to eq(Set.new(%w[value]))
|
|
11
13
|
end
|
|
12
14
|
end
|
|
13
15
|
|
|
14
|
-
context
|
|
15
|
-
it
|
|
16
|
-
subject.delete(
|
|
17
|
-
expect(subject[
|
|
16
|
+
context '#delete' do
|
|
17
|
+
it 'should delete key' do
|
|
18
|
+
subject.delete('key')
|
|
19
|
+
expect(subject['key']).to be_nil
|
|
18
20
|
end
|
|
19
21
|
end
|
|
20
22
|
|
|
21
|
-
context
|
|
22
|
-
it
|
|
23
|
-
subject.add(
|
|
24
|
-
expect(subject[
|
|
23
|
+
context '#add' do
|
|
24
|
+
it 'should add value with string' do
|
|
25
|
+
subject.add('key', 'new_value')
|
|
26
|
+
expect(subject['key']).to eq(Set.new(%w[value new_value]))
|
|
25
27
|
end
|
|
26
28
|
|
|
27
|
-
it
|
|
28
|
-
subject.add(
|
|
29
|
-
expect(subject[
|
|
29
|
+
it 'should add value with array' do
|
|
30
|
+
subject.add('key', %w[value1 value2])
|
|
31
|
+
expect(subject['key']).to eq(Set.new(%w[value value1 value2]))
|
|
30
32
|
end
|
|
31
33
|
end
|
|
32
34
|
|
|
33
|
-
context
|
|
34
|
-
it
|
|
35
|
-
expect(subject.include?(
|
|
35
|
+
context '#include?' do
|
|
36
|
+
it 'should include key/value' do
|
|
37
|
+
expect(subject.include?('key', 'value')).to eq true
|
|
36
38
|
end
|
|
37
39
|
|
|
38
|
-
it
|
|
39
|
-
expect(subject.include?(
|
|
40
|
+
it 'should not include wrong key/value' do
|
|
41
|
+
expect(subject.include?('key', 'val')).to eq false
|
|
40
42
|
end
|
|
41
43
|
end
|
|
42
44
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
module Bullet
|
|
@@ -7,14 +9,14 @@ module Bullet
|
|
|
7
9
|
let(:another_post) { Post.last }
|
|
8
10
|
subject { Object.new.tap { |object| object.add(post.bullet_key) } }
|
|
9
11
|
|
|
10
|
-
context
|
|
11
|
-
it
|
|
12
|
+
context '#include?' do
|
|
13
|
+
it 'should include the object' do
|
|
12
14
|
expect(subject).to be_include(post.bullet_key)
|
|
13
15
|
end
|
|
14
16
|
end
|
|
15
17
|
|
|
16
|
-
context
|
|
17
|
-
it
|
|
18
|
+
context '#add' do
|
|
19
|
+
it 'should add an object' do
|
|
18
20
|
subject.add(another_post.bullet_key)
|
|
19
21
|
expect(subject).to be_include(another_post.bullet_key)
|
|
20
22
|
end
|