aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-04-27 12:37:21 +0100
committerJon Leighton <j@jonathanleighton.com>2012-04-27 12:37:21 +0100
commit0ed05b0e7379e0a6aa47c5677b90383b9f0132b2 (patch)
treeb5b67fb711af82657ef42509724f490236cdb516 /activerecord/test/cases/associations
parent61555a0df11f535d46a0a631fbb0d0773613d08e (diff)
downloadrails-0ed05b0e7379e0a6aa47c5677b90383b9f0132b2.tar.gz
rails-0ed05b0e7379e0a6aa47c5677b90383b9f0132b2.tar.bz2
rails-0ed05b0e7379e0a6aa47c5677b90383b9f0132b2.zip
find and replace deprecated keys
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r--activerecord/test/cases/associations/belongs_to_associations_test.rb4
-rw-r--r--activerecord/test/cases/associations/cascaded_eager_loading_test.rb28
-rw-r--r--activerecord/test/cases/associations/eager_load_nested_include_test.rb2
-rw-r--r--activerecord/test/cases/associations/eager_singularization_test.rb14
-rw-r--r--activerecord/test/cases/associations/eager_test.rb126
-rw-r--r--activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb14
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb48
-rw-r--r--activerecord/test/cases/associations/has_one_associations_test.rb2
-rw-r--r--activerecord/test/cases/associations/has_one_through_associations_test.rb14
-rw-r--r--activerecord/test/cases/associations/inverse_associations_test.rb18
-rw-r--r--activerecord/test/cases/associations/join_model_test.rb30
11 files changed, 150 insertions, 150 deletions
diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb
index 65a353fdaf..0d6ba9dab1 100644
--- a/activerecord/test/cases/associations/belongs_to_associations_test.rb
+++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb
@@ -73,14 +73,14 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
def test_eager_loading_with_primary_key
Firm.create("name" => "Apple")
Client.create("name" => "Citibank", :firm_name => "Apple")
- citibank_result = Client.scoped(:conditions => {:name => "Citibank"}, :include => :firm_with_primary_key).first
+ citibank_result = Client.scoped(:where => {:name => "Citibank"}, :includes => :firm_with_primary_key).first
assert citibank_result.association_cache.key?(:firm_with_primary_key)
end
def test_eager_loading_with_primary_key_as_symbol
Firm.create("name" => "Apple")
Client.create("name" => "Citibank", :firm_name => "Apple")
- citibank_result = Client.scoped(:conditions => {:name => "Citibank"}, :include => :firm_with_primary_key_symbols).first
+ citibank_result = Client.scoped(:where => {:name => "Citibank"}, :includes => :firm_with_primary_key_symbols).first
assert citibank_result.association_cache.key?(:firm_with_primary_key_symbols)
end
diff --git a/activerecord/test/cases/associations/cascaded_eager_loading_test.rb b/activerecord/test/cases/associations/cascaded_eager_loading_test.rb
index 6ffb8cd2d2..01f7f18397 100644
--- a/activerecord/test/cases/associations/cascaded_eager_loading_test.rb
+++ b/activerecord/test/cases/associations/cascaded_eager_loading_test.rb
@@ -16,7 +16,7 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase
:categorizations, :people, :categories, :edges, :vertices
def test_eager_association_loading_with_cascaded_two_levels
- authors = Author.scoped(:include=>{:posts=>:comments}, :order=>"authors.id").all
+ authors = Author.scoped(:includes=>{:posts=>:comments}, :order=>"authors.id").all
assert_equal 3, authors.size
assert_equal 5, authors[0].posts.size
assert_equal 3, authors[1].posts.size
@@ -24,7 +24,7 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase
end
def test_eager_association_loading_with_cascaded_two_levels_and_one_level
- authors = Author.scoped(:include=>[{:posts=>:comments}, :categorizations], :order=>"authors.id").all
+ authors = Author.scoped(:includes=>[{:posts=>:comments}, :categorizations], :order=>"authors.id").all
assert_equal 3, authors.size
assert_equal 5, authors[0].posts.size
assert_equal 3, authors[1].posts.size
@@ -84,7 +84,7 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase
end
def test_eager_association_loading_with_cascaded_two_levels_with_two_has_many_associations
- authors = Author.scoped(:include=>{:posts=>[:comments, :categorizations]}, :order=>"authors.id").all
+ authors = Author.scoped(:includes=>{:posts=>[:comments, :categorizations]}, :order=>"authors.id").all
assert_equal 3, authors.size
assert_equal 5, authors[0].posts.size
assert_equal 3, authors[1].posts.size
@@ -92,7 +92,7 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase
end
def test_eager_association_loading_with_cascaded_two_levels_and_self_table_reference
- authors = Author.scoped(:include=>{:posts=>[:comments, :author]}, :order=>"authors.id").all
+ authors = Author.scoped(:includes=>{:posts=>[:comments, :author]}, :order=>"authors.id").all
assert_equal 3, authors.size
assert_equal 5, authors[0].posts.size
assert_equal authors(:david).name, authors[0].name
@@ -100,13 +100,13 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase
end
def test_eager_association_loading_with_cascaded_two_levels_with_condition
- authors = Author.scoped(:include=>{:posts=>:comments}, :conditions=>"authors.id=1", :order=>"authors.id").all
+ authors = Author.scoped(:includes=>{:posts=>:comments}, :where=>"authors.id=1", :order=>"authors.id").all
assert_equal 1, authors.size
assert_equal 5, authors[0].posts.size
end
def test_eager_association_loading_with_cascaded_three_levels_by_ping_pong
- firms = Firm.scoped(:include=>{:account=>{:firm=>:account}}, :order=>"companies.id").all
+ firms = Firm.scoped(:includes=>{:account=>{:firm=>:account}}, :order=>"companies.id").all
assert_equal 2, firms.size
assert_equal firms.first.account, firms.first.account.firm.account
assert_equal companies(:first_firm).account, assert_no_queries { firms.first.account.firm.account }
@@ -114,7 +114,7 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase
end
def test_eager_association_loading_with_has_many_sti
- topics = Topic.scoped(:include => :replies, :order => 'topics.id').all
+ topics = Topic.scoped(:includes => :replies, :order => 'topics.id').all
first, second, = topics(:first).replies.size, topics(:second).replies.size
assert_no_queries do
assert_equal first, topics[0].replies.size
@@ -127,7 +127,7 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase
silly.parent_id = 1
assert silly.save
- topics = Topic.scoped(:include => :replies, :order => ['topics.id', 'replies_topics.id']).all
+ topics = Topic.scoped(:includes => :replies, :order => ['topics.id', 'replies_topics.id']).all
assert_no_queries do
assert_equal 2, topics[0].replies.size
assert_equal 0, topics[1].replies.size
@@ -135,14 +135,14 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase
end
def test_eager_association_loading_with_belongs_to_sti
- replies = Reply.scoped(:include => :topic, :order => 'topics.id').all
+ replies = Reply.scoped(:includes => :topic, :order => 'topics.id').all
assert replies.include?(topics(:second))
assert !replies.include?(topics(:first))
assert_equal topics(:first), assert_no_queries { replies.first.topic }
end
def test_eager_association_loading_with_multiple_stis_and_order
- author = Author.scoped(:include => { :posts => [ :special_comments , :very_special_comment ] }, :order => ['authors.name', 'comments.body', 'very_special_comments_posts.body'], :conditions => 'posts.id = 4').first
+ author = Author.scoped(:includes => { :posts => [ :special_comments , :very_special_comment ] }, :order => ['authors.name', 'comments.body', 'very_special_comments_posts.body'], :where => 'posts.id = 4').first
assert_equal authors(:david), author
assert_no_queries do
author.posts.first.special_comments
@@ -151,7 +151,7 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase
end
def test_eager_association_loading_of_stis_with_multiple_references
- authors = Author.scoped(:include => { :posts => { :special_comments => { :post => [ :special_comments, :very_special_comment ] } } }, :order => 'comments.body, very_special_comments_posts.body', :conditions => 'posts.id = 4').all
+ authors = Author.scoped(:includes => { :posts => { :special_comments => { :post => [ :special_comments, :very_special_comment ] } } }, :order => 'comments.body, very_special_comments_posts.body', :where => 'posts.id = 4').all
assert_equal [authors(:david)], authors
assert_no_queries do
authors.first.posts.first.special_comments.first.post.special_comments
@@ -160,7 +160,7 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase
end
def test_eager_association_loading_where_first_level_returns_nil
- authors = Author.scoped(:include => {:post_about_thinking => :comments}, :order => 'authors.id DESC').all
+ authors = Author.scoped(:includes => {:post_about_thinking => :comments}, :order => 'authors.id DESC').all
assert_equal [authors(:bob), authors(:mary), authors(:david)], authors
assert_no_queries do
authors[2].post_about_thinking.comments.first
@@ -168,12 +168,12 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase
end
def test_eager_association_loading_with_recursive_cascading_four_levels_has_many_through
- source = Vertex.scoped(:include=>{:sinks=>{:sinks=>{:sinks=>:sinks}}}, :order => 'vertices.id').first
+ source = Vertex.scoped(:includes=>{:sinks=>{:sinks=>{:sinks=>:sinks}}}, :order => 'vertices.id').first
assert_equal vertices(:vertex_4), assert_no_queries { source.sinks.first.sinks.first.sinks.first }
end
def test_eager_association_loading_with_recursive_cascading_four_levels_has_and_belongs_to_many
- sink = Vertex.scoped(:include=>{:sources=>{:sources=>{:sources=>:sources}}}, :order => 'vertices.id DESC').first
+ sink = Vertex.scoped(:includes=>{:sources=>{:sources=>{:sources=>:sources}}}, :order => 'vertices.id DESC').first
assert_equal vertices(:vertex_1), assert_no_queries { sink.sources.first.sources.first.sources.first.sources.first }
end
end
diff --git a/activerecord/test/cases/associations/eager_load_nested_include_test.rb b/activerecord/test/cases/associations/eager_load_nested_include_test.rb
index b034f0fe56..861a395c58 100644
--- a/activerecord/test/cases/associations/eager_load_nested_include_test.rb
+++ b/activerecord/test/cases/associations/eager_load_nested_include_test.rb
@@ -93,7 +93,7 @@ class EagerLoadPolyAssocsTest < ActiveRecord::TestCase
def test_include_query
res = 0
- res = ShapeExpression.scoped(:include => [ :shape, { :paint => :non_poly } ]).all
+ res = ShapeExpression.scoped(:includes => [ :shape, { :paint => :non_poly } ]).all
assert_equal NUM_SHAPE_EXPRESSIONS, res.size
assert_queries(0) do
res.each do |se|
diff --git a/activerecord/test/cases/associations/eager_singularization_test.rb b/activerecord/test/cases/associations/eager_singularization_test.rb
index 1c635fcd96..5805e71249 100644
--- a/activerecord/test/cases/associations/eager_singularization_test.rb
+++ b/activerecord/test/cases/associations/eager_singularization_test.rb
@@ -103,43 +103,43 @@ class EagerSingularizationTest < ActiveRecord::TestCase
def test_eager_no_extra_singularization_belongs_to
return unless @have_tables
assert_nothing_raised do
- Virus.scoped(:include => :octopus).all
+ Virus.scoped(:includes => :octopus).all
end
end
def test_eager_no_extra_singularization_has_one
return unless @have_tables
assert_nothing_raised do
- Octopus.scoped(:include => :virus).all
+ Octopus.scoped(:includes => :virus).all
end
end
def test_eager_no_extra_singularization_has_many
return unless @have_tables
assert_nothing_raised do
- Bus.scoped(:include => :passes).all
+ Bus.scoped(:includes => :passes).all
end
end
def test_eager_no_extra_singularization_has_and_belongs_to_many
return unless @have_tables
assert_nothing_raised do
- Crisis.scoped(:include => :messes).all
- Mess.scoped(:include => :crises).all
+ Crisis.scoped(:includes => :messes).all
+ Mess.scoped(:includes => :crises).all
end
end
def test_eager_no_extra_singularization_has_many_through_belongs_to
return unless @have_tables
assert_nothing_raised do
- Crisis.scoped(:include => :successes).all
+ Crisis.scoped(:includes => :successes).all
end
end
def test_eager_no_extra_singularization_has_many_through_has_many
return unless @have_tables
assert_nothing_raised do
- Crisis.scoped(:include => :compresses).all
+ Crisis.scoped(:includes => :compresses).all
end
end
end
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index 172182e5bf..781d244bf7 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -40,22 +40,22 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def test_loading_with_one_association
- posts = Post.scoped(:include => :comments).all
+ posts = Post.scoped(:includes => :comments).all
post = posts.find { |p| p.id == 1 }
assert_equal 2, post.comments.size
assert post.comments.include?(comments(:greetings))
- post = Post.scoped(:include => :comments, :conditions => "posts.title = 'Welcome to the weblog'").first
+ post = Post.scoped(:includes => :comments, :where => "posts.title = 'Welcome to the weblog'").first
assert_equal 2, post.comments.size
assert post.comments.include?(comments(:greetings))
- posts = Post.scoped(:include => :last_comment).all
+ posts = Post.scoped(:includes => :last_comment).all
post = posts.find { |p| p.id == 1 }
assert_equal Post.find(1).last_comment, post.last_comment
end
def test_loading_with_one_association_with_non_preload
- posts = Post.scoped(:include => :last_comment, :order => 'comments.id DESC').all
+ posts = Post.scoped(:includes => :last_comment, :order => 'comments.id DESC').all
post = posts.find { |p| p.id == 1 }
assert_equal Post.find(1).last_comment, post.last_comment
end
@@ -70,7 +70,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def test_with_ordering
- list = Post.scoped(:include => :comments, :order => "posts.id DESC").all
+ list = Post.scoped(:includes => :comments, :order => "posts.id DESC").all
[:other_by_mary, :other_by_bob, :misc_by_mary, :misc_by_bob, :eager_other,
:sti_habtm, :sti_post_and_comments, :sti_comments, :authorless, :thinking, :welcome
].each_with_index do |post, index|
@@ -84,14 +84,14 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def test_loading_with_multiple_associations
- posts = Post.scoped(:include => [ :comments, :author, :categories ], :order => "posts.id").all
+ posts = Post.scoped(:includes => [ :comments, :author, :categories ], :order => "posts.id").all
assert_equal 2, posts.first.comments.size
assert_equal 2, posts.first.categories.size
assert posts.first.comments.include?(comments(:greetings))
end
def test_duplicate_middle_objects
- comments = Comment.scoped(:conditions => 'post_id = 1', :include => [:post => :author]).all
+ comments = Comment.scoped(:where => 'post_id = 1', :includes => [:post => :author]).all
assert_no_queries do
comments.each {|comment| comment.post.author.name}
end
@@ -99,25 +99,25 @@ class EagerAssociationTest < ActiveRecord::TestCase
def test_preloading_has_many_in_multiple_queries_with_more_ids_than_database_can_handle
Post.connection.expects(:in_clause_length).at_least_once.returns(5)
- posts = Post.scoped(:include=>:comments).all
+ posts = Post.scoped(:includes=>:comments).all
assert_equal 11, posts.size
end
def test_preloading_has_many_in_one_queries_when_database_has_no_limit_on_ids_it_can_handle
Post.connection.expects(:in_clause_length).at_least_once.returns(nil)
- posts = Post.scoped(:include=>:comments).all
+ posts = Post.scoped(:includes=>:comments).all
assert_equal 11, posts.size
end
def test_preloading_habtm_in_multiple_queries_with_more_ids_than_database_can_handle
Post.connection.expects(:in_clause_length).at_least_once.returns(5)
- posts = Post.scoped(:include=>:categories).all
+ posts = Post.scoped(:includes=>:categories).all
assert_equal 11, posts.size
end
def test_preloading_habtm_in_one_queries_when_database_has_no_limit_on_ids_it_can_handle
Post.connection.expects(:in_clause_length).at_least_once.returns(nil)
- posts = Post.scoped(:include=>:categories).all
+ posts = Post.scoped(:includes=>:categories).all
assert_equal 11, posts.size
end
@@ -234,13 +234,13 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def test_loading_from_an_association
- posts = authors(:david).posts.scoped(:include => :comments, :order => "posts.id").all
+ posts = authors(:david).posts.scoped(:includes => :comments, :order => "posts.id").all
assert_equal 2, posts.first.comments.size
end
def test_loading_from_an_association_that_has_a_hash_of_conditions
assert_nothing_raised do
- Author.scoped(:include => :hello_posts_with_hash_conditions).all
+ Author.scoped(:includes => :hello_posts_with_hash_conditions).all
end
assert !Author.find(authors(:david).id, :include => :hello_posts_with_hash_conditions).hello_posts.empty?
end
@@ -300,12 +300,12 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def test_eager_association_loading_with_belongs_to_and_foreign_keys
- pets = Pet.scoped(:include => :owner).all
+ pets = Pet.scoped(:includes => :owner).all
assert_equal 3, pets.length
end
def test_eager_association_loading_with_belongs_to
- comments = Comment.scoped(:include => :post).all
+ comments = Comment.scoped(:includes => :post).all
assert_equal 11, comments.length
titles = comments.map { |c| c.post.title }
assert titles.include?(posts(:welcome).title)
@@ -313,31 +313,31 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def test_eager_association_loading_with_belongs_to_and_limit
- comments = Comment.scoped(:include => :post, :limit => 5, :order => 'comments.id').all
+ comments = Comment.scoped(:includes => :post, :limit => 5, :order => 'comments.id').all
assert_equal 5, comments.length
assert_equal [1,2,3,5,6], comments.collect { |c| c.id }
end
def test_eager_association_loading_with_belongs_to_and_limit_and_conditions
- comments = Comment.scoped(:include => :post, :conditions => 'post_id = 4', :limit => 3, :order => 'comments.id').all
+ comments = Comment.scoped(:includes => :post, :where => 'post_id = 4', :limit => 3, :order => 'comments.id').all
assert_equal 3, comments.length
assert_equal [5,6,7], comments.collect { |c| c.id }
end
def test_eager_association_loading_with_belongs_to_and_limit_and_offset
- comments = Comment.scoped(:include => :post, :limit => 3, :offset => 2, :order => 'comments.id').all
+ comments = Comment.scoped(:includes => :post, :limit => 3, :offset => 2, :order => 'comments.id').all
assert_equal 3, comments.length
assert_equal [3,5,6], comments.collect { |c| c.id }
end
def test_eager_association_loading_with_belongs_to_and_limit_and_offset_and_conditions
- comments = Comment.scoped(:include => :post, :conditions => 'post_id = 4', :limit => 3, :offset => 1, :order => 'comments.id').all
+ comments = Comment.scoped(:includes => :post, :where => 'post_id = 4', :limit => 3, :offset => 1, :order => 'comments.id').all
assert_equal 3, comments.length
assert_equal [6,7,8], comments.collect { |c| c.id }
end
def test_eager_association_loading_with_belongs_to_and_limit_and_offset_and_conditions_array
- comments = Comment.scoped(:include => :post, :conditions => ['post_id = ?',4], :limit => 3, :offset => 1, :order => 'comments.id').all
+ comments = Comment.scoped(:includes => :post, :where => ['post_id = ?',4], :limit => 3, :offset => 1, :order => 'comments.id').all
assert_equal 3, comments.length
assert_equal [6,7,8], comments.collect { |c| c.id }
end
@@ -345,7 +345,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
def test_eager_association_loading_with_belongs_to_and_conditions_string_with_unquoted_table_name
assert_nothing_raised do
ActiveSupport::Deprecation.silence do
- Comment.scoped(:include => :post, :conditions => ['posts.id = ?',4]).all
+ Comment.scoped(:includes => :post, :where => ['posts.id = ?',4]).all
end
end
end
@@ -353,7 +353,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
def test_eager_association_loading_with_belongs_to_and_conditions_hash
comments = []
assert_nothing_raised do
- comments = Comment.scoped(:include => :post, :conditions => {:posts => {:id => 4}}, :limit => 3, :order => 'comments.id').all
+ comments = Comment.scoped(:includes => :post, :where => {:posts => {:id => 4}}, :limit => 3, :order => 'comments.id').all
end
assert_equal 3, comments.length
assert_equal [5,6,7], comments.collect { |c| c.id }
@@ -366,14 +366,14 @@ class EagerAssociationTest < ActiveRecord::TestCase
quoted_posts_id= Comment.connection.quote_table_name('posts') + '.' + Comment.connection.quote_column_name('id')
assert_nothing_raised do
ActiveSupport::Deprecation.silence do
- Comment.scoped(:include => :post, :conditions => ["#{quoted_posts_id} = ?",4]).all
+ Comment.scoped(:includes => :post, :where => ["#{quoted_posts_id} = ?",4]).all
end
end
end
def test_eager_association_loading_with_belongs_to_and_order_string_with_unquoted_table_name
assert_nothing_raised do
- Comment.scoped(:include => :post, :order => 'posts.id').all
+ Comment.scoped(:includes => :post, :order => 'posts.id').all
end
end
@@ -381,25 +381,25 @@ class EagerAssociationTest < ActiveRecord::TestCase
quoted_posts_id= Comment.connection.quote_table_name('posts') + '.' + Comment.connection.quote_column_name('id')
assert_nothing_raised do
ActiveSupport::Deprecation.silence do
- Comment.scoped(:include => :post, :order => quoted_posts_id).all
+ Comment.scoped(:includes => :post, :order => quoted_posts_id).all
end
end
end
def test_eager_association_loading_with_belongs_to_and_limit_and_multiple_associations
- posts = Post.scoped(:include => [:author, :very_special_comment], :limit => 1, :order => 'posts.id').all
+ posts = Post.scoped(:includes => [:author, :very_special_comment], :limit => 1, :order => 'posts.id').all
assert_equal 1, posts.length
assert_equal [1], posts.collect { |p| p.id }
end
def test_eager_association_loading_with_belongs_to_and_limit_and_offset_and_multiple_associations
- posts = Post.scoped(:include => [:author, :very_special_comment], :limit => 1, :offset => 1, :order => 'posts.id').all
+ posts = Post.scoped(:includes => [:author, :very_special_comment], :limit => 1, :offset => 1, :order => 'posts.id').all
assert_equal 1, posts.length
assert_equal [2], posts.collect { |p| p.id }
end
def test_eager_association_loading_with_belongs_to_inferred_foreign_key_from_association_name
- author_favorite = AuthorFavorite.scoped(:include => :favorite_author).first
+ author_favorite = AuthorFavorite.scoped(:includes => :favorite_author).first
assert_equal authors(:mary), assert_no_queries { author_favorite.favorite_author }
end
@@ -458,14 +458,14 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def test_eager_association_loading_with_explicit_join
- posts = Post.scoped(:include => :comments, :joins => "INNER JOIN authors ON posts.author_id = authors.id AND authors.name = 'Mary'", :limit => 1, :order => 'author_id').all
+ posts = Post.scoped(:includes => :comments, :joins => "INNER JOIN authors ON posts.author_id = authors.id AND authors.name = 'Mary'", :limit => 1, :order => 'author_id').all
assert_equal 1, posts.length
end
def test_eager_with_has_many_through
- posts_with_comments = people(:michael).posts.scoped(:include => :comments, :order => 'posts.id').all
- posts_with_author = people(:michael).posts.scoped(:include => :author, :order => 'posts.id').all
- posts_with_comments_and_author = people(:michael).posts.scoped(:include => [ :comments, :author ], :order => 'posts.id').all
+ posts_with_comments = people(:michael).posts.scoped(:includes => :comments, :order => 'posts.id').all
+ posts_with_author = people(:michael).posts.scoped(:includes => :author, :order => 'posts.id').all
+ posts_with_comments_and_author = people(:michael).posts.scoped(:includes => [ :comments, :author ], :order => 'posts.id').all
assert_equal 2, posts_with_comments.inject(0) { |sum, post| sum += post.comments.size }
assert_equal authors(:david), assert_no_queries { posts_with_author.first.author }
assert_equal authors(:david), assert_no_queries { posts_with_comments_and_author.first.author }
@@ -476,17 +476,17 @@ class EagerAssociationTest < ActiveRecord::TestCase
Post.create!(:author => author, :title => "TITLE", :body => "BODY")
author.author_favorites.create(:favorite_author_id => 1)
author.author_favorites.create(:favorite_author_id => 2)
- posts_with_author_favorites = author.posts.scoped(:include => :author_favorites).all
+ posts_with_author_favorites = author.posts.scoped(:includes => :author_favorites).all
assert_no_queries { posts_with_author_favorites.first.author_favorites.first.author_id }
end
def test_eager_with_has_many_through_an_sti_join_model
- author = Author.scoped(:include => :special_post_comments, :order => 'authors.id').first
+ author = Author.scoped(:includes => :special_post_comments, :order => 'authors.id').first
assert_equal [comments(:does_it_hurt)], assert_no_queries { author.special_post_comments }
end
def test_eager_with_has_many_through_an_sti_join_model_with_conditions_on_both
- author = Author.scoped(:include => :special_nonexistant_post_comments, :order => 'authors.id').first
+ author = Author.scoped(:includes => :special_nonexistant_post_comments, :order => 'authors.id').first
assert_equal [], author.special_nonexistant_post_comments
end
@@ -520,16 +520,16 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def test_eager_with_has_many_and_limit
- posts = Post.scoped(:order => 'posts.id asc', :include => [ :author, :comments ], :limit => 2).all
+ posts = Post.scoped(:order => 'posts.id asc', :includes => [ :author, :comments ], :limit => 2).all
assert_equal 2, posts.size
assert_equal 3, posts.inject(0) { |sum, post| sum += post.comments.size }
end
def test_eager_with_has_many_and_limit_and_conditions
if current_adapter?(:OpenBaseAdapter)
- posts = Post.scoped(:include => [ :author, :comments ], :limit => 2, :conditions => "FETCHBLOB(posts.body) = 'hello'", :order => "posts.id").all
+ posts = Post.scoped(:includes => [ :author, :comments ], :limit => 2, :where => "FETCHBLOB(posts.body) = 'hello'", :order => "posts.id").all
else
- posts = Post.scoped(:include => [ :author, :comments ], :limit => 2, :conditions => "posts.body = 'hello'", :order => "posts.id").all
+ posts = Post.scoped(:includes => [ :author, :comments ], :limit => 2, :where => "posts.body = 'hello'", :order => "posts.id").all
end
assert_equal 2, posts.size
assert_equal [4,5], posts.collect { |p| p.id }
@@ -537,9 +537,9 @@ class EagerAssociationTest < ActiveRecord::TestCase
def test_eager_with_has_many_and_limit_and_conditions_array
if current_adapter?(:OpenBaseAdapter)
- posts = Post.scoped(:include => [ :author, :comments ], :limit => 2, :conditions => [ "FETCHBLOB(posts.body) = ?", 'hello' ], :order => "posts.id").all
+ posts = Post.scoped(:includes => [ :author, :comments ], :limit => 2, :where => [ "FETCHBLOB(posts.body) = ?", 'hello' ], :order => "posts.id").all
else
- posts = Post.scoped(:include => [ :author, :comments ], :limit => 2, :conditions => [ "posts.body = ?", 'hello' ], :order => "posts.id").all
+ posts = Post.scoped(:includes => [ :author, :comments ], :limit => 2, :where => [ "posts.body = ?", 'hello' ], :order => "posts.id").all
end
assert_equal 2, posts.size
assert_equal [4,5], posts.collect { |p| p.id }
@@ -547,7 +547,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
def test_eager_with_has_many_and_limit_and_conditions_array_on_the_eagers
posts = ActiveSupport::Deprecation.silence do
- Post.scoped(:include => [ :author, :comments ], :limit => 2, :conditions => [ "authors.name = ?", 'David' ]).all
+ Post.scoped(:includes => [ :author, :comments ], :limit => 2, :where => [ "authors.name = ?", 'David' ]).all
end
assert_equal 2, posts.size
@@ -558,7 +558,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def test_eager_with_has_many_and_limit_and_high_offset
- posts = Post.scoped(:include => [ :author, :comments ], :limit => 2, :offset => 10, :conditions => { 'authors.name' => 'David' }).all
+ posts = Post.scoped(:includes => [ :author, :comments ], :limit => 2, :offset => 10, :where => { 'authors.name' => 'David' }).all
assert_equal 0, posts.size
end
@@ -602,7 +602,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def test_eager_with_has_and_belongs_to_many_and_limit
- posts = Post.scoped(:include => :categories, :order => "posts.id", :limit => 3).all
+ posts = Post.scoped(:includes => :categories, :order => "posts.id", :limit => 3).all
assert_equal 3, posts.size
assert_equal 2, posts[0].categories.size
assert_equal 1, posts[1].categories.size
@@ -668,7 +668,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def test_eager_association_loading_with_habtm
- posts = Post.scoped(:include => :categories, :order => "posts.id").all
+ posts = Post.scoped(:includes => :categories, :order => "posts.id").all
assert_equal 2, posts[0].categories.size
assert_equal 1, posts[1].categories.size
assert_equal 0, posts[2].categories.size
@@ -677,7 +677,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def test_eager_with_inheritance
- SpecialPost.scoped(:include => [ :comments ]).all
+ SpecialPost.scoped(:includes => [ :comments ]).all
end
def test_eager_has_one_with_association_inheritance
@@ -771,7 +771,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def find_all_ordered(className, include=nil)
- className.scoped(:order=>"#{className.table_name}.#{className.primary_key}", :include=>include).all
+ className.scoped(:order=>"#{className.table_name}.#{className.primary_key}", :includes=>include).all
end
def test_limited_eager_with_order
@@ -881,13 +881,13 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
end
def test_eager_with_valid_association_as_string_not_symbol
- assert_nothing_raised { Post.scoped(:include => 'comments').all }
+ assert_nothing_raised { Post.scoped(:includes => 'comments').all }
end
def test_eager_with_floating_point_numbers
assert_queries(2) do
# Before changes, the floating point numbers will be interpreted as table names and will cause this to run in one query
- Comment.scoped(:conditions => "123.456 = 123.456", :include => :post).all
+ Comment.scoped(:where => "123.456 = 123.456", :includes => :post).all
end
end
@@ -946,16 +946,16 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def test_conditions_on_join_table_with_include_and_limit
- assert_equal 3, Developer.scoped(:include => 'projects', :conditions => { 'developers_projects.access_level' => 1 }, :limit => 5).all.size
+ assert_equal 3, Developer.scoped(:includes => 'projects', :where => { 'developers_projects.access_level' => 1 }, :limit => 5).all.size
end
def test_order_on_join_table_with_include_and_limit
- assert_equal 5, Developer.scoped(:include => 'projects', :order => 'developers_projects.joined_on DESC', :limit => 5).all.size
+ assert_equal 5, Developer.scoped(:includes => 'projects', :order => 'developers_projects.joined_on DESC', :limit => 5).all.size
end
def test_eager_loading_with_order_on_joined_table_preloads
posts = assert_queries(2) do
- Post.scoped(:joins => :comments, :include => :author, :order => 'comments.id DESC').all
+ Post.scoped(:joins => :comments, :includes => :author, :order => 'comments.id DESC').all
end
assert_equal posts(:eager_other), posts[1]
assert_equal authors(:mary), assert_no_queries { posts[1].author}
@@ -963,24 +963,24 @@ class EagerAssociationTest < ActiveRecord::TestCase
def test_eager_loading_with_conditions_on_joined_table_preloads
posts = assert_queries(2) do
- Post.scoped(:select => 'distinct posts.*', :include => :author, :joins => [:comments], :conditions => "comments.body like 'Thank you%'", :order => 'posts.id').all
+ Post.scoped(:select => 'distinct posts.*', :includes => :author, :joins => [:comments], :where => "comments.body like 'Thank you%'", :order => 'posts.id').all
end
assert_equal [posts(:welcome)], posts
assert_equal authors(:david), assert_no_queries { posts[0].author}
posts = assert_queries(2) do
- Post.scoped(:select => 'distinct posts.*', :include => :author, :joins => [:comments], :conditions => "comments.body like 'Thank you%'", :order => 'posts.id').all
+ Post.scoped(:select => 'distinct posts.*', :includes => :author, :joins => [:comments], :where => "comments.body like 'Thank you%'", :order => 'posts.id').all
end
assert_equal [posts(:welcome)], posts
assert_equal authors(:david), assert_no_queries { posts[0].author}
posts = assert_queries(2) do
- Post.scoped(:include => :author, :joins => {:taggings => :tag}, :conditions => "tags.name = 'General'", :order => 'posts.id').all
+ Post.scoped(:includes => :author, :joins => {:taggings => :tag}, :where => "tags.name = 'General'", :order => 'posts.id').all
end
assert_equal posts(:welcome, :thinking), posts
posts = assert_queries(2) do
- Post.scoped(:include => :author, :joins => {:taggings => {:tag => :taggings}}, :conditions => "taggings_tags.super_tag_id=2", :order => 'posts.id').all
+ Post.scoped(:includes => :author, :joins => {:taggings => {:tag => :taggings}}, :where => "taggings_tags.super_tag_id=2", :order => 'posts.id').all
end
assert_equal posts(:welcome, :thinking), posts
@@ -988,13 +988,13 @@ class EagerAssociationTest < ActiveRecord::TestCase
def test_eager_loading_with_conditions_on_string_joined_table_preloads
posts = assert_queries(2) do
- Post.scoped(:select => 'distinct posts.*', :include => :author, :joins => "INNER JOIN comments on comments.post_id = posts.id", :conditions => "comments.body like 'Thank you%'", :order => 'posts.id').all
+ Post.scoped(:select => 'distinct posts.*', :includes => :author, :joins => "INNER JOIN comments on comments.post_id = posts.id", :where => "comments.body like 'Thank you%'", :order => 'posts.id').all
end
assert_equal [posts(:welcome)], posts
assert_equal authors(:david), assert_no_queries { posts[0].author}
posts = assert_queries(2) do
- Post.scoped(:select => 'distinct posts.*', :include => :author, :joins => ["INNER JOIN comments on comments.post_id = posts.id"], :conditions => "comments.body like 'Thank you%'", :order => 'posts.id').all
+ Post.scoped(:select => 'distinct posts.*', :includes => :author, :joins => ["INNER JOIN comments on comments.post_id = posts.id"], :where => "comments.body like 'Thank you%'", :order => 'posts.id').all
end
assert_equal [posts(:welcome)], posts
assert_equal authors(:david), assert_no_queries { posts[0].author}
@@ -1003,7 +1003,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
def test_eager_loading_with_select_on_joined_table_preloads
posts = assert_queries(2) do
- Post.scoped(:select => 'posts.*, authors.name as author_name', :include => :comments, :joins => :author, :order => 'posts.id').all
+ Post.scoped(:select => 'posts.*, authors.name as author_name', :includes => :comments, :joins => :author, :order => 'posts.id').all
end
assert_equal 'David', posts[0].author_name
assert_equal posts(:welcome).comments, assert_no_queries { posts[0].comments}
@@ -1013,14 +1013,14 @@ class EagerAssociationTest < ActiveRecord::TestCase
Author.columns
authors = assert_queries(2) do
- Author.scoped(:include => :author_address, :joins => :comments, :conditions => "posts.title like 'Welcome%'").all
+ Author.scoped(:includes => :author_address, :joins => :comments, :where => "posts.title like 'Welcome%'").all
end
assert_equal authors(:david), authors[0]
assert_equal author_addresses(:david_address), authors[0].author_address
end
def test_preload_belongs_to_uses_exclusive_scope
- people = Person.males.scoped(:include => :primary_contact).all
+ people = Person.males.scoped(:includes => :primary_contact).all
assert_not_equal people.length, 0
people.each do |person|
assert_no_queries {assert_not_nil person.primary_contact}
@@ -1058,7 +1058,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
def test_preload_has_one_using_primary_key
expected = accounts(:signals37)
- firm = Firm.scoped(:include => :account_using_primary_key, :order => 'companies.id').first
+ firm = Firm.scoped(:includes => :account_using_primary_key, :order => 'companies.id').first
assert_no_queries do
assert_equal expected, firm.account_using_primary_key
end
@@ -1066,7 +1066,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
def test_include_has_one_using_primary_key
expected = accounts(:signals37)
- firm = Firm.scoped(:include => :account_using_primary_key, :order => 'accounts.id').all.detect {|f| f.id == 1}
+ firm = Firm.scoped(:includes => :account_using_primary_key, :order => 'accounts.id').all.detect {|f| f.id == 1}
assert_no_queries do
assert_equal expected, firm.account_using_primary_key
end
@@ -1130,7 +1130,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def test_deep_including_through_habtm
- posts = Post.scoped(:include => {:categories => :categorizations}, :order => "posts.id").all
+ posts = Post.scoped(:includes => {:categories => :categorizations}, :order => "posts.id").all
assert_no_queries { assert_equal 2, posts[0].categories[0].categorizations.length }
assert_no_queries { assert_equal 1, posts[0].categories[1].categorizations.length }
assert_no_queries { assert_equal 2, posts[1].categories[0].categorizations.length }
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 15f10285d1..7ddaf78848 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
@@ -549,14 +549,14 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
def test_find_with_merged_options
assert_equal 1, projects(:active_record).limited_developers.size
assert_equal 1, projects(:active_record).limited_developers.all.size
- assert_equal 3, projects(:active_record).limited_developers.scoped(:limit => nil).all.size
+ assert_equal 3, projects(:active_record).limited_developers.limit(nil).all.size
end
def test_dynamic_find_should_respect_association_order
# Developers are ordered 'name DESC, id DESC'
high_id_jamis = projects(:active_record).developers.create(:name => 'Jamis')
- assert_equal high_id_jamis, projects(:active_record).developers.scoped(:conditions => "name = 'Jamis'").first
+ assert_equal high_id_jamis, projects(:active_record).developers.scoped(:where => "name = 'Jamis'").first
assert_equal high_id_jamis, projects(:active_record).developers.find_by_name('Jamis')
end
@@ -566,7 +566,7 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
middle_id_jamis = developers(:poor_jamis)
high_id_jamis = projects(:active_record).developers.create(:name => 'Jamis')
- assert_equal [high_id_jamis, middle_id_jamis, low_id_jamis], projects(:active_record).developers.scoped(:conditions => "name = 'Jamis'").all
+ assert_equal [high_id_jamis, middle_id_jamis, low_id_jamis], projects(:active_record).developers.scoped(:where => "name = 'Jamis'").all
assert_equal [high_id_jamis, middle_id_jamis, low_id_jamis], projects(:active_record).developers.find_all_by_name('Jamis')
end
@@ -576,12 +576,12 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
end
def test_dynamic_find_all_should_respect_association_limit
- assert_equal 1, projects(:active_record).limited_developers.scoped(:conditions => "name = 'Jamis'").all.length
+ assert_equal 1, projects(:active_record).limited_developers.scoped(:where => "name = 'Jamis'").all.length
assert_equal 1, projects(:active_record).limited_developers.find_all_by_name('Jamis').length
end
def test_dynamic_find_all_order_should_override_association_limit
- assert_equal 2, projects(:active_record).limited_developers.scoped(:conditions => "name = 'Jamis'", :limit => 9_000).all.length
+ assert_equal 2, projects(:active_record).limited_developers.scoped(:where => "name = 'Jamis'", :limit => 9_000).all.length
assert_equal 2, projects(:active_record).limited_developers.find_all_by_name('Jamis', :limit => 9_000).length
end
@@ -705,8 +705,8 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
end
def test_find_grouped
- all_posts_from_category1 = Post.scoped(:conditions => "category_id = 1", :joins => :categories).all
- grouped_posts_of_category1 = Post.scoped(:conditions => "category_id = 1", :group => "author_id", :select => 'count(posts.id) as posts_count', :joins => :categories).all
+ all_posts_from_category1 = Post.scoped(:where => "category_id = 1", :joins => :categories).all
+ grouped_posts_of_category1 = Post.scoped(:where => "category_id = 1", :group => "author_id", :select => 'count(posts.id) as posts_count', :joins => :categories).all
assert_equal 5, all_posts_from_category1.size
assert_equal 2, grouped_posts_of_category1.size
end
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 4b22746430..fb8f45f0ce 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -273,14 +273,14 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
def test_find_with_blank_conditions
[[], {}, nil, ""].each do |blank|
- assert_equal 2, Firm.scoped(:order => "id").first.clients.scoped(:conditions => blank).all.size
+ assert_equal 2, Firm.scoped(:order => "id").first.clients.where(blank).all.size
end
end
def test_find_many_with_merged_options
assert_equal 1, companies(:first_firm).limited_clients.size
assert_equal 1, companies(:first_firm).limited_clients.all.size
- assert_equal 2, companies(:first_firm).limited_clients.scoped(:limit => nil).all.size
+ assert_equal 2, companies(:first_firm).limited_clients.limit(nil).all.size
end
def test_find_should_append_to_association_order
@@ -293,22 +293,22 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
end
def test_dynamic_find_should_respect_association_order
- assert_equal companies(:second_client), companies(:first_firm).clients_sorted_desc.scoped(:conditions => "type = 'Client'").first
+ assert_equal companies(:second_client), companies(:first_firm).clients_sorted_desc.scoped(:where => "type = 'Client'").first
assert_equal companies(:second_client), companies(:first_firm).clients_sorted_desc.find_by_type('Client')
end
def test_dynamic_find_all_should_respect_association_order
- assert_equal [companies(:second_client), companies(:first_client)], companies(:first_firm).clients_sorted_desc.scoped(:conditions => "type = 'Client'").all
+ assert_equal [companies(:second_client), companies(:first_client)], companies(:first_firm).clients_sorted_desc.scoped(:where => "type = 'Client'").all
assert_equal [companies(:second_client), companies(:first_client)], companies(:first_firm).clients_sorted_desc.find_all_by_type('Client')
end
def test_dynamic_find_all_should_respect_association_limit
- assert_equal 1, companies(:first_firm).limited_clients.scoped(:conditions => "type = 'Client'").all.length
+ assert_equal 1, companies(:first_firm).limited_clients.scoped(:where => "type = 'Client'").all.length
assert_equal 1, companies(:first_firm).limited_clients.find_all_by_type('Client').length
end
def test_dynamic_find_all_limit_should_override_association_limit
- assert_equal 2, companies(:first_firm).limited_clients.scoped(:conditions => "type = 'Client'", :limit => 9_000).all.length
+ assert_equal 2, companies(:first_firm).limited_clients.scoped(:where => "type = 'Client'", :limit => 9_000).all.length
assert_equal 2, companies(:first_firm).limited_clients.find_all_by_type('Client', :limit => 9_000).length
end
@@ -432,8 +432,8 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
def test_find_all
firm = Firm.scoped(:order => "id").first
- assert_equal 2, firm.clients.scoped(:conditions => "#{QUOTED_TYPE} = 'Client'").all.length
- assert_equal 1, firm.clients.scoped(:conditions => "name = 'Summit'").all.length
+ assert_equal 2, firm.clients.scoped(:where => "#{QUOTED_TYPE} = 'Client'").all.length
+ assert_equal 1, firm.clients.scoped(:where => "name = 'Summit'").all.length
end
def test_find_each
@@ -478,28 +478,28 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
def test_find_all_sanitized
# sometimes tests on Oracle fail if ORDER BY is not provided therefore add always :order with :first
firm = Firm.scoped(:order => "id").first
- summit = firm.clients.scoped(:conditions => "name = 'Summit'").all
- assert_equal summit, firm.clients.scoped(:conditions => ["name = ?", "Summit"]).all
- assert_equal summit, firm.clients.scoped(:conditions => ["name = :name", { :name => "Summit" }]).all
+ summit = firm.clients.scoped(:where => "name = 'Summit'").all
+ assert_equal summit, firm.clients.scoped(:where => ["name = ?", "Summit"]).all
+ assert_equal summit, firm.clients.scoped(:where => ["name = :name", { :name => "Summit" }]).all
end
def test_find_first
firm = Firm.scoped(:order => "id").first
client2 = Client.find(2)
assert_equal firm.clients.first, firm.clients.scoped(:order => "id").first
- assert_equal client2, firm.clients.scoped(:conditions => "#{QUOTED_TYPE} = 'Client'", :order => "id").first
+ assert_equal client2, firm.clients.scoped(:where => "#{QUOTED_TYPE} = 'Client'", :order => "id").first
end
def test_find_first_sanitized
firm = Firm.scoped(:order => "id").first
client2 = Client.find(2)
- assert_equal client2, firm.clients.scoped(:conditions => ["#{QUOTED_TYPE} = ?", 'Client'], :order => "id").first
- assert_equal client2, firm.clients.scoped(:conditions => ["#{QUOTED_TYPE} = :type", { :type => 'Client' }], :order => "id").first
+ assert_equal client2, firm.clients.scoped(:where => ["#{QUOTED_TYPE} = ?", 'Client'], :order => "id").first
+ assert_equal client2, firm.clients.scoped(:where => ["#{QUOTED_TYPE} = :type", { :type => 'Client' }], :order => "id").first
end
def test_find_all_with_include_and_conditions
assert_nothing_raised do
- Developer.scoped(:joins => :audit_logs, :conditions => {'audit_logs.message' => nil, :name => 'Smith'}).all
+ Developer.scoped(:joins => :audit_logs, :where => {'audit_logs.message' => nil, :name => 'Smith'}).all
end
end
@@ -509,8 +509,8 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
end
def test_find_grouped
- all_clients_of_firm1 = Client.scoped(:conditions => "firm_id = 1").all
- grouped_clients_of_firm1 = Client.scoped(:conditions => "firm_id = 1", :group => "firm_id", :select => 'firm_id, count(id) as clients_count').all
+ all_clients_of_firm1 = Client.scoped(:where => "firm_id = 1").all
+ grouped_clients_of_firm1 = Client.scoped(:where => "firm_id = 1", :group => "firm_id", :select => 'firm_id, count(id) as clients_count').all
assert_equal 2, all_clients_of_firm1.size
assert_equal 1, grouped_clients_of_firm1.size
end
@@ -1110,7 +1110,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
firm = companies(:first_firm)
assert_equal 2, firm.clients.size
firm.destroy
- assert Client.scoped(:conditions => "firm_id=#{firm.id}").all.empty?
+ assert Client.scoped(:where => "firm_id=#{firm.id}").all.empty?
end
def test_dependence_for_associations_with_hash_condition
@@ -1148,7 +1148,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
firm.destroy rescue "do nothing"
- assert_equal 2, Client.scoped(:conditions => "firm_id=#{firm.id}").all.size
+ assert_equal 2, Client.scoped(:where => "firm_id=#{firm.id}").all.size
end
def test_dependence_on_account
@@ -1329,27 +1329,27 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
end
def test_dynamic_find_should_respect_association_order_for_through
- assert_equal Comment.find(10), authors(:david).comments_desc.scoped(:conditions => "comments.type = 'SpecialComment'").first
+ assert_equal Comment.find(10), authors(:david).comments_desc.scoped(:where => "comments.type = 'SpecialComment'").first
assert_equal Comment.find(10), authors(:david).comments_desc.find_by_type('SpecialComment')
end
def test_dynamic_find_all_should_respect_association_order_for_through
- assert_equal [Comment.find(10), Comment.find(7), Comment.find(6), Comment.find(3)], authors(:david).comments_desc.scoped(:conditions => "comments.type = 'SpecialComment'").all
+ assert_equal [Comment.find(10), Comment.find(7), Comment.find(6), Comment.find(3)], authors(:david).comments_desc.scoped(:where => "comments.type = 'SpecialComment'").all
assert_equal [Comment.find(10), Comment.find(7), Comment.find(6), Comment.find(3)], authors(:david).comments_desc.find_all_by_type('SpecialComment')
end
def test_dynamic_find_all_should_respect_association_limit_for_through
- assert_equal 1, authors(:david).limited_comments.scoped(:conditions => "comments.type = 'SpecialComment'").all.length
+ assert_equal 1, authors(:david).limited_comments.scoped(:where => "comments.type = 'SpecialComment'").all.length
assert_equal 1, authors(:david).limited_comments.find_all_by_type('SpecialComment').length
end
def test_dynamic_find_all_order_should_override_association_limit_for_through
- assert_equal 4, authors(:david).limited_comments.scoped(:conditions => "comments.type = 'SpecialComment'", :limit => 9_000).all.length
+ assert_equal 4, authors(:david).limited_comments.scoped(:where => "comments.type = 'SpecialComment'", :limit => 9_000).all.length
assert_equal 4, authors(:david).limited_comments.find_all_by_type('SpecialComment', :limit => 9_000).length
end
def test_find_all_include_over_the_same_table_for_through
- assert_equal 2, people(:michael).posts.scoped(:include => :people).all.length
+ assert_equal 2, people(:michael).posts.scoped(:includes => :people).all.length
end
def test_has_many_through_respects_hash_conditions
diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb
index 9a5719c298..57d2f3ee06 100644
--- a/activerecord/test/cases/associations/has_one_associations_test.rb
+++ b/activerecord/test/cases/associations/has_one_associations_test.rb
@@ -25,7 +25,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
assert_queries(1) { assert_nil firm.account }
assert_queries(0) { assert_nil firm.account }
- firms = Firm.scoped(:include => :account).all
+ firms = Firm.scoped(:includes => :account).all
assert_queries(0) { firms.each(&:account) }
end
diff --git a/activerecord/test/cases/associations/has_one_through_associations_test.rb b/activerecord/test/cases/associations/has_one_through_associations_test.rb
index fd95178d54..00c7a78e82 100644
--- a/activerecord/test/cases/associations/has_one_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_one_through_associations_test.rb
@@ -73,7 +73,7 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase
def test_has_one_through_eager_loading
members = assert_queries(3) do #base table, through table, clubs table
- Member.scoped(:include => :club, :conditions => ["name = ?", "Groucho Marx"]).all
+ Member.scoped(:includes => :club, :where => ["name = ?", "Groucho Marx"]).all
end
assert_equal 1, members.size
assert_not_nil assert_no_queries {members[0].club}
@@ -81,7 +81,7 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase
def test_has_one_through_eager_loading_through_polymorphic
members = assert_queries(3) do #base table, through table, clubs table
- Member.scoped(:include => :sponsor_club, :conditions => ["name = ?", "Groucho Marx"]).all
+ Member.scoped(:includes => :sponsor_club, :where => ["name = ?", "Groucho Marx"]).all
end
assert_equal 1, members.size
assert_not_nil assert_no_queries {members[0].sponsor_club}
@@ -104,14 +104,14 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase
end
def test_eager_has_one_through_polymorphic_with_source_type
- clubs = Club.scoped(:include => :sponsored_member, :conditions => ["name = ?","Moustache and Eyebrow Fancier Club"]).all
+ clubs = Club.scoped(:includes => :sponsored_member, :where => ["name = ?","Moustache and Eyebrow Fancier Club"]).all
# Only the eyebrow fanciers club has a sponsored_member
assert_not_nil assert_no_queries {clubs[0].sponsored_member}
end
def test_has_one_through_nonpreload_eagerloading
members = assert_queries(1) do
- Member.scoped(:include => :club, :conditions => ["members.name = ?", "Groucho Marx"], :order => 'clubs.name').all #force fallback
+ Member.scoped(:includes => :club, :where => ["members.name = ?", "Groucho Marx"], :order => 'clubs.name').all #force fallback
end
assert_equal 1, members.size
assert_not_nil assert_no_queries {members[0].club}
@@ -119,7 +119,7 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase
def test_has_one_through_nonpreload_eager_loading_through_polymorphic
members = assert_queries(1) do
- Member.scoped(:include => :sponsor_club, :conditions => ["members.name = ?", "Groucho Marx"], :order => 'clubs.name').all #force fallback
+ Member.scoped(:includes => :sponsor_club, :where => ["members.name = ?", "Groucho Marx"], :order => 'clubs.name').all #force fallback
end
assert_equal 1, members.size
assert_not_nil assert_no_queries {members[0].sponsor_club}
@@ -128,7 +128,7 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase
def test_has_one_through_nonpreload_eager_loading_through_polymorphic_with_more_than_one_through_record
Sponsor.new(:sponsor_club => clubs(:crazy_club), :sponsorable => members(:groucho)).save!
members = assert_queries(1) do
- Member.scoped(:include => :sponsor_club, :conditions => ["members.name = ?", "Groucho Marx"], :order => 'clubs.name DESC').all #force fallback
+ Member.scoped(:includes => :sponsor_club, :where => ["members.name = ?", "Groucho Marx"], :order => 'clubs.name DESC').all #force fallback
end
assert_equal 1, members.size
assert_not_nil assert_no_queries { members[0].sponsor_club }
@@ -197,7 +197,7 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase
@member.member_detail = @member_detail
@member.organization = @organization
@member_details = assert_queries(3) do
- MemberDetail.scoped(:include => :member_type).all
+ MemberDetail.scoped(:includes => :member_type).all
end
@new_detail = @member_details[0]
assert @new_detail.send(:association, :member_type).loaded?
diff --git a/activerecord/test/cases/associations/inverse_associations_test.rb b/activerecord/test/cases/associations/inverse_associations_test.rb
index 563f38d023..f35ffb2994 100644
--- a/activerecord/test/cases/associations/inverse_associations_test.rb
+++ b/activerecord/test/cases/associations/inverse_associations_test.rb
@@ -96,7 +96,7 @@ class InverseHasOneTests < ActiveRecord::TestCase
def test_parent_instance_should_be_shared_with_eager_loaded_child_on_find
- m = Man.scoped(:conditions => {:name => 'Gordon'}, :include => :face).first
+ m = Man.scoped(:where => {:name => 'Gordon'}, :includes => :face).first
f = m.face
assert_equal m.name, f.man.name, "Name of man should be the same before changes to parent instance"
m.name = 'Bongo'
@@ -104,7 +104,7 @@ class InverseHasOneTests < ActiveRecord::TestCase
f.man.name = 'Mungo'
assert_equal m.name, f.man.name, "Name of man should be the same after changes to child-owned instance"
- m = Man.scoped(:conditions => {:name => 'Gordon'}, :include => :face, :order => 'faces.id').first
+ m = Man.scoped(:where => {:name => 'Gordon'}, :includes => :face, :order => 'faces.id').first
f = m.face
assert_equal m.name, f.man.name, "Name of man should be the same before changes to parent instance"
m.name = 'Bongo'
@@ -179,7 +179,7 @@ class InverseHasManyTests < ActiveRecord::TestCase
end
def test_parent_instance_should_be_shared_with_eager_loaded_children
- m = Man.scoped(:conditions => {:name => 'Gordon'}, :include => :interests).first
+ m = Man.scoped(:where => {:name => 'Gordon'}, :includes => :interests).first
is = m.interests
is.each do |i|
assert_equal m.name, i.man.name, "Name of man should be the same before changes to parent instance"
@@ -189,7 +189,7 @@ class InverseHasManyTests < ActiveRecord::TestCase
assert_equal m.name, i.man.name, "Name of man should be the same after changes to child-owned instance"
end
- m = Man.scoped(:conditions => {:name => 'Gordon'}, :include => :interests, :order => 'interests.id').first
+ m = Man.scoped(:where => {:name => 'Gordon'}, :includes => :interests, :order => 'interests.id').first
is = m.interests
is.each do |i|
assert_equal m.name, i.man.name, "Name of man should be the same before changes to parent instance"
@@ -278,7 +278,7 @@ class InverseBelongsToTests < ActiveRecord::TestCase
end
def test_eager_loaded_child_instance_should_be_shared_with_parent_on_find
- f = Face.scoped(:include => :man, :conditions => {:description => 'trusting'}).first
+ f = Face.scoped(:includes => :man, :where => {:description => 'trusting'}).first
m = f.man
assert_equal f.description, m.face.description, "Description of face should be the same before changes to child instance"
f.description = 'gormless'
@@ -286,7 +286,7 @@ class InverseBelongsToTests < ActiveRecord::TestCase
m.face.description = 'pleasing'
assert_equal f.description, m.face.description, "Description of face should be the same after changes to parent-owned instance"
- f = Face.scoped(:include => :man, :order => 'men.id', :conditions => {:description => 'trusting'}).first
+ f = Face.scoped(:includes => :man, :order => 'men.id', :where => {:description => 'trusting'}).first
m = f.man
assert_equal f.description, m.face.description, "Description of face should be the same before changes to child instance"
f.description = 'gormless'
@@ -351,7 +351,7 @@ class InversePolymorphicBelongsToTests < ActiveRecord::TestCase
fixtures :men, :faces, :interests
def test_child_instance_should_be_shared_with_parent_on_find
- f = Face.scoped(:conditions => {:description => 'confused'}).first
+ f = Face.scoped(:where => {:description => 'confused'}).first
m = f.polymorphic_man
assert_equal f.description, m.polymorphic_face.description, "Description of face should be the same before changes to child instance"
f.description = 'gormless'
@@ -361,7 +361,7 @@ class InversePolymorphicBelongsToTests < ActiveRecord::TestCase
end
def test_eager_loaded_child_instance_should_be_shared_with_parent_on_find
- f = Face.scoped(:conditions => {:description => 'confused'}, :include => :man).first
+ f = Face.scoped(:where => {:description => 'confused'}, :includes => :man).first
m = f.polymorphic_man
assert_equal f.description, m.polymorphic_face.description, "Description of face should be the same before changes to child instance"
f.description = 'gormless'
@@ -369,7 +369,7 @@ class InversePolymorphicBelongsToTests < ActiveRecord::TestCase
m.polymorphic_face.description = 'pleasing'
assert_equal f.description, m.polymorphic_face.description, "Description of face should be the same after changes to parent-owned instance"
- f = Face.scoped(:conditions => {:description => 'confused'}, :include => :man, :order => 'men.id').first
+ f = Face.scoped(:where => {:description => 'confused'}, :includes => :man, :order => 'men.id').first
m = f.polymorphic_man
assert_equal f.description, m.polymorphic_face.description, "Description of face should be the same before changes to child instance"
f.description = 'gormless'
diff --git a/activerecord/test/cases/associations/join_model_test.rb b/activerecord/test/cases/associations/join_model_test.rb
index 63b7acfc7a..5d25cc20f7 100644
--- a/activerecord/test/cases/associations/join_model_test.rb
+++ b/activerecord/test/cases/associations/join_model_test.rb
@@ -238,7 +238,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
def test_include_has_many_through
posts = Post.scoped(:order => 'posts.id').all
- posts_with_authors = Post.scoped(:include => :authors, :order => 'posts.id').all
+ posts_with_authors = Post.scoped(:includes => :authors, :order => 'posts.id').all
assert_equal posts.length, posts_with_authors.length
posts.length.times do |i|
assert_equal posts[i].authors.length, assert_no_queries { posts_with_authors[i].authors.length }
@@ -263,7 +263,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
def test_include_polymorphic_has_many_through
posts = Post.scoped(:order => 'posts.id').all
- posts_with_tags = Post.scoped(:include => :tags, :order => 'posts.id').all
+ posts_with_tags = Post.scoped(:includes => :tags, :order => 'posts.id').all
assert_equal posts.length, posts_with_tags.length
posts.length.times do |i|
assert_equal posts[i].tags.length, assert_no_queries { posts_with_tags[i].tags.length }
@@ -272,7 +272,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
def test_include_polymorphic_has_many
posts = Post.scoped(:order => 'posts.id').all
- posts_with_taggings = Post.scoped(:include => :taggings, :order => 'posts.id').all
+ posts_with_taggings = Post.scoped(:includes => :taggings, :order => 'posts.id').all
assert_equal posts.length, posts_with_taggings.length
posts.length.times do |i|
assert_equal posts[i].taggings.length, assert_no_queries { posts_with_taggings[i].taggings.length }
@@ -292,8 +292,8 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
end
def test_has_many_find_conditions
- assert_equal categories(:general), authors(:david).categories.scoped(:conditions => "categories.name = 'General'").first
- assert_nil authors(:david).categories.scoped(:conditions => "categories.name = 'Technology'").first
+ assert_equal categories(:general), authors(:david).categories.scoped(:where => "categories.name = 'General'").first
+ assert_nil authors(:david).categories.scoped(:where => "categories.name = 'Technology'").first
end
def test_has_many_class_methods_called_by_method_missing
@@ -386,7 +386,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
end
def test_has_many_through_has_many_find_conditions
- options = { :conditions => "comments.#{QUOTED_TYPE}='SpecialComment'", :order => 'comments.id' }
+ options = { :where => "comments.#{QUOTED_TYPE}='SpecialComment'", :order => 'comments.id' }
assert_equal comments(:does_it_hurt), authors(:david).comments.scoped(options).first
end
@@ -411,7 +411,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
end
def test_eager_load_has_many_through_has_many
- author = Author.scoped(:conditions => ['name = ?', 'David'], :include => :comments, :order => 'comments.id').first
+ author = Author.scoped(:where => ['name = ?', 'David'], :includes => :comments, :order => 'comments.id').first
SpecialComment.new; VerySpecialComment.new
assert_no_queries do
assert_equal [1,2,3,5,6,7,8,9,10,12], author.comments.collect(&:id)
@@ -419,7 +419,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
end
def test_eager_load_has_many_through_has_many_with_conditions
- post = Post.scoped(:include => :invalid_tags).first
+ post = Post.scoped(:includes => :invalid_tags).first
assert_no_queries do
post.invalid_tags
end
@@ -427,8 +427,8 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
def test_eager_belongs_to_and_has_one_not_singularized
assert_nothing_raised do
- Author.scoped(:include => :author_address).first
- AuthorAddress.scoped(:include => :author).first
+ Author.scoped(:includes => :author_address).first
+ AuthorAddress.scoped(:includes => :author).first
end
end
@@ -633,7 +633,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
def test_preload_polymorphic_has_many_through
posts = Post.scoped(:order => 'posts.id').all
- posts_with_tags = Post.scoped(:include => :tags, :order => 'posts.id').all
+ posts_with_tags = Post.scoped(:includes => :tags, :order => 'posts.id').all
assert_equal posts.length, posts_with_tags.length
posts.length.times do |i|
assert_equal posts[i].tags.length, assert_no_queries { posts_with_tags[i].tags.length }
@@ -641,7 +641,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
end
def test_preload_polymorph_many_types
- taggings = Tagging.scoped(:include => :taggable, :conditions => ['taggable_type != ?', 'FakeModel']).all
+ taggings = Tagging.scoped(:includes => :taggable, :where => ['taggable_type != ?', 'FakeModel']).all
assert_no_queries do
taggings.first.taggable.id
taggings[1].taggable.id
@@ -654,13 +654,13 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
def test_preload_nil_polymorphic_belongs_to
assert_nothing_raised do
- Tagging.scoped(:include => :taggable, :conditions => ['taggable_type IS NULL']).all
+ Tagging.scoped(:includes => :taggable, :where => ['taggable_type IS NULL']).all
end
end
def test_preload_polymorphic_has_many
posts = Post.scoped(:order => 'posts.id').all
- posts_with_taggings = Post.scoped(:include => :taggings, :order => 'posts.id').all
+ posts_with_taggings = Post.scoped(:includes => :taggings, :order => 'posts.id').all
assert_equal posts.length, posts_with_taggings.length
posts.length.times do |i|
assert_equal posts[i].taggings.length, assert_no_queries { posts_with_taggings[i].taggings.length }
@@ -668,7 +668,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
end
def test_belongs_to_shared_parent
- comments = Comment.scoped(:include => :post, :conditions => 'post_id = 1').all
+ comments = Comment.scoped(:includes => :post, :where => 'post_id = 1').all
assert_no_queries do
assert_equal comments.first.post, comments[1].post
end