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.
- data/MIT-LICENSE +1 -1
- data/README.textile +38 -8
- data/README_for_rails2.textile +19 -3
- data/lib/bullet/action_controller2.rb +4 -4
- data/lib/bullet/active_record2.rb +16 -16
- data/lib/bullet/active_record3.rb +16 -25
- data/lib/bullet/detector/association.rb +135 -0
- data/lib/bullet/detector/base.rb +19 -0
- data/lib/bullet/detector/counter.rb +43 -0
- data/lib/bullet/detector/n_plus_one_query.rb +39 -0
- data/lib/bullet/detector/unused_eager_association.rb +39 -0
- data/lib/bullet/detector.rb +9 -0
- data/lib/bullet/notification/base.rb +57 -0
- data/lib/bullet/notification/counter_cache.rb +13 -0
- data/lib/bullet/notification/n_plus_one_query.rb +32 -0
- data/lib/bullet/notification/unused_eager_loading.rb +14 -0
- data/lib/bullet/notification.rb +4 -79
- data/lib/bullet/notification_collector.rb +25 -0
- data/lib/bullet/rack.rb +44 -0
- data/lib/bullet/registry/association.rb +16 -0
- data/lib/bullet/registry/base.rb +39 -0
- data/lib/bullet/registry/object.rb +15 -0
- data/lib/bullet/registry.rb +7 -0
- data/lib/bullet/version.rb +5 -0
- data/lib/bullet.rb +63 -42
- metadata +60 -42
- data/Rakefile +0 -34
- data/VERSION +0 -1
- data/bullet.gemspec +0 -67
- data/lib/bullet/association.rb +0 -294
- data/lib/bullet/counter.rb +0 -101
- data/lib/bullet/logger.rb +0 -9
- data/lib/bulletware.rb +0 -42
- data/rails/init.rb +0 -1
- data/spec/bullet/association_for_chris_spec.rb +0 -96
- data/spec/bullet/association_for_peschkaj_spec.rb +0 -86
- data/spec/bullet/association_spec.rb +0 -1043
- data/spec/bullet/counter_spec.rb +0 -136
- data/spec/spec.opts +0 -3
- data/spec/spec_helper.rb +0 -45
- 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
|