Class: Test::Unit::TestCase

Inherits:
Object
  • Object
show all
Includes:
ClassInheritableAttributes
Defined in:
lib/active_record/fixtures.rb

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fixtures(*table_names) ⇒ Object



369
370
371
372
# File 'lib/active_record/fixtures.rb', line 369

def self.fixtures(*table_names)
  self.fixture_table_names = table_names.flatten
  require_fixture_classes
end

.method_added(method) ⇒ Object



413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/active_record/fixtures.rb', line 413

def self.method_added(method)
  case method.to_s
  when 'setup'
    unless method_defined?(:setup_without_fixtures)
      alias_method :setup_without_fixtures, :setup
      define_method(:setup) do
        setup_with_fixtures
        setup_without_fixtures
      end
    end
  when 'teardown'
    unless method_defined?(:teardown_without_fixtures)
      alias_method :teardown_without_fixtures, :teardown
      define_method(:teardown) do
        teardown_without_fixtures
        teardown_with_fixtures
      end
    end
  end
end

.require_fixture_classesObject



374
375
376
377
378
379
380
381
382
# File 'lib/active_record/fixtures.rb', line 374

def self.require_fixture_classes
  fixture_table_names.each do |table_name| 
    begin
      require Inflector.singularize(table_name.to_s)
    rescue LoadError
      # Let's hope the developer has included it himself
    end
  end
end

Instance Method Details

#setup_with_fixturesObject Also known as: setup



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# File 'lib/active_record/fixtures.rb', line 384

def setup_with_fixtures
  # Load fixtures once and begin transaction.
  if use_transactional_fixtures
    load_fixtures unless @already_loaded_fixtures
    @already_loaded_fixtures = true
    ActiveRecord::Base.lock_mutex
    ActiveRecord::Base.connection.begin_db_transaction

  # Load fixtures for every test.
  else
    load_fixtures
  end

  # Instantiate fixtures for every test if requested.
  instantiate_fixtures if use_instantiated_fixtures
end

#teardown_with_fixturesObject Also known as: teardown



403
404
405
406
407
408
409
# File 'lib/active_record/fixtures.rb', line 403

def teardown_with_fixtures
  # Rollback changes.
  if use_transactional_fixtures
    ActiveRecord::Base.connection.rollback_db_transaction
    ActiveRecord::Base.unlock_mutex
  end
end