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

Merge pull request #9889 from neerajdotname/unscoped

Unscoped works with other named scope even without block form
This commit is contained in:
Rafael Mendonça França 2013-03-23 13:04:09 -07:00
commit bad0b81a07
2 changed files with 4 additions and 8 deletions

View file

@ -27,14 +27,6 @@ module ActiveRecord
# Post.unscoped {
# Post.limit(10) # Fires "SELECT * FROM posts LIMIT 10"
# }
#
# It is recommended that you use the block form of unscoped because
# chaining unscoped with +scope+ does not work. Assuming that
# +published+ is a +scope+, the following two statements
# are equal: the +default_scope+ is applied on both.
#
# Post.unscoped.published
# Post.published
def unscoped
block_given? ? relation.scoping { yield } : relation
end

View file

@ -634,7 +634,11 @@ class DefaultScopingTest < ActiveRecord::TestCase
assert_equal [DeveloperCalledJamis.find(developers(:poor_jamis).id)], DeveloperCalledJamis.poor
assert DeveloperCalledJamis.unscoped.poor.include?(developers(:david).becomes(DeveloperCalledJamis))
assert_equal 11, DeveloperCalledJamis.unscoped.length
assert_equal 1, DeveloperCalledJamis.poor.length
assert_equal 10, DeveloperCalledJamis.unscoped.poor.length
assert_equal 10, DeveloperCalledJamis.unscoped { DeveloperCalledJamis.poor }.length
end
def test_default_scope_select_ignored_by_aggregations