1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

5 commits

Author SHA1 Message Date
Jon Leighton
8606a7fbe9 Fix scope chaining + STI
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.
2013-04-05 13:14:28 +01:00
Neeraj Singh
f029fb07c2 failing test for #9869 2013-04-05 13:14:28 +01:00
Takehiro Adachi
7be9e88682 split relation_scoping_test.rb's default scoping tests into another file 2013-03-30 13:23:01 +09:00
Takehiro Adachi
e4da432a3a rename named_scope_test.rb to a proper file name
The file name should be name_scoping_test.rb and the class should be
`NamedScopingTest` according to ActiveRecord::Scoping::Name
2013-03-30 13:15:37 +09:00
Takehiro Adachi
1fde758297 move tests for NamedScope and DefaultScope under test/cases/scoping/
The scoping/default.rb and scoping/named.rb got moved under scoping/ in
commit 2b22564c4e,
but the tests never did.
2013-03-30 13:13:18 +09:00