From 71db2420a1ffb73dad6fd4ca64be01e422c2b37d Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Tue, 2 Jul 2013 07:08:12 +0530 Subject: [PATCH] calling default_scope without a proc will raise ArgumentError Calling default_scope without a proc will now raise `ArgumentError`. --- activerecord/CHANGELOG.md | 4 ++++ activerecord/lib/active_record/scoping/default.rb | 5 ++--- activerecord/test/cases/scoping/named_scoping_test.rb | 5 ++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index f99f1501f6..fe06670166 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,7 @@ +* Calling default_scope without a proc will now raise `ArgumentError`. + + *Neeraj Singh* + * Removed deprecated method `type_cast_code` from Column. *Neeraj Singh* diff --git a/activerecord/lib/active_record/scoping/default.rb b/activerecord/lib/active_record/scoping/default.rb index 59bdb9166e..a5d6aad3f0 100644 --- a/activerecord/lib/active_record/scoping/default.rb +++ b/activerecord/lib/active_record/scoping/default.rb @@ -83,12 +83,11 @@ def default_scope(scope = nil) scope = Proc.new if block_given? if scope.is_a?(Relation) || !scope.respond_to?(:call) - ActiveSupport::Deprecation.warn( - "Calling #default_scope without a block is deprecated. For example instead " \ + raise ArgumentError, + "Support for calling #default_scope without a block is removed. For example instead " \ "of `default_scope where(color: 'red')`, please use " \ "`default_scope { where(color: 'red') }`. (Alternatively you can just redefine " \ "self.default_scope.)" - ) end self.default_scopes += [scope] diff --git a/activerecord/test/cases/scoping/named_scoping_test.rb b/activerecord/test/cases/scoping/named_scoping_test.rb index 73ff8abb4e..abd0b8621a 100644 --- a/activerecord/test/cases/scoping/named_scoping_test.rb +++ b/activerecord/test/cases/scoping/named_scoping_test.rb @@ -445,14 +445,13 @@ def test_eager_scopes_are_deprecated assert_equal [posts(:welcome).title], klass.welcome_2.map(&:title) end - def test_eager_default_scope_relations_are_deprecated + def test_eager_default_scope_relations_are_remove klass = Class.new(ActiveRecord::Base) klass.table_name = 'posts' - assert_deprecated do + assert_raises(ArgumentError) do klass.send(:default_scope, klass.where(:id => posts(:welcome).id)) end - assert_equal [posts(:welcome).title], klass.all.map(&:title) end def test_subclass_merges_scopes_properly -- GitLab