aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/scoping/default_scoping_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* unscope now works on default_scope after ↵Rafael Mendonça França2013-11-021-1/+1
| | | | 94924dc32baf78f13e289172534c2e71c9c8cade
* remove trailing whitespace added with b057765 [ci skip].Yves Senn2013-10-211-2/+2
|
* Allow unscope to work with `where.not`Eric Hankins2013-10-211-6/+14
| | | | | | Allows you to call #unscope on a relation with negative equality operators, i.e. Arel::Nodes::NotIn and Arel::Nodes::NotEqual that have been generated through the use of where.not.
* asakusa.rb hack night!Aaron Patterson + Akira Matsuda2013-08-061-0/+2
| | | | Fix in-memory tests
* Revert change on ActiveRecord::Relation#order method that prepends newRafael Mendonça França2013-07-291-4/+4
| | | | | | | | | | | | | | | order on the old ones The previous behavior added a major backward incompatibility since it impossible to have a upgrade path without major changes on the application code. We are taking the most conservative path to be consistent with the idea of having a smoother upgrade on Rails 4. We are reverting the behavior for what was in Rails 3.x and, if needed, we will implement a new API to prepend the order clauses in Rails 4.1.
* close our connection when we are doneAaron Patterson2013-07-081-1/+6
|
* Simplify/fix implementation of default scopesJon Leighton2013-06-281-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The previous implementation was necessary in order to support stuff like: class Post < ActiveRecord::Base default_scope where(published: true) scope :ordered, order("created_at") end If we didn't evaluate the default scope at the last possible moment before sending the SQL to the database, it would become impossible to do: Post.unscoped.ordered This is because the default scope would already be bound up in the "ordered" scope, and therefore wouldn't be removed by the "Post.unscoped" part. In 4.0, we have deprecated all "eager" forms of scopes. So now you must write: class Post < ActiveRecord::Base default_scope { where(published: true) } scope :ordered, -> { order("created_at") } end This prevents the default scope getting bound up inside the "ordered" scope, which means we can now have a simpler/better/more natural implementation of default scoping. A knock on effect is that some things that didn't work properly now do. For example it was previously impossible to use #except to remove a part of the default scope, since the default scope was evaluated after the call to #except.
* Delegate #unscope query methodCarlos Antonio da Silva2013-04-281-0/+10
|
* split relation_scoping_test.rb's default scoping tests into another fileTakehiro Adachi2013-03-301-0/+360