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

calling default_scope without a proc will raise ArgumentError

Calling default_scope without a proc will now raise `ArgumentError`.
This commit is contained in:
Neeraj Singh 2013-07-02 07:08:12 +05:30
parent aa3ff85f47
commit 71db2420a1
3 changed files with 8 additions and 6 deletions

View file

@ -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*

View file

@ -83,12 +83,11 @@ module ActiveRecord
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]

View file

@ -445,14 +445,13 @@ class NamedScopingTest < ActiveRecord::TestCase
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