aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/fixtures.rb
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2006-03-06 23:03:35 +0000
committerRick Olson <technoweenie@gmail.com>2006-03-06 23:03:35 +0000
commit2383a60443244dedd4b8708a2ecac922dcffc786 (patch)
tree43d205419086b7978409ea6e558aa80cbc02bcfb /activerecord/lib/active_record/fixtures.rb
parent0332d882b6d6157c6983d1d78e4f5636fdb45229 (diff)
downloadrails-2383a60443244dedd4b8708a2ecac922dcffc786.tar.gz
rails-2383a60443244dedd4b8708a2ecac922dcffc786.tar.bz2
rails-2383a60443244dedd4b8708a2ecac922dcffc786.zip
Allow set_fixture_class to take Classes instead of strings for a class in a module. Raise FixtureClassNotFound if a fixture can't load. [Rick Olson] closes #4095
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3804 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/fixtures.rb')
-rwxr-xr-xactiverecord/lib/active_record/fixtures.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb
index 57d286aecd..71a28f4712 100755
--- a/activerecord/lib/active_record/fixtures.rb
+++ b/activerecord/lib/active_record/fixtures.rb
@@ -9,6 +9,9 @@ module YAML #:nodoc:
end
end
+class FixtureClassNotFound < ActiveRecord::ActiveRecordError #:nodoc:
+end
+
# Fixtures are a way of organizing data that you want to test against; in short, sample data. They come in 3 flavours:
#
# 1. YAML fixtures
@@ -391,9 +394,11 @@ class Fixture #:nodoc:
end
def find
- if Object.const_defined?(@class_name)
- klass = Object.const_get(@class_name)
+ klass = @class_name.is_a?(Class) ? @class_name : Object.const_get(@class_name) rescue nil
+ if klass
klass.find(self[klass.primary_key])
+ else
+ raise FixtureClassNotFound, "The class #{@class_name.inspect} was not found."
end
end