mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix to_json
after changes_applied
for ActiveModel::Dirty
object
Follow up to #41677. Mutation tracking variables are not only `@mutations_from_database` but also `@mutations_before_last_save`.
This commit is contained in:
parent
6abe728e1d
commit
0f001f00eb
2 changed files with 9 additions and 3 deletions
|
@ -141,7 +141,7 @@ module ActiveModel
|
||||||
end
|
end
|
||||||
|
|
||||||
def as_json(options = {}) # :nodoc:
|
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)
|
super(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -244,13 +244,19 @@ class DirtyTest < ActiveModel::TestCase
|
||||||
assert_equal "{\"name\":\"Dmitry\",\"color\":null,\"size\":null,\"status\":\"initialized\"}", @model.to_json
|
assert_equal "{\"name\":\"Dmitry\",\"color\":null,\"size\":null,\"status\":\"initialized\"}", @model.to_json
|
||||||
end
|
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"
|
@model.name = "Dmitry"
|
||||||
assert_equal "{\"color\":null,\"size\":null,\"status\":\"initialized\"}", @model.to_json(except: "name")
|
assert_equal "{\"color\":null,\"size\":null,\"status\":\"initialized\"}", @model.to_json(except: "name")
|
||||||
end
|
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"
|
@model.name = "Dmitry"
|
||||||
assert_equal "{\"color\":null,\"size\":null,\"status\":\"initialized\"}", @model.to_json(except: ["name"])
|
assert_equal "{\"color\":null,\"size\":null,\"status\":\"initialized\"}", @model.to_json(except: ["name"])
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue