bullet 2.0.0.beta.2 → 2.0.1

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.
Files changed (41) hide show
  1. data/MIT-LICENSE +1 -1
  2. data/README.textile +38 -8
  3. data/README_for_rails2.textile +19 -3
  4. data/lib/bullet/action_controller2.rb +4 -4
  5. data/lib/bullet/active_record2.rb +16 -16
  6. data/lib/bullet/active_record3.rb +16 -25
  7. data/lib/bullet/detector/association.rb +135 -0
  8. data/lib/bullet/detector/base.rb +19 -0
  9. data/lib/bullet/detector/counter.rb +43 -0
  10. data/lib/bullet/detector/n_plus_one_query.rb +39 -0
  11. data/lib/bullet/detector/unused_eager_association.rb +39 -0
  12. data/lib/bullet/detector.rb +9 -0
  13. data/lib/bullet/notification/base.rb +57 -0
  14. data/lib/bullet/notification/counter_cache.rb +13 -0
  15. data/lib/bullet/notification/n_plus_one_query.rb +32 -0
  16. data/lib/bullet/notification/unused_eager_loading.rb +14 -0
  17. data/lib/bullet/notification.rb +4 -79
  18. data/lib/bullet/notification_collector.rb +25 -0
  19. data/lib/bullet/rack.rb +44 -0
  20. data/lib/bullet/registry/association.rb +16 -0
  21. data/lib/bullet/registry/base.rb +39 -0
  22. data/lib/bullet/registry/object.rb +15 -0
  23. data/lib/bullet/registry.rb +7 -0
  24. data/lib/bullet/version.rb +5 -0
  25. data/lib/bullet.rb +63 -42
  26. metadata +60 -42
  27. data/Rakefile +0 -34
  28. data/VERSION +0 -1
  29. data/bullet.gemspec +0 -67
  30. data/lib/bullet/association.rb +0 -294
  31. data/lib/bullet/counter.rb +0 -101
  32. data/lib/bullet/logger.rb +0 -9
  33. data/lib/bulletware.rb +0 -42
  34. data/rails/init.rb +0 -1
  35. data/spec/bullet/association_for_chris_spec.rb +0 -96
  36. data/spec/bullet/association_for_peschkaj_spec.rb +0 -86
  37. data/spec/bullet/association_spec.rb +0 -1043
  38. data/spec/bullet/counter_spec.rb +0 -136
  39. data/spec/spec.opts +0 -3
  40. data/spec/spec_helper.rb +0 -45
  41. data/tasks/bullet_tasks.rake +0 -9
@@ -1,136 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
4
-
5
- describe Bullet::Counter do
6
- def setup_db
7
- ActiveRecord::Schema.define(:version => 1) do
8
- create_table :countries do |t|
9
- t.string :name
10
- end
11
-
12
- create_table :cities do |t|
13
- t.string :name
14
- t.integer :country_id
15
- end
16
- end
17
- end
18
-
19
- def teardown_db
20
- ActiveRecord::Base.connection.tables.each do |table|
21
- ActiveRecord::Base.connection.drop_table(table)
22
- end
23
- end
24
-
25
- class Country < ActiveRecord::Base
26
- has_many :cities
27
- end
28
-
29
- class City < ActiveRecord::Base
30
- belongs_to :country
31
- end
32
-
33
- before(:all) do
34
- setup_db
35
-
36
- country1 = Country.create(:name => 'first')
37
- country2 = Country.create(:name => 'second')
38
-
39
- country1.cities.create(:name => 'first')
40
- country1.cities.create(:name => 'second')
41
- country2.cities.create(:name => 'third')
42
- country2.cities.create(:name => 'fourth')
43
- end
44
-
45
- after(:all) do
46
- teardown_db
47
- end
48
-
49
- before(:each) do
50
- Bullet::Counter.start_request
51
- end
52
-
53
- after(:each) do
54
- Bullet::Counter.end_request
55
- end
56
-
57
- it "should need counter cache with all cities" do
58
- Country.all.each do |country|
59
- country.cities.size
60
- end
61
- Bullet::Counter.should be_need_counter_caches
62
- end
63
-
64
- it "should not need coounter cache with only one object" do
65
- Country.first.cities.size
66
- Bullet::Counter.should_not be_need_counter_caches
67
- end
68
-
69
- it "should not need counter cache with part of cities" do
70
- Country.all.each do |country|
71
- country.cities.where(:name => 'first').size
72
- end
73
- Bullet::Counter.should_not be_need_counter_caches
74
- end
75
- end
76
-
77
- describe Bullet::Counter do
78
- def setup_db
79
- ActiveRecord::Schema.define(:version => 1) do
80
- create_table :people do |t|
81
- t.string :name
82
- t.integer :pets_count
83
- end
84
-
85
- create_table :pets do |t|
86
- t.string :name
87
- t.integer :person_id
88
- end
89
- end
90
- end
91
-
92
- def teardown_db
93
- ActiveRecord::Base.connection.tables.each do |table|
94
- ActiveRecord::Base.connection.drop_table(table)
95
- end
96
- end
97
-
98
- class Person < ActiveRecord::Base
99
- has_many :pets
100
- end
101
-
102
- class Pet < ActiveRecord::Base
103
- belongs_to :person, :counter_cache => true
104
- end
105
-
106
- before(:all) do
107
- setup_db
108
-
109
- person1 = Person.create(:name => 'first')
110
- person2 = Person.create(:name => 'second')
111
-
112
- person1.pets.create(:name => 'first')
113
- person1.pets.create(:name => 'second')
114
- person2.pets.create(:name => 'third')
115
- person2.pets.create(:name => 'fourth')
116
- end
117
-
118
- after(:all) do
119
- teardown_db
120
- end
121
-
122
- before(:each) do
123
- Bullet::Counter.start_request
124
- end
125
-
126
- after(:each) do
127
- Bullet::Counter.end_request
128
- end
129
-
130
- it "should not need counter cache" do
131
- Person.all.each do |person|
132
- person.pets.size
133
- end
134
- Bullet::Counter.should_not be_need_counter_caches
135
- end
136
- end
data/spec/spec.opts DELETED
@@ -1,3 +0,0 @@
1
- --colour
2
- --format
3
- specdoc
data/spec/spec_helper.rb DELETED
@@ -1,45 +0,0 @@
1
- require 'rubygems'
2
- require 'rspec'
3
- require 'rspec/autorun'
4
- require 'rails'
5
- require 'active_record'
6
- require 'action_controller'
7
-
8
- module Rails
9
- class <<self
10
- def root
11
- File.expand_path(__FILE__).split('/')[0..-3].join('/')
12
- end
13
- end
14
- end
15
-
16
- $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
17
- require 'bullet'
18
- Bullet.enable = true
19
- ActiveRecord::Migration.verbose = false
20
-
21
- module Bullet
22
- class Association
23
- class <<self
24
- # returns true if all associations are preloaded
25
- def completely_preloading_associations?
26
- !has_unpreload_associations?
27
- end
28
-
29
- # returns true if a given object has a specific association
30
- def creating_object_association_for?(object, association)
31
- object_associations[object].present? && object_associations[object].include?(association)
32
- end
33
-
34
- # returns true if a given class includes the specific unpreloaded association
35
- def detecting_unpreloaded_association_for?(klazz, association)
36
- unpreload_associations[klazz].present? && unpreload_associations[klazz].include?(association)
37
- end
38
-
39
- # returns true if the given class includes the specific unused preloaded association
40
- def unused_preload_associations_for?(klazz, association)
41
- unused_preload_associations[klazz].present? && unused_preload_associations[klazz].include?(association)
42
- end
43
- end
44
- end
45
- end
@@ -1,9 +0,0 @@
1
- namespace :bullet do
2
- namespace :log do
3
- desc "Truncates the bullet log file to zero bytes"
4
- task :clear do
5
- f = File.open("log/bullet.log", "w")
6
- f.close
7
- end
8
- end
9
- end