Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6227

Show
Ignore:
Timestamp:
02/25/07 17:31:43 (2 years ago)
Author:
david
Message:

Added fixtures :all to test_helper.rb to assume that most people just want all their fixtures loaded all the time [DHH] Added fixtures :all as a way of loading all fixtures in the fixture directory at once (closes #7214) [manfred]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r6196 r6227  
    11*SVN* 
     2 
     3* Added fixtures :all as a way of loading all fixtures in the fixture directory at once #7214 [manfred] 
    24 
    35* Added database connection as a yield parameter to ActiveRecord::Base.transaction so you can manually rollback [DHH]. Example: 
  • trunk/activerecord/lib/active_record/fixtures.rb

    r6023 r6227  
    245245  def self.create_fixtures(fixtures_directory, table_names, class_names = {}) 
    246246    table_names = [table_names].flatten.map { |n| n.to_s } 
    247     connection = block_given? ? yield : ActiveRecord::Base.connection 
     247    connection  = block_given? ? yield : ActiveRecord::Base.connection 
     248 
    248249    ActiveRecord::Base.silence do 
    249250      fixtures_map = {} 
     251 
    250252      fixtures = table_names.map do |table_name| 
    251253        fixtures_map[table_name] = Fixtures.new(connection, File.split(table_name.to_s).last, class_names[table_name.to_sym], File.join(fixtures_directory, table_name.to_s)) 
    252254      end                
     255 
    253256      all_loaded_fixtures.merge! fixtures_map   
    254257 
     
    292295  end 
    293296 
     297 
    294298  private 
    295  
    296299    def read_fixture_files 
    297300      if File.file?(yaml_file_path) 
     
    461464       
    462465      def self.fixtures(*table_names) 
    463         table_names = table_names.flatten.map { |n| n.to_s } 
     466        if table_names.first == :all 
     467          table_names = Dir["#{fixture_path}/*.yml"] + Dir["#{fixture_path}/*.csv"] 
     468          table_names.map! { |f| File.basename(f).split('.')[0..-2].join('.') } 
     469        else 
     470          table_names = table_names.flatten.map { |n| n.to_s } 
     471        end 
     472 
    464473        self.fixture_table_names |= table_names 
    465474        require_fixture_classes(table_names) 
  • trunk/activerecord/test/fixtures_test.rb

    r6023 r6227  
    400400    end 
    401401end 
     402 
     403class LoadAllFixturesTest < Test::Unit::TestCase 
     404  write_inheritable_attribute :fixture_path, File.join(File.dirname(__FILE__), '/fixtures/all') 
     405  fixtures :all 
     406 
     407  def test_all_there 
     408    assert_equal %w(developers people tasks), fixture_table_names.sort 
     409  end 
     410end 
  • trunk/railties/CHANGELOG

    r6212 r6227  
    11*SVN* 
     2 
     3* Added fixtures :all to test_helper.rb to assume that most people just want all their fixtures loaded all the time [DHH] 
    24 
    35* Added config/initializers where all ruby files within it are automatically loaded after the Rails configuration is done, so you don't have to litter the environment.rb file with a ton of mixed stuff [DHH] 
  • trunk/railties/helpers/test_helper.rb

    r2801 r6227  
    2525  self.use_instantiated_fixtures  = false 
    2626 
     27  # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. 
     28  # If you need to control the loading order (due to foreign key constraints etc), you'll 
     29  # need to change this line to explicitly name the order you desire. 
     30  fixtures :all 
     31 
    2732  # Add more helper methods to be used by all tests here... 
    2833end