Skip to content

Commit 50cbc03

Browse files
committed
Remove deprecated scope use without passing a callable object.
Removed tests from deprecated code.
1 parent 9105c59 commit 50cbc03

File tree

3 files changed

+4
-23
lines changed

3 files changed

+4
-23
lines changed

activerecord/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Remove deprecated `scope` use without passing a callable object.
2+
3+
*Arun Agrawal*
4+
15
* Remove deprecated `transaction_joinable=` in favor of `begin_transaction`
26
with `:joinable` option.
37

activerecord/lib/active_record/scoping/named.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,6 @@ def scope_attributes? # :nodoc:
141141
def scope(name, body, &block)
142142
extension = Module.new(&block) if block
143143

144-
# Check body.is_a?(Relation) to prevent the relation actually being
145-
# loaded by respond_to?
146-
if body.is_a?(Relation) || !body.respond_to?(:call)
147-
ActiveSupport::Deprecation.warn(
148-
"Using #scope without passing a callable object is deprecated. For " \
149-
"example `scope :red, where(color: 'red')` should be changed to " \
150-
"`scope :red, -> { where(color: 'red') }`. There are numerous gotchas " \
151-
"in the former usage and it makes the implementation more complicated " \
152-
"and buggy. (If you prefer, you can just define a class method named " \
153-
"`self.red`.)"
154-
)
155-
end
156-
157144
singleton_class.send(:define_method, name) do |*args|
158145
if body.respond_to?(:call)
159146
scope = all.scoping { body.call(*args) }

activerecord/test/cases/scoping/named_scoping_test.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -435,16 +435,6 @@ def test_scoped_are_lazy_loaded_if_table_still_does_not_exist
435435
end
436436
end
437437

438-
def test_eager_scopes_are_deprecated
439-
klass = Class.new(ActiveRecord::Base)
440-
klass.table_name = 'posts'
441-
442-
assert_deprecated do
443-
klass.scope :welcome_2, klass.where(:id => posts(:welcome).id)
444-
end
445-
assert_equal [posts(:welcome).title], klass.welcome_2.map(&:title)
446-
end
447-
448438
def test_eager_default_scope_relations_are_remove
449439
klass = Class.new(ActiveRecord::Base)
450440
klass.table_name = 'posts'

0 commit comments

Comments
 (0)