bullet 5.7.0 → 6.0.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 (114) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +2 -0
  3. data/CHANGELOG.md +27 -1
  4. data/Gemfile.mongoid-7.0 +15 -0
  5. data/Gemfile.rails-4.0 +1 -1
  6. data/Gemfile.rails-4.1 +1 -1
  7. data/Gemfile.rails-4.2 +1 -1
  8. data/Gemfile.rails-5.0 +1 -1
  9. data/Gemfile.rails-5.1 +1 -1
  10. data/Gemfile.rails-5.2 +2 -2
  11. data/Gemfile.rails-6.0 +15 -0
  12. data/Guardfile +1 -1
  13. data/README.md +10 -5
  14. data/Rakefile +5 -5
  15. data/bullet.gemspec +12 -6
  16. data/lib/bullet/active_record4.rb +10 -14
  17. data/lib/bullet/active_record41.rb +8 -14
  18. data/lib/bullet/active_record42.rb +16 -22
  19. data/lib/bullet/active_record5.rb +69 -49
  20. data/lib/bullet/active_record52.rb +40 -40
  21. data/lib/bullet/active_record60.rb +245 -0
  22. data/lib/bullet/bullet_xhr.js +58 -0
  23. data/lib/bullet/dependency.rb +19 -5
  24. data/lib/bullet/detector/association.rb +18 -16
  25. data/lib/bullet/detector/base.rb +2 -0
  26. data/lib/bullet/detector/counter_cache.rb +13 -10
  27. data/lib/bullet/detector/n_plus_one_query.rb +21 -19
  28. data/lib/bullet/detector/unused_eager_loading.rb +27 -22
  29. data/lib/bullet/detector.rb +2 -0
  30. data/lib/bullet/ext/object.rb +9 -5
  31. data/lib/bullet/ext/string.rb +3 -1
  32. data/lib/bullet/mongoid4x.rb +7 -2
  33. data/lib/bullet/mongoid5x.rb +7 -2
  34. data/lib/bullet/mongoid6x.rb +11 -6
  35. data/lib/bullet/mongoid7x.rb +61 -0
  36. data/lib/bullet/notification/base.rb +21 -15
  37. data/lib/bullet/notification/counter_cache.rb +2 -0
  38. data/lib/bullet/notification/n_plus_one_query.rb +6 -4
  39. data/lib/bullet/notification/unused_eager_loading.rb +6 -4
  40. data/lib/bullet/notification.rb +2 -0
  41. data/lib/bullet/notification_collector.rb +2 -1
  42. data/lib/bullet/rack.rb +52 -31
  43. data/lib/bullet/registry/association.rb +2 -0
  44. data/lib/bullet/registry/base.rb +2 -0
  45. data/lib/bullet/registry/object.rb +2 -0
  46. data/lib/bullet/registry.rb +2 -0
  47. data/lib/bullet/stack_trace_filter.rb +57 -21
  48. data/lib/bullet/version.rb +2 -1
  49. data/lib/bullet.rb +48 -31
  50. data/lib/generators/bullet/install_generator.rb +5 -3
  51. data/perf/benchmark.rb +9 -7
  52. data/rails/init.rb +2 -0
  53. data/spec/bullet/detector/association_spec.rb +2 -0
  54. data/spec/bullet/detector/base_spec.rb +2 -0
  55. data/spec/bullet/detector/counter_cache_spec.rb +2 -0
  56. data/spec/bullet/detector/n_plus_one_query_spec.rb +33 -8
  57. data/spec/bullet/detector/unused_eager_loading_spec.rb +2 -0
  58. data/spec/bullet/ext/object_spec.rb +12 -5
  59. data/spec/bullet/ext/string_spec.rb +2 -0
  60. data/spec/bullet/notification/base_spec.rb +8 -6
  61. data/spec/bullet/notification/counter_cache_spec.rb +3 -1
  62. data/spec/bullet/notification/n_plus_one_query_spec.rb +3 -1
  63. data/spec/bullet/notification/unused_eager_loading_spec.rb +3 -1
  64. data/spec/bullet/notification_collector_spec.rb +2 -0
  65. data/spec/bullet/rack_spec.rb +22 -12
  66. data/spec/bullet/registry/association_spec.rb +4 -2
  67. data/spec/bullet/registry/base_spec.rb +5 -3
  68. data/spec/bullet/registry/object_spec.rb +2 -0
  69. data/spec/bullet_spec.rb +9 -7
  70. data/spec/integration/active_record/association_spec.rb +70 -19
  71. data/spec/integration/counter_cache_spec.rb +5 -3
  72. data/spec/integration/mongoid/association_spec.rb +2 -0
  73. data/spec/models/address.rb +2 -0
  74. data/spec/models/author.rb +2 -0
  75. data/spec/models/base_user.rb +2 -0
  76. data/spec/models/category.rb +2 -0
  77. data/spec/models/city.rb +2 -0
  78. data/spec/models/client.rb +4 -0
  79. data/spec/models/comment.rb +2 -0
  80. data/spec/models/company.rb +2 -0
  81. data/spec/models/country.rb +2 -0
  82. data/spec/models/document.rb +2 -0
  83. data/spec/models/entry.rb +2 -0
  84. data/spec/models/firm.rb +3 -0
  85. data/spec/models/folder.rb +2 -0
  86. data/spec/models/group.rb +4 -0
  87. data/spec/models/mongoid/address.rb +3 -1
  88. data/spec/models/mongoid/category.rb +4 -2
  89. data/spec/models/mongoid/comment.rb +3 -1
  90. data/spec/models/mongoid/company.rb +3 -1
  91. data/spec/models/mongoid/entry.rb +3 -1
  92. data/spec/models/mongoid/post.rb +6 -4
  93. data/spec/models/mongoid/user.rb +2 -0
  94. data/spec/models/newspaper.rb +2 -0
  95. data/spec/models/page.rb +2 -0
  96. data/spec/models/person.rb +2 -0
  97. data/spec/models/pet.rb +2 -0
  98. data/spec/models/post.rb +17 -0
  99. data/spec/models/relationship.rb +2 -0
  100. data/spec/models/reply.rb +2 -0
  101. data/spec/models/student.rb +2 -0
  102. data/spec/models/submission.rb +2 -0
  103. data/spec/models/teacher.rb +2 -0
  104. data/spec/models/user.rb +2 -0
  105. data/spec/models/writer.rb +2 -0
  106. data/spec/spec_helper.rb +3 -1
  107. data/spec/support/bullet_ext.rb +2 -0
  108. data/spec/support/mongo_seed.rb +32 -30
  109. data/spec/support/rack_double.rb +9 -16
  110. data/spec/support/sqlite_seed.rb +84 -75
  111. data/tasks/bullet_tasks.rake +2 -0
  112. data/test.sh +2 -0
  113. data/update.sh +1 -0
  114. metadata +17 -9
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Bullet
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Bullet
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Bullet
@@ -91,21 +93,44 @@ module Bullet
91
93
  after { Bullet.stacktrace_excludes = nil }
92
94
 
93
95
  it 'should not create notification when stacktrace contains paths that are in the exclude list' do
94
- in_project = OpenStruct.new(:absolute_path => File.join(Dir.pwd, 'abc', 'abc.rb'))
95
- included_path = OpenStruct.new(:absolute_path => '/ghi/ghi.rb')
96
- excluded_path = OpenStruct.new(:absolute_path => '/def/def.rb')
96
+ in_project = OpenStruct.new(absolute_path: File.join(Dir.pwd, 'abc', 'abc.rb'))
97
+ included_path = OpenStruct.new(absolute_path: '/ghi/ghi.rb')
98
+ excluded_path = OpenStruct.new(absolute_path: '/def/def.rb')
97
99
 
98
100
  expect(NPlusOneQuery).to receive(:caller_locations).and_return([in_project, included_path, excluded_path])
99
101
  expect(NPlusOneQuery).to_not receive(:create_notification)
100
102
  NPlusOneQuery.call_association(@post, :association)
101
103
  end
104
+
105
+ # just a sanity spec to make sure the following spec works correctly
106
+ it "should create notification when stacktrace contains methods that aren't in the exclude list" do
107
+ method = NPlusOneQuery.method(:excluded_stacktrace_path?).source_location
108
+ in_project = OpenStruct.new(absolute_path: File.join(Dir.pwd, 'abc', 'abc.rb'))
109
+ excluded_path = OpenStruct.new(absolute_path: method.first, lineno: method.last)
110
+
111
+ expect(NPlusOneQuery).to receive(:caller_locations).at_least(1).and_return([in_project, excluded_path])
112
+ expect(NPlusOneQuery).to receive(:conditions_met?).and_return(true)
113
+ expect(NPlusOneQuery).to receive(:create_notification)
114
+ NPlusOneQuery.call_association(@post, :association)
115
+ end
116
+
117
+ it 'should not create notification when stacktrace contains methods that are in the exclude list' do
118
+ method = NPlusOneQuery.method(:excluded_stacktrace_path?).source_location
119
+ Bullet.stacktrace_excludes = [method]
120
+ in_project = OpenStruct.new(absolute_path: File.join(Dir.pwd, 'abc', 'abc.rb'))
121
+ excluded_path = OpenStruct.new(absolute_path: method.first, lineno: method.last)
122
+
123
+ expect(NPlusOneQuery).to receive(:caller_locations).and_return([in_project, excluded_path])
124
+ expect(NPlusOneQuery).to_not receive(:create_notification)
125
+ NPlusOneQuery.call_association(@post, :association)
126
+ end
102
127
  end
103
128
  end
104
129
 
105
130
  context '.caller_in_project' do
106
131
  it 'should include only paths that are in the project' do
107
- in_project = OpenStruct.new(:absolute_path => File.join(Dir.pwd, 'abc', 'abc.rb'))
108
- not_in_project = OpenStruct.new(:absolute_path => '/def/def.rb')
132
+ in_project = OpenStruct.new(absolute_path: File.join(Dir.pwd, 'abc', 'abc.rb'))
133
+ not_in_project = OpenStruct.new(absolute_path: '/def/def.rb')
109
134
 
110
135
  expect(NPlusOneQuery).to receive(:caller_locations).and_return([in_project, not_in_project])
111
136
  expect(NPlusOneQuery).to receive(:conditions_met?).with(@post, :association).and_return(true)
@@ -118,9 +143,9 @@ module Bullet
118
143
  after { Bullet.stacktrace_includes = nil }
119
144
 
120
145
  it 'should include paths that are in the stacktrace_include list' do
121
- in_project = OpenStruct.new(:absolute_path => File.join(Dir.pwd, 'abc', 'abc.rb'))
122
- included_gems = [OpenStruct.new(:absolute_path => '/def/def.rb'), OpenStruct.new(:absolute_path => 'xyz/xyz.rb')]
123
- excluded_gem = OpenStruct.new(:absolute_path => '/ghi/ghi.rb')
146
+ in_project = OpenStruct.new(absolute_path: File.join(Dir.pwd, 'abc', 'abc.rb'))
147
+ included_gems = [OpenStruct.new(absolute_path: '/def/def.rb'), OpenStruct.new(absolute_path: 'xyz/xyz.rb')]
148
+ excluded_gem = OpenStruct.new(absolute_path: '/ghi/ghi.rb')
124
149
 
125
150
  expect(NPlusOneQuery).to receive(:caller_locations).and_return([in_project, *included_gems, excluded_gem])
126
151
  expect(NPlusOneQuery).to receive(:conditions_met?).with(@post, :association).and_return(true)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Bullet
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Object do
@@ -15,23 +17,28 @@ describe Object do
15
17
  end
16
18
  end
17
19
 
18
- context 'primary_key_value' do
20
+ context 'bullet_primary_key_value' do
19
21
  it 'should return id' do
20
22
  post = Post.first
21
- expect(post.primary_key_value).to eq(post.id)
23
+ expect(post.bullet_primary_key_value).to eq(post.id)
22
24
  end
23
25
 
24
26
  it 'should return primary key value' do
25
27
  post = Post.first
26
28
  Post.primary_key = 'name'
27
- expect(post.primary_key_value).to eq(post.name)
29
+ expect(post.bullet_primary_key_value).to eq(post.name)
28
30
  Post.primary_key = 'id'
29
31
  end
30
32
 
31
33
  it 'should return value for multiple primary keys' do
32
34
  post = Post.first
33
- allow(Post).to receive(:primary_keys).and_return([:category_id, :writer_id])
34
- expect(post.primary_key_value).to eq("#{post.category_id},#{post.writer_id}")
35
+ allow(Post).to receive(:primary_keys).and_return(%i[category_id writer_id])
36
+ expect(post.bullet_primary_key_value).to eq("#{post.category_id},#{post.writer_id}")
37
+ end
38
+
39
+ it 'it should return nil for unpersisted records' do
40
+ post = Post.new(id: 123)
41
+ expect(post.bullet_primary_key_value).to be_nil
35
42
  end
36
43
  end
37
44
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe String do
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Bullet
4
6
  module Notification
5
7
  describe Base do
6
- subject { Base.new(Post, [:comments, :votes]) }
8
+ subject { Base.new(Post, %i[comments votes]) }
7
9
 
8
10
  context '#title' do
9
11
  it 'should raise NoMethodError' do
@@ -66,7 +68,7 @@ module Bullet
66
68
  allow(subject).to receive(:url).and_return('url')
67
69
  allow(subject).to receive(:title).and_return('title')
68
70
  allow(subject).to receive(:body_with_caller).and_return('body_with_caller')
69
- expect(subject.notification_data).to eq(:user => 'whoami', :url => 'url', :title => 'title', :body => 'body_with_caller')
71
+ expect(subject.notification_data).to eq(user: 'whoami', url: 'url', title: 'title', body: 'body_with_caller')
70
72
  end
71
73
  end
72
74
 
@@ -74,8 +76,8 @@ module Bullet
74
76
  it 'should send full_notice to notifier' do
75
77
  notifier = double
76
78
  allow(subject).to receive(:notifier).and_return(notifier)
77
- allow(subject).to receive(:notification_data).and_return(:foo => :bar)
78
- expect(notifier).to receive(:inline_notify).with(:foo => :bar)
79
+ allow(subject).to receive(:notification_data).and_return(foo: :bar)
80
+ expect(notifier).to receive(:inline_notify).with(foo: :bar)
79
81
  subject.notify_inline
80
82
  end
81
83
  end
@@ -84,8 +86,8 @@ module Bullet
84
86
  it 'should send full_out_of_channel to notifier' do
85
87
  notifier = double
86
88
  allow(subject).to receive(:notifier).and_return(notifier)
87
- allow(subject).to receive(:notification_data).and_return(:foo => :bar)
88
- expect(notifier).to receive(:out_of_channel_notify).with(:foo => :bar)
89
+ allow(subject).to receive(:notification_data).and_return(foo: :bar)
90
+ expect(notifier).to receive(:out_of_channel_notify).with(foo: :bar)
89
91
  subject.notify_out_of_channel
90
92
  end
91
93
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Bullet
4
6
  module Notification
5
7
  describe CounterCache do
6
- subject { CounterCache.new(Post, [:comments, :votes]) }
8
+ subject { CounterCache.new(Post, %i[comments votes]) }
7
9
 
8
10
  it { expect(subject.body).to eq(' Post => [:comments, :votes]') }
9
11
  it { expect(subject.title).to eq('Need Counter Cache') }
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Bullet
4
6
  module Notification
5
7
  describe NPlusOneQuery do
6
- subject { NPlusOneQuery.new([['caller1', 'caller2']], Post, [:comments, :votes], 'path') }
8
+ subject { NPlusOneQuery.new([%w[caller1 caller2]], Post, %i[comments votes], 'path') }
7
9
 
8
10
  it { expect(subject.body_with_caller).to eq(" Post => [:comments, :votes]\n Add to your finder: :includes => [:comments, :votes]\nCall stack\n caller1\n caller2\n") }
9
11
  it { expect([subject.body_with_caller, subject.body_with_caller]).to eq([" Post => [:comments, :votes]\n Add to your finder: :includes => [:comments, :votes]\nCall stack\n caller1\n caller2\n", " Post => [:comments, :votes]\n Add to your finder: :includes => [:comments, :votes]\nCall stack\n caller1\n caller2\n"]) }
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Bullet
4
6
  module Notification
5
7
  describe UnusedEagerLoading do
6
- subject { UnusedEagerLoading.new([''], Post, [:comments, :votes], 'path') }
8
+ subject { UnusedEagerLoading.new([''], Post, %i[comments votes], 'path') }
7
9
 
8
10
  it { expect(subject.body).to eq(" Post => [:comments, :votes]\n Remove from your finder: :includes => [:comments, :votes]") }
9
11
  it { expect(subject.title).to eq('AVOID eager loading in path') }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Bullet
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  require 'spec_helper'
3
4
 
@@ -9,48 +10,48 @@ module Bullet
9
10
  context '#html_request?' do
10
11
  it 'should be true if Content-Type is text/html and http body contains html tag' do
11
12
  headers = { 'Content-Type' => 'text/html' }
12
- response = double(:body => '<html><head></head><body></body></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
17
  it 'should be true if Content-Type is text/html and http body contains html tag with attributes' do
17
18
  headers = { 'Content-Type' => 'text/html' }
18
- response = double(:body => "<html attr='hello'><head></head><body></body></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
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
29
  it 'should be false if Content-Type is javascript' do
29
30
  headers = { 'Content-Type' => 'text/javascript' }
30
- response = double(:body => '<html><head></head><body></body></html>')
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
36
  headers = { 'Content-Type' => 'text/html' }
36
- response = double(:body => '<div>Partial</div>')
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
42
  context 'empty?' do
42
43
  it 'should be false if response is a string and not empty' do
43
- response = double(:body => '<html><head></head><body></body></html>')
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
+ it 'should be false if response is not found' do
48
49
  response = ['Not Found']
49
- expect(middleware).to be_empty(response)
50
+ expect(middleware).not_to be_empty(response)
50
51
  end
51
52
 
52
53
  it 'should be true if response body is empty' do
53
- response = double(:body => '')
54
+ response = double(body: '')
54
55
  expect(middleware).to be_empty(response)
55
56
  end
56
57
  end
@@ -67,8 +68,9 @@ module Bullet
67
68
  it 'should change response body if notification is active' do
68
69
  expect(Bullet).to receive(:notification?).and_return(true)
69
70
  expect(Bullet).to receive(:gather_inline_notifications).and_return('<bullet></bullet>')
71
+ expect(middleware).to receive(:xhr_script).and_return('')
70
72
  expect(Bullet).to receive(:perform_out_of_channel_notifications)
71
- status, headers, response = middleware.call({ 'Content-Type' => 'text/html' })
73
+ status, headers, response = middleware.call('Content-Type' => 'text/html')
72
74
  expect(headers['Content-Length']).to eq('56')
73
75
  expect(response).to eq(['<html><head></head><body><bullet></bullet></body></html>'])
74
76
  end
@@ -79,8 +81,8 @@ module Bullet
79
81
  app.response = response
80
82
  expect(Bullet).to receive(:notification?).and_return(true)
81
83
  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')
84
+ status, headers, response = middleware.call('Content-Type' => 'text/html')
85
+ expect(headers['Content-Length']).to eq((58 + middleware.send(:xhr_script).length).to_s)
84
86
  end
85
87
  end
86
88
 
@@ -94,6 +96,14 @@ module Bullet
94
96
  end
95
97
  end
96
98
 
99
+ context '#set_header' do
100
+ it 'should truncate headers to under 8kb' do
101
+ long_header = ['a' * 1024] * 10
102
+ expected_res = (['a' * 1024] * 7).to_json
103
+ expect(middleware.set_header({}, 'Dummy-Header', long_header)).to eq(expected_res)
104
+ end
105
+ end
106
+
97
107
  describe '#response_body' do
98
108
  let(:response) { double }
99
109
  let(:body_string) { '<html><body>My Body</body></html>' }
@@ -1,9 +1,11 @@
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
10
  context '#merge' do
9
11
  it 'should merge key/value' do
@@ -14,7 +16,7 @@ module Bullet
14
16
 
15
17
  context '#similarly_associated' do
16
18
  it 'should return similarly associated keys' do
17
- expect(subject.similarly_associated('key1', Set.new(['value']))).to eq(['key1', 'key2'])
19
+ expect(subject.similarly_associated('key1', Set.new(['value']))).to eq(%w[key1 key2])
18
20
  end
19
21
 
20
22
  it 'should return empty if key does not exist' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Bullet
@@ -21,12 +23,12 @@ module Bullet
21
23
  context '#add' do
22
24
  it 'should add value with string' do
23
25
  subject.add('key', 'new_value')
24
- expect(subject['key']).to eq(Set.new(['value', 'new_value']))
26
+ expect(subject['key']).to eq(Set.new(%w[value new_value]))
25
27
  end
26
28
 
27
29
  it 'should add value with array' do
28
- subject.add('key', ['value1', 'value2'])
29
- expect(subject['key']).to eq(Set.new(['value', 'value1', 'value2']))
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
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Bullet
data/spec/bullet_spec.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Bullet, focused: true do
@@ -88,7 +90,7 @@ describe Bullet, focused: true do
88
90
  describe '#add_whitelist' do
89
91
  context "for 'special' class names" do
90
92
  it 'is added to the whitelist successfully' do
91
- Bullet.add_whitelist(:type => :n_plus_one_query, :class_name => 'Klass', :association => :department)
93
+ Bullet.add_whitelist(type: :n_plus_one_query, class_name: 'Klass', association: :department)
92
94
  expect(Bullet.get_whitelist_associations(:n_plus_one_query, 'Klass')).to include :department
93
95
  end
94
96
  end
@@ -97,17 +99,17 @@ describe Bullet, focused: true do
97
99
  describe '#delete_whitelist' do
98
100
  context "for 'special' class names" do
99
101
  it 'is deleted from the whitelist successfully' do
100
- Bullet.add_whitelist(:type => :n_plus_one_query, :class_name => 'Klass', :association => :department)
101
- Bullet.delete_whitelist(:type => :n_plus_one_query, :class_name => 'Klass', :association => :department)
102
+ Bullet.add_whitelist(type: :n_plus_one_query, class_name: 'Klass', association: :department)
103
+ Bullet.delete_whitelist(type: :n_plus_one_query, class_name: 'Klass', association: :department)
102
104
  expect(Bullet.whitelist[:n_plus_one_query]).to eq({})
103
105
  end
104
106
  end
105
107
 
106
108
  context 'when exists multiple definitions' do
107
109
  it 'is deleted from the whitelist successfully' do
108
- Bullet.add_whitelist(:type => :n_plus_one_query, :class_name => 'Klass', :association => :department)
109
- Bullet.add_whitelist(:type => :n_plus_one_query, :class_name => 'Klass', :association => :team)
110
- Bullet.delete_whitelist(:type => :n_plus_one_query, :class_name => 'Klass', :association => :team)
110
+ Bullet.add_whitelist(type: :n_plus_one_query, class_name: 'Klass', association: :department)
111
+ Bullet.add_whitelist(type: :n_plus_one_query, class_name: 'Klass', association: :team)
112
+ Bullet.delete_whitelist(type: :n_plus_one_query, class_name: 'Klass', association: :team)
111
113
  expect(Bullet.get_whitelist_associations(:n_plus_one_query, 'Klass')).to include :department
112
114
  expect(Bullet.get_whitelist_associations(:n_plus_one_query, 'Klass')).to_not include :team
113
115
  end
@@ -127,7 +129,7 @@ describe Bullet, focused: true do
127
129
  {
128
130
  'REQUEST_METHOD' => 'GET',
129
131
  'PATH_INFO' => '/path',
130
- 'QUERY_STRING' => 'foo=bar',
132
+ 'QUERY_STRING' => 'foo=bar'
131
133
  }
132
134
  }
133
135