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.
Files changed (123) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/main.yml +66 -0
  3. data/CHANGELOG.md +83 -1
  4. data/Gemfile +6 -1
  5. data/Gemfile.mongoid-7.0 +15 -0
  6. data/Gemfile.rails-4.0 +1 -1
  7. data/Gemfile.rails-4.1 +1 -1
  8. data/Gemfile.rails-4.2 +1 -1
  9. data/Gemfile.rails-5.0 +2 -2
  10. data/Gemfile.rails-5.1 +15 -0
  11. data/Gemfile.rails-5.2 +15 -0
  12. data/Gemfile.rails-6.0 +15 -0
  13. data/Gemfile.rails-6.1 +15 -0
  14. data/Guardfile +2 -2
  15. data/Hacking.md +1 -1
  16. data/README.md +58 -37
  17. data/Rakefile +20 -21
  18. data/bullet.gemspec +21 -15
  19. data/lib/bullet/active_job.rb +13 -0
  20. data/lib/bullet/active_record4.rb +15 -34
  21. data/lib/bullet/active_record41.rb +14 -31
  22. data/lib/bullet/active_record42.rb +23 -36
  23. data/lib/bullet/active_record5.rb +178 -158
  24. data/lib/bullet/active_record52.rb +251 -0
  25. data/lib/bullet/active_record60.rb +278 -0
  26. data/lib/bullet/active_record61.rb +278 -0
  27. data/lib/bullet/bullet_xhr.js +64 -0
  28. data/lib/bullet/dependency.rb +60 -32
  29. data/lib/bullet/detector/association.rb +41 -32
  30. data/lib/bullet/detector/base.rb +2 -0
  31. data/lib/bullet/detector/counter_cache.rb +25 -17
  32. data/lib/bullet/detector/n_plus_one_query.rb +38 -24
  33. data/lib/bullet/detector/unused_eager_loading.rb +35 -26
  34. data/lib/bullet/detector.rb +2 -0
  35. data/lib/bullet/ext/object.rb +9 -5
  36. data/lib/bullet/ext/string.rb +3 -1
  37. data/lib/bullet/mongoid4x.rb +9 -8
  38. data/lib/bullet/mongoid5x.rb +9 -8
  39. data/lib/bullet/mongoid6x.rb +13 -12
  40. data/lib/bullet/mongoid7x.rb +57 -0
  41. data/lib/bullet/notification/base.rb +28 -25
  42. data/lib/bullet/notification/counter_cache.rb +3 -1
  43. data/lib/bullet/notification/n_plus_one_query.rb +8 -7
  44. data/lib/bullet/notification/unused_eager_loading.rb +8 -7
  45. data/lib/bullet/notification.rb +4 -1
  46. data/lib/bullet/notification_collector.rb +2 -1
  47. data/lib/bullet/rack.rb +66 -35
  48. data/lib/bullet/registry/association.rb +2 -0
  49. data/lib/bullet/registry/base.rb +2 -0
  50. data/lib/bullet/registry/object.rb +2 -0
  51. data/lib/bullet/registry.rb +2 -0
  52. data/lib/bullet/stack_trace_filter.rb +50 -20
  53. data/lib/bullet/version.rb +3 -2
  54. data/lib/bullet.rb +136 -55
  55. data/lib/generators/bullet/install_generator.rb +48 -0
  56. data/perf/benchmark.rb +19 -22
  57. data/rails/init.rb +2 -0
  58. data/spec/bullet/detector/association_spec.rb +6 -4
  59. data/spec/bullet/detector/base_spec.rb +2 -0
  60. data/spec/bullet/detector/counter_cache_spec.rb +17 -15
  61. data/spec/bullet/detector/n_plus_one_query_spec.rb +75 -46
  62. data/spec/bullet/detector/unused_eager_loading_spec.rb +45 -26
  63. data/spec/bullet/ext/object_spec.rb +18 -11
  64. data/spec/bullet/ext/string_spec.rb +7 -5
  65. data/spec/bullet/notification/base_spec.rb +38 -39
  66. data/spec/bullet/notification/counter_cache_spec.rb +5 -3
  67. data/spec/bullet/notification/n_plus_one_query_spec.rb +20 -5
  68. data/spec/bullet/notification/unused_eager_loading_spec.rb +9 -3
  69. data/spec/bullet/notification_collector_spec.rb +12 -10
  70. data/spec/bullet/rack_spec.rb +200 -48
  71. data/spec/bullet/registry/association_spec.rb +12 -10
  72. data/spec/bullet/registry/base_spec.rb +22 -20
  73. data/spec/bullet/registry/object_spec.rb +6 -4
  74. data/spec/bullet_spec.rb +64 -33
  75. data/spec/integration/{active_record4 → active_record}/association_spec.rb +238 -223
  76. data/spec/integration/counter_cache_spec.rb +26 -44
  77. data/spec/integration/mongoid/association_spec.rb +53 -65
  78. data/spec/models/address.rb +2 -0
  79. data/spec/models/attachment.rb +5 -0
  80. data/spec/models/author.rb +2 -0
  81. data/spec/models/base_user.rb +2 -0
  82. data/spec/models/category.rb +2 -0
  83. data/spec/models/city.rb +2 -0
  84. data/spec/models/client.rb +4 -0
  85. data/spec/models/comment.rb +3 -1
  86. data/spec/models/company.rb +2 -0
  87. data/spec/models/country.rb +2 -0
  88. data/spec/models/deal.rb +5 -0
  89. data/spec/models/document.rb +4 -2
  90. data/spec/models/entry.rb +2 -0
  91. data/spec/models/firm.rb +3 -0
  92. data/spec/models/folder.rb +2 -0
  93. data/spec/models/group.rb +4 -0
  94. data/spec/models/mongoid/address.rb +3 -1
  95. data/spec/models/mongoid/category.rb +4 -2
  96. data/spec/models/mongoid/comment.rb +3 -1
  97. data/spec/models/mongoid/company.rb +3 -1
  98. data/spec/models/mongoid/entry.rb +3 -1
  99. data/spec/models/mongoid/post.rb +6 -4
  100. data/spec/models/mongoid/user.rb +2 -0
  101. data/spec/models/newspaper.rb +3 -1
  102. data/spec/models/page.rb +2 -0
  103. data/spec/models/person.rb +2 -0
  104. data/spec/models/pet.rb +2 -0
  105. data/spec/models/post.rb +19 -0
  106. data/spec/models/relationship.rb +2 -0
  107. data/spec/models/reply.rb +2 -0
  108. data/spec/models/student.rb +2 -0
  109. data/spec/models/submission.rb +3 -0
  110. data/spec/models/teacher.rb +2 -0
  111. data/spec/models/user.rb +3 -0
  112. data/spec/models/writer.rb +2 -0
  113. data/spec/spec_helper.rb +19 -23
  114. data/spec/support/bullet_ext.rb +10 -9
  115. data/spec/support/mongo_seed.rb +38 -57
  116. data/spec/support/rack_double.rb +13 -19
  117. data/spec/support/sqlite_seed.rb +104 -76
  118. data/tasks/bullet_tasks.rake +4 -2
  119. data/test.sh +5 -0
  120. data/update.sh +3 -0
  121. metadata +34 -17
  122. data/.travis.yml +0 -16
  123. 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("value") } }
7
+ subject { NotificationCollector.new.tap { |collector| collector.add('value') } }
6
8
 
7
- context "#add" do
8
- it "should add a value" do
9
- subject.add("value1")
10
- expect(subject.collection).to be_include("value1")
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 "#reset" do
15
- it "should reset collector" do
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 "#notifications_present?" do
22
- it "should be true if collection is not empty" do
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 "should be false if collection is empty" do
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
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
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 "#html_request?" do
10
- it "should be true if Content-Type is text/html and http body contains html tag" do
11
- headers = {"Content-Type" => "text/html"}
12
- response = double(:body => "<html><head></head><body></body></html>")
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 "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>")
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 "should be false if there is no Content-Type header" do
23
+ it 'should be false if there is no Content-Type header' do
23
24
  headers = {}
24
- response = double(:body => "<html><head></head><body></body></html>")
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 "should be false if Content-Type is javascript" do
29
- headers = {"Content-Type" => "text/javascript"}
30
- response = double(:body => "<html><head></head><body></body></html>")
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 = {"Content-Type" => "text/html"}
36
- response = double(:body => "<div>Partial</div>")
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 "empty?" do
42
- it "should be false if response is a string and not empty" do
43
- response = double(:body => "<html><head></head><body></body></html>")
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 "should be true if response is not found" do
48
- response = ["Not Found"]
49
- expect(middleware).to be_empty(response)
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 "should be true if response body is empty" do
53
- response = double(:body => "")
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 "#call" do
59
- context "when Bullet is enabled" do
60
- it "should return original response body" do
61
- expected_response = Support::ResponseDouble.new "Actual body"
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 "should change response body if notification is active" do
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(:gather_inline_notifications).and_return("<bullet></bullet>")
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
- status, headers, response = middleware.call({"Content-Type" => "text/html"})
72
- expect(headers["Content-Length"]).to eq("56")
73
- expect(response).to eq(["<html><head></head><body><bullet></bullet></body></html>"])
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 "should set the right Content-Length if response body contains accents" do
78
+ it 'should set the right Content-Length if response body contains accents' do
77
79
  response = Support::ResponseDouble.new
78
- response.body = "<html><head></head><body>é</body></html>"
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
- expect(Bullet).to receive(:gather_inline_notifications).and_return("<bullet></bullet>")
82
- status, headers, response = middleware.call({"Content-Type" => "text/html"})
83
- expect(headers["Content-Length"]).to eq("58")
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 "when Bullet is disabled" do
217
+ context 'when Bullet is disabled' do
88
218
  before(:each) { allow(Bullet).to receive(:enable?).and_return(false) }
89
219
 
90
- it "should not call Bullet.start_request" do
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
- describe "#response_body" do
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) { "<html><body>My Body</body></html>" }
237
+ let(:body_string) { '<html><body>My Body</body></html>' }
100
238
 
101
- context "when `response` responds to `body`" do
239
+ context 'when `response` responds to `body`' do
102
240
  before { allow(response).to receive(:body).and_return(body) }
103
241
 
104
- context "when `body` returns an Array" do
242
+ context 'when `body` returns an Array' do
105
243
  let(:body) { [body_string, 'random string'] }
106
- it "should return the plain body string" do
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 "when `body` does not return an Array" do
249
+ context 'when `body` does not return an Array' do
112
250
  let(:body) { body_string }
113
- it "should return the plain body string" do
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 "when `response` does not respond to `body`" do
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 "should return the plain body string" do
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(["key1", "key2"], "value") } }
8
+ subject { Association.new.tap { |association| association.add(%w[key1 key2], 'value') } }
7
9
 
8
- context "#merge" do
9
- it "should merge key/value" do
10
- subject.merge("key0", "value0")
11
- expect(subject["key0"]).to be_include("value0")
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 "#similarly_associated" do
16
- it "should return similarly associated keys" do
17
- expect(subject.similarly_associated("key1", Set.new(["value"]))).to eq(["key1", "key2"])
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 "should return empty if key does not exist" do
21
- expect(subject.similarly_associated("key3", Set.new(["value"]))).to be_empty
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("key", "value") } }
8
+ subject { Base.new.tap { |base| base.add('key', 'value') } }
7
9
 
8
- context "#[]" do
9
- it "should get value by key" do
10
- expect(subject["key"]).to eq(Set.new(["value"]))
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 "#delete" do
15
- it "should delete key" do
16
- subject.delete("key")
17
- expect(subject["key"]).to be_nil
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 "#add" do
22
- it "should add value with string" do
23
- subject.add("key", "new_value")
24
- expect(subject["key"]).to eq(Set.new(["value", "new_value"]))
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 "should add value with array" do
28
- subject.add("key", ["value1", "value2"])
29
- expect(subject["key"]).to eq(Set.new(["value", "value1", "value2"]))
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 "#include?" do
34
- it "should include key/value" do
35
- expect(subject.include?("key", "value")).to eq true
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 "should not include wrong key/value" do
39
- expect(subject.include?("key", "val")).to eq false
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 "#include?" do
11
- it "should include the object" do
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 "#add" do
17
- it "should add an object" do
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