aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/serialized_attribute_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Remove unused requiresRyuta Kamizono2019-03-011-2/+0
| | | | | `require "bcrypt"` is unsed since #15431. `require "models/topic"` is unused since 893c647da37189543b2c2d55b07d414b1ba8b0d0.
* Avoid `Topic.dup` to prevent weird test failureRyuta Kamizono2019-03-011-1/+1
| | | | | | This is an alternative of 65c4b1b50df3fa59198de2d45d1f54b61ecc7864. https://buildkite.com/rails/rails/builds/59147#117e9445-23e8-455a-b486-ea0ae9636405/120-129
* Reset dirty `topics` table for `SerializedAttributeTest`Ryuta Kamizono2019-03-011-1/+1
| | | | | | | | | Some untransactional tests (e.g. `CallbacksOnMultipleActionsTest`) makes `topics` table dirty. We should reset dirty `topics` table before `SerializedAttributeTest` is run. https://travis-ci.org/rails/rails/jobs/499719624#L1209-L1215
* Use dedicated `Topic` model for `SerializedAttributeTest`Ryuta Kamizono2019-02-281-20/+14
| | | | | | | | | | | | | | | | | | This fixes both #34555 and #34738. Revert "Merge pull request #34900 from gmcgibbon/fix_test_find_only_some_columns" This reverts commit ff807f823b869d3491935a096183ee2bebd58e7b, reversing changes made to 9f1a07af0499080c9fd8815705a03a4c7e8fb506. Revert "Merge pull request #34560 from gmcgibbon/fix_decorate_leak_on_serial_attr_test" This reverts commit bd62389307e138ee0f274a9d62697567a3334ea0, reversing changes made to ec66c6a2fa4ee200259341a18ecd96310f388ba3. Revert "Fix unstable `test_serialized_attribute_works_under_concurrent_initial_access` test" This reverts commit 65c4b1b50df3fa59198de2d45d1f54b61ecc7864.
* Reset column info on original Topic in serialized attr testGannon McGibbon2019-01-091-2/+11
| | | | | Call .reset_column_information on ::Topic in serialized attribute test so that attribute methods are safely undefined for all topics.
* Fix unstable ↵yuuji.yaginuma2018-12-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | `test_serialized_attribute_works_under_concurrent_initial_access` test Since bd62389307e138ee0f274a9d62697567a3334ea0, isolate test of `test_serialized_attribute_works_under_concurrent_initial_access` fails. ``` $ ./bin/test -w test/cases/serialized_attribute_test.rb -n test_serialized_attribute_works_under_concurrent_initial_access Using sqlite3 Run options: -n test_serialized_attribute_works_under_concurrent_initial_access --seed 32129 # Running: E Error: SerializedAttributeTest#test_serialized_attribute_works_under_concurrent_initial_access: ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: ``` If duplicate an unloaded model, it seems that method invocation for that class is not guaranteed. Use the original class to avoid it.
* Fix attribute decoration leak on serialized attribute testGannon McGibbon2018-11-291-0/+4
|
* Address intermittent CI failure due to non-determined sort orderRyuta Kamizono2018-08-191-1/+1
| | | | https://travis-ci.org/rails/rails/jobs/417783260#L1173-L1179
* Fix force equality checking not to break the serialized attribute with ArrayRyuta Kamizono2018-06-061-0/+7
| | | | Context: https://github.com/rails/rails/commit/43ef00e5d7a55ad79bc840276d33cb70f1f5dde5#commitcomment-29256140
* Make force equality checking more strictly not to allow serialized attributeRyuta Kamizono2018-05-251-0/+7
| | | | | | | | | | | Since #26074, introduced force equality checking to build a predicate consistently for both `find` and `create` (fixes #27313). But the assumption that only array/range attribute have subtype was wrong. We need to make force equality checking more strictly not to allow serialized attribute. Fixes #32761.
* Use assert_predicate and assert_not_predicateDaniel Colson2018-01-251-2/+2
|
* Change refute to assert_notDaniel Colson2018-01-251-1/+1
|
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Add a Monitor to ModelSchema#load_schemaMatthew Draper2017-05-251-0/+28
| | | | [Vikrant Chaudhary, David Abdemoulaie, Matthew Draper]
* Indicate action that failed in YamlColumnKir Shatrov2017-02-051-1/+1
|
* Report the attribute on ActiveRecord::SerializationTypeMismatchKir Shatrov2017-01-291-0/+14
|
* assert_equal takes expectation firstAkira Matsuda2016-12-261-3/+3
|
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-1/+1
|
* Revert "Made ActiveRecord consistently use ActiveRecord::Type (not"Sean Griffin2016-10-231-2/+2
| | | | | | This reverts commit 671eb742eec77b5c8281ac2a2e3976ef32a6e424. This is not a change we would like moving forward.
* Made ActiveRecord consistently use ActiveRecord::Type (notIain Beeston2016-10-031-2/+2
| | | | | | | | ActiveModel::Type) Some code was previously referring to ActiveModel::Type::*. This could cause issues in the future if any of the ActiveRecord::Type classes were overridden in the future.
* Do not handle as an associated predicate if a table has the columnRyuta Kamizono2016-08-161-0/+7
| | | | | | If handled as an associated predicate even though a table has the column, will generate invalid SQL by valid column name treated as a table name.
* modernizes hash syntax in activerecordXavier Noria2016-08-061-9/+9
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-17/+17
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Fix false positive mutation detection when JSON is used with serializeSean Griffin2016-05-121-0/+33
| | | | | | | | | | | | | When looking for mutation, we compare the serialized version of the value to the before_type_cast form. `Type::Serialized` was breaking this contract by passing the already serialized attribute to the subtype's mutation detection. This never manifested previously, as all mutable subtypes either didn't do anything in their `serialize` method, or had a way to detect double serialization (e.g. `is_a?(String)`). However, now that JSON types can handle string primitives, we need to avoid double serialization. Fixes #24993.
* Add a test to ensure `serialize` persists `nil` as `NULL`Sean Griffin2015-06-121-0/+8
|
* Add a missing test case for the persistence behavior of `serialize`Sean Griffin2015-06-111-0/+13
| | | | | | | | | | | | | | | | | `serialize` makes the contract that if it is given a class name, it will never return something other than an instance of that class. This means that it must cast `nil` to the empty form of that object. As such, we should then persist empty forms of that object as `nil`. While this is techincally under the contract of ``` model.attribute = value assert_equal model.attribute, model.tap(&:save).reload.attribute ``` which we can't actually test universally without property based testing, it has come up more than once and is worth calling out specifically since we aren't looking to change it.
* Make sure to persist a newly-nil serialized valueMatthew Draper2015-03-231-0/+10
| | | | | | | The subtype will (quite reasonably) ignore the possibility that it has `changed_in_place?` by becoming nil. Fixes #19467
* Remove deprecated `serialized_attributes`Rafael Mendonça França2015-01-041-6/+0
|
* Provide a better error message for unsupported classes in `serialize`Sean Griffin2014-12-271-0/+6
| | | | | | | | | We only support classes which provide a no-args constructor to use as a default value. We can provide a more helpful error message if we catch this when `serialize` is called, rather than letting it error when you try to assign the attribute. Fixes #18224
* Don't treat `nil` as changed in serialized typesSean Griffin2014-12-231-0/+8
| | | | | | | We were ignoring the `default_value?` escape clause in the serialized type, which caused the default value to always be treated as changed. Fixes #18169
* `update_column` take ruby-land input, not database-land inputSean Griffin2014-12-161-2/+4
| | | | | | | | | | | | | | | In the case of serialized columns, we would expect the unserialized value as input, not the serialized value. The original issue which made this distinction, #14163, introduced a bug. If you passed serialized input to the method, it would double serialize when it was sent to the database. You would see the wrong input upon reloading, or get an error if you had a specific type on the serialized column. To put it another way, `update_column` is a special case of `update_all`, which would take `['a']` and not `['a'].to_yaml`, but you would not pass data from `params` to it. Fixes #18037
* Fixed test throwing unused variable warningVipul A M2014-10-191-1/+1
|
* test, better describe `SerializationTypeMismatch` behavior. refs #14716.Yves Senn2014-10-161-2/+1
|
* AR#reset_column_information sometimes queries via table_exists?Akira Matsuda2014-08-311-1/+1
| | | | so this assertion causes random test fail
* Document the change in `nil` handling for serialized attributesGodfrey Chan2014-07-151-9/+12
| | | | Also updated the test case to reflect that
* Fixed SQL syntax for postgresqlGodfrey Chan2014-07-151-1/+1
|
* Merge pull request #16162 from chancancode/fix_json_coderGodfrey Chan2014-07-151-0/+18
| | | | Fixed JSON coder when loading NULL from DB
* Revert "Revert "Merge pull request #16059 from jenncoop/json-serialized-attr""Godfrey Chan2014-07-151-1/+15
| | | | | | | This reverts commit 6f3c64eeb1dc8288dae49f114aaf619adc7dcb7f. Conflicts: activerecord/CHANGELOG.md
* Revert "Merge pull request #16059 from jenncoop/json-serialized-attr"Godfrey Chan2014-07-051-15/+1
| | | | | | This reverts commit a03097759bd7103bb9db253e7ba095f011453f75. This needs more work before it would work correctly on master.
* Merge pull request #16059 from jenncoop/json-serialized-attrGodfrey Chan2014-07-051-1/+15
| | | | | | | | Fixed issue with ActiveRecord serialize object as JSON Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/attribute_methods/serialization.rb
* Deprecate `serialized_attributes` without replacementSean Griffin2014-06-141-2/+4
| | | | | We've stopped using it internally, in favor of polymorphism. So should you!
* Introduce an Attribute object to handle the type casting danceSean Griffin2014-06-131-6/+0
| | | | | | | | | | | | | | | There's a lot more that can be moved to these, but this felt like a good place to introduce the object. Plans are: - Remove all knowledge of type casting from the columns, beyond a reference to the cast_type - Move type_cast_for_database to these objects - Potentially make them mutable, introduce a state machine, and have dirty checking handled here as well - Move `attribute`, `decorate_attribute`, and anything else that modifies types to mess with this object, not the columns hash - Introduce a collection object to manage these, reduce allocations, and not require serializing the types
* Don't query the database schema when calling `serialize`Sean Griffin2014-06-071-0/+7
| | | | | | We need to decorate the types lazily. This is extracted to a separate API, as there are other refactorings that will be able to make use of it, and to allow unit testing the finer points more granularly.
* Bring type casting behavior of hstore/json in line with serializedSean Griffin2014-06-041-1/+1
| | | | | `@raw_attributes` should not contain the type-cast, mutable version of the value.
* Remove most code related to serialized propertiesSean Griffin2014-06-011-4/+7
| | | | | | | | | | | Nearly completely implemented in terms of custom properties. `_before_type_cast` now stores the raw serialized string consistently, which removes the need to keep track of "state". The following is now consistently true: - `model.serialized == model.reload.serialized` - A model can be dumped and loaded infinitely without changing - A model can be saved and reloaded infinitely without changing
* Update some bad test cases for serialized columnsSean Griffin2014-05-301-53/+17
| | | | | | | | | | | | The first case was not testing what the issue mentioned actually was (A subclass of a class with serialized attributes does not serialize when they come from the database). The second case was a bad coder. It would fail if the model was `dup`ed, or if the the model was loaded from the database and then saved again. The third case wasn't testing anything that wasn't covered by the second (and was also a bad coder for the same reasons as the second).
* Refactor serialized types to be partially defined as custom propertiesSean Griffin2014-05-291-10/+0
| | | | | | | Many of the methods defined in `AttributeMethods::Serialization` can be refactored onto this type as well, but this is a reasonable small step. Removes the `Type` class, and the need for `decorate_columns` to handle serialized types.
* Fix serialized field returning serialized data after update_columnSimon Eskildsen2014-04-051-0/+16
|