mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
fix #scoped deprecations
This commit is contained in:
parent
e1a83690da
commit
1606bee64a
4 changed files with 16 additions and 15 deletions
|
@ -24,11 +24,11 @@ class EagerLoadIncludeFullStiClassNamesTest < ActiveRecord::TestCase
|
|||
old = ActiveRecord::Base.store_full_sti_class
|
||||
|
||||
ActiveRecord::Base.store_full_sti_class = false
|
||||
post = Namespaced::Post.find_by_title( 'Great stuff', :include => :tagging )
|
||||
post = Namespaced::Post.includes(:tagging).find_by_title('Great stuff')
|
||||
assert_nil post.tagging
|
||||
|
||||
ActiveRecord::Base.store_full_sti_class = true
|
||||
post = Namespaced::Post.find_by_title( 'Great stuff', :include => :tagging )
|
||||
post = Namespaced::Post.includes(:tagging).find_by_title('Great stuff')
|
||||
assert_instance_of Tagging, post.tagging
|
||||
ensure
|
||||
ActiveRecord::Base.store_full_sti_class = old
|
||||
|
|
|
@ -246,7 +246,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_include_polymorphic_has_one
|
||||
post = Post.find_by_id(posts(:welcome).id, :include => :tagging)
|
||||
post = Post.includes(:tagging).find posts(:welcome).id
|
||||
tagging = taggings(:welcome_general)
|
||||
assert_no_queries do
|
||||
assert_equal tagging, post.tagging
|
||||
|
@ -254,7 +254,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_include_polymorphic_has_one_defined_in_abstract_parent
|
||||
item = Item.find_by_id(items(:dvd).id, :include => :tagging)
|
||||
item = Item.includes(:tagging).find items(:dvd).id
|
||||
tagging = taggings(:godfather)
|
||||
assert_no_queries do
|
||||
assert_equal tagging, item.tagging
|
||||
|
@ -403,7 +403,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_include_has_many_through_polymorphic_has_many
|
||||
author = Author.find_by_id(authors(:david).id, :include => :taggings)
|
||||
author = Author.includes(:taggings).find authors(:david).id
|
||||
expected_taggings = taggings(:welcome_general, :thinking_general)
|
||||
assert_no_queries do
|
||||
assert_equal expected_taggings, author.taggings.uniq.sort_by { |t| t.id }
|
||||
|
|
|
@ -640,7 +640,7 @@ class FinderTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_find_by_one_attribute_with_conditions
|
||||
assert_equal accounts(:rails_core_account), Account.find_by_credit_limit(50, :conditions => ['firm_id = ?', 6])
|
||||
assert_equal accounts(:rails_core_account), Account.where('firm_id = ?', 6).find_by_credit_limit(50)
|
||||
end
|
||||
|
||||
def test_find_by_one_attribute_that_is_an_aggregate
|
||||
|
@ -680,12 +680,12 @@ class FinderTest < ActiveRecord::TestCase
|
|||
def test_dynamic_finder_on_one_attribute_with_conditions_returns_same_results_after_caching
|
||||
# ensure this test can run independently of order
|
||||
class << Account; self; end.send(:remove_method, :find_by_credit_limit) if Account.public_methods.any? { |m| m.to_s == 'find_by_credit_limit' }
|
||||
a = Account.find_by_credit_limit(50, :conditions => ['firm_id = ?', 6])
|
||||
assert_equal a, Account.find_by_credit_limit(50, :conditions => ['firm_id = ?', 6]) # find_by_credit_limit has been cached
|
||||
a = Account.where('firm_id = ?', 6).find_by_credit_limit(50)
|
||||
assert_equal a, Account.where('firm_id = ?', 6).find_by_credit_limit(50) # find_by_credit_limit has been cached
|
||||
end
|
||||
|
||||
def test_find_by_one_attribute_with_several_options
|
||||
assert_equal accounts(:unknown), Account.find_by_credit_limit(50, :order => 'id DESC', :conditions => ['id != ?', 3])
|
||||
assert_equal accounts(:unknown), Account.order('id DESC').where('id != ?', 3).find_by_credit_limit(50)
|
||||
end
|
||||
|
||||
def test_find_by_one_missing_attribute
|
||||
|
@ -719,7 +719,7 @@ class FinderTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_find_last_by_one_attribute_with_several_options
|
||||
assert_equal accounts(:signals37), Account.find_last_by_credit_limit(50, :order => 'id DESC', :conditions => ['id != ?', 3])
|
||||
assert_equal accounts(:signals37), Account.order('id DESC').where('id != ?', 3).find_last_by_credit_limit(50)
|
||||
end
|
||||
|
||||
def test_find_last_by_one_missing_attribute
|
||||
|
|
|
@ -140,9 +140,10 @@ class NamedScopeTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_active_records_have_scope_named__scoped__
|
||||
assert !Topic.find(:all, scope = {:conditions => "content LIKE '%Have%'"}).empty?
|
||||
scope = Topic.where("content LIKE '%Have%'")
|
||||
assert !scope.empty?
|
||||
|
||||
assert_equal Topic.find(:all, scope), Topic.scoped(scope)
|
||||
assert_equal scope, Topic.scoped(where: "content LIKE '%Have%'")
|
||||
end
|
||||
|
||||
def test_first_and_last_should_support_find_options
|
||||
|
@ -235,9 +236,9 @@ class NamedScopeTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_many_should_return_false_if_none_or_one
|
||||
topics = Topic.base.scoped(:conditions => {:id => 0})
|
||||
topics = Topic.base.where(:id => 0)
|
||||
assert !topics.many?
|
||||
topics = Topic.base.scoped(:conditions => {:id => 1})
|
||||
topics = Topic.base.where(:id => 1)
|
||||
assert !topics.many?
|
||||
end
|
||||
|
||||
|
@ -315,7 +316,7 @@ class NamedScopeTest < ActiveRecord::TestCase
|
|||
def test_chaining_with_duplicate_joins
|
||||
join = "INNER JOIN comments ON comments.post_id = posts.id"
|
||||
post = Post.find(1)
|
||||
assert_equal post.comments.size, Post.scoped(:joins => join).scoped(:joins => join, :conditions => "posts.id = #{post.id}").size
|
||||
assert_equal post.comments.size, Post.joins(join).joins(join).where("posts.id = #{post.id}").size
|
||||
end
|
||||
|
||||
def test_chaining_should_use_latest_conditions_when_creating
|
||||
|
|
Loading…
Reference in a new issue