Module: ActiveRecord::TestFixtures::ClassMethods

### Home Classes Methods

### In Files

- lib/active_record/fixtures.rb

### Methods

- #fixtures
- #require_fixture_classes
- #set_fixture_class
- #setup_fixture_accessors
- #try_to_load_dependency
- #uses_transaction
- #uses_transaction?

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- ActiveRecord
- ActiveRecord::ActiveRecordError
- ActiveRecord::AdapterNotFound
- ActiveRecord::AdapterNotSpecified
- ActiveRecord::Aggregations
- ActiveRecord::Aggregations::ClassMethods
- ActiveRecord::AssociationPreload
- ActiveRecord::AssociationPreload::ClassMethods
- ActiveRecord::AssociationTypeMismatch
- ActiveRecord::Associations
- ActiveRecord::Associations::ClassMethods
- ActiveRecord::Associations::HasOneThroughAssociation
- ActiveRecord::Associations::ThroughAssociationScope
- ActiveRecord::AttributeAssignmentError
- ActiveRecord::AttributeMethods
- ActiveRecord::AttributeMethods::BeforeTypeCast
- ActiveRecord::AttributeMethods::ClassMethods
- ActiveRecord::AttributeMethods::Dirty
- ActiveRecord::AttributeMethods::PrimaryKey
- ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods
- ActiveRecord::AttributeMethods::Query
- ActiveRecord::AttributeMethods::Read
- ActiveRecord::AttributeMethods::Read::ClassMethods
- ActiveRecord::AttributeMethods::TimeZoneConversion
- ActiveRecord::AttributeMethods::TimeZoneConversion::ClassMethods
- ActiveRecord::AttributeMethods::Write
- ActiveRecord::AttributeMethods::Write::ClassMethods
- ActiveRecord::AutosaveAssociation
- ActiveRecord::AutosaveAssociation::ClassMethods
- ActiveRecord::Base
- ActiveRecord::Calculations
- ActiveRecord::Callbacks
- ActiveRecord::Callbacks::ClassMethods
- ActiveRecord::ConfigurationError
- ActiveRecord::ConnectionAdapters
- ActiveRecord::ConnectionAdapters::AbstractAdapter
- ActiveRecord::ConnectionAdapters::Column
- ActiveRecord::ConnectionAdapters::Column::Format
- ActiveRecord::ConnectionAdapters::ConnectionHandler
- ActiveRecord::ConnectionAdapters::ConnectionManagement
- ActiveRecord::ConnectionAdapters::ConnectionPool
- ActiveRecord::ConnectionAdapters::DatabaseLimits
- ActiveRecord::ConnectionAdapters::DatabaseStatements
- ActiveRecord::ConnectionAdapters::MysqlAdapter
- ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
- ActiveRecord::ConnectionAdapters::PostgreSQLColumn
- ActiveRecord::ConnectionAdapters::QueryCache
- ActiveRecord::ConnectionAdapters::Quoting
- ActiveRecord::ConnectionAdapters::SQLiteAdapter
- ActiveRecord::ConnectionAdapters::SQLiteAdapter::Version
- ActiveRecord::ConnectionAdapters::SchemaStatements
- ActiveRecord::ConnectionAdapters::Table
- ActiveRecord::ConnectionAdapters::TableDefinition
- ActiveRecord::ConnectionNotEstablished
- ActiveRecord::ConnectionTimeoutError
- ActiveRecord::CounterCache
- ActiveRecord::DangerousAttributeError
- ActiveRecord::DynamicFinderMatch
- ActiveRecord::DynamicScopeMatch
- ActiveRecord::FinderMethods
- ActiveRecord::Generators
- ActiveRecord::Generators::Migration
- ActiveRecord::Generators::MigrationGenerator
- ActiveRecord::Generators::ModelGenerator
- ActiveRecord::Generators::ObserverGenerator
- ActiveRecord::Generators::SessionMigrationGenerator
- ActiveRecord::InvalidForeignKey
- ActiveRecord::IrreversibleMigration
- ActiveRecord::Locking
- ActiveRecord::Locking::Optimistic
- ActiveRecord::Locking::Optimistic::ClassMethods
- ActiveRecord::Locking::Pessimistic
- ActiveRecord::LogSubscriber
- ActiveRecord::Migration
- ActiveRecord::MigrationProxy
- ActiveRecord::MultiparameterAssignmentErrors
- ActiveRecord::NamedScope
- ActiveRecord::NamedScope::ClassMethods
- ActiveRecord::NestedAttributes
- ActiveRecord::NestedAttributes::ClassMethods
- ActiveRecord::NestedAttributes::TooManyRecords
- ActiveRecord::Observer
- ActiveRecord::Persistence
- ActiveRecord::PredicateBuilder
- ActiveRecord::PreparedStatementInvalid
- ActiveRecord::QueryCache
- ActiveRecord::QueryCache::ClassMethods
- ActiveRecord::QueryMethods
- ActiveRecord::Railtie
- ActiveRecord::Railties
- ActiveRecord::Railties::ControllerRuntime
- ActiveRecord::Railties::ControllerRuntime::ClassMethods
- ActiveRecord::ReadOnlyRecord
- ActiveRecord::RecordInvalid
- ActiveRecord::RecordNotFound
- ActiveRecord::RecordNotSaved
- ActiveRecord::RecordNotUnique
- ActiveRecord::Reflection
- ActiveRecord::Reflection::ClassMethods
- ActiveRecord::Reflection::MacroReflection
- ActiveRecord::Relation
- ActiveRecord::Rollback
- ActiveRecord::Schema
- ActiveRecord::Serialization
- ActiveRecord::SerializationTypeMismatch
- ActiveRecord::SessionStore
- ActiveRecord::SessionStore::Session
- ActiveRecord::SessionStore::SqlBypass
- ActiveRecord::SpawnMethods
- ActiveRecord::StaleObjectError
- ActiveRecord::StatementInvalid
- ActiveRecord::TestFixtures
- ActiveRecord::TestFixtures::ClassMethods
- ActiveRecord::ThrowResult
- ActiveRecord::Timestamp
- ActiveRecord::Transactions
- ActiveRecord::Transactions::ClassMethods
- ActiveRecord::UnknownAttributeError
- ActiveRecord::Validations
- ActiveRecord::Validations::AssociatedValidator
- ActiveRecord::Validations::ClassMethods
- ActiveRecord::Validations::UniquenessValidator
- ActiveRecord::WrappedDatabaseException
- <
- Fixtures
- FixturesFileNotFound

No matching classes.

# ActiveRecord::TestFixtures::ClassMethods

### Public Instance Methods

fixtures(*table_names) click to toggle source

    # File lib/active_record/fixtures.rb, line 848
    def fixtures(*table_names)
      if table_names.first == :all
        table_names = Dir["#{fixture_path}/**/*.{yml,csv}"]
        table_names.map! { |f| f[(fixture_path.size + 1)..-5] }
      else
        table_names = table_names.flatten.map { |n| n.to_s }
      end

      self.fixture_table_names |= table_names
      require_fixture_classes(table_names)
      setup_fixture_accessors(table_names)
    end

require_fixture_classes(table_names = nil) click to toggle source

    # File lib/active_record/fixtures.rb, line 873
    def require_fixture_classes(table_names = nil)
      (table_names || fixture_table_names).each do |table_name|
        file_name = table_name.to_s
        file_name = file_name.singularize if ActiveRecord::Base.pluralize_table_names
        try_to_load_dependency(file_name)
      end
    end

set_fixture_class(class_names = {}) click to toggle source

    # File lib/active_record/fixtures.rb, line 844
    def set_fixture_class(class_names = {})
      self.fixture_class_names = self.fixture_class_names.merge(class_names)
    end

setup_fixture_accessors(table_names = nil) click to toggle source

    # File lib/active_record/fixtures.rb, line 881
    def setup_fixture_accessors(table_names = nil)
      table_names = Array.wrap(table_names || fixture_table_names)
      table_names.each do |table_name|
        table_name = table_name.to_s.tr('./', '_')

        redefine_method(table_name) do |*fixtures|
          force_reload = fixtures.pop if fixtures.last == true || fixtures.last == :reload

          @fixture_cache[table_name] ||= {}

          instances = fixtures.map do |fixture|
            @fixture_cache[table_name].delete(fixture) if force_reload

            if @loaded_fixtures[table_name][fixture.to_s]
              @fixture_cache[table_name][fixture] ||= @loaded_fixtures[table_name][fixture.to_s].find
            else
              raise StandardError, "No fixture with name '#{fixture}' found for table '#{table_name}'"
            end
          end

          instances.size == 1 ? instances.first : instances
        end
        private table_name
      end
    end

try_to_load_dependency(file_name) click to toggle source

    # File lib/active_record/fixtures.rb, line 861
    def try_to_load_dependency(file_name)
      require_dependency file_name
    rescue LoadError => e
      # Let's hope the developer has included it himself

      # Let's warn in case this is a subdependency, otherwise
      # subdependency error messages are totally cryptic
      if ActiveRecord::Base.logger
        ActiveRecord::Base.logger.warn("Unable to load #{file_name}, underlying cause #{e.message} \n\n #{e.backtrace.join("\n")}")
      end
    end

uses_transaction(*methods) click to toggle source

    # File lib/active_record/fixtures.rb, line 907
    def uses_transaction(*methods)
      @uses_transaction = [] unless defined?(@uses_transaction)
      @uses_transaction.concat methods.map { |m| m.to_s }
    end

uses_transaction?(method) click to toggle source

    # File lib/active_record/fixtures.rb, line 912
    def uses_transaction?(method)
      @uses_transaction = [] unless defined?(@uses_transaction)
      @uses_transaction.include?(method.to_s)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.