bullet 7.0.7 → 7.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -1
  3. data/README.md +6 -3
  4. data/lib/bullet/active_record4.rb +10 -0
  5. data/lib/bullet/active_record41.rb +10 -0
  6. data/lib/bullet/active_record42.rb +10 -0
  7. data/lib/bullet/active_record5.rb +18 -0
  8. data/lib/bullet/active_record52.rb +18 -0
  9. data/lib/bullet/active_record60.rb +18 -0
  10. data/lib/bullet/active_record61.rb +18 -0
  11. data/lib/bullet/active_record70.rb +32 -8
  12. data/lib/bullet/active_record71.rb +308 -0
  13. data/lib/bullet/dependency.rb +12 -0
  14. data/lib/bullet/detector/n_plus_one_query.rb +2 -5
  15. data/lib/bullet/detector/unused_eager_loading.rb +5 -2
  16. data/lib/bullet/ext/object.rb +14 -3
  17. data/lib/bullet/mongoid8x.rb +59 -0
  18. data/lib/bullet/notification/base.rb +9 -8
  19. data/lib/bullet/notification/counter_cache.rb +1 -1
  20. data/lib/bullet/rack.rb +4 -2
  21. data/lib/bullet/registry/association.rb +2 -1
  22. data/lib/bullet/stack_trace_filter.rb +3 -2
  23. data/lib/bullet/version.rb +1 -1
  24. data/lib/bullet.rb +7 -2
  25. metadata +7 -155
  26. data/.github/workflows/main.yml +0 -82
  27. data/.gitignore +0 -15
  28. data/.rspec +0 -2
  29. data/Gemfile +0 -24
  30. data/Gemfile.mongoid +0 -12
  31. data/Gemfile.mongoid-4.0 +0 -15
  32. data/Gemfile.mongoid-5.0 +0 -15
  33. data/Gemfile.mongoid-6.0 +0 -15
  34. data/Gemfile.mongoid-7.0 +0 -15
  35. data/Gemfile.rails-4.0 +0 -16
  36. data/Gemfile.rails-4.1 +0 -16
  37. data/Gemfile.rails-4.2 +0 -16
  38. data/Gemfile.rails-5.0 +0 -15
  39. data/Gemfile.rails-5.1 +0 -15
  40. data/Gemfile.rails-5.2 +0 -15
  41. data/Gemfile.rails-6.0 +0 -15
  42. data/Gemfile.rails-6.1 +0 -15
  43. data/Gemfile.rails-7.0 +0 -10
  44. data/Guardfile +0 -8
  45. data/Hacking.md +0 -75
  46. data/Rakefile +0 -51
  47. data/bullet.gemspec +0 -33
  48. data/perf/benchmark.rb +0 -118
  49. data/rails/init.rb +0 -3
  50. data/spec/bullet/detector/association_spec.rb +0 -28
  51. data/spec/bullet/detector/base_spec.rb +0 -10
  52. data/spec/bullet/detector/counter_cache_spec.rb +0 -58
  53. data/spec/bullet/detector/n_plus_one_query_spec.rb +0 -150
  54. data/spec/bullet/detector/unused_eager_loading_spec.rb +0 -126
  55. data/spec/bullet/ext/object_spec.rb +0 -44
  56. data/spec/bullet/ext/string_spec.rb +0 -15
  57. data/spec/bullet/notification/base_spec.rb +0 -94
  58. data/spec/bullet/notification/counter_cache_spec.rb +0 -14
  59. data/spec/bullet/notification/n_plus_one_query_spec.rb +0 -29
  60. data/spec/bullet/notification/unused_eager_loading_spec.rb +0 -18
  61. data/spec/bullet/notification_collector_spec.rb +0 -34
  62. data/spec/bullet/rack_spec.rb +0 -296
  63. data/spec/bullet/registry/association_spec.rb +0 -28
  64. data/spec/bullet/registry/base_spec.rb +0 -46
  65. data/spec/bullet/registry/object_spec.rb +0 -26
  66. data/spec/bullet/stack_trace_filter_spec.rb +0 -26
  67. data/spec/bullet_spec.rb +0 -136
  68. data/spec/integration/active_record/association_spec.rb +0 -822
  69. data/spec/integration/counter_cache_spec.rb +0 -68
  70. data/spec/integration/mongoid/association_spec.rb +0 -246
  71. data/spec/models/address.rb +0 -5
  72. data/spec/models/attachment.rb +0 -5
  73. data/spec/models/author.rb +0 -5
  74. data/spec/models/base_user.rb +0 -7
  75. data/spec/models/category.rb +0 -12
  76. data/spec/models/city.rb +0 -5
  77. data/spec/models/client.rb +0 -8
  78. data/spec/models/comment.rb +0 -8
  79. data/spec/models/company.rb +0 -5
  80. data/spec/models/country.rb +0 -5
  81. data/spec/models/deal.rb +0 -5
  82. data/spec/models/document.rb +0 -7
  83. data/spec/models/entry.rb +0 -5
  84. data/spec/models/firm.rb +0 -7
  85. data/spec/models/folder.rb +0 -4
  86. data/spec/models/group.rb +0 -4
  87. data/spec/models/mongoid/address.rb +0 -9
  88. data/spec/models/mongoid/category.rb +0 -10
  89. data/spec/models/mongoid/comment.rb +0 -9
  90. data/spec/models/mongoid/company.rb +0 -9
  91. data/spec/models/mongoid/entry.rb +0 -9
  92. data/spec/models/mongoid/post.rb +0 -14
  93. data/spec/models/mongoid/user.rb +0 -7
  94. data/spec/models/newspaper.rb +0 -5
  95. data/spec/models/page.rb +0 -4
  96. data/spec/models/person.rb +0 -5
  97. data/spec/models/pet.rb +0 -5
  98. data/spec/models/post.rb +0 -34
  99. data/spec/models/relationship.rb +0 -6
  100. data/spec/models/reply.rb +0 -5
  101. data/spec/models/role.rb +0 -7
  102. data/spec/models/student.rb +0 -5
  103. data/spec/models/submission.rb +0 -7
  104. data/spec/models/teacher.rb +0 -5
  105. data/spec/models/user.rb +0 -8
  106. data/spec/models/writer.rb +0 -4
  107. data/spec/spec_helper.rb +0 -97
  108. data/spec/support/bullet_ext.rb +0 -56
  109. data/spec/support/mongo_seed.rb +0 -59
  110. data/spec/support/rack_double.rb +0 -49
  111. data/spec/support/sqlite_seed.rb +0 -284
  112. data/test.sh +0 -15
  113. data/update.sh +0 -10
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Bullet
6
- module Registry
7
- describe Association do
8
- subject { Association.new.tap { |association| association.add(%w[key1 key2], 'value') } }
9
-
10
- context '#merge' do
11
- it 'should merge key/value' do
12
- subject.merge('key0', 'value0')
13
- expect(subject['key0']).to be_include('value0')
14
- end
15
- end
16
-
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])
20
- end
21
-
22
- it 'should return empty if key does not exist' do
23
- expect(subject.similarly_associated('key3', Set.new(%w[value]))).to be_empty
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Bullet
6
- module Registry
7
- describe Base do
8
- subject { Base.new.tap { |base| base.add('key', 'value') } }
9
-
10
- context '#[]' do
11
- it 'should get value by key' do
12
- expect(subject['key']).to eq(Set.new(%w[value]))
13
- end
14
- end
15
-
16
- context '#delete' do
17
- it 'should delete key' do
18
- subject.delete('key')
19
- expect(subject['key']).to be_nil
20
- end
21
- end
22
-
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]))
27
- end
28
-
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]))
32
- end
33
- end
34
-
35
- context '#include?' do
36
- it 'should include key/value' do
37
- expect(subject.include?('key', 'value')).to eq true
38
- end
39
-
40
- it 'should not include wrong key/value' do
41
- expect(subject.include?('key', 'val')).to eq false
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Bullet
6
- module Registry
7
- describe Object do
8
- let(:post) { Post.first }
9
- let(:another_post) { Post.last }
10
- subject { Object.new.tap { |object| object.add(post.bullet_key) } }
11
-
12
- context '#include?' do
13
- it 'should include the object' do
14
- expect(subject).to be_include(post.bullet_key)
15
- end
16
- end
17
-
18
- context '#add' do
19
- it 'should add an object' do
20
- subject.add(another_post.bullet_key)
21
- expect(subject).to be_include(another_post.bullet_key)
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Bullet
6
- RSpec.describe StackTraceFilter do
7
- let(:dummy_class) { Class.new { extend StackTraceFilter } }
8
- let(:root_path) { Dir.pwd }
9
- let(:bundler_path) { Bundler.bundle_path }
10
-
11
- describe '#caller_in_project' do
12
- it 'gets the caller in the project' do
13
- expect(dummy_class).to receive(:call_stacks).and_return({
14
- 'Post:1' => [
15
- File.join(root_path, 'lib/bullet.rb'),
16
- File.join(root_path, 'vendor/uniform_notifier.rb'),
17
- File.join(bundler_path, 'rack.rb')
18
- ]
19
- })
20
- expect(dummy_class.caller_in_project('Post:1')).to eq([
21
- File.join(root_path, 'lib/bullet.rb')
22
- ])
23
- end
24
- end
25
- end
26
- end
data/spec/bullet_spec.rb DELETED
@@ -1,136 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Bullet, focused: true do
6
- subject { Bullet }
7
-
8
- describe '#enable' do
9
- context 'enable Bullet' do
10
- before do
11
- # Bullet.enable
12
- # Do nothing. Bullet has already been enabled for the whole test suite.
13
- end
14
-
15
- it 'should be enabled' do
16
- expect(subject).to be_enable
17
- end
18
-
19
- context 'disable Bullet' do
20
- before { Bullet.enable = false }
21
-
22
- it 'should be disabled' do
23
- expect(subject).to_not be_enable
24
- end
25
-
26
- context 'enable Bullet again without patching again the orms' do
27
- before do
28
- expect(Bullet::Mongoid).not_to receive(:enable) if defined?(Bullet::Mongoid)
29
- expect(Bullet::ActiveRecord).not_to receive(:enable) if defined?(Bullet::ActiveRecord)
30
- Bullet.enable = true
31
- end
32
-
33
- it 'should be enabled again' do
34
- expect(subject).to be_enable
35
- end
36
- end
37
- end
38
- end
39
- end
40
-
41
- describe '#start?' do
42
- context 'when bullet is disabled' do
43
- before(:each) { Bullet.enable = false }
44
-
45
- it 'should not be started' do
46
- expect(Bullet).not_to be_start
47
- end
48
- end
49
- end
50
-
51
- describe '#debug' do
52
- before(:each) { $stdout = StringIO.new }
53
-
54
- after(:each) { $stdout = STDOUT }
55
-
56
- context 'when debug is enabled' do
57
- before(:each) { ENV['BULLET_DEBUG'] = 'true' }
58
-
59
- after(:each) { ENV['BULLET_DEBUG'] = 'false' }
60
-
61
- it 'should output debug information' do
62
- Bullet.debug('debug_message', 'this is helpful information')
63
-
64
- expect($stdout.string).to eq("[Bullet][debug_message] this is helpful information\n")
65
- end
66
- end
67
-
68
- context 'when debug is disabled' do
69
- it 'should output debug information' do
70
- Bullet.debug('debug_message', 'this is helpful information')
71
-
72
- expect($stdout.string).to be_empty
73
- end
74
- end
75
- end
76
-
77
- describe '#add_safelist' do
78
- context "for 'special' class names" do
79
- it 'is added to the safelist successfully' do
80
- Bullet.add_safelist(type: :n_plus_one_query, class_name: 'Klass', association: :department)
81
- expect(Bullet.get_safelist_associations(:n_plus_one_query, 'Klass')).to include :department
82
- end
83
- end
84
- end
85
-
86
- describe '#delete_safelist' do
87
- context "for 'special' class names" do
88
- it 'is deleted from the safelist successfully' do
89
- Bullet.add_safelist(type: :n_plus_one_query, class_name: 'Klass', association: :department)
90
- Bullet.delete_safelist(type: :n_plus_one_query, class_name: 'Klass', association: :department)
91
- expect(Bullet.safelist[:n_plus_one_query]).to eq({})
92
- end
93
- end
94
-
95
- context 'when exists multiple definitions' do
96
- it 'is deleted from the safelist successfully' do
97
- Bullet.add_safelist(type: :n_plus_one_query, class_name: 'Klass', association: :department)
98
- Bullet.add_safelist(type: :n_plus_one_query, class_name: 'Klass', association: :team)
99
- Bullet.delete_safelist(type: :n_plus_one_query, class_name: 'Klass', association: :team)
100
- expect(Bullet.get_safelist_associations(:n_plus_one_query, 'Klass')).to include :department
101
- expect(Bullet.get_safelist_associations(:n_plus_one_query, 'Klass')).to_not include :team
102
- end
103
- end
104
- end
105
-
106
- describe '#perform_out_of_channel_notifications' do
107
- let(:notification) { double }
108
-
109
- before do
110
- allow(Bullet).to receive(:for_each_active_notifier_with_notification).and_yield(notification)
111
- allow(notification).to receive(:notify_out_of_channel)
112
- end
113
-
114
- context 'when called with Rack environment hash' do
115
- let(:env) { { 'REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/path', 'QUERY_STRING' => 'foo=bar' } }
116
-
117
- context "when env['REQUEST_URI'] is nil" do
118
- before { env['REQUEST_URI'] = nil }
119
-
120
- it 'should notification.url is built' do
121
- expect(notification).to receive(:url=).with('GET /path?foo=bar')
122
- Bullet.perform_out_of_channel_notifications(env)
123
- end
124
- end
125
-
126
- context "when env['REQUEST_URI'] is present" do
127
- before { env['REQUEST_URI'] = 'http://example.com/path' }
128
-
129
- it "should notification.url is env['REQUEST_URI']" do
130
- expect(notification).to receive(:url=).with('GET http://example.com/path')
131
- Bullet.perform_out_of_channel_notifications(env)
132
- end
133
- end
134
- end
135
- end
136
- end