flyerhzm-bullet 1.5.6 → 1.5.7
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bullet.gemspec +2 -2
- data/lib/bullet/active_record.rb +11 -0
- data/spec/bullet_association_spec.rb +40 -1
- data/spec/bullet_counter_spec.rb +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.5.
|
1
|
+
1.5.7
|
data/bullet.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bullet}
|
8
|
-
s.version = "1.5.
|
8
|
+
s.version = "1.5.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Richard Huang"]
|
12
|
-
s.date = %q{2009-09-
|
12
|
+
s.date = %q{2009-09-22}
|
13
13
|
s.description = %q{The Bullet plugin is designed to help you increase your application's performance by reducing the number of queries it makes. It will watch your queries while you develop your application and notify you when you should add eager loading (N+1 queries) or when you're using eager loading that isn't necessary.}
|
14
14
|
s.email = %q{flyerhzm@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/bullet/active_record.rb
CHANGED
@@ -45,6 +45,17 @@ module Bullet
|
|
45
45
|
Bullet::Association.define_association(self, reflection.name)
|
46
46
|
origin_collection_reader_method(reflection, association_proxy_class)
|
47
47
|
end
|
48
|
+
|
49
|
+
# add include in named_scope
|
50
|
+
alias_method :origin_find_with_associations, :find_with_associations
|
51
|
+
def find_with_associations(options)
|
52
|
+
records = origin_find_with_associations(options)
|
53
|
+
records.each do |record|
|
54
|
+
Bullet::Association.add_association(record, merge_includes(scope(:find, :include), options[:include]))
|
55
|
+
end
|
56
|
+
Bullet::Association.add_eager_loadings(records, merge_includes(scope(:find, :include), options[:include]))
|
57
|
+
records
|
58
|
+
end
|
48
59
|
end
|
49
60
|
|
50
61
|
::ActiveRecord::Associations::AssociationCollection.class_eval do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
|
-
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :
|
3
|
+
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
4
4
|
|
5
5
|
describe Bullet::Association, 'has_many' do
|
6
6
|
def setup_db
|
@@ -40,6 +40,11 @@ describe Bullet::Association, 'has_many' do
|
|
40
40
|
class Post < ActiveRecord::Base
|
41
41
|
belongs_to :category
|
42
42
|
has_many :comments
|
43
|
+
|
44
|
+
named_scope :preload_posts, lambda { {:include => :comments} }
|
45
|
+
named_scope :in_category_name, lambda { |name|
|
46
|
+
{ :conditions => ['categories.name = ?', name], :include => :category }
|
47
|
+
}
|
43
48
|
end
|
44
49
|
|
45
50
|
class Entry < ActiveRecord::Base
|
@@ -241,6 +246,40 @@ describe Bullet::Association, 'has_many' do
|
|
241
246
|
end
|
242
247
|
end
|
243
248
|
|
249
|
+
context "named_scope for_category_name" do
|
250
|
+
it "should detect preload with post => category" do
|
251
|
+
Post.in_category_name('first').all.each do |post|
|
252
|
+
post.category.name
|
253
|
+
end
|
254
|
+
Bullet::Association.should_not be_has_unpreload_associations
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should not be unused preload post => category" do
|
258
|
+
Post.in_category_name('first').all.each do |post|
|
259
|
+
post.name
|
260
|
+
end
|
261
|
+
Bullet::Association.should_not be_has_unpreload_associations
|
262
|
+
Bullet::Association.check_unused_preload_associations
|
263
|
+
Bullet::Association.should be_has_unused_preload_associations
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
context "named_scope preload_posts" do
|
268
|
+
it "should no preload post => comments with named_scope" do
|
269
|
+
Post.preload_posts.each do |post|
|
270
|
+
post.comments.collect(&:name)
|
271
|
+
end
|
272
|
+
Bullet::Association.should_not be_has_unpreload_associations
|
273
|
+
end
|
274
|
+
|
275
|
+
it "should unused preload with named_scope" do
|
276
|
+
Post.preload_posts.collect(&:name)
|
277
|
+
Bullet::Association.should_not be_has_unpreload_associations
|
278
|
+
Bullet::Association.check_unused_preload_associations
|
279
|
+
Bullet::Association.should be_has_unused_preload_associations
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
244
283
|
context "no unused" do
|
245
284
|
it "should no unused only display only one post => comment" do
|
246
285
|
Post.find(:all, :include => :comments).each do |post|
|
data/spec/bullet_counter_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
|
-
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :
|
3
|
+
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
4
4
|
|
5
5
|
describe Bullet::Counter do
|
6
6
|
def setup_db
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flyerhzm-bullet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-09-
|
12
|
+
date: 2009-09-22 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|