aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Fix join middle table alias when using HABTMTakayuki Nakata2019-07-261-2/+9
| | | | | | | | In using HABTM, join middle table alias is combined with the associated models name without sort, while middle table name is combined with those models name with sort. Fixes #36742.
* Address intermittent CI failure due to unfilled schema columns cacheRyuta Kamizono2019-05-291-3/+3
| | | | https://buildkite.com/rails/rails/builds/61358#a78ee50e-30b5-48a2-858f-63eba287d919/1290-1298
* Give up filling schema cache before `assert_no_queries`Ryuta Kamizono2019-05-221-8/+2
| | | | | | | | | | | | | | | | | This reverts commit a1ee4a9ff9d4a3cb255365310ead0dc7b739c6be. Even if a1ee4a9 is applied, CI is still flakiness. https://buildkite.com/rails/rails/builds/61252#2c090afa-aa84-4a2b-8b81-9f09219222c6/994-1005 https://buildkite.com/rails/rails/builds/61252#2e55bf83-1bde-44a2-a4f1-b5c3f6820fb4/929-938 Failing tests by whether schema cache is filled or not, it actually means that whether SCHEMA SQLs are executed or not is not target for the tests. So I've reverted commit a1ee4a9 which filling schema cache before `assert_no_queries`, and replace `assert_no_queries` to `assert_queries(0)`.
* Enable `Style/RedundantBegin` cop to avoid newly adding redundant begin blockRyuta Kamizono2018-12-211-10/+8
| | | | | | | | | | Currently we sometimes find a redundant begin block in code review (e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205). I'd like to enable `Style/RedundantBegin` cop to avoid that, since rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5 (https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with that situation than before.
* Add regression test against habtm memoized singular_idsAlberto Almagro2018-10-161-0/+12
| | | | | | | | | | | | | | | Starting in Rails 5.0.0 and still present in Rails 5.2.1, `singular_ids` got memoized and didn't reload after more items were added to the relation. Although 19c8071 happens to fix the issue, it only adds tests for `has_many` relations while this bug only affected `has_and_belongs_to_many` relations. This commit adds a regression test to ensure it never happens again with `habtm` relations. Ensures #34179 never gets reproduced.
* Ensure to test that `project.developers` is ordered by `developers.name desc`Ryuta Kamizono2018-10-151-1/+1
| | | | | | | | | `developers.name desc` was added at d59f3a7, but any test case isn't failed even if the `developers.name desc` is removed since all tested developers are consistently ordered on both `name` and `id`. I changed one developers creation ordering to ensure to test that `project.developers` is ordered by `developers.name desc`.
* Call `define_attribute_methods` before `assert_no_queries` to address CI ↵Ryuta Kamizono2018-10-091-0/+8
| | | | | | | | | | | | flakiness Follow up 45be690f8e6db019aac6198ba49d608a2e14824b. Somehow calling `define_attribute_methods` in `build`/`new` sometimes causes the `table_exists?` query. To address CI flakiness due to `assert_no_queries` failure, ensure `define_attribute_methods` before `assert_no_queries`.
* Remove `ignore_none: false` to assert no queries more strictlyRyuta Kamizono2018-10-051-4/+4
| | | | Follow up 811be477786455d144819a5e9fbb7f9f54b8da69.
* Use `assert_no_queries` not to ignore BEGIN/COMMIT queriesRyuta Kamizono2018-10-051-1/+1
| | | | | | | | | `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.
* Fix numericality validator not to be affected by custom getterRyuta Kamizono2018-08-131-1/+1
| | | | | | | | | | | | | | | | | | | | Since fe9547b6, numericality validator would parse raw value only when a value came from user to work type casting to a value from database. But that was caused a regression that the validator would work against getter value instead of parsed raw value, a getter is sometimes customized by people. #33550 There we never guarantees that the value before type cast was going to the used in this validation (actually here is only place that getter value might not be used), but we should not change the behavior unless there is some particular reason. The purpose of fe9547b6 is to work type casting to a value from database. We could achieve the purpose by using `read_attribute`, without using getter value. Fixes #33550.
* `references(:developers_projects_join)` isn't needed if using `where` with ↵Ryuta Kamizono2018-06-261-16/+2
| | | | hash condition
* Replace `assert !` with `assert_not`Daniel Colson2018-04-191-1/+1
| | | | | This autocorrects the violations after adding a custom cop in 3305c78dcd.
* Deprecate update_attributes and update_attributes!Eddie Lebow2018-02-171-1/+1
| | | | Closes #31998
* Remove extra whitespaceDaniel Colson2018-01-251-7/+7
|
* Use assert_empty and assert_not_emptyDaniel Colson2018-01-251-17/+17
|
* Use assert_predicate and assert_not_predicateDaniel Colson2018-01-251-41/+41
|
* Remove deprecated support to passing a class to `:class_name` on associationsRafael Mendonça França2017-10-231-13/+0
|
* 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
|
* Remove a redundant test case of HABTM_associations_testKoichi ITO2017-05-311-13/+0
|
* Define path with __dir__bogdanvlviv2017-05-231-1/+1
| | | | | | ".. with __dir__ we can restore order in the Universe." - by @fxn Related to 5b8738c2df003a96f0e490c43559747618d10f5f
* Don't attempt to create a new record that was already created.Isaac Betesh2017-04-201-0/+20
| | | | Fixes #24032
* Correct spellingBenjamin Fleischer2017-02-051-2/+2
| | | | | | | ``` go get -u github.com/client9/misspell/cmd/misspell misspell -w -error -source=text . ```
* Deprecate reflection class name to accept a classKir Shatrov2017-01-091-2/+4
| | | | | | | | The idea of `class_name` as an option of reflection is that passing a string would allow us to lazy autoload the class. Using `belongs_to :client, class_name: Customer` is eagerloading models more than necessary and creating possible circular dependencies.
* Remove deprecated force reload argument in association readersRafael Mendonça França2016-12-291-6/+0
|
* Respect new records for `CollectionProxy#uniq`Ryuta Kamizono2016-11-131-1/+1
| | | | | | | | | | | | | Currently if `CollectionProxy` has more than one new record, `CollectionProxy#uniq` result is incorrect. And `CollectionProxy#uniq` was aliased to `distinct` in a1bb6c8b06db. But the `uniq` method and the `SELECT DISTINCT` method are different methods. The doc in `CollectionProxy` is for the `SELECT DISTINCT` method, not for the `uniq` method. Therefore, reverting the alias in `CollectionProxy` to fix the inconsistency and to have the both methods.
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-2/+2
|
* Merge PR #19759Arthur Neves2016-10-281-0/+13
|\ | | | | | | Fix for has_and_belongs_to_many & has_many_through associations
| * Fix for has_and_belongs_to_many & has_many_through associations while ↵Mehmet Emin İNAÇ2016-02-131-0/+13
| | | | | | | | | | | | | | | | partial_writes is false This will fix #19663 Also with this fix, active record does not fire unnecassary update queries while partial_writes is true
* | Fix HABTM associations join table resolver bug on constants and symbolsMehmet Emin İNAÇ2016-10-271-1/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Using Constant and symbol class_name option for associations are valid but raises exception on HABTM associations. There was a test case which tries to cover symbol class_name usage but doesn't cover correctly. Fixed both symbol usage and constant usage as well. These are all working as expected now; ``` has_and_belongs_to_many :foos, class_name: 'Foo' has_and_belongs_to_many :foos, class_name: :Foo has_and_belongs_to_many :foos, class_name: Foo ``` Closes #23767
* | improve error message when include assertions failMichael Grosser2016-09-161-10/+10
| | | | | | | | | | | | 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
* | Add three new rubocop rulesRafael Mendonça França2016-08-161-4/+4
| | | | | | | | | | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* | Fix broken alignments caused by auto-correct commit 411ccbdRyuta Kamizono2016-08-101-1/+2
| | | | | | | | Hash syntax auto-correcting breaks alignments. 411ccbdab2608c62aabdb320d52cb02d446bb39c
* | remove redundant curlies from hash argumentsXavier Noria2016-08-061-4/+2
| |
* | modernizes hash syntax in activerecordXavier Noria2016-08-061-46/+46
| |
* | applies new string literal convention in activerecord/testXavier Noria2016-08-061-82/+82
| | | | | | | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* | Merge pull request #25767 from ↵Rafael França2016-07-271-0/+6
|\ \ | | | | | | | | | | | | kamipo/association_name_is_the_same_as_join_table_name Correctly return `associated_table` when `associated_with?` is true
| * | Correctly return `associated_table` when `associated_with?` is trueRyuta Kamizono2016-07-101-0/+6
| | | | | | | | | | | | | | | | | | | | | `AssociationQueryHandler` requires `association` initialized `TableMetadata` even if `table_name == arel_table.name`. Fixes #25689.
* | | Move the warning about composite primary key to `AttributeMethods::PrimaryKey`Ryuta Kamizono2016-07-021-1/+1
|/ / | | | | | | | | | | | | | | | | | | | | Actually schema dumper/creation supports composite primary key (#21614). Therefore it should not show the warning about composite primary key in connection adapter. This change moves the warning to `AttributeMethods::PrimaryKey` and suppress the warning for habtm join table. Fixes #25388.
* | remove args from assert_nothing_raised in testsTara Scherner de la Fuente2016-02-221-1/+1
| |
* | fix typoLobsiinvok2016-02-201-1/+1
| |
* | eliminate warnings about multiple primary keys on habtm join tablesAaron Patterson2016-02-191-0/+13
|/ | | | | | | | habtm join tables commonly have two id columns and it's OK to make those two id columns a primary key. This commit eliminates the warnings for join tables that have this setup. ManageIQ/manageiq#6713
* Typos in AR testsAkira Matsuda2016-02-031-2/+2
|
* Ensure `has_and_belongs_to_many` works with `belongs_to_required_by_default`Sean Griffin2015-10-291-0/+6
| | | | | | | | | | | | | Before this commit, if `ActiveRecord::Base.belongs_to_required_by_default` is set to `true`, then creating a record through `has_and_belongs_to_many` fails with the cryptic error message `Left side must exist`. This is because `inverse_of` isn't working properly in this case, presumably since we're doing trickery with anonymous classes in the middle. Rather than following this rabbit hole to try and get `inverse_of` to work in a case that we know is not publicly supported, we can just turn off this validation to match the behavior of 4.2 and earlier.
* Merge pull request #18383 from ↵Rafael Mendonça França2015-10-271-0/+19
|\ | | | | | | | | | | scambra/habtm-with-where-includes-16032-for-master Includes HABTM returns correct size now
| * Includes HABTM returns correct size now. It's caused by the join dependencySergio Cambra2015-01-071-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | only instantiates one HABTM object because the join table hasn't a primary key. Updated commit from @bigxiang commit dbaa837 Fixes #16032. Examples: before: Project.first.salaried_developers.size # => 3 Project.includes(:salaried_developers).first.salaried_developers.size # => 1 after: Project.first.salaried_developers.size # => 3 Project.includes(:salaried_developers).first.salaried_developers.size # => 3
* | Include association's `unscope` when preloadingJimmy Bourassa2015-09-091-0/+21
| |
* | Removed mocha from Active Record Part 1Ronak Jangir2015-08-251-3/+4
| |
* | use correct DB connection for generated HABTM tableMatt Hanlon2015-08-071-0/+12
| |