aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/attribute_methods_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* No difference between JRuby and CRuby at ↵Yasuo Honda2017-11-211-6/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | test_read_attributes_before_type_cast_on_a_boolean https://github.com/jruby/activerecord-jdbc-adapter ActiveRecord JDBC Adapter is actively developed and it supports Rails 5.1 now. This pull request addresses one of the failure when running ActiveRecord unit tests with ActiveRecord JDBC Adapter. As of right now, ActiveRecord JDBC Adapter supports Rails 5.1, not master branch then this test only can run on `5-1-stable` branch. But I have opened this pull request to `master` branch since this type cast should be going to work in the future versions of ActiveRecord JDBC Adapter . ```ruby $ ARCONN=jdbcmysql bin/test test/cases/attribute_methods_test.rb:203 Using jdbcmysql Run options: --seed 8874 F Finished in 0.709120s, 1.4102 runs/s, 1.4102 assertions/s. 1) Failure: AttributeMethodsTest#test_read_attributes_before_type_cast_on_a_boolean [/home/yahonda/git/rails/activerecord/test/cases/attribute_methods_test.rb:203]: Expected: "0" Actual: 0 1 runs, 1 assertions, 1 failures, 0 errors, 0 skips $ ```
* Add test for class of GeneratedAttributeMethods instance in ancestorsChris Salzberg2017-10-091-0/+5
|
* Remove unused `cached_columns` and `time_related_columns_on_topic` in ↵Ryuta Kamizono2017-09-271-8/+0
| | | | | | `AttributeMethodsTest` These are no longer used since 66736c8e.
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Make `generated_attribute_methods` to privateRyuta Kamizono2017-07-141-1/+1
| | | | Because `generated_attribute_methods` is an internal API.
* 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
|
* Fix `define_attribute_method` with Symbol in ARPrem Sichanugrist2017-02-211-0/+7
| | | | | | | | | | | | | | | | | | | This issue is only appear when you try to call `define_attribute_method` and passing a symbol in Active Record. It does not appear in isolation in Active Model itself. Before this patch, when you run `User.define_attribute_method :foo`, you will get: NoMethodError: undefined method `unpack' for :foo:Symbol from activerecord/lib/active_record/attribute_methods/read.rb:28:in `define_method_attribute' from activerecord/lib/active_record/attribute_methods/primary_key.rb:61:in `define_method_attribute' from activemodel/lib/active_model/attribute_methods.rb:292:in `block in define_attribute_method' from activemodel/lib/active_model/attribute_methods.rb:285:in `each' from activemodel/lib/active_model/attribute_methods.rb:285:in `define_attribute_method' This patch contains both a fix in Active Model and a test in Active Record for this error.
* "Use assert_nil if expecting nil. This will fail in minitest 6."Akira Matsuda2016-12-251-4/+4
|
* Check whether the current attribute being write is aliased or not before writingPrathamesh Sonpatki2016-12-091-0/+7
| | | | - If aliased, then use the aliased attribute name.
* Check whether the current attribute being read is aliased or not before readingPrathamesh Sonpatki2016-12-081-0/+10
| | | | | - If aliased, then use the aliased attribute name. - Fixes #26417.
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-6/+6
|
* improve error message when include assertions failMichael Grosser2016-09-161-3/+3
| | | | | | assert [1, 3].includes?(2) fails with unhelpful "Asserting failed" message assert_includes [1, 3], 2 fails with "Expected [1, 3] to include 2" which makes it easier to debug and more obvious what went wrong
* Fix broken heredoc indentation caused by rubocop auto-correctRyuta Kamizono2016-09-031-5/+5
| | | | | | All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772. But heredocs was still kept absolute position. This commit aligns heredocs indentation for consistency.
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-24/+24
|
* remove redundant curlies from hash argumentsXavier Noria2016-08-061-1/+1
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-186/+186
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* removes spurious lineXavier Noria2016-07-241-1/+0
|
* give some love to this test fileXavier Noria2016-07-231-151/+155
| | | | | | | | | It all started noticing some foo.method({ ... }) method calls in passing. This is a whole pass modernizing this file. While some string literals are edited where I touched code, this pass does not uniformizes quotes. A ton are left untouched on purposes. We have no defined style.
* systematic revision of =~ usage in ARXavier Noria2016-07-231-1/+1
| | | | | Where appropriatei, prefer the more concise Regexp#match?, String#include?, String#start_with?, or String#end_with?
* 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.