aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/fixtures.rb4
-rw-r--r--activerecord/test/cases/enum_test.rb6
-rw-r--r--activerecord/test/fixtures/books.yml5
3 files changed, 14 insertions, 1 deletions
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
diff --git a/activerecord/test/cases/enum_test.rb b/activerecord/test/cases/enum_test.rb
index 769b171717..ba23049a92 100644
--- a/activerecord/test/cases/enum_test.rb
+++ b/activerecord/test/cases/enum_test.rb
@@ -405,4 +405,10 @@ class EnumTest < ActiveRecord::TestCase
assert_not @book.in_spanish?
assert_not @book.in_french?
end
+
+ test "uses default status when no status is provided in fixtures" do
+ book = books(:tlg)
+ assert book.proposed?, "expected fixture to default to proposed status"
+ assert book.in_english?, "expected fixture to default to english language"
+ end
end
diff --git a/activerecord/test/fixtures/books.yml b/activerecord/test/fixtures/books.yml
index 93cfabd61c..1f75e3fb52 100644
--- a/activerecord/test/fixtures/books.yml
+++ b/activerecord/test/fixtures/books.yml
@@ -24,3 +24,8 @@ ddd:
name: "Domain-Driven Design"
format: "hardcover"
status: 2
+
+tlg:
+ author_id: 1
+ id: 4
+ name: "Thoughleadering"