aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-09-13 23:31:54 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-09-13 23:31:54 +0000
commit5589c734a87080f6a47ec2ab00797cd4ee4d9aee (patch)
tree550bf597a864e9041a2b5184ff409a6fc78232be /activerecord
parent9aeddc553874ddfd9a2527e1e21127c2a323aaee (diff)
downloadrails-5589c734a87080f6a47ec2ab00797cd4ee4d9aee.tar.gz
rails-5589c734a87080f6a47ec2ab00797cd4ee4d9aee.tar.bz2
rails-5589c734a87080f6a47ec2ab00797cd4ee4d9aee.zip
Improve yaml fixtures error reporting. Closes #6205.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5104 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/fixtures.rb29
2 files changed, 18 insertions, 13 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 9c5f3adb55..97573e272f 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Improve yaml fixtures error reporting. #6205 [Bruce Williams]
+
* Rename AR::Base#quote so people can use that name in their models. #3628 [Koz]
* Add deprecation warning for inferred foreign key. #6029 [Josh Susser]
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb
index f1aa1c1087..e5d258288d 100755
--- a/activerecord/lib/active_record/fixtures.rb
+++ b/activerecord/lib/active_record/fixtures.rb
@@ -294,21 +294,24 @@ class Fixtures < YAML::Omap
def read_fixture_files
if File.file?(yaml_file_path)
# YAML fixtures
+ yaml_string = ""
+ Dir["#{@fixture_path}/**/*.yml"].select {|f| test(?f,f) }.each do |subfixture_path|
+ yaml_string << IO.read(subfixture_path)
+ end
+ yaml_string << IO.read(yaml_file_path)
begin
- yaml_string = ""
- Dir["#{@fixture_path}/**/*.yml"].select {|f| test(?f,f) }.each do |subfixture_path|
- yaml_string << IO.read(subfixture_path)
- end
- yaml_string << IO.read(yaml_file_path)
-
- if yaml = YAML::load(erb_render(yaml_string))
- yaml = yaml.value if yaml.respond_to?(:type_id) and yaml.respond_to?(:value)
- yaml.each do |name, data|
- self[name] = Fixture.new(data, @class_name)
- end
- end
+ yaml = YAML::load(erb_render(yaml_string))
rescue Exception=>boom
raise Fixture::FormatError, "a YAML error occurred parsing #{yaml_file_path}. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html\nThe exact error was:\n #{boom.class}: #{boom}"
+ end
+ if yaml
+ yaml = yaml.value if yaml.respond_to?(:type_id) and yaml.respond_to?(:value)
+ yaml.each do |name, data|
+ unless data
+ raise Fixture::FormatError, "Bad data for #{@class_name} fixture named #{name} (nil)"
+ end
+ self[name] = Fixture.new(data, @class_name)
+ end
end
elsif File.file?(csv_file_path)
# CSV fixtures
@@ -368,7 +371,7 @@ class Fixture #:nodoc:
when String
@fixture = read_fixture_file(fixture)
else
- raise ArgumentError, "Bad fixture argument #{fixture.inspect}"
+ raise ArgumentError, "Bad fixture argument #{fixture.inspect} during creation of #{class_name} fixture"
end
@class_name = class_name