aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-04-27 13:11:13 +0100
committerJon Leighton <j@jonathanleighton.com>2012-04-27 13:11:13 +0100
commit20ea8df6b5ba430cb4947a583faa22543cc9f20a (patch)
tree18eda7013200f462be29f6589fc7a66ad930326e /activerecord/test
parent0ed05b0e7379e0a6aa47c5677b90383b9f0132b2 (diff)
downloadrails-20ea8df6b5ba430cb4947a583faa22543cc9f20a.tar.gz
rails-20ea8df6b5ba430cb4947a583faa22543cc9f20a.tar.bz2
rails-20ea8df6b5ba430cb4947a583faa22543cc9f20a.zip
more deprecations manually fixed
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/eager_test.rb62
-rw-r--r--activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb14
-rw-r--r--activerecord/test/cases/finder_test.rb35
3 files changed, 53 insertions, 58 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index 781d244bf7..2d8b566c1d 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -61,10 +61,10 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def test_loading_conditions_with_or
- posts = authors(:david).posts.references(:comments).find(
- :all, :include => :comments,
- :conditions => "comments.body like 'Normal%' OR comments.#{QUOTED_TYPE} = 'SpecialComment'"
- )
+ posts = authors(:david).posts.references(:comments).scoped(
+ :includes => :comments,
+ :where => "comments.body like 'Normal%' OR comments.#{QUOTED_TYPE} = 'SpecialComment'"
+ ).all
assert_nil posts.detect { |p| p.author_id != authors(:david).id },
"expected to find only david's posts"
end
@@ -154,8 +154,8 @@ class EagerAssociationTest < ActiveRecord::TestCase
popular_post.readers.create!(:person => people(:michael))
popular_post.readers.create!(:person => people(:david))
- readers = Reader.scoped(:conditions => ["post_id = ?", popular_post.id],
- :include => {:post => :comments}).all
+ readers = Reader.scoped(:where => ["post_id = ?", popular_post.id],
+ :includes => {:post => :comments}).all
readers.each do |reader|
assert_equal [comment], reader.post.comments
end
@@ -167,8 +167,8 @@ class EagerAssociationTest < ActiveRecord::TestCase
car_post.categories << categories(:technology)
comment = car_post.comments.create!(:body => "hmm")
- categories = Category.scoped(:conditions => { 'posts.id' => car_post.id },
- :include => {:posts => :comments}).all
+ categories = Category.scoped(:where => { 'posts.id' => car_post.id },
+ :includes => {:posts => :comments}).all
categories.each do |category|
assert_equal [comment], category.posts[0].comments
end
@@ -491,7 +491,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def test_eager_with_has_many_through_join_model_with_conditions
- assert_equal Author.scoped(:include => :hello_post_comments,
+ assert_equal Author.scoped(:includes => :hello_post_comments,
:order => 'authors.id').first.hello_post_comments.sort_by(&:id),
Author.scoped(:order => 'authors.id').first.hello_post_comments.sort_by(&:id)
end
@@ -565,16 +565,16 @@ class EagerAssociationTest < ActiveRecord::TestCase
def test_eager_with_has_many_and_limit_and_high_offset_and_multiple_array_conditions
assert_queries(1) do
posts = Post.references(:authors, :comments).
- scoped(:include => [ :author, :comments ], :limit => 2, :offset => 10,
- :conditions => [ "authors.name = ? and comments.body = ?", 'David', 'go crazy' ]).all
+ scoped(:includes => [ :author, :comments ], :limit => 2, :offset => 10,
+ :where => [ "authors.name = ? and comments.body = ?", 'David', 'go crazy' ]).all
assert_equal 0, posts.size
end
end
def test_eager_with_has_many_and_limit_and_high_offset_and_multiple_hash_conditions
assert_queries(1) do
- posts = Post.scoped(:include => [ :author, :comments ], :limit => 2, :offset => 10,
- :conditions => { 'authors.name' => 'David', 'comments.body' => 'go crazy' }).all
+ posts = Post.scoped(:includes => [ :author, :comments ], :limit => 2, :offset => 10,
+ :where => { 'authors.name' => 'David', 'comments.body' => 'go crazy' }).all
assert_equal 0, posts.size
end
end
@@ -702,8 +702,8 @@ class EagerAssociationTest < ActiveRecord::TestCase
def test_eager_with_has_one_dependent_does_not_destroy_dependent
assert_not_nil companies(:first_firm).account
- f = Firm.scoped(:include => :account,
- :conditions => ["companies.name = ?", "37signals"]).first
+ f = Firm.scoped(:includes => :account,
+ :where => ["companies.name = ?", "37signals"]).first
assert_not_nil f.account
assert_equal companies(:first_firm, :reload).account, f.account
end
@@ -777,45 +777,45 @@ class EagerAssociationTest < ActiveRecord::TestCase
def test_limited_eager_with_order
assert_equal(
posts(:thinking, :sti_comments),
- Post.find(
- :all, :include => [:author, :comments], :conditions => { 'authors.name' => 'David' },
+ Post.scoped(
+ :includes => [:author, :comments], :where => { 'authors.name' => 'David' },
:order => 'UPPER(posts.title)', :limit => 2, :offset => 1
- )
+ ).all
)
assert_equal(
posts(:sti_post_and_comments, :sti_comments),
- Post.find(
- :all, :include => [:author, :comments], :conditions => { 'authors.name' => 'David' },
+ Post.scoped(
+ :includes => [:author, :comments], :where => { 'authors.name' => 'David' },
:order => 'UPPER(posts.title) DESC', :limit => 2, :offset => 1
- )
+ ).all
)
end
def test_limited_eager_with_multiple_order_columns
assert_equal(
posts(:thinking, :sti_comments),
- Post.find(
- :all, :include => [:author, :comments], :conditions => { 'authors.name' => 'David' },
+ Post.scoped(
+ :includes => [:author, :comments], :where => { 'authors.name' => 'David' },
:order => ['UPPER(posts.title)', 'posts.id'], :limit => 2, :offset => 1
- )
+ ).all
)
assert_equal(
posts(:sti_post_and_comments, :sti_comments),
- Post.find(
- :all, :include => [:author, :comments], :conditions => { 'authors.name' => 'David' },
+ Post.scoped(
+ :includes => [:author, :comments], :where => { 'authors.name' => 'David' },
:order => ['UPPER(posts.title) DESC', 'posts.id'], :limit => 2, :offset => 1
- )
+ ).all
)
end
def test_limited_eager_with_numeric_in_association
assert_equal(
people(:david, :susan),
- Person.references(:number1_fans_people).find(
- :all, :include => [:readers, :primary_contact, :number1_fan],
- :conditions => "number1_fans_people.first_name like 'M%'",
+ Person.references(:number1_fans_people).scoped(
+ :includes => [:readers, :primary_contact, :number1_fan],
+ :where => "number1_fans_people.first_name like 'M%'",
:order => 'people.id', :limit => 2, :offset => 0
- )
+ ).all
)
end
diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
index 7ddaf78848..22fd80df28 100644
--- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -681,10 +681,10 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
def test_join_table_alias
assert_equal(
3,
- Developer.references(:developers_projects_join).find(
- :all, :include => {:projects => :developers},
- :conditions => 'developers_projects_join.joined_on IS NOT NULL'
- ).size
+ Developer.references(:developers_projects_join).scoped(
+ :includes => {:projects => :developers},
+ :where => 'developers_projects_join.joined_on IS NOT NULL'
+ ).to_a.size
)
end
@@ -697,10 +697,10 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
assert_equal(
3,
- Developer.references(:developers_projects_join).find(
- :all, :include => {:projects => :developers}, :conditions => 'developers_projects_join.joined_on IS NOT NULL',
+ Developer.references(:developers_projects_join).scoped(
+ :includes => {:projects => :developers}, :where => 'developers_projects_join.joined_on IS NOT NULL',
:group => group.join(",")
- ).size
+ ).to_a.size
)
end
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index e2fcee1070..9dfc8a6025 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -981,11 +981,10 @@ class FinderTest < ActiveRecord::TestCase
end
def test_find_all_with_join
- developers_on_project_one = Developer.find(
- :all,
+ developers_on_project_one = Developer.scoped(
:joins => 'LEFT JOIN developers_projects ON developers.id = developers_projects.developer_id',
- :conditions => 'project_id=1'
- )
+ :where => 'project_id=1'
+ ).all
assert_equal 3, developers_on_project_one.length
developer_names = developers_on_project_one.map { |d| d.name }
assert developer_names.include?('David')
@@ -993,17 +992,15 @@ class FinderTest < ActiveRecord::TestCase
end
def test_joins_dont_clobber_id
- first = Firm.find(
- :first,
+ first = Firm.scoped(
:joins => 'INNER JOIN companies clients ON clients.firm_id = companies.id',
- :conditions => 'companies.id = 1'
- )
+ :where => 'companies.id = 1'
+ ).first
assert_equal 1, first.id
end
def test_joins_with_string_array
- person_with_reader_and_post = Post.find(
- :all,
+ person_with_reader_and_post = Post.scoped(
:joins => [
"INNER JOIN categorizations ON categorizations.post_id = posts.id",
"INNER JOIN categories ON categories.id = categorizations.category_id AND categories.type = 'SpecialCategory'"
@@ -1065,14 +1062,13 @@ class FinderTest < ActiveRecord::TestCase
def test_find_with_order_on_included_associations_with_construct_finder_sql_for_association_limiting_and_is_distinct
assert_equal 2, Post.scoped(:includes => { :authors => :author_address }, :order => 'author_addresses.id DESC ', :limit => 2).all.size
- assert_equal 3, Post.scoped(:include => { :author => :author_address, :authors => :author_address},
+ assert_equal 3, Post.scoped(:includes => { :author => :author_address, :authors => :author_address},
:order => 'author_addresses_authors.id DESC ', :limit => 3).all.size
end
def test_find_with_nil_inside_set_passed_for_one_attribute
- client_of = Company.find(
- :all,
- :conditions => {
+ client_of = Company.scoped(
+ :where => {
:client_of => [2, 1, nil],
:name => ['37signals', 'Summit', 'Microsoft'] },
:order => 'client_of DESC'
@@ -1083,9 +1079,8 @@ class FinderTest < ActiveRecord::TestCase
end
def test_find_with_nil_inside_set_passed_for_attribute
- client_of = Company.find(
- :all,
- :conditions => { :client_of => [nil] },
+ client_of = Company.scoped(
+ :where => { :client_of => [nil] },
:order => 'client_of DESC'
).map { |x| x.client_of }
@@ -1093,10 +1088,10 @@ class FinderTest < ActiveRecord::TestCase
end
def test_with_limiting_with_custom_select
- posts = Post.references(:authors).find(
- :all, :include => :author, :select => ' posts.*, authors.id as "author_id"',
+ posts = Post.references(:authors).scoped(
+ :includes => :author, :select => ' posts.*, authors.id as "author_id"',
:limit => 3, :order => 'posts.id'
- )
+ ).all
assert_equal 3, posts.size
assert_equal [0, 1, 1], posts.map(&:author_id).sort
end