From a1a2951518b2a4249101ebc87694800a345512f7 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Sat, 23 Mar 2013 14:58:21 -0400 Subject: [PATCH 1/2] unscoped works with named scope [ci skip] Update comment to reflect that unscoped works with named scope even when named scope is using without block form --- activerecord/lib/active_record/scoping/default.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/activerecord/lib/active_record/scoping/default.rb b/activerecord/lib/active_record/scoping/default.rb index 5bd481082e1f3..cde4f29d084b8 100644 --- a/activerecord/lib/active_record/scoping/default.rb +++ b/activerecord/lib/active_record/scoping/default.rb @@ -27,14 +27,6 @@ module ClassMethods # 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 From 36a45230dac4546b71b145681cf553a5a4f9eccb Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Sat, 23 Mar 2013 14:57:07 -0400 Subject: [PATCH 2/2] enhance unscoped tests Make it obvious that using unscoped with another scope without the block works --- activerecord/test/cases/relation_scoping_test.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/activerecord/test/cases/relation_scoping_test.rb b/activerecord/test/cases/relation_scoping_test.rb index 239004a2236bc..6cd89b622703d 100644 --- a/activerecord/test/cases/relation_scoping_test.rb +++ b/activerecord/test/cases/relation_scoping_test.rb @@ -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 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