1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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
This commit is contained in:
Jeremy Kemper 2007-06-22 17:36:20 +00:00
parent 989332c734
commit dae6108998
6 changed files with 57 additions and 122 deletions

View file

@ -1,5 +1,7 @@
*SVN* *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] * Save associated records only if the association is already loaded. #8713 [blaine]
* MySQL: fix show_variable. #8448 [matt, Jeremy Kemper] * MySQL: fix show_variable. #8448 [matt, Jeremy Kemper]

View file

@ -55,7 +55,7 @@ class CascadedEagerLoadingTest < Test::Unit::TestCase
def test_eager_association_loading_with_acts_as_tree def test_eager_association_loading_with_acts_as_tree
roots = TreeMixin.find(:all, :include=>"children", :conditions=>"mixins.parent_id IS NULL", :order=>"mixins.id") 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_no_queries do
assert_equal 2, roots[0].children.size assert_equal 2, roots[0].children.size
assert_equal 0, roots[1].children.size assert_equal 0, roots[1].children.size
@ -73,7 +73,7 @@ class CascadedEagerLoadingTest < Test::Unit::TestCase
def test_eager_association_loading_with_has_many_sti def test_eager_association_loading_with_has_many_sti
topics = Topic.find(:all, :include => :replies, :order => 'topics.id') 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_no_queries do
assert_equal 1, topics[0].replies.size assert_equal 1, topics[0].replies.size
assert_equal 0, topics[1].replies.size assert_equal 0, topics[1].replies.size

View file

@ -292,13 +292,13 @@ class EagerAssociationTest < Test::Unit::TestCase
end end
def test_limited_eager_with_order 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(: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), 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(: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 end
def test_limited_eager_with_multiple_order_columns 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(: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), 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(: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 end
def test_eager_with_multiple_associations_with_same_table_has_many_and_habtm def test_eager_with_multiple_associations_with_same_table_has_many_and_habtm

View file

@ -294,20 +294,20 @@ class AssociationsJoinModelTest < Test::Unit::TestCase
def test_has_many_polymorphic def test_has_many_polymorphic
assert_raises ActiveRecord::HasManyThroughAssociationPolymorphicError do assert_raises ActiveRecord::HasManyThroughAssociationPolymorphicError do
assert_equal [posts(:welcome), posts(:thinking)], tags(:general).taggables assert_equal posts(:welcome, :thinking), tags(:general).taggables
end end
assert_raises ActiveRecord::EagerLoadPolymorphicError do 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
end end
def test_has_many_polymorphic_with_source_type 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 end
def test_eager_has_many_polymorphic_with_source_type def test_eager_has_many_polymorphic_with_source_type
tag_with_include = Tag.find(tags(:general).id, :include => :tagged_posts) 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_no_queries do
assert_equal desired, tag_with_include.tagged_posts assert_equal desired, tag_with_include.tagged_posts
end end
@ -339,12 +339,12 @@ class AssociationsJoinModelTest < Test::Unit::TestCase
end end
def test_has_many_through_polymorphic_has_many 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 end
def test_include_has_many_through_polymorphic_has_many def test_include_has_many_through_polymorphic_has_many
author = Author.find_by_id(authors(:david).id, :include => :taggings) 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_no_queries do
assert_equal expected_taggings, author.taggings.uniq.sort_by { |t| t.id } assert_equal expected_taggings, author.taggings.uniq.sort_by { |t| t.id }
end end

View file

@ -950,7 +950,7 @@ class HasManyAssociationsTest < Test::Unit::TestCase
core = companies(:rails_core) core = companies(:rails_core)
assert_equal accounts(:rails_core_account), core.account 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 core.destroy
assert_nil accounts(:rails_core_account).reload.firm_id assert_nil accounts(:rails_core_account).reload.firm_id
assert_nil companies(:leetsoft).reload.client_of assert_nil companies(:leetsoft).reload.client_of
@ -984,8 +984,7 @@ class HasManyAssociationsTest < Test::Unit::TestCase
def test_replace_with_new def test_replace_with_new
firm = Firm.find(:first) firm = Firm.find(:first)
new_client = Client.new("name" => "New Client") firm.clients = [companies(:second_client), Client.new("name" => "New Client")]
firm.clients = [companies(:second_client),new_client]
firm.save firm.save
firm.reload firm.reload
assert_equal 2, firm.clients.length assert_equal 2, firm.clients.length
@ -1509,8 +1508,8 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase
end end
def test_habtm_unique_order_preserved 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, :jamis, :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).developers
end end
def test_build def test_build
@ -1791,13 +1790,13 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase
end end
def test_get_ids 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 assert_equal [projects(:active_record).id], developers(:jamis).project_ids
end end
def test_assign_ids def test_assign_ids
developer = Developer.new("name" => "Joe") 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.save
developer.reload developer.reload
assert_equal 2, developer.projects.length assert_equal 2, developer.projects.length

View file

@ -25,76 +25,49 @@ class ListTest < Test::Unit::TestCase
fixtures :mixins fixtures :mixins
def test_reordering def test_reordering
assert_equal [mixins(:list_1), assert_equal mixins(:list_1, :list_2, :list_3, :list_4),
mixins(:list_2),
mixins(:list_3),
mixins(:list_4)],
ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos') ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
mixins(:list_2).move_lower mixins(:list_2).move_lower
assert_equal [mixins(:list_1), assert_equal mixins(:list_1, :list_3, :list_2, :list_4),
mixins(:list_3),
mixins(:list_2),
mixins(:list_4)],
ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos') ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
mixins(:list_2).move_higher mixins(:list_2).move_higher
assert_equal [mixins(:list_1), assert_equal mixins(:list_1, :list_2, :list_3, :list_4),
mixins(:list_2),
mixins(:list_3),
mixins(:list_4)],
ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos') ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
mixins(:list_1).move_to_bottom mixins(:list_1).move_to_bottom
assert_equal [mixins(:list_2), assert_equal mixins(:list_2, :list_3, :list_4, :list_1),
mixins(:list_3),
mixins(:list_4),
mixins(:list_1)],
ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos') ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
mixins(:list_1).move_to_top mixins(:list_1).move_to_top
assert_equal [mixins(:list_1), assert_equal mixins(:list_1, :list_2, :list_3, :list_4),
mixins(:list_2),
mixins(:list_3),
mixins(:list_4)],
ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos') ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
mixins(:list_2).move_to_bottom mixins(:list_2).move_to_bottom
assert_equal [mixins(:list_1), assert_equal mixins(:list_1, :list_3, :list_4, :list_2),
mixins(:list_3),
mixins(:list_4),
mixins(:list_2)],
ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos') ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
mixins(:list_4).move_to_top mixins(:list_4).move_to_top
assert_equal [mixins(:list_4), assert_equal mixins(:list_4, :list_1, :list_3, :list_2),
mixins(:list_1),
mixins(:list_3),
mixins(:list_2)],
ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos') ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
end end
def test_move_to_bottom_with_next_to_last_item def test_move_to_bottom_with_next_to_last_item
assert_equal [mixins(:list_1), assert_equal mixins(:list_1, :list_2, :list_3, :list_4),
mixins(:list_2),
mixins(:list_3),
mixins(:list_4)],
ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos') ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
mixins(:list_3).move_to_bottom mixins(:list_3).move_to_bottom
assert_equal [mixins(:list_1), assert_equal mixins(:list_1, :list_2, :list_4, :list_3),
mixins(:list_2),
mixins(:list_4),
mixins(:list_3)],
ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos') ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
end end
@ -170,17 +143,12 @@ class ListTest < Test::Unit::TestCase
end end
def test_delete_middle def test_delete_middle
assert_equal [mixins(:list_1), assert_equal mixins(:list_1, :list_2, :list_3, :list_4),
mixins(:list_2),
mixins(:list_3),
mixins(:list_4)],
ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos') ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
mixins(:list_2).destroy mixins(:list_2).destroy
assert_equal [mixins(:list_1, :reload), assert_equal mixins(:list_1, :list_3, :list_4, :reload),
mixins(:list_3, :reload),
mixins(:list_4, :reload)],
ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos') ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
assert_equal 1, mixins(:list_1).pos assert_equal 1, mixins(:list_1).pos
@ -189,8 +157,7 @@ class ListTest < Test::Unit::TestCase
mixins(:list_1).destroy mixins(:list_1).destroy
assert_equal [mixins(:list_3, :reload), assert_equal mixins(:list_3, :list_4, :reload),
mixins(:list_4, :reload)],
ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos') ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos')
assert_equal 1, mixins(:list_3).pos assert_equal 1, mixins(:list_3).pos
@ -226,7 +193,7 @@ class TreeTest < Test::Unit::TestCase
end end
def test_children 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_2).children, [mixins(:tree_3)]
assert_equal mixins(:tree_3).children, [] assert_equal mixins(:tree_3).children, []
assert_equal mixins(:tree_4).children, [] assert_equal mixins(:tree_4).children, []
@ -272,7 +239,7 @@ class TreeTest < Test::Unit::TestCase
def test_ancestors def test_ancestors
assert_equal [], mixins(:tree_1).ancestors assert_equal [], mixins(:tree_1).ancestors
assert_equal [mixins(:tree_1)], mixins(:tree_2).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(:tree_1)], mixins(:tree_4).ancestors
assert_equal [], mixins(:tree2_1).ancestors assert_equal [], mixins(:tree2_1).ancestors
assert_equal [], mixins(:tree3_1).ancestors assert_equal [], mixins(:tree3_1).ancestors
@ -289,25 +256,25 @@ class TreeTest < Test::Unit::TestCase
end end
def test_roots 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 end
def test_siblings 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_4)], mixins(:tree_2).siblings
assert_equal [], mixins(:tree_3).siblings assert_equal [], mixins(:tree_3).siblings
assert_equal [mixins(:tree_2)], mixins(:tree_4).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, :tree3_1), mixins(:tree2_1).siblings
assert_equal [mixins(:tree_1), mixins(:tree2_1)], mixins(:tree3_1).siblings assert_equal mixins(:tree_1, :tree2_1), mixins(:tree3_1).siblings
end end
def test_self_and_siblings 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_1, :tree2_1, :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_2, :tree_4), mixins(:tree_2).self_and_siblings
assert_equal [mixins(:tree_3)], mixins(:tree_3).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_2, :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, :tree2_1, :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_1, :tree2_1, :tree3_1), mixins(:tree3_1).self_and_siblings
end end
end end
@ -315,11 +282,11 @@ class TreeTestWithoutOrder < Test::Unit::TestCase
fixtures :mixins fixtures :mixins
def test_root 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 end
def test_roots 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
end end
@ -394,76 +361,49 @@ class ListSubTest < Test::Unit::TestCase
fixtures :mixins fixtures :mixins
def test_reordering def test_reordering
assert_equal [mixins(:list_sub_1), assert_equal mixins(:list_sub_1, :list_sub_2, :list_sub_3, :list_sub_4),
mixins(:list_sub_2),
mixins(:list_sub_3),
mixins(:list_sub_4)],
ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos') ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos')
mixins(:list_sub_2).move_lower mixins(:list_sub_2).move_lower
assert_equal [mixins(:list_sub_1), assert_equal mixins(:list_sub_1, :list_sub_3, :list_sub_2, :list_sub_4),
mixins(:list_sub_3),
mixins(:list_sub_2),
mixins(:list_sub_4)],
ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos') ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos')
mixins(:list_sub_2).move_higher mixins(:list_sub_2).move_higher
assert_equal [mixins(:list_sub_1), assert_equal mixins(:list_sub_1, :list_sub_2, :list_sub_3, :list_sub_4),
mixins(:list_sub_2),
mixins(:list_sub_3),
mixins(:list_sub_4)],
ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos') ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos')
mixins(:list_sub_1).move_to_bottom mixins(:list_sub_1).move_to_bottom
assert_equal [mixins(:list_sub_2), assert_equal mixins(:list_sub_2, :list_sub_3, :list_sub_4, :list_sub_1),
mixins(:list_sub_3),
mixins(:list_sub_4),
mixins(:list_sub_1)],
ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos') ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos')
mixins(:list_sub_1).move_to_top mixins(:list_sub_1).move_to_top
assert_equal [mixins(:list_sub_1), assert_equal mixins(:list_sub_1, :list_sub_2, :list_sub_3, :list_sub_4),
mixins(:list_sub_2),
mixins(:list_sub_3),
mixins(:list_sub_4)],
ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos') ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos')
mixins(:list_sub_2).move_to_bottom mixins(:list_sub_2).move_to_bottom
assert_equal [mixins(:list_sub_1), assert_equal mixins(:list_sub_1, :list_sub_3, :list_sub_4, :list_sub_2),
mixins(:list_sub_3),
mixins(:list_sub_4),
mixins(:list_sub_2)],
ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos') ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos')
mixins(:list_sub_4).move_to_top mixins(:list_sub_4).move_to_top
assert_equal [mixins(:list_sub_4), assert_equal mixins(:list_sub_4, :list_sub_1, :list_sub_3, :list_sub_2),
mixins(:list_sub_1),
mixins(:list_sub_3),
mixins(:list_sub_2)],
ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos') ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos')
end end
def test_move_to_bottom_with_next_to_last_item def test_move_to_bottom_with_next_to_last_item
assert_equal [mixins(:list_sub_1), assert_equal mixins(:list_sub_1, :list_sub_2, :list_sub_3, :list_sub_4),
mixins(:list_sub_2),
mixins(:list_sub_3),
mixins(:list_sub_4)],
ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos') ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos')
mixins(:list_sub_3).move_to_bottom mixins(:list_sub_3).move_to_bottom
assert_equal [mixins(:list_sub_1), assert_equal mixins(:list_sub_1, :list_sub_2, :list_sub_4, :list_sub_3),
mixins(:list_sub_2),
mixins(:list_sub_4),
mixins(:list_sub_3)],
ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos') ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos')
end end
@ -518,17 +458,12 @@ class ListSubTest < Test::Unit::TestCase
end end
def test_delete_middle def test_delete_middle
assert_equal [mixins(:list_sub_1), assert_equal mixins(:list_sub_1, :list_sub_2, :list_sub_3, :list_sub_4),
mixins(:list_sub_2),
mixins(:list_sub_3),
mixins(:list_sub_4)],
ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos') ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos')
mixins(:list_sub_2).destroy mixins(:list_sub_2).destroy
assert_equal [mixins(:list_sub_1, :reload), assert_equal mixins(:list_sub_1, :list_sub_3, :list_sub_4, :reload),
mixins(:list_sub_3, :reload),
mixins(:list_sub_4, :reload)],
ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos') ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos')
assert_equal 1, mixins(:list_sub_1).pos assert_equal 1, mixins(:list_sub_1).pos
@ -537,8 +472,7 @@ class ListSubTest < Test::Unit::TestCase
mixins(:list_sub_1).destroy mixins(:list_sub_1).destroy
assert_equal [mixins(:list_sub_3, :reload), assert_equal mixins(:list_sub_3, :list_sub_4, :reload),
mixins(:list_sub_4, :reload)],
ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos') ListMixin.find(:all, :conditions => 'parent_id = 5000', :order => 'pos')
assert_equal 1, mixins(:list_sub_3).pos assert_equal 1, mixins(:list_sub_3).pos