Changeset 6227
- Timestamp:
- 02/25/07 17:31:43 (2 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/fixtures.rb (modified) (3 diffs)
- trunk/activerecord/test/fixtures_test.rb (modified) (1 diff)
- trunk/activerecord/test/fixtures/all (added)
- trunk/activerecord/test/fixtures/all/developers.yml (added)
- trunk/activerecord/test/fixtures/all/people.csv (added)
- trunk/activerecord/test/fixtures/all/tasks.yml (added)
- trunk/railties/CHANGELOG (modified) (1 diff)
- trunk/railties/helpers/test_helper.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r6196 r6227 1 1 *SVN* 2 3 * Added fixtures :all as a way of loading all fixtures in the fixture directory at once #7214 [manfred] 2 4 3 5 * 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 245 245 def self.create_fixtures(fixtures_directory, table_names, class_names = {}) 246 246 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 248 249 ActiveRecord::Base.silence do 249 250 fixtures_map = {} 251 250 252 fixtures = table_names.map do |table_name| 251 253 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)) 252 254 end 255 253 256 all_loaded_fixtures.merge! fixtures_map 254 257 … … 292 295 end 293 296 297 294 298 private 295 296 299 def read_fixture_files 297 300 if File.file?(yaml_file_path) … … 461 464 462 465 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 464 473 self.fixture_table_names |= table_names 465 474 require_fixture_classes(table_names) trunk/activerecord/test/fixtures_test.rb
r6023 r6227 400 400 end 401 401 end 402 403 class 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 410 end trunk/railties/CHANGELOG
r6212 r6227 1 1 *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] 2 4 3 5 * 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 25 25 self.use_instantiated_fixtures = false 26 26 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 27 32 # Add more helper methods to be used by all tests here... 28 33 end