mirror of https://github.com/rails/rails
Merge pull request #42855 from kamipo/fix_to_json
Fix `to_json` after `changes_applied` for `ActiveModel::Dirty` object
This commit is contained in:
commit
2a6459d8ca
|
@ -141,7 +141,7 @@ module ActiveModel
|
|||
end
|
||||
|
||||
def as_json(options = {}) # :nodoc:
|
||||
options[:except] = [options[:except], "mutations_from_database"].flatten
|
||||
options[:except] = [*options[:except], "mutations_from_database", "mutations_before_last_save"]
|
||||
super(options)
|
||||
end
|
||||
|
||||
|
|
|
@ -244,13 +244,19 @@ class DirtyTest < ActiveModel::TestCase
|
|||
assert_equal "{\"name\":\"Dmitry\",\"color\":null,\"size\":null,\"status\":\"initialized\"}", @model.to_json
|
||||
end
|
||||
|
||||
test "to_json should work on model with :except string option " do
|
||||
test "to_json should work on model with :except string option" do
|
||||
@model.name = "Dmitry"
|
||||
assert_equal "{\"color\":null,\"size\":null,\"status\":\"initialized\"}", @model.to_json(except: "name")
|
||||
end
|
||||
|
||||
test "to_json should work on model with :except array option " do
|
||||
test "to_json should work on model with :except array option" do
|
||||
@model.name = "Dmitry"
|
||||
assert_equal "{\"color\":null,\"size\":null,\"status\":\"initialized\"}", @model.to_json(except: ["name"])
|
||||
end
|
||||
|
||||
test "to_json should work on model after save" do
|
||||
@model.name = "Dmitry"
|
||||
@model.save
|
||||
assert_equal "{\"name\":\"Dmitry\",\"color\":null,\"size\":null,\"status\":\"initialized\"}", @model.to_json
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue