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/test/cases/enum_test.rb | 6 ++++++ activerecord/test/fixtures/books.yml | 5 +++++ 2 files changed, 11 insertions(+) (limited to 'activerecord/test') 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" -- cgit v1.2.3