aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorGeorge Claghorn <george.claghorn@gmail.com>2015-05-15 23:27:41 -0400
committerGeorge Claghorn <george.claghorn@gmail.com>2015-05-27 21:48:58 -0400
commit908cfef6e2f2c888e02b89fc74888786efda2a45 (patch)
tree9674dec4166259eb74133c8a845bf04862db3050 /activerecord/lib/active_record
parent27fdf4591d06d11728649714bdaf0a006908861b (diff)
downloadrails-908cfef6e2f2c888e02b89fc74888786efda2a45.tar.gz
rails-908cfef6e2f2c888e02b89fc74888786efda2a45.tar.bz2
rails-908cfef6e2f2c888e02b89fc74888786efda2a45.zip
Resolve enums in test fixtures
Currently, values for columns backing Active Record enums must be specified as integers in test fixtures: awdr: title: "Agile Web Development with Rails" status: 2 rfr: title: "Ruby for Rails" status: <%= Book.statuses[:proposed] %> This is potentially confusing, since enum values are typically specified as symbols or strings in application code. To resolve the confusion, this change permits the use of symbols or strings to specify enum values: awdr: status: :published It is compatible with fixtures that specify enum values as integers.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/fixtures.rb5
1 files changed, 5 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb
index 2c1771dd6c..1ec8f818cd 100644
--- a/activerecord/lib/active_record/fixtures.rb
+++ b/activerecord/lib/active_record/fixtures.rb
@@ -644,6 +644,11 @@ module ActiveRecord
row[primary_key_name] = ActiveRecord::FixtureSet.identify(label, primary_key_type)
end
+ # Resolve enums
+ model_class.defined_enums.each do |name, values|
+ row[name] = values.fetch(row[name], row[name])
+ end
+
# If STI is used, find the correct subclass for association reflection
reflection_class =
if row.include?(inheritance_column_name)