ibm_db 2.5.5 → 2.5.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,61 +11,73 @@ require 'models/author'
11
11
  require 'models/owner'
12
12
  require 'models/pet'
13
13
  require 'models/toy'
14
+ require 'models/contract'
15
+ require 'models/company'
16
+ require 'models/developer'
17
+ require 'models/subscriber'
18
+ require 'models/book'
19
+ require 'models/subscription'
14
20
 
15
21
  class HasManyThroughAssociationsTest < ActiveRecord::TestCase
16
- fixtures :posts, :readers, :people, :comments, :authors, :owners, :pets, :toys
22
+ fixtures :posts, :readers, :people, :comments, :authors,
23
+ :owners, :pets, :toys, :jobs, :references, :companies,
24
+ :subscribers, :books, :subscriptions, :developers
25
+
26
+ # Dummies to force column loads so query counts are clean.
27
+ def setup
28
+ Person.create :first_name => 'gummy'
29
+ Reader.create :person_id => 0, :post_id => 0
30
+ end
17
31
 
18
32
  def test_associate_existing
19
- assert_queries(2) { posts(:thinking);people(:david) }
20
-
21
- posts(:thinking).people
33
+ assert_queries(2) { posts(:thinking); people(:david) }
22
34
 
23
35
  assert_queries(1) do
24
36
  posts(:thinking).people << people(:david)
25
37
  end
26
-
38
+
27
39
  assert_queries(1) do
28
40
  assert posts(:thinking).people.include?(people(:david))
29
41
  end
30
-
42
+
31
43
  assert posts(:thinking).reload.people(true).include?(people(:david))
32
44
  end
33
45
 
34
46
  def test_associating_new
35
47
  assert_queries(1) { posts(:thinking) }
36
48
  new_person = nil # so block binding catches it
37
-
49
+
38
50
  assert_queries(0) do
39
51
  new_person = Person.new :first_name => 'bob'
40
52
  end
41
-
53
+
42
54
  # Associating new records always saves them
43
55
  # Thus, 1 query for the new person record, 1 query for the new join table record
44
56
  assert_queries(2) do
45
57
  posts(:thinking).people << new_person
46
58
  end
47
-
59
+
48
60
  assert_queries(1) do
49
61
  assert posts(:thinking).people.include?(new_person)
50
62
  end
51
-
63
+
52
64
  assert posts(:thinking).reload.people(true).include?(new_person)
53
65
  end
54
66
 
55
67
  def test_associate_new_by_building
56
68
  assert_queries(1) { posts(:thinking) }
57
-
69
+
58
70
  assert_queries(0) do
59
- posts(:thinking).people.build(:first_name=>"Bob")
60
- posts(:thinking).people.new(:first_name=>"Ted")
71
+ posts(:thinking).people.build(:first_name => "Bob")
72
+ posts(:thinking).people.new(:first_name => "Ted")
61
73
  end
62
-
74
+
63
75
  # Should only need to load the association once
64
76
  assert_queries(1) do
65
77
  assert posts(:thinking).people.collect(&:first_name).include?("Bob")
66
78
  assert posts(:thinking).people.collect(&:first_name).include?("Ted")
67
79
  end
68
-
80
+
69
81
  # 2 queries for each new record (1 to save the record itself, 1 for the join model)
70
82
  # * 2 new records = 4
71
83
  # + 1 query to save the actual post = 5
@@ -73,27 +85,27 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
73
85
  posts(:thinking).body += '-changed'
74
86
  posts(:thinking).save
75
87
  end
76
-
88
+
77
89
  assert posts(:thinking).reload.people(true).collect(&:first_name).include?("Bob")
78
90
  assert posts(:thinking).reload.people(true).collect(&:first_name).include?("Ted")
79
91
  end
80
92
 
81
93
  def test_delete_association
82
94
  assert_queries(2){posts(:welcome);people(:michael); }
83
-
95
+
84
96
  assert_queries(1) do
85
97
  posts(:welcome).people.delete(people(:michael))
86
98
  end
87
-
99
+
88
100
  assert_queries(1) do
89
101
  assert posts(:welcome).people.empty?
90
102
  end
91
-
103
+
92
104
  assert posts(:welcome).reload.people(true).empty?
93
105
  end
94
106
 
95
107
  def test_destroy_association
96
- assert_difference "Person.count", -1 do
108
+ assert_difference ["Person.count", "Reader.count"], -1 do
97
109
  posts(:welcome).people.destroy(people(:michael))
98
110
  end
99
111
 
@@ -102,7 +114,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
102
114
  end
103
115
 
104
116
  def test_destroy_all
105
- assert_difference "Person.count", -1 do
117
+ assert_difference ["Person.count", "Reader.count"], -1 do
106
118
  posts(:welcome).people.destroy_all
107
119
  end
108
120
 
@@ -110,38 +122,66 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
110
122
  assert posts(:welcome).people(true).empty?
111
123
  end
112
124
 
125
+ def test_should_raise_exception_for_destroying_mismatching_records
126
+ assert_no_difference ["Person.count", "Reader.count"] do
127
+ assert_raise(ActiveRecord::AssociationTypeMismatch) { posts(:welcome).people.destroy(posts(:thinking)) }
128
+ end
129
+ end
130
+
113
131
  def test_replace_association
114
132
  assert_queries(4){posts(:welcome);people(:david);people(:michael); posts(:welcome).people(true)}
115
-
133
+
116
134
  # 1 query to delete the existing reader (michael)
117
135
  # 1 query to associate the new reader (david)
118
136
  assert_queries(2) do
119
137
  posts(:welcome).people = [people(:david)]
120
138
  end
121
-
139
+
122
140
  assert_queries(0){
123
141
  assert posts(:welcome).people.include?(people(:david))
124
142
  assert !posts(:welcome).people.include?(people(:michael))
125
143
  }
126
-
144
+
127
145
  assert posts(:welcome).reload.people(true).include?(people(:david))
128
146
  assert !posts(:welcome).reload.people(true).include?(people(:michael))
129
147
  end
130
148
 
149
+ def test_replace_order_is_preserved
150
+ posts(:welcome).people.clear
151
+ posts(:welcome).people = [people(:david), people(:michael)]
152
+ assert_equal [people(:david).id, people(:michael).id], posts(:welcome).readers.order('id').map(&:person_id)
153
+
154
+ # Test the inverse order in case the first success was a coincidence
155
+ posts(:welcome).people.clear
156
+ posts(:welcome).people = [people(:michael), people(:david)]
157
+ assert_equal [people(:michael).id, people(:david).id], posts(:welcome).readers.order('id').map(&:person_id)
158
+ end
159
+
160
+ def test_replace_by_id_order_is_preserved
161
+ posts(:welcome).people.clear
162
+ posts(:welcome).person_ids = [people(:david).id, people(:michael).id]
163
+ assert_equal [people(:david).id, people(:michael).id], posts(:welcome).readers.order('id').map(&:person_id)
164
+
165
+ # Test the inverse order in case the first success was a coincidence
166
+ posts(:welcome).people.clear
167
+ posts(:welcome).person_ids = [people(:michael).id, people(:david).id]
168
+ assert_equal [people(:michael).id, people(:david).id], posts(:welcome).readers.order('id').map(&:person_id)
169
+ end
170
+
131
171
  def test_associate_with_create
132
172
  assert_queries(1) { posts(:thinking) }
133
-
173
+
134
174
  # 1 query for the new record, 1 for the join table record
135
175
  # No need to update the actual collection yet!
136
176
  assert_queries(2) do
137
177
  posts(:thinking).people.create(:first_name=>"Jeb")
138
178
  end
139
-
179
+
140
180
  # *Now* we actually need the collection so it's loaded
141
181
  assert_queries(1) do
142
182
  assert posts(:thinking).people.collect(&:first_name).include?("Jeb")
143
183
  end
144
-
184
+
145
185
  assert posts(:thinking).reload.people(true).collect(&:first_name).include?("Jeb")
146
186
  end
147
187
 
@@ -151,23 +191,74 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
151
191
  assert_equal peeps + 1, posts(:thinking).people.count
152
192
  end
153
193
 
194
+ def test_associate_with_create_with_through_having_conditions
195
+ impatient_people = posts(:thinking).impatient_people.count
196
+ posts(:thinking).impatient_people.create!(:first_name => 'foo')
197
+ assert_equal impatient_people + 1, posts(:thinking).impatient_people.count
198
+ end
199
+
154
200
  def test_associate_with_create_exclamation_and_no_options
155
201
  peeps = posts(:thinking).people.count
156
202
  posts(:thinking).people.create!(:first_name => 'foo')
157
203
  assert_equal peeps + 1, posts(:thinking).people.count
158
204
  end
159
205
 
206
+ def test_create_on_new_record
207
+ p = Post.new
208
+
209
+ assert_raises(ActiveRecord::RecordNotSaved) { p.people.create(:first_name => "mew") }
210
+ assert_raises(ActiveRecord::RecordNotSaved) { p.people.create!(:first_name => "snow") }
211
+ end
212
+
213
+ def test_associate_with_create_and_invalid_options
214
+ firm = companies(:first_firm)
215
+ assert_no_difference('firm.developers.count') { assert_nothing_raised { firm.developers.create(:name => '0') } }
216
+ end
217
+
218
+ def test_associate_with_create_and_valid_options
219
+ firm = companies(:first_firm)
220
+ assert_difference('firm.developers.count', 1) { firm.developers.create(:name => 'developer') }
221
+ end
222
+
223
+ def test_associate_with_create_bang_and_invalid_options
224
+ firm = companies(:first_firm)
225
+ assert_no_difference('firm.developers.count') { assert_raises(ActiveRecord::RecordInvalid) { firm.developers.create!(:name => '0') } }
226
+ end
227
+
228
+ def test_associate_with_create_bang_and_valid_options
229
+ firm = companies(:first_firm)
230
+ assert_difference('firm.developers.count', 1) { firm.developers.create!(:name => 'developer') }
231
+ end
232
+
233
+ def test_push_with_invalid_record
234
+ firm = companies(:first_firm)
235
+ assert_raises(ActiveRecord::RecordInvalid) { firm.developers << Developer.new(:name => '0') }
236
+ end
237
+
238
+ def test_push_with_invalid_join_record
239
+ repair_validations(Contract) do
240
+ Contract.validate {|r| r.errors[:base] << 'Invalid Contract' }
241
+
242
+ firm = companies(:first_firm)
243
+ lifo = Developer.new(:name => 'lifo')
244
+ assert_raises(ActiveRecord::RecordInvalid) { firm.developers << lifo }
245
+
246
+ lifo = Developer.create!(:name => 'lifo')
247
+ assert_raises(ActiveRecord::RecordInvalid) { firm.developers << lifo }
248
+ end
249
+ end
250
+
160
251
  def test_clear_associations
161
252
  assert_queries(2) { posts(:welcome);posts(:welcome).people(true) }
162
-
253
+
163
254
  assert_queries(1) do
164
255
  posts(:welcome).people.clear
165
256
  end
166
-
257
+
167
258
  assert_queries(0) do
168
259
  assert posts(:welcome).people.empty?
169
260
  end
170
-
261
+
171
262
  assert posts(:welcome).reload.people(true).empty?
172
263
  end
173
264
 
@@ -205,7 +296,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
205
296
  ], log.last(2)
206
297
 
207
298
  post.people_with_callbacks = [people(:michael),people(:david), Person.new(:first_name => "Julian"), Person.create!(:first_name => "Roger")]
208
- assert_equal (%w(Ted Bob Sam Lary) * 2).sort, log[-12..-5].collect(&:last).sort
299
+ assert_equal((%w(Ted Bob Sam Lary) * 2).sort, log[-12..-5].collect(&:last).sort)
209
300
  assert_equal [
210
301
  [:added, :before, "Julian"],
211
302
  [:added, :after, "Julian"],
@@ -214,7 +305,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
214
305
  ], log.last(4)
215
306
 
216
307
  post.people_with_callbacks.clear
217
- assert_equal (%w(Michael David Julian Roger) * 2).sort, log.last(8).collect(&:last).sort
308
+ assert_equal((%w(Michael David Julian Roger) * 2).sort, log.last(8).collect(&:last).sort)
218
309
  end
219
310
 
220
311
  unless current_adapter?(:IBM_DBAdapter) #refer db2 ? SQL0214N
@@ -233,8 +324,12 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
233
324
  assert_equal 2, people(:michael).jobs.size
234
325
  end
235
326
 
236
- def test_get_ids
237
- assert_equal [posts(:welcome).id, posts(:authorless).id].sort, people(:michael).post_ids.sort
327
+ def test_get_ids_for_belongs_to_source
328
+ assert_sql(/DISTINCT/) { assert_equal [posts(:welcome).id, posts(:authorless).id].sort, people(:michael).post_ids.sort }
329
+ end
330
+
331
+ def test_get_ids_for_has_many_source
332
+ assert_equal [comments(:eager_other_comment1).id], authors(:mary).comment_ids
238
333
  end
239
334
 
240
335
  def test_get_ids_for_loaded_associations
@@ -278,4 +373,89 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
278
373
  def test_has_many_association_through_a_has_many_association_with_nonstandard_primary_keys
279
374
  assert_equal 1, owners(:blackbeard).toys.count
280
375
  end
376
+
377
+ def test_find_on_has_many_association_collection_with_include_and_conditions
378
+ post_with_no_comments = people(:michael).posts_with_no_comments.first
379
+ assert_equal post_with_no_comments, posts(:authorless)
380
+ end
381
+
382
+ def test_has_many_through_has_one_reflection
383
+ assert_equal [comments(:eager_sti_on_associations_vs_comment)], authors(:david).very_special_comments
384
+ end
385
+
386
+ def test_modifying_has_many_through_has_one_reflection_should_raise
387
+ [
388
+ lambda { authors(:david).very_special_comments = [VerySpecialComment.create!(:body => "Gorp!", :post_id => 1011), VerySpecialComment.create!(:body => "Eep!", :post_id => 1012)] },
389
+ lambda { authors(:david).very_special_comments << VerySpecialComment.create!(:body => "Hoohah!", :post_id => 1013) },
390
+ lambda { authors(:david).very_special_comments.delete(authors(:david).very_special_comments.first) },
391
+ ].each {|block| assert_raise(ActiveRecord::HasManyThroughCantAssociateThroughHasOneOrManyReflection, &block) }
392
+ end
393
+
394
+ def test_collection_singular_ids_getter_with_string_primary_keys
395
+ book = books(:awdr)
396
+ assert_equal 2, book.subscriber_ids.size
397
+ assert_equal [subscribers(:first).nick, subscribers(:second).nick].sort, book.subscriber_ids.sort
398
+ end
399
+
400
+ def test_collection_singular_ids_setter
401
+ company = companies(:rails_core)
402
+ dev = Developer.find(:first)
403
+
404
+ company.developer_ids = [dev.id]
405
+ assert_equal [dev], company.developers
406
+ end
407
+
408
+ def test_collection_singular_ids_setter_with_string_primary_keys
409
+ assert_nothing_raised do
410
+ book = books(:awdr)
411
+ book.subscriber_ids = [subscribers(:second).nick]
412
+ assert_equal [subscribers(:second)], book.subscribers(true)
413
+
414
+ book.subscriber_ids = []
415
+ assert_equal [], book.subscribers(true)
416
+ end
417
+
418
+ end
419
+
420
+ def test_collection_singular_ids_setter_raises_exception_when_invalid_ids_set
421
+ company = companies(:rails_core)
422
+ ids = [Developer.find(:first).id, -9999]
423
+ assert_raises(ActiveRecord::RecordNotFound) {company.developer_ids= ids}
424
+ end
425
+
426
+ def test_build_a_model_from_hm_through_association_with_where_clause
427
+ assert_nothing_raised { books(:awdr).subscribers.where(:nick => "marklazz").build }
428
+ end
429
+
430
+ def test_attributes_are_being_set_when_initialized_from_hm_through_association_with_where_clause
431
+ new_subscriber = books(:awdr).subscribers.where(:nick => "marklazz").build
432
+ assert_equal new_subscriber.nick, "marklazz"
433
+ end
434
+
435
+ def test_attributes_are_being_set_when_initialized_from_hm_through_association_with_multiple_where_clauses
436
+ new_subscriber = books(:awdr).subscribers.where(:nick => "marklazz").where(:name => 'Marcelo Giorgi').build
437
+ assert_equal new_subscriber.nick, "marklazz"
438
+ assert_equal new_subscriber.name, "Marcelo Giorgi"
439
+ end
440
+
441
+ def test_include_method_in_association_through_should_return_true_for_instance_added_with_build
442
+ person = Person.new
443
+ reference = person.references.build
444
+ job = reference.build_job
445
+ assert person.jobs.include?(job)
446
+ end
447
+
448
+ def test_include_method_in_association_through_should_return_true_for_instance_added_with_nested_builds
449
+ author = Author.new
450
+ post = author.posts.build
451
+ comment = post.comments.build
452
+ assert author.comments.include?(comment)
453
+ end
454
+
455
+ def test_size_of_through_association_should_increase_correctly_when_has_many_association_is_added
456
+ post = posts(:thinking)
457
+ readers = post.readers.size
458
+ post.people << people(:michael)
459
+ assert_equal readers + 1, post.readers.size
460
+ end
281
461
  end
@@ -14,7 +14,9 @@ require 'models/citation'
14
14
 
15
15
  class AssociationsJoinModelTest < ActiveRecord::TestCase
16
16
  self.use_transactional_fixtures = false
17
- fixtures :posts, :authors, :categories, :categorizations, :comments, :tags, :taggings, :author_favorites, :vertices, :items, :books
17
+ fixtures :posts, :authors, :categories, :categorizations, :comments, :tags, :taggings, :author_favorites, :vertices, :items, :books,
18
+ # Reload edges table from fixtures as otherwise repeated test was failing
19
+ :edges
18
20
 
19
21
  def test_has_many
20
22
  assert authors(:david).categories.include?(categories(:general))
@@ -79,18 +81,6 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
79
81
  #
80
82
  end
81
83
 
82
- def test_polymorphic_has_many
83
- assert posts(:welcome).taggings.include?(taggings(:welcome_general))
84
- end
85
-
86
- def test_polymorphic_has_one
87
- assert_equal taggings(:welcome_general), posts(:welcome).tagging
88
- end
89
-
90
- def test_polymorphic_belongs_to
91
- assert_equal posts(:welcome), posts(:welcome).taggings.first.taggable
92
- end
93
-
94
84
  def test_polymorphic_has_many_going_through_join_model
95
85
  assert_equal tags(:general), tag = posts(:welcome).tags.first
96
86
  assert_no_queries do
@@ -319,16 +309,16 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
319
309
 
320
310
  def test_has_many_find_conditions
321
311
  assert_equal categories(:general), authors(:david).categories.find(:first, :conditions => "categories.name = 'General'")
322
- assert_equal nil, authors(:david).categories.find(:first, :conditions => "categories.name = 'Technology'")
312
+ assert_nil authors(:david).categories.find(:first, :conditions => "categories.name = 'Technology'")
323
313
  end
324
314
 
325
315
  def test_has_many_class_methods_called_by_method_missing
326
316
  assert_equal categories(:general), authors(:david).categories.find_all_by_name('General').first
327
- assert_equal nil, authors(:david).categories.find_by_name('Technology')
317
+ assert_nil authors(:david).categories.find_by_name('Technology')
328
318
  end
329
319
 
330
320
  def test_has_many_array_methods_called_by_method_missing
331
- assert true, authors(:david).categories.any? { |category| category.name == 'General' }
321
+ assert authors(:david).categories.any? { |category| category.name == 'General' }
332
322
  assert_nothing_raised { authors(:david).categories.sort }
333
323
  end
334
324
 
@@ -336,7 +326,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
336
326
  assert_equal [], posts(:thinking).authors
337
327
  assert_equal [authors(:mary)], posts(:authorless).authors
338
328
  end
339
-
329
+
340
330
  def test_both_scoped_and_explicit_joins_should_be_respected
341
331
  assert_nothing_raised do
342
332
  Post.send(:with_scope, :find => {:joins => "left outer join comments on comments.id = posts.id"}) do
@@ -346,11 +336,11 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
346
336
  end
347
337
 
348
338
  def test_belongs_to_polymorphic_with_counter_cache
349
- assert_equal 0, posts(:welcome)[:taggings_count]
339
+ assert_equal 1, posts(:welcome)[:taggings_count]
350
340
  tagging = posts(:welcome).taggings.create(:tag => tags(:general))
351
- assert_equal 1, posts(:welcome, :reload)[:taggings_count]
341
+ assert_equal 2, posts(:welcome, :reload)[:taggings_count]
352
342
  tagging.destroy
353
- assert posts(:welcome, :reload)[:taggings_count].zero?
343
+ assert_equal 1, posts(:welcome, :reload)[:taggings_count]
354
344
  end
355
345
 
356
346
  def test_unavailable_through_reflection
@@ -372,14 +362,16 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
372
362
  end
373
363
 
374
364
  def test_has_many_polymorphic_with_source_type
375
- assert_equal posts(:welcome, :thinking), tags(:general).tagged_posts
365
+ # added sort by ID as otherwise Oracle select sometimes returned rows in different order
366
+ assert_equal posts(:welcome, :thinking).sort_by(&:id), tags(:general).tagged_posts.sort_by(&:id)
376
367
  end
377
368
 
378
369
  def test_eager_has_many_polymorphic_with_source_type
379
370
  tag_with_include = Tag.find(tags(:general).id, :include => :tagged_posts)
380
371
  desired = posts(:welcome, :thinking)
381
372
  assert_no_queries do
382
- assert_equal desired, tag_with_include.tagged_posts
373
+ # added sort by ID as otherwise test using JRuby was failing as array elements were in different order
374
+ assert_equal desired.sort_by(&:id), tag_with_include.tagged_posts.sort_by(&:id)
383
375
  end
384
376
  assert_equal 5, tag_with_include.taggings.length
385
377
  end
@@ -406,7 +398,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
406
398
  end
407
399
 
408
400
  def test_has_many_through_polymorphic_has_one
409
- assert_raise(ActiveRecord::HasManyThroughSourceAssociationMacroError) { authors(:david).tagging }
401
+ assert_equal Tagging.find(1,2).sort_by { |t| t.id }, authors(:david).tagging
410
402
  end
411
403
 
412
404
  def test_has_many_through_polymorphic_has_many
@@ -493,8 +485,8 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
493
485
 
494
486
  def test_has_many_through_uses_conditions_specified_on_the_has_many_association
495
487
  author = Author.find(:first)
496
- assert !author.comments.blank?
497
- assert author.nonexistant_comments.blank?
488
+ assert_present author.comments
489
+ assert_blank author.nonexistant_comments
498
490
  end
499
491
 
500
492
  def test_has_many_through_uses_correct_attributes
@@ -506,11 +498,11 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
506
498
  new_tag = Tag.new(:name => "new")
507
499
 
508
500
  saved_post.tags << new_tag
509
- assert !new_tag.new_record? #consistent with habtm!
510
- assert !saved_post.new_record?
501
+ assert new_tag.persisted? #consistent with habtm!
502
+ assert saved_post.persisted?
511
503
  assert saved_post.tags.include?(new_tag)
512
504
 
513
- assert !new_tag.new_record?
505
+ assert new_tag.persisted?
514
506
  assert saved_post.reload.tags(true).include?(new_tag)
515
507
 
516
508
 
@@ -518,16 +510,16 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
518
510
  saved_tag = tags(:general)
519
511
 
520
512
  new_post.tags << saved_tag
521
- assert new_post.new_record?
522
- assert !saved_tag.new_record?
513
+ assert !new_post.persisted?
514
+ assert saved_tag.persisted?
523
515
  assert new_post.tags.include?(saved_tag)
524
516
 
525
517
  new_post.save!
526
- assert !new_post.new_record?
518
+ assert new_post.persisted?
527
519
  assert new_post.reload.tags(true).include?(saved_tag)
528
520
 
529
- assert posts(:thinking).tags.build.new_record?
530
- assert posts(:thinking).tags.new.new_record?
521
+ assert !posts(:thinking).tags.build.persisted?
522
+ assert !posts(:thinking).tags.new.persisted?
531
523
  end
532
524
 
533
525
  def test_create_associate_when_adding_to_has_many_through
@@ -641,7 +633,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
641
633
  def test_calculations_on_has_many_through_should_disambiguate_fields
642
634
  assert_nothing_raised { authors(:david).categories.maximum(:id) }
643
635
  end
644
-
636
+
645
637
  def test_calculations_on_has_many_through_should_not_disambiguate_fields_unless_necessary
646
638
  assert_nothing_raised { authors(:david).categories.maximum("categories.id") }
647
639
  end