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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.rails-5.2 +15 -0
- data/Guardfile +2 -2
- data/Rakefile +16 -17
- data/bullet.gemspec +11 -11
- data/lib/bullet/active_record52.rb +225 -0
- data/lib/bullet/dependency.rb +6 -0
- data/lib/bullet/detector/association.rb +3 -2
- data/lib/bullet/detector/counter_cache.rb +4 -3
- data/lib/bullet/detector/n_plus_one_query.rb +6 -5
- data/lib/bullet/detector/unused_eager_loading.rb +4 -3
- data/lib/bullet/ext/string.rb +1 -1
- data/lib/bullet/mongoid4x.rb +1 -1
- data/lib/bullet/mongoid5x.rb +1 -1
- data/lib/bullet/mongoid6x.rb +1 -1
- data/lib/bullet/notification/base.rb +9 -8
- data/lib/bullet/notification/counter_cache.rb +1 -1
- data/lib/bullet/notification/n_plus_one_query.rb +2 -1
- data/lib/bullet/notification/unused_eager_loading.rb +2 -1
- data/lib/bullet/rack.rb +5 -5
- data/lib/bullet/stack_trace_filter.rb +2 -2
- data/lib/bullet/version.rb +2 -2
- data/lib/bullet.rb +15 -7
- data/lib/generators/bullet/install_generator.rb +5 -5
- data/perf/benchmark.rb +6 -8
- data/spec/bullet/detector/association_spec.rb +4 -4
- data/spec/bullet/detector/counter_cache_spec.rb +11 -11
- data/spec/bullet/detector/n_plus_one_query_spec.rb +35 -35
- data/spec/bullet/detector/unused_eager_loading_spec.rb +19 -19
- data/spec/bullet/ext/object_spec.rb +7 -7
- data/spec/bullet/ext/string_spec.rb +5 -5
- data/spec/bullet/notification/base_spec.rb +32 -33
- data/spec/bullet/notification/counter_cache_spec.rb +2 -2
- data/spec/bullet/notification/n_plus_one_query_spec.rb +3 -3
- data/spec/bullet/notification/unused_eager_loading_spec.rb +2 -2
- data/spec/bullet/notification_collector_spec.rb +10 -10
- data/spec/bullet/rack_spec.rb +46 -46
- data/spec/bullet/registry/association_spec.rb +10 -10
- data/spec/bullet/registry/base_spec.rb +20 -20
- data/spec/bullet/registry/object_spec.rb +4 -4
- data/spec/bullet_spec.rb +20 -1
- data/spec/integration/active_record/association_spec.rb +106 -106
- data/spec/integration/counter_cache_spec.rb +12 -12
- data/spec/integration/mongoid/association_spec.rb +33 -33
- data/spec/models/comment.rb +1 -1
- data/spec/models/document.rb +2 -2
- data/spec/models/mongoid/address.rb +1 -1
- data/spec/models/mongoid/category.rb +2 -2
- data/spec/models/mongoid/comment.rb +1 -1
- data/spec/models/mongoid/company.rb +1 -1
- data/spec/models/mongoid/entry.rb +1 -1
- data/spec/models/mongoid/post.rb +3 -3
- data/spec/models/newspaper.rb +1 -1
- data/spec/spec_helper.rb +12 -12
- data/spec/support/mongo_seed.rb +6 -6
- data/spec/support/rack_double.rb +4 -3
- data/spec/support/sqlite_seed.rb +6 -7
- data/tasks/bullet_tasks.rake +2 -2
- data/test.sh +2 -0
- data/update.sh +2 -0
- 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
|
|
9
|
-
it
|
|
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
|
|
15
|
-
it
|
|
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
|
|
21
|
-
it
|
|
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
|
|
27
|
-
temp_env_variable(
|
|
28
|
-
expect(subject.whoami).to eq(
|
|
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
|
|
33
|
-
temp_env_variable(
|
|
34
|
-
expect(subject).to receive(:`).with(
|
|
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
|
|
40
|
-
temp_env_variable(
|
|
41
|
-
expect(subject).to receive(:`).with(
|
|
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
|
|
57
|
-
it
|
|
58
|
-
allow(subject).to receive(:body).and_return(
|
|
59
|
-
allow(subject).to receive(:call_stack_messages).and_return(
|
|
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
|
|
65
|
-
it
|
|
66
|
-
allow(subject).to receive(:whoami).and_return(
|
|
67
|
-
allow(subject).to receive(:url).and_return(
|
|
68
|
-
allow(subject).to receive(:title).and_return(
|
|
69
|
-
allow(subject).to receive(:body_with_caller).and_return(
|
|
70
|
-
expect(subject.notification_data).to eq(:user =>
|
|
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
|
|
75
|
-
it
|
|
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
|
|
85
|
-
it
|
|
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(
|
|
9
|
-
it { expect(subject.title).to eq(
|
|
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([[
|
|
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([
|
|
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(
|
|
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([
|
|
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(
|
|
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(
|
|
5
|
+
subject { NotificationCollector.new.tap { |collector| collector.add('value') } }
|
|
6
6
|
|
|
7
|
-
context
|
|
8
|
-
it
|
|
9
|
-
subject.add(
|
|
10
|
-
expect(subject.collection).to be_include(
|
|
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
|
|
15
|
-
it
|
|
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
|
|
22
|
-
it
|
|
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
|
|
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
|
data/spec/bullet/rack_spec.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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
|
|
10
|
-
it
|
|
11
|
-
headers = {
|
|
12
|
-
response = double(:body =>
|
|
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
|
|
17
|
-
headers = {
|
|
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
|
|
22
|
+
it 'should be false if there is no Content-Type header' do
|
|
23
23
|
headers = {}
|
|
24
|
-
response = double(:body =>
|
|
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
|
|
29
|
-
headers = {
|
|
30
|
-
response = double(:body =>
|
|
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 = {
|
|
36
|
-
response = double(:body =>
|
|
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
|
|
42
|
-
it
|
|
43
|
-
response = double(:body =>
|
|
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
|
|
48
|
-
response = [
|
|
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
|
|
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
|
|
59
|
-
context
|
|
60
|
-
it
|
|
61
|
-
expected_response = Support::ResponseDouble.new
|
|
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
|
|
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(
|
|
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({
|
|
72
|
-
expect(headers[
|
|
73
|
-
expect(response).to eq([
|
|
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
|
|
76
|
+
it 'should set the right Content-Length if response body contains accents' do
|
|
77
77
|
response = Support::ResponseDouble.new
|
|
78
|
-
response.body =
|
|
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(
|
|
82
|
-
status, headers, response = middleware.call({
|
|
83
|
-
expect(headers[
|
|
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
|
|
87
|
+
context 'when Bullet is disabled' do
|
|
88
88
|
before(:each) { allow(Bullet).to receive(:enable?).and_return(false) }
|
|
89
89
|
|
|
90
|
-
it
|
|
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
|
|
97
|
+
describe '#response_body' do
|
|
98
98
|
let(:response) { double }
|
|
99
|
-
let(:body_string) {
|
|
99
|
+
let(:body_string) { '<html><body>My Body</body></html>' }
|
|
100
100
|
|
|
101
|
-
context
|
|
101
|
+
context 'when `response` responds to `body`' do
|
|
102
102
|
before { allow(response).to receive(:body).and_return(body) }
|
|
103
103
|
|
|
104
|
-
context
|
|
104
|
+
context 'when `body` returns an Array' do
|
|
105
105
|
let(:body) { [body_string, 'random string'] }
|
|
106
|
-
it
|
|
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
|
|
111
|
+
context 'when `body` does not return an Array' do
|
|
112
112
|
let(:body) { body_string }
|
|
113
|
-
it
|
|
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
|
|
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
|
|
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([
|
|
6
|
+
subject { Association.new.tap { |association| association.add(['key1', 'key2'], 'value') } }
|
|
7
7
|
|
|
8
|
-
context
|
|
9
|
-
it
|
|
10
|
-
subject.merge(
|
|
11
|
-
expect(subject[
|
|
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
|
|
16
|
-
it
|
|
17
|
-
expect(subject.similarly_associated(
|
|
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
|
|
21
|
-
expect(subject.similarly_associated(
|
|
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(
|
|
6
|
+
subject { Base.new.tap { |base| base.add('key', 'value') } }
|
|
7
7
|
|
|
8
|
-
context
|
|
9
|
-
it
|
|
10
|
-
expect(subject[
|
|
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
|
|
15
|
-
it
|
|
16
|
-
subject.delete(
|
|
17
|
-
expect(subject[
|
|
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
|
|
22
|
-
it
|
|
23
|
-
subject.add(
|
|
24
|
-
expect(subject[
|
|
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
|
|
28
|
-
subject.add(
|
|
29
|
-
expect(subject[
|
|
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
|
|
34
|
-
it
|
|
35
|
-
expect(subject.include?(
|
|
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
|
|
39
|
-
expect(subject.include?(
|
|
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
|
|
11
|
-
it
|
|
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
|
|
17
|
-
it
|
|
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
|
|