aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/scoping
Commit message (Collapse)AuthorAgeFilesLines
* Block a few default Class methods as scope name.Arthur Neves2014-04-031-0/+3
| | | | | | Add tests to make sure scopes cannot be create with names such as: private, protected, public. Make sure enum values don't collide with those methods too.
* do not rely on method_missing hitting arelAaron Patterson2014-03-241-2/+3
| | | | arel methods are not supposed to be public API for ActiveRecord
* Add tests for default scope behaviour changeJon Leighton2014-02-231-0/+18
| | | | See #13875
* Remove warnings for already defined methodsRafael Mendonça França2014-02-011-1/+3
|
* Let `unscope` ignore non Arel scope.where_valuesWashington Luiz2014-01-301-0/+10
|
* `scope` now raises on "dangerous" name conflictsGodfrey Chan2014-01-291-0/+57
| | | | | | | | | | Similar to dangerous attribute methods, a scope name conflict is dangerous if it conflicts with an existing class method defined within `ActiveRecord::Base` but not its ancestors. See also #13389. *Godfrey Chan*, *Philippe Creux*
* Ensure #second acts like #first AR finderJason Meller2014-01-201-4/+4
| | | | | | | | | | | | This commit bring the famous ordinal Array instance methods defined in ActiveSupport into ActiveRecord as fully-fledged finders. These finders ensure a default ascending order of the table's primary key, and utilize the OFFSET SQL verb to locate the user's desired record. If an offset is defined in the query, calling #second adds to the offset to get the actual desired record. Fixes #13743.
* 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
|
* Remove deprecated `scope` use without passing a callable object.Arun Agrawal2013-07-031-10/+0
| | | | Removed tests from deprecated code.
* calling default_scope without a proc will raise ArgumentErrorNeeraj Singh2013-07-021-3/+2
| | | | Calling default_scope without a proc will now raise `ArgumentError`.
* remove deprecated implicit join references.Yves Senn2013-06-291-5/+0
|
* 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
|
* Fix scope chaining + STIJon Leighton2013-04-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | See #9869 and #9929. The problem arises from the following example: class Project < ActiveRecord::Base scope :completed, -> { where completed: true } end class MajorProject < Project end When calling: MajorProject.where(tasks_count: 10).completed This expands to: MajorProject.where(tasks_count: 10).scoping { MajorProject.completed } However the lambda for the `completed` scope is defined on Project. This means that when it is called, `self` is Project rather than MajorProject. So it expands to: MajorProject.where(tasks_count: 10).scoping { Project.where(completed: true) } Since the scoping was applied on MajorProject, and not Project, this fails to apply the tasks_count condition. The solution is to make scoping apply across STI classes. I am slightly concerned about the possible side-effects of this, but no tests fail and it seems ok. I guess we'll see.
* failing test for #9869Neeraj Singh2013-04-051-0/+5
|
* split relation_scoping_test.rb's default scoping tests into another fileTakehiro Adachi2013-03-302-357/+360
|
* rename named_scope_test.rb to a proper file nameTakehiro Adachi2013-03-301-1/+1
| | | | | The file name should be name_scoping_test.rb and the class should be `NamedScopingTest` according to ActiveRecord::Scoping::Name
* move tests for NamedScope and DefaultScope under test/cases/scoping/Takehiro Adachi2013-03-302-0/+1150
The scoping/default.rb and scoping/named.rb got moved under scoping/ in commit 2b22564c4efaa63d4bbc006762838c4025c1bdca, but the tests never did.