aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2007-02-25 17:31:43 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2007-02-25 17:31:43 +0000
commit87b7b5b3e74cb6ce3efc7e472c933bf846b26cc3 (patch)
tree21aa7e606c4c0c317e671ef771cab37e0f740da8 /activerecord
parent781985f7f229eb665b3eed693eb9642caebc44a0 (diff)
downloadrails-87b7b5b3e74cb6ce3efc7e472c933bf846b26cc3.tar.gz
rails-87b7b5b3e74cb6ce3efc7e472c933bf846b26cc3.tar.bz2
rails-87b7b5b3e74cb6ce3efc7e472c933bf846b26cc3.zip
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]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6227 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/fixtures.rb15
-rw-r--r--activerecord/test/fixtures/all/developers.yml0
-rw-r--r--activerecord/test/fixtures/all/people.csv0
-rw-r--r--activerecord/test/fixtures/all/tasks.yml0
-rwxr-xr-xactiverecord/test/fixtures_test.rb9
6 files changed, 23 insertions, 3 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index dade34a38b..93ae6e9c36 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Added fixtures :all as a way of loading all fixtures in the fixture directory at once #7214 [manfred]
+
* Added database connection as a yield parameter to ActiveRecord::Base.transaction so you can manually rollback [DHH]. Example:
transaction do |transaction|
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb
index cf05b63779..92c4647819 100755
--- a/activerecord/lib/active_record/fixtures.rb
+++ b/activerecord/lib/active_record/fixtures.rb
@@ -244,12 +244,15 @@ class Fixtures < YAML::Omap
def self.create_fixtures(fixtures_directory, table_names, class_names = {})
table_names = [table_names].flatten.map { |n| n.to_s }
- connection = block_given? ? yield : ActiveRecord::Base.connection
+ connection = block_given? ? yield : ActiveRecord::Base.connection
+
ActiveRecord::Base.silence do
fixtures_map = {}
+
fixtures = table_names.map do |table_name|
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))
end
+
all_loaded_fixtures.merge! fixtures_map
connection.transaction(Thread.current['open_transactions'] == 0) do
@@ -291,8 +294,8 @@ class Fixtures < YAML::Omap
end
end
- private
+ private
def read_fixture_files
if File.file?(yaml_file_path)
# YAML fixtures
@@ -460,7 +463,13 @@ module Test #:nodoc:
end
def self.fixtures(*table_names)
- table_names = table_names.flatten.map { |n| n.to_s }
+ if table_names.first == :all
+ table_names = Dir["#{fixture_path}/*.yml"] + Dir["#{fixture_path}/*.csv"]
+ table_names.map! { |f| File.basename(f).split('.')[0..-2].join('.') }
+ 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)
diff --git a/activerecord/test/fixtures/all/developers.yml b/activerecord/test/fixtures/all/developers.yml
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/activerecord/test/fixtures/all/developers.yml
diff --git a/activerecord/test/fixtures/all/people.csv b/activerecord/test/fixtures/all/people.csv
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/activerecord/test/fixtures/all/people.csv
diff --git a/activerecord/test/fixtures/all/tasks.yml b/activerecord/test/fixtures/all/tasks.yml
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/activerecord/test/fixtures/all/tasks.yml
diff --git a/activerecord/test/fixtures_test.rb b/activerecord/test/fixtures_test.rb
index 35882526a1..7ccfc9be86 100755
--- a/activerecord/test/fixtures_test.rb
+++ b/activerecord/test/fixtures_test.rb
@@ -399,3 +399,12 @@ class FixturesBrokenRollbackTest < Test::Unit::TestCase
raise 'argh'
end
end
+
+class LoadAllFixturesTest < Test::Unit::TestCase
+ write_inheritable_attribute :fixture_path, File.join(File.dirname(__FILE__), '/fixtures/all')
+ fixtures :all
+
+ def test_all_there
+ assert_equal %w(developers people tasks), fixture_table_names.sort
+ end
+end