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,86 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
4
- # This test is just used for http://github.com/flyerhzm/bullet/issues#issue/20
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
13
-
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
19
-
20
- create_table :users do |t|
21
- t.column :name, :string
22
- t.column :category_id, :integer
23
- end
24
- end
25
- end
26
-
27
- def teardown_db
28
- ActiveRecord::Base.connection.tables.each do |table|
29
- ActiveRecord::Base.connection.drop_table(table)
30
- end
31
- end
32
-
33
- class Category < ActiveRecord::Base
34
- has_many :submissions
35
- has_many :users
36
- end
37
-
38
- class Submission < ActiveRecord::Base
39
- belongs_to :category
40
- belongs_to :user
41
- end
42
-
43
- class User < ActiveRecord::Base
44
- has_one :submission
45
- belongs_to :category
46
- end
47
-
48
- before(:all) do
49
- setup_db
50
-
51
- category1 = Category.create(:name => "category1")
52
- category2 = Category.create(:name => "category2")
53
-
54
- user1 = User.create(:name => 'user1', :category => category1)
55
- user2 = User.create(:name => 'user2', :category => category1)
56
-
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
62
-
63
- after(:all) do
64
- teardown_db
65
- end
66
-
67
- before(:each) do
68
- Bullet::Association.start_request
69
- end
70
-
71
- after(:each) do
72
- Bullet::Association.end_request
73
- end
74
-
75
- it "should not detect unused preload associations" do
76
- category = Category.includes({:submissions => :user}).order("id DESC").find_by_name('category1')
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)
84
- end
85
- end
86
- end