提交 71db2420 编写于 作者: N Neeraj Singh

calling default_scope without a proc will raise ArgumentError

Calling default_scope without a proc will now raise `ArgumentError`.
上级 aa3ff85f
* Calling default_scope without a proc will now raise `ArgumentError`.
*Neeraj Singh*
* Removed deprecated method `type_cast_code` from Column.
*Neeraj Singh*
......
......@@ -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]
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册