mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Removing instances of string class_names in fixtures.
Also, constantizing the default_fixture_model_name when it gets loaded in from the file. Later, when the class_name is passed to a new FixtureSet, a deprecation warning will occur if the class_name is a string.
This commit is contained in:
parent
539180cf8e
commit
bac384e85f
3 changed files with 14 additions and 11 deletions
|
@ -455,7 +455,7 @@ module ActiveRecord
|
|||
fixtures_map[fs_name] = new( # ActiveRecord::FixtureSet.new
|
||||
connection,
|
||||
fs_name,
|
||||
class_names[fs_name] || default_fixture_model_name(fs_name),
|
||||
class_names[fs_name] || (default_fixture_model_name(fs_name).safe_constantize),
|
||||
::File.join(fixtures_directory, fs_name))
|
||||
end
|
||||
|
||||
|
@ -504,11 +504,14 @@ module ActiveRecord
|
|||
@name = name
|
||||
@path = path
|
||||
|
||||
if class_name.is_a?(String)
|
||||
ActiveSupport::Deprecation.warn("The ability to pass in strings as a class name will be removed in Rails 4.2, consider using the class itself instead.")
|
||||
end
|
||||
|
||||
if class_name.is_a?(Class) # TODO: Should be an AR::Base type class, or any?
|
||||
@model_class = class_name
|
||||
else
|
||||
ActiveSupport::Deprecation.warn("The ability to pass in strings as a class name will be removed in Rails 4.1, consider using the class itself instead.")
|
||||
@model_class = class_name.constantize rescue nil
|
||||
@model_class = class_name.safe_constantize if class_name
|
||||
end
|
||||
|
||||
@connection = ( model_class.respond_to?(:connection) ?
|
||||
|
|
|
@ -190,11 +190,11 @@ class FixturesTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_empty_yaml_fixture
|
||||
assert_not_nil ActiveRecord::FixtureSet.new( Account.connection, "accounts", 'Account', FIXTURES_ROOT + "/naked/yml/accounts")
|
||||
assert_not_nil ActiveRecord::FixtureSet.new( Account.connection, "accounts", Account, FIXTURES_ROOT + "/naked/yml/accounts")
|
||||
end
|
||||
|
||||
def test_empty_yaml_fixture_with_a_comment_in_it
|
||||
assert_not_nil ActiveRecord::FixtureSet.new( Account.connection, "companies", 'Company', FIXTURES_ROOT + "/naked/yml/companies")
|
||||
assert_not_nil ActiveRecord::FixtureSet.new( Account.connection, "companies", Company, FIXTURES_ROOT + "/naked/yml/companies")
|
||||
end
|
||||
|
||||
def test_nonexistent_fixture_file
|
||||
|
@ -204,19 +204,19 @@ class FixturesTest < ActiveRecord::TestCase
|
|||
assert Dir[nonexistent_fixture_path+"*"].empty?
|
||||
|
||||
assert_raise(Errno::ENOENT) do
|
||||
ActiveRecord::FixtureSet.new( Account.connection, "companies", 'Company', nonexistent_fixture_path)
|
||||
ActiveRecord::FixtureSet.new( Account.connection, "companies", Company, nonexistent_fixture_path)
|
||||
end
|
||||
end
|
||||
|
||||
def test_dirty_dirty_yaml_file
|
||||
assert_raise(ActiveRecord::Fixture::FormatError) do
|
||||
ActiveRecord::FixtureSet.new( Account.connection, "courses", 'Course', FIXTURES_ROOT + "/naked/yml/courses")
|
||||
ActiveRecord::FixtureSet.new( Account.connection, "courses", Course, FIXTURES_ROOT + "/naked/yml/courses")
|
||||
end
|
||||
end
|
||||
|
||||
def test_omap_fixtures
|
||||
assert_nothing_raised do
|
||||
fixtures = ActiveRecord::FixtureSet.new(Account.connection, 'categories', 'Category', FIXTURES_ROOT + "/categories_ordered")
|
||||
fixtures = ActiveRecord::FixtureSet.new(Account.connection, 'categories', Category, FIXTURES_ROOT + "/categories_ordered")
|
||||
|
||||
fixtures.each.with_index do |(name, fixture), i|
|
||||
assert_equal "fixture_no_#{i}", name
|
||||
|
@ -449,7 +449,7 @@ class OverRideFixtureMethodTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
class CheckSetTableNameFixturesTest < ActiveRecord::TestCase
|
||||
set_fixture_class :funny_jokes => 'Joke'
|
||||
set_fixture_class :funny_jokes => Joke
|
||||
fixtures :funny_jokes
|
||||
# Set to false to blow away fixtures cache and ensure our fixtures are loaded
|
||||
# and thus takes into account our set_fixture_class
|
||||
|
@ -532,7 +532,7 @@ class InvalidTableNameFixturesTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
class CheckEscapedYamlFixturesTest < ActiveRecord::TestCase
|
||||
set_fixture_class :funny_jokes => 'Joke'
|
||||
set_fixture_class :funny_jokes => Joke
|
||||
fixtures :funny_jokes
|
||||
# Set to false to blow away fixtures cache and ensure our fixtures are loaded
|
||||
# and thus takes into account our set_fixture_class
|
||||
|
|
|
@ -181,7 +181,7 @@ definition:
|
|||
|
||||
```ruby
|
||||
class FunnyJoke < ActiveSupport::TestCase
|
||||
set_fixture_class funny_jokes: 'Joke'
|
||||
set_fixture_class funny_jokes: Joke
|
||||
fixtures :funny_jokes
|
||||
...
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue