bullet 6.0.2 → 6.1.4
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/.travis.yml +3 -1
- data/CHANGELOG.md +25 -0
- data/Gemfile.rails-6.0 +1 -1
- data/Gemfile.rails-6.1 +15 -0
- data/README.md +12 -2
- data/lib/bullet.rb +31 -20
- data/lib/bullet/active_job.rb +1 -3
- data/lib/bullet/active_record4.rb +9 -23
- data/lib/bullet/active_record41.rb +7 -19
- data/lib/bullet/active_record42.rb +8 -16
- data/lib/bullet/active_record5.rb +188 -170
- data/lib/bullet/active_record52.rb +187 -161
- data/lib/bullet/active_record60.rb +194 -175
- data/lib/bullet/active_record61.rb +278 -0
- data/lib/bullet/bullet_xhr.js +17 -23
- data/lib/bullet/dependency.rb +42 -34
- data/lib/bullet/detector/association.rb +24 -18
- data/lib/bullet/detector/base.rb +1 -2
- data/lib/bullet/detector/counter_cache.rb +10 -6
- data/lib/bullet/detector/n_plus_one_query.rb +18 -8
- data/lib/bullet/detector/unused_eager_loading.rb +5 -2
- data/lib/bullet/mongoid4x.rb +3 -7
- data/lib/bullet/mongoid5x.rb +3 -7
- data/lib/bullet/mongoid6x.rb +3 -7
- data/lib/bullet/mongoid7x.rb +3 -7
- data/lib/bullet/notification/base.rb +14 -18
- data/lib/bullet/notification/n_plus_one_query.rb +2 -4
- data/lib/bullet/notification/unused_eager_loading.rb +2 -4
- data/lib/bullet/rack.rb +23 -15
- data/lib/bullet/stack_trace_filter.rb +7 -16
- data/lib/bullet/version.rb +1 -1
- data/lib/generators/bullet/install_generator.rb +23 -23
- data/perf/benchmark.rb +8 -14
- data/spec/bullet/detector/counter_cache_spec.rb +6 -6
- data/spec/bullet/detector/n_plus_one_query_spec.rb +7 -3
- data/spec/bullet/detector/unused_eager_loading_spec.rb +19 -6
- data/spec/bullet/notification/base_spec.rb +1 -3
- data/spec/bullet/notification/n_plus_one_query_spec.rb +16 -3
- data/spec/bullet/notification/unused_eager_loading_spec.rb +5 -1
- data/spec/bullet/rack_spec.rb +133 -7
- data/spec/bullet/registry/association_spec.rb +2 -2
- data/spec/bullet/registry/base_spec.rb +1 -1
- data/spec/bullet_spec.rb +10 -29
- data/spec/integration/active_record/association_spec.rb +77 -122
- data/spec/integration/counter_cache_spec.rb +10 -30
- data/spec/integration/mongoid/association_spec.rb +18 -32
- data/spec/models/attachment.rb +5 -0
- data/spec/models/folder.rb +1 -2
- data/spec/models/group.rb +1 -2
- data/spec/models/page.rb +1 -2
- data/spec/models/submission.rb +1 -0
- data/spec/models/user.rb +1 -0
- data/spec/models/writer.rb +1 -2
- data/spec/spec_helper.rb +6 -10
- data/spec/support/bullet_ext.rb +8 -9
- data/spec/support/mongo_seed.rb +2 -16
- data/spec/support/sqlite_seed.rb +8 -0
- metadata +10 -6
data/lib/bullet/mongoid7x.rb
CHANGED
@@ -23,7 +23,7 @@ module Bullet
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def each(&block)
|
26
|
-
return to_enum unless
|
26
|
+
return to_enum unless block
|
27
27
|
|
28
28
|
records = []
|
29
29
|
origin_each { |record| records << record }
|
@@ -37,9 +37,7 @@ module Bullet
|
|
37
37
|
|
38
38
|
def eager_load(docs)
|
39
39
|
associations = criteria.inclusions.map(&:name)
|
40
|
-
docs.each
|
41
|
-
Bullet::Detector::NPlusOneQuery.add_object_associations(doc, associations)
|
42
|
-
end
|
40
|
+
docs.each { |doc| Bullet::Detector::NPlusOneQuery.add_object_associations(doc, associations) }
|
43
41
|
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(docs, associations)
|
44
42
|
origin_eager_load(docs)
|
45
43
|
end
|
@@ -50,9 +48,7 @@ module Bullet
|
|
50
48
|
|
51
49
|
def get_relation(name, association, object, reload = false)
|
52
50
|
result = origin_get_relation(name, association, object, reload)
|
53
|
-
unless association.embedded?
|
54
|
-
Bullet::Detector::NPlusOneQuery.call_association(self, name)
|
55
|
-
end
|
51
|
+
Bullet::Detector::NPlusOneQuery.call_association(self, name) unless association.embedded?
|
56
52
|
result
|
57
53
|
end
|
58
54
|
end
|
@@ -8,7 +8,8 @@ module Bullet
|
|
8
8
|
|
9
9
|
def initialize(base_class, association_or_associations, path = nil)
|
10
10
|
@base_class = base_class
|
11
|
-
@associations =
|
11
|
+
@associations =
|
12
|
+
association_or_associations.is_a?(Array) ? association_or_associations : [association_or_associations]
|
12
13
|
@path = path
|
13
14
|
end
|
14
15
|
|
@@ -25,16 +26,16 @@ module Bullet
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def whoami
|
28
|
-
@user ||=
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
29
|
+
@user ||=
|
30
|
+
ENV['USER'].presence ||
|
31
|
+
(
|
32
|
+
begin
|
33
|
+
`whoami`.chomp
|
34
|
+
rescue StandardError
|
35
|
+
''
|
36
|
+
end
|
37
|
+
)
|
38
|
+
@user.present? ? "user: #{@user}" : ''
|
38
39
|
end
|
39
40
|
|
40
41
|
def body_with_caller
|
@@ -54,12 +55,7 @@ module Bullet
|
|
54
55
|
end
|
55
56
|
|
56
57
|
def notification_data
|
57
|
-
{
|
58
|
-
user: whoami,
|
59
|
-
url: url,
|
60
|
-
title: title,
|
61
|
-
body: body_with_caller
|
62
|
-
}
|
58
|
+
{ user: whoami, url: url, title: title, body: body_with_caller }
|
63
59
|
end
|
64
60
|
|
65
61
|
def eql?(other)
|
@@ -77,7 +73,7 @@ module Bullet
|
|
77
73
|
end
|
78
74
|
|
79
75
|
def associations_str
|
80
|
-
"
|
76
|
+
".includes(#{@associations.map { |a| a.to_s.to_sym }.inspect})"
|
81
77
|
end
|
82
78
|
end
|
83
79
|
end
|
@@ -10,7 +10,7 @@ module Bullet
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def body
|
13
|
-
"#{klazz_associations_str}\n Add to your
|
13
|
+
"#{klazz_associations_str}\n Add to your query: #{associations_str}"
|
14
14
|
end
|
15
15
|
|
16
16
|
def title
|
@@ -18,9 +18,7 @@ module Bullet
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def notification_data
|
21
|
-
super.merge(
|
22
|
-
backtrace: []
|
23
|
-
)
|
21
|
+
super.merge(backtrace: [])
|
24
22
|
end
|
25
23
|
|
26
24
|
protected
|
@@ -10,7 +10,7 @@ module Bullet
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def body
|
13
|
-
"#{klazz_associations_str}\n Remove from your
|
13
|
+
"#{klazz_associations_str}\n Remove from your query: #{associations_str}"
|
14
14
|
end
|
15
15
|
|
16
16
|
def title
|
@@ -18,9 +18,7 @@ module Bullet
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def notification_data
|
21
|
-
super.merge(
|
22
|
-
backtrace: []
|
23
|
-
)
|
21
|
+
super.merge(backtrace: [])
|
24
22
|
end
|
25
23
|
|
26
24
|
protected
|
data/lib/bullet/rack.rb
CHANGED
@@ -15,15 +15,16 @@ module Bullet
|
|
15
15
|
status, headers, response = @app.call(env)
|
16
16
|
|
17
17
|
response_body = nil
|
18
|
+
|
18
19
|
if Bullet.notification?
|
19
|
-
if !file?(headers) && !sse?(headers) && !empty?(response) && status == 200
|
20
|
+
if Bullet.inject_into_page? && !file?(headers) && !sse?(headers) && !empty?(response) && status == 200
|
20
21
|
if html_request?(headers, response)
|
21
22
|
response_body = response_body(response)
|
22
23
|
response_body = append_to_html_body(response_body, footer_note) if Bullet.add_footer
|
23
24
|
response_body = append_to_html_body(response_body, Bullet.gather_inline_notifications)
|
24
|
-
response_body = append_to_html_body(response_body, xhr_script)
|
25
|
+
response_body = append_to_html_body(response_body, xhr_script) if Bullet.add_footer && !Bullet.skip_http_headers
|
25
26
|
headers['Content-Length'] = response_body.bytesize.to_s
|
26
|
-
|
27
|
+
elsif !Bullet.skip_http_headers
|
27
28
|
set_header(headers, 'X-bullet-footer-text', Bullet.footer_info.uniq) if Bullet.add_footer
|
28
29
|
set_header(headers, 'X-bullet-console-text', Bullet.text_notifications) if Bullet.console_enabled?
|
29
30
|
end
|
@@ -45,6 +46,7 @@ module Bullet
|
|
45
46
|
|
46
47
|
def append_to_html_body(response_body, content)
|
47
48
|
body = response_body.dup
|
49
|
+
content = content.html_safe if content.respond_to?(:html_safe)
|
48
50
|
if body.include?('</body>')
|
49
51
|
position = body.rindex('</body>')
|
50
52
|
body.insert(position, content)
|
@@ -54,7 +56,7 @@ module Bullet
|
|
54
56
|
end
|
55
57
|
|
56
58
|
def footer_note
|
57
|
-
"<
|
59
|
+
"<details #{details_attributes}><summary #{summary_attributes}>Bullet Warnings</summary><div #{footer_content_attributes}>#{Bullet.footer_info.uniq.join('<br>')}#{footer_console_message}</div></details>"
|
58
60
|
end
|
59
61
|
|
60
62
|
def set_header(headers, header_name, header_array)
|
@@ -87,22 +89,28 @@ module Bullet
|
|
87
89
|
|
88
90
|
private
|
89
91
|
|
90
|
-
def
|
92
|
+
def details_attributes
|
93
|
+
<<~EOF
|
94
|
+
id="bullet-footer" data-is-bullet-footer
|
95
|
+
style="cursor: pointer; position: fixed; left: 0px; bottom: 0px; z-index: 9999; background: #fdf2f2; color: #9b1c1c; font-size: 12px; border-radius: 0px 8px 0px 0px; border: 1px solid #9b1c1c;"
|
96
|
+
EOF
|
97
|
+
end
|
98
|
+
|
99
|
+
def summary_attributes
|
91
100
|
<<~EOF
|
92
|
-
|
93
|
-
-moz-border-top-colors: none; -moz-border-right-colors: none; -moz-border-bottom-colors: none;
|
94
|
-
-moz-border-left-colors: none; -moz-border-image: none; border-width: 2pt 2pt 0px 0px;
|
95
|
-
padding: 3px 5px; border-radius: 0pt 10pt 0pt 0px; background: none repeat scroll 0% 0% rgba(200, 200, 200, 0.8);
|
96
|
-
color: rgb(119, 119, 119); font-size: 16px; font-family: 'Arial', sans-serif; z-index:9999;"
|
101
|
+
style="font-weight: 600; padding: 2px 8px"
|
97
102
|
EOF
|
98
103
|
end
|
99
104
|
|
100
|
-
def
|
101
|
-
|
105
|
+
def footer_content_attributes
|
106
|
+
<<~EOF
|
107
|
+
style="padding: 8px; border-top: 1px solid #9b1c1c;"
|
108
|
+
EOF
|
109
|
+
end
|
110
|
+
|
111
|
+
def footer_console_message
|
102
112
|
if Bullet.console_enabled?
|
103
|
-
"<span>See 'Uniform Notifier' in JS Console for Stacktrace</span
|
104
|
-
else
|
105
|
-
cancel_button
|
113
|
+
"<br/><span style='font-style: italic;'>See 'Uniform Notifier' in JS Console for Stacktrace</span>"
|
106
114
|
end
|
107
115
|
end
|
108
116
|
|
@@ -3,13 +3,15 @@
|
|
3
3
|
module Bullet
|
4
4
|
module StackTraceFilter
|
5
5
|
VENDOR_PATH = '/vendor'
|
6
|
+
IS_RUBY_19 = Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.0.0')
|
6
7
|
|
7
8
|
def caller_in_project
|
8
9
|
vendor_root = Bullet.app_root + VENDOR_PATH
|
9
10
|
bundler_path = Bundler.bundle_path.to_s
|
10
11
|
select_caller_locations do |location|
|
11
12
|
caller_path = location_as_path(location)
|
12
|
-
caller_path.include?(Bullet.app_root) && !caller_path.include?(vendor_root) &&
|
13
|
+
caller_path.include?(Bullet.app_root) && !caller_path.include?(vendor_root) &&
|
14
|
+
!caller_path.include?(bundler_path) ||
|
13
15
|
Bullet.stacktrace_includes.any? { |include_pattern| pattern_matches?(location, include_pattern) }
|
14
16
|
end
|
15
17
|
end
|
@@ -46,26 +48,15 @@ module Bullet
|
|
46
48
|
end
|
47
49
|
|
48
50
|
def location_as_path(location)
|
49
|
-
|
51
|
+
IS_RUBY_19 ? location : location.absolute_path.to_s
|
50
52
|
end
|
51
53
|
|
52
54
|
def select_caller_locations
|
53
|
-
if
|
54
|
-
caller.select
|
55
|
-
yield caller_path
|
56
|
-
end
|
55
|
+
if IS_RUBY_19
|
56
|
+
caller.select { |caller_path| yield caller_path }
|
57
57
|
else
|
58
|
-
caller_locations.select
|
59
|
-
yield location
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def ruby_19?
|
65
|
-
if @ruby_19.nil?
|
66
|
-
@ruby_19 = Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.0.0')
|
58
|
+
caller_locations.select { |location| yield location }
|
67
59
|
end
|
68
|
-
@ruby_19
|
69
60
|
end
|
70
61
|
end
|
71
62
|
end
|
data/lib/bullet/version.rb
CHANGED
@@ -10,17 +10,17 @@ module Bullet
|
|
10
10
|
|
11
11
|
def enable_in_development
|
12
12
|
environment(nil, env: 'development') do
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
13
|
+
<<~FILE
|
14
|
+
config.after_initialize do
|
15
|
+
Bullet.enable = true
|
16
|
+
Bullet.alert = true
|
17
|
+
Bullet.bullet_logger = true
|
18
|
+
Bullet.console = true
|
19
|
+
# Bullet.growl = true
|
20
|
+
Bullet.rails_logger = true
|
21
|
+
Bullet.add_footer = true
|
22
|
+
end
|
23
|
+
|
24
24
|
FILE
|
25
25
|
end
|
26
26
|
|
@@ -28,20 +28,20 @@ module Bullet
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def enable_in_test
|
31
|
-
|
32
|
-
environment(nil, env: 'test') do
|
33
|
-
<<-"FILE".strip
|
34
|
-
|
35
|
-
config.after_initialize do
|
36
|
-
Bullet.enable = true
|
37
|
-
Bullet.bullet_logger = true
|
38
|
-
Bullet.raise = true # raise an error if n+1 query occurs
|
39
|
-
end
|
40
|
-
FILE
|
41
|
-
end
|
31
|
+
return unless yes?('Would you like to enable bullet in test environment? (y/n)')
|
42
32
|
|
43
|
-
|
33
|
+
environment(nil, env: 'test') do
|
34
|
+
<<~FILE
|
35
|
+
config.after_initialize do
|
36
|
+
Bullet.enable = true
|
37
|
+
Bullet.bullet_logger = true
|
38
|
+
Bullet.raise = true # raise an error if n+1 query occurs
|
39
|
+
end
|
40
|
+
|
41
|
+
FILE
|
44
42
|
end
|
43
|
+
|
44
|
+
say 'Enabled bullet in config/environments/test.rb'
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
data/perf/benchmark.rb
CHANGED
@@ -29,11 +29,11 @@ class User < ActiveRecord::Base
|
|
29
29
|
end
|
30
30
|
|
31
31
|
# create database bullet_benchmark;
|
32
|
-
ActiveRecord::Base.establish_connection(
|
32
|
+
ActiveRecord::Base.establish_connection(
|
33
|
+
adapter: 'mysql2', database: 'bullet_benchmark', server: '/tmp/mysql.socket', username: 'root'
|
34
|
+
)
|
33
35
|
|
34
|
-
ActiveRecord::Base.connection.tables.each
|
35
|
-
ActiveRecord::Base.connection.drop_table(table)
|
36
|
-
end
|
36
|
+
ActiveRecord::Base.connection.tables.each { |table| ActiveRecord::Base.connection.drop_table(table) }
|
37
37
|
|
38
38
|
ActiveRecord::Schema.define(version: 1) do
|
39
39
|
create_table :posts do |t|
|
@@ -54,26 +54,20 @@ ActiveRecord::Schema.define(version: 1) do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
users_size = 100
|
57
|
-
posts_size =
|
57
|
+
posts_size = 1_000
|
58
58
|
comments_size = 10_000
|
59
59
|
users = []
|
60
|
-
users_size.times
|
61
|
-
users << User.new(name: "user#{i}")
|
62
|
-
end
|
60
|
+
users_size.times { |i| users << User.new(name: "user#{i}") }
|
63
61
|
User.import users
|
64
62
|
users = User.all
|
65
63
|
|
66
64
|
posts = []
|
67
|
-
posts_size.times
|
68
|
-
posts << Post.new(title: "Title #{i}", body: "Body #{i}", user: users[i % 100])
|
69
|
-
end
|
65
|
+
posts_size.times { |i| posts << Post.new(title: "Title #{i}", body: "Body #{i}", user: users[i % 100]) }
|
70
66
|
Post.import posts
|
71
67
|
posts = Post.all
|
72
68
|
|
73
69
|
comments = []
|
74
|
-
comments_size.times
|
75
|
-
comments << Comment.new(body: "Comment #{i}", post: posts[i % 1000], user: users[i % 100])
|
76
|
-
end
|
70
|
+
comments_size.times { |i| comments << Comment.new(body: "Comment #{i}", post: posts[i % 1_000], user: users[i % 100]) }
|
77
71
|
Comment.import comments
|
78
72
|
|
79
73
|
puts 'Start benchmarking...'
|
@@ -12,15 +12,15 @@ module Bullet
|
|
12
12
|
|
13
13
|
context '.add_counter_cache' do
|
14
14
|
it 'should create notification if conditions met' do
|
15
|
-
expect(CounterCache).to receive(:conditions_met?).with(@post1, [
|
16
|
-
expect(CounterCache).to receive(:create_notification).with('Post', [
|
17
|
-
CounterCache.add_counter_cache(@post1, [
|
15
|
+
expect(CounterCache).to receive(:conditions_met?).with(@post1, %i[comments]).and_return(true)
|
16
|
+
expect(CounterCache).to receive(:create_notification).with('Post', %i[comments])
|
17
|
+
CounterCache.add_counter_cache(@post1, %i[comments])
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'should not create notification if conditions not met' do
|
21
|
-
expect(CounterCache).to receive(:conditions_met?).with(@post1, [
|
21
|
+
expect(CounterCache).to receive(:conditions_met?).with(@post1, %i[comments]).and_return(false)
|
22
22
|
expect(CounterCache).to receive(:create_notification).never
|
23
|
-
CounterCache.add_counter_cache(@post1, [
|
23
|
+
CounterCache.add_counter_cache(@post1, %i[comments])
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -47,7 +47,7 @@ module Bullet
|
|
47
47
|
expect(CounterCache.conditions_met?(@post1, :associations)).to eq false
|
48
48
|
end
|
49
49
|
|
50
|
-
it 'should be
|
50
|
+
it 'should be false when object is possible, and impossible' do
|
51
51
|
CounterCache.add_possible_objects(@post1)
|
52
52
|
CounterCache.add_impossible_object(@post1)
|
53
53
|
expect(CounterCache.conditions_met?(@post1, :associations)).to eq false
|
@@ -76,8 +76,8 @@ module Bullet
|
|
76
76
|
context '.call_association' do
|
77
77
|
it 'should create notification if conditions met' do
|
78
78
|
expect(NPlusOneQuery).to receive(:conditions_met?).with(@post, :association).and_return(true)
|
79
|
-
expect(NPlusOneQuery).to receive(:caller_in_project).and_return([
|
80
|
-
expect(NPlusOneQuery).to receive(:create_notification).with([
|
79
|
+
expect(NPlusOneQuery).to receive(:caller_in_project).and_return(%w[caller])
|
80
|
+
expect(NPlusOneQuery).to receive(:create_notification).with(%w[caller], 'Post', :association)
|
81
81
|
NPlusOneQuery.call_association(@post, :association)
|
82
82
|
end
|
83
83
|
|
@@ -149,7 +149,11 @@ module Bullet
|
|
149
149
|
|
150
150
|
expect(NPlusOneQuery).to receive(:caller_locations).and_return([in_project, *included_gems, excluded_gem])
|
151
151
|
expect(NPlusOneQuery).to receive(:conditions_met?).with(@post, :association).and_return(true)
|
152
|
-
expect(NPlusOneQuery).to receive(:create_notification).with(
|
152
|
+
expect(NPlusOneQuery).to receive(:create_notification).with(
|
153
|
+
[in_project, *included_gems],
|
154
|
+
'Post',
|
155
|
+
:association
|
156
|
+
)
|
153
157
|
NPlusOneQuery.call_association(@post, :association)
|
154
158
|
end
|
155
159
|
end
|
@@ -36,12 +36,14 @@ module Bullet
|
|
36
36
|
it 'should return empty if associations exist in call_association' do
|
37
37
|
UnusedEagerLoading.add_eager_loadings([@post], :association)
|
38
38
|
UnusedEagerLoading.add_call_object_associations(@post, :association)
|
39
|
-
expect(
|
39
|
+
expect(
|
40
|
+
UnusedEagerLoading.send(:diff_object_associations, @post.bullet_key, Set.new([:association]))
|
41
|
+
).to be_empty
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
43
45
|
context '.check_unused_preload_associations' do
|
44
|
-
let(:paths) { [
|
46
|
+
let(:paths) { %w[/dir1 /dir1/subdir] }
|
45
47
|
it 'should create notification if object_association_diff is not empty' do
|
46
48
|
UnusedEagerLoading.add_object_associations(@post, :association)
|
47
49
|
allow(UnusedEagerLoading).to receive(:caller_in_project).and_return(paths)
|
@@ -53,7 +55,9 @@ module Bullet
|
|
53
55
|
UnusedEagerLoading.add_object_associations(@post, :association)
|
54
56
|
UnusedEagerLoading.add_eager_loadings([@post], :association)
|
55
57
|
UnusedEagerLoading.add_call_object_associations(@post, :association)
|
56
|
-
expect(
|
58
|
+
expect(
|
59
|
+
UnusedEagerLoading.send(:diff_object_associations, @post.bullet_key, Set.new([:association]))
|
60
|
+
).to be_empty
|
57
61
|
expect(UnusedEagerLoading).not_to receive(:create_notification).with('Post', [:association])
|
58
62
|
UnusedEagerLoading.check_unused_preload_associations
|
59
63
|
end
|
@@ -62,14 +66,23 @@ module Bullet
|
|
62
66
|
context '.add_eager_loadings' do
|
63
67
|
it 'should add objects, associations pair when eager_loadings are empty' do
|
64
68
|
UnusedEagerLoading.add_eager_loadings([@post, @post2], :associations)
|
65
|
-
expect(UnusedEagerLoading.send(:eager_loadings)).to be_include(
|
69
|
+
expect(UnusedEagerLoading.send(:eager_loadings)).to be_include(
|
70
|
+
[@post.bullet_key, @post2.bullet_key],
|
71
|
+
:associations
|
72
|
+
)
|
66
73
|
end
|
67
74
|
|
68
75
|
it 'should add objects, associations pair for existing eager_loadings' do
|
69
76
|
UnusedEagerLoading.add_eager_loadings([@post, @post2], :association1)
|
70
77
|
UnusedEagerLoading.add_eager_loadings([@post, @post2], :association2)
|
71
|
-
expect(UnusedEagerLoading.send(:eager_loadings)).to be_include(
|
72
|
-
|
78
|
+
expect(UnusedEagerLoading.send(:eager_loadings)).to be_include(
|
79
|
+
[@post.bullet_key, @post2.bullet_key],
|
80
|
+
:association1
|
81
|
+
)
|
82
|
+
expect(UnusedEagerLoading.send(:eager_loadings)).to be_include(
|
83
|
+
[@post.bullet_key, @post2.bullet_key],
|
84
|
+
:association2
|
85
|
+
)
|
73
86
|
end
|
74
87
|
|
75
88
|
it 'should merge objects, associations pair for existing eager_loadings' do
|