aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-05-10 10:42:03 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-05-23 15:06:12 -0700
commit081b36c6ce799f2e4c755bdaf2fa978c9e494567 (patch)
tree5b8c74ae96d10764e7b5f24bdaf4dcfc36be92b6 /activerecord/lib
parent5278af3d8efbe348864baca0c40a532e8b137ce1 (diff)
downloadrails-081b36c6ce799f2e4c755bdaf2fa978c9e494567.tar.gz
rails-081b36c6ce799f2e4c755bdaf2fa978c9e494567.tar.bz2
rails-081b36c6ce799f2e4c755bdaf2fa978c9e494567.zip
fixture file will validate fixture format
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/fixtures/file.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/fixtures/file.rb b/activerecord/lib/active_record/fixtures/file.rb
index beda5a65df..da07cf5da1 100644
--- a/activerecord/lib/active_record/fixtures/file.rb
+++ b/activerecord/lib/active_record/fixtures/file.rb
@@ -34,12 +34,19 @@ module ActiveRecord
return @rows if @rows
data = YAML.load(render(IO.read(@file)))
- @rows = data ? data.to_a : []
+ @rows = data ? validate(data).to_a : []
end
def render(content)
ERB.new(content).result
end
+
+ # Validate our unmarshalled data.
+ def validate(data)
+ raise Fixture::FormatError, 'fixture is not a hash' unless Hash === data
+ raise Fixture::FormatError unless data.all? { |name, row| Hash === row }
+ data
+ end
end
end
end