aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/scoping
Commit message (Collapse)AuthorAgeFilesLines
* Fix random CI failure due to non-deterministic sorting orderRyuta Kamizono2017-08-131-2/+4
| | | | https://travis-ci.org/rails/rails/jobs/263617099#L769-L775
* Merge remote-tracking branch 'origin/master' into unlock-minitestRafael Mendonça França2017-08-013-1/+40
|\
| * Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-193-0/+6
| |
| * Fix unscoping `default_scope` for `Preloader`Ryuta Kamizono2017-07-191-0/+2
| |
| * Fix unscoping `default_scope` in STI associationsRyuta Kamizono2017-07-191-0/+16
| | | | | | | | | | | | | | Since 5c71000, it has lost to be able to unscope `default_scope` in STI associations. This change will use `.empty_scope?` instead of `.values.empty?` to regard as an empty scope if only have `type_condition`.
| * Post.joins(:users) should not be affected by `User.current_scope`Sean Griffin2017-07-171-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change was introduced by #18109. The intent of that change was to specifically apply `unscoped`, not to allow all changes to `current_scope` to affect the join. The idea of allowing `current_scope` to affect joins is interesting and potentially more consistent, but has sever problems associated with it. The fact that we're specifically stripping out joins indicates one such problem (and potentially leads to invalid queries). Ultimately it's difficult to reason about what `Posts.joins(:users)` actually means if it's affected by `User.current_scope`, and it's difficult to specifically control what does or doesn't get added. If we were starting from scratch, I don't think I'd have `joins` be affected by `default_scope` either, but that's too big of a breaking change to make at this point. With this change, we no longer apply `current_scope` when bringing in joins, with the singular exception of the motivating use case which introduced this bug, which is providing a way to *opt-out* of having the default scope apply to joins. Fixes #29338.
| * Enable `Layout/FirstParameterIndentation` copRyuta Kamizono2017-07-171-1/+1
| | | | | | | | | | | | | | We have some indentation cops. But now there is a little inconsistent params indentations. Enable `Layout/FirstParameterIndentation` cop to prevent newly inconsistent indentation added and auto-correct to existing violations.
| * Fix `create_with` using both string and symbolRyuta Kamizono2017-07-161-0/+5
| | | | | | | | | | | | | | This is related with #27680. Since `where_values_hash` keys constructed by `where` are string, so we need `stringify_keys` to `create_with_value` before merging it.
* | Merge branch 'master' into unlock-minitestKasper Timm Hansen2017-07-151-0/+9
|\|
| * Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-023-3/+0
| | | | | | | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
| * Enforce frozen string in RubocopKir Shatrov2017-07-013-0/+3
| |
| * Fix to scoping is correctly restoredRyuta Kamizono2017-06-291-0/+9
| | | | | | | | | | | | | | | | This regression was caused by #23004. If STI subclass is using scoping in parent class scoping, `current_scope` in subclass is never restored. I fixed to restore `current_scope` to previous value correctly.
* | Merge branch 'master' into unlock-minitestRafael Mendonça França2017-06-021-0/+6
|\|
| * Add missing `delegate :extending, to: :all`Ryuta Kamizono2017-06-011-0/+6
| |
* | Merge branch 'master' into unlock-minitestKasper Timm Hansen2017-05-291-4/+11
|\|
| * Fix crashing on circular left join references with scopingRyuta Kamizono2017-05-241-2/+9
| | | | | | | | Follow up of #25702.
| * Restore `fixtures :author_addresses`Ryuta Kamizono2017-04-271-2/+2
| | | | | | | | | | This change reverted in eac6f369 but it is needed for data integrity. See #25328.
* | Explicitly create necessary data for testyuuji.yaginuma2017-05-131-0/+4
|/ | | | | | `DefaultScopingWithThreadTest` expects that there are two or more of `developers` data, but have not created data in the test. Therefore, tests may fail depending on execution order.
* Revert "Merge pull request #27636 from ↵Rafael Mendonça França2017-04-261-2/+2
| | | | | | | | | mtsmfm/disable-referential-integrity-without-superuser-privilege-take-2" This reverts commit c1faca6333abe4b938b98fedc8d1f47b88209ecf, reversing changes made to 8c658a0ecc7f2b5fc015d424baf9edf6f3eb2b0b. See https://github.com/rails/rails/pull/27636#issuecomment-297534129
* Fix a failed AR test when running with OracleAdapterKoichi ITO2017-03-311-0/+2
|
* Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser ↵Fumiaki MATSUSHIMA2017-03-261-2/+2
| | | | | | | | | | | | | | | privileges (take 2) Re-create https://github.com/rails/rails/pull/21233 eeac6151a5 was reverted (127509c071b4) because it breaks tests. ---------------- ref: 72c1557254 - We must use `authors` fixture with `author_addresses` because of its foreign key constraint. - Tests require PostgreSQL >= 9.4.2 because it had a bug about `ALTER CONSTRAINTS` and fixed in 9.4.2.
* Use `load` rather than `collect` for force loadingRyuta Kamizono2017-03-191-9/+9
| | | | | | | Since b644964b `ActiveRecord::Relation` includes `Enumerable` so delegating `collect`, `all?`, and `include?` are also unneeded. `collect` without block returns `Enumerable` without preloading by that. We should use `load` rather than `collect` for force loading.
* Fix fragile test (`AssociationProxyTest#test_save_on_parent_saves_children`)Fumiaki MATSUSHIMA2017-03-161-36/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If we run only following tests: - test/cases/scoping/default_scoping_test.rb - test/cases/associations_test.rb ``` $ cat Rakefile.test require "rake/testtask" ENV["ARCONN"] = "postgresql" Rake::TestTask.new do |t| t.libs << "test" t.test_files = %w( test/cases/scoping/default_scoping_test.rb test/cases/associations_test.rb ) end ``` a test will fail: ``` $ bundle exec rake test -f Rakefile.test /app/activesupport/lib/active_support/core_ext/enumerable.rb:20: warning: method redefined; discarding old sum Using postgresql Run options: --seed 11830 # Running: .........................................................................................F................ Finished in 6.939055s, 15.2759 runs/s, 27.9577 assertions/s. 1) Failure: AssociationProxyTest#test_save_on_parent_saves_children [/app/activerecord/test/cases/associations_test.rb:185]: Expected: 1 Actual: 2 106 runs, 194 assertions, 1 failures, 0 errors, 0 skips rake aborted! Command failed with status (1) /usr/local/bin/bundle:22:in `load' /usr/local/bin/bundle:22:in `<main>' Tasks: TOP => test (See full trace by running task with --trace) ``` In #28083, change `self.use_transactional_tests` to `false` but we forget to clean-up fixture. However we don't have to disable transaction except a few tests.
* Order array contents to match Relation#firstMatthew Draper2017-02-251-1/+1
|
* Ensure test threads share a DB connectioneileencodes2017-02-201-0/+2
| | | | | | | | | | | | | | | | | | | | | | | This ensures multiple threads inside a transactional test to see consistent database state. When a system test starts Puma spins up one thread and Capybara spins up another thread. Because of this when tests are run the database cannot see what was inserted into the database on teardown. This is because there are two threads using two different connections. This change uses the statement cache to lock the threads to using a single connection ID instead of each not being able to see each other. This code only runs in the fixture setup and teardown so it does not affect real production databases. When a transaction is opened we set `lock_thread` to `Thread.current` so we can keep track of which connection the thread is using. When we rollback the transaction we unlock the thread and then there will be no left-over data in the database because the transaction will roll back the correct connections. [ Eileen M. Uchitelle, Matthew Draper ]
* Revert "Merge pull request #21233 from ↵Rafael Mendonça França2017-01-031-2/+2
| | | | | | | | | | mtsmfm/disable-referential-integrity-without-superuser-privileges" This reverts commit eeac6151a55cb7d5f799e1ae33aa64a839cbc3aa, reversing changes made to 5c40239d3104543e70508360d27584a3e4dc5baf. Reason: Broke the isolated tests. https://travis-ci.org/rails/rails/builds/188721346
* Merge pull request #21233 from ↵Rafael França2017-01-031-2/+2
|\ | | | | | | | | mtsmfm/disable-referential-integrity-without-superuser-privileges Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser privileges
| * Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser ↵Fumiaki MATSUSHIMA2016-12-031-2/+2
| | | | | | | | | | | | | | | | | | privileges ref: 72c1557254 - We must use `authors` fixture with `author_addresses` because of its foreign key constraint. - Tests require PostgreSQL >= 9.4.2 because it had a bug about `ALTER CONSTRAINTS` and fixed in 9.4.2.
* | Replace sleep with synchronizationMatthew Draper2017-01-021-1/+7
| |
* | "Use assert_nil if expecting nil. This will fail in minitest 6."Akira Matsuda2016-12-252-3/+3
|/
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-292-3/+3
|
* let Regexp#match? be globally availableXavier Noria2016-10-271-1/+0
| | | | | | Regexp#match? should be considered to be part of the Ruby core library. We are emulating it for < 2.4, but not having to require the extension is part of the illusion of the emulation.
* improve error message when include assertions failMichael Grosser2016-09-163-11/+11
| | | | | | 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-162-11/+11
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* Fix warning: ambiguous first argumentRyuta Kamizono2016-08-121-1/+1
|
* Use `FETCH FIRST` for Oracle12 database and Arel Oracle12 visitorYasuo Honda2016-08-081-1/+1
| | | | | also test `ROWNUM <=` for Oracle 11g or older version of Oracle and Oracle visitor Oracle 12c database and Arel Oracle12 visitor supports better top N query.
* applies remaining conventions across the projectXavier Noria2016-08-061-1/+0
|
* modernizes hash syntax in activerecordXavier Noria2016-08-063-45/+45
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-063-139/+139
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Remove circular join references in join_dependencyTakashi Kokubun2016-07-281-0/+7
| | | | Fixes #25653.
* adds missing requiresXavier Noria2016-07-241-0/+1
|
* 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?
* Fix the calling `merge` method at first in a scopesuginoy2016-07-191-0/+7
| | | | | | | | | | | | Changing the order of method chaining `merge` and other query method such as `joins` should produce the same result. ```ruby class Topic < ApplicationRecord scope :safe_chaininig, -> { joins(:comments).merge(Comment.newest) } scope :unsafe_chaininig, -> { merge(Comment.newest).joins(:comments) } #=> NoMethodError end ```
* Fix some typos in comments.Joe Rafaniello2016-05-041-1/+1
| | | | [ci skip]
* Do not delegate `AR::Base#empty?` to `all`Sean Griffin2016-05-021-6/+0
| | | | | | | | | | Unlike `one?` and `none?`, `empty?` has interactions with methods outside of enumerable. It also doesn't fit in the same vein. `Topic.any?` makes sense. `Topic.empty?` does not, as `Topic` is not a container. Fixes #24808 Close #24812
* Delegate some additional methods in querying.rbKenta2016-03-301-0/+20
|
* Execute default_scope defined by abstract class within the scope of subclassMehmet Emin İNAÇ2016-03-081-0/+12
|
* Merge pull request #18109 from k0kubun/unscoped-joinsSean Griffin2016-02-111-0/+12
|\ | | | | | | | | | | Allow `joins` to be unscoped Fixes #13775
| * Allow `joins` to be unscopedTakashi Kokubun2016-01-311-0/+12
| |
* | Suppress :warning:sAkira Matsuda2016-01-281-1/+1
| |