ibm_db 0.9.5 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,630 @@
1
+ require "cases/helper"
2
+ require 'models/post'
3
+ require 'models/binary'
4
+ require 'models/topic'
5
+ require 'models/computer'
6
+ require 'models/developer'
7
+ require 'models/company'
8
+ require 'models/task'
9
+ require 'models/reply'
10
+ require 'models/joke'
11
+ require 'models/course'
12
+ require 'models/category'
13
+ require 'models/parrot'
14
+ require 'models/pirate'
15
+ require 'models/treasure'
16
+ require 'models/matey'
17
+ require 'models/ship'
18
+
19
+ class FixturesTest < ActiveRecord::TestCase
20
+ self.use_instantiated_fixtures = true
21
+ self.use_transactional_fixtures = false
22
+
23
+ fixtures :topics, :developers, :accounts, :tasks, :categories, :funny_jokes, :binaries
24
+
25
+ FIXTURES = %w( accounts binaries companies customers
26
+ developers developers_projects entrants
27
+ movies projects subscribers topics tasks )
28
+ MATCH_ATTRIBUTE_NAME = /[a-zA-Z][-_\w]*/
29
+
30
+ def test_clean_fixtures
31
+ FIXTURES.each do |name|
32
+ fixtures = nil
33
+ assert_nothing_raised { fixtures = create_fixtures(name) }
34
+ assert_kind_of(Fixtures, fixtures)
35
+ fixtures.each { |name, fixture|
36
+ fixture.each { |key, value|
37
+ assert_match(MATCH_ATTRIBUTE_NAME, key)
38
+ }
39
+ }
40
+ end
41
+ end
42
+
43
+ def test_multiple_clean_fixtures
44
+ fixtures_array = nil
45
+ assert_nothing_raised { fixtures_array = create_fixtures(*FIXTURES) }
46
+ assert_kind_of(Array, fixtures_array)
47
+ fixtures_array.each { |fixtures| assert_kind_of(Fixtures, fixtures) }
48
+ end
49
+
50
+ def test_attributes
51
+ topics = create_fixtures("topics")
52
+ assert_equal("The First Topic", topics["first"]["title"])
53
+ assert_nil(topics["second"]["author_email_address"])
54
+ end
55
+
56
+ def test_inserts
57
+ topics = create_fixtures("topics")
58
+ first_row = ActiveRecord::Base.connection.select_one("SELECT * FROM topics WHERE author_name = 'David'")
59
+ assert_equal("The First Topic", first_row["title"])
60
+
61
+ second_row = ActiveRecord::Base.connection.select_one("SELECT * FROM topics WHERE author_name = 'Mary'")
62
+ assert_nil(second_row["author_email_address"])
63
+ end
64
+
65
+ if ActiveRecord::Base.connection.supports_migrations?
66
+ def test_inserts_with_pre_and_suffix
67
+ # Reset cache to make finds on the new table work
68
+ Fixtures.reset_cache
69
+
70
+ ActiveRecord::Base.connection.create_table :prefix_topics_suffix do |t|
71
+ t.column :title, :string
72
+ t.column :author_name, :string
73
+ t.column :author_email_address, :string
74
+ t.column :written_on, :datetime
75
+ t.column :bonus_time, :time
76
+ t.column :last_read, :date
77
+ t.column :content, :string
78
+ t.column :approved, :boolean, :default => true
79
+ t.column :replies_count, :integer, :default => 0
80
+ t.column :parent_id, :integer
81
+ t.column :type, :string, :limit => 50
82
+ end
83
+
84
+ # Store existing prefix/suffix
85
+ old_prefix = ActiveRecord::Base.table_name_prefix
86
+ old_suffix = ActiveRecord::Base.table_name_suffix
87
+
88
+ # Set a prefix/suffix we can test against
89
+ ActiveRecord::Base.table_name_prefix = 'prefix_'
90
+ ActiveRecord::Base.table_name_suffix = '_suffix'
91
+
92
+ topics = create_fixtures("topics")
93
+
94
+ first_row = ActiveRecord::Base.connection.select_one("SELECT * FROM prefix_topics_suffix WHERE author_name = 'David'")
95
+ assert_equal("The First Topic", first_row["title"])
96
+
97
+ second_row = ActiveRecord::Base.connection.select_one("SELECT * FROM prefix_topics_suffix WHERE author_name = 'Mary'")
98
+ assert_nil(second_row["author_email_address"])
99
+
100
+ # This checks for a caching problem which causes a bug in the fixtures
101
+ # class-level configuration helper.
102
+ assert_not_nil topics, "Fixture data inserted, but fixture objects not returned from create"
103
+ ensure
104
+ # Restore prefix/suffix to its previous values
105
+ ActiveRecord::Base.table_name_prefix = old_prefix
106
+ ActiveRecord::Base.table_name_suffix = old_suffix
107
+
108
+ ActiveRecord::Base.connection.drop_table :prefix_topics_suffix rescue nil
109
+ end
110
+ end
111
+
112
+ def test_insert_with_datetime
113
+ topics = create_fixtures("tasks")
114
+ first = Task.find(1)
115
+ assert first
116
+ end
117
+
118
+ def test_logger_level_invariant
119
+ level = ActiveRecord::Base.logger.level
120
+ create_fixtures('topics')
121
+ assert_equal level, ActiveRecord::Base.logger.level
122
+ end
123
+
124
+ def test_instantiation
125
+ topics = create_fixtures("topics")
126
+ assert_kind_of Topic, topics["first"].find
127
+ end
128
+
129
+ def test_complete_instantiation
130
+ assert_equal 4, @topics.size
131
+ assert_equal "The First Topic", @first.title
132
+ end
133
+
134
+ def test_fixtures_from_root_yml_with_instantiation
135
+ # assert_equal 2, @accounts.size
136
+ assert_equal 50, @unknown.credit_limit
137
+ end
138
+
139
+ def test_erb_in_fixtures
140
+ assert_equal 11, @developers.size
141
+ assert_equal "fixture_5", @dev_5.name
142
+ end
143
+
144
+ def test_empty_yaml_fixture
145
+ assert_not_nil Fixtures.new( Account.connection, "accounts", 'Account', FIXTURES_ROOT + "/naked/yml/accounts")
146
+ end
147
+
148
+ def test_empty_yaml_fixture_with_a_comment_in_it
149
+ assert_not_nil Fixtures.new( Account.connection, "companies", 'Company', FIXTURES_ROOT + "/naked/yml/companies")
150
+ end
151
+
152
+ def test_dirty_dirty_yaml_file
153
+ assert_raises(Fixture::FormatError) do
154
+ Fixtures.new( Account.connection, "courses", 'Course', FIXTURES_ROOT + "/naked/yml/courses")
155
+ end
156
+ end
157
+
158
+ def test_empty_csv_fixtures
159
+ assert_not_nil Fixtures.new( Account.connection, "accounts", 'Account', FIXTURES_ROOT + "/naked/csv/accounts")
160
+ end
161
+
162
+ def test_omap_fixtures
163
+ assert_nothing_raised do
164
+ fixtures = Fixtures.new(Account.connection, 'categories', 'Category', FIXTURES_ROOT + "/categories_ordered")
165
+
166
+ i = 0
167
+ fixtures.each do |name, fixture|
168
+ assert_equal "fixture_no_#{i}", name
169
+ assert_equal "Category #{i}", fixture['name']
170
+ i += 1
171
+ end
172
+ end
173
+ end
174
+
175
+ def test_yml_file_in_subdirectory
176
+ assert_equal(categories(:sub_special_1).name, "A special category in a subdir file")
177
+ assert_equal(categories(:sub_special_1).class, SpecialCategory)
178
+ end
179
+
180
+ def test_subsubdir_file_with_arbitrary_name
181
+ assert_equal(categories(:sub_special_3).name, "A special category in an arbitrarily named subsubdir file")
182
+ assert_equal(categories(:sub_special_3).class, SpecialCategory)
183
+ end
184
+
185
+ def test_binary_in_fixtures
186
+ assert_equal 1, @binaries.size
187
+ unless current_adapter?(:IBM_DBAdapter)
188
+ data = File.read(ASSETS_ROOT + "/flowers.jpg")
189
+ else
190
+ data = File.open(ASSETS_ROOT + "/flowers.jpg","rb").read
191
+ end
192
+ data.force_encoding('ASCII-8BIT') if data.respond_to?(:force_encoding)
193
+ data.freeze
194
+ assert_equal data, @flowers.data
195
+ end
196
+ end
197
+
198
+ if Account.connection.respond_to?(:reset_pk_sequence!)
199
+ class FixturesResetPkSequenceTest < ActiveRecord::TestCase
200
+ fixtures :accounts
201
+ fixtures :companies
202
+
203
+ def setup
204
+ @instances = [Account.new(:credit_limit => 50), Company.new(:name => 'RoR Consulting')]
205
+ Fixtures.reset_cache # make sure tables get reinitialized
206
+ end
207
+
208
+ def test_resets_to_min_pk_with_specified_pk_and_sequence
209
+ @instances.each do |instance|
210
+ model = instance.class
211
+ model.delete_all
212
+ model.connection.reset_pk_sequence!(model.table_name, model.primary_key, model.sequence_name)
213
+
214
+ instance.save!
215
+ assert_equal 1, instance.id, "Sequence reset for #{model.table_name} failed."
216
+ end
217
+ end
218
+
219
+ def test_resets_to_min_pk_with_default_pk_and_sequence
220
+ @instances.each do |instance|
221
+ model = instance.class
222
+ model.delete_all
223
+ model.connection.reset_pk_sequence!(model.table_name)
224
+
225
+ instance.save!
226
+ assert_equal 1, instance.id, "Sequence reset for #{model.table_name} failed."
227
+ end
228
+ end
229
+
230
+ def test_create_fixtures_resets_sequences_when_not_cached
231
+ @instances.each do |instance|
232
+ max_id = create_fixtures(instance.class.table_name).inject(0) do |max_id, (name, fixture)|
233
+ fixture_id = fixture['id'].to_i
234
+ fixture_id > max_id ? fixture_id : max_id
235
+ end
236
+
237
+ # Clone the last fixture to check that it gets the next greatest id.
238
+ instance.save!
239
+ assert_equal max_id + 1, instance.id, "Sequence reset for #{instance.class.table_name} failed."
240
+ end
241
+ end
242
+ end
243
+ end
244
+
245
+ class FixturesWithoutInstantiationTest < ActiveRecord::TestCase
246
+ self.use_instantiated_fixtures = false
247
+ fixtures :topics, :developers, :accounts
248
+
249
+ def test_without_complete_instantiation
250
+ assert_nil @first
251
+ assert_nil @topics
252
+ assert_nil @developers
253
+ assert_nil @accounts
254
+ end
255
+
256
+ def test_fixtures_from_root_yml_without_instantiation
257
+ assert_nil @unknown
258
+ end
259
+
260
+ def test_accessor_methods
261
+ assert_equal "The First Topic", topics(:first).title
262
+ assert_equal "Jamis", developers(:jamis).name
263
+ assert_equal 50, accounts(:signals37).credit_limit
264
+ end
265
+
266
+ def test_accessor_methods_with_multiple_args
267
+ assert_equal 2, topics(:first, :second).size
268
+ assert_raise(StandardError) { topics([:first, :second]) }
269
+ end
270
+
271
+ uses_mocha 'reloading_fixtures_through_accessor_methods' do
272
+ def test_reloading_fixtures_through_accessor_methods
273
+ assert_equal "The First Topic", topics(:first).title
274
+ @loaded_fixtures['topics']['first'].expects(:find).returns(stub(:title => "Fresh Topic!"))
275
+ assert_equal "Fresh Topic!", topics(:first, true).title
276
+ end
277
+ end
278
+ end
279
+
280
+ class FixturesWithoutInstanceInstantiationTest < ActiveRecord::TestCase
281
+ self.use_instantiated_fixtures = true
282
+ self.use_instantiated_fixtures = :no_instances
283
+
284
+ fixtures :topics, :developers, :accounts
285
+
286
+ def test_without_instance_instantiation
287
+ assert_nil @first
288
+ assert_not_nil @topics
289
+ assert_not_nil @developers
290
+ assert_not_nil @accounts
291
+ end
292
+ end
293
+
294
+ class TransactionalFixturesTest < ActiveRecord::TestCase
295
+ self.use_instantiated_fixtures = true
296
+ self.use_transactional_fixtures = true
297
+
298
+ fixtures :topics
299
+
300
+ def test_destroy
301
+ assert_not_nil @first
302
+ @first.destroy
303
+ end
304
+
305
+ def test_destroy_just_kidding
306
+ assert_not_nil @first
307
+ end
308
+ end
309
+
310
+ class MultipleFixturesTest < ActiveRecord::TestCase
311
+ fixtures :topics
312
+ fixtures :developers, :accounts
313
+
314
+ def test_fixture_table_names
315
+ assert_equal %w(topics developers accounts), fixture_table_names
316
+ end
317
+ end
318
+
319
+ class SetupTest < ActiveRecord::TestCase
320
+ # fixtures :topics
321
+
322
+ def setup
323
+ @first = true
324
+ end
325
+
326
+ def test_nothing
327
+ end
328
+ end
329
+
330
+ class SetupSubclassTest < SetupTest
331
+ def setup
332
+ super
333
+ @second = true
334
+ end
335
+
336
+ def test_subclassing_should_preserve_setups
337
+ assert @first
338
+ assert @second
339
+ end
340
+ end
341
+
342
+
343
+ class OverlappingFixturesTest < ActiveRecord::TestCase
344
+ fixtures :topics, :developers
345
+ fixtures :developers, :accounts
346
+
347
+ def test_fixture_table_names
348
+ assert_equal %w(topics developers accounts), fixture_table_names
349
+ end
350
+ end
351
+
352
+ class ForeignKeyFixturesTest < ActiveRecord::TestCase
353
+ fixtures :fk_test_has_pk, :fk_test_has_fk
354
+
355
+ # if foreign keys are implemented and fixtures
356
+ # are not deleted in reverse order then this test
357
+ # case will raise StatementInvalid
358
+
359
+ def test_number1
360
+ assert true
361
+ end
362
+
363
+ def test_number2
364
+ assert true
365
+ end
366
+ end
367
+
368
+ class CheckSetTableNameFixturesTest < ActiveRecord::TestCase
369
+ set_fixture_class :funny_jokes => 'Joke'
370
+ fixtures :funny_jokes
371
+ # Set to false to blow away fixtures cache and ensure our fixtures are loaded
372
+ # and thus takes into account our set_fixture_class
373
+ self.use_transactional_fixtures = false
374
+
375
+ def test_table_method
376
+ assert_kind_of Joke, funny_jokes(:a_joke)
377
+ end
378
+ end
379
+
380
+ class CustomConnectionFixturesTest < ActiveRecord::TestCase
381
+ set_fixture_class :courses => Course
382
+ fixtures :courses
383
+ # Set to false to blow away fixtures cache and ensure our fixtures are loaded
384
+ # and thus takes into account our set_fixture_class
385
+ self.use_transactional_fixtures = false
386
+
387
+ def test_connection
388
+ assert_kind_of Course, courses(:ruby)
389
+ assert_equal Course.connection, courses(:ruby).connection
390
+ end
391
+ end
392
+
393
+ class InvalidTableNameFixturesTest < ActiveRecord::TestCase
394
+ fixtures :funny_jokes
395
+ # Set to false to blow away fixtures cache and ensure our fixtures are loaded
396
+ # and thus takes into account our lack of set_fixture_class
397
+ self.use_transactional_fixtures = false
398
+
399
+ def test_raises_error
400
+ assert_raises FixtureClassNotFound do
401
+ funny_jokes(:a_joke)
402
+ end
403
+ end
404
+ end
405
+
406
+ class CheckEscapedYamlFixturesTest < ActiveRecord::TestCase
407
+ set_fixture_class :funny_jokes => 'Joke'
408
+ fixtures :funny_jokes
409
+ # Set to false to blow away fixtures cache and ensure our fixtures are loaded
410
+ # and thus takes into account our set_fixture_class
411
+ self.use_transactional_fixtures = false
412
+
413
+ def test_proper_escaped_fixture
414
+ assert_equal "The \\n Aristocrats\nAte the candy\n", funny_jokes(:another_joke).name
415
+ end
416
+ end
417
+
418
+ class DevelopersProject; end
419
+ class ManyToManyFixturesWithClassDefined < ActiveRecord::TestCase
420
+ fixtures :developers_projects
421
+
422
+ def test_this_should_run_cleanly
423
+ assert true
424
+ end
425
+ end
426
+
427
+ class FixturesBrokenRollbackTest < ActiveRecord::TestCase
428
+ def blank_setup; end
429
+ alias_method :ar_setup_fixtures, :setup_fixtures
430
+ alias_method :setup_fixtures, :blank_setup
431
+ alias_method :setup, :blank_setup
432
+
433
+ def blank_teardown; end
434
+ alias_method :ar_teardown_fixtures, :teardown_fixtures
435
+ alias_method :teardown_fixtures, :blank_teardown
436
+ alias_method :teardown, :blank_teardown
437
+
438
+ def test_no_rollback_in_teardown_unless_transaction_active
439
+ assert_equal 0, Thread.current['open_transactions']
440
+ assert_raise(RuntimeError) { ar_setup_fixtures }
441
+ assert_equal 0, Thread.current['open_transactions']
442
+ assert_nothing_raised { ar_teardown_fixtures }
443
+ assert_equal 0, Thread.current['open_transactions']
444
+ end
445
+
446
+ private
447
+ def load_fixtures
448
+ raise 'argh'
449
+ end
450
+ end
451
+
452
+ class LoadAllFixturesTest < ActiveRecord::TestCase
453
+ self.fixture_path = FIXTURES_ROOT + "/all"
454
+ fixtures :all
455
+
456
+ def test_all_there
457
+ assert_equal %w(developers people tasks), fixture_table_names.sort
458
+ end
459
+ end
460
+
461
+ class FasterFixturesTest < ActiveRecord::TestCase
462
+ fixtures :categories, :authors
463
+
464
+ def load_extra_fixture(name)
465
+ fixture = create_fixtures(name)
466
+ assert fixture.is_a?(Fixtures)
467
+ @loaded_fixtures[fixture.table_name] = fixture
468
+ end
469
+
470
+ def test_cache
471
+ assert Fixtures.fixture_is_cached?(ActiveRecord::Base.connection, 'categories')
472
+ assert Fixtures.fixture_is_cached?(ActiveRecord::Base.connection, 'authors')
473
+
474
+ assert_no_queries do
475
+ create_fixtures('categories')
476
+ create_fixtures('authors')
477
+ end
478
+
479
+ load_extra_fixture('posts')
480
+ assert Fixtures.fixture_is_cached?(ActiveRecord::Base.connection, 'posts')
481
+ self.class.setup_fixture_accessors('posts')
482
+ assert_equal 'Welcome to the weblog', posts(:welcome).title
483
+ end
484
+ end
485
+
486
+ class FoxyFixturesTest < ActiveRecord::TestCase
487
+ fixtures :parrots, :parrots_pirates, :pirates, :treasures, :mateys, :ships, :computers, :developers
488
+
489
+ def test_identifies_strings
490
+ assert_equal(Fixtures.identify("foo"), Fixtures.identify("foo"))
491
+ assert_not_equal(Fixtures.identify("foo"), Fixtures.identify("FOO"))
492
+ end
493
+
494
+ def test_identifies_symbols
495
+ assert_equal(Fixtures.identify(:foo), Fixtures.identify(:foo))
496
+ end
497
+
498
+ TIMESTAMP_COLUMNS = %w(created_at created_on updated_at updated_on)
499
+
500
+ def test_populates_timestamp_columns
501
+ TIMESTAMP_COLUMNS.each do |property|
502
+ assert_not_nil(parrots(:george).send(property), "should set #{property}")
503
+ end
504
+ end
505
+
506
+ def test_does_not_populate_timestamp_columns_if_model_has_set_record_timestamps_to_false
507
+ TIMESTAMP_COLUMNS.each do |property|
508
+ assert_nil(ships(:black_pearl).send(property), "should not set #{property}")
509
+ end
510
+ end
511
+
512
+ def test_populates_all_columns_with_the_same_time
513
+ last = nil
514
+
515
+ TIMESTAMP_COLUMNS.each do |property|
516
+ current = parrots(:george).send(property)
517
+ last ||= current
518
+
519
+ assert_equal(last, current)
520
+ last = current
521
+ end
522
+ end
523
+
524
+ def test_only_populates_columns_that_exist
525
+ assert_not_nil(pirates(:blackbeard).created_on)
526
+ assert_not_nil(pirates(:blackbeard).updated_on)
527
+ end
528
+
529
+ def test_preserves_existing_fixture_data
530
+ assert_equal(2.weeks.ago.to_date, pirates(:redbeard).created_on.to_date)
531
+ assert_equal(2.weeks.ago.to_date, pirates(:redbeard).updated_on.to_date)
532
+ end
533
+
534
+ def test_generates_unique_ids
535
+ assert_not_nil(parrots(:george).id)
536
+ assert_not_equal(parrots(:george).id, parrots(:louis).id)
537
+ end
538
+
539
+ def test_automatically_sets_primary_key
540
+ assert_not_nil(ships(:black_pearl))
541
+ end
542
+
543
+ def test_preserves_existing_primary_key
544
+ assert_equal(2, ships(:interceptor).id)
545
+ end
546
+
547
+ def test_resolves_belongs_to_symbols
548
+ assert_equal(parrots(:george), pirates(:blackbeard).parrot)
549
+ end
550
+
551
+ def test_ignores_belongs_to_symbols_if_association_and_foreign_key_are_named_the_same
552
+ assert_equal(developers(:david), computers(:workstation).developer)
553
+ end
554
+
555
+ def test_supports_join_tables
556
+ assert(pirates(:blackbeard).parrots.include?(parrots(:george)))
557
+ assert(pirates(:blackbeard).parrots.include?(parrots(:louis)))
558
+ assert(parrots(:george).pirates.include?(pirates(:blackbeard)))
559
+ end
560
+
561
+ def test_supports_inline_habtm
562
+ assert(parrots(:george).treasures.include?(treasures(:diamond)))
563
+ assert(parrots(:george).treasures.include?(treasures(:sapphire)))
564
+ assert(!parrots(:george).treasures.include?(treasures(:ruby)))
565
+ end
566
+
567
+ def test_supports_inline_habtm_with_specified_id
568
+ assert(parrots(:polly).treasures.include?(treasures(:ruby)))
569
+ assert(parrots(:polly).treasures.include?(treasures(:sapphire)))
570
+ assert(!parrots(:polly).treasures.include?(treasures(:diamond)))
571
+ end
572
+
573
+ def test_supports_yaml_arrays
574
+ assert(parrots(:louis).treasures.include?(treasures(:diamond)))
575
+ assert(parrots(:louis).treasures.include?(treasures(:sapphire)))
576
+ end
577
+
578
+ def test_strips_DEFAULTS_key
579
+ assert_raise(StandardError) { parrots(:DEFAULTS) }
580
+
581
+ # this lets us do YAML defaults and not have an extra fixture entry
582
+ %w(sapphire ruby).each { |t| assert(parrots(:davey).treasures.include?(treasures(t))) }
583
+ end
584
+
585
+ def test_supports_label_interpolation
586
+ assert_equal("frederick", parrots(:frederick).name)
587
+ end
588
+
589
+ def test_supports_polymorphic_belongs_to
590
+ assert_equal(pirates(:redbeard), treasures(:sapphire).looter)
591
+ assert_equal(parrots(:louis), treasures(:ruby).looter)
592
+ end
593
+
594
+ def test_only_generates_a_pk_if_necessary
595
+ m = Matey.find(:first)
596
+ m.pirate = pirates(:blackbeard)
597
+ m.target = pirates(:redbeard)
598
+ end
599
+
600
+ def test_supports_sti
601
+ assert_kind_of DeadParrot, parrots(:polly)
602
+ assert_equal pirates(:blackbeard), parrots(:polly).killer
603
+ end
604
+ end
605
+
606
+ class ActiveSupportSubclassWithFixturesTest < ActiveRecord::TestCase
607
+ fixtures :parrots
608
+
609
+ # This seemingly useless assertion catches a bug that caused the fixtures
610
+ # setup code call nil[]
611
+ def test_foo
612
+ assert_equal parrots(:louis), Parrot.find_by_name("King Louis")
613
+ end
614
+ end
615
+
616
+ class FixtureLoadingTest < ActiveRecord::TestCase
617
+ uses_mocha 'reloading_fixtures_through_accessor_methods' do
618
+ def test_logs_message_for_failed_dependency_load
619
+ Test::Unit::TestCase.expects(:require_dependency).with(:does_not_exist).raises(LoadError)
620
+ ActiveRecord::Base.logger.expects(:warn)
621
+ Test::Unit::TestCase.try_to_load_dependency(:does_not_exist)
622
+ end
623
+
624
+ def test_does_not_logs_message_for_successful_dependency_load
625
+ Test::Unit::TestCase.expects(:require_dependency).with(:works_out_fine)
626
+ ActiveRecord::Base.logger.expects(:warn).never
627
+ Test::Unit::TestCase.try_to_load_dependency(:works_out_fine)
628
+ end
629
+ end
630
+ end