bullet 4.0.0 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,3 +7,5 @@ gemfile:
7
7
  - Gemfile.rails-3.0.12
8
8
  - Gemfile.rails-2.3.14
9
9
  env: DB=sqlite
10
+ before_install:
11
+ - echo "yes" | gem uninstall json
data/Gemfile CHANGED
@@ -8,8 +8,7 @@ gem 'rails', '3.2.3'
8
8
  gem 'sqlite3'
9
9
  gem 'mysql'
10
10
  gem 'activerecord-import'
11
- gem 'mongoid'
12
- gem 'bson_ext'
11
+ gem 'mongoid', '3.0.0.rc'
13
12
 
14
13
  gem "rspec"
15
14
  gem "guard"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bullet (4.0.0)
4
+ bullet (4.1.0)
5
5
  uniform_notifier (~> 1.0.0)
6
6
 
7
7
  GEM
@@ -38,9 +38,6 @@ GEM
38
38
  i18n (~> 0.6)
39
39
  multi_json (~> 1.0)
40
40
  arel (3.0.2)
41
- bson (1.6.2)
42
- bson_ext (1.6.2)
43
- bson (~> 1.6.2)
44
41
  builder (3.0.0)
45
42
  diff-lcs (1.1.3)
46
43
  erubis (2.7.0)
@@ -59,14 +56,15 @@ GEM
59
56
  mime-types (~> 1.16)
60
57
  treetop (~> 1.4.8)
61
58
  mime-types (1.18)
62
- mongo (1.6.2)
63
- bson (~> 1.6.2)
64
- mongoid (2.4.9)
59
+ mongoid (3.0.0.rc)
65
60
  activemodel (~> 3.1)
66
- mongo (~> 1.3)
61
+ moped (~> 1.0.0.rc)
62
+ origin (~> 1.0.0.rc)
67
63
  tzinfo (~> 0.3.22)
68
- multi_json (1.3.4)
64
+ moped (1.0.0.rc)
65
+ multi_json (1.3.6)
69
66
  mysql (2.8.1)
67
+ origin (1.0.0.rc)
70
68
  perftools.rb (2.0.0)
71
69
  polyglot (0.3.3)
72
70
  rack (1.4.1)
@@ -120,11 +118,10 @@ PLATFORMS
120
118
 
121
119
  DEPENDENCIES
122
120
  activerecord-import
123
- bson_ext
124
121
  bullet!
125
122
  guard
126
123
  guard-rspec
127
- mongoid
124
+ mongoid (= 3.0.0.rc)
128
125
  mysql
129
126
  perftools.rb
130
127
  rails (= 3.2.3)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bullet (2.3.1)
4
+ bullet (4.1.0)
5
5
  uniform_notifier (~> 1.0.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bullet (2.3.1)
4
+ bullet (4.1.0)
5
5
  uniform_notifier (~> 1.0.0)
6
6
 
7
7
  GEM
@@ -8,7 +8,7 @@ gem 'rails', '3.1.4'
8
8
  gem 'sqlite3'
9
9
  gem 'mysql'
10
10
  gem 'activerecord-import'
11
- gem 'mongoid'
11
+ gem 'mongoid', '2.4.10'
12
12
  gem 'bson_ext'
13
13
 
14
14
  gem "rspec"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bullet (2.3.1)
4
+ bullet (4.1.0)
5
5
  uniform_notifier (~> 1.0.0)
6
6
 
7
7
  GEM
@@ -61,11 +61,11 @@ GEM
61
61
  mime-types (1.18)
62
62
  mongo (1.6.2)
63
63
  bson (~> 1.6.2)
64
- mongoid (2.4.9)
64
+ mongoid (2.4.10)
65
65
  activemodel (~> 3.1)
66
66
  mongo (~> 1.3)
67
67
  tzinfo (~> 0.3.22)
68
- multi_json (1.3.4)
68
+ multi_json (1.3.6)
69
69
  mysql (2.8.1)
70
70
  perftools.rb (2.0.0)
71
71
  polyglot (0.3.3)
@@ -126,7 +126,7 @@ DEPENDENCIES
126
126
  bullet!
127
127
  guard
128
128
  guard-rspec
129
- mongoid
129
+ mongoid (= 2.4.10)
130
130
  mysql
131
131
  perftools.rb
132
132
  rails (= 3.1.4)
@@ -12,7 +12,15 @@ module Bullet
12
12
  autoload :ActiveRecord, 'bullet/active_record2'
13
13
  autoload :ActionController, 'bullet/action_controller2'
14
14
  end
15
- autoload :Mongoid, 'bullet/mongoid'
15
+ begin
16
+ require 'mongoid'
17
+ if Mongoid::VERSION =~ /\A2\.4/
18
+ autoload :Mongoid, 'bullet/mongoid24'
19
+ elsif Mongoid::VERSION =~ /\A3/
20
+ autoload :Mongoid, 'bullet/mongoid3'
21
+ end
22
+ rescue LoadError
23
+ end
16
24
  autoload :Rack, 'bullet/rack'
17
25
  autoload :BulletLogger, 'bullet/logger'
18
26
  autoload :Notification, 'bullet/notification'
@@ -2,10 +2,12 @@ module Bullet
2
2
  module Mongoid
3
3
  def self.enable
4
4
  require 'mongoid'
5
+
5
6
  ::Mongoid::Contexts::Mongo.class_eval do
6
7
  alias_method :origin_first, :first
7
8
  alias_method :origin_last, :last
8
9
  alias_method :origin_iterate, :iterate
10
+ alias_method :origin_eager_load, :eager_load
9
11
 
10
12
  def first
11
13
  result = origin_first
@@ -28,19 +30,6 @@ module Bullet
28
30
  end
29
31
  origin_iterate(&block)
30
32
  end
31
- end
32
-
33
- ::Mongoid::Relations::Accessors.class_eval do
34
- alias_method :origin_set_relation, :set_relation
35
-
36
- def set_relation(name, relation)
37
- Bullet::Detector::NPlusOneQuery.call_association(self, name)
38
- origin_set_relation(name, relation)
39
- end
40
- end
41
-
42
- ::Mongoid::Contexts::Mongo.class_eval do
43
- alias_method :origin_eager_load, :eager_load
44
33
 
45
34
  def eager_load(docs)
46
35
  associations = criteria.inclusions.map(&:name)
@@ -51,6 +40,15 @@ module Bullet
51
40
  origin_eager_load(docs)
52
41
  end
53
42
  end
43
+
44
+ ::Mongoid::Relations::Accessors.class_eval do
45
+ alias_method :origin_set_relation, :set_relation
46
+
47
+ def set_relation(name, relation)
48
+ Bullet::Detector::NPlusOneQuery.call_association(self, name)
49
+ origin_set_relation(name, relation)
50
+ end
51
+ end
54
52
  end
55
53
  end
56
54
  end
@@ -0,0 +1,53 @@
1
+ module Bullet
2
+ module Mongoid
3
+ def self.enable
4
+ require 'mongoid'
5
+ ::Mongoid::Contextual::Mongo.class_eval do
6
+ alias_method :origin_first, :first
7
+ alias_method :origin_last, :last
8
+ alias_method :origin_each, :each
9
+ alias_method :origin_eager_load, :eager_load
10
+
11
+ def first
12
+ result = origin_first
13
+ Bullet::Detector::Association.add_impossible_object(result)
14
+ result
15
+ end
16
+
17
+ def last
18
+ result = origin_last
19
+ Bullet::Detector::Association.add_impossible_object(result)
20
+ result
21
+ end
22
+
23
+ def each(&block)
24
+ records = query.map{ |doc| ::Mongoid::Factory.from_db(klass, doc) }
25
+ if records.length > 1
26
+ Bullet::Detector::Association.add_possible_objects(records)
27
+ elsif records.size == 1
28
+ Bullet::Detector::Association.add_impossible_object(records.first)
29
+ end
30
+ origin_each(&block)
31
+ end
32
+
33
+ def eager_load(docs)
34
+ associations = criteria.inclusions.map(&:name)
35
+ docs.each do |doc|
36
+ Bullet::Detector::Association.add_object_associations(doc, associations)
37
+ end
38
+ Bullet::Detector::Association.add_eager_loadings(docs, associations)
39
+ origin_eager_load(docs)
40
+ end
41
+ end
42
+
43
+ ::Mongoid::Relations::Accessors.class_eval do
44
+ alias_method :origin_set_relation, :set_relation
45
+
46
+ def set_relation(name, relation)
47
+ Bullet::Detector::NPlusOneQuery.call_association(self, name)
48
+ origin_set_relation(name, relation)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  module Bullet
3
- VERSION = "4.0.0"
3
+ VERSION = "4.1.0"
4
4
  end
5
5
 
@@ -1,275 +1,252 @@
1
- require 'spec_helper'
2
-
3
1
  begin
4
2
  require 'mongoid'
5
- describe Bullet::Detector::Association, 'has_many' do
3
+ require 'spec_helper'
4
+
5
+ describe Bullet::Detector::Association do
6
6
  before(:each) do
7
7
  Bullet.clear
8
8
  Bullet.start_request
9
9
  end
10
10
  after(:each) do
11
11
  Bullet.end_request
12
+ Mongoid::IdentityMap.clear
12
13
  end
13
14
 
14
- context "posts => comments" do
15
- it "should detect non preload posts => comments" do
16
- Mongoid::Post.all.each do |post|
17
- post.comments.map(&:name)
15
+ context 'has_many' do
16
+ context "posts => comments" do
17
+ it "should detect non preload posts => comments" do
18
+ Mongoid::Post.all.each do |post|
19
+ post.comments.map(&:name)
20
+ end
21
+ Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
22
+ Bullet::Detector::Association.should_not be_has_unused_preload_associations
23
+
24
+ Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Post, :comments)
18
25
  end
19
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
20
- Bullet::Detector::Association.should_not be_has_unused_preload_associations
21
26
 
22
- Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Post, :comments)
23
- end
27
+ it "should detect preload post => comments" do
28
+ Mongoid::Post.includes(:comments).each do |post|
29
+ post.comments.map(&:name)
30
+ end
31
+ Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
32
+ Bullet::Detector::Association.should_not be_has_unused_preload_associations
24
33
 
25
- it "should detect preload post => comments" do
26
- Mongoid::Post.includes(:comments).each do |post|
27
- post.comments.map(&:name)
34
+ Bullet::Detector::Association.should be_completely_preloading_associations
28
35
  end
29
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
30
- Bullet::Detector::Association.should_not be_has_unused_preload_associations
31
36
 
32
- Bullet::Detector::Association.should be_completely_preloading_associations
33
- end
34
-
35
- it "should detect unused preload post => comments" do
36
- Mongoid::Post.includes(:comments).map(&:name)
37
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
38
- Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Post, :comments)
37
+ it "should detect unused preload post => comments" do
38
+ Mongoid::Post.includes(:comments).map(&:name)
39
+ Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
40
+ Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Post, :comments)
39
41
 
40
- Bullet::Detector::Association.should be_completely_preloading_associations
41
- end
42
+ Bullet::Detector::Association.should be_completely_preloading_associations
43
+ end
42
44
 
43
- it "should not detect unused preload post => comments" do
44
- Mongoid::Post.all.map(&:name)
45
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
46
- Bullet::Detector::Association.should_not be_has_unused_preload_associations
45
+ it "should not detect unused preload post => comments" do
46
+ Mongoid::Post.all.map(&:name)
47
+ Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
48
+ Bullet::Detector::Association.should_not be_has_unused_preload_associations
47
49
 
48
- Bullet::Detector::Association.should be_completely_preloading_associations
50
+ Bullet::Detector::Association.should be_completely_preloading_associations
51
+ end
49
52
  end
50
- end
51
53
 
52
- context "category => posts, category => entries" do
53
- it "should detect non preload with category => [posts, entries]" do
54
- Mongoid::Category.all.each do |category|
55
- category.posts.map(&:name)
56
- category.entries.map(&:name)
54
+ context "category => posts, category => entries" do
55
+ it "should detect non preload with category => [posts, entries]" do
56
+ Mongoid::Category.all.each do |category|
57
+ category.posts.map(&:name)
58
+ category.entries.map(&:name)
59
+ end
60
+ Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
61
+ Bullet::Detector::Association.should_not be_has_unused_preload_associations
62
+
63
+ Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Category, :posts)
64
+ Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Category, :entries)
57
65
  end
58
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
59
- Bullet::Detector::Association.should_not be_has_unused_preload_associations
60
66
 
61
- Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Category, :posts)
62
- Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Category, :entries)
63
- end
67
+ it "should detect preload with category => posts, but not with category => entries" do
68
+ Mongoid::Category.includes(:posts).each do |category|
69
+ category.posts.map(&:name)
70
+ category.entries.map(&:name)
71
+ end
72
+ Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
73
+ Bullet::Detector::Association.should_not be_has_unused_preload_associations
64
74
 
65
- it "should detect preload with category => posts, but not with category => entries" do
66
- Mongoid::Category.includes(:posts).each do |category|
67
- category.posts.collect(&:name)
68
- category.entries.collect(&:name)
75
+ Bullet::Detector::Association.should_not be_detecting_unpreloaded_association_for(Mongoid::Category, :posts)
76
+ Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Category, :entries)
69
77
  end
70
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
71
- Bullet::Detector::Association.should_not be_has_unused_preload_associations
72
78
 
73
- Bullet::Detector::Association.should_not be_detecting_unpreloaded_association_for(Mongoid::Category, :posts)
74
- Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Category, :entries)
75
- end
79
+ it "should detect preload with category => [posts, entries]" do
80
+ Mongoid::Category.includes(:posts, :entries).each do |category|
81
+ category.posts.map(&:name)
82
+ category.entries.map(&:name)
83
+ end
84
+ Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
85
+ Bullet::Detector::Association.should_not be_has_unused_preload_associations
76
86
 
77
- it "should detect preload with category => [posts, entries]" do
78
- Mongoid::Category.includes([:posts, :entries]).each do |category|
79
- category.posts.map(&:name)
80
- category.entries.map(&:name)
87
+ Bullet::Detector::Association.should be_completely_preloading_associations
81
88
  end
82
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
83
- Bullet::Detector::Association.should_not be_has_unused_preload_associations
84
89
 
85
- Bullet::Detector::Association.should be_completely_preloading_associations
86
- end
90
+ it "should detect unused preload with category => [posts, entries]" do
91
+ Mongoid::Category.includes(:posts, :entries).map(&:name)
92
+ Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
93
+ Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Category, :posts)
94
+ Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Category, :entries)
87
95
 
88
- it "should detect unused preload with category => [posts, entries]" do
89
- Mongoid::Category.includes([:posts, :entries]).map(&:name)
90
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
91
- Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Category, :posts)
92
- Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Category, :entries)
96
+ Bullet::Detector::Association.should be_completely_preloading_associations
97
+ end
93
98
 
94
- Bullet::Detector::Association.should be_completely_preloading_associations
95
- end
99
+ it "should detect unused preload with category => entries, but not with category => posts" do
100
+ Mongoid::Category.includes(:posts, :entries).each do |category|
101
+ category.posts.map(&:name)
102
+ end
103
+ Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
104
+ Bullet::Detector::Association.should_not be_unused_preload_associations_for(Mongoid::Category, :posts)
105
+ Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Category, :entries)
96
106
 
97
- it "should detect unused preload with category => entries, but not with category => posts" do
98
- Mongoid::Category.includes([:posts, :entries]).each do |category|
99
- category.posts.map(&:name)
107
+ Bullet::Detector::Association.should be_completely_preloading_associations
100
108
  end
101
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
102
- Bullet::Detector::Association.should_not be_unused_preload_associations_for(Mongoid::Category, :posts)
103
- Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Category, :entries)
104
-
105
- Bullet::Detector::Association.should be_completely_preloading_associations
106
109
  end
107
- end
108
110
 
109
- context "post => comment" do
110
- it "should detect unused preload with post => comments" do
111
- Mongoid::Post.includes(:comments).each do |post|
112
- post.comments.first.name
113
- end
114
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
115
- Bullet::Detector::Association.should_not be_unused_preload_associations_for(Mongoid::Post, :comments)
111
+ context "post => comment" do
112
+ it "should detect unused preload with post => comments" do
113
+ Mongoid::Post.includes(:comments).each do |post|
114
+ post.comments.first.name
115
+ end
116
+ Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
117
+ Bullet::Detector::Association.should_not be_unused_preload_associations_for(Mongoid::Post, :comments)
116
118
 
117
- Bullet::Detector::Association.should be_completely_preloading_associations
118
- end
119
+ Bullet::Detector::Association.should be_completely_preloading_associations
120
+ end
119
121
 
120
- it "should detect preload with post => commnets" do
121
- Mongoid::Post.first.comments.collect(&:name)
122
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
123
- Bullet::Detector::Association.should_not be_has_unused_preload_associations
122
+ it "should detect preload with post => commnets" do
123
+ Mongoid::Post.first.comments.map(&:name)
124
+ Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
125
+ Bullet::Detector::Association.should_not be_has_unused_preload_associations
124
126
 
125
- Bullet::Detector::Association.should be_completely_preloading_associations
127
+ Bullet::Detector::Association.should be_completely_preloading_associations
128
+ end
126
129
  end
127
- end
128
130
 
129
- context "scope preload_comments" do
130
- it "should detect preload post => comments with scope" do
131
- Mongoid::Post.preload_comments.each do |post|
132
- post.comments.map(&:name)
133
- end
134
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
135
- Bullet::Detector::Association.should_not be_has_unused_preload_associations
131
+ context "scope preload_comments" do
132
+ it "should detect preload post => comments with scope" do
133
+ Mongoid::Post.preload_comments.each do |post|
134
+ post.comments.map(&:name)
135
+ end
136
+ Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
137
+ Bullet::Detector::Association.should_not be_has_unused_preload_associations
136
138
 
137
- Bullet::Detector::Association.should be_completely_preloading_associations
138
- end
139
+ Bullet::Detector::Association.should be_completely_preloading_associations
140
+ end
139
141
 
140
- it "should detect unused preload with scope" do
141
- Mongoid::Post.preload_comments.map(&:name)
142
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
143
- Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Post, :comments)
142
+ it "should detect unused preload with scope" do
143
+ Mongoid::Post.preload_comments.map(&:name)
144
+ Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
145
+ Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Post, :comments)
144
146
 
145
- Bullet::Detector::Association.should be_completely_preloading_associations
147
+ Bullet::Detector::Association.should be_completely_preloading_associations
148
+ end
146
149
  end
147
150
  end
148
- end
149
151
 
150
- describe Bullet::Detector::Association, 'belongs_to' do
151
- before(:each) do
152
- Bullet.clear
153
- Bullet.start_request
154
- end
152
+ context 'belongs_to' do
153
+ context "comment => post" do
154
+ it "should detect non preload with comment => post" do
155
+ Mongoid::Comment.all.each do |comment|
156
+ comment.post.name
157
+ end
158
+ Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
159
+ Bullet::Detector::Association.should_not be_has_unused_preload_associations
155
160
 
156
- after(:each) do
157
- Bullet.end_request
158
- end
159
-
160
- context "comment => post" do
161
- it "should detect non preload with comment => post" do
162
- Mongoid::Comment.all.each do |comment|
163
- comment.post.name
161
+ Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Comment, :post)
164
162
  end
165
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
166
- Bullet::Detector::Association.should_not be_has_unused_preload_associations
167
163
 
168
- Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Comment, :post)
169
- end
164
+ it "should detect preload with one comment => post" do
165
+ Mongoid::Comment.first.post.name
166
+ Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
167
+ Bullet::Detector::Association.should_not be_has_unused_preload_associations
170
168
 
171
- it "should detect preload with one comment => post" do
172
- Mongoid::Comment.first.post.name
173
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
174
- Bullet::Detector::Association.should_not be_has_unused_preload_associations
169
+ Bullet::Detector::Association.should be_completely_preloading_associations
170
+ end
175
171
 
176
- Bullet::Detector::Association.should be_completely_preloading_associations
177
- end
172
+ it "should detect preload with comment => post" do
173
+ Mongoid::Comment.includes(:post).each do |comment|
174
+ comment.post.name
175
+ end
176
+ Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
177
+ Bullet::Detector::Association.should_not be_has_unused_preload_associations
178
178
 
179
- it "should detect preload with comment => post" do
180
- Mongoid::Comment.includes(:post).each do |comment|
181
- comment.post.name
179
+ Bullet::Detector::Association.should be_completely_preloading_associations
182
180
  end
183
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
184
- Bullet::Detector::Association.should_not be_has_unused_preload_associations
185
181
 
186
- Bullet::Detector::Association.should be_completely_preloading_associations
187
- end
182
+ it "should not detect preload with comment => post" do
183
+ Mongoid::Comment.all.map(&:name)
184
+ Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
185
+ Bullet::Detector::Association.should_not be_has_unused_preload_associations
188
186
 
189
- it "should not detect preload with comment => post" do
190
- Mongoid::Comment.all.collect(&:name)
191
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
192
- Bullet::Detector::Association.should_not be_has_unused_preload_associations
193
-
194
- Bullet::Detector::Association.should be_completely_preloading_associations
195
- end
187
+ Bullet::Detector::Association.should be_completely_preloading_associations
188
+ end
196
189
 
197
- it "should detect unused preload with comments => post" do
198
- Mongoid::Comment.includes(:post).map(&:name)
199
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
200
- Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Comment, :post)
190
+ it "should detect unused preload with comments => post" do
191
+ Mongoid::Comment.includes(:post).map(&:name)
192
+ Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
193
+ Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Comment, :post)
201
194
 
202
- Bullet::Detector::Association.should be_completely_preloading_associations
195
+ Bullet::Detector::Association.should be_completely_preloading_associations
196
+ end
203
197
  end
204
198
  end
205
- end
206
199
 
207
- describe Bullet::Detector::Association, "has_one" do
208
- before(:each) do
209
- Bullet.clear
210
- Bullet.start_request
211
- end
200
+ context "has_one" do
201
+ context "company => address" do
202
+ it "should detect non preload association" do
203
+ Mongoid::Company.all.each do |company|
204
+ company.address.name
205
+ end
206
+ Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
207
+ Bullet::Detector::Association.should_not be_has_unused_preload_associations
212
208
 
213
- after(:each) do
214
- Bullet.end_request
215
- end
209
+ Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Company, :address)
210
+ end
211
+
212
+ it "should detect preload association" do
213
+ Mongoid::Company.includes(:address).each do |company|
214
+ company.address.name
215
+ end
216
+ Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
217
+ Bullet::Detector::Association.should_not be_has_unused_preload_associations
216
218
 
217
- context "company => address" do
218
- it "should detect non preload association" do
219
- Mongoid::Company.all.each do |company|
220
- company.address.name
219
+ Bullet::Detector::Association.should be_completely_preloading_associations
221
220
  end
222
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
223
- Bullet::Detector::Association.should_not be_has_unused_preload_associations
224
221
 
225
- Bullet::Detector::Association.should be_detecting_unpreloaded_association_for(Mongoid::Company, :address)
226
- end
222
+ it "should not detect preload association" do
223
+ Mongoid::Company.all.map(&:name)
224
+ Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
225
+ Bullet::Detector::Association.should_not be_has_unused_preload_associations
227
226
 
228
- it "should detect preload association" do
229
- Mongoid::Company.includes(:address).each do |company|
230
- company.address.name
227
+ Bullet::Detector::Association.should be_completely_preloading_associations
231
228
  end
232
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
233
- Bullet::Detector::Association.should_not be_has_unused_preload_associations
234
229
 
235
- Bullet::Detector::Association.should be_completely_preloading_associations
230
+ it "should detect unused preload association" do
231
+ criteria = Mongoid::Company.includes(:address)
232
+ criteria.map(&:name)
233
+ Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
234
+ Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Company, :address)
235
+
236
+ Bullet::Detector::Association.should be_completely_preloading_associations
237
+ end
236
238
  end
239
+ end
237
240
 
241
+ context "call one association that in possible objects" do
238
242
  it "should not detect preload association" do
239
- Mongoid::Company.all.collect(&:name)
243
+ Mongoid::Post.all
244
+ Mongoid::Post.first.comments.map(&:name)
240
245
  Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
241
246
  Bullet::Detector::Association.should_not be_has_unused_preload_associations
242
247
 
243
248
  Bullet::Detector::Association.should be_completely_preloading_associations
244
249
  end
245
-
246
- it "should detect unused preload association" do
247
- Mongoid::Company.includes(:address).collect(&:name)
248
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
249
- Bullet::Detector::Association.should be_unused_preload_associations_for(Mongoid::Company, :address)
250
-
251
- Bullet::Detector::Association.should be_completely_preloading_associations
252
- end
253
- end
254
- end
255
-
256
- describe Bullet::Detector::Association, "call one association that in possible objects" do
257
- before(:each) do
258
- Bullet.clear
259
- Bullet.start_request
260
- end
261
-
262
- after(:each) do
263
- Bullet.end_request
264
- end
265
-
266
- it "should not detect preload association" do
267
- Mongoid::Post.all
268
- Mongoid::Post.first.comments.map(&:name)
269
- Bullet::Detector::UnusedEagerAssociation.check_unused_preload_associations
270
- Bullet::Detector::Association.should_not be_has_unused_preload_associations
271
-
272
- Bullet::Detector::Association.should be_completely_preloading_associations
273
250
  end
274
251
  end
275
252
  rescue LoadError
@@ -29,11 +29,19 @@ module Support
29
29
  end
30
30
 
31
31
  def setup_db
32
- Mongoid.database = Mongo::Connection.new("localhost", 27017).db("bullet")
32
+ if Mongoid::VERSION =~ /\A2\.4/
33
+ Mongoid.configure do |config|
34
+ config.master = Mongo::Connection.new.db("bullet")
35
+ end
36
+ elsif Mongoid::VERSION =~ /\A3/
37
+ Mongoid.configure do |config|
38
+ config.connect_to("bullet")
39
+ end
40
+ end
33
41
  end
34
42
 
35
43
  def teardown_db
36
- Mongoid.database.collections.select {|c| c.name !~ /system/ }.map(&:drop)
44
+ Mongoid.purge!
37
45
  end
38
46
 
39
47
  extend self
data/test.sh ADDED
@@ -0,0 +1,4 @@
1
+ bundle && bundle exec rspec spec
2
+ BUNDLE_GEMFILE=Gemfile.rails-3.1.4 bundle && bundle exec rspec spec
3
+ BUNDLE_GEMFILE=Gemfile.rails-3.0.12 bundle && bundle exec rspec spec
4
+ BUNDLE_GEMFILE=Gemfile.rails-2.3.14 bundle && bundle exec rspec spec
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bullet
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-09 00:00:00.000000000 Z
12
+ date: 2012-05-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: uniform_notifier
16
- requirement: &70311383422560 !ruby/object:Gem::Requirement
16
+ requirement: &70161212330380 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70311383422560
24
+ version_requirements: *70161212330380
25
25
  description: A rails plugin to kill N+1 queries and unused eager loading.
26
26
  email:
27
27
  - flyerhzm@gmail.com
@@ -62,7 +62,8 @@ files:
62
62
  - lib/bullet/detector/unused_eager_association.rb
63
63
  - lib/bullet/ext/object.rb
64
64
  - lib/bullet/ext/string.rb
65
- - lib/bullet/mongoid.rb
65
+ - lib/bullet/mongoid24.rb
66
+ - lib/bullet/mongoid3.rb
66
67
  - lib/bullet/notification.rb
67
68
  - lib/bullet/notification/base.rb
68
69
  - lib/bullet/notification/counter_cache.rb
@@ -135,6 +136,7 @@ files:
135
136
  - spec/support/sqlite_seed.rb
136
137
  - tasks/bullet_tasks.rake
137
138
  - test.result
139
+ - test.sh
138
140
  homepage: http://github.com/flyerhzm/bullet
139
141
  licenses: []
140
142
  post_install_message:
@@ -149,7 +151,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
149
151
  version: '0'
150
152
  segments:
151
153
  - 0
152
- hash: -3387566190207483190
154
+ hash: 2670779275443337107
153
155
  required_rubygems_version: !ruby/object:Gem::Requirement
154
156
  none: false
155
157
  requirements:
@@ -158,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
160
  version: 1.3.6
159
161
  requirements: []
160
162
  rubyforge_project:
161
- rubygems_version: 1.8.15
163
+ rubygems_version: 1.8.17
162
164
  signing_key:
163
165
  specification_version: 3
164
166
  summary: A rails plugin to kill N+1 queries and unused eager loading.