aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/attribute_set_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Don't error when `attributes` is called on a frozen AR modelSean Griffin2014-12-081-0/+8
| | | | | | | | | | | | | | | | | | `freeze` will ultimately end up freezing the `AttributeSet`, which in turn freezes its `@attributes` hash. However, we actually insert a special object to lazily instantiate the values of the hash on demand. When it does need to actually instantiate all of them for iteration (the only case is `ActiveRecord::Base#attributes`, which calls `AttributeSet#to_h`), it will set an instance variable as a performance optimization Since it's just an optimization for subsequent calls, and that method being called at all is a very uncommon case, we can just leave the ivar alone if we're frozen, as opposed to coming up with some overly complicated mechanism for freezing which allows us to continue to modify ourselves. Fixes #17960
* Correctly determine if an attribute is uninitializedSean Griffin2014-11-141-1/+9
| | | | | | | In real usage, we give the builder a types hash with a default value of `Type::Value.new`. This means we need to explicitly check for the key, rather than the truthiness of the type to determine if it's a known but uninitialized attribute
* Reduce the amount of work performed when instantiating AR modelsSean Griffin2014-11-141-0/+9
| | | | | | | | | | We don't know which attributes will or won't be used, and we don't want to create massive bottlenecks at instantiation. Rather than doing *any* iteration over types and values, we can lazily instantiate the object. The lazy attribute hash should not fully implement hash, or subclass hash at any point in the future. It is not meant to be a replacement, but instead implement its own interface which happens to overlap.
* AttributeSet#include? -> AttributeSet#key?Sean Griffin2014-07-111-5/+5
| | | | https://github.com/rails/rails/pull/15868/files#r14135210
* `Attribute` should know about its nameSean Griffin2014-06-261-0/+3
| | | | | This allows using polymorphism for the uninitialized attributes raising an exception behavior.
* Encapsulate the creation of `Attribute` objectsSean Griffin2014-06-261-1/+35
| | | | | | | | This will make it less painful to add additional properties, which should persist across writes, such as `name`. Conflicts: activerecord/lib/active_record/attribute_set.rb
* Merge pull request #15868 from sgrif/sg-uninitialized-attributesRafael Mendonça França2014-06-261-0/+56
|\ | | | | | | | | | | | | | | Move behavior of `read_attribute` to `AttributeSet` Conflicts: activerecord/lib/active_record/attribute_set.rb activerecord/test/cases/attribute_set_test.rb
| * Move behavior of `read_attribute` to `AttributeSet`Sean Griffin2014-06-251-0/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Moved `Builder` to its own file, as it started looking very weird once I added private methods to the `AttributeSet` class and the `Builder` class started to grow. Would like to refactor `fetch_value` to change to ```ruby self[name].value(&block) ``` But that requires the attributes to know about their name, which they currently do not.
* | Merge pull request #15846 from sgrif/sg-attributes-before-type-castRafael Mendonça França2014-06-261-0/+7
|\ \ | |/ |/| | | | | | | | | | | Move `attributes_before_type_cast` to `AttributeSet` Conflicts: activerecord/lib/active_record/attribute_set.rb activerecord/test/cases/attribute_set_test.rb
| * Move `attributes_before_type_cast` to `AttributeSet`Sean Griffin2014-06-211-0/+7
| |
* | Merge pull request #15839 from sgrif/sg-attr-set-nullYves Senn2014-06-221-0/+8
|\ \ | | | | | | Return a null object from `AttributeSet#[]`
| * | Return a null object from `AttributeSet#[]`Sean Griffin2014-06-201-0/+8
| |/
* / Move `attributes` to the `AttributeSet` object.Sean Griffin2014-06-211-0/+8
|/
* Introduce an object to aid in creation and management of `@attributes`Sean Griffin2014-06-191-0/+49
Mostly delegation to start, but we can start moving a lot of behavior in bulk to this object.