bullet 5.6.0 → 5.7.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 (62) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/Gemfile.rails-5.2 +15 -0
  4. data/Guardfile +2 -2
  5. data/Rakefile +16 -17
  6. data/bullet.gemspec +11 -11
  7. data/lib/bullet/active_record52.rb +225 -0
  8. data/lib/bullet/dependency.rb +6 -0
  9. data/lib/bullet/detector/association.rb +3 -2
  10. data/lib/bullet/detector/counter_cache.rb +4 -3
  11. data/lib/bullet/detector/n_plus_one_query.rb +6 -5
  12. data/lib/bullet/detector/unused_eager_loading.rb +4 -3
  13. data/lib/bullet/ext/string.rb +1 -1
  14. data/lib/bullet/mongoid4x.rb +1 -1
  15. data/lib/bullet/mongoid5x.rb +1 -1
  16. data/lib/bullet/mongoid6x.rb +1 -1
  17. data/lib/bullet/notification/base.rb +9 -8
  18. data/lib/bullet/notification/counter_cache.rb +1 -1
  19. data/lib/bullet/notification/n_plus_one_query.rb +2 -1
  20. data/lib/bullet/notification/unused_eager_loading.rb +2 -1
  21. data/lib/bullet/rack.rb +5 -5
  22. data/lib/bullet/stack_trace_filter.rb +2 -2
  23. data/lib/bullet/version.rb +2 -2
  24. data/lib/bullet.rb +15 -7
  25. data/lib/generators/bullet/install_generator.rb +5 -5
  26. data/perf/benchmark.rb +6 -8
  27. data/spec/bullet/detector/association_spec.rb +4 -4
  28. data/spec/bullet/detector/counter_cache_spec.rb +11 -11
  29. data/spec/bullet/detector/n_plus_one_query_spec.rb +35 -35
  30. data/spec/bullet/detector/unused_eager_loading_spec.rb +19 -19
  31. data/spec/bullet/ext/object_spec.rb +7 -7
  32. data/spec/bullet/ext/string_spec.rb +5 -5
  33. data/spec/bullet/notification/base_spec.rb +32 -33
  34. data/spec/bullet/notification/counter_cache_spec.rb +2 -2
  35. data/spec/bullet/notification/n_plus_one_query_spec.rb +3 -3
  36. data/spec/bullet/notification/unused_eager_loading_spec.rb +2 -2
  37. data/spec/bullet/notification_collector_spec.rb +10 -10
  38. data/spec/bullet/rack_spec.rb +46 -46
  39. data/spec/bullet/registry/association_spec.rb +10 -10
  40. data/spec/bullet/registry/base_spec.rb +20 -20
  41. data/spec/bullet/registry/object_spec.rb +4 -4
  42. data/spec/bullet_spec.rb +20 -1
  43. data/spec/integration/active_record/association_spec.rb +106 -106
  44. data/spec/integration/counter_cache_spec.rb +12 -12
  45. data/spec/integration/mongoid/association_spec.rb +33 -33
  46. data/spec/models/comment.rb +1 -1
  47. data/spec/models/document.rb +2 -2
  48. data/spec/models/mongoid/address.rb +1 -1
  49. data/spec/models/mongoid/category.rb +2 -2
  50. data/spec/models/mongoid/comment.rb +1 -1
  51. data/spec/models/mongoid/company.rb +1 -1
  52. data/spec/models/mongoid/entry.rb +1 -1
  53. data/spec/models/mongoid/post.rb +3 -3
  54. data/spec/models/newspaper.rb +1 -1
  55. data/spec/spec_helper.rb +12 -12
  56. data/spec/support/mongo_seed.rb +6 -6
  57. data/spec/support/rack_double.rb +4 -3
  58. data/spec/support/sqlite_seed.rb +6 -7
  59. data/tasks/bullet_tasks.rake +2 -2
  60. data/test.sh +2 -0
  61. data/update.sh +2 -0
  62. metadata +5 -3
@@ -5,41 +5,41 @@ module Bullet
5
5
  describe Base do
6
6
  subject { Base.new(Post, [:comments, :votes]) }
7
7
 
8
- context "#title" do
9
- it "should raise NoMethodError" do
8
+ context '#title' do
9
+ it 'should raise NoMethodError' do
10
10
  expect { subject.title }.to raise_error(NoMethodError)
11
11
  end
12
12
  end
13
13
 
14
- context "#body" do
15
- it "should raise NoMethodError" do
14
+ context '#body' do
15
+ it 'should raise NoMethodError' do
16
16
  expect { subject.body }.to raise_error(NoMethodError)
17
17
  end
18
18
  end
19
19
 
20
- context "#whoami" do
21
- it "should display user name" do
20
+ context '#whoami' do
21
+ it 'should display user name' do
22
22
  user = `whoami`.chomp
23
23
  expect(subject.whoami).to eq("user: #{user}")
24
24
  end
25
25
 
26
- it "should leverage ENV parameter" do
27
- temp_env_variable("USER", "bogus") do
28
- expect(subject.whoami).to eq("user: bogus")
26
+ it 'should leverage ENV parameter' do
27
+ temp_env_variable('USER', 'bogus') do
28
+ expect(subject.whoami).to eq('user: bogus')
29
29
  end
30
30
  end
31
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("")
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
36
  end
37
37
  end
38
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("")
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
43
  end
44
44
  end
45
45
 
@@ -50,29 +50,28 @@ module Bullet
50
50
  ensure
51
51
  ENV[name] = old_value
52
52
  end
53
-
54
53
  end
55
54
 
56
- context "#body_with_caller" do
57
- it "should return body" do
58
- allow(subject).to receive(:body).and_return("body")
59
- allow(subject).to receive(:call_stack_messages).and_return("call_stack_messages")
55
+ context '#body_with_caller' do
56
+ it 'should return body' do
57
+ allow(subject).to receive(:body).and_return('body')
58
+ allow(subject).to receive(:call_stack_messages).and_return('call_stack_messages')
60
59
  expect(subject.body_with_caller).to eq("body\ncall_stack_messages\n")
61
60
  end
62
61
  end
63
62
 
64
- context "#notification_data" do
65
- it "should return notification data" do
66
- allow(subject).to receive(:whoami).and_return("whoami")
67
- allow(subject).to receive(:url).and_return("url")
68
- allow(subject).to receive(:title).and_return("title")
69
- allow(subject).to receive(:body_with_caller).and_return("body_with_caller")
70
- expect(subject.notification_data).to eq(:user => "whoami", :url => "url", :title => "title", :body => "body_with_caller")
63
+ context '#notification_data' do
64
+ it 'should return notification data' do
65
+ allow(subject).to receive(:whoami).and_return('whoami')
66
+ allow(subject).to receive(:url).and_return('url')
67
+ allow(subject).to receive(:title).and_return('title')
68
+ 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
70
  end
72
71
  end
73
72
 
74
- context "#notify_inline" do
75
- it "should send full_notice to notifier" do
73
+ context '#notify_inline' do
74
+ it 'should send full_notice to notifier' do
76
75
  notifier = double
77
76
  allow(subject).to receive(:notifier).and_return(notifier)
78
77
  allow(subject).to receive(:notification_data).and_return(:foo => :bar)
@@ -81,8 +80,8 @@ module Bullet
81
80
  end
82
81
  end
83
82
 
84
- context "#notify_out_of_channel" do
85
- it "should send full_out_of_channel to notifier" do
83
+ context '#notify_out_of_channel' do
84
+ it 'should send full_out_of_channel to notifier' do
86
85
  notifier = double
87
86
  allow(subject).to receive(:notifier).and_return(notifier)
88
87
  allow(subject).to receive(:notification_data).and_return(:foo => :bar)
@@ -5,8 +5,8 @@ module Bullet
5
5
  describe CounterCache do
6
6
  subject { CounterCache.new(Post, [:comments, :votes]) }
7
7
 
8
- it { expect(subject.body).to eq(" Post => [:comments, :votes]") }
9
- it { expect(subject.title).to eq("Need Counter Cache") }
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
@@ -3,12 +3,12 @@ require 'spec_helper'
3
3
  module Bullet
4
4
  module Notification
5
5
  describe NPlusOneQuery do
6
- subject { NPlusOneQuery.new([["caller1", "caller2"]], Post, [:comments, :votes], "path") }
6
+ subject { NPlusOneQuery.new([['caller1', 'caller2']], Post, [:comments, :votes], 'path') }
7
7
 
8
8
  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
- 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" ]) }
9
+ 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"]) }
10
10
  it { expect(subject.body).to eq(" Post => [:comments, :votes]\n Add to your finder: :includes => [:comments, :votes]") }
11
- it { expect(subject.title).to eq("USE eager loading in path") }
11
+ it { expect(subject.title).to eq('USE eager loading in path') }
12
12
  end
13
13
  end
14
14
  end
@@ -3,10 +3,10 @@ require 'spec_helper'
3
3
  module Bullet
4
4
  module Notification
5
5
  describe UnusedEagerLoading do
6
- subject { UnusedEagerLoading.new([""], Post, [:comments, :votes], "path") }
6
+ subject { UnusedEagerLoading.new([''], Post, [:comments, :votes], 'path') }
7
7
 
8
8
  it { expect(subject.body).to eq(" Post => [:comments, :votes]\n Remove from your finder: :includes => [:comments, :votes]") }
9
- it { expect(subject.title).to eq("AVOID eager loading in path") }
9
+ it { expect(subject.title).to eq('AVOID eager loading in path') }
10
10
  end
11
11
  end
12
12
  end
@@ -2,28 +2,28 @@ require 'spec_helper'
2
2
 
3
3
  module Bullet
4
4
  describe NotificationCollector do
5
- subject { NotificationCollector.new.tap { |collector| collector.add("value") } }
5
+ subject { NotificationCollector.new.tap { |collector| collector.add('value') } }
6
6
 
7
- context "#add" do
8
- it "should add a value" do
9
- subject.add("value1")
10
- expect(subject.collection).to be_include("value1")
7
+ context '#add' do
8
+ it 'should add a value' do
9
+ subject.add('value1')
10
+ expect(subject.collection).to be_include('value1')
11
11
  end
12
12
  end
13
13
 
14
- context "#reset" do
15
- it "should reset collector" do
14
+ context '#reset' do
15
+ it 'should reset collector' do
16
16
  subject.reset
17
17
  expect(subject.collection).to be_empty
18
18
  end
19
19
  end
20
20
 
21
- context "#notifications_present?" do
22
- it "should be true if collection is not empty" do
21
+ context '#notifications_present?' do
22
+ it 'should be true if collection is not empty' do
23
23
  expect(subject).to be_notifications_present
24
24
  end
25
25
 
26
- it "should be false if collection is empty" do
26
+ it 'should be false if collection is empty' do
27
27
  subject.reset
28
28
  expect(subject).not_to be_notifications_present
29
29
  end
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+
2
2
  require 'spec_helper'
3
3
 
4
4
  module Bullet
@@ -6,120 +6,120 @@ module Bullet
6
6
  let(:middleware) { Bullet::Rack.new app }
7
7
  let(:app) { Support::AppDouble.new }
8
8
 
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>")
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>')
13
13
  expect(middleware).to be_html_request(headers, response)
14
14
  end
15
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"}
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
18
  response = double(:body => "<html attr='hello'><head></head><body></body></html>")
19
19
  expect(middleware).to be_html_request(headers, response)
20
20
  end
21
21
 
22
- it "should be false if there is no Content-Type header" do
22
+ it 'should be false if there is no Content-Type header' do
23
23
  headers = {}
24
- response = double(:body => "<html><head></head><body></body></html>")
24
+ response = double(:body => '<html><head></head><body></body></html>')
25
25
  expect(middleware).not_to be_html_request(headers, response)
26
26
  end
27
27
 
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>")
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>')
31
31
  expect(middleware).not_to be_html_request(headers, response)
32
32
  end
33
33
 
34
34
  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>")
35
+ headers = { 'Content-Type' => 'text/html' }
36
+ response = double(:body => '<div>Partial</div>')
37
37
  expect(middleware).not_to be_html_request(headers, response)
38
38
  end
39
39
  end
40
40
 
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>")
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>')
44
44
  expect(middleware).not_to be_empty(response)
45
45
  end
46
46
 
47
- it "should be true if response is not found" do
48
- response = ["Not Found"]
47
+ it 'should be true if response is not found' do
48
+ response = ['Not Found']
49
49
  expect(middleware).to be_empty(response)
50
50
  end
51
51
 
52
- it "should be true if response body is empty" do
53
- response = double(:body => "")
52
+ it 'should be true if response body is empty' do
53
+ response = double(:body => '')
54
54
  expect(middleware).to be_empty(response)
55
55
  end
56
56
  end
57
57
 
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"
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'
62
62
  app.response = expected_response
63
63
  _, _, response = middleware.call({})
64
64
  expect(response).to eq(expected_response)
65
65
  end
66
66
 
67
- it "should change response body if notification is active" do
67
+ it 'should change response body if notification is active' do
68
68
  expect(Bullet).to receive(:notification?).and_return(true)
69
- expect(Bullet).to receive(:gather_inline_notifications).and_return("<bullet></bullet>")
69
+ expect(Bullet).to receive(:gather_inline_notifications).and_return('<bullet></bullet>')
70
70
  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>"])
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>'])
74
74
  end
75
75
 
76
- it "should set the right Content-Length if response body contains accents" do
76
+ it 'should set the right Content-Length if response body contains accents' do
77
77
  response = Support::ResponseDouble.new
78
- response.body = "<html><head></head><body>é</body></html>"
78
+ response.body = '<html><head></head><body>é</body></html>'
79
79
  app.response = response
80
80
  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")
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')
84
84
  end
85
85
  end
86
86
 
87
- context "when Bullet is disabled" do
87
+ context 'when Bullet is disabled' do
88
88
  before(:each) { allow(Bullet).to receive(:enable?).and_return(false) }
89
89
 
90
- it "should not call Bullet.start_request" do
90
+ it 'should not call Bullet.start_request' do
91
91
  expect(Bullet).not_to receive(:start_request)
92
92
  middleware.call({})
93
93
  end
94
94
  end
95
95
  end
96
96
 
97
- describe "#response_body" do
97
+ describe '#response_body' do
98
98
  let(:response) { double }
99
- let(:body_string) { "<html><body>My Body</body></html>" }
99
+ let(:body_string) { '<html><body>My Body</body></html>' }
100
100
 
101
- context "when `response` responds to `body`" do
101
+ context 'when `response` responds to `body`' do
102
102
  before { allow(response).to receive(:body).and_return(body) }
103
103
 
104
- context "when `body` returns an Array" do
104
+ context 'when `body` returns an Array' do
105
105
  let(:body) { [body_string, 'random string'] }
106
- it "should return the plain body string" do
106
+ it 'should return the plain body string' do
107
107
  expect(middleware.response_body(response)).to eq body_string
108
108
  end
109
109
  end
110
110
 
111
- context "when `body` does not return an Array" do
111
+ context 'when `body` does not return an Array' do
112
112
  let(:body) { body_string }
113
- it "should return the plain body string" do
113
+ it 'should return the plain body string' do
114
114
  expect(middleware.response_body(response)).to eq body_string
115
115
  end
116
116
  end
117
117
  end
118
118
 
119
- context "when `response` does not respond to `body`" do
119
+ context 'when `response` does not respond to `body`' do
120
120
  before { allow(response).to receive(:first).and_return(body_string) }
121
121
 
122
- it "should return the plain body string" do
122
+ it 'should return the plain body string' do
123
123
  expect(middleware.response_body(response)).to eq body_string
124
124
  end
125
125
  end
@@ -3,22 +3,22 @@ require 'spec_helper'
3
3
  module Bullet
4
4
  module Registry
5
5
  describe Association do
6
- subject { Association.new.tap { |association| association.add(["key1", "key2"], "value") } }
6
+ subject { Association.new.tap { |association| association.add(['key1', 'key2'], 'value') } }
7
7
 
8
- context "#merge" do
9
- it "should merge key/value" do
10
- subject.merge("key0", "value0")
11
- expect(subject["key0"]).to be_include("value0")
8
+ context '#merge' do
9
+ it 'should merge key/value' do
10
+ subject.merge('key0', 'value0')
11
+ expect(subject['key0']).to be_include('value0')
12
12
  end
13
13
  end
14
14
 
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"])
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'])
18
18
  end
19
19
 
20
- it "should return empty if key does not exist" do
21
- expect(subject.similarly_associated("key3", Set.new(["value"]))).to be_empty
20
+ it 'should return empty if key does not exist' do
21
+ expect(subject.similarly_associated('key3', Set.new(['value']))).to be_empty
22
22
  end
23
23
  end
24
24
  end
@@ -3,40 +3,40 @@ require 'spec_helper'
3
3
  module Bullet
4
4
  module Registry
5
5
  describe Base do
6
- subject { Base.new.tap { |base| base.add("key", "value") } }
6
+ subject { Base.new.tap { |base| base.add('key', 'value') } }
7
7
 
8
- context "#[]" do
9
- it "should get value by key" do
10
- expect(subject["key"]).to eq(Set.new(["value"]))
8
+ context '#[]' do
9
+ it 'should get value by key' do
10
+ expect(subject['key']).to eq(Set.new(['value']))
11
11
  end
12
12
  end
13
13
 
14
- context "#delete" do
15
- it "should delete key" do
16
- subject.delete("key")
17
- expect(subject["key"]).to be_nil
14
+ context '#delete' do
15
+ it 'should delete key' do
16
+ subject.delete('key')
17
+ expect(subject['key']).to be_nil
18
18
  end
19
19
  end
20
20
 
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"]))
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']))
25
25
  end
26
26
 
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"]))
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']))
30
30
  end
31
31
  end
32
32
 
33
- context "#include?" do
34
- it "should include key/value" do
35
- expect(subject.include?("key", "value")).to eq true
33
+ context '#include?' do
34
+ it 'should include key/value' do
35
+ expect(subject.include?('key', 'value')).to eq true
36
36
  end
37
37
 
38
- it "should not include wrong key/value" do
39
- expect(subject.include?("key", "val")).to eq false
38
+ it 'should not include wrong key/value' do
39
+ expect(subject.include?('key', 'val')).to eq false
40
40
  end
41
41
  end
42
42
  end
@@ -7,14 +7,14 @@ module Bullet
7
7
  let(:another_post) { Post.last }
8
8
  subject { Object.new.tap { |object| object.add(post.bullet_key) } }
9
9
 
10
- context "#include?" do
11
- it "should include the object" do
10
+ context '#include?' do
11
+ it 'should include the object' do
12
12
  expect(subject).to be_include(post.bullet_key)
13
13
  end
14
14
  end
15
15
 
16
- context "#add" do
17
- it "should add an object" do
16
+ context '#add' do
17
+ it 'should add an object' do
18
18
  subject.add(another_post.bullet_key)
19
19
  expect(subject).to be_include(another_post.bullet_key)
20
20
  end
data/spec/bullet_spec.rb CHANGED
@@ -4,7 +4,6 @@ describe Bullet, focused: true do
4
4
  subject { Bullet }
5
5
 
6
6
  describe '#enable' do
7
-
8
7
  context 'enable Bullet' do
9
8
  before do
10
9
  # Bullet.enable
@@ -95,6 +94,26 @@ describe Bullet, focused: true do
95
94
  end
96
95
  end
97
96
 
97
+ describe '#delete_whitelist' do
98
+ context "for 'special' class names" do
99
+ 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
+ expect(Bullet.whitelist[:n_plus_one_query]).to eq({})
103
+ end
104
+ end
105
+
106
+ context 'when exists multiple definitions' do
107
+ 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)
111
+ expect(Bullet.get_whitelist_associations(:n_plus_one_query, 'Klass')).to include :department
112
+ expect(Bullet.get_whitelist_associations(:n_plus_one_query, 'Klass')).to_not include :team
113
+ end
114
+ end
115
+ end
116
+
98
117
  describe '#perform_out_of_channel_notifications' do
99
118
  let(:notification) { double }
100
119