diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2016-01-23 08:42:40 -0700 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2016-01-23 08:44:16 -0700 |
commit | 67c1719012506c3387df067961252b5df50a97ce (patch) | |
tree | 98daecc48f5df488d8e2147e51a71d4b07d2cd6f /activerecord/test/cases | |
parent | 8de32bb25295787b68d307c74e50462cd99e6ecc (diff) | |
download | rails-67c1719012506c3387df067961252b5df50a97ce.tar.gz rails-67c1719012506c3387df067961252b5df50a97ce.tar.bz2 rails-67c1719012506c3387df067961252b5df50a97ce.zip |
Use the database type to deserialize enum
This fixes incorrect assumptions made by e991c7b that we can assume the
DB is already casting the value for us. The enum type needs additional
information to perform casting, and needs a subtype.
I've opted not to call `super` in `cast`, as we have a known set of
types which we accept there, and the subtype likely doesn't accept them
(symbol -> integer doesn't make sense)
Close #23190
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/enum_test.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/test/cases/enum_test.rb b/activerecord/test/cases/enum_test.rb index 7c930de97b..babacd1ee9 100644 --- a/activerecord/test/cases/enum_test.rb +++ b/activerecord/test/cases/enum_test.rb @@ -411,4 +411,14 @@ class EnumTest < ActiveRecord::TestCase assert book.proposed?, "expected fixture to default to proposed status" assert book.in_english?, "expected fixture to default to english language" end + + test "uses default value from database on initialization" do + book = Book.new + assert book.proposed? + end + + test "uses default value from database on initialization when using custom mapping" do + book = Book.new + assert book.hard? + end end |