bullet 4.7.0 → 4.8.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/.gitignore +1 -0
- data/.travis.yml +17 -17
- data/CHANGELOG.md +15 -0
- data/Gemfile +9 -2
- data/Gemfile.mongoid-2.4 +22 -0
- data/Gemfile.mongoid-2.5 +22 -0
- data/Gemfile.mongoid-2.6 +22 -0
- data/Gemfile.mongoid-2.7 +22 -0
- data/Gemfile.mongoid-2.8 +22 -0
- data/Gemfile.mongoid-3.0 +22 -0
- data/Gemfile.mongoid-3.1 +22 -0
- data/Gemfile.rails-3.0 +21 -0
- data/Gemfile.rails-3.1 +21 -0
- data/Gemfile.rails-3.2 +21 -0
- data/Gemfile.rails-4.0 +21 -0
- data/{Gemfile.rails-3.0.20 → Gemfile.rails-4.1} +1 -1
- data/README.md +25 -24
- data/Rakefile +13 -6
- data/bullet.gemspec +1 -1
- data/lib/bullet/active_record41.rb +97 -0
- data/lib/bullet/dependency.rb +11 -1
- data/lib/bullet/mongoid4x.rb +1 -1
- data/lib/bullet/registry/base.rb +1 -1
- data/lib/bullet/version.rb +1 -1
- data/lib/bullet.rb +1 -1
- data/spec/bullet/detector/association_spec.rb +8 -8
- data/spec/bullet/detector/base_spec.rb +1 -1
- data/spec/bullet/detector/counter_cache_spec.rb +12 -12
- data/spec/bullet/detector/n_plus_one_query_spec.rb +32 -32
- data/spec/bullet/detector/unused_eager_loading_spec.rb +18 -18
- data/spec/bullet/ext/object_spec.rb +2 -2
- data/spec/bullet/ext/string_spec.rb +2 -2
- data/spec/bullet/notification/base_spec.rb +19 -13
- 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 +4 -4
- data/spec/bullet/rack_spec.rb +21 -21
- data/spec/bullet/registry/association_spec.rb +3 -3
- data/spec/bullet/registry/base_spec.rb +6 -6
- data/spec/bullet/registry/object_spec.rb +2 -2
- data/spec/integration/active_record3/association_spec.rb +107 -107
- data/spec/integration/active_record4/association_spec.rb +105 -105
- data/spec/integration/counter_cache_spec.rb +4 -4
- data/spec/integration/mongoid/association_spec.rb +52 -52
- data/spec/spec_helper.rb +0 -1
- data/test.sh +12 -11
- metadata +27 -40
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/Gemfile.lock +0 -160
- data/Gemfile.mongoid-2.4.12 +0 -15
- data/Gemfile.mongoid-2.4.12.lock +0 -163
- data/Gemfile.mongoid-2.5.2 +0 -15
- data/Gemfile.mongoid-2.5.2.lock +0 -163
- data/Gemfile.mongoid-2.6.0 +0 -15
- data/Gemfile.mongoid-2.6.0.lock +0 -163
- data/Gemfile.mongoid-2.7.1 +0 -15
- data/Gemfile.mongoid-2.7.1.lock +0 -163
- data/Gemfile.mongoid-2.8.1 +0 -15
- data/Gemfile.mongoid-2.8.1.lock +0 -166
- data/Gemfile.mongoid-3.0.23 +0 -15
- data/Gemfile.mongoid-3.0.23.lock +0 -163
- data/Gemfile.mongoid-3.1.5 +0 -15
- data/Gemfile.mongoid-3.1.5.lock +0 -163
- data/Gemfile.mongoid.lock +0 -167
- data/Gemfile.rails-3.0.20.lock +0 -147
- data/Gemfile.rails-3.1.12 +0 -14
- data/Gemfile.rails-3.1.12.lock +0 -157
- data/Gemfile.rails-3.2.15 +0 -14
- data/Gemfile.rails-3.2.15.lock +0 -155
- data/Gemfile.rails-4.0.1 +0 -14
- data/Gemfile.rails-4.0.1.lock +0 -150
|
@@ -12,32 +12,32 @@ module Bullet
|
|
|
12
12
|
context ".start_request" do
|
|
13
13
|
it "should set @@checked to false" do
|
|
14
14
|
Association.start_request
|
|
15
|
-
Association.class_variable_get(:@@checked).
|
|
15
|
+
expect(Association.class_variable_get(:@@checked)).to eq false
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
context ".clear" do
|
|
20
20
|
it "should clear all class variables" do
|
|
21
21
|
Association.clear
|
|
22
|
-
Association.class_variable_get(:@@object_associations).
|
|
23
|
-
Association.class_variable_get(:@@possible_objects).
|
|
24
|
-
Association.class_variable_get(:@@impossible_objects).
|
|
25
|
-
Association.class_variable_get(:@@call_object_associations).
|
|
26
|
-
Association.class_variable_get(:@@eager_loadings).
|
|
22
|
+
expect(Association.class_variable_get(:@@object_associations)).to be_nil
|
|
23
|
+
expect(Association.class_variable_get(:@@possible_objects)).to be_nil
|
|
24
|
+
expect(Association.class_variable_get(:@@impossible_objects)).to be_nil
|
|
25
|
+
expect(Association.class_variable_get(:@@call_object_associations)).to be_nil
|
|
26
|
+
expect(Association.class_variable_get(:@@eager_loadings)).to be_nil
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
context ".add_object_association" do
|
|
31
31
|
it "should add object, associations pair" do
|
|
32
32
|
Association.add_object_associations(@post1, :associations)
|
|
33
|
-
Association.send(:object_associations).
|
|
33
|
+
expect(Association.send(:object_associations)).to be_include(@post1.bullet_ar_key, :associations)
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
context ".add_call_object_associations" do
|
|
38
38
|
it "should add call object, associations pair" do
|
|
39
39
|
Association.add_call_object_associations(@post1, :associations)
|
|
40
|
-
Association.send(:call_object_associations).
|
|
40
|
+
expect(Association.send(:call_object_associations)).to be_include(@post1.bullet_ar_key, :associations)
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
end
|
|
@@ -11,21 +11,21 @@ module Bullet
|
|
|
11
11
|
|
|
12
12
|
context ".clear" do
|
|
13
13
|
it "should clear all class variables" do
|
|
14
|
-
CounterCache.class_variable_get(:@@possible_objects).
|
|
15
|
-
CounterCache.class_variable_get(:@@impossible_objects).
|
|
14
|
+
expect(CounterCache.class_variable_get(:@@possible_objects)).to be_nil
|
|
15
|
+
expect(CounterCache.class_variable_get(:@@impossible_objects)).to be_nil
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
context ".add_counter_cache" do
|
|
20
20
|
it "should create notification if conditions met" do
|
|
21
|
-
CounterCache.
|
|
22
|
-
CounterCache.
|
|
21
|
+
expect(CounterCache).to receive(:conditions_met?).with(@post1.bullet_ar_key, [:comments]).and_return(true)
|
|
22
|
+
expect(CounterCache).to receive(:create_notification).with("Post", [:comments])
|
|
23
23
|
CounterCache.add_counter_cache(@post1, [:comments])
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
it "should not create notification if conditions not met" do
|
|
27
|
-
CounterCache.
|
|
28
|
-
CounterCache.
|
|
27
|
+
expect(CounterCache).to receive(:conditions_met?).with(@post1.bullet_ar_key, [:comments]).and_return(false)
|
|
28
|
+
expect(CounterCache).to receive(:create_notification).never
|
|
29
29
|
CounterCache.add_counter_cache(@post1, [:comments])
|
|
30
30
|
end
|
|
31
31
|
end
|
|
@@ -33,30 +33,30 @@ module Bullet
|
|
|
33
33
|
context ".add_possible_objects" do
|
|
34
34
|
it "should add possible objects" do
|
|
35
35
|
CounterCache.add_possible_objects([@post1, @post2])
|
|
36
|
-
CounterCache.send(:possible_objects).
|
|
37
|
-
CounterCache.send(:possible_objects).
|
|
36
|
+
expect(CounterCache.send(:possible_objects)).to be_include(@post1.bullet_ar_key)
|
|
37
|
+
expect(CounterCache.send(:possible_objects)).to be_include(@post2.bullet_ar_key)
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
it "should add impossible object" do
|
|
41
41
|
CounterCache.add_impossible_object(@post1)
|
|
42
|
-
CounterCache.send(:impossible_objects).
|
|
42
|
+
expect(CounterCache.send(:impossible_objects)).to be_include(@post1.bullet_ar_key)
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
context ".conditions_met?" do
|
|
47
47
|
it "should be true when object is possible, not impossible" do
|
|
48
48
|
CounterCache.add_possible_objects(@post1)
|
|
49
|
-
CounterCache.send(:conditions_met?, @post1.bullet_ar_key, :associations).
|
|
49
|
+
expect(CounterCache.send(:conditions_met?, @post1.bullet_ar_key, :associations)).to eq true
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
it "should be false when object is not possible" do
|
|
53
|
-
CounterCache.send(:conditions_met?, @post1.bullet_ar_key, :associations).
|
|
53
|
+
expect(CounterCache.send(:conditions_met?, @post1.bullet_ar_key, :associations)).to eq false
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
it "should be true when object is possible, and impossible" do
|
|
57
57
|
CounterCache.add_possible_objects(@post1)
|
|
58
58
|
CounterCache.add_impossible_object(@post1)
|
|
59
|
-
CounterCache.send(:conditions_met?, @post1.bullet_ar_key, :associations).
|
|
59
|
+
expect(CounterCache.send(:conditions_met?, @post1.bullet_ar_key, :associations)).to eq false
|
|
60
60
|
end
|
|
61
61
|
end
|
|
62
62
|
end
|
|
@@ -12,11 +12,11 @@ module Bullet
|
|
|
12
12
|
context ".call_association" do
|
|
13
13
|
it "should set @@checked to true" do
|
|
14
14
|
NPlusOneQuery.call_association(@post, :associations)
|
|
15
|
-
NPlusOneQuery.class_variable_get(:@@checked).
|
|
15
|
+
expect(NPlusOneQuery.class_variable_get(:@@checked)).to eq true
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
it "should add call_object_associations" do
|
|
19
|
-
NPlusOneQuery.
|
|
19
|
+
expect(NPlusOneQuery).to receive(:add_call_object_associations).with(@post, :associations)
|
|
20
20
|
NPlusOneQuery.call_association(@post, :associations)
|
|
21
21
|
end
|
|
22
22
|
end
|
|
@@ -24,71 +24,71 @@ module Bullet
|
|
|
24
24
|
context ".possible?" do
|
|
25
25
|
it "should be true if possible_objects contain" do
|
|
26
26
|
NPlusOneQuery.add_possible_objects(@post)
|
|
27
|
-
NPlusOneQuery.send(:possible?, @post.bullet_ar_key).
|
|
27
|
+
expect(NPlusOneQuery.send(:possible?, @post.bullet_ar_key)).to eq true
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
context ".impossible?" do
|
|
32
32
|
it "should be true if impossible_objects contain" do
|
|
33
33
|
NPlusOneQuery.add_impossible_object(@post)
|
|
34
|
-
NPlusOneQuery.send(:impossible?, @post.bullet_ar_key).
|
|
34
|
+
expect(NPlusOneQuery.send(:impossible?, @post.bullet_ar_key)).to eq true
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
context ".association?" do
|
|
39
39
|
it "should be true if object, associations pair is already existed" do
|
|
40
40
|
NPlusOneQuery.add_object_associations(@post, :association)
|
|
41
|
-
NPlusOneQuery.send(:association?, @post.bullet_ar_key, :association).
|
|
41
|
+
expect(NPlusOneQuery.send(:association?, @post.bullet_ar_key, :association)).to eq true
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
it "should be false if object, association pair is not existed" do
|
|
45
45
|
NPlusOneQuery.add_object_associations(@post, :association1)
|
|
46
|
-
NPlusOneQuery.send(:association?, @post.bullet_ar_key, :associatio2).
|
|
46
|
+
expect(NPlusOneQuery.send(:association?, @post.bullet_ar_key, :associatio2)).to eq false
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
context ".conditions_met?" do
|
|
51
51
|
it "should be true if object is possible, not impossible and object, associations pair is not already existed" do
|
|
52
|
-
NPlusOneQuery.
|
|
53
|
-
NPlusOneQuery.
|
|
54
|
-
NPlusOneQuery.
|
|
55
|
-
NPlusOneQuery.send(:conditions_met?, @post.bullet_ar_key, :associations).
|
|
52
|
+
allow(NPlusOneQuery).to receive(:possible?).with(@post.bullet_ar_key).and_return(true)
|
|
53
|
+
allow(NPlusOneQuery).to receive(:impossible?).with(@post.bullet_ar_key).and_return(false)
|
|
54
|
+
allow(NPlusOneQuery).to receive(:association?).with(@post.bullet_ar_key, :associations).and_return(false)
|
|
55
|
+
expect(NPlusOneQuery.send(:conditions_met?, @post.bullet_ar_key, :associations)).to eq true
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
it "should be false if object is not possible, not impossible and object, associations pair is not already existed" do
|
|
59
|
-
NPlusOneQuery.
|
|
60
|
-
NPlusOneQuery.
|
|
61
|
-
NPlusOneQuery.
|
|
62
|
-
NPlusOneQuery.send(:conditions_met?, @post.bullet_ar_key, :associations).
|
|
59
|
+
allow(NPlusOneQuery).to receive(:possible?).with(@post.bullet_ar_key).and_return(false)
|
|
60
|
+
allow(NPlusOneQuery).to receive(:impossible?).with(@post.bullet_ar_key).and_return(false)
|
|
61
|
+
allow(NPlusOneQuery).to receive(:association?).with(@post.bullet_ar_key, :associations).and_return(false)
|
|
62
|
+
expect(NPlusOneQuery.send(:conditions_met?, @post.bullet_ar_key, :associations)).to eq false
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
it "should be false if object is possible, but impossible and object, associations pair is not already existed" do
|
|
66
|
-
NPlusOneQuery.
|
|
67
|
-
NPlusOneQuery.
|
|
68
|
-
NPlusOneQuery.
|
|
69
|
-
NPlusOneQuery.send(:conditions_met?, @post.bullet_ar_key, :associations).
|
|
66
|
+
allow(NPlusOneQuery).to receive(:possible?).with(@post.bullet_ar_key).and_return(true)
|
|
67
|
+
allow(NPlusOneQuery).to receive(:impossible?).with(@post.bullet_ar_key).and_return(true)
|
|
68
|
+
allow(NPlusOneQuery).to receive(:association?).with(@post.bullet_ar_key, :associations).and_return(false)
|
|
69
|
+
expect(NPlusOneQuery.send(:conditions_met?, @post.bullet_ar_key, :associations)).to eq false
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
it "should be false if object is possible, not impossible and object, associations pair is already existed" do
|
|
73
|
-
NPlusOneQuery.
|
|
74
|
-
NPlusOneQuery.
|
|
75
|
-
NPlusOneQuery.
|
|
76
|
-
NPlusOneQuery.send(:conditions_met?, @post.bullet_ar_key, :associations).
|
|
73
|
+
allow(NPlusOneQuery).to receive(:possible?).with(@post.bullet_ar_key).and_return(true)
|
|
74
|
+
allow(NPlusOneQuery).to receive(:impossible?).with(@post.bullet_ar_key).and_return(false)
|
|
75
|
+
allow(NPlusOneQuery).to receive(:association?).with(@post.bullet_ar_key, :associations).and_return(true)
|
|
76
|
+
expect(NPlusOneQuery.send(:conditions_met?, @post.bullet_ar_key, :associations)).to eq false
|
|
77
77
|
end
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
context ".call_association" do
|
|
81
81
|
it "should create notification if conditions met" do
|
|
82
|
-
NPlusOneQuery.
|
|
83
|
-
NPlusOneQuery.
|
|
84
|
-
NPlusOneQuery.
|
|
82
|
+
expect(NPlusOneQuery).to receive(:conditions_met?).with(@post.bullet_ar_key, :association).and_return(true)
|
|
83
|
+
expect(NPlusOneQuery).to receive(:caller_in_project).and_return(["caller"])
|
|
84
|
+
expect(NPlusOneQuery).to receive(:create_notification).with(["caller"], "Post", :association)
|
|
85
85
|
NPlusOneQuery.call_association(@post, :association)
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
it "should not create notification if conditions not met" do
|
|
89
|
-
NPlusOneQuery.
|
|
90
|
-
NPlusOneQuery.
|
|
91
|
-
NPlusOneQuery.
|
|
89
|
+
expect(NPlusOneQuery).to receive(:conditions_met?).with(@post.bullet_ar_key, :association).and_return(false)
|
|
90
|
+
expect(NPlusOneQuery).not_to receive(:caller_in_project!)
|
|
91
|
+
expect(NPlusOneQuery).not_to receive(:create_notification).with("Post", :association)
|
|
92
92
|
NPlusOneQuery.call_association(@post, :association)
|
|
93
93
|
end
|
|
94
94
|
end
|
|
@@ -96,19 +96,19 @@ module Bullet
|
|
|
96
96
|
context ".add_possible_objects" do
|
|
97
97
|
it "should add possible objects" do
|
|
98
98
|
NPlusOneQuery.add_possible_objects([@post, @post2])
|
|
99
|
-
NPlusOneQuery.send(:possible_objects).
|
|
100
|
-
NPlusOneQuery.send(:possible_objects).
|
|
99
|
+
expect(NPlusOneQuery.send(:possible_objects)).to be_include(@post.bullet_ar_key)
|
|
100
|
+
expect(NPlusOneQuery.send(:possible_objects)).to be_include(@post2.bullet_ar_key)
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
it "should not raise error if object is nil" do
|
|
104
|
-
|
|
104
|
+
expect { NPlusOneQuery.add_possible_objects(nil) }.not_to raise_error
|
|
105
105
|
end
|
|
106
106
|
end
|
|
107
107
|
|
|
108
108
|
context ".add_impossible_object" do
|
|
109
109
|
it "should add impossible object" do
|
|
110
110
|
NPlusOneQuery.add_impossible_object(@post)
|
|
111
|
-
NPlusOneQuery.send(:impossible_objects).
|
|
111
|
+
expect(NPlusOneQuery.send(:impossible_objects)).to be_include(@post.bullet_ar_key)
|
|
112
112
|
end
|
|
113
113
|
end
|
|
114
114
|
end
|
|
@@ -11,42 +11,42 @@ module Bullet
|
|
|
11
11
|
|
|
12
12
|
context ".call_associations" do
|
|
13
13
|
it "should get empty array if eager_loadings" do
|
|
14
|
-
UnusedEagerLoading.send(:call_associations, @post.bullet_ar_key, Set.new([:association])).
|
|
14
|
+
expect(UnusedEagerLoading.send(:call_associations, @post.bullet_ar_key, Set.new([:association]))).to be_empty
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
it "should get call associations if object and association are both in eager_loadings and call_object_associations" do
|
|
18
18
|
UnusedEagerLoading.add_eager_loadings([@post], :association)
|
|
19
19
|
UnusedEagerLoading.add_call_object_associations(@post, :association)
|
|
20
|
-
UnusedEagerLoading.send(:call_associations, @post.bullet_ar_key, Set.new([:association])).
|
|
20
|
+
expect(UnusedEagerLoading.send(:call_associations, @post.bullet_ar_key, Set.new([:association]))).to eq([:association])
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
it "should not get call associations if not exist in call_object_associations" do
|
|
24
24
|
UnusedEagerLoading.add_eager_loadings([@post], :association)
|
|
25
|
-
UnusedEagerLoading.send(:call_associations, @post.bullet_ar_key, Set.new([:association])).
|
|
25
|
+
expect(UnusedEagerLoading.send(:call_associations, @post.bullet_ar_key, Set.new([:association]))).to be_empty
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
context ".diff_object_associations" do
|
|
30
30
|
it "should return associations not exist in call_association" do
|
|
31
|
-
UnusedEagerLoading.send(:diff_object_associations, @post.bullet_ar_key, Set.new([:association])).
|
|
31
|
+
expect(UnusedEagerLoading.send(:diff_object_associations, @post.bullet_ar_key, Set.new([:association]))).to eq([:association])
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
it "should return empty if associations exist in call_association" do
|
|
35
35
|
UnusedEagerLoading.add_eager_loadings([@post], :association)
|
|
36
36
|
UnusedEagerLoading.add_call_object_associations(@post, :association)
|
|
37
|
-
UnusedEagerLoading.send(:diff_object_associations, @post.bullet_ar_key, Set.new([:association])).
|
|
37
|
+
expect(UnusedEagerLoading.send(:diff_object_associations, @post.bullet_ar_key, Set.new([:association]))).to be_empty
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
context ".check_unused_preload_associations" do
|
|
42
42
|
it "should set @@checked to true" do
|
|
43
43
|
UnusedEagerLoading.check_unused_preload_associations
|
|
44
|
-
UnusedEagerLoading.class_variable_get(:@@checked).
|
|
44
|
+
expect(UnusedEagerLoading.class_variable_get(:@@checked)).to eq true
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
it "should create notification if object_association_diff is not empty" do
|
|
48
48
|
UnusedEagerLoading.add_object_associations(@post, :association)
|
|
49
|
-
UnusedEagerLoading.
|
|
49
|
+
expect(UnusedEagerLoading).to receive(:create_notification).with("Post", [:association])
|
|
50
50
|
UnusedEagerLoading.check_unused_preload_associations
|
|
51
51
|
end
|
|
52
52
|
|
|
@@ -55,8 +55,8 @@ module Bullet
|
|
|
55
55
|
UnusedEagerLoading.add_object_associations(@post, :association)
|
|
56
56
|
UnusedEagerLoading.add_eager_loadings([@post], :association)
|
|
57
57
|
UnusedEagerLoading.add_call_object_associations(@post, :association)
|
|
58
|
-
UnusedEagerLoading.send(:diff_object_associations, @post.bullet_ar_key, Set.new([:association])).
|
|
59
|
-
UnusedEagerLoading.
|
|
58
|
+
expect(UnusedEagerLoading.send(:diff_object_associations, @post.bullet_ar_key, Set.new([:association]))).to be_empty
|
|
59
|
+
expect(UnusedEagerLoading).not_to receive(:create_notification).with("Post", [:association])
|
|
60
60
|
UnusedEagerLoading.check_unused_preload_associations
|
|
61
61
|
end
|
|
62
62
|
end
|
|
@@ -64,30 +64,30 @@ module Bullet
|
|
|
64
64
|
context ".add_eager_loadings" do
|
|
65
65
|
it "should add objects, associations pair when eager_loadings are empty" do
|
|
66
66
|
UnusedEagerLoading.add_eager_loadings([@post, @post2], :associations)
|
|
67
|
-
UnusedEagerLoading.send(:eager_loadings).
|
|
67
|
+
expect(UnusedEagerLoading.send(:eager_loadings)).to be_include([@post.bullet_ar_key, @post2.bullet_ar_key], :associations)
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
it "should add objects, associations pair for existing eager_loadings" do
|
|
71
71
|
UnusedEagerLoading.add_eager_loadings([@post, @post2], :association1)
|
|
72
72
|
UnusedEagerLoading.add_eager_loadings([@post, @post2], :association2)
|
|
73
|
-
UnusedEagerLoading.send(:eager_loadings).
|
|
74
|
-
UnusedEagerLoading.send(:eager_loadings).
|
|
73
|
+
expect(UnusedEagerLoading.send(:eager_loadings)).to be_include([@post.bullet_ar_key, @post2.bullet_ar_key], :association1)
|
|
74
|
+
expect(UnusedEagerLoading.send(:eager_loadings)).to be_include([@post.bullet_ar_key, @post2.bullet_ar_key], :association2)
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
it "should merge objects, associations pair for existing eager_loadings" do
|
|
78
78
|
UnusedEagerLoading.add_eager_loadings([@post], :association1)
|
|
79
79
|
UnusedEagerLoading.add_eager_loadings([@post, @post2], :association2)
|
|
80
|
-
UnusedEagerLoading.send(:eager_loadings).
|
|
81
|
-
UnusedEagerLoading.send(:eager_loadings).
|
|
82
|
-
UnusedEagerLoading.send(:eager_loadings).
|
|
80
|
+
expect(UnusedEagerLoading.send(:eager_loadings)).to be_include([@post.bullet_ar_key], :association1)
|
|
81
|
+
expect(UnusedEagerLoading.send(:eager_loadings)).to be_include([@post.bullet_ar_key], :association2)
|
|
82
|
+
expect(UnusedEagerLoading.send(:eager_loadings)).to be_include([@post.bullet_ar_key, @post2.bullet_ar_key], :association2)
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
it "should delete objects, associations pair for existing eager_loadings" do
|
|
86
86
|
UnusedEagerLoading.add_eager_loadings([@post, @post2], :association1)
|
|
87
87
|
UnusedEagerLoading.add_eager_loadings([@post], :association2)
|
|
88
|
-
UnusedEagerLoading.send(:eager_loadings).
|
|
89
|
-
UnusedEagerLoading.send(:eager_loadings).
|
|
90
|
-
UnusedEagerLoading.send(:eager_loadings).
|
|
88
|
+
expect(UnusedEagerLoading.send(:eager_loadings)).to be_include([@post.bullet_ar_key], :association1)
|
|
89
|
+
expect(UnusedEagerLoading.send(:eager_loadings)).to be_include([@post.bullet_ar_key], :association2)
|
|
90
|
+
expect(UnusedEagerLoading.send(:eager_loadings)).to be_include([@post2.bullet_ar_key], :association1)
|
|
91
91
|
end
|
|
92
92
|
end
|
|
93
93
|
end
|
|
@@ -4,13 +4,13 @@ describe Object do
|
|
|
4
4
|
context "bullet_ar_key" do
|
|
5
5
|
it "should return class and id composition" do
|
|
6
6
|
post = Post.first
|
|
7
|
-
post.bullet_ar_key.
|
|
7
|
+
expect(post.bullet_ar_key).to eq("Post:#{post.id}")
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
if mongoid?
|
|
11
11
|
it "should return class with namesapce and id composition" do
|
|
12
12
|
post = Mongoid::Post.first
|
|
13
|
-
post.bullet_ar_key.
|
|
13
|
+
expect(post.bullet_ar_key).to eq("Mongoid::Post:#{post.id}")
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
end
|
|
@@ -3,11 +3,11 @@ require 'spec_helper'
|
|
|
3
3
|
describe String do
|
|
4
4
|
context "bullet_class_name" do
|
|
5
5
|
it "should only return class name" do
|
|
6
|
-
"Post:1".bullet_class_name.
|
|
6
|
+
expect("Post:1".bullet_class_name).to eq("Post")
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
it "should return class name with namespace" do
|
|
10
|
-
"Mongoid::Post:1234567890".bullet_class_name.
|
|
10
|
+
expect("Mongoid::Post:1234567890".bullet_class_name).to eq("Mongoid::Post")
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
end
|
|
@@ -7,49 +7,54 @@ module Bullet
|
|
|
7
7
|
|
|
8
8
|
context "#title" do
|
|
9
9
|
it "should raise NoMethodError" do
|
|
10
|
-
|
|
10
|
+
expect { subject.title }.to raise_error(NoMethodError)
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
context "#body" do
|
|
15
15
|
it "should raise NoMethodError" do
|
|
16
|
-
|
|
16
|
+
expect { subject.body }.to raise_error(NoMethodError)
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
context "#whoami" do
|
|
21
21
|
it "should display user name" do
|
|
22
22
|
user = `whoami`.chomp
|
|
23
|
-
subject.whoami.
|
|
23
|
+
expect(subject.whoami).to eq("user: #{user}")
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
context "#body_with_caller" do
|
|
28
28
|
it "should return body" do
|
|
29
|
-
subject.
|
|
30
|
-
subject.body_with_caller.
|
|
29
|
+
allow(subject).to receive(:body).and_return("body")
|
|
30
|
+
expect(subject.body_with_caller).to eq("body")
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
context "#standard_notice" do
|
|
35
35
|
it "should return title + body" do
|
|
36
|
-
subject.
|
|
37
|
-
subject.
|
|
36
|
+
allow(subject).to receive(:title).and_return("title")
|
|
37
|
+
allow(subject).to receive(:body).and_return("body")
|
|
38
|
+
expect(subject.standard_notice).to eq("title\nbody")
|
|
38
39
|
end
|
|
39
40
|
end
|
|
40
41
|
|
|
41
42
|
context "#full_notice" do
|
|
42
43
|
it "should return whoami + url + title + body_with_caller" do
|
|
43
|
-
subject.
|
|
44
|
-
subject.
|
|
44
|
+
allow(subject).to receive(:whoami).and_return("whoami")
|
|
45
|
+
allow(subject).to receive(:url).and_return("url")
|
|
46
|
+
allow(subject).to receive(:title).and_return("title")
|
|
47
|
+
allow(subject).to receive(:body_with_caller).and_return("body_with_caller")
|
|
48
|
+
expect(subject.full_notice).to eq("whoami\nurl\ntitle\nbody_with_caller")
|
|
45
49
|
end
|
|
46
50
|
end
|
|
47
51
|
|
|
48
52
|
context "#notify_inline" do
|
|
49
53
|
it "should send full_notice to notifier" do
|
|
50
54
|
notifier = double
|
|
51
|
-
subject.
|
|
52
|
-
|
|
55
|
+
allow(subject).to receive(:notifier).and_return(notifier)
|
|
56
|
+
allow(subject).to receive(:full_notice).and_return("full_notice")
|
|
57
|
+
expect(notifier).to receive(:inline_notify).with("full_notice")
|
|
53
58
|
subject.notify_inline
|
|
54
59
|
end
|
|
55
60
|
end
|
|
@@ -57,8 +62,9 @@ module Bullet
|
|
|
57
62
|
context "#notify_out_of_channel" do
|
|
58
63
|
it "should send full_out_of_channel to notifier" do
|
|
59
64
|
notifier = double
|
|
60
|
-
subject.
|
|
61
|
-
|
|
65
|
+
allow(subject).to receive(:notifier).and_return(notifier)
|
|
66
|
+
allow(subject).to receive(:full_notice).and_return("full_notice")
|
|
67
|
+
expect(notifier).to receive(:out_of_channel_notify).with("full_notice")
|
|
62
68
|
subject.notify_out_of_channel
|
|
63
69
|
end
|
|
64
70
|
end
|
|
@@ -5,8 +5,8 @@ module Bullet
|
|
|
5
5
|
describe CounterCache do
|
|
6
6
|
subject { CounterCache.new(Post, [:comments, :votes]) }
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
@@ -5,9 +5,9 @@ module Bullet
|
|
|
5
5
|
describe NPlusOneQuery do
|
|
6
6
|
subject { NPlusOneQuery.new([["caller1", "caller2"]], Post, [:comments, :votes], "path") }
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
it { expect(subject.body_with_caller).to eq(" Post => [:comments, :votes]\n Add to your finder: :include => [:comments, :votes]\nN+1 Query method call stack\n caller1\n caller2") }
|
|
9
|
+
it { expect(subject.body).to eq(" Post => [:comments, :votes]\n Add to your finder: :include => [:comments, :votes]") }
|
|
10
|
+
it { expect(subject.title).to eq("N+1 Query in path") }
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
end
|
|
@@ -5,8 +5,8 @@ module Bullet
|
|
|
5
5
|
describe UnusedEagerLoading do
|
|
6
6
|
subject { UnusedEagerLoading.new(Post, [:comments, :votes], "path") }
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
it { expect(subject.body).to eq(" Post => [:comments, :votes]\n Remove from your finder: :include => [:comments, :votes]") }
|
|
9
|
+
it { expect(subject.title).to eq("Unused Eager Loading in path") }
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
end
|
|
@@ -7,25 +7,25 @@ module Bullet
|
|
|
7
7
|
context "#add" do
|
|
8
8
|
it "should add a value" do
|
|
9
9
|
subject.add("value1")
|
|
10
|
-
subject.collection.
|
|
10
|
+
expect(subject.collection).to be_include("value1")
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
context "#reset" do
|
|
15
15
|
it "should reset collector" do
|
|
16
16
|
subject.reset
|
|
17
|
-
subject.collection.
|
|
17
|
+
expect(subject.collection).to be_empty
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
context "#notifications_present?" do
|
|
22
22
|
it "should be true if collection is not empty" do
|
|
23
|
-
subject.
|
|
23
|
+
expect(subject).to be_notifications_present
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
it "should be false if collection is empty" do
|
|
27
27
|
subject.reset
|
|
28
|
-
subject.
|
|
28
|
+
expect(subject).not_to be_notifications_present
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
end
|