Skip to content

Commit

Permalink
Merge pull request #9889 from neerajdotname/unscoped
Browse files Browse the repository at this point in the history
Unscoped works with other named scope even without block form
  • Loading branch information
rafaelfranca committed Mar 23, 2013
2 parents 9e8b7d9 + 36a4523 commit bad0b81
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
8 changes: 0 additions & 8 deletions activerecord/lib/active_record/scoping/default.rb
Expand Up @@ -27,14 +27,6 @@ module ClassMethods
# Post.unscoped { # Post.unscoped {
# Post.limit(10) # Fires "SELECT * FROM posts LIMIT 10" # 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 def unscoped
block_given? ? relation.scoping { yield } : relation block_given? ? relation.scoping { yield } : relation
end end
Expand Down
4 changes: 4 additions & 0 deletions activerecord/test/cases/relation_scoping_test.rb
Expand Up @@ -634,7 +634,11 @@ def test_unscoped_with_named_scope_should_not_have_default_scope
assert_equal [DeveloperCalledJamis.find(developers(:poor_jamis).id)], DeveloperCalledJamis.poor assert_equal [DeveloperCalledJamis.find(developers(:poor_jamis).id)], DeveloperCalledJamis.poor


assert DeveloperCalledJamis.unscoped.poor.include?(developers(:david).becomes(DeveloperCalledJamis)) 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.poor.length
assert_equal 10, DeveloperCalledJamis.unscoped { DeveloperCalledJamis.poor }.length
end end


def test_default_scope_select_ignored_by_aggregations def test_default_scope_select_ignored_by_aggregations
Expand Down

0 comments on commit bad0b81

Please sign in to comment.