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

extract deprecated code

This commit is contained in:
Jon Leighton 2012-04-22 12:28:26 +02:00
parent 618c5fc3c0
commit af27c8b041
3 changed files with 4 additions and 11 deletions

View file

@ -171,7 +171,7 @@ module ActiveRecord
# Article.published.featured.latest_article
# Article.featured.titles
def scope(name, body = {}, &block)
def scope(name, body, &block)
extension = Module.new(&block) if block
# Check body.is_a?(Relation) to prevent the relation actually being
@ -188,9 +188,7 @@ module ActiveRecord
end
singleton_class.send(:define_method, name) do |*args|
options = body.respond_to?(:call) ? unscoped { body.call(*args) } : body
options = scoped.apply_finder_options(options) if options.is_a?(Hash)
options = body.respond_to?(:call) ? unscoped { body.call(*args) } : body
relation = scoped.merge(options)
extension ? relation.extending(extension) : relation

View file

@ -459,11 +459,6 @@ class NamedScopeTest < ActiveRecord::TestCase
klass = Class.new(ActiveRecord::Base)
klass.table_name = 'posts'
assert_deprecated do
klass.scope :welcome, { :conditions => { :id => posts(:welcome).id } }
end
assert_equal [posts(:welcome).title], klass.welcome.map(&:title)
assert_deprecated do
klass.scope :welcome_2, klass.where(:id => posts(:welcome).id)
end

View file

@ -45,8 +45,8 @@ class Topic < ActiveRecord::Base
2
end
end
scope :named_extension, -> { { :extend => NamedExtension } }
scope :multiple_extensions, -> { { :extend => [MultipleExtensionTwo, MultipleExtensionOne] } }
scope :named_extension, :extend => NamedExtension
scope :multiple_extensions, :extend => [MultipleExtensionTwo, MultipleExtensionOne]
has_many :replies, :dependent => :destroy, :foreign_key => "parent_id"
has_many :replies_with_primary_key, :class_name => "Reply", :dependent => :destroy, :primary_key => "title", :foreign_key => "parent_title"