Merge pull request #36907 from wjessop/string_attribute_should_compare_with_typecast_symbol_after_update

Serialize symbols to strings in ImmutableString serialize method
This commit is contained in:
Matthew Draper 2019-09-28 18:20:08 +09:30 committed by GitHub
commit ade48853d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -9,7 +9,7 @@ module ActiveModel
def serialize(value)
case value
when ::Numeric, ActiveSupport::Duration then value.to_s
when ::Numeric, ::Symbol, ActiveSupport::Duration then value.to_s
when true then "t"
when false then "f"
else super

View File

@ -326,6 +326,13 @@ class DirtyTest < ActiveRecord::TestCase
assert_not_predicate topic, :approved_changed?
end
def test_string_attribute_should_compare_with_typecast_symbol_after_update
pirate = Pirate.create!(catchphrase: :foo)
pirate.update_column :catchphrase, :foo
pirate.catchphrase
assert_not_predicate pirate, :catchphrase_changed?
end
def test_partial_update
pirate = Pirate.new(catchphrase: "foo")
old_updated_on = 1.hour.ago.beginning_of_day