diff --git a/test/models/relationship_2_test.rb b/test/models/relationship_2_test.rb index f289131be..a95fc134f 100644 --- a/test/models/relationship_2_test.rb +++ b/test/models/relationship_2_test.rb @@ -426,6 +426,7 @@ def teardown pm1 = create_project_media team: t pm2 = create_project_media team: t pm3 = create_project_media team: t + pm4 = create_project_media team: t # Create a relationship between two items assert_difference 'Relationship.count' do @@ -434,13 +435,6 @@ def teardown end end - # If an item is already a parent, it can't be a child in another relationship - assert_no_difference 'Relationship.count' do - assert_raises ActiveRecord::StatementInvalid do - create_relationship source_id: pm3.id, target_id: pm1.id - end - end - # If an item is already a child, it can't be a child in another relationship assert_no_difference 'Relationship.count' do assert_raises ActiveRecord::StatementInvalid do @@ -455,10 +449,17 @@ def teardown end end + # If an item is already a parent, it can't be a child in another relationship - move targets to new relationship + assert_equal 1, Relationship.where(source_id: pm1.id).count + assert_equal 0, Relationship.where(source_id: pm3.id).count + create_relationship source_id: pm3.id, target_id: pm1.id + assert_equal 0, Relationship.where(source_id: pm1.id).count + assert_equal 2, Relationship.where(source_id: pm3.id).count + # If an item is already a parent, it can still have another child assert_difference 'Relationship.count' do assert_nothing_raised do - create_relationship source_id: pm1.id, target_id: pm3.id + create_relationship source_id: pm3.id, target_id: pm4.id end end end