mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
let the class cache object clean up user input
This commit is contained in:
parent
7a30bb112f
commit
0c5d0beac1
1 changed files with 20 additions and 8 deletions
|
@ -440,23 +440,35 @@ module ActiveRecord
|
|||
def initialize(class_names, config)
|
||||
@class_names = class_names.stringify_keys
|
||||
@config = config
|
||||
|
||||
# Remove string values that aren't constants or subclasses of AR
|
||||
@class_names.delete_if { |k,klass|
|
||||
unless klass.is_a? Class
|
||||
klass = klass.safe_constantize
|
||||
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
|
||||
!insert_class(@class_names, k, klass)
|
||||
}
|
||||
end
|
||||
|
||||
def [](fs_name)
|
||||
@class_names.fetch(fs_name) {
|
||||
klass = default_fixture_model(fs_name, @config).safe_constantize
|
||||
|
||||
# We only want to deal with AR objects.
|
||||
if klass && klass < ActiveRecord::Base
|
||||
@class_names[fs_name] = klass
|
||||
else
|
||||
@class_names[fs_name] = nil
|
||||
end
|
||||
insert_class(@class_names, fs_name, klass)
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def insert_class(class_names, name, klass)
|
||||
# We only want to deal with AR objects.
|
||||
if klass && klass < ActiveRecord::Base
|
||||
class_names[name] = klass
|
||||
else
|
||||
class_names[name] = nil
|
||||
end
|
||||
end
|
||||
|
||||
def default_fixture_model(fs_name, config)
|
||||
ActiveRecord::FixtureSet.default_fixture_model_name(fs_name, config)
|
||||
end
|
||||
|
@ -479,7 +491,7 @@ module ActiveRecord
|
|||
|
||||
fixture_sets = files_to_read.map do |fs_name|
|
||||
klass = class_names[fs_name]
|
||||
conn = klass.respond_to?(:connection) ? klass.connection : connection
|
||||
conn = klass ? klass.connection : connection
|
||||
fixtures_map[fs_name] = new( # ActiveRecord::FixtureSet.new
|
||||
conn,
|
||||
fs_name,
|
||||
|
|
Loading…
Reference in a new issue