bullet 1.7.5 → 1.7.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.7.5
1
+ 1.7.6
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bullet}
8
- s.version = "1.7.5"
8
+ s.version = "1.7.6"
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{2010-02-12}
12
+ s.date = %q{2010-03-07}
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 = [
@@ -44,11 +44,11 @@ Gem::Specification.new do |s|
44
44
  s.rubygems_version = %q{1.3.5}
45
45
  s.summary = %q{A plugin to kill N+1 queries and unused eager loading}
46
46
  s.test_files = [
47
- "spec/bullet/association_for_chris_spec.rb",
48
- "spec/bullet/association_for_peschkaj_spec.rb",
49
- "spec/bullet/association_spec.rb",
47
+ "spec/spec_helper.rb",
50
48
  "spec/bullet/counter_spec.rb",
51
- "spec/spec_helper.rb"
49
+ "spec/bullet/association_spec.rb",
50
+ "spec/bullet/association_for_chris_spec.rb",
51
+ "spec/bullet/association_for_peschkaj_spec.rb"
52
52
  ]
53
53
 
54
54
  if s.respond_to? :specification_version then
@@ -94,6 +94,15 @@ module Bullet
94
94
  result
95
95
  end
96
96
  end
97
+
98
+ ::ActiveRecord::Associations::HasManyThroughAssociation.class_eval do
99
+ alias_method :origin_has_cached_counter?, :has_cached_counter?
100
+ def has_cached_counter?
101
+ result = origin_has_cached_counter?
102
+ Bullet::Counter.add_counter_cache(@owner, @reflection.name) unless result
103
+ result
104
+ end
105
+ end
97
106
  end
98
107
  end
99
108
  end
@@ -2,93 +2,95 @@ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
4
4
  # This test is just used for http://github.com/flyerhzm/bullet/issues/#issue/14
5
- describe Bullet::Association, 'for chris' do
5
+ describe Bullet::Association do
6
6
 
7
- def setup_db
8
- ActiveRecord::Schema.define(:version => 1) do
9
- create_table :locations do |t|
10
- t.column :name, :string
11
- end
7
+ describe "for chris" do
8
+ def setup_db
9
+ ActiveRecord::Schema.define(:version => 1) do
10
+ create_table :locations do |t|
11
+ t.column :name, :string
12
+ end
12
13
 
13
- create_table :hotels do |t|
14
- t.column :name, :string
15
- t.column :location_id, :integer
16
- end
14
+ create_table :hotels do |t|
15
+ t.column :name, :string
16
+ t.column :location_id, :integer
17
+ end
17
18
 
18
- create_table :deals do |t|
19
- t.column :name, :string
20
- t.column :hotel_id, :integer
19
+ create_table :deals do |t|
20
+ t.column :name, :string
21
+ t.column :hotel_id, :integer
22
+ end
21
23
  end
22
24
  end
23
- end
24
25
 
25
- def teardown_db
26
- ActiveRecord::Base.connection.tables.each do |table|
27
- ActiveRecord::Base.connection.drop_table(table)
26
+ def teardown_db
27
+ ActiveRecord::Base.connection.tables.each do |table|
28
+ ActiveRecord::Base.connection.drop_table(table)
29
+ end
28
30
  end
29
- end
30
31
 
31
- class Location < ActiveRecord::Base
32
- has_many :hotels
33
- end
32
+ class Location < ActiveRecord::Base
33
+ has_many :hotels
34
+ end
34
35
 
35
- class Hotel < ActiveRecord::Base
36
- belongs_to :location
37
- has_many :deals
38
- end
36
+ class Hotel < ActiveRecord::Base
37
+ belongs_to :location
38
+ has_many :deals
39
+ end
39
40
 
40
- class Deal < ActiveRecord::Base
41
- belongs_to :hotel
42
- has_one :location, :through => :hotel
43
- end
41
+ class Deal < ActiveRecord::Base
42
+ belongs_to :hotel
43
+ has_one :location, :through => :hotel
44
+ end
44
45
 
45
- before(:all) do
46
- setup_db
46
+ before(:all) do
47
+ setup_db
47
48
 
48
- location1 = Location.create(:name => "location1")
49
- location2 = Location.create(:name => "location2")
49
+ location1 = Location.create(:name => "location1")
50
+ location2 = Location.create(:name => "location2")
50
51
 
51
- hotel1 = location1.hotels.create(:name => "hotel1")
52
- hotel2 = location1.hotels.create(:name => "hotel2")
53
- hotel3 = location2.hotels.create(:name => "hotel3")
54
- hotel4 = location2.hotels.create(:name => "hotel4")
52
+ hotel1 = location1.hotels.create(:name => "hotel1")
53
+ hotel2 = location1.hotels.create(:name => "hotel2")
54
+ hotel3 = location2.hotels.create(:name => "hotel3")
55
+ hotel4 = location2.hotels.create(:name => "hotel4")
55
56
 
56
- deal1 = hotel1.deals.create(:name => "deal1")
57
- deal2 = hotel2.deals.create(:name => "deal2")
58
- deal3 = hotel3.deals.create(:name => "deal3")
59
- deal4 = hotel4.deals.create(:name => "deal4")
60
- end
57
+ deal1 = hotel1.deals.create(:name => "deal1")
58
+ deal2 = hotel2.deals.create(:name => "deal2")
59
+ deal3 = hotel3.deals.create(:name => "deal3")
60
+ deal4 = hotel4.deals.create(:name => "deal4")
61
+ end
61
62
 
62
- after(:all) do
63
- teardown_db
64
- end
63
+ after(:all) do
64
+ teardown_db
65
+ end
65
66
 
66
- before(:each) do
67
- Bullet::Association.start_request
68
- end
67
+ before(:each) do
68
+ Bullet::Association.start_request
69
+ end
69
70
 
70
- after(:each) do
71
- Bullet::Association.end_request
72
- end
71
+ after(:each) do
72
+ Bullet::Association.end_request
73
+ end
73
74
 
74
- it "should detect unpreload association from deal to hotel" do
75
- Deal.find(:all).each do |deal|
76
- deal.hotel.location.name
75
+ it "should detect unpreload association from deal to hotel" do
76
+ Deal.find(:all).each do |deal|
77
+ deal.hotel.location.name
78
+ end
79
+ Bullet::Association.should be_detecting_unpreloaded_association_for(Deal, :hotel)
77
80
  end
78
- Bullet::Association.should be_detecting_unpreloaded_association_for(Deal, :hotel)
79
- end
80
81
 
81
- it "should detect unpreload association from hotel to location" do
82
- Deal.find(:all, :include => :hotel).each do |deal|
83
- deal.hotel.location.name
82
+ it "should detect unpreload association from hotel to location" do
83
+ Deal.find(:all, :include => :hotel).each do |deal|
84
+ deal.hotel.location.name
85
+ end
86
+ Bullet::Association.should be_detecting_unpreloaded_association_for(Hotel, :location)
84
87
  end
85
- Bullet::Association.should be_detecting_unpreloaded_association_for(Hotel, :location)
86
- end
87
88
 
88
- it "should not detect unpreload association" do
89
- Deal.find(:all, :include => {:hotel => :location}).each do |deal|
90
- deal.hotel.location.name
89
+ it "should not detect unpreload association" do
90
+ Deal.find(:all, :include => {:hotel => :location}).each do |deal|
91
+ deal.hotel.location.name
92
+ end
93
+ Bullet::Association.should_not be_has_unused_preload_associations
91
94
  end
92
- Bullet::Association.should_not be_has_unused_preload_associations
93
95
  end
94
96
  end
@@ -2,83 +2,85 @@ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
4
4
  # This test is just used for http://github.com/flyerhzm/bullet/issues#issue/20
5
- describe Bullet::Association, 'for peschkaj' do
5
+ describe Bullet::Association do
6
+
7
+ describe "for peschkaj" do
8
+ def setup_db
9
+ ActiveRecord::Schema.define(:version => 1) do
10
+ create_table :categories do |t|
11
+ t.column :name, :string
12
+ end
6
13
 
7
- def setup_db
8
- ActiveRecord::Schema.define(:version => 1) do
9
- create_table :categories do |t|
10
- t.column :name, :string
11
- end
14
+ create_table :submissions do |t|
15
+ t.column :name, :string
16
+ t.column :category_id, :integer
17
+ t.column :user_id, :integer
18
+ end
12
19
 
13
- create_table :submissions do |t|
14
- t.column :name, :string
15
- t.column :category_id, :integer
16
- t.column :user_id, :integer
20
+ create_table :users do |t|
21
+ t.column :name, :string
22
+ t.column :category_id, :integer
23
+ end
17
24
  end
25
+ end
18
26
 
19
- create_table :users do |t|
20
- t.column :name, :string
21
- t.column :category_id, :integer
27
+ def teardown_db
28
+ ActiveRecord::Base.connection.tables.each do |table|
29
+ ActiveRecord::Base.connection.drop_table(table)
22
30
  end
23
31
  end
24
- end
25
32
 
26
- def teardown_db
27
- ActiveRecord::Base.connection.tables.each do |table|
28
- ActiveRecord::Base.connection.drop_table(table)
33
+ class Category < ActiveRecord::Base
34
+ has_many :submissions
35
+ has_many :users
29
36
  end
30
- end
31
-
32
- class Category < ActiveRecord::Base
33
- has_many :submissions
34
- has_many :users
35
- end
36
37
 
37
- class Submission < ActiveRecord::Base
38
- belongs_to :category
39
- belongs_to :user
40
- end
38
+ class Submission < ActiveRecord::Base
39
+ belongs_to :category
40
+ belongs_to :user
41
+ end
41
42
 
42
- class User < ActiveRecord::Base
43
- has_one :submission
44
- belongs_to :category
45
- end
43
+ class User < ActiveRecord::Base
44
+ has_one :submission
45
+ belongs_to :category
46
+ end
46
47
 
47
- before(:all) do
48
- setup_db
48
+ before(:all) do
49
+ setup_db
49
50
 
50
- category1 = Category.create(:name => "category1")
51
- category2 = Category.create(:name => "category2")
51
+ category1 = Category.create(:name => "category1")
52
+ category2 = Category.create(:name => "category2")
52
53
 
53
- user1 = User.create(:name => 'user1', :category => category1)
54
- user2 = User.create(:name => 'user2', :category => category1)
54
+ user1 = User.create(:name => 'user1', :category => category1)
55
+ user2 = User.create(:name => 'user2', :category => category1)
55
56
 
56
- submission1 = category1.submissions.create(:name => "submission1", :user => user1)
57
- submission2 = category1.submissions.create(:name => "submission2", :user => user2)
58
- submission3 = category2.submissions.create(:name => "submission3", :user => user1)
59
- submission4 = category2.submissions.create(:name => "submission4", :user => user2)
60
- end
57
+ submission1 = category1.submissions.create(:name => "submission1", :user => user1)
58
+ submission2 = category1.submissions.create(:name => "submission2", :user => user2)
59
+ submission3 = category2.submissions.create(:name => "submission3", :user => user1)
60
+ submission4 = category2.submissions.create(:name => "submission4", :user => user2)
61
+ end
61
62
 
62
- after(:all) do
63
- teardown_db
64
- end
63
+ after(:all) do
64
+ teardown_db
65
+ end
65
66
 
66
- before(:each) do
67
- Bullet::Association.start_request
68
- end
67
+ before(:each) do
68
+ Bullet::Association.start_request
69
+ end
69
70
 
70
- after(:each) do
71
- Bullet::Association.end_request
72
- end
71
+ after(:each) do
72
+ Bullet::Association.end_request
73
+ end
73
74
 
74
- it "should not detect unused preload associations" do
75
- category = Category.find_by_name('category1', :include => {:submissions => :user}, :order => "id DESC")
76
- category.submissions.map do |submission|
77
- submission.name
78
- submission.user.name
75
+ it "should not detect unused preload associations" do
76
+ category = Category.find_by_name('category1', :include => {:submissions => :user}, :order => "id DESC")
77
+ category.submissions.map do |submission|
78
+ submission.name
79
+ submission.user.name
80
+ end
81
+ Bullet::Association.check_unused_preload_associations
82
+ Bullet::Association.should_not be_unused_preload_associations_for(Category, :submissions)
83
+ Bullet::Association.should_not be_unused_preload_associations_for(Submission, :user)
79
84
  end
80
- Bullet::Association.check_unused_preload_associations
81
- Bullet::Association.should_not be_unused_preload_associations_for(Category, :submissions)
82
- Bullet::Association.should_not be_unused_preload_associations_for(Submission, :user)
83
85
  end
84
86
  end
@@ -706,26 +706,26 @@ describe Bullet::Association, 'has_many :as' do
706
706
  user3 = User.create(:name => 'third')
707
707
  user4 = User.create(:name => 'fourth')
708
708
 
709
- pet1 = User.create(:name => "dog")
710
- pet2 = User.create(:name => "dog")
711
- pet3 = User.create(:name => "cat")
712
- pet4 = User.create(:name => "cat")
713
-
714
- user1.votes << Vote.create(:vote => 10)
715
- user1.votes << Vote.create(:vote => 20)
716
- user2.votes << Vote.create(:vote => 10)
717
- user2.votes << Vote.create(:vote => 20)
718
- user3.votes << Vote.create(:vote => 10)
719
- user3.votes << Vote.create(:vote => 20)
720
- user4.votes << Vote.create(:vote => 10)
721
- user4.votes << Vote.create(:vote => 20)
709
+ pet1 = user1.pets.create(:name => "dog")
710
+ pet2 = user1.pets.create(:name => "dog")
711
+ pet3 = user2.pets.create(:name => "cat")
712
+ pet4 = user2.pets.create(:name => "cat")
713
+
714
+ user1.votes.create(:vote => 10)
715
+ user1.votes.create(:vote => 20)
716
+ user2.votes.create(:vote => 10)
717
+ user2.votes.create(:vote => 20)
718
+ user3.votes.create(:vote => 10)
719
+ user3.votes.create(:vote => 20)
720
+ user4.votes.create(:vote => 10)
721
+ user4.votes.create(:vote => 20)
722
722
 
723
723
  news1 = News.create(:name => 'first')
724
724
  news2 = News.create(:name => 'second')
725
- news1.votes << Vote.create(:vote => 10)
726
- news1.votes << Vote.create(:vote => 20)
727
- news2.votes << Vote.create(:vote => 10)
728
- news2.votes << Vote.create(:vote => 20)
725
+ news1.votes.create(:vote => 10)
726
+ news1.votes.create(:vote => 20)
727
+ news2.votes.create(:vote => 10)
728
+ news2.votes.create(:vote => 20)
729
729
  end
730
730
 
731
731
  after(:all) do
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: 1.7.5
4
+ version: 1.7.6
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: 2010-02-12 00:00:00 +08:00
12
+ date: 2010-03-07 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -72,8 +72,8 @@ signing_key:
72
72
  specification_version: 3
73
73
  summary: A plugin to kill N+1 queries and unused eager loading
74
74
  test_files:
75
+ - spec/spec_helper.rb
76
+ - spec/bullet/counter_spec.rb
77
+ - spec/bullet/association_spec.rb
75
78
  - spec/bullet/association_for_chris_spec.rb
76
79
  - spec/bullet/association_for_peschkaj_spec.rb
77
- - spec/bullet/association_spec.rb
78
- - spec/bullet/counter_spec.rb
79
- - spec/spec_helper.rb