ibm_db 1.1.1-mswin32

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