aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/collection_cache_key_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Fix Collection cache key with limit and custom select (PG:AmbigousColumn: Error)Federico Martinez2018-10-151-0/+14
| | | | Change query to use alias name for timestamp_column to avoid ambiguity problems when using timestamp from subquery.
* Use `assert_no_queries` not to ignore BEGIN/COMMIT queriesRyuta Kamizono2018-10-051-2/+2
| | | | | | | | | `test_update_does_not_run_sql_if_record_has_not_changed` would pass without #18501 since `assert_queries` ignores BEGIN/COMMIT unless `ignore_none: true` is given. Since #32647, empty BEGIN/COMMIT is ommited. So we no longer need to use `assert_queries(0)` to ignore BEGIN/COMMIT in the queries.
* Avoid passing unnecessary arguments to relationDaniel Colson2018-01-241-1/+5
| | | | | | | | | | | | Most of the time the table and predicate_builder passed to Relation.new are exactly the arel_table and predicate builder of the given klass. This uses klass.arel_table and klass.predicate_builder as the defaults, so we don't have to pass them in most cases. This does change the signaure of both Relation and AssocationRelation. Are we ok with that?
* Fix `cache_key` with a relation having distinct and orderRyuta Kamizono2017-12-301-0/+6
| | | | | | | | | | | | | We can't replace existing SELECT list as long as having DISTINCT, it will cause incorrect result. And also, PostgreSQL has a limitation that ORDER BY expressions must appear in select list for SELECT DISTINCT. Therefore, we should not replace existing SELECT list when using DISTINCT. Fixes #29779.
* Fix `cache_key` with a relation having custom select and orderRyuta Kamizono2017-12-291-0/+6
| | | | We can't replace existing select list as long as referenced by ORDER BY.
* Introduced `ActiveSupport::Digest` that allows to specify hash function ↵Dmitri Dolguikh2017-12-121-4/+4
| | | | | | | | implementation and defaults to `Digest::MD5`. Replaced calls to `::Digest::MD5.hexdigest` with calls to `ActiveSupport::Digest.hexdigest`.
* Ensure `apply_join_dependency` for `collection_cache_key` if eager-loading ↵Ryuta Kamizono2017-11-061-0/+10
| | | | | | is needed Fixes #30315.
* Don't use `collection.table_name` in `collection_cache_key`Ryuta Kamizono2017-09-141-0/+18
| | | | | Because `collection.table_name` doesn't respect table alias. Use `collection.arel_attribute` instead.
* 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
|
* Replace \Z to \zRyuta Kamizono2017-04-241-12/+12
| | | | \Z was a mistake of \z. Replace \Z to \z to prevent newly \Z added.
* `cache_key` respects the limit in a relation even if a relation is not loadedRyuta Kamizono2017-04-171-2/+28
| | | | | | `cache_key` includes the size of a relation. But if a relation is not loadded, the size is not respected even if a relation has a limit. It should be respected for consistency.
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-3/+3
|
* Fix AR::Relation#cache_key to remove select scope added by userPrathamesh Sonpatki2016-01-241-0/+6
| | | | | | | | | | - We don't need the select scope added by user as we only want to max timestamp and size of the collection. So we already know which columns to select. - Additionally having user defined columns in select scope blows the cache_key method with PostGreSQL because it needs all `selected` columns in the group_by clause or aggregate function. - Fixes #23038.
* Fix ActiveRecord::Relation#cache_key for relations with no resultsPrathamesh Sonpatki2016-01-221-0/+5
| | | | | | | - When relations return no result or 0 result then cache_key should handle it gracefully instead of blowing up trying to access `result[:size]` and `result[:timestamp]`. - Fixes #23063.
* Fix ActiveRecord::Relation#cache_key for loaded empty collectionPrathamesh Sonpatki2016-01-161-0/+8
| | | | | | | | | - Before this patch if we try to find cache_key of a loaded but empty collection it used to give error because of trying to call `updated_at` on `nil` value generated by `collection.max_by(&timestamp_column).public_send(timestamp_column)`. - This commit fixes above error by checking if size is greater than zero or not.
* fixes #21815Maarten Jacobs2015-10-161-1/+1
| | | | | | | | | | | | | | | The default timestamp used for AR is `updated_at` in nanoseconds! (:nsec) This causes issues on any machine that runs an OS that supports nanoseconds timestamps, i.e. not-OS X, where the cache_key of the record persisted in the database (milliseconds precision) is out-of-sync with the cache_key in the ruby VM. This commit adds: A test that shows the issue, it can be found in the separate file `cache_key_test.rb`, because - model couldn't be defined inline - transactional testing needed to be turned off to get it to pass the MySQL tests This seemed cleaner than putting it in an existing testcase file. It adds :usec as a dateformat that calculates datetime in microseconds It sets precision of cache_key to :usec instead of :nsec, as no db supports nsec precision on timestamps
* Fix ambiguous argument warningMehmet Emin İNAÇ2015-08-021-1/+1
| | | | encapsulate all arguments
* Add #cache_key to ActiveRecord::Relation.Alberto F. Capel2015-07-201-0/+70