提交 dae61089 编写于 作者: J Jeremy Kemper

Update tests' use of fixtures for the new collections api. Closes #8726.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7081 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 989332c7
*SVN*
* Update tests' use of fixtures for the new collections api. #8726 [kamal]
* Save associated records only if the association is already loaded. #8713 [blaine]
* MySQL: fix show_variable. #8448 [matt, Jeremy Kemper]
......
......@@ -55,7 +55,7 @@ def test_eager_association_loading_with_cascaded_two_levels_with_condition
def test_eager_association_loading_with_acts_as_tree
roots = TreeMixin.find(:all, :include=>"children", :conditions=>"mixins.parent_id IS NULL", :order=>"mixins.id")
assert_equal [mixins(:tree_1), mixins(:tree2_1), mixins(:tree3_1)], roots
assert_equal mixins(:tree_1, :tree2_1, :tree3_1), roots
assert_no_queries do
assert_equal 2, roots[0].children.size
assert_equal 0, roots[1].children.size
......@@ -73,7 +73,7 @@ def test_eager_association_loading_with_cascaded_three_levels_by_ping_pong
def test_eager_association_loading_with_has_many_sti
topics = Topic.find(:all, :include => :replies, :order => 'topics.id')
assert_equal [topics(:first), topics(:second)], topics
assert_equal topics(:first, :second), topics
assert_no_queries do
assert_equal 1, topics[0].replies.size
assert_equal 0, topics[1].replies.size
......
......@@ -292,13 +292,13 @@ def find_all_ordered(className, include=nil)
end
def test_limited_eager_with_order
assert_equal [posts(:thinking), posts(:sti_comments)], Post.find(:all, :include => [:author, :comments], :conditions => "authors.name = 'David'", :order => 'UPPER(posts.title)', :limit => 2, :offset => 1)
assert_equal [posts(:sti_post_and_comments), posts(:sti_comments)], Post.find(:all, :include => [:author, :comments], :conditions => "authors.name = 'David'", :order => 'UPPER(posts.title) DESC', :limit => 2, :offset => 1)
assert_equal posts(:thinking, :sti_comments), Post.find(:all, :include => [:author, :comments], :conditions => "authors.name = 'David'", :order => 'UPPER(posts.title)', :limit => 2, :offset => 1)
assert_equal posts(:sti_post_and_comments, :sti_comments), Post.find(:all, :include => [:author, :comments], :conditions => "authors.name = 'David'", :order => 'UPPER(posts.title) DESC', :limit => 2, :offset => 1)
end
def test_limited_eager_with_multiple_order_columns
assert_equal [posts(:thinking), posts(:sti_comments)], Post.find(:all, :include => [:author, :comments], :conditions => "authors.name = 'David'", :order => 'UPPER(posts.title), posts.id', :limit => 2, :offset => 1)
assert_equal [posts(:sti_post_and_comments), posts(:sti_comments)], Post.find(:all, :include => [:author, :comments], :conditions => "authors.name = 'David'", :order => 'UPPER(posts.title) DESC, posts.id', :limit => 2, :offset => 1)
assert_equal posts(:thinking, :sti_comments), Post.find(:all, :include => [:author, :comments], :conditions => "authors.name = 'David'", :order => 'UPPER(posts.title), posts.id', :limit => 2, :offset => 1)
assert_equal posts(:sti_post_and_comments, :sti_comments), Post.find(:all, :include => [:author, :comments], :conditions => "authors.name = 'David'", :order => 'UPPER(posts.title) DESC, posts.id', :limit => 2, :offset => 1)
end
def test_eager_with_multiple_associations_with_same_table_has_many_and_habtm
......
......@@ -294,20 +294,20 @@ def test_has_many_through_join_model_with_conditions
def test_has_many_polymorphic
assert_raises ActiveRecord::HasManyThroughAssociationPolymorphicError do
assert_equal [posts(:welcome), posts(:thinking)], tags(:general).taggables
assert_equal posts(:welcome, :thinking), tags(:general).taggables
end
assert_raises ActiveRecord::EagerLoadPolymorphicError do
assert_equal [posts(:welcome), posts(:thinking)], tags(:general).taggings.find(:all, :include => :taggable)
assert_equal posts(:welcome, :thinking), tags(:general).taggings.find(:all, :include => :taggable)
end
end
def test_has_many_polymorphic_with_source_type
assert_equal [posts(:welcome), posts(:thinking)], tags(:general).tagged_posts
assert_equal posts(:welcome, :thinking), tags(:general).tagged_posts
end
def test_eager_has_many_polymorphic_with_source_type
tag_with_include = Tag.find(tags(:general).id, :include => :tagged_posts)
desired = [posts(:welcome), posts(:thinking)]
desired = posts(:welcome, :thinking)
assert_no_queries do
assert_equal desired, tag_with_include.tagged_posts
end
......@@ -339,12 +339,12 @@ def test_has_many_through_polymorphic_has_one
end
def test_has_many_through_polymorphic_has_many
assert_equal [taggings(:welcome_general), taggings(:thinking_general)], authors(:david).taggings.uniq.sort_by { |t| t.id }
assert_equal taggings(:welcome_general, :thinking_general), authors(:david).taggings.uniq.sort_by { |t| t.id }
end
def test_include_has_many_through_polymorphic_has_many
author = Author.find_by_id(authors(:david).id, :include => :taggings)
expected_taggings = [taggings(:welcome_general), taggings(:thinking_general)]
expected_taggings = taggings(:welcome_general, :thinking_general)
assert_no_queries do
assert_equal expected_taggings, author.taggings.uniq.sort_by { |t| t.id }
end
......
......@@ -950,7 +950,7 @@ def test_depends_and_nullify
core = companies(:rails_core)
assert_equal accounts(:rails_core_account), core.account
assert_equal [companies(:leetsoft), companies(:jadedpixel)], core.companies
assert_equal companies(:leetsoft, :jadedpixel), core.companies
core.destroy
assert_nil accounts(:rails_core_account).reload.firm_id
assert_nil companies(:leetsoft).reload.client_of
......@@ -984,8 +984,7 @@ def test_replace_with_less
def test_replace_with_new
firm = Firm.find(:first)
new_client = Client.new("name" => "New Client")
firm.clients = [companies(:second_client),new_client]
firm.clients = [companies(:second_client), Client.new("name" => "New Client")]
firm.save
firm.reload
assert_equal 2, firm.clients.length
......@@ -1509,8 +1508,8 @@ def test_habtm_saving_multiple_relationships
end
def test_habtm_unique_order_preserved
assert_equal [developers(:poor_jamis), developers(:jamis), developers(:david)], projects(:active_record).non_unique_developers
assert_equal [developers(:poor_jamis), developers(:jamis), developers(:david)], projects(:active_record).developers
assert_equal developers(:poor_jamis, :jamis, :david), projects(:active_record).non_unique_developers
assert_equal developers(:poor_jamis, :jamis, :david), projects(:active_record).developers
end
def test_build
......@@ -1791,13 +1790,13 @@ def test_join_with_group
end
def test_get_ids
assert_equal [projects(:active_record).id, projects(:action_controller).id], developers(:david).project_ids
assert_equal projects(:active_record, :action_controller).map(&:id), developers(:david).project_ids
assert_equal [projects(:active_record).id], developers(:jamis).project_ids
end
def test_assign_ids
developer = Developer.new("name" => "Joe")
developer.project_ids = [projects(:active_record).id, projects(:action_controller).id]
developer.project_ids = projects(:active_record, :action_controller).map(&:id)
developer.save
developer.reload
assert_equal 2, developer.projects.length
......
......@@ -25,76 +25,49 @@ class ListTest < Test::Unit::TestCase
fixtures :mixins
def test_reordering
assert_equal [mixins(:list_1),
mixins(:list_2),
mixins(:list_3),
mixins(:list_4)],
assert_equal mixins(:list_1, :list_2, :list_3, :list_4),
ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
mixins(:list_2).move_lower
assert_equal [mixins(:list_1),
mixins(:list_3),
mixins(:list_2),
mixins(:list_4)],
assert_equal mixins(:list_1, :list_3, :list_2, :list_4),
ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
mixins(:list_2).move_higher
assert_equal [mixins(:list_1),
mixins(:list_2),
mixins(:list_3),
mixins(:list_4)],
assert_equal mixins(:list_1, :list_2, :list_3, :list_4),
ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
mixins(:list_1).move_to_bottom
assert_equal [mixins(:list_2),
mixins(:list_3),
mixins(:list_4),
mixins(:list_1)],
assert_equal mixins(:list_2, :list_3, :list_4, :list_1),
ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
mixins(:list_1).move_to_top
assert_equal [mixins(:list_1),
mixins(:list_2),
mixins(:list_3),
mixins(:list_4)],
assert_equal mixins(:list_1, :list_2, :list_3, :list_4),
ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
mixins(:list_2).move_to_bottom
assert_equal [mixins(:list_1),
mixins(:list_3),
mixins(:list_4),
mixins(:list_2)],
assert_equal mixins(:list_1, :list_3, :list_4, :list_2),
ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
mixins(:list_4).move_to_top
assert_equal [mixins(:list_4),
mixins(:list_1),
mixins(:list_3),
mixins(:list_2)],
assert_equal mixins(:list_4, :list_1, :list_3, :list_2),
ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
end
def test_move_to_bottom_with_next_to_last_item
assert_equal [mixins(:list_1),
mixins(:list_2),
mixins(:list_3),
mixins(:list_4)],
assert_equal mixins(:list_1, :list_2, :list_3, :list_4),
ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
mixins(:list_3).move_to_bottom
assert_equal [mixins(:list_1),
mixins(:list_2),
mixins(:list_4),
mixins(:list_3)],
assert_equal mixins(:list_1, :list_2, :list_4, :list_3),
ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
end
......@@ -170,17 +143,12 @@ def test_insert_at
end
def test_delete_middle
assert_equal [mixins(:list_1),
mixins(:list_2),
mixins(:list_3),
mixins(:list_4)],
assert_equal mixins(:list_1, :list_2, :list_3, :list_4),
ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
mixins(:list_2).destroy
assert_equal [mixins(:list_1, :reload),
mixins(:list_3, :reload),
mixins(:list_4, :reload)],
assert_equal mixins(:list_1, :list_3, :list_4, :reload),
ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
assert_equal 1, mixins(:list_1).pos
......@@ -189,8 +157,7 @@ def test_delete_middle
mixins(:list_1).destroy
assert_equal [mixins(:list_3, :reload),
mixins(:list_4, :reload)],
assert_equal mixins(:list_3, :list_4, :reload),
ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
assert_equal 1, mixins(:list_3).pos
......@@ -226,7 +193,7 @@ def test_has_child
end
def test_children
assert_equal mixins(:tree_1).children, [mixins(:tree_2), mixins(:tree_4)]
assert_equal mixins(:tree_1).children, mixins(:tree_2, :tree_4)
assert_equal mixins(:tree_2).children, [mixins(:tree_3)]
assert_equal mixins(:tree_3).children, []
assert_equal mixins(:tree_4).children, []
......@@ -272,7 +239,7 @@ def test_insert
def test_ancestors
assert_equal [], mixins(:tree_1).ancestors
assert_equal [mixins(:tree_1)], mixins(:tree_2).ancestors
assert_equal [mixins(:tree_2), mixins(:tree_1)], mixins(:tree_3).ancestors
assert_equal mixins(:tree_2, :tree_1), mixins(:tree_3).ancestors
assert_equal [mixins(:tree_1)], mixins(:tree_4).ancestors
assert_equal [], mixins(:tree2_1).ancestors
assert_equal [], mixins(:tree3_1).ancestors
......@@ -289,25 +256,25 @@ def test_root
end
def test_roots
assert_equal [mixins(:tree_1), mixins(:tree2_1), mixins(:tree3_1)], TreeMixin.roots
assert_equal mixins(:tree_1, :tree2_1, :tree3_1), TreeMixin.roots
end
def test_siblings
assert_equal [mixins(:tree2_1), mixins(:tree3_1)], mixins(:tree_1).siblings
assert_equal mixins(:tree2_1, :tree3_1), mixins(:tree_1).siblings
assert_equal [mixins(:tree_4)], mixins(:tree_2).siblings
assert_equal [], mixins(:tree_3).siblings
assert_equal [mixins(:tree_2)], mixins(:tree_4).siblings
assert_equal [mixins(:tree_1), mixins(:tree3_1)], mixins(:tree2_1).siblings
assert_equal [mixins(:tree_1), mixins(:tree2_1)], mixins(:tree3_1).siblings
assert_equal mixins(:tree_1, :tree3_1), mixins(:tree2_1).siblings
assert_equal mixins(:tree_1, :tree2_1), mixins(:tree3_1).siblings
end
def test_self_and_siblings
assert_equal [mixins(:tree_1), mixins(:tree2_1), mixins(:tree3_1)], mixins(:tree_1).self_and_siblings
assert_equal [mixins(:tree_2), mixins(:tree_4)], mixins(:tree_2).self_and_siblings
assert_equal mixins(:tree_1, :tree2_1, :tree3_1), mixins(:tree_1).self_and_siblings
assert_equal mixins(:tree_2, :tree_4), mixins(:tree_2).self_and_siblings
assert_equal [mixins(:tree_3)], mixins(:tree_3).self_and_siblings
assert_equal [mixins(:tree_2), mixins(:tree_4)], mixins(:tree_4).self_and_siblings
assert_equal [mixins(:tree_1), mixins(:tree2_1), mixins(:tree3_1)], mixins(:tree2_1).self_and_siblings
assert_equal [mixins(:tree_1), mixins(:tree2_1), mixins(:tree3_1)], mixins(:tree3_1).self_and_siblings
assert_equal mixins(:tree_2, :tree_4), mixins(:tree_4).self_and_siblings
assert_equal mixins(:tree_1, :tree2_1, :tree3_1), mixins(:tree2_1).self_and_siblings
assert_equal mixins(:tree_1, :tree2_1, :tree3_1), mixins(:tree3_1).self_and_siblings
end
end
......@@ -315,11 +282,11 @@ class TreeTestWithoutOrder < Test::Unit::TestCase
fixtures :mixins
def test_root
assert [mixins(:tree_without_order_1), mixins(:tree_without_order_2)].include?(TreeMixinWithoutOrder.root)
assert mixins(:tree_without_order_1, :tree_without_order_2).include?(TreeMixinWithoutOrder.root)
end
def test_roots
assert_equal [], [mixins(:tree_without_order_1), mixins(:tree_without_order_2)] - TreeMixinWithoutOrder.roots
assert_equal [], mixins(:tree_without_order_1, :tree_without_order_2) - TreeMixinWithoutOrder.roots
end
end
......@@ -394,76 +361,49 @@ class ListSubTest < Test::Unit::TestCase
fixtures :mixins
def test_reordering
assert_equal [mixins(:list_sub_1),
mixins(:list_sub_2),
mixins(:list_sub_3),
mixins(:list_sub_4)],
assert_equal mixins(:list_sub_1, :list_sub_2, :list_sub_3, :list_sub_4),
ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos')
mixins(:list_sub_2).move_lower
assert_equal [mixins(:list_sub_1),
mixins(:list_sub_3),
mixins(:list_sub_2),
mixins(:list_sub_4)],
assert_equal mixins(:list_sub_1, :list_sub_3, :list_sub_2, :list_sub_4),
ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos')
mixins(:list_sub_2).move_higher
assert_equal [mixins(:list_sub_1),
mixins(:list_sub_2),
mixins(:list_sub_3),
mixins(:list_sub_4)],
assert_equal mixins(:list_sub_1, :list_sub_2, :list_sub_3, :list_sub_4),
ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos')
mixins(:list_sub_1).move_to_bottom
assert_equal [mixins(:list_sub_2),
mixins(:list_sub_3),
mixins(:list_sub_4),
mixins(:list_sub_1)],
assert_equal mixins(:list_sub_2, :list_sub_3, :list_sub_4, :list_sub_1),
ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos')
mixins(:list_sub_1).move_to_top
assert_equal [mixins(:list_sub_1),
mixins(:list_sub_2),
mixins(:list_sub_3),
mixins(:list_sub_4)],
assert_equal mixins(:list_sub_1, :list_sub_2, :list_sub_3, :list_sub_4),
ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos')
mixins(:list_sub_2).move_to_bottom
assert_equal [mixins(:list_sub_1),
mixins(:list_sub_3),
mixins(:list_sub_4),
mixins(:list_sub_2)],
assert_equal mixins(:list_sub_1, :list_sub_3, :list_sub_4, :list_sub_2),
ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos')
mixins(:list_sub_4).move_to_top
assert_equal [mixins(:list_sub_4),
mixins(:list_sub_1),
mixins(:list_sub_3),
mixins(:list_sub_2)],
assert_equal mixins(:list_sub_4, :list_sub_1, :list_sub_3, :list_sub_2),
ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos')
end
def test_move_to_bottom_with_next_to_last_item
assert_equal [mixins(:list_sub_1),
mixins(:list_sub_2),
mixins(:list_sub_3),
mixins(:list_sub_4)],
assert_equal mixins(:list_sub_1, :list_sub_2, :list_sub_3, :list_sub_4),
ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos')
mixins(:list_sub_3).move_to_bottom
assert_equal [mixins(:list_sub_1),
mixins(:list_sub_2),
mixins(:list_sub_4),
mixins(:list_sub_3)],
assert_equal mixins(:list_sub_1, :list_sub_2, :list_sub_4, :list_sub_3),
ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos')
end
......@@ -518,17 +458,12 @@ def test_insert_at
end
def test_delete_middle
assert_equal [mixins(:list_sub_1),
mixins(:list_sub_2),
mixins(:list_sub_3),
mixins(:list_sub_4)],
assert_equal mixins(:list_sub_1, :list_sub_2, :list_sub_3, :list_sub_4),
ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos')
mixins(:list_sub_2).destroy
assert_equal [mixins(:list_sub_1, :reload),
mixins(:list_sub_3, :reload),
mixins(:list_sub_4, :reload)],
assert_equal mixins(:list_sub_1, :list_sub_3, :list_sub_4, :reload),
ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos')
assert_equal 1, mixins(:list_sub_1).pos
......@@ -537,8 +472,7 @@ def test_delete_middle
mixins(:list_sub_1).destroy
assert_equal [mixins(:list_sub_3, :reload),
mixins(:list_sub_4, :reload)],
assert_equal mixins(:list_sub_3, :list_sub_4, :reload),
ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos')
assert_equal 1, mixins(:list_sub_3).pos
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册