mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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
This commit is contained in:
parent
0332d882b6
commit
2383a60443
3 changed files with 20 additions and 8 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* 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]
|
||||
|
||||
* Fix quoting of inheritance column for STI eager loading #4098 [Jonathan Viney <jonathan@bluewire.net.nz>]
|
||||
|
||||
* Added smarter table aliasing for eager associations for multiple self joins #3580 [Rick Olson]
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ require 'fixtures/company'
|
|||
require 'fixtures/task'
|
||||
require 'fixtures/reply'
|
||||
require 'fixtures/joke'
|
||||
require 'fixtures/category'
|
||||
|
||||
class FixturesTest < Test::Unit::TestCase
|
||||
self.use_instantiated_fixtures = true
|
||||
|
@ -332,9 +333,13 @@ class SetTableNameFixturesTest < Test::Unit::TestCase
|
|||
assert_kind_of Joke, funny_jokes(:a_joke)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class InvalidTableNameFixturesTest < Test::Unit::TestCase
|
||||
fixtures :funny_jokes
|
||||
|
||||
def test_raises_error
|
||||
assert_raises FixtureClassNotFound do
|
||||
funny_jokes(:a_joke)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue