提交 0ed05b0e 编写于 作者: J Jon Leighton

find and replace deprecated keys

上级 61555a0d
...@@ -130,7 +130,7 @@ def test_calculations_work_with_reserved_words ...@@ -130,7 +130,7 @@ def test_calculations_work_with_reserved_words
end end
def test_associations_work_with_reserved_words def test_associations_work_with_reserved_words
assert_nothing_raised { Select.scoped(:include => [:groups]).all } assert_nothing_raised { Select.scoped(:includes => [:groups]).all }
end end
#the following functions were added to DRY test cases #the following functions were added to DRY test cases
......
...@@ -130,7 +130,7 @@ def test_calculations_work_with_reserved_words ...@@ -130,7 +130,7 @@ def test_calculations_work_with_reserved_words
end end
def test_associations_work_with_reserved_words def test_associations_work_with_reserved_words
assert_nothing_raised { Select.scoped(:include => [:groups]).all } assert_nothing_raised { Select.scoped(:includes => [:groups]).all }
end end
#the following functions were added to DRY test cases #the following functions were added to DRY test cases
......
...@@ -73,14 +73,14 @@ def test_natural_assignment_with_primary_key ...@@ -73,14 +73,14 @@ def test_natural_assignment_with_primary_key
def test_eager_loading_with_primary_key def test_eager_loading_with_primary_key
Firm.create("name" => "Apple") Firm.create("name" => "Apple")
Client.create("name" => "Citibank", :firm_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) assert citibank_result.association_cache.key?(:firm_with_primary_key)
end end
def test_eager_loading_with_primary_key_as_symbol def test_eager_loading_with_primary_key_as_symbol
Firm.create("name" => "Apple") Firm.create("name" => "Apple")
Client.create("name" => "Citibank", :firm_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) assert citibank_result.association_cache.key?(:firm_with_primary_key_symbols)
end end
......
...@@ -16,7 +16,7 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase ...@@ -16,7 +16,7 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase
:categorizations, :people, :categories, :edges, :vertices :categorizations, :people, :categories, :edges, :vertices
def test_eager_association_loading_with_cascaded_two_levels 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 3, authors.size
assert_equal 5, authors[0].posts.size assert_equal 5, authors[0].posts.size
assert_equal 3, authors[1].posts.size assert_equal 3, authors[1].posts.size
...@@ -24,7 +24,7 @@ def test_eager_association_loading_with_cascaded_two_levels ...@@ -24,7 +24,7 @@ def test_eager_association_loading_with_cascaded_two_levels
end end
def test_eager_association_loading_with_cascaded_two_levels_and_one_level 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 3, authors.size
assert_equal 5, authors[0].posts.size assert_equal 5, authors[0].posts.size
assert_equal 3, authors[1].posts.size assert_equal 3, authors[1].posts.size
...@@ -84,7 +84,7 @@ def test_eager_association_loading_with_join_for_count ...@@ -84,7 +84,7 @@ def test_eager_association_loading_with_join_for_count
end end
def test_eager_association_loading_with_cascaded_two_levels_with_two_has_many_associations 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 3, authors.size
assert_equal 5, authors[0].posts.size assert_equal 5, authors[0].posts.size
assert_equal 3, authors[1].posts.size assert_equal 3, authors[1].posts.size
...@@ -92,7 +92,7 @@ def test_eager_association_loading_with_cascaded_two_levels_with_two_has_many_as ...@@ -92,7 +92,7 @@ def test_eager_association_loading_with_cascaded_two_levels_with_two_has_many_as
end end
def test_eager_association_loading_with_cascaded_two_levels_and_self_table_reference 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 3, authors.size
assert_equal 5, authors[0].posts.size assert_equal 5, authors[0].posts.size
assert_equal authors(:david).name, authors[0].name assert_equal authors(:david).name, authors[0].name
...@@ -100,13 +100,13 @@ def test_eager_association_loading_with_cascaded_two_levels_and_self_table_refer ...@@ -100,13 +100,13 @@ def test_eager_association_loading_with_cascaded_two_levels_and_self_table_refer
end end
def test_eager_association_loading_with_cascaded_two_levels_with_condition 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 1, authors.size
assert_equal 5, authors[0].posts.size assert_equal 5, authors[0].posts.size
end end
def test_eager_association_loading_with_cascaded_three_levels_by_ping_pong 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 2, firms.size
assert_equal firms.first.account, firms.first.account.firm.account assert_equal firms.first.account, firms.first.account.firm.account
assert_equal companies(:first_firm).account, assert_no_queries { firms.first.account.firm.account } assert_equal companies(:first_firm).account, assert_no_queries { firms.first.account.firm.account }
...@@ -114,7 +114,7 @@ def test_eager_association_loading_with_cascaded_three_levels_by_ping_pong ...@@ -114,7 +114,7 @@ def test_eager_association_loading_with_cascaded_three_levels_by_ping_pong
end end
def test_eager_association_loading_with_has_many_sti 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 first, second, = topics(:first).replies.size, topics(:second).replies.size
assert_no_queries do assert_no_queries do
assert_equal first, topics[0].replies.size assert_equal first, topics[0].replies.size
...@@ -127,7 +127,7 @@ def test_eager_association_loading_with_has_many_sti_and_subclasses ...@@ -127,7 +127,7 @@ def test_eager_association_loading_with_has_many_sti_and_subclasses
silly.parent_id = 1 silly.parent_id = 1
assert silly.save 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_no_queries do
assert_equal 2, topics[0].replies.size assert_equal 2, topics[0].replies.size
assert_equal 0, topics[1].replies.size assert_equal 0, topics[1].replies.size
...@@ -135,14 +135,14 @@ def test_eager_association_loading_with_has_many_sti_and_subclasses ...@@ -135,14 +135,14 @@ def test_eager_association_loading_with_has_many_sti_and_subclasses
end end
def test_eager_association_loading_with_belongs_to_sti 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(:second))
assert !replies.include?(topics(:first)) assert !replies.include?(topics(:first))
assert_equal topics(:first), assert_no_queries { replies.first.topic } assert_equal topics(:first), assert_no_queries { replies.first.topic }
end end
def test_eager_association_loading_with_multiple_stis_and_order 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_equal authors(:david), author
assert_no_queries do assert_no_queries do
author.posts.first.special_comments author.posts.first.special_comments
...@@ -151,7 +151,7 @@ def test_eager_association_loading_with_multiple_stis_and_order ...@@ -151,7 +151,7 @@ def test_eager_association_loading_with_multiple_stis_and_order
end end
def test_eager_association_loading_of_stis_with_multiple_references 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_equal [authors(:david)], authors
assert_no_queries do assert_no_queries do
authors.first.posts.first.special_comments.first.post.special_comments authors.first.posts.first.special_comments.first.post.special_comments
...@@ -160,7 +160,7 @@ def test_eager_association_loading_of_stis_with_multiple_references ...@@ -160,7 +160,7 @@ def test_eager_association_loading_of_stis_with_multiple_references
end end
def test_eager_association_loading_where_first_level_returns_nil 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_equal [authors(:bob), authors(:mary), authors(:david)], authors
assert_no_queries do assert_no_queries do
authors[2].post_about_thinking.comments.first authors[2].post_about_thinking.comments.first
...@@ -168,12 +168,12 @@ def test_eager_association_loading_where_first_level_returns_nil ...@@ -168,12 +168,12 @@ def test_eager_association_loading_where_first_level_returns_nil
end end
def test_eager_association_loading_with_recursive_cascading_four_levels_has_many_through 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 } assert_equal vertices(:vertex_4), assert_no_queries { source.sinks.first.sinks.first.sinks.first }
end end
def test_eager_association_loading_with_recursive_cascading_four_levels_has_and_belongs_to_many 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 } assert_equal vertices(:vertex_1), assert_no_queries { sink.sources.first.sources.first.sources.first.sources.first }
end end
end end
...@@ -93,7 +93,7 @@ def generate_test_object_graphs ...@@ -93,7 +93,7 @@ def generate_test_object_graphs
def test_include_query def test_include_query
res = 0 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_equal NUM_SHAPE_EXPRESSIONS, res.size
assert_queries(0) do assert_queries(0) do
res.each do |se| res.each do |se|
......
...@@ -103,43 +103,43 @@ def teardown ...@@ -103,43 +103,43 @@ def teardown
def test_eager_no_extra_singularization_belongs_to def test_eager_no_extra_singularization_belongs_to
return unless @have_tables return unless @have_tables
assert_nothing_raised do assert_nothing_raised do
Virus.scoped(:include => :octopus).all Virus.scoped(:includes => :octopus).all
end end
end end
def test_eager_no_extra_singularization_has_one def test_eager_no_extra_singularization_has_one
return unless @have_tables return unless @have_tables
assert_nothing_raised do assert_nothing_raised do
Octopus.scoped(:include => :virus).all Octopus.scoped(:includes => :virus).all
end end
end end
def test_eager_no_extra_singularization_has_many def test_eager_no_extra_singularization_has_many
return unless @have_tables return unless @have_tables
assert_nothing_raised do assert_nothing_raised do
Bus.scoped(:include => :passes).all Bus.scoped(:includes => :passes).all
end end
end end
def test_eager_no_extra_singularization_has_and_belongs_to_many def test_eager_no_extra_singularization_has_and_belongs_to_many
return unless @have_tables return unless @have_tables
assert_nothing_raised do assert_nothing_raised do
Crisis.scoped(:include => :messes).all Crisis.scoped(:includes => :messes).all
Mess.scoped(:include => :crises).all Mess.scoped(:includes => :crises).all
end end
end end
def test_eager_no_extra_singularization_has_many_through_belongs_to def test_eager_no_extra_singularization_has_many_through_belongs_to
return unless @have_tables return unless @have_tables
assert_nothing_raised do assert_nothing_raised do
Crisis.scoped(:include => :successes).all Crisis.scoped(:includes => :successes).all
end end
end end
def test_eager_no_extra_singularization_has_many_through_has_many def test_eager_no_extra_singularization_has_many_through_has_many
return unless @have_tables return unless @have_tables
assert_nothing_raised do assert_nothing_raised do
Crisis.scoped(:include => :compresses).all Crisis.scoped(:includes => :compresses).all
end end
end end
end end
...@@ -549,14 +549,14 @@ def test_find_in_association_with_custom_finder_sql_and_string_id ...@@ -549,14 +549,14 @@ def test_find_in_association_with_custom_finder_sql_and_string_id
def test_find_with_merged_options def test_find_with_merged_options
assert_equal 1, projects(:active_record).limited_developers.size assert_equal 1, projects(:active_record).limited_developers.size
assert_equal 1, projects(:active_record).limited_developers.all.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 end
def test_dynamic_find_should_respect_association_order def test_dynamic_find_should_respect_association_order
# Developers are ordered 'name DESC, id DESC' # Developers are ordered 'name DESC, id DESC'
high_id_jamis = projects(:active_record).developers.create(:name => 'Jamis') 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') assert_equal high_id_jamis, projects(:active_record).developers.find_by_name('Jamis')
end end
...@@ -566,7 +566,7 @@ def test_dynamic_find_all_should_respect_association_order ...@@ -566,7 +566,7 @@ def test_dynamic_find_all_should_respect_association_order
middle_id_jamis = developers(:poor_jamis) middle_id_jamis = developers(:poor_jamis)
high_id_jamis = projects(:active_record).developers.create(:name => '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') assert_equal [high_id_jamis, middle_id_jamis, low_id_jamis], projects(:active_record).developers.find_all_by_name('Jamis')
end end
...@@ -576,12 +576,12 @@ def test_find_should_append_to_association_order ...@@ -576,12 +576,12 @@ def test_find_should_append_to_association_order
end end
def test_dynamic_find_all_should_respect_association_limit 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 assert_equal 1, projects(:active_record).limited_developers.find_all_by_name('Jamis').length
end end
def test_dynamic_find_all_order_should_override_association_limit 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 assert_equal 2, projects(:active_record).limited_developers.find_all_by_name('Jamis', :limit => 9_000).length
end end
...@@ -705,8 +705,8 @@ def test_join_with_group ...@@ -705,8 +705,8 @@ def test_join_with_group
end end
def test_find_grouped def test_find_grouped
all_posts_from_category1 = Post.scoped(:conditions => "category_id = 1", :joins => :categories).all all_posts_from_category1 = Post.scoped(:where => "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 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 5, all_posts_from_category1.size
assert_equal 2, grouped_posts_of_category1.size assert_equal 2, grouped_posts_of_category1.size
end end
......
...@@ -273,14 +273,14 @@ def test_finding_array_compatibility ...@@ -273,14 +273,14 @@ def test_finding_array_compatibility
def test_find_with_blank_conditions def test_find_with_blank_conditions
[[], {}, nil, ""].each do |blank| [[], {}, 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
end end
def test_find_many_with_merged_options def test_find_many_with_merged_options
assert_equal 1, companies(:first_firm).limited_clients.size assert_equal 1, companies(:first_firm).limited_clients.size
assert_equal 1, companies(:first_firm).limited_clients.all.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 end
def test_find_should_append_to_association_order def test_find_should_append_to_association_order
...@@ -293,22 +293,22 @@ def test_dynamic_find_last_without_specified_order ...@@ -293,22 +293,22 @@ def test_dynamic_find_last_without_specified_order
end end
def test_dynamic_find_should_respect_association_order 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') assert_equal companies(:second_client), companies(:first_firm).clients_sorted_desc.find_by_type('Client')
end end
def test_dynamic_find_all_should_respect_association_order 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') assert_equal [companies(:second_client), companies(:first_client)], companies(:first_firm).clients_sorted_desc.find_all_by_type('Client')
end end
def test_dynamic_find_all_should_respect_association_limit 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 assert_equal 1, companies(:first_firm).limited_clients.find_all_by_type('Client').length
end end
def test_dynamic_find_all_limit_should_override_association_limit 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 assert_equal 2, companies(:first_firm).limited_clients.find_all_by_type('Client', :limit => 9_000).length
end end
...@@ -432,8 +432,8 @@ def test_find_string_ids_when_using_finder_sql ...@@ -432,8 +432,8 @@ def test_find_string_ids_when_using_finder_sql
def test_find_all def test_find_all
firm = Firm.scoped(:order => "id").first firm = Firm.scoped(:order => "id").first
assert_equal 2, firm.clients.scoped(:conditions => "#{QUOTED_TYPE} = 'Client'").all.length assert_equal 2, firm.clients.scoped(:where => "#{QUOTED_TYPE} = 'Client'").all.length
assert_equal 1, firm.clients.scoped(:conditions => "name = 'Summit'").all.length assert_equal 1, firm.clients.scoped(:where => "name = 'Summit'").all.length
end end
def test_find_each def test_find_each
...@@ -478,28 +478,28 @@ def test_find_in_batches ...@@ -478,28 +478,28 @@ def test_find_in_batches
def test_find_all_sanitized def test_find_all_sanitized
# sometimes tests on Oracle fail if ORDER BY is not provided therefore add always :order with :first # sometimes tests on Oracle fail if ORDER BY is not provided therefore add always :order with :first
firm = Firm.scoped(:order => "id").first firm = Firm.scoped(:order => "id").first
summit = firm.clients.scoped(:conditions => "name = 'Summit'").all summit = firm.clients.scoped(:where => "name = 'Summit'").all
assert_equal summit, firm.clients.scoped(:conditions => ["name = ?", "Summit"]).all assert_equal summit, firm.clients.scoped(:where => ["name = ?", "Summit"]).all
assert_equal summit, firm.clients.scoped(:conditions => ["name = :name", { :name => "Summit" }]).all assert_equal summit, firm.clients.scoped(:where => ["name = :name", { :name => "Summit" }]).all
end end
def test_find_first def test_find_first
firm = Firm.scoped(:order => "id").first firm = Firm.scoped(:order => "id").first
client2 = Client.find(2) client2 = Client.find(2)
assert_equal firm.clients.first, firm.clients.scoped(:order => "id").first 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 end
def test_find_first_sanitized def test_find_first_sanitized
firm = Firm.scoped(:order => "id").first firm = Firm.scoped(:order => "id").first
client2 = Client.find(2) client2 = Client.find(2)
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
assert_equal client2, firm.clients.scoped(:conditions => ["#{QUOTED_TYPE} = :type", { :type => 'Client' }], :order => "id").first assert_equal client2, firm.clients.scoped(:where => ["#{QUOTED_TYPE} = :type", { :type => 'Client' }], :order => "id").first
end end
def test_find_all_with_include_and_conditions def test_find_all_with_include_and_conditions
assert_nothing_raised do 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
end end
...@@ -509,8 +509,8 @@ def test_find_in_collection ...@@ -509,8 +509,8 @@ def test_find_in_collection
end end
def test_find_grouped def test_find_grouped
all_clients_of_firm1 = Client.scoped(:conditions => "firm_id = 1").all all_clients_of_firm1 = Client.scoped(:where => "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 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 2, all_clients_of_firm1.size
assert_equal 1, grouped_clients_of_firm1.size assert_equal 1, grouped_clients_of_firm1.size
end end
...@@ -1110,7 +1110,7 @@ def test_dependence ...@@ -1110,7 +1110,7 @@ def test_dependence
firm = companies(:first_firm) firm = companies(:first_firm)
assert_equal 2, firm.clients.size assert_equal 2, firm.clients.size
firm.destroy firm.destroy
assert Client.scoped(:conditions => "firm_id=#{firm.id}").all.empty? assert Client.scoped(:where => "firm_id=#{firm.id}").all.empty?
end end
def test_dependence_for_associations_with_hash_condition def test_dependence_for_associations_with_hash_condition
...@@ -1148,7 +1148,7 @@ def test_dependence_with_transaction_support_on_failure ...@@ -1148,7 +1148,7 @@ def test_dependence_with_transaction_support_on_failure
firm.destroy rescue "do nothing" 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 end
def test_dependence_on_account def test_dependence_on_account
...@@ -1329,27 +1329,27 @@ def test_modifying_a_through_a_has_many_should_raise ...@@ -1329,27 +1329,27 @@ def test_modifying_a_through_a_has_many_should_raise
end end
def test_dynamic_find_should_respect_association_order_for_through 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') assert_equal Comment.find(10), authors(:david).comments_desc.find_by_type('SpecialComment')
end end
def test_dynamic_find_all_should_respect_association_order_for_through 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') assert_equal [Comment.find(10), Comment.find(7), Comment.find(6), Comment.find(3)], authors(:david).comments_desc.find_all_by_type('SpecialComment')
end end
def test_dynamic_find_all_should_respect_association_limit_for_through 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 assert_equal 1, authors(:david).limited_comments.find_all_by_type('SpecialComment').length
end end
def test_dynamic_find_all_order_should_override_association_limit_for_through 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 assert_equal 4, authors(:david).limited_comments.find_all_by_type('SpecialComment', :limit => 9_000).length
end end
def test_find_all_include_over_the_same_table_for_through 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 end
def test_has_many_through_respects_hash_conditions def test_has_many_through_respects_hash_conditions
......
...@@ -25,7 +25,7 @@ def test_has_one_cache_nils ...@@ -25,7 +25,7 @@ def test_has_one_cache_nils
assert_queries(1) { assert_nil firm.account } assert_queries(1) { assert_nil firm.account }
assert_queries(0) { 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) } assert_queries(0) { firms.each(&:account) }
end end
......
...@@ -73,7 +73,7 @@ def test_has_one_through_polymorphic ...@@ -73,7 +73,7 @@ def test_has_one_through_polymorphic
def test_has_one_through_eager_loading def test_has_one_through_eager_loading
members = assert_queries(3) do #base table, through table, clubs table 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 end
assert_equal 1, members.size assert_equal 1, members.size
assert_not_nil assert_no_queries {members[0].club} assert_not_nil assert_no_queries {members[0].club}
...@@ -81,7 +81,7 @@ def test_has_one_through_eager_loading ...@@ -81,7 +81,7 @@ def test_has_one_through_eager_loading
def test_has_one_through_eager_loading_through_polymorphic def test_has_one_through_eager_loading_through_polymorphic
members = assert_queries(3) do #base table, through table, clubs table 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 end
assert_equal 1, members.size assert_equal 1, members.size
assert_not_nil assert_no_queries {members[0].sponsor_club} assert_not_nil assert_no_queries {members[0].sponsor_club}
...@@ -104,14 +104,14 @@ def test_has_one_through_polymorphic_with_source_type ...@@ -104,14 +104,14 @@ def test_has_one_through_polymorphic_with_source_type
end end
def test_eager_has_one_through_polymorphic_with_source_type 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 # Only the eyebrow fanciers club has a sponsored_member
assert_not_nil assert_no_queries {clubs[0].sponsored_member} assert_not_nil assert_no_queries {clubs[0].sponsored_member}
end end
def test_has_one_through_nonpreload_eagerloading def test_has_one_through_nonpreload_eagerloading
members = assert_queries(1) do 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 end
assert_equal 1, members.size assert_equal 1, members.size
assert_not_nil assert_no_queries {members[0].club} assert_not_nil assert_no_queries {members[0].club}
...@@ -119,7 +119,7 @@ def test_has_one_through_nonpreload_eagerloading ...@@ -119,7 +119,7 @@ def test_has_one_through_nonpreload_eagerloading
def test_has_one_through_nonpreload_eager_loading_through_polymorphic def test_has_one_through_nonpreload_eager_loading_through_polymorphic
members = assert_queries(1) do 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 end
assert_equal 1, members.size assert_equal 1, members.size
assert_not_nil assert_no_queries {members[0].sponsor_club} assert_not_nil assert_no_queries {members[0].sponsor_club}
...@@ -128,7 +128,7 @@ def test_has_one_through_nonpreload_eager_loading_through_polymorphic ...@@ -128,7 +128,7 @@ def test_has_one_through_nonpreload_eager_loading_through_polymorphic
def test_has_one_through_nonpreload_eager_loading_through_polymorphic_with_more_than_one_through_record 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! Sponsor.new(:sponsor_club => clubs(:crazy_club), :sponsorable => members(:groucho)).save!
members = assert_queries(1) do 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 end
assert_equal 1, members.size assert_equal 1, members.size
assert_not_nil assert_no_queries { members[0].sponsor_club } assert_not_nil assert_no_queries { members[0].sponsor_club }
...@@ -197,7 +197,7 @@ def test_preloading_has_one_through_on_belongs_to ...@@ -197,7 +197,7 @@ def test_preloading_has_one_through_on_belongs_to
@member.member_detail = @member_detail @member.member_detail = @member_detail
@member.organization = @organization @member.organization = @organization
@member_details = assert_queries(3) do @member_details = assert_queries(3) do
MemberDetail.scoped(:include => :member_type).all MemberDetail.scoped(:includes => :member_type).all
end end
@new_detail = @member_details[0] @new_detail = @member_details[0]
assert @new_detail.send(:association, :member_type).loaded? assert @new_detail.send(:association, :member_type).loaded?
......
...@@ -96,7 +96,7 @@ def test_parent_instance_should_be_shared_with_child_on_find ...@@ -96,7 +96,7 @@ def test_parent_instance_should_be_shared_with_child_on_find
def test_parent_instance_should_be_shared_with_eager_loaded_child_on_find 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 f = m.face
assert_equal m.name, f.man.name, "Name of man should be the same before changes to parent instance" assert_equal m.name, f.man.name, "Name of man should be the same before changes to parent instance"
m.name = 'Bongo' m.name = 'Bongo'
...@@ -104,7 +104,7 @@ def test_parent_instance_should_be_shared_with_eager_loaded_child_on_find ...@@ -104,7 +104,7 @@ def test_parent_instance_should_be_shared_with_eager_loaded_child_on_find
f.man.name = 'Mungo' f.man.name = 'Mungo'
assert_equal m.name, f.man.name, "Name of man should be the same after changes to child-owned instance" 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 f = m.face
assert_equal m.name, f.man.name, "Name of man should be the same before changes to parent instance" assert_equal m.name, f.man.name, "Name of man should be the same before changes to parent instance"
m.name = 'Bongo' m.name = 'Bongo'
...@@ -179,7 +179,7 @@ def test_parent_instance_should_be_shared_with_every_child_on_find ...@@ -179,7 +179,7 @@ def test_parent_instance_should_be_shared_with_every_child_on_find
end end
def test_parent_instance_should_be_shared_with_eager_loaded_children 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 = m.interests
is.each do |i| is.each do |i|
assert_equal m.name, i.man.name, "Name of man should be the same before changes to parent instance" assert_equal m.name, i.man.name, "Name of man should be the same before changes to parent instance"
...@@ -189,7 +189,7 @@ def test_parent_instance_should_be_shared_with_eager_loaded_children ...@@ -189,7 +189,7 @@ def test_parent_instance_should_be_shared_with_eager_loaded_children
assert_equal m.name, i.man.name, "Name of man should be the same after changes to child-owned instance" assert_equal m.name, i.man.name, "Name of man should be the same after changes to child-owned instance"
end 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 = m.interests
is.each do |i| is.each do |i|
assert_equal m.name, i.man.name, "Name of man should be the same before changes to parent instance" assert_equal m.name, i.man.name, "Name of man should be the same before changes to parent instance"
...@@ -278,7 +278,7 @@ def test_child_instance_should_be_shared_with_parent_on_find ...@@ -278,7 +278,7 @@ def test_child_instance_should_be_shared_with_parent_on_find
end end
def test_eager_loaded_child_instance_should_be_shared_with_parent_on_find 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 m = f.man
assert_equal f.description, m.face.description, "Description of face should be the same before changes to child instance" assert_equal f.description, m.face.description, "Description of face should be the same before changes to child instance"
f.description = 'gormless' f.description = 'gormless'
...@@ -286,7 +286,7 @@ def test_eager_loaded_child_instance_should_be_shared_with_parent_on_find ...@@ -286,7 +286,7 @@ def test_eager_loaded_child_instance_should_be_shared_with_parent_on_find
m.face.description = 'pleasing' m.face.description = 'pleasing'
assert_equal f.description, m.face.description, "Description of face should be the same after changes to parent-owned instance" 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 m = f.man
assert_equal f.description, m.face.description, "Description of face should be the same before changes to child instance" assert_equal f.description, m.face.description, "Description of face should be the same before changes to child instance"
f.description = 'gormless' f.description = 'gormless'
...@@ -351,7 +351,7 @@ class InversePolymorphicBelongsToTests < ActiveRecord::TestCase ...@@ -351,7 +351,7 @@ class InversePolymorphicBelongsToTests < ActiveRecord::TestCase
fixtures :men, :faces, :interests fixtures :men, :faces, :interests
def test_child_instance_should_be_shared_with_parent_on_find 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 m = f.polymorphic_man
assert_equal f.description, m.polymorphic_face.description, "Description of face should be the same before changes to child instance" assert_equal f.description, m.polymorphic_face.description, "Description of face should be the same before changes to child instance"
f.description = 'gormless' f.description = 'gormless'
...@@ -361,7 +361,7 @@ def test_child_instance_should_be_shared_with_parent_on_find ...@@ -361,7 +361,7 @@ def test_child_instance_should_be_shared_with_parent_on_find
end end
def test_eager_loaded_child_instance_should_be_shared_with_parent_on_find 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 m = f.polymorphic_man
assert_equal f.description, m.polymorphic_face.description, "Description of face should be the same before changes to child instance" assert_equal f.description, m.polymorphic_face.description, "Description of face should be the same before changes to child instance"
f.description = 'gormless' f.description = 'gormless'
...@@ -369,7 +369,7 @@ def test_eager_loaded_child_instance_should_be_shared_with_parent_on_find ...@@ -369,7 +369,7 @@ def test_eager_loaded_child_instance_should_be_shared_with_parent_on_find
m.polymorphic_face.description = 'pleasing' 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" 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 m = f.polymorphic_man
assert_equal f.description, m.polymorphic_face.description, "Description of face should be the same before changes to child instance" assert_equal f.description, m.polymorphic_face.description, "Description of face should be the same before changes to child instance"
f.description = 'gormless' f.description = 'gormless'
......
...@@ -238,7 +238,7 @@ def test_has_many_with_piggyback ...@@ -238,7 +238,7 @@ def test_has_many_with_piggyback
def test_include_has_many_through def test_include_has_many_through
posts = Post.scoped(:order => 'posts.id').all 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 assert_equal posts.length, posts_with_authors.length
posts.length.times do |i| posts.length.times do |i|
assert_equal posts[i].authors.length, assert_no_queries { posts_with_authors[i].authors.length } assert_equal posts[i].authors.length, assert_no_queries { posts_with_authors[i].authors.length }
...@@ -263,7 +263,7 @@ def test_include_polymorphic_has_one_defined_in_abstract_parent ...@@ -263,7 +263,7 @@ def test_include_polymorphic_has_one_defined_in_abstract_parent
def test_include_polymorphic_has_many_through def test_include_polymorphic_has_many_through
posts = Post.scoped(:order => 'posts.id').all 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 assert_equal posts.length, posts_with_tags.length
posts.length.times do |i| posts.length.times do |i|
assert_equal posts[i].tags.length, assert_no_queries { posts_with_tags[i].tags.length } assert_equal posts[i].tags.length, assert_no_queries { posts_with_tags[i].tags.length }
...@@ -272,7 +272,7 @@ def test_include_polymorphic_has_many_through ...@@ -272,7 +272,7 @@ def test_include_polymorphic_has_many_through
def test_include_polymorphic_has_many def test_include_polymorphic_has_many
posts = Post.scoped(:order => 'posts.id').all 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 assert_equal posts.length, posts_with_taggings.length
posts.length.times do |i| posts.length.times do |i|
assert_equal posts[i].taggings.length, assert_no_queries { posts_with_taggings[i].taggings.length } assert_equal posts[i].taggings.length, assert_no_queries { posts_with_taggings[i].taggings.length }
...@@ -292,8 +292,8 @@ def test_has_many_with_hash_conditions ...@@ -292,8 +292,8 @@ def test_has_many_with_hash_conditions
end end
def test_has_many_find_conditions def test_has_many_find_conditions
assert_equal categories(:general), authors(:david).categories.scoped(:conditions => "categories.name = 'General'").first assert_equal categories(:general), authors(:david).categories.scoped(:where => "categories.name = 'General'").first
assert_nil authors(:david).categories.scoped(:conditions => "categories.name = 'Technology'").first assert_nil authors(:david).categories.scoped(:where => "categories.name = 'Technology'").first
end end
def test_has_many_class_methods_called_by_method_missing def test_has_many_class_methods_called_by_method_missing
...@@ -386,7 +386,7 @@ def test_has_many_through_has_many_find_first ...@@ -386,7 +386,7 @@ def test_has_many_through_has_many_find_first
end end
def test_has_many_through_has_many_find_conditions 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 assert_equal comments(:does_it_hurt), authors(:david).comments.scoped(options).first
end end
...@@ -411,7 +411,7 @@ def test_include_has_many_through_polymorphic_has_many ...@@ -411,7 +411,7 @@ def test_include_has_many_through_polymorphic_has_many
end end
def test_eager_load_has_many_through_has_many 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 SpecialComment.new; VerySpecialComment.new
assert_no_queries do assert_no_queries do
assert_equal [1,2,3,5,6,7,8,9,10,12], author.comments.collect(&:id) assert_equal [1,2,3,5,6,7,8,9,10,12], author.comments.collect(&:id)
...@@ -419,7 +419,7 @@ def test_eager_load_has_many_through_has_many ...@@ -419,7 +419,7 @@ def test_eager_load_has_many_through_has_many
end end
def test_eager_load_has_many_through_has_many_with_conditions 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 assert_no_queries do
post.invalid_tags post.invalid_tags
end end
...@@ -427,8 +427,8 @@ def test_eager_load_has_many_through_has_many_with_conditions ...@@ -427,8 +427,8 @@ def test_eager_load_has_many_through_has_many_with_conditions
def test_eager_belongs_to_and_has_one_not_singularized def test_eager_belongs_to_and_has_one_not_singularized
assert_nothing_raised do assert_nothing_raised do
Author.scoped(:include => :author_address).first Author.scoped(:includes => :author_address).first
AuthorAddress.scoped(:include => :author).first AuthorAddress.scoped(:includes => :author).first
end end
end end
...@@ -633,7 +633,7 @@ def test_polymorphic_belongs_to ...@@ -633,7 +633,7 @@ def test_polymorphic_belongs_to
def test_preload_polymorphic_has_many_through def test_preload_polymorphic_has_many_through
posts = Post.scoped(:order => 'posts.id').all 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 assert_equal posts.length, posts_with_tags.length
posts.length.times do |i| posts.length.times do |i|
assert_equal posts[i].tags.length, assert_no_queries { posts_with_tags[i].tags.length } assert_equal posts[i].tags.length, assert_no_queries { posts_with_tags[i].tags.length }
...@@ -641,7 +641,7 @@ def test_preload_polymorphic_has_many_through ...@@ -641,7 +641,7 @@ def test_preload_polymorphic_has_many_through
end end
def test_preload_polymorph_many_types 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 assert_no_queries do
taggings.first.taggable.id taggings.first.taggable.id
taggings[1].taggable.id taggings[1].taggable.id
...@@ -654,13 +654,13 @@ def test_preload_polymorph_many_types ...@@ -654,13 +654,13 @@ def test_preload_polymorph_many_types
def test_preload_nil_polymorphic_belongs_to def test_preload_nil_polymorphic_belongs_to
assert_nothing_raised do 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
end end
def test_preload_polymorphic_has_many def test_preload_polymorphic_has_many
posts = Post.scoped(:order => 'posts.id').all 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 assert_equal posts.length, posts_with_taggings.length
posts.length.times do |i| posts.length.times do |i|
assert_equal posts[i].taggings.length, assert_no_queries { posts_with_taggings[i].taggings.length } assert_equal posts[i].taggings.length, assert_no_queries { posts_with_taggings[i].taggings.length }
...@@ -668,7 +668,7 @@ def test_preload_polymorphic_has_many ...@@ -668,7 +668,7 @@ def test_preload_polymorphic_has_many
end end
def test_belongs_to_shared_parent 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_no_queries do
assert_equal comments.first.post, comments[1].post assert_equal comments.first.post, comments[1].post
end end
......
...@@ -74,8 +74,8 @@ def test_loading_the_association_target_should_load_most_recent_attributes_for_c ...@@ -74,8 +74,8 @@ def test_loading_the_association_target_should_load_most_recent_attributes_for_c
def test_include_with_order_works def test_include_with_order_works
assert_nothing_raised {Account.scoped(:order => 'id', :include => :firm).first} assert_nothing_raised {Account.scoped(:order => 'id', :includes => :firm).first}
assert_nothing_raised {Account.scoped(:order => :id, :include => :firm).first} assert_nothing_raised {Account.scoped(:order => :id, :includes => :firm).first}
end end
def test_bad_collection_keys def test_bad_collection_keys
......
...@@ -155,7 +155,7 @@ def test_assignment_before_either_saved ...@@ -155,7 +155,7 @@ def test_assignment_before_either_saved
end end
def test_not_resaved_when_unchanged def test_not_resaved_when_unchanged
firm = Firm.scoped(:include => :account).first firm = Firm.scoped(:includes => :account).first
firm.name += '-changed' firm.name += '-changed'
assert_queries(1) { firm.save! } assert_queries(1) { firm.save! }
......
...@@ -356,7 +356,7 @@ def test_load ...@@ -356,7 +356,7 @@ def test_load
end end
def test_load_with_condition def test_load_with_condition
topics = Topic.scoped(:conditions => "author_name = 'Mary'").all topics = Topic.scoped(:where => "author_name = 'Mary'").all
assert_equal(1, topics.size) assert_equal(1, topics.size)
assert_equal(topics(:second).title, topics.first.title) assert_equal(topics(:second).title, topics.first.title)
...@@ -1264,10 +1264,10 @@ def test_column_name_properly_quoted ...@@ -1264,10 +1264,10 @@ def test_column_name_properly_quoted
end end
def test_quoting_arrays def test_quoting_arrays
replies = Reply.scoped(:conditions => [ "id IN (?)", topics(:first).replies.collect(&:id) ]).all replies = Reply.scoped(:where => [ "id IN (?)", topics(:first).replies.collect(&:id) ]).all
assert_equal topics(:first).replies.size, replies.size assert_equal topics(:first).replies.size, replies.size
replies = Reply.scoped(:conditions => [ "id IN (?)", [] ]).all replies = Reply.scoped(:where => [ "id IN (?)", [] ]).all
assert_equal 0, replies.size assert_equal 0, replies.size
end end
...@@ -1739,8 +1739,8 @@ def test_inspect_new_instance ...@@ -1739,8 +1739,8 @@ def test_inspect_new_instance
end end
def test_inspect_limited_select_instance def test_inspect_limited_select_instance
assert_equal %(#<Topic id: 1>), Topic.scoped(:select => 'id', :conditions => 'id = 1').first.inspect assert_equal %(#<Topic id: 1>), Topic.scoped(:select => 'id', :where => 'id = 1').first.inspect
assert_equal %(#<Topic id: 1, title: "The First Topic">), Topic.scoped(:select => 'id, title', :conditions => 'id = 1').first.inspect assert_equal %(#<Topic id: 1, title: "The First Topic">), Topic.scoped(:select => 'id, title', :where => 'id = 1').first.inspect
end end
def test_inspect_class_without_table def test_inspect_class_without_table
......
...@@ -281,23 +281,23 @@ def test_find_on_association_proxy_conditions ...@@ -281,23 +281,23 @@ def test_find_on_association_proxy_conditions
end end
def test_find_on_hash_conditions_with_range def test_find_on_hash_conditions_with_range
assert_equal [1,2], Topic.scoped(:conditions => { :id => 1..2 }).all.map(&:id).sort assert_equal [1,2], Topic.scoped(:where => { :id => 1..2 }).all.map(&:id).sort
assert_raise(ActiveRecord::RecordNotFound) { Topic.find(1, :conditions => { :id => 2..3 }) } assert_raise(ActiveRecord::RecordNotFound) { Topic.find(1, :conditions => { :id => 2..3 }) }
end end
def test_find_on_hash_conditions_with_end_exclusive_range def test_find_on_hash_conditions_with_end_exclusive_range
assert_equal [1,2,3], Topic.scoped(:conditions => { :id => 1..3 }).all.map(&:id).sort assert_equal [1,2,3], Topic.scoped(:where => { :id => 1..3 }).all.map(&:id).sort
assert_equal [1,2], Topic.scoped(:conditions => { :id => 1...3 }).all.map(&:id).sort assert_equal [1,2], Topic.scoped(:where => { :id => 1...3 }).all.map(&:id).sort
assert_raise(ActiveRecord::RecordNotFound) { Topic.find(3, :conditions => { :id => 2...3 }) } assert_raise(ActiveRecord::RecordNotFound) { Topic.find(3, :conditions => { :id => 2...3 }) }
end end
def test_find_on_hash_conditions_with_multiple_ranges def test_find_on_hash_conditions_with_multiple_ranges
assert_equal [1,2,3], Comment.scoped(:conditions => { :id => 1..3, :post_id => 1..2 }).all.map(&:id).sort assert_equal [1,2,3], Comment.scoped(:where => { :id => 1..3, :post_id => 1..2 }).all.map(&:id).sort
assert_equal [1], Comment.scoped(:conditions => { :id => 1..1, :post_id => 1..10 }).all.map(&:id).sort assert_equal [1], Comment.scoped(:where => { :id => 1..1, :post_id => 1..10 }).all.map(&:id).sort
end end
def test_find_on_hash_conditions_with_array_of_integers_and_ranges def test_find_on_hash_conditions_with_array_of_integers_and_ranges
assert_equal [1,2,3,5,6,7,8,9], Comment.scoped(:conditions => {:id => [1..2, 3, 5, 6..8, 9]}).all.map(&:id).sort assert_equal [1,2,3,5,6,7,8,9], Comment.scoped(:where => {:id => [1..2, 3, 5, 6..8, 9]}).all.map(&:id).sort
end end
def test_find_on_multiple_hash_conditions def test_find_on_multiple_hash_conditions
...@@ -309,43 +309,43 @@ def test_find_on_multiple_hash_conditions ...@@ -309,43 +309,43 @@ def test_find_on_multiple_hash_conditions
def test_condition_interpolation def test_condition_interpolation
assert_kind_of Firm, Company.where("name = '%s'", "37signals").first assert_kind_of Firm, Company.where("name = '%s'", "37signals").first
assert_nil Company.scoped(:conditions => ["name = '%s'", "37signals!"]).first assert_nil Company.scoped(:where => ["name = '%s'", "37signals!"]).first
assert_nil Company.scoped(:conditions => ["name = '%s'", "37signals!' OR 1=1"]).first assert_nil Company.scoped(:where => ["name = '%s'", "37signals!' OR 1=1"]).first
assert_kind_of Time, Topic.scoped(:conditions => ["id = %d", 1]).first.written_on assert_kind_of Time, Topic.scoped(:where => ["id = %d", 1]).first.written_on
end end
def test_condition_array_interpolation def test_condition_array_interpolation
assert_kind_of Firm, Company.scoped(:conditions => ["name = '%s'", "37signals"]).first assert_kind_of Firm, Company.scoped(:where => ["name = '%s'", "37signals"]).first
assert_nil Company.scoped(:conditions => ["name = '%s'", "37signals!"]).first assert_nil Company.scoped(:where => ["name = '%s'", "37signals!"]).first
assert_nil Company.scoped(:conditions => ["name = '%s'", "37signals!' OR 1=1"]).first assert_nil Company.scoped(:where => ["name = '%s'", "37signals!' OR 1=1"]).first
assert_kind_of Time, Topic.scoped(:conditions => ["id = %d", 1]).first.written_on assert_kind_of Time, Topic.scoped(:where => ["id = %d", 1]).first.written_on
end end
def test_condition_hash_interpolation def test_condition_hash_interpolation
assert_kind_of Firm, Company.scoped(:conditions => { :name => "37signals"}).first assert_kind_of Firm, Company.scoped(:where => { :name => "37signals"}).first
assert_nil Company.scoped(:conditions => { :name => "37signals!"}).first assert_nil Company.scoped(:where => { :name => "37signals!"}).first
assert_kind_of Time, Topic.scoped(:conditions => {:id => 1}).first.written_on assert_kind_of Time, Topic.scoped(:where => {:id => 1}).first.written_on
end end
def test_hash_condition_find_malformed def test_hash_condition_find_malformed
assert_raise(ActiveRecord::StatementInvalid) { assert_raise(ActiveRecord::StatementInvalid) {
Company.scoped(:conditions => { :id => 2, :dhh => true }).first Company.scoped(:where => { :id => 2, :dhh => true }).first
} }
end end
def test_hash_condition_find_with_escaped_characters def test_hash_condition_find_with_escaped_characters
Company.create("name" => "Ain't noth'n like' \#stuff") Company.create("name" => "Ain't noth'n like' \#stuff")
assert Company.scoped(:conditions => { :name => "Ain't noth'n like' \#stuff" }).first assert Company.scoped(:where => { :name => "Ain't noth'n like' \#stuff" }).first
end end
def test_hash_condition_find_with_array def test_hash_condition_find_with_array
p1, p2 = Post.scoped(:limit => 2, :order => 'id asc').all p1, p2 = Post.scoped(:limit => 2, :order => 'id asc').all
assert_equal [p1, p2], Post.scoped(:conditions => { :id => [p1, p2] }, :order => 'id asc').all assert_equal [p1, p2], Post.scoped(:where => { :id => [p1, p2] }, :order => 'id asc').all
assert_equal [p1, p2], Post.scoped(:conditions => { :id => [p1, p2.id] }, :order => 'id asc').all assert_equal [p1, p2], Post.scoped(:where => { :id => [p1, p2.id] }, :order => 'id asc').all
end end
def test_hash_condition_find_with_nil def test_hash_condition_find_with_nil
topic = Topic.scoped(:conditions => { :last_read => nil } ).first topic = Topic.scoped(:where => { :last_read => nil } ).first
assert_not_nil topic assert_not_nil topic
assert_nil topic.last_read assert_nil topic.last_read
end end
...@@ -353,42 +353,42 @@ def test_hash_condition_find_with_nil ...@@ -353,42 +353,42 @@ def test_hash_condition_find_with_nil
def test_hash_condition_find_with_aggregate_having_one_mapping def test_hash_condition_find_with_aggregate_having_one_mapping
balance = customers(:david).balance balance = customers(:david).balance
assert_kind_of Money, balance assert_kind_of Money, balance
found_customer = Customer.scoped(:conditions => {:balance => balance}).first found_customer = Customer.scoped(:where => {:balance => balance}).first
assert_equal customers(:david), found_customer assert_equal customers(:david), found_customer
end end
def test_hash_condition_find_with_aggregate_attribute_having_same_name_as_field_and_key_value_being_aggregate def test_hash_condition_find_with_aggregate_attribute_having_same_name_as_field_and_key_value_being_aggregate
gps_location = customers(:david).gps_location gps_location = customers(:david).gps_location
assert_kind_of GpsLocation, gps_location assert_kind_of GpsLocation, gps_location
found_customer = Customer.scoped(:conditions => {:gps_location => gps_location}).first found_customer = Customer.scoped(:where => {:gps_location => gps_location}).first
assert_equal customers(:david), found_customer assert_equal customers(:david), found_customer
end end
def test_hash_condition_find_with_aggregate_having_one_mapping_and_key_value_being_attribute_value def test_hash_condition_find_with_aggregate_having_one_mapping_and_key_value_being_attribute_value
balance = customers(:david).balance balance = customers(:david).balance
assert_kind_of Money, balance assert_kind_of Money, balance
found_customer = Customer.scoped(:conditions => {:balance => balance.amount}).first found_customer = Customer.scoped(:where => {:balance => balance.amount}).first
assert_equal customers(:david), found_customer assert_equal customers(:david), found_customer
end end
def test_hash_condition_find_with_aggregate_attribute_having_same_name_as_field_and_key_value_being_attribute_value def test_hash_condition_find_with_aggregate_attribute_having_same_name_as_field_and_key_value_being_attribute_value
gps_location = customers(:david).gps_location gps_location = customers(:david).gps_location
assert_kind_of GpsLocation, gps_location assert_kind_of GpsLocation, gps_location
found_customer = Customer.scoped(:conditions => {:gps_location => gps_location.gps_location}).first found_customer = Customer.scoped(:where => {:gps_location => gps_location.gps_location}).first
assert_equal customers(:david), found_customer assert_equal customers(:david), found_customer
end end
def test_hash_condition_find_with_aggregate_having_three_mappings def test_hash_condition_find_with_aggregate_having_three_mappings
address = customers(:david).address address = customers(:david).address
assert_kind_of Address, address assert_kind_of Address, address
found_customer = Customer.scoped(:conditions => {:address => address}).first found_customer = Customer.scoped(:where => {:address => address}).first
assert_equal customers(:david), found_customer assert_equal customers(:david), found_customer
end end
def test_hash_condition_find_with_one_condition_being_aggregate_and_another_not def test_hash_condition_find_with_one_condition_being_aggregate_and_another_not
address = customers(:david).address address = customers(:david).address
assert_kind_of Address, address assert_kind_of Address, address
found_customer = Customer.scoped(:conditions => {:address => address, :name => customers(:david).name}).first found_customer = Customer.scoped(:where => {:address => address, :name => customers(:david).name}).first
assert_equal customers(:david), found_customer assert_equal customers(:david), found_customer
end end
...@@ -396,7 +396,7 @@ def test_condition_utc_time_interpolation_with_default_timezone_local ...@@ -396,7 +396,7 @@ def test_condition_utc_time_interpolation_with_default_timezone_local
with_env_tz 'America/New_York' do with_env_tz 'America/New_York' do
with_active_record_default_timezone :local do with_active_record_default_timezone :local do
topic = Topic.first topic = Topic.first
assert_equal topic, Topic.scoped(:conditions => ['written_on = ?', topic.written_on.getutc]).first assert_equal topic, Topic.scoped(:where => ['written_on = ?', topic.written_on.getutc]).first
end end
end end
end end
...@@ -405,7 +405,7 @@ def test_hash_condition_utc_time_interpolation_with_default_timezone_local ...@@ -405,7 +405,7 @@ def test_hash_condition_utc_time_interpolation_with_default_timezone_local
with_env_tz 'America/New_York' do with_env_tz 'America/New_York' do
with_active_record_default_timezone :local do with_active_record_default_timezone :local do
topic = Topic.first topic = Topic.first
assert_equal topic, Topic.scoped(:conditions => {:written_on => topic.written_on.getutc}).first assert_equal topic, Topic.scoped(:where => {:written_on => topic.written_on.getutc}).first
end end
end end
end end
...@@ -414,7 +414,7 @@ def test_condition_local_time_interpolation_with_default_timezone_utc ...@@ -414,7 +414,7 @@ def test_condition_local_time_interpolation_with_default_timezone_utc
with_env_tz 'America/New_York' do with_env_tz 'America/New_York' do
with_active_record_default_timezone :utc do with_active_record_default_timezone :utc do
topic = Topic.first topic = Topic.first
assert_equal topic, Topic.scoped(:conditions => ['written_on = ?', topic.written_on.getlocal]).first assert_equal topic, Topic.scoped(:where => ['written_on = ?', topic.written_on.getlocal]).first
end end
end end
end end
...@@ -423,32 +423,32 @@ def test_hash_condition_local_time_interpolation_with_default_timezone_utc ...@@ -423,32 +423,32 @@ def test_hash_condition_local_time_interpolation_with_default_timezone_utc
with_env_tz 'America/New_York' do with_env_tz 'America/New_York' do
with_active_record_default_timezone :utc do with_active_record_default_timezone :utc do
topic = Topic.first topic = Topic.first
assert_equal topic, Topic.scoped(:conditions => {:written_on => topic.written_on.getlocal}).first assert_equal topic, Topic.scoped(:where => {:written_on => topic.written_on.getlocal}).first
end end
end end
end end
def test_bind_variables def test_bind_variables
assert_kind_of Firm, Company.scoped(:conditions => ["name = ?", "37signals"]).first assert_kind_of Firm, Company.scoped(:where => ["name = ?", "37signals"]).first
assert_nil Company.scoped(:conditions => ["name = ?", "37signals!"]).first assert_nil Company.scoped(:where => ["name = ?", "37signals!"]).first
assert_nil Company.scoped(:conditions => ["name = ?", "37signals!' OR 1=1"]).first assert_nil Company.scoped(:where => ["name = ?", "37signals!' OR 1=1"]).first
assert_kind_of Time, Topic.scoped(:conditions => ["id = ?", 1]).first.written_on assert_kind_of Time, Topic.scoped(:where => ["id = ?", 1]).first.written_on
assert_raise(ActiveRecord::PreparedStatementInvalid) { assert_raise(ActiveRecord::PreparedStatementInvalid) {
Company.scoped(:conditions => ["id=? AND name = ?", 2]).first Company.scoped(:where => ["id=? AND name = ?", 2]).first
} }
assert_raise(ActiveRecord::PreparedStatementInvalid) { assert_raise(ActiveRecord::PreparedStatementInvalid) {
Company.scoped(:conditions => ["id=?", 2, 3, 4]).first Company.scoped(:where => ["id=?", 2, 3, 4]).first
} }
end end
def test_bind_variables_with_quotes def test_bind_variables_with_quotes
Company.create("name" => "37signals' go'es agains") Company.create("name" => "37signals' go'es agains")
assert Company.scoped(:conditions => ["name = ?", "37signals' go'es agains"]).first assert Company.scoped(:where => ["name = ?", "37signals' go'es agains"]).first
end end
def test_named_bind_variables_with_quotes def test_named_bind_variables_with_quotes
Company.create("name" => "37signals' go'es agains") Company.create("name" => "37signals' go'es agains")
assert Company.scoped(:conditions => ["name = :name", {:name => "37signals' go'es agains"}]).first assert Company.scoped(:where => ["name = :name", {:name => "37signals' go'es agains"}]).first
end end
def test_bind_arity def test_bind_arity
...@@ -466,10 +466,10 @@ def test_named_bind_variables ...@@ -466,10 +466,10 @@ def test_named_bind_variables
assert_nothing_raised { bind("'+00:00'", :foo => "bar") } assert_nothing_raised { bind("'+00:00'", :foo => "bar") }
assert_kind_of Firm, Company.scoped(:conditions => ["name = :name", { :name => "37signals" }]).first assert_kind_of Firm, Company.scoped(:where => ["name = :name", { :name => "37signals" }]).first
assert_nil Company.scoped(:conditions => ["name = :name", { :name => "37signals!" }]).first assert_nil Company.scoped(:where => ["name = :name", { :name => "37signals!" }]).first
assert_nil Company.scoped(:conditions => ["name = :name", { :name => "37signals!' OR 1=1" }]).first assert_nil Company.scoped(:where => ["name = :name", { :name => "37signals!' OR 1=1" }]).first
assert_kind_of Time, Topic.scoped(:conditions => ["id = :id", { :id => 1 }]).first.written_on assert_kind_of Time, Topic.scoped(:where => ["id = :id", { :id => 1 }]).first.written_on
end end
class SimpleEnumerable class SimpleEnumerable
...@@ -1035,8 +1035,8 @@ def test_find_by_empty_in_condition ...@@ -1035,8 +1035,8 @@ def test_find_by_empty_in_condition
def test_find_by_records def test_find_by_records
p1, p2 = Post.scoped(:limit => 2, :order => 'id asc').all p1, p2 = Post.scoped(:limit => 2, :order => 'id asc').all
assert_equal [p1, p2], Post.scoped(:conditions => ['id in (?)', [p1, p2]], :order => 'id asc') assert_equal [p1, p2], Post.scoped(:where => ['id in (?)', [p1, p2]], :order => 'id asc')
assert_equal [p1, p2], Post.scoped(:conditions => ['id in (?)', [p1, p2.id]], :order => 'id asc') assert_equal [p1, p2], Post.scoped(:where => ['id in (?)', [p1, p2.id]], :order => 'id asc')
end end
def test_select_value def test_select_value
...@@ -1063,7 +1063,7 @@ def test_select_rows ...@@ -1063,7 +1063,7 @@ def test_select_rows
end end
def test_find_with_order_on_included_associations_with_construct_finder_sql_for_association_limiting_and_is_distinct def test_find_with_order_on_included_associations_with_construct_finder_sql_for_association_limiting_and_is_distinct
assert_equal 2, Post.scoped(:include => { :authors => :author_address }, :order => 'author_addresses.id DESC ', :limit => 2).all.size 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(:include => { :author => :author_address, :authors => :author_address},
:order => 'author_addresses_authors.id DESC ', :limit => 3).all.size :order => 'author_addresses_authors.id DESC ', :limit => 3).all.size
......
...@@ -173,9 +173,9 @@ def test_alt_destroy_all_within_inheritance ...@@ -173,9 +173,9 @@ def test_alt_destroy_all_within_inheritance
end end
def test_find_first_within_inheritance def test_find_first_within_inheritance
assert_kind_of Firm, Company.scoped(:conditions => "name = '37signals'").first assert_kind_of Firm, Company.scoped(:where => "name = '37signals'").first
assert_kind_of Firm, Firm.scoped(:conditions => "name = '37signals'").first assert_kind_of Firm, Firm.scoped(:where => "name = '37signals'").first
assert_nil Client.scoped(:conditions => "name = '37signals'").first assert_nil Client.scoped(:where => "name = '37signals'").first
end end
def test_alt_find_first_within_inheritance def test_alt_find_first_within_inheritance
...@@ -187,10 +187,10 @@ def test_alt_find_first_within_inheritance ...@@ -187,10 +187,10 @@ def test_alt_find_first_within_inheritance
def test_complex_inheritance def test_complex_inheritance
very_special_client = VerySpecialClient.create("name" => "veryspecial") very_special_client = VerySpecialClient.create("name" => "veryspecial")
assert_equal very_special_client, VerySpecialClient.where("name = 'veryspecial'").first assert_equal very_special_client, VerySpecialClient.where("name = 'veryspecial'").first
assert_equal very_special_client, SpecialClient.scoped(:conditions => "name = 'veryspecial'").first assert_equal very_special_client, SpecialClient.scoped(:where => "name = 'veryspecial'").first
assert_equal very_special_client, Company.scoped(:conditions => "name = 'veryspecial'").first assert_equal very_special_client, Company.scoped(:where => "name = 'veryspecial'").first
assert_equal very_special_client, Client.scoped(:conditions => "name = 'veryspecial'").first assert_equal very_special_client, Client.scoped(:where => "name = 'veryspecial'").first
assert_equal 1, Client.scoped(:conditions => "name = 'Summit'").all.size assert_equal 1, Client.scoped(:where => "name = 'Summit'").all.size
assert_equal very_special_client, Client.find(very_special_client.id) assert_equal very_special_client, Client.find(very_special_client.id)
end end
......
...@@ -58,9 +58,9 @@ def test_respond_to_respects_include_private_parameter ...@@ -58,9 +58,9 @@ def test_respond_to_respects_include_private_parameter
end end
def test_scopes_with_options_limit_finds_to_those_matching_the_criteria_specified def test_scopes_with_options_limit_finds_to_those_matching_the_criteria_specified
assert !Topic.scoped(:conditions => {:approved => true}).all.empty? assert !Topic.scoped(:where => {:approved => true}).all.empty?
assert_equal Topic.scoped(:conditions => {:approved => true}).all, Topic.approved assert_equal Topic.scoped(:where => {:approved => true}).all, Topic.approved
assert_equal Topic.where(:approved => true).count, Topic.approved.count assert_equal Topic.where(:approved => true).count, Topic.approved.count
end end
...@@ -71,8 +71,8 @@ def test_scopes_with_string_name_can_be_composed ...@@ -71,8 +71,8 @@ def test_scopes_with_string_name_can_be_composed
end end
def test_scopes_are_composable def test_scopes_are_composable
assert_equal((approved = Topic.scoped(:conditions => {:approved => true}).all), Topic.approved) assert_equal((approved = Topic.scoped(:where => {:approved => true}).all), Topic.approved)
assert_equal((replied = Topic.scoped(:conditions => 'replies_count > 0').all), Topic.replied) assert_equal((replied = Topic.scoped(:where => 'replies_count > 0').all), Topic.replied)
assert !(approved == replied) assert !(approved == replied)
assert !(approved & replied).empty? assert !(approved & replied).empty?
...@@ -464,7 +464,7 @@ def self.name; "Post"; end ...@@ -464,7 +464,7 @@ def self.name; "Post"; end
def test_dynamic_scope def test_dynamic_scope
assert_equal @test_klass.scoped_by_author_id(1).find(1), @test_klass.find(1) assert_equal @test_klass.scoped_by_author_id(1).find(1), @test_klass.find(1)
assert_equal @test_klass.scoped_by_author_id_and_title(1, "Welcome to the weblog").first, @test_klass.scoped(:conditions => { :author_id => 1, :title => "Welcome to the weblog"}).first assert_equal @test_klass.scoped_by_author_id_and_title(1, "Welcome to the weblog").first, @test_klass.scoped(:where => { :author_id => 1, :title => "Welcome to the weblog"}).first
end end
def test_dynamic_scope_should_create_methods_after_hitting_method_missing def test_dynamic_scope_should_create_methods_after_hitting_method_missing
......
...@@ -282,7 +282,7 @@ def test_find_all_with_join ...@@ -282,7 +282,7 @@ def test_find_all_with_join
end end
def test_find_on_hash_conditions def test_find_on_hash_conditions
assert_equal Topic.scoped(:conditions => {:approved => false}).all, Topic.where({ :approved => false }).to_a assert_equal Topic.scoped(:where => {:approved => false}).all, Topic.where({ :approved => false }).to_a
end end
def test_joins_with_string_array def test_joins_with_string_array
......
...@@ -19,7 +19,7 @@ def self.what_are_you ...@@ -19,7 +19,7 @@ def self.what_are_you
end end
def self.search_by_type(q) def self.search_by_type(q)
self.scoped(:conditions => ["#{QUOTED_TYPE} = ?", q]).all self.scoped(:where => ["#{QUOTED_TYPE} = ?", q]).all
end end
def self.all_as_method def self.all_as_method
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册