ibm_db 0.9.5 → 0.10.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.
Files changed (44) hide show
  1. data/CHANGES +5 -0
  2. data/README +63 -97
  3. data/ext/ibm_db.c +20 -4
  4. data/ext/ruby_ibm_db.h +10 -0
  5. data/lib/active_record/connection_adapters/ibm_db_adapter.rb +2 -4
  6. data/test/{adapter_test.rb → cases/adapter_test.rb} +39 -14
  7. data/test/cases/associations/cascaded_eager_loading_test.rb +113 -0
  8. data/test/{associations → cases/associations}/eager_test.rb +231 -65
  9. data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +686 -0
  10. data/test/cases/associations/join_model_test.rb +797 -0
  11. data/test/{base_test.rb → cases/base_test.rb} +605 -385
  12. data/test/cases/calculations_test.rb +275 -0
  13. data/test/cases/finder_test.rb +885 -0
  14. data/test/cases/fixtures_test.rb +630 -0
  15. data/test/{migration_test.rb → cases/migration_test.rb} +530 -146
  16. data/test/cases/query_cache_test.rb +127 -0
  17. data/test/cases/validations_test.rb +1509 -0
  18. data/test/connections/native_ibm_db/connection.rb +1 -1
  19. data/test/models/warehouse_thing.rb +5 -0
  20. data/test/schema/i5/ibm_db_specific_schema.rb +133 -0
  21. data/test/schema/ids/ibm_db_specific_schema.rb +136 -0
  22. data/test/schema/luw/ibm_db_specific_schema.rb +133 -0
  23. data/test/schema/schema.rb +432 -0
  24. data/test/schema/zOS/ibm_db_specific_schema.rb +204 -0
  25. metadata +29 -33
  26. data/test/associations_test.rb +0 -2151
  27. data/test/fixtures/db_definitions/i5/ibm_db.drop.sql +0 -33
  28. data/test/fixtures/db_definitions/i5/ibm_db.sql +0 -236
  29. data/test/fixtures/db_definitions/i5/ibm_db2.drop.sql +0 -2
  30. data/test/fixtures/db_definitions/i5/ibm_db2.sql +0 -5
  31. data/test/fixtures/db_definitions/ids/ibm_db.drop.sql +0 -33
  32. data/test/fixtures/db_definitions/ids/ibm_db.sql +0 -237
  33. data/test/fixtures/db_definitions/ids/ibm_db2.drop.sql +0 -2
  34. data/test/fixtures/db_definitions/ids/ibm_db2.sql +0 -5
  35. data/test/fixtures/db_definitions/luw/ibm_db.drop.sql +0 -33
  36. data/test/fixtures/db_definitions/luw/ibm_db.sql +0 -236
  37. data/test/fixtures/db_definitions/luw/ibm_db2.drop.sql +0 -2
  38. data/test/fixtures/db_definitions/luw/ibm_db2.sql +0 -5
  39. data/test/fixtures/db_definitions/schema.rb +0 -361
  40. data/test/fixtures/db_definitions/zOS/ibm_db.drop.sql +0 -33
  41. data/test/fixtures/db_definitions/zOS/ibm_db.sql +0 -288
  42. data/test/fixtures/db_definitions/zOS/ibm_db2.drop.sql +0 -2
  43. data/test/fixtures/db_definitions/zOS/ibm_db2.sql +0 -7
  44. data/test/locking_test.rb +0 -282
@@ -1,15 +1,24 @@
1
- require 'abstract_unit'
2
- require 'fixtures/post'
3
- require 'fixtures/comment'
4
- require 'fixtures/author'
5
- require 'fixtures/category'
6
- require 'fixtures/company'
7
- require 'fixtures/person'
8
- require 'fixtures/reader'
9
-
10
- class EagerAssociationTest < Test::Unit::TestCase
1
+ require "cases/helper"
2
+ require 'models/post'
3
+ require 'models/tagging'
4
+ require 'models/comment'
5
+ require 'models/author'
6
+ require 'models/category'
7
+ require 'models/company'
8
+ require 'models/person'
9
+ require 'models/reader'
10
+ require 'models/owner'
11
+ require 'models/pet'
12
+ require 'models/reference'
13
+ require 'models/job'
14
+ require 'models/subscriber'
15
+ require 'models/subscription'
16
+ require 'models/book'
17
+
18
+ class EagerAssociationTest < ActiveRecord::TestCase
11
19
  fixtures :posts, :comments, :authors, :categories, :categories_posts,
12
- :companies, :accounts, :tags, :people, :readers
20
+ :companies, :accounts, :tags, :taggings, :people, :readers,
21
+ :owners, :pets, :author_favorites, :jobs, :references, :subscribers, :subscriptions, :books
13
22
 
14
23
  def test_loading_with_one_association
15
24
  posts = Post.find(:all, :include => :comments)
@@ -20,6 +29,10 @@ class EagerAssociationTest < Test::Unit::TestCase
20
29
  post = Post.find(:first, :include => :comments, :conditions => "posts.title = 'Welcome to the weblog'")
21
30
  assert_equal 2, post.comments.size
22
31
  assert post.comments.include?(comments(:greetings))
32
+
33
+ posts = Post.find(:all, :include => :last_comment)
34
+ post = posts.find { |p| p.id == 1 }
35
+ assert_equal Post.find(1).last_comment, post.last_comment
23
36
  end
24
37
 
25
38
  def test_loading_conditions_with_or
@@ -56,6 +69,39 @@ class EagerAssociationTest < Test::Unit::TestCase
56
69
  assert posts.first.comments.include?(comments(:greetings))
57
70
  end
58
71
 
72
+ def test_duplicate_middle_objects
73
+ comments = Comment.find :all, :conditions => 'post_id = 1', :include => [:post => :author]
74
+ assert_no_queries do
75
+ comments.each {|comment| comment.post.author.name}
76
+ end
77
+ end
78
+
79
+ def test_including_duplicate_objects_from_belongs_to
80
+ popular_post = Post.create!(:title => 'foo', :body => "I like cars!")
81
+ comment = popular_post.comments.create!(:body => "lol")
82
+ popular_post.readers.create!(:person => people(:michael))
83
+ popular_post.readers.create!(:person => people(:david))
84
+
85
+ readers = Reader.find(:all, :conditions => ["post_id = ?", popular_post.id],
86
+ :include => {:post => :comments})
87
+ readers.each do |reader|
88
+ assert_equal [comment], reader.post.comments
89
+ end
90
+ end
91
+
92
+ def test_including_duplicate_objects_from_has_many
93
+ car_post = Post.create!(:title => 'foo', :body => "I like cars!")
94
+ car_post.categories << categories(:general)
95
+ car_post.categories << categories(:technology)
96
+
97
+ comment = car_post.comments.create!(:body => "hmm")
98
+ categories = Category.find(:all, :conditions => ["posts.id=?", car_post.id],
99
+ :include => {:posts => :comments})
100
+ categories.each do |category|
101
+ assert_equal [comment], category.posts[0].comments
102
+ end
103
+ end
104
+
59
105
  def test_loading_from_an_association
60
106
  posts = authors(:david).posts.find(:all, :include => :comments, :order => "posts.id")
61
107
  assert_equal 2, posts.first.comments.size
@@ -65,6 +111,17 @@ class EagerAssociationTest < Test::Unit::TestCase
65
111
  assert_nil Post.find(posts(:authorless).id, :include => :author).author
66
112
  end
67
113
 
114
+ def test_nested_loading_with_no_associations
115
+ assert_nothing_raised do
116
+ Post.find(posts(:authorless).id, :include => {:author => :author_addresss})
117
+ end
118
+ end
119
+
120
+ def test_eager_association_loading_with_belongs_to_and_foreign_keys
121
+ pets = Pet.find(:all, :include => :owner)
122
+ assert_equal 3, pets.length
123
+ end
124
+
68
125
  def test_eager_association_loading_with_belongs_to
69
126
  comments = Comment.find(:all, :include => :post)
70
127
  assert_equal 10, comments.length
@@ -72,7 +129,7 @@ class EagerAssociationTest < Test::Unit::TestCase
72
129
  assert titles.include?(posts(:welcome).title)
73
130
  assert titles.include?(posts(:sti_post_and_comments).title)
74
131
  end
75
-
132
+
76
133
  def test_eager_association_loading_with_belongs_to_and_limit
77
134
  comments = Comment.find(:all, :include => :post, :limit => 5, :order => 'comments.id')
78
135
  assert_equal 5, comments.length
@@ -96,33 +153,105 @@ class EagerAssociationTest < Test::Unit::TestCase
96
153
  assert_equal 3, comments.length
97
154
  assert_equal [6,7,8], comments.collect { |c| c.id }
98
155
  end
99
-
156
+
100
157
  def test_eager_association_loading_with_belongs_to_and_limit_and_offset_and_conditions_array
101
158
  comments = Comment.find(:all, :include => :post, :conditions => ['post_id = ?',4], :limit => 3, :offset => 1, :order => 'comments.id')
102
159
  assert_equal 3, comments.length
103
160
  assert_equal [6,7,8], comments.collect { |c| c.id }
104
161
  end
105
162
 
163
+ def test_eager_association_loading_with_belongs_to_and_conditions_string_with_unquoted_table_name
164
+ assert_nothing_raised do
165
+ Comment.find(:all, :include => :post, :conditions => ['posts.id = ?',4])
166
+ end
167
+ end
168
+
169
+ def test_eager_association_loading_with_belongs_to_and_conditions_string_with_quoted_table_name
170
+ quoted_posts_id= Comment.connection.quote_table_name('posts') + '.' + Comment.connection.quote_column_name('id')
171
+ assert_nothing_raised do
172
+ Comment.find(:all, :include => :post, :conditions => ["#{quoted_posts_id} = ?",4])
173
+ end
174
+ end
175
+
176
+ def test_eager_association_loading_with_belongs_to_and_order_string_with_unquoted_table_name
177
+ assert_nothing_raised do
178
+ Comment.find(:all, :include => :post, :order => 'posts.id')
179
+ end
180
+ end
181
+
182
+ def test_eager_association_loading_with_belongs_to_and_order_string_with_quoted_table_name
183
+ quoted_posts_id= Comment.connection.quote_table_name('posts') + '.' + Comment.connection.quote_column_name('id')
184
+ assert_nothing_raised do
185
+ Comment.find(:all, :include => :post, :order => quoted_posts_id)
186
+ end
187
+ end
188
+
106
189
  def test_eager_association_loading_with_belongs_to_and_limit_and_multiple_associations
107
190
  posts = Post.find(:all, :include => [:author, :very_special_comment], :limit => 1, :order => 'posts.id')
108
191
  assert_equal 1, posts.length
109
192
  assert_equal [1], posts.collect { |p| p.id }
110
193
  end
111
-
194
+
112
195
  def test_eager_association_loading_with_belongs_to_and_limit_and_offset_and_multiple_associations
113
196
  posts = Post.find(:all, :include => [:author, :very_special_comment], :limit => 1, :offset => 1, :order => 'posts.id')
114
197
  assert_equal 1, posts.length
115
198
  assert_equal [2], posts.collect { |p| p.id }
116
199
  end
117
-
118
- def test_eager_association_loading_with_explicit_join
119
- unless current_adapter?(:IBM_DBAdapter)#throws an error with sqlcode=-214,DISTINCT keyword in the select query not allowed
120
200
 
121
- posts = Post.find(:all, :include => :comments, :joins => "INNER JOIN authors ON posts.author_id = authors.id AND authors.name = 'Mary'", :limit => 1, :order => 'author_id')
122
- assert_equal 1, posts.length
123
- end
201
+ def test_eager_association_loading_with_belongs_to_inferred_foreign_key_from_association_name
202
+ author_favorite = AuthorFavorite.find(:first, :include => :favorite_author)
203
+ assert_equal authors(:mary), assert_no_queries { author_favorite.favorite_author }
204
+ end
205
+
206
+ def test_eager_load_belongs_to_quotes_table_and_column_names
207
+ job = Job.find jobs(:unicyclist).id, :include => :ideal_reference
208
+ references(:michael_unicyclist)
209
+ assert_no_queries{ assert_equal references(:michael_unicyclist), job.ideal_reference}
210
+ end
211
+
212
+ def test_eager_load_has_one_quotes_table_and_column_names
213
+ michael = Person.find(people(:michael), :include => :favourite_reference)
214
+ references(:michael_unicyclist)
215
+ assert_no_queries{ assert_equal references(:michael_unicyclist), michael.favourite_reference}
216
+ end
217
+
218
+ def test_eager_load_has_many_quotes_table_and_column_names
219
+ michael = Person.find(people(:michael), :include => :references)
220
+ references(:michael_magician,:michael_unicyclist)
221
+ assert_no_queries{ assert_equal references(:michael_magician,:michael_unicyclist), michael.references.sort_by(&:id) }
222
+ end
223
+
224
+ def test_eager_load_has_many_through_quotes_table_and_column_names
225
+ michael = Person.find(people(:michael), :include => :jobs)
226
+ jobs(:magician, :unicyclist)
227
+ assert_no_queries{ assert_equal jobs(:unicyclist, :magician), michael.jobs.sort_by(&:id) }
228
+ end
229
+
230
+ def test_eager_load_has_many_with_string_keys
231
+ subscriptions = subscriptions(:webster_awdr, :webster_rfr)
232
+ subscriber =Subscriber.find(subscribers(:second).id, :include => :subscriptions)
233
+ assert_equal subscriptions, subscriber.subscriptions.sort_by(&:id)
234
+ end
235
+
236
+ def test_eager_load_has_many_through_with_string_keys
237
+ books = books(:awdr, :rfr)
238
+ subscriber = Subscriber.find(subscribers(:second).id, :include => :books)
239
+ assert_equal books, subscriber.books.sort_by(&:id)
124
240
  end
125
241
 
242
+ def test_eager_load_belongs_to_with_string_keys
243
+ subscriber = subscribers(:second)
244
+ subscription = Subscription.find(subscriptions(:webster_awdr).id, :include => :subscriber)
245
+ assert_equal subscriber, subscription.subscriber
246
+ end
247
+
248
+ unless current_adapter?(:IBM_DBAdapter)
249
+ def test_eager_association_loading_with_explicit_join
250
+ posts = Post.find(:all, :include => :comments, :joins => "INNER JOIN authors ON posts.author_id = authors.id AND authors.name = 'Mary'", :limit => 1, :order => 'author_id')
251
+ assert_equal 1, posts.length
252
+ end
253
+ end
254
+
126
255
  def test_eager_with_has_many_through
127
256
  posts_with_comments = people(:michael).posts.find(:all, :include => :comments)
128
257
  posts_with_author = people(:michael).posts.find(:all, :include => :author )
@@ -136,7 +265,7 @@ class EagerAssociationTest < Test::Unit::TestCase
136
265
  author = Author.find(:first, :include => :special_post_comments, :order => 'authors.id')
137
266
  assert_equal [comments(:does_it_hurt)], assert_no_queries { author.special_post_comments }
138
267
  end
139
-
268
+
140
269
  def test_eager_with_has_many_through_an_sti_join_model_with_conditions_on_both
141
270
  author = Author.find(:first, :include => :special_nonexistant_post_comments, :order => 'authors.id')
142
271
  assert_equal [], author.special_nonexistant_post_comments
@@ -148,6 +277,17 @@ class EagerAssociationTest < Test::Unit::TestCase
148
277
  Author.find(:first, :order => 'authors.id').hello_post_comments.sort_by(&:id)
149
278
  end
150
279
 
280
+ def test_eager_with_has_many_through_join_model_with_conditions_on_top_level
281
+ assert_equal comments(:more_greetings), Author.find(authors(:david).id, :include => :comments_with_order_and_conditions).comments_with_order_and_conditions.first
282
+ end
283
+
284
+ def test_eager_with_has_many_through_join_model_with_include
285
+ author_comments = Author.find(authors(:david).id, :include => :comments_with_include).comments_with_include.to_a
286
+ assert_no_queries do
287
+ author_comments.first.post.title
288
+ end
289
+ end
290
+
151
291
  def test_eager_with_has_many_and_limit
152
292
  posts = Post.find(:all, :order => 'posts.id asc', :include => [ :author, :comments ], :limit => 2)
153
293
  assert_equal 2, posts.size
@@ -171,13 +311,13 @@ class EagerAssociationTest < Test::Unit::TestCase
171
311
  posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => [ "posts.body = ?", 'hello' ], :order => "posts.id")
172
312
  end
173
313
  assert_equal 2, posts.size
174
- assert_equal [4,5], posts.collect { |p| p.id }
314
+ assert_equal [4,5], posts.collect { |p| p.id }
175
315
  end
176
316
 
177
317
  def test_eager_with_has_many_and_limit_and_conditions_array_on_the_eagers
178
318
  posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => [ "authors.name = ?", 'David' ])
179
319
  assert_equal 2, posts.size
180
-
320
+
181
321
  count = Post.count(:include => [ :author, :comments ], :limit => 2, :conditions => [ "authors.name = ?", 'David' ])
182
322
  assert_equal count, posts.size
183
323
  end
@@ -196,12 +336,18 @@ class EagerAssociationTest < Test::Unit::TestCase
196
336
  posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => "posts.title = 'magic forest'")
197
337
  assert_equal 0, posts.size
198
338
  end
199
-
339
+
200
340
  def test_eager_count_performed_on_a_has_many_association_with_multi_table_conditional
201
341
  author = authors(:david)
202
342
  author_posts_without_comments = author.posts.select { |post| post.comments.blank? }
203
343
  assert_equal author_posts_without_comments.size, author.posts.count(:all, :include => :comments, :conditions => 'comments.id is null')
204
344
  end
345
+
346
+ def test_eager_count_performed_on_a_has_many_through_association_with_multi_table_conditional
347
+ person = people(:michael)
348
+ person_posts_without_comments = person.posts.select { |post| post.comments.blank? }
349
+ assert_equal person_posts_without_comments.size, person.posts_with_no_comments.count
350
+ end
205
351
 
206
352
  def test_eager_with_has_and_belongs_to_many_and_limit
207
353
  posts = Post.find(:all, :include => :categories, :order => "posts.id", :limit => 3)
@@ -214,15 +360,15 @@ class EagerAssociationTest < Test::Unit::TestCase
214
360
  end
215
361
 
216
362
  def test_eager_with_has_many_and_limit_and_conditions_on_the_eagers
217
- posts = authors(:david).posts.find(:all,
218
- :include => :comments,
363
+ posts = authors(:david).posts.find(:all,
364
+ :include => :comments,
219
365
  :conditions => "comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment'",
220
366
  :limit => 2
221
367
  )
222
368
  assert_equal 2, posts.size
223
-
369
+
224
370
  count = Post.count(
225
- :include => [ :comments, :author ],
371
+ :include => [ :comments, :author ],
226
372
  :conditions => "authors.name = 'David' AND (comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment')",
227
373
  :limit => 2
228
374
  )
@@ -232,15 +378,15 @@ class EagerAssociationTest < Test::Unit::TestCase
232
378
  def test_eager_with_has_many_and_limit_and_scoped_conditions_on_the_eagers
233
379
  posts = nil
234
380
  Post.with_scope(:find => {
235
- :include => :comments,
381
+ :include => :comments,
236
382
  :conditions => "comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment'"
237
383
  }) do
238
384
  posts = authors(:david).posts.find(:all, :limit => 2)
239
385
  assert_equal 2, posts.size
240
386
  end
241
-
387
+
242
388
  Post.with_scope(:find => {
243
- :include => [ :comments, :author ],
389
+ :include => [ :comments, :author ],
244
390
  :conditions => "authors.name = 'David' AND (comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment')"
245
391
  }) do
246
392
  count = Post.count(:limit => 2)
@@ -250,15 +396,15 @@ class EagerAssociationTest < Test::Unit::TestCase
250
396
 
251
397
  def test_eager_with_has_many_and_limit_and_scoped_and_explicit_conditions_on_the_eagers
252
398
  Post.with_scope(:find => { :conditions => "1=1" }) do
253
- posts = authors(:david).posts.find(:all,
254
- :include => :comments,
399
+ posts = authors(:david).posts.find(:all,
400
+ :include => :comments,
255
401
  :conditions => "comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment'",
256
402
  :limit => 2
257
403
  )
258
404
  assert_equal 2, posts.size
259
-
405
+
260
406
  count = Post.count(
261
- :include => [ :comments, :author ],
407
+ :include => [ :comments, :author ],
262
408
  :conditions => "authors.name = 'David' AND (comments.body like 'Normal%' OR comments.#{QUOTED_TYPE}= 'SpecialComment')",
263
409
  :limit => 2
264
410
  )
@@ -314,7 +460,7 @@ class EagerAssociationTest < Test::Unit::TestCase
314
460
  assert_not_nil f.account
315
461
  assert_equal companies(:first_firm, :reload).account, f.account
316
462
  end
317
-
463
+
318
464
  def test_eager_with_multi_table_conditional_properly_counts_the_records_when_using_size
319
465
  author = authors(:david)
320
466
  posts_with_no_comments = author.posts.select { |post| post.comments.blank? }
@@ -336,24 +482,32 @@ class EagerAssociationTest < Test::Unit::TestCase
336
482
  post = Post.find(6, :include=>[ :monkeys, :elephants ])
337
483
  }
338
484
  end
339
-
485
+
340
486
  def find_all_ordered(className, include=nil)
341
487
  className.find(:all, :order=>"#{className.table_name}.#{className.primary_key}", :include=>include)
342
488
  end
343
-
344
- def test_limited_eager_with_order
345
- unless current_adapter?(:IBM_DBAdapter)#throws an error with sqlcode=-214,DISTINCT keyword in the select query not allowed.
346
- assert_equal posts(:thinking, :sti_comments), Post.find(:all, :include => [:author, :comments], :conditions => "authors.name = 'David'", :order => 'UPPER(posts.title)', :limit => 2, :offset => 1)
347
- assert_equal posts(:sti_post_and_comments, :sti_comments), Post.find(:all, :include => [:author, :comments], :conditions => "authors.name = 'David'", :order => 'UPPER(posts.title) DESC', :limit => 2, :offset => 1)
348
- end
489
+
490
+ unless current_adapter?(:IBM_DBAdapter)
491
+ def test_limited_eager_with_order
492
+ assert_equal posts(:thinking, :sti_comments), Post.find(:all, :include => [:author, :comments], :conditions => "authors.name = 'David'", :order => 'UPPER(posts.title)', :limit => 2, :offset => 1)
493
+ assert_equal posts(:sti_post_and_comments, :sti_comments), Post.find(:all, :include => [:author, :comments], :conditions => "authors.name = 'David'", :order => 'UPPER(posts.title) DESC', :limit => 2, :offset => 1)
494
+ end
495
+
496
+ def test_limited_eager_with_multiple_order_columns
497
+ assert_equal posts(:thinking, :sti_comments), Post.find(:all, :include => [:author, :comments], :conditions => "authors.name = 'David'", :order => 'UPPER(posts.title), posts.id', :limit => 2, :offset => 1)
498
+ assert_equal posts(:sti_post_and_comments, :sti_comments), Post.find(:all, :include => [:author, :comments], :conditions => "authors.name = 'David'", :order => 'UPPER(posts.title) DESC, posts.id', :limit => 2, :offset => 1)
499
+ end
349
500
  end
350
501
 
351
- def test_limited_eager_with_multiple_order_columns
352
- unless current_adapter?(:IBM_DBAdapter)#throws an error with sqlcode=-214,DISTINCT keyword in the select query not allowed
353
-
354
- assert_equal posts(:thinking, :sti_comments), Post.find(:all, :include => [:author, :comments], :conditions => "authors.name = 'David'", :order => 'UPPER(posts.title), posts.id', :limit => 2, :offset => 1)
355
- assert_equal posts(:sti_post_and_comments, :sti_comments), Post.find(:all, :include => [:author, :comments], :conditions => "authors.name = 'David'", :order => 'UPPER(posts.title) DESC, posts.id', :limit => 2, :offset => 1)
356
- end
502
+ def test_preload_with_interpolation
503
+ assert_equal [comments(:greetings)], Post.find(posts(:welcome).id, :include => :comments_with_interpolated_conditions).comments_with_interpolated_conditions
504
+ end
505
+
506
+ def test_polymorphic_type_condition
507
+ post = Post.find(posts(:thinking).id, :include => :taggings)
508
+ assert post.taggings.include?(taggings(:thinking_general))
509
+ post = SpecialPost.find(posts(:thinking).id, :include => :taggings)
510
+ assert post.taggings.include?(taggings(:thinking_general))
357
511
  end
358
512
 
359
513
  def test_eager_with_multiple_associations_with_same_table_has_many_and_habtm
@@ -369,8 +523,8 @@ class EagerAssociationTest < Test::Unit::TestCase
369
523
  [Author, Category].each do |className|
370
524
  d1 = find_all_ordered(className)
371
525
  # test including all post types at once
372
- d2 = find_all_ordered(className, post_types)
373
- d1.each_index do |i|
526
+ d2 = find_all_ordered(className, post_types)
527
+ d1.each_index do |i|
374
528
  assert_equal(d1[i], d2[i])
375
529
  assert_equal_after_sort(d1[i].posts, d2[i].posts)
376
530
  post_types[1..-1].each do |post_type|
@@ -383,21 +537,21 @@ class EagerAssociationTest < Test::Unit::TestCase
383
537
  end
384
538
  end
385
539
  end
386
-
540
+
387
541
  def test_eager_with_multiple_associations_with_same_table_has_one
388
542
  d1 = find_all_ordered(Firm)
389
543
  d2 = find_all_ordered(Firm, :account)
390
- d1.each_index do |i|
544
+ d1.each_index do |i|
391
545
  assert_equal(d1[i], d2[i])
392
546
  assert_equal(d1[i].account, d2[i].account)
393
547
  end
394
548
  end
395
-
549
+
396
550
  def test_eager_with_multiple_associations_with_same_table_belongs_to
397
551
  firm_types = [:firm, :firm_with_basic_id, :firm_with_other_name, :firm_with_condition]
398
552
  d1 = find_all_ordered(Client)
399
553
  d2 = find_all_ordered(Client, firm_types)
400
- d1.each_index do |i|
554
+ d1.each_index do |i|
401
555
  assert_equal(d1[i], d2[i])
402
556
  firm_types.each { |type| assert_equal(d1[i].send(type), d2[i].send(type)) }
403
557
  end
@@ -408,36 +562,42 @@ class EagerAssociationTest < Test::Unit::TestCase
408
562
 
409
563
  def test_preconfigured_includes_with_belongs_to
410
564
  author = posts(:welcome).author_with_posts
411
- assert_equal 5, author.posts.size
565
+ assert_no_queries {assert_equal 5, author.posts.size}
412
566
  end
413
567
 
414
568
  def test_preconfigured_includes_with_has_one
415
569
  comment = posts(:sti_comments).very_special_comment_with_post
416
- assert_equal posts(:sti_comments), comment.post
570
+ assert_no_queries {assert_equal posts(:sti_comments), comment.post}
417
571
  end
418
572
 
419
573
  def test_preconfigured_includes_with_has_many
420
574
  posts = authors(:david).posts_with_comments
421
575
  one = posts.detect { |p| p.id == 1 }
422
- assert_equal 5, posts.size
423
- assert_equal 2, one.comments.size
576
+ assert_no_queries do
577
+ assert_equal 5, posts.size
578
+ assert_equal 2, one.comments.size
579
+ end
424
580
  end
425
581
 
426
582
  def test_preconfigured_includes_with_habtm
427
583
  posts = authors(:david).posts_with_categories
428
584
  one = posts.detect { |p| p.id == 1 }
429
- assert_equal 5, posts.size
430
- assert_equal 2, one.categories.size
585
+ assert_no_queries do
586
+ assert_equal 5, posts.size
587
+ assert_equal 2, one.categories.size
588
+ end
431
589
  end
432
590
 
433
591
  def test_preconfigured_includes_with_has_many_and_habtm
434
592
  posts = authors(:david).posts_with_comments_and_categories
435
593
  one = posts.detect { |p| p.id == 1 }
436
- assert_equal 5, posts.size
437
- assert_equal 2, one.comments.size
438
- assert_equal 2, one.categories.size
594
+ assert_no_queries do
595
+ assert_equal 5, posts.size
596
+ assert_equal 2, one.comments.size
597
+ assert_equal 2, one.categories.size
598
+ end
439
599
  end
440
-
600
+
441
601
  def test_count_with_include
442
602
  if current_adapter?(:SQLServerAdapter, :SybaseAdapter)
443
603
  assert_equal 3, authors(:david).posts_with_comments.count(:conditions => "len(comments.body) > 15")
@@ -447,4 +607,10 @@ class EagerAssociationTest < Test::Unit::TestCase
447
607
  assert_equal 3, authors(:david).posts_with_comments.count(:conditions => "length(comments.body) > 15")
448
608
  end
449
609
  end
610
+
611
+ def test_load_with_sti_sharing_association
612
+ assert_queries(2) do #should not do 1 query per subclass
613
+ Comment.find :all, :include => :post
614
+ end
615
+ end
450
616
  end