aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/yaml_serialization_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Add three new rubocop rulesRafael Mendonça França2016-08-161-2/+2
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-7/+7
|
* modernizes hash syntax in activerecordXavier Noria2016-08-061-3/+3
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-9/+9
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Make Active Record emit significantly smaller YAMLSean Griffin2016-05-311-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reduces the size of a YAML encoded Active Record object by ~80% depending on the number of columns. There were a number of wasteful things that occurred when we encoded the objects before that have resulted in numerous wins - We were emitting the result of `attributes_before_type_cast` as a hack to work around some laziness issues - The name of an attribute was emitted multiple times, since the attribute objects were in a hash keyed by the name. We now store them in an array instead, and reconstruct the hash using the name - The types were included for every attribute. This would use backrefs if multiple objects were encoded, but really we don't need to include it at all unless it differs from the type at the class level. (The only time that will occur is if the field is the result of a custom select clause) - `original_attribute:` was included over and over and over again since the ivar is almost always `nil`. We've added a custom implementation of `encode_with` on the attribute objects to ensure we don't write the key when the field is `nil`. This isn't without a cost though. Since we're no longer including the types, an object can find itself in an invalid state if the type changes on the class after serialization. This is the same as 4.1 and earlier, but I think it's worth noting. I was worried that I'd introduce some new state bugs as a result of doing this, so I've added an additional test that asserts mutation not being lost as the result of YAML round tripping. Fixes #25145
* Add YAML compatibility for objects from Rails 4.2Sean Griffin2015-03-101-26/+18
| | | | | | | | | | | 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.
* Attempt to provide backwards compatible YAML deserializationSean Griffin2015-03-101-0/+43
| | | | | | | | | | | | | | | | | | 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.
* Implement required #encode_withGustavo Beathyate2014-07-151-0/+1
| | | | | | | 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"`
* Keep the types of virtual columns after yaml serializationSean Griffin2014-06-101-1/+14
| | | | | On MySQL and PostgreSQL, the adapter does not type cast virtual columns for us.
* New records should remain new after yaml serializationSean Griffin2014-06-011-0/+17
|
* Don't change values in `@raw_attributes` during serializationSean Griffin2014-06-011-7/+12
| | | | | | 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.
* Add test for ActiveRecord::Relation YAML serialization, for #5303 issueIvan Antropov2013-11-031-0/+4
|
* prevent global timezone state from leaking out of test cases.Yves Senn2013-10-251-10/+4
|
* No need to require psych since require yaml does that.Rafael Mendonça França2012-01-041-1/+0
|
* No need to use rescue block to require psychRafael Mendonça França2012-01-041-18/+14
|
* stop test resetting global stateJon Leighton2011-12-231-0/+6
|
* Add hackery to make Syck use encode_with/init_with. Fixes 1.8 after recent ↵Jon Leighton2011-12-011-0/+5
| | | | changes to attribute serialization.
* please use ruby -I lib:test path/to/test.rb, or export RUBY_OPTAaron Patterson2011-06-061-1/+1
|
* Refactor Active Record test connection setup. Please see the ↵Jon Leighton2011-06-041-1/+1
| | | | 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.
* adding an `encode_with` method for Psych dump/load methodsAaron Patterson2011-01-051-0/+7
|
* make sure new objects can round tripAaron Patterson2011-01-051-0/+6
|
* make sure that Psych can roundtrip an AR objectAaron Patterson2011-01-051-0/+13
|
* adding a test for YAML round tripAaron Patterson2010-12-021-0/+9
|
* Added #to_i to DateTime in ActiveSupport so #to_yaml works correctly on ↵Serguei Filimonov2009-12-151-0/+11
ActiveRecord models with DateTime attributes.