bullet 4.3.1 → 4.5.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/.travis.yml +4 -4
- data/CHANGELOG.md +31 -0
- data/{Hacking.textile → Hacking.md} +10 -5
- data/{README.textile → README.md} +174 -144
- data/lib/bullet/active_record2.rb +9 -9
- data/lib/bullet/active_record3.rb +9 -9
- data/lib/bullet/active_record3x.rb +11 -11
- data/lib/bullet/active_record4.rb +94 -0
- data/lib/bullet/dependency.rb +3 -1
- data/lib/bullet/detector/association.rb +2 -43
- data/lib/bullet/detector/{counter.rb → counter_cache.rb} +13 -3
- data/lib/bullet/detector/n_plus_one_query.rb +21 -2
- data/lib/bullet/detector/{unused_eager_association.rb → unused_eager_loading.rb} +40 -3
- data/lib/bullet/detector.rb +2 -2
- data/lib/bullet/mongoid2x.rb +5 -5
- data/lib/bullet/mongoid3x.rb +6 -6
- data/lib/bullet/version.rb +1 -1
- data/lib/bullet.rb +42 -7
- data/spec/bullet/detector/association_spec.rb +0 -49
- data/spec/bullet/detector/counter_cache_spec.rb +64 -0
- data/spec/bullet/detector/n_plus_one_query_spec.rb +23 -1
- data/spec/bullet/detector/unused_eager_loading_spec.rb +95 -0
- data/spec/integration/association_spec.rb +155 -63
- data/spec/integration/{counter_spec.rb → counter_cache_spec.rb} +26 -2
- data/spec/integration/mongoid/association_spec.rb +24 -24
- data/spec/integration/rails2/association_spec.rb +49 -49
- data/spec/integration/rails2/{counter_spec.rb → counter_cache_spec.rb} +13 -1
- metadata +17 -15
- data/spec/bullet/detector/counter_spec.rb +0 -64
- data/spec/bullet/detector/unused_eager_association_spec.rb +0 -62
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bullet
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.
|
|
4
|
+
version: 4.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Richard Huang
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2013-03-
|
|
11
|
+
date: 2013-03-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: uniform_notifier
|
|
@@ -36,6 +36,7 @@ files:
|
|
|
36
36
|
- .rvmrc
|
|
37
37
|
- .rvmrc.example
|
|
38
38
|
- .travis.yml
|
|
39
|
+
- CHANGELOG.md
|
|
39
40
|
- Gemfile
|
|
40
41
|
- Gemfile.rails-2.3.17
|
|
41
42
|
- Gemfile.rails-3.0.20
|
|
@@ -43,9 +44,9 @@ files:
|
|
|
43
44
|
- Gemfile.rails-3.2.12
|
|
44
45
|
- Gemfile.rails-4-beta
|
|
45
46
|
- Guardfile
|
|
46
|
-
- Hacking.
|
|
47
|
+
- Hacking.md
|
|
47
48
|
- MIT-LICENSE
|
|
48
|
-
- README.
|
|
49
|
+
- README.md
|
|
49
50
|
- README_for_rails2.textile
|
|
50
51
|
- Rakefile
|
|
51
52
|
- bullet.gemspec
|
|
@@ -54,13 +55,14 @@ files:
|
|
|
54
55
|
- lib/bullet/active_record2.rb
|
|
55
56
|
- lib/bullet/active_record3.rb
|
|
56
57
|
- lib/bullet/active_record3x.rb
|
|
58
|
+
- lib/bullet/active_record4.rb
|
|
57
59
|
- lib/bullet/dependency.rb
|
|
58
60
|
- lib/bullet/detector.rb
|
|
59
61
|
- lib/bullet/detector/association.rb
|
|
60
62
|
- lib/bullet/detector/base.rb
|
|
61
|
-
- lib/bullet/detector/
|
|
63
|
+
- lib/bullet/detector/counter_cache.rb
|
|
62
64
|
- lib/bullet/detector/n_plus_one_query.rb
|
|
63
|
-
- lib/bullet/detector/
|
|
65
|
+
- lib/bullet/detector/unused_eager_loading.rb
|
|
64
66
|
- lib/bullet/ext/object.rb
|
|
65
67
|
- lib/bullet/ext/string.rb
|
|
66
68
|
- lib/bullet/mongoid2x.rb
|
|
@@ -81,9 +83,9 @@ files:
|
|
|
81
83
|
- rails/init.rb
|
|
82
84
|
- spec/bullet/detector/association_spec.rb
|
|
83
85
|
- spec/bullet/detector/base_spec.rb
|
|
84
|
-
- spec/bullet/detector/
|
|
86
|
+
- spec/bullet/detector/counter_cache_spec.rb
|
|
85
87
|
- spec/bullet/detector/n_plus_one_query_spec.rb
|
|
86
|
-
- spec/bullet/detector/
|
|
88
|
+
- spec/bullet/detector/unused_eager_loading_spec.rb
|
|
87
89
|
- spec/bullet/ext/object_spec.rb
|
|
88
90
|
- spec/bullet/ext/string_spec.rb
|
|
89
91
|
- spec/bullet/notification/base_spec.rb
|
|
@@ -96,10 +98,10 @@ files:
|
|
|
96
98
|
- spec/bullet/registry/base_spec.rb
|
|
97
99
|
- spec/bullet/registry/object_spec.rb
|
|
98
100
|
- spec/integration/association_spec.rb
|
|
99
|
-
- spec/integration/
|
|
101
|
+
- spec/integration/counter_cache_spec.rb
|
|
100
102
|
- spec/integration/mongoid/association_spec.rb
|
|
101
103
|
- spec/integration/rails2/association_spec.rb
|
|
102
|
-
- spec/integration/rails2/
|
|
104
|
+
- spec/integration/rails2/counter_cache_spec.rb
|
|
103
105
|
- spec/models/address.rb
|
|
104
106
|
- spec/models/author.rb
|
|
105
107
|
- spec/models/base_user.rb
|
|
@@ -157,16 +159,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
157
159
|
version: 1.3.6
|
|
158
160
|
requirements: []
|
|
159
161
|
rubyforge_project:
|
|
160
|
-
rubygems_version: 2.0.
|
|
162
|
+
rubygems_version: 2.0.2
|
|
161
163
|
signing_key:
|
|
162
164
|
specification_version: 4
|
|
163
165
|
summary: A rails plugin to kill N+1 queries and unused eager loading.
|
|
164
166
|
test_files:
|
|
165
167
|
- spec/bullet/detector/association_spec.rb
|
|
166
168
|
- spec/bullet/detector/base_spec.rb
|
|
167
|
-
- spec/bullet/detector/
|
|
169
|
+
- spec/bullet/detector/counter_cache_spec.rb
|
|
168
170
|
- spec/bullet/detector/n_plus_one_query_spec.rb
|
|
169
|
-
- spec/bullet/detector/
|
|
171
|
+
- spec/bullet/detector/unused_eager_loading_spec.rb
|
|
170
172
|
- spec/bullet/ext/object_spec.rb
|
|
171
173
|
- spec/bullet/ext/string_spec.rb
|
|
172
174
|
- spec/bullet/notification/base_spec.rb
|
|
@@ -179,10 +181,10 @@ test_files:
|
|
|
179
181
|
- spec/bullet/registry/base_spec.rb
|
|
180
182
|
- spec/bullet/registry/object_spec.rb
|
|
181
183
|
- spec/integration/association_spec.rb
|
|
182
|
-
- spec/integration/
|
|
184
|
+
- spec/integration/counter_cache_spec.rb
|
|
183
185
|
- spec/integration/mongoid/association_spec.rb
|
|
184
186
|
- spec/integration/rails2/association_spec.rb
|
|
185
|
-
- spec/integration/rails2/
|
|
187
|
+
- spec/integration/rails2/counter_cache_spec.rb
|
|
186
188
|
- spec/models/address.rb
|
|
187
189
|
- spec/models/author.rb
|
|
188
190
|
- spec/models/base_user.rb
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module Bullet
|
|
4
|
-
module Detector
|
|
5
|
-
describe Counter do
|
|
6
|
-
before :all do
|
|
7
|
-
@post1 = Post.first
|
|
8
|
-
@post2 = Post.last
|
|
9
|
-
end
|
|
10
|
-
before(:each) { Counter.clear }
|
|
11
|
-
|
|
12
|
-
context ".clear" do
|
|
13
|
-
it "should clear all class variables" do
|
|
14
|
-
Counter.class_variable_get(:@@possible_objects).should be_nil
|
|
15
|
-
Counter.class_variable_get(:@@impossible_objects).should be_nil
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
context ".add_counter_cache" do
|
|
20
|
-
it "should create notification if conditions met" do
|
|
21
|
-
Counter.should_receive(:conditions_met?).with(@post1.bullet_ar_key, [:comments]).and_return(true)
|
|
22
|
-
Counter.should_receive(:create_notification).with("Post", [:comments])
|
|
23
|
-
Counter.add_counter_cache(@post1, [:comments])
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it "should not create notification if conditions not met" do
|
|
27
|
-
Counter.should_receive(:conditions_met?).with(@post1.bullet_ar_key, [:comments]).and_return(false)
|
|
28
|
-
Counter.should_receive(:create_notification).never
|
|
29
|
-
Counter.add_counter_cache(@post1, [:comments])
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context ".add_possible_objects" do
|
|
34
|
-
it "should add possible objects" do
|
|
35
|
-
Counter.add_possible_objects([@post1, @post2])
|
|
36
|
-
Counter.send(:possible_objects).should be_include(@post1.bullet_ar_key)
|
|
37
|
-
Counter.send(:possible_objects).should be_include(@post2.bullet_ar_key)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it "should add impossible object" do
|
|
41
|
-
Counter.add_impossible_object(@post1)
|
|
42
|
-
Counter.send(:impossible_objects).should be_include(@post1.bullet_ar_key)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
context ".conditions_met?" do
|
|
47
|
-
it "should be true when object is possible, not impossible" do
|
|
48
|
-
Counter.add_possible_objects(@post1)
|
|
49
|
-
Counter.send(:conditions_met?, @post1.bullet_ar_key, :associations).should be_true
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it "should be false when object is not possible" do
|
|
53
|
-
Counter.send(:conditions_met?, @post1.bullet_ar_key, :associations).should be_false
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
it "should be true when object is possible, and impossible" do
|
|
57
|
-
Counter.add_possible_objects(@post1)
|
|
58
|
-
Counter.add_impossible_object(@post1)
|
|
59
|
-
Counter.send(:conditions_met?, @post1.bullet_ar_key, :associations).should be_false
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module Bullet
|
|
4
|
-
module Detector
|
|
5
|
-
describe UnusedEagerAssociation do
|
|
6
|
-
before(:all) { @post = Post.first }
|
|
7
|
-
before(:each) { UnusedEagerAssociation.clear }
|
|
8
|
-
|
|
9
|
-
context ".call_associations" do
|
|
10
|
-
it "should get empty array if eager_loadgins" do
|
|
11
|
-
UnusedEagerAssociation.send(:call_associations, @post.bullet_ar_key, Set.new([:association])).should be_empty
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "should get call associations if object and association are both in eager_loadings and call_object_associations" do
|
|
15
|
-
UnusedEagerAssociation.add_eager_loadings([@post], :association)
|
|
16
|
-
UnusedEagerAssociation.add_call_object_associations(@post, :association)
|
|
17
|
-
UnusedEagerAssociation.send(:call_associations, @post.bullet_ar_key, Set.new([:association])).should == [:association]
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "should not get call associations if not exist in call_object_associations" do
|
|
21
|
-
UnusedEagerAssociation.add_eager_loadings([@post], :association)
|
|
22
|
-
UnusedEagerAssociation.send(:call_associations, @post.bullet_ar_key, Set.new([:association])).should be_empty
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
context ".diff_object_associations" do
|
|
27
|
-
it "should return associations not exist in call_association" do
|
|
28
|
-
UnusedEagerAssociation.send(:diff_object_associations, @post.bullet_ar_key, Set.new([:association])).should == [:association]
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "should return empty if associations exist in call_association" do
|
|
32
|
-
UnusedEagerAssociation.add_eager_loadings([@post], :association)
|
|
33
|
-
UnusedEagerAssociation.add_call_object_associations(@post, :association)
|
|
34
|
-
UnusedEagerAssociation.send(:diff_object_associations, @post.bullet_ar_key, Set.new([:association])).should be_empty
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
context ".check_unused_preload_associations" do
|
|
39
|
-
it "should set @@checked to true" do
|
|
40
|
-
UnusedEagerAssociation.check_unused_preload_associations
|
|
41
|
-
UnusedEagerAssociation.class_variable_get(:@@checked).should be_true
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it "should create notification if object_association_diff is not empty" do
|
|
45
|
-
UnusedEagerAssociation.add_object_associations(@post, :association)
|
|
46
|
-
UnusedEagerAssociation.should_receive(:create_notification).with("Post", [:association])
|
|
47
|
-
UnusedEagerAssociation.check_unused_preload_associations
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it "should not create notification if object_association_diff is empty" do
|
|
51
|
-
UnusedEagerAssociation.clear
|
|
52
|
-
UnusedEagerAssociation.add_object_associations(@post, :association)
|
|
53
|
-
UnusedEagerAssociation.add_eager_loadings([@post], :association)
|
|
54
|
-
UnusedEagerAssociation.add_call_object_associations(@post, :association)
|
|
55
|
-
UnusedEagerAssociation.send(:diff_object_associations, @post.bullet_ar_key, Set.new([:association])).should be_empty
|
|
56
|
-
UnusedEagerAssociation.should_not_receive(:create_notification).with("Post", [:association])
|
|
57
|
-
UnusedEagerAssociation.check_unused_preload_associations
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|