From 081b36c6ce799f2e4c755bdaf2fa978c9e494567 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 10 May 2011 10:42:03 -0700 Subject: fixture file will validate fixture format --- activerecord/lib/active_record/fixtures/file.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'activerecord/lib') 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 -- cgit v1.2.3