bullet 2.3.0 → 4.0.0
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/.travis.yml +5 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +44 -33
- data/Gemfile.rails-2.3.14 +16 -0
- data/Gemfile.rails-2.3.14.lock +65 -0
- data/Gemfile.rails-3.0.12 +17 -0
- data/Gemfile.rails-3.0.12.lock +116 -0
- data/Gemfile.rails-3.1.4 +18 -0
- data/Gemfile.rails-3.1.4.lock +134 -0
- data/README.textile +6 -6
- data/lib/bullet/active_record2.rb +12 -0
- data/lib/bullet/active_record3.rb +12 -0
- data/lib/bullet/detector/association.rb +11 -12
- data/lib/bullet/detector/counter.rb +6 -6
- data/lib/bullet/detector/n_plus_one_query.rb +9 -9
- data/lib/bullet/detector/unused_eager_association.rb +9 -9
- data/lib/bullet/ext/object.rb +5 -0
- data/lib/bullet/ext/string.rb +5 -0
- data/lib/bullet/mongoid.rb +56 -0
- data/lib/bullet/registry/object.rb +4 -6
- data/lib/bullet/version.rb +1 -1
- data/lib/bullet.rb +15 -9
- data/spec/bullet/detector/association_spec.rb +20 -16
- data/spec/bullet/detector/counter_spec.rb +8 -9
- data/spec/bullet/detector/n_plus_one_query_spec.rb +22 -22
- data/spec/bullet/detector/unused_eager_association_spec.rb +11 -11
- data/spec/bullet/ext/object_spec.rb +20 -0
- data/spec/bullet/ext/string_spec.rb +13 -0
- data/spec/bullet/registry/object_spec.rb +4 -4
- data/spec/integration/association_spec.rb +463 -401
- data/spec/integration/counter_spec.rb +27 -25
- data/spec/integration/mongoid/association_spec.rb +276 -0
- data/spec/integration/rails2/association_spec.rb +593 -0
- data/spec/integration/rails2/counter_spec.rb +39 -0
- data/spec/models/mongoid/address.rb +5 -0
- data/spec/models/mongoid/category.rb +6 -0
- data/spec/models/mongoid/comment.rb +5 -0
- data/spec/models/mongoid/company.rb +5 -0
- data/spec/models/mongoid/entry.rb +5 -0
- data/spec/models/mongoid/post.rb +8 -0
- data/spec/models/post.rb +12 -6
- data/spec/spec_helper.rb +32 -8
- data/spec/support/bullet_ext.rb +1 -1
- data/spec/support/mongo_seed.rb +41 -0
- data/spec/support/{seed.rb → sqlite_seed.rb} +1 -22
- data/test.result +2293 -0
- metadata +42 -22
- data/spec/integration/association_for_chris_spec.rb +0 -37
- data/spec/integration/association_for_peschkaj_spec.rb +0 -26
- data/spec/models/contact.rb +0 -3
- data/spec/models/deal.rb +0 -4
- data/spec/models/email.rb +0 -3
- data/spec/models/hotel.rb +0 -4
- data/spec/models/location.rb +0 -3
data/spec/models/post.rb
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
class Post < ActiveRecord::Base
|
|
2
2
|
belongs_to :category
|
|
3
|
-
has_many :comments
|
|
4
3
|
belongs_to :writer
|
|
4
|
+
has_many :comments
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
if Rails.version.to_i == 2
|
|
7
|
+
named_scope :preload_comments, lambda { {:include => :comments} }
|
|
8
|
+
named_scope :in_category_name, lambda { |name|
|
|
9
|
+
{:conditions => ['categories.name = ?', name], :include => :category}
|
|
10
|
+
}
|
|
11
|
+
else
|
|
12
|
+
scope :preload_comments, lambda { includes(:comments) }
|
|
13
|
+
scope :in_category_name, lambda { |name|
|
|
14
|
+
where(['categories.name = ?', name]).includes(:category)
|
|
15
|
+
}
|
|
16
|
+
end
|
|
11
17
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
require 'rspec'
|
|
2
|
-
|
|
3
|
-
require 'rails'
|
|
2
|
+
begin
|
|
3
|
+
require 'rails'
|
|
4
|
+
rescue LoadError
|
|
5
|
+
# rails 2.3
|
|
6
|
+
require 'initializer'
|
|
7
|
+
end
|
|
4
8
|
require 'active_record'
|
|
5
9
|
require 'action_controller'
|
|
6
10
|
|
|
@@ -21,24 +25,44 @@ MODELS = File.join(File.dirname(__FILE__), "models")
|
|
|
21
25
|
$LOAD_PATH.unshift(MODELS)
|
|
22
26
|
|
|
23
27
|
# Autoload every model for the test suite that sits in spec/models.
|
|
24
|
-
Dir[ File.join(MODELS, "*.rb") ].sort.each do |
|
|
25
|
-
name = File.basename(
|
|
28
|
+
Dir[ File.join(MODELS, "*.rb") ].sort.each do |filename|
|
|
29
|
+
name = File.basename(filename, ".rb")
|
|
26
30
|
autoload name.camelize.to_sym, name
|
|
27
31
|
end
|
|
28
32
|
|
|
29
33
|
SUPPORT = File.join(File.dirname(__FILE__), "support")
|
|
30
|
-
Dir[ File.join(SUPPORT, "*.rb") ].sort.each { |file| require file }
|
|
34
|
+
Dir[ File.join(SUPPORT, "*.rb") ].reject { |filename| filename =~ /mongo_seed.rb$/ }.sort.each { |file| require file }
|
|
31
35
|
|
|
32
36
|
RSpec.configure do |config|
|
|
33
37
|
config.before(:suite) do
|
|
34
|
-
Support::
|
|
35
|
-
Support::
|
|
38
|
+
Support::SqliteSeed.setup_db
|
|
39
|
+
Support::SqliteSeed.seed_db
|
|
36
40
|
end
|
|
37
41
|
|
|
38
42
|
config.after(:suite) do
|
|
39
|
-
Support::
|
|
43
|
+
Support::SqliteSeed.teardown_db
|
|
40
44
|
end
|
|
41
45
|
|
|
42
46
|
config.filter_run :focus => true
|
|
43
47
|
config.run_all_when_everything_filtered = true
|
|
44
48
|
end
|
|
49
|
+
|
|
50
|
+
begin
|
|
51
|
+
require 'mongoid'
|
|
52
|
+
|
|
53
|
+
# Autoload every model for the test suite that sits in spec/models.
|
|
54
|
+
Dir[ File.join(MODELS, "mongoid", "*.rb") ].sort.each { |file| require file }
|
|
55
|
+
require File.join(SUPPORT, "mongo_seed.rb")
|
|
56
|
+
|
|
57
|
+
RSpec.configure do |config|
|
|
58
|
+
config.before(:suite) do
|
|
59
|
+
Support::MongoSeed.setup_db
|
|
60
|
+
Support::MongoSeed.seed_db
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
config.after(:suite) do
|
|
64
|
+
Support::MongoSeed.teardown_db
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
rescue LoadError
|
|
68
|
+
end
|
data/spec/support/bullet_ext.rb
CHANGED
|
@@ -33,7 +33,7 @@ module Bullet
|
|
|
33
33
|
|
|
34
34
|
# returns true if a given object has a specific association
|
|
35
35
|
def creating_object_association_for?(object, association)
|
|
36
|
-
object_associations[object.
|
|
36
|
+
object_associations[object.bullet_ar_key].present? && object_associations[object.bullet_ar_key].include?(association)
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
# returns true if a given class includes the specific unpreloaded association
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module Support
|
|
2
|
+
module MongoSeed
|
|
3
|
+
def seed_db
|
|
4
|
+
category1 = Mongoid::Category.create(:name => 'first')
|
|
5
|
+
category2 = Mongoid::Category.create(:name => 'second')
|
|
6
|
+
|
|
7
|
+
post1 = category1.posts.create(:name => 'first')
|
|
8
|
+
post1a = category1.posts.create(:name => 'like first')
|
|
9
|
+
post2 = category2.posts.create(:name => 'second')
|
|
10
|
+
|
|
11
|
+
comment1 = post1.comments.create(:name => 'first')
|
|
12
|
+
comment2 = post1.comments.create(:name => 'first2')
|
|
13
|
+
comment3 = post1.comments.create(:name => 'first3')
|
|
14
|
+
comment4 = post1.comments.create(:name => 'second')
|
|
15
|
+
comment8 = post1a.comments.create(:name => "like first 1")
|
|
16
|
+
comment9 = post1a.comments.create(:name => "like first 2")
|
|
17
|
+
comment5 = post2.comments.create(:name => 'third')
|
|
18
|
+
comment6 = post2.comments.create(:name => 'fourth')
|
|
19
|
+
comment7 = post2.comments.create(:name => 'fourth')
|
|
20
|
+
|
|
21
|
+
entry1 = category1.entries.create(:name => 'first')
|
|
22
|
+
entry2 = category1.entries.create(:name => 'second')
|
|
23
|
+
|
|
24
|
+
company1 = Mongoid::Company.create(:name => 'first')
|
|
25
|
+
company2 = Mongoid::Company.create(:name => 'second')
|
|
26
|
+
|
|
27
|
+
Mongoid::Address.create(:name => 'first', :company => company1)
|
|
28
|
+
Mongoid::Address.create(:name => 'second', :company => company2)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def setup_db
|
|
32
|
+
Mongoid.database = Mongo::Connection.new("localhost", 27017).db("bullet")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def teardown_db
|
|
36
|
+
Mongoid.database.collections.select {|c| c.name !~ /system/ }.map(&:drop)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
extend self
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module Support
|
|
2
|
-
module
|
|
2
|
+
module SqliteSeed
|
|
3
3
|
def seed_db
|
|
4
4
|
newspaper1 = Newspaper.create(:name => "First Newspaper")
|
|
5
5
|
newspaper2 = Newspaper.create(:name => "Second Newspaper")
|
|
@@ -54,14 +54,6 @@ module Support
|
|
|
54
54
|
Address.create(:name => 'first', :company => company1)
|
|
55
55
|
Address.create(:name => 'second', :company => company2)
|
|
56
56
|
|
|
57
|
-
contact1 = Contact.create(:name => 'first')
|
|
58
|
-
contact2 = Contact.create(:name => 'second')
|
|
59
|
-
|
|
60
|
-
email1 = contact1.emails.create(:name => 'first')
|
|
61
|
-
email2 = contact1.emails.create(:name => 'second')
|
|
62
|
-
email3 = contact2.emails.create(:name => 'third')
|
|
63
|
-
email4 = contact2.emails.create(:name => 'fourth')
|
|
64
|
-
|
|
65
57
|
country1 = Country.create(:name => 'first')
|
|
66
58
|
country2 = Country.create(:name => 'second')
|
|
67
59
|
|
|
@@ -94,19 +86,6 @@ module Support
|
|
|
94
86
|
submission2 = category1.submissions.create(:name => "submission2", :user => user2)
|
|
95
87
|
submission3 = category2.submissions.create(:name => "submission3", :user => user1)
|
|
96
88
|
submission4 = category2.submissions.create(:name => "submission4", :user => user2)
|
|
97
|
-
|
|
98
|
-
location1 = Location.create(:name => "location1")
|
|
99
|
-
location2 = Location.create(:name => "location2")
|
|
100
|
-
|
|
101
|
-
hotel1 = location1.hotels.create(:name => "hotel1")
|
|
102
|
-
hotel2 = location1.hotels.create(:name => "hotel2")
|
|
103
|
-
hotel3 = location2.hotels.create(:name => "hotel3")
|
|
104
|
-
hotel4 = location2.hotels.create(:name => "hotel4")
|
|
105
|
-
|
|
106
|
-
deal1 = hotel1.deals.create(:name => "deal1")
|
|
107
|
-
deal2 = hotel2.deals.create(:name => "deal2")
|
|
108
|
-
deal3 = hotel3.deals.create(:name => "deal3")
|
|
109
|
-
deal4 = hotel4.deals.create(:name => "deal4")
|
|
110
89
|
end
|
|
111
90
|
|
|
112
91
|
def setup_db
|