aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/attribute_methods_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Do not specal case inspecting associated arrays of over 10 elements, ↵Kevin McPhillips2016-06-291-2/+21
| | | | preventing infinite looping in some cases.
* Typos in AR testsAkira Matsuda2016-02-041-1/+1
|
* Avoid infinite recursion when bad values are passed to tz aware fieldsSean Griffin2016-02-021-0/+7
| | | | | | | | | | | | | | | We had previously updated this to attempt to map over whatever was passed in, so that additional types like range and array could benefit from this behavior without the time zone converter having to deal with every known type. However, the default behavior of a type is to just yield the given value to `map`, which means that if we don't actually know how to handle a value, we'll just recurse infinitely. Since both uses of `map` in this case occur in cases where we know receiving the same object will recurse, we can just break on reference equality. Fixes #23241.
* Remove legacy mysql adapterAbdelkader Boudih2015-12-171-1/+1
|
* 💣Sean Griffin2015-10-021-1/+1
| | | | | I misread this test in https://github.com/rails/rails/commit/1a693c79c32cba070256fdb7bd1990c3d07d554f
* Fix test failures on MySQLSean Griffin2015-10-021-1/+1
| | | | | There were a few places where I missed a `create` vs `new` before_type_cast check, and the semantics of `reload` became wrong.
* Further encapsulate dirty checking on `Attribute`Sean Griffin2015-10-021-3/+0
| | | | | | | | | | | | | | | | | | | We can skip the allocation of a full `AttributeSet` by changing the semantics of how we structure things. Instead of comparing two separate `AttributeSet` objects, and `Attribute` is now a singly linked list of every change that has happened to it. Since the attribute objects are immutable, to apply the changes we simply need to copy the head of the list. It's worth noting that this causes one subtle change in the behavior of AR. When a record is saved successfully, the `before_type_cast` version of everything will be what was sent to the database. I honestly think these semantics make more sense, as we could have just as easily had the DB do `RETURNING *` and updated the record with those if we had things like timestamps implemented at the DB layer. This brings our performance closer to 4.2, but we're still not quite there.
* Should test both mysql adaptersRyuta Kamizono2015-09-201-1/+1
| | | | | Some test cases are testing only mysql adapter. We should test mysql2 adapter also.
* Removed duplicate require ‘models/computer’Ronak Jangir2015-08-261-1/+0
|
* Removed mocha from Active Record Part 1Ronak Jangir2015-08-251-2/+3
|
* Follow-up to #10776Robin Dupret2015-02-261-3/+3
| | | | | | | | | | The name `ActiveModel::AttributeAssignment::UnknownAttributeError` is too implementation specific so let's move the constant directly under the ActiveModel namespace. Also since this constant used to be under the ActiveRecord namespace, to make the upgrade path easier, let's avoid raising the former constant when we deal with this error on the Active Record side.
* Extracted `ActiveRecord::AttributeAssignment` to ↵Bogdan Gusiev2015-01-231-3/+3
| | | | | | `ActiveModel::AttributesAssignment` Allows to use it for any object as an includable module.
* Introduce `ActiveRecord::Base#accessed_fields`Sean Griffin2015-01-201-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This method can be used to see all of the fields on a model which have been read. This can be useful during development mode to quickly find out which fields need to be selected. For performance critical pages, if you are not using all of the fields of a database, an easy performance win is only selecting the fields which you need. By calling this method at the end of a controller action, it's easy to determine which fields need to be selected. While writing this, I also noticed a place for an easy performance win internally which I had been wanting to introduce. You cannot mutate a field which you have not read. Therefore, we can skip the calculation of in place changes if we have never read from the field. This can significantly speed up methods like `#changed?` if any of the fields have an expensive mutable type (like `serialize`) ``` Calculating ------------------------------------- #changed? with serialized column (before) 391.000 i/100ms #changed? with serialized column (after) 1.514k i/100ms ------------------------------------------------- #changed? with serialized column (before) 4.243k (± 3.7%) i/s - 21.505k #changed? with serialized column (after) 16.789k (± 3.2%) i/s - 84.784k ```
* Time columns should support time zone aware attributesSean Griffin2015-01-151-1/+50
| | | | | | The types that are affected by `time_zone_aware_attributes` (which is on by default) have been made configurable, in case this is a breaking change for existing applications.
* Only use the `_before_type_cast` in the form when from user inputSean Griffin2015-01-141-0/+8
| | | | | | While we don't want to change the form input when validations fail, blindly using `_before_type_cast` will cause the input to display the wrong data for any type which does additional work on database values.
* Add firebird support to test suiteRay Zane2015-01-051-2/+2
|
* Remove `cache_attributes` and friendsRafael Mendonça França2015-01-041-14/+0
|
* Build fix when running in isolationArun Agrawal2014-11-141-0/+1
| | | | | `Computer` class needs to be require See #17217 for more details
* Merge pull request #17019 from yuki24/add-class-name-to-unknown-attr-errorYves Senn2014-10-201-2/+2
|\ | | | | | | Message on AR::UnknownAttributeError should include the class name of a record
| * AR::UnknownAttributeError should include the class name of a recordYuki Nishijima2014-10-151-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This would be helpful if 2 models have an attribute that has a similar name to the other. e.g: before: User.new(name: "Yuki Nishijima", projects_attributes: [name: "kaminari"]) # => ActiveRecord::UnknownAttributeError: unknown attribute: name after: User.new(name: "Yuki Nishijima", projects_attributes: [name: "kaminari"]) # => ActiveRecord::UnknownAttributeError: unknown attribute on User: name
* | AR::UnknownAttributeError should include the class name of a recordYuki Nishijima2014-10-201-3/+3
|/ | | | | | | | | | | | | | | This would be helpful if 2 models have an attribute that has a similar name to the other. e.g: before: User.new(name: "Yuki Nishijima", projects_attributes: [name: "kaminari"]) # => ActiveRecord::UnknownAttributeError: unknown attribute: name after: User.new(name: "Yuki Nishijima", projects_attributes: [name: "kaminari"]) # => ActiveRecord::UnknownAttributeError: unknown attribute on User: name
* Fix assertions in AR::TestCase::AttributeMethodsTestYuki Nishijima2014-09-211-3/+3
| | | | | This test has always been green because it uses "assert" and the first argument is an truthy class/object.
* Fix typo [ci skip]Yuki Nishijima2014-09-201-1/+1
|
* Allow YAML serialization when using TZ aware attributesSean Griffin2014-09-171-0/+8
|
* Merge pull request #16458 from chancancode/ar_fix_reserved_inheritanceGodfrey Chan2014-08-171-0/+18
|\ | | | | | | | | | | | | Fixed issue w/custom accessors + reserved name + inheritance Conflicts: activerecord/CHANGELOG.md
| * Fixed issue w/custom accessors + reserved name + inheritanceGodfrey Chan2014-08-111-0/+18
| | | | | | | | | | | | | | | | | | | | Fixed an issue where custom accessor methods (such as those generated by `enum`) with the same name as a global method are incorrectly overridden when subclassing. This was partially fixed in 4155431 then broken again by e5f15a8. Fixes #16288.
* | fix typo in method name (broken build :sweat:)Yves Senn2014-08-151-1/+1
| |
* | prefer `has_attribute?` over `attributes.key?`.Yves Senn2014-08-151-1/+1
|/ | | | Follow up to the discussion on #16505.
* Merge pull request #15718 from chancancode/regression_from_15694Godfrey Chan2014-07-161-1/+5
|\ | | | | Fixed a regression introduced in 84cf156
| * Fixed a regression introduced in 84cf156Godfrey Chan2014-06-141-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 84cf156 (PR #15694) introduced a subtle regression. There are actually three distinct entry points to creating an AR object – via .new (i.e. #initialize), via #init_with (e.g. from YAML or database queries) and via .allocate. With the patch in 84cf156, attribute methods and respond_to? will not work correctly when objects are allocated directly, without going through either The reason this test case didn't catch the regression was that the `Topic` class is shared between test cases, so by the time this test case is ran the attribute methods are very likely to be defined. Switching to use a fresh anonymous class in the test to ensure we surface this problem in the future.
* | Move writing unknown column exception to null attributeSean Griffin2014-06-261-0/+9
| | | | | | | | | | | | Making this change revealed several subtle bugs related to models with no primary key, and anonymous classes. These have been fixed as well, with regression tests added.
* | Add missing test cases for `attribute_names` instance methodSean Griffin2014-06-221-0/+20
| | | | | | | | | | There is a class method with the same name that is tested, but not the instance method.
* | Add missing test cases for `attribute_method?`Sean Griffin2014-06-211-0/+11
|/
* Reorder test which does not represent real world usageSean Griffin2014-06-131-2/+2
| | | | | | We don't generally modify our classes at runtime like this. Let's create the instance after the class is created. Original commit doesn't imply that this was intentional behavior.
* rm cached attributesSean Griffin2014-06-111-35/+9
| | | | | | | | | | The original patch that added this concept can be found [here](https://web.archive.org/web/20090601022739/http://dev.rubyonrails.org/ticket/9767). The current default behavior is to cache everything except serialized columns, unless the user specified otherwise. If anyone were to specify otherwise, many types would actually be completely broken. Still, the method is left in place with a deprecation warning in case anyone is actually still calling this method.
* Remove most code related to serialized propertiesSean Griffin2014-06-011-1/+1
| | | | | | | | | | | 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
* Add missing test case for writing unknown attributesSean Griffin2014-05-301-0/+2
|
* Rename attribute related instance variables to better express intentSean Griffin2014-05-301-1/+1
| | | | | | | | | `@attributes` was actually used for `_before_type_cast` and friends, while `@attributes_cache` is the type cast version (and caching is the wrong word there, but I'm working on removing the conditionals around that). I opted for `@raw_attributes`, because `_before_type_cast` is also semantically misleading. The values in said hash are in the state given by the form builder or database, so raw seemed to be a good word.
* Don't recurse infinitely when calling non-existent method on superKris Kemper2014-05-221-0/+12
|
* Remove :timestamp column typeSean Griffin2014-05-191-1/+1
| | | | | | | | | | | | The `:timestamp` type for columns is unused. All database adapters treat them as the same database type. All code in `ActiveRecord` which changes its behavior based on the column's type acts the same in both cases. However, when the type is passed to code that checks for the `:datetime` type, but not `:timestamp` (such as XML serialization), the result is unexpected behavior. Existing schema definitions will continue to work, and the `timestamp` type is transparently aliased to `datetime`.
* Just call read_attribute, no need to use `send`.Lauro Caetano2014-04-141-4/+4
| | | | Follow up to af549a1ad6692d7e2c756750651f0e1b293f5185
* Use teardown helper method.Guo Xiang Tan2014-03-141-1/+1
| | | | | | | | Follow-Up to https://github.com/rails/rails/pull/14348 Ensure that SQLCounter.clear_log is called after each test. This is a step to prevent side effects when running tests. This will allow us to run them in random order.
* Fixes STI when 2+ levels deep.Arthur Neves2014-03-101-0/+13
| | | | | | PR #14052 Added a regression where it was only looking for methods in one level up, So when the method was defined in a 2+ levels up the inheritance chain, the method was not found as defined.
* Merge remote-tracking branch ↵Jon Leighton2014-02-251-11/+19
|\ | | | | | | | | | | | | 'chancancode/fix_instance_method_already_implemented' Conflicts: activerecord/CHANGELOG.md
| * Fixed STI classes not defining an attribute method if there is aGodfrey Chan2014-02-231-11/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | conflicting private method defined on its ancestors. The problem is that `method_defined_within?(name, klass, superklass)` only works correclty when `klass` and `superklass` are both `Class`es. If both `klass` and `superklass` are both `Class`es, they share the same inheritance chain, so if a method is defined on `klass` but not `superklass`, this method must be introduced at some point between `klass` and `superklass`. This does not work when `superklass` is a `Module`. A `Module`'s inheritance chain contains just itself. So if a method is defined on `klass` but not on `superklass`, the method could still be defined somewhere upstream, e.g. in `Object`. This fix works by avoiding calling `method_defined_within?` with a module while still fufilling the requirement (checking that the method is defined withing `superclass` but not is not a generated attribute method). 4d8ee288 is likely an attempted partial fix for this problem. This unrolls that fix and properly check the `superclass` as intended. Fixes #11569.
* | Coerce strings when reading attributes.Yves Senn2014-02-231-0/+18
|/
* Fix AR#method_missing re-dispatching into overwritten attribute methods.thedarkone2013-09-291-2/+33
| | | | | | | | | | | | | | This was happening when a `super` call in an overwritten attribute method was triggering a method_missing fallback, because attribute methods haven't been generated yet. class Topic < ActiveRecord::Base def title # `super` would re-invoke this method if define_attribute_methods # hasn't been called yet resulting in double '!' appending super + '!' end end
* Merge pull request #9860 from wangjohn/update_attributes_throws_error_with_nilRafael Mendonça França2013-09-241-1/+1
|\ | | | | | | | | | | | | Raising an error when nil is passed to update_attributes. Conflicts: activerecord/CHANGELOG.md
| * Raising an error when nil or non-hash is passed to update_attributes.wangjohn2013-06-251-1/+1
| |
* | Remove deprecation warning from attribute_missing Arun Agrawal2013-07-151-15/+0
| | | | | | for attributes that are columns.