mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #41516 from kamipo/serialized_value_should_be_type_casted_by_subtype
Serialized value on the enum attribute should be type casted by the subtype
This commit is contained in:
commit
8c590afc7c
2 changed files with 9 additions and 1 deletions
|
@ -140,7 +140,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def serialize(value)
|
def serialize(value)
|
||||||
mapping.fetch(value, value)
|
subtype.serialize(mapping.fetch(value, value))
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_valid_value(value)
|
def assert_valid_value(value)
|
||||||
|
|
|
@ -92,6 +92,14 @@ class EnumTest < ActiveRecord::TestCase
|
||||||
assert_equal books(:ddd), Book.where(last_read: "forgotten").first
|
assert_equal books(:ddd), Book.where(last_read: "forgotten").first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "find via where should be type casted" do
|
||||||
|
book = Book.enabled.create!
|
||||||
|
assert_predicate book, :enabled?
|
||||||
|
|
||||||
|
enabled = Book.boolean_statuses[:enabled].to_s
|
||||||
|
assert_equal book, Book.where(boolean_status: enabled).last
|
||||||
|
end
|
||||||
|
|
||||||
test "build from scope" do
|
test "build from scope" do
|
||||||
assert_predicate Book.written.build, :written?
|
assert_predicate Book.written.build, :written?
|
||||||
assert_not_predicate Book.written.build, :proposed?
|
assert_not_predicate Book.written.build, :proposed?
|
||||||
|
|
Loading…
Reference in a new issue