1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

19 commits

Author SHA1 Message Date
Sean Griffin
4e7217027f Add YAML compatibility for objects from Rails 4.2
As of Ruby 2.2, Psych can handle any object which is marshallable. This
was not true on previous versions of Ruby, so our delegator types had to
provide their own implementation of `init_with` and `encode_with`.
Unfortunately, this doesn't match up with what Psych will do today.

Since by the time we hit this layer, the objects will have already been
created, I think it makes the most sense to just grab the current type
from the class.
2015-03-10 11:56:45 -06:00
Sean Griffin
afc124c3b4 Attempt to provide backwards compatible YAML deserialization
I should have done this in the first place. We are now serializing an
explicit version so we can make more careful changes in the future. This
will load Active Record objects which were serialized in Rails 4.1.

There will be bugs, as YAML serialization was at least partially broken
back then. There will also be edge cases that we might not be able to
handle, especially if the type of a column has changed.

In addition, we're passing this as `from_database`, since that is
required for serialized columns at minimum. All other types were
serializing the cast value. At a glance, there should be no types for
which this is a problem.

Finally, dirty checking information will be lost on records serialized
in 4.1, so no columns will be marked as changed.
2015-03-10 11:56:45 -06:00
Gustavo Beathyate
b8e8096a89 Implement required #encode_with
While running the spec `ARCONN=mysql2 ruby -v -Itest
test/cases/yaml_serialization_test.rb`
the following warning shows up:
`implementing to_yaml is deprecated, please implement "encode_with"`
2014-07-15 15:50:29 -05:00
Sean Griffin
47f1c10c8f Keep the types of virtual columns after yaml serialization
On MySQL and PostgreSQL, the adapter does not type cast virtual columns
for us.
2014-06-10 08:42:47 -06:00
Sean Griffin
e08494a912 New records should remain new after yaml serialization 2014-06-01 17:52:46 -06:00
Sean Griffin
93734629a3 Don't change values in @raw_attributes during serialization
During `init_with`, the attributes given to the coder will be placed
into `@raw_attributes`. As such, we should read from `@raw_attributes`
when encoding, rather than `@attributes`, which has been type cast.
2014-06-01 10:55:23 -06:00
Ivan Antropov
0c89d316ab Add test for ActiveRecord::Relation YAML serialization, for #5303 issue 2013-11-03 21:35:44 +07:00
Yves Senn
abe91cb3bf prevent global timezone state from leaking out of test cases. 2013-10-25 14:40:57 +02:00
Rafael Mendonça França
7d26fad384 No need to require psych since require yaml does that. 2012-01-04 14:29:13 -03:00
Rafael Mendonça França
761b049b2e No need to use rescue block to require psych 2012-01-04 13:30:57 -03:00
Jon Leighton
e2b6919223 stop test resetting global state 2011-12-23 23:22:24 +00:00
Jon Leighton
52eedf5e2b Add hackery to make Syck use encode_with/init_with. Fixes 1.8 after recent changes to attribute serialization. 2011-12-01 01:15:16 +00:00
Aaron Patterson
61774e0d49 please use ruby -I lib:test path/to/test.rb, or export RUBY_OPT 2011-06-06 15:47:13 -07:00
Jon Leighton
253bb6b926 Refactor Active Record test connection setup. Please see the RUNNING_UNIT_TESTS file for details, but essentially you can now configure things in test/config.yml. You can also run tests directly via the command line, e.g. ruby path/to/test.rb (no rake needed, uses default db connection from test/config.yml). This will help us fix the CI by enabling us to isolate the different Rails versions to different databases. 2011-06-04 23:47:03 +01:00
Aaron Patterson
eba8411652 adding an encode_with method for Psych dump/load methods 2011-01-05 14:59:19 -08:00
Aaron Patterson
97bc74c746 make sure new objects can round trip 2011-01-05 14:03:13 -08:00
Aaron Patterson
6d74710828 make sure that Psych can roundtrip an AR object 2011-01-05 14:01:47 -08:00
Aaron Patterson
da6ce2e253 adding a test for YAML round trip 2010-12-02 08:44:48 -08:00
Serguei Filimonov
2ae8300489 Added #to_i to DateTime in ActiveSupport so #to_yaml works correctly on ActiveRecord models with DateTime attributes. 2009-12-15 08:15:21 -06:00