diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-09-09 15:16:41 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-09-09 15:16:41 -0700 |
commit | 0c5d0beac1f2479600993fb0c1ede36d7b9f1f81 (patch) | |
tree | 0e8fb2bdc2215b61dda96a3cfd69adf91ec1ed43 /activerecord | |
parent | 7a30bb112f81eec318d181d4c10f5ced58e4c082 (diff) | |
download | rails-0c5d0beac1f2479600993fb0c1ede36d7b9f1f81.tar.gz rails-0c5d0beac1f2479600993fb0c1ede36d7b9f1f81.tar.bz2 rails-0c5d0beac1f2479600993fb0c1ede36d7b9f1f81.zip |
let the class cache object clean up user input
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/fixtures.rb | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 65648d82af..9a26e5df3f 100644 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -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, |