mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Aesthetic
This commit is contained in:
parent
6bc179075d
commit
5977e7e4d5
3 changed files with 13 additions and 13 deletions
|
@ -1,4 +1,4 @@
|
|||
* ActiveRecord objects can now be correctly dumped, loaded and dumped again without issues.
|
||||
* Active Record objects can now be correctly dumped, loaded and dumped again without issues.
|
||||
|
||||
Previously, if you did `YAML.dump`, `YAML.load` and then `YAML.dump` again
|
||||
in an ActiveRecord model that used serialization it would fail at the last
|
||||
|
|
|
@ -76,7 +76,6 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
class Attribute < Struct.new(:coder, :value, :state) # :nodoc:
|
||||
|
||||
def unserialized_value(v = value)
|
||||
state == :serialized ? unserialize(v) : value
|
||||
end
|
||||
|
@ -167,7 +166,7 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def attributes_for_coder
|
||||
attribute_names.each_with_object({}) do |name,attrs|
|
||||
attribute_names.each_with_object({}) do |name, attrs|
|
||||
attrs[name] = if self.class.serialized_attributes.include?(name)
|
||||
@attributes[name].serialized_value
|
||||
else
|
||||
|
|
|
@ -175,18 +175,19 @@ class StoreTest < ActiveRecord::TestCase
|
|||
"preferences" => "--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess\nremember_login: true\n",
|
||||
"json_data" => "{\"height\":\"tall\"}", "json_data_empty"=>"{\"is_a_good_guy\":true}",
|
||||
"params" => "--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess {}\n",
|
||||
"account_id"=> @john.account_id }
|
||||
"account_id"=> @john.account_id
|
||||
}
|
||||
|
||||
assert_equal attributes, @john.attributes_for_coder
|
||||
end
|
||||
|
||||
test "dump, load and dump again a model" do
|
||||
dumped = YAML.dump( @john )
|
||||
loaded = YAML.load( dumped )
|
||||
dumped = YAML.dump(@john)
|
||||
loaded = YAML.load(dumped)
|
||||
assert_equal @john, loaded
|
||||
|
||||
second_dump = YAML.dump( loaded )
|
||||
second_dump = YAML.dump(loaded)
|
||||
assert_equal dumped, second_dump
|
||||
assert_equal @john, YAML.load( second_dump )
|
||||
assert_equal @john, YAML.load(second_dump)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue