aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/scoping/default_scoping_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Fix indentation [ci skip]Ryuta Kamizono2019-02-271-2/+2
|
* Fix random CI failure due to non-deterministic sorting orderRyuta Kamizono2019-02-271-5/+5
| | | | https://travis-ci.org/rails/rails/jobs/499061043#L1187-L1193
* Fixes #33610Darwin D Wu2018-09-111-0/+16
| | | | | | | | | | | | In order to avoid double assignments of nested_attributes for `has_many` relations during record initialization, nested_attributes in `create_with` should not be passed into `klass.new` and have them populate during `initialize_internals_callback` with scope attributes. However, `create_with` keys should always have precedence over where clauses, so if there are same keys in both `create_with` and `where_values_hash`, the value in `create_with` should be the one that's used.
* Use assert_no_match for test_order_to_unscope_reorderingYasuo Honda2018-04-201-1/+1
|
* Replace `assert !` with `assert_not`Daniel Colson2018-04-191-1/+1
| | | | | This autocorrects the violations after adding a custom cop in 3305c78dcd.
* Use assert_empty and assert_not_emptyDaniel Colson2018-01-251-2/+2
|
* Use assert_predicate and assert_not_predicateDaniel Colson2018-01-251-2/+2
|
* Merge pull request #28313 from sandrew/masterRyuta Kamizono2018-01-151-0/+12
|\ | | | | | | Allow unscoping of left_outer_joins
* | Fix postgres ordering issue on default scoping testGabriel Sobrinho2017-11-131-15/+15
| |
* | Merge remote-tracking branch 'origin/master' into unlock-minitestRafael Mendonça França2017-08-011-1/+36
|\ \
| * | Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
| | |
| * | 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.
| * | 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
| | |
* | | 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.
* | Fix a failed AR test when running with OracleAdapterKoichi ITO2017-03-311-0/+2
| |
* | 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.
* 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 ]
* Replace sleep with synchronizationMatthew Draper2017-01-021-1/+7
|
* "Use assert_nil if expecting nil. This will fail in minitest 6."Akira Matsuda2016-12-251-2/+2
|
* 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-161-2/+2
| | | | | | 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-1/+1
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* modernizes hash syntax in activerecordXavier Noria2016-08-061-17/+17
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-81/+81
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* 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?
* Execute default_scope defined by abstract class within the scope of subclassMehmet Emin İNAÇ2016-03-081-0/+12
|
* Allow `joins` to be unscopedTakashi Kokubun2016-01-311-0/+12
|
* Skip the STI condition when evaluating a default scopeMatthew Draper2016-01-121-0/+14
| | | | | | | | | | | | | Given a default_scope on a parent of the current class, where that parent is not the base class, the parent's STI condition would become attached to the evaluated default scope, and then override the child's own STI condition. Instead, we can treat the STI condition as though it is a default scope, and skip it in this situation: the scope will be merged into the base relation, which already contains the correct STI condition. Fixes #22426.
* Merge pull request #19770 from vngrs/prevent_duplicated_where_clausesRafael Mendonça França2015-08-131-0/+6
|\ | | | | Prevent duplicating `where` clauses
| * Prevent duplicating `where` clauses when model is extended from an abstract ↵Mehmet Emin İNAÇ2015-04-151-0/+6
| | | | | | | | | | | | | | | | | | | | class Fixes #19528 fix for mysql2 test better test
* | Fix unscope for less thanTAKAHASHI Kazuaki2015-03-271-0/+12
|/ | | | | | Code such as the following will be corrected. Developer.where(id: -Float::INFINITY...2).unscope(where: :id)
* `WhereClause#predicates` does not need to be publicSean Griffin2015-01-271-4/+4
| | | | | | | | | | | The only place it was accessed was in tests. Many of them have another way that they can test their behavior, that doesn't involve reaching into internals as far as they did. `AssociationScopeTest` is testing a situation where the where clause would have one bind param per predicate, so it can just ignore the predicates entirely. The where chain test was primarly duplicating the logic tested on `WhereClause` directly, so I instead just make sure it calls the appropriate method which is fully tested in isolation.
* Remove all references to `where_values` in testsSean Griffin2015-01-251-5/+5
|
* Remove all cases of manuallly wrapping `Arel::Nodes::Quoted`Sean Griffin2014-12-291-4/+2
| | | | | | | | | | This is no longer required now that we are injecting a type caster object into the Arel table, with the exception of uniqueness validations. Since it calls `ConnectionAdapter#type_cast`, the value has already been cast for the database. We don't want Arel to attempt to cast it further, so we need to continue wrapping it in a quoted node. This can potentially go away when this validator is refactored to make better use of `where` or the predicate builder.
* Inform Arel that we don't need to cast a value in testsSean Griffin2014-12-261-2/+4
| | | | | | | Part of the larger refactoring to remove type casting from Arel. We can inform it that we already have the right type by wrapping the value in an `Arel::Nodes::Quoted`. This commit can be reverted when we have removed type casting from Arel in Rail 5.1
* Allow to unscope where conditions using `arel_table` with Symboldeeeki2014-12-031-0/+8
| | | | | | This commit fixes the following case. User.where(User.arel_table[:created_at].lteq(1.year.ago)).unscope(where :created_at)
* Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-32/+32
|
* Build fix when running in isolationArun Agrawal2014-11-141-0/+1
| | | | | `Computer` class needs to be require See #17217 for more details
* Skip StatementCache for eager loaded associations (Fixes #16761)Sammy Larbi2014-09-041-1/+20
| | | | | | Eagerly loaded collection and singular associations are ignored by the StatementCache, which causes errors when the queries they generate reference columns that were not eagerly loaded. This commit skips the creation of the StatementCache as a fix for these scenarios.
* Add tests for default scope behaviour changeJon Leighton2014-02-231-0/+18
| | | | See #13875
* Let `unscope` ignore non Arel scope.where_valuesWashington Luiz2014-01-301-0/+10
|
* Fix bad usage of #select with hashCarlos Antonio da Silva2013-12-031-1/+1
|
* Fix ActiveRecord::Relation#unscopeJon Leighton2013-11-201-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I'm pretty confused about the addition of this method. The documentation says that it was intended to allow the removal of values from the default scope (in contrast to #except). However it behaves exactly the same as except: https://gist.github.com/jonleighton/7537008 (other than having a slightly enhanced syntax). The removal of the default scope is allowed by 94924dc32baf78f13e289172534c2e71c9c8cade, which was not a change we could make until 4.1 due to the need to deprecate things. However after that change #unscope still gives us nothing that #except doesn't already give us. However there *is* a desire to be able to unscope stuff in a way that persists across merges, which would allow associations to be defined which unscope stuff from the default scope of the associated model. E.g. has_many :comments, -> { unscope where: :trashed } So that's what this change implements. I've also corrected the documentation. I removed the guide references to #except as I think unscope really supercedes #except now. While we're here, there's also a potential desire to be able to write this: has_many :comments, -> { unscoped } However, it doesn't make sense and would not be straightforward to implement. While with #unscope we're specifying exactly what we want to be removed from the relation, with "unscoped" we're just saying that we want it to not have some things which were added earlier on by the default scope. However in the case of an association, we surely don't want *all* conditions to be removed, otherwise the above would just become "SELECT * FROM comments" with no foreign key constraint. To make the above work, we'd have to somehow tag the relation values which get added when evaluating the default scope in order to differentiate them from other relation values. Which is way too much complexity and therefore not worth it when most use cases can be satisfied with unscope. Closes #10643, #11061.
* Don't skip tests if we don't need to.Rafael Mendonça França2013-11-081-25/+23
| | | | | | | We can conditional define the tests depending on the adapter or connection. Lets keep the skip for fail tests that need to be fixed.