ibm_db 2.5.6-x86-mswin32-60

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