aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
Commit message (Collapse)AuthorAgeFilesLines
* Fix `warning: assigned but unused variable - comment`Ryuta Kamizono2017-07-251-1/+1
| | | | | | | | | | | | | | | ``` % ARCONN=sqlite3 be ruby -w -Itest test/cases/associations/belongs_to_associations_test.rb -n test_multiple_counter_cache_with_after_create_update test/cases/associations/belongs_to_associations_test.rb:1181: warning: assigned but unused variable - comment Using sqlite3 Run options: -n test_multiple_counter_cache_with_after_create_update --seed 49644 . Finished in 0.114266s, 8.7515 runs/s, 17.5030 assertions/s. 1 runs, 2 assertions, 0 failures, 0 errors, 0 skips ```
* Merge pull request #29765 from lugray/fix_counter_cacheRafael França2017-07-241-0/+11
|\ | | | | Fix `counter_cache` double increment
| * Add test for fixed `counter_cache` double incrementLisa Ugray2017-07-191-0/+11
| | | | | | | | | | | | | | | | | | | | | | When an `after_create` callback did `update_attributes` on a record with multiple `belongs_to` associations with counter caches, even numbered associations would have their counters double-incremented. Fixes to `ActiveModel::Dirty` in 020abad fixed this. This adds regression tests for this bug fixed incidentally in the other commit, which also removed the need for the workaround using @_after_create_counter_called.
* | Refactor Active Record to let Arel manage bind paramsSean Griffin2017-07-241-17/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A common source of bugs and code bloat within Active Record has been the need for us to maintain the list of bind values separately from the AST they're associated with. This makes any sort of AST manipulation incredibly difficult, as any time we want to potentially insert or remove an AST node, we need to traverse the entire tree to find where the associated bind parameters are. With this change, the bind parameters now live on the AST directly. Active Record does not need to know or care about them until the final AST traversal for SQL construction. Rather than returning just the SQL, the Arel collector will now return both the SQL and the bind parameters. At this point the connection adapter will have all the values that it had before. A bit of this code is janky and something I'd like to refactor later. In particular, I don't like how we're handling associations in the predicate builder, the special casing of `StatementCache::Substitute` in `QueryAttribute`, or generally how we're handling bind value replacement in the statement cache when prepared statements are disabled. This also mostly reverts #26378, as it moved all the code into a location that I wanted to delete. /cc @metaskills @yahonda, this change will affect the adapters Fixes #29766. Fixes #29804. Fixes #26541. Close #28539. Close #24769. Close #26468. Close #26202. There are probably other issues/PRs that can be closed because of this commit, but that's all I could find on the first few pages.
* | Merge pull request #29855 from lugray/has_one_destroyed_by_associationRafael França2017-07-211-0/+34
|\ \ | | | | | | Match destroyed_by_association for has_one to has_many
| * | Match destroyed_by_association for has_one to has_manyLisa Ugray2017-07-211-0/+34
| |/ | | | | | | | | | | | | When a has_many association is destroyed by `dependent: destroy`, destroyed_by_association is set to the reflection, and this can be checked in callbacks. This matches that behaviour for has_one associations.
* | Reset column information after schema changedyuuji.yaginuma2017-07-201-0/+2
| | | | | | | | | | This fixes the following failures. https://travis-ci.org/rails/rails/jobs/253990014
* | Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-1921-0/+42
|/
* Merge pull request #29679 from kamipo/add_test_case_for_27724Kasper Timm Hansen2017-07-151-0/+7
|\ | | | | Add a test case for overwriting existing condition on associations
| * Add a test case for overwriting existing condition on associationsRyuta Kamizono2017-07-071-0/+7
| | | | | | | | | | | | | | | | Overwriting existing condition on associations has already supported (23bcc65 for eager loading, 2bfa2c0 for preloading). Fixes #27724. Closes #29154.
* | Remove extra `.merge!(order: "id")` for `Relation#first` in testsRyuta Kamizono2017-07-132-32/+28
|/ | | | | Since 07e5301, `Relation#first` will order by primary key if no order is defined.
* Fix eager loading association with scope including joinsRyuta Kamizono2017-07-041-0/+1
| | | | Fixes #28324.
* Fix preloading association with scope including joinsRyuta Kamizono2017-07-041-0/+4
|
* Remove redundant `assert_respond_to`Ryuta Kamizono2017-07-031-26/+0
| | | | It is covered by following assertion.
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-0221-21/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Merge pull request #29540 from kirs/rubocop-frozen-stringMatthew Draper2017-07-0221-0/+21
|\ | | | | | | Enforce frozen string in Rubocop
| * Enforce frozen string in RubocopKir Shatrov2017-07-0121-0/+21
| |
* | Merge pull request #29631 from kamipo/should_be_clear_association_idsMatthew Draper2017-07-011-0/+5
|\ \ | | | | | | Should be clear `@association_ids` when joined newly associated record
| * | Should be clear `@association_ids` when joined newly associated recordRyuta Kamizono2017-06-301-0/+5
| |/ | | | | | | Fixes #29627.
* | Merge pull request #28808 from fschwahn/fix-polymorphic-automic-inverseMatthew Draper2017-07-012-6/+16
|\ \ | |/ |/| Fix automatic inverse for polymorphic interfaces
| * Add regression test for setting inverse instances on normal & polymorphic ↵Fabian Schwahn2017-04-201-0/+14
| | | | | | | | relationships when building objects on new records
| * Remove :polymorphic from INVALID_AUTOMATIC_INVERSE_OPTIONSFabian Schwahn2017-04-201-6/+2
| | | | | | | | | | | | | | This makes automatic inverse detection possible for polymorphic :has_one & :has_many possible. This resolves a number of issues, eg. `touch: true` on polymorphic relationships (#16446) and automatically setting inverse associations on newly built objects (#15028, #21843).
* | Remove unused `aliased_table_name` in `Association`Ryuta Kamizono2017-06-291-1/+0
| | | | | | | | | | | | | | `aliased_table_name` in `Association` was added at a3502c4. `aliased_table_name` in `JoinDependency` (added at 55854c4) is used, but it looks like that added one in `Association` is never used from the beginning.
* | Merge pull request #29601 from ↵Rafael Mendonça França2017-06-281-10/+17
|\ \ | | | | | | | | | | | | | | | kamipo/fix_eager_loading_to_respect_store_full_sti_class Fix eager loading to respect `store_full_sti_class` setting
| * | Fix eager loading to respect `store_full_sti_class` settingRyuta Kamizono2017-06-291-10/+17
| | |
* | | Merge pull request #29610 from ↵Rafael França2017-06-281-2/+1
|\ \ \ | | | | | | | | | | | | | | | | kamipo/dont_passing_klass_connection_to_association_scope Don't passing `klass.connection` to `AssociationScope`
| * | | Don't passing `klass.connection` to `AssociationScope`Ryuta Kamizono2017-06-291-2/+1
| | | | | | | | | | | | | | | | | | | | Passing `klass.connection` is redundant because `AssociationScope` is passed an association itself and an association has `klass`.
* | | | Merge pull request #29611 from kamipo/add_test_case_for_unscoping_default_scopeRafael França2017-06-281-2/+3
|\ \ \ \ | |_|/ / |/| | | Add a test case for unscoping `default_scope` in associations
| * | | Add a test case for unscoping `default_scope` in associationsRyuta Kamizono2017-06-291-2/+3
| |/ / | | | | | | | | | | | | | | | | | | | | | Unscoping `default_scope` in associations has already supported (#17360 for preloading, c9cf8b8 for eager loading). Fixes #20679. Closes #16531.
* | | Merge pull request #29602 from kamipo/use_reload_in_test_find_first_after_reloadRafael França2017-06-281-10/+10
|\ \ \ | |/ / |/| | Use `reload` in `test_find_first_after_reload`
| * | Use `reload` in `test_find_first_after_reload`Ryuta Kamizono2017-06-281-10/+10
| | | | | | | | | | | | | | | | | | | | | And use `assert_same` instead of `assert_equal` and tiny fix assert message s/#reload/#reset/. Follow up of #29511.
* | | ActiveRecord: do not create "has many through" records that have been removedTobias Kraze2017-06-281-0/+11
|/ / | | | | | | | | If a record was built on a HasManyThroughAssociation, then removed, and then the record was saved, the removed record would be created anyways.
* | Move clearing of @offsets cache to reset_scopeJohn Hawthorn2017-06-211-12/+21
| |
* | Clear offset cache on CollectionProxy reset/reloadJohn Hawthorn2017-06-201-0/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The `@offsets` cache is used by FinderMethods to cache records found by find_nth. This cache is cleared in AR::Relation#reset, but not in CollectionProxy#reset or CollectionProxy#reload. Because of this, since #29098, calling #first/#find_nth/etc after calling #reload or #reset on an association could return a stale record. This is an issue both when the full association target is loaded and when the item is loaded in #find_nth. This commit solves the problem by clearing the `@offsets` cache in CollectionProxy#reset and CollectionProxy#reload.
* | Raise on create for singular association when parent is unpersistedAlex Kitchens2017-06-081-0/+9
| | | | | | | | | | | | A collection association will raise on `#create_association` when the parent is unpersisted. A singular association should do the same. This addresses issue #29219.
* | Remove redundant `assert_nothing_raised` before another assertionsRyuta Kamizono2017-06-062-9/+0
| | | | | | | | These `assert_nothing_raised` are covered by following assertions.
* | Correct a has_many association testKoichi ITO2017-06-011-1/+1
| |
* | Remove a redundant test case of HABTM_associations_testKoichi ITO2017-05-311-13/+0
| |
* | Merge pull request #29098 from kamipo/fix_association_with_extension_issuesMatthew Draper2017-05-302-1/+15
|\ \ | | | | | | | | | Fix association with extension issues
| * | Fix association with extension issuesRyuta Kamizono2017-05-282-1/+15
| | | | | | | | | | | | | | | | | | | | | | | | This fixes the following issues. * `association_scope` doesn't include `default_scope`. Should use `scope` instead. * We can't use `method_missing` for customizing existing method. * We can't use `relation_delegate_class` for sharing extensions. Should extend per association.
* | | Remove a redundant test assertionKoichi ITO2017-05-291-6/+0
|/ /
* | Merge pull request #29176 from bogdanvlviv/define-path-with__dir__Matthew Draper2017-05-261-1/+1
|\ \ | | | | | | Define path with __dir__
| * | Define path with __dir__bogdanvlviv2017-05-231-1/+1
| | | | | | | | | | | | | | | | | | ".. with __dir__ we can restore order in the Universe." - by @fxn Related to 5b8738c2df003a96f0e490c43559747618d10f5f
* | | Fix a RuboCop offences using `rubocop -a`Koichi ITO2017-05-241-1/+1
| | |
* | | Merge pull request #29141 from kamipo/make_helper_methods_to_privateMatthew Draper2017-05-241-18/+19
|\ \ \ | | | | | | | | Make helper methods in tests to private
| * | | Make helper methods in tests to privateRyuta Kamizono2017-05-191-18/+19
| |/ / | | | | | | | | | | | | `make_model` and `make_no_pk_hm_t` in `HasManyThroughAssociationsTest` are not a test case. it should be private.
* / / Remove a duplicate test of inverse_associations_test in ARKoichi ITO2017-05-211-14/+0
|/ /
* | Don't eager loading if unneeded for `FinderMethods#exists?`Ryuta Kamizono2017-05-111-0/+1
| | | | | | | | Fixes #29025.
* | Evaluate belongs_to :default option against the owner, not the associationGeorge Claghorn2017-04-271-0/+18
| |
* | Restore `fixtures :author_addresses`Ryuta Kamizono2017-04-278-10/+10
| | | | | | | | | | This change reverted in eac6f369 but it is needed for data integrity. See #25328.