From eff3a3178e93405d9af06acbb1e269489d650cb7 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Thu, 2 Jul 2015 15:42:52 -0400 Subject: Use default model enum in fixtures if not defined After 908cfef was introduced fixtures that did not set an enum would return nil instead of the default enum value. The fixtures should assume the default if a different enum is not defined. The change checks first if the enum is defined in the fixture before setting it based on the fixture. --- activerecord/lib/active_record/fixtures.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index b01444a090..d062dd9e34 100644 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -645,7 +645,9 @@ module ActiveRecord # Resolve enums model_class.defined_enums.each do |name, values| - row[name] = values.fetch(row[name], row[name]) + if row.include?(name) + row[name] = values.fetch(row[name], row[name]) + end end # If STI is used, find the correct subclass for association reflection -- cgit v1.2.3