Skip to content

Commit 7445e89

Browse files
committed
Test remove relationship does not remove related resource
1 parent b7a7990 commit 7445e89

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/controllers/controller_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,25 @@ def test_update_relationship_to_one_singular_param
13961396
assert_equal ruby.id, post_object.section_id
13971397
end
13981398

1399+
def test_remove_relationship_to_many_belongs_to
1400+
set_content_type_header!
1401+
c = Comment.find(3)
1402+
p = Post.find(2)
1403+
total_comment_count = Comment.count
1404+
post_comment_count = p.comments.count
1405+
1406+
put :destroy_relationship, params: {post_id: "#{p.id}", relationship: 'comments', data: [{type: 'comments', id: "#{c.id}"}]}
1407+
1408+
assert_response :no_content
1409+
p = Post.find(2)
1410+
c = Comment.find(3)
1411+
1412+
assert_equal post_comment_count - 1, p.comments.length
1413+
assert_equal total_comment_count, Comment.count
1414+
1415+
assert_nil c.post_id
1416+
end
1417+
13991418
def test_update_relationship_to_many_join_table_single
14001419
set_content_type_header!
14011420
put :update_relationship, params: {post_id: 3, relationship: 'tags', data: []}

0 commit comments

Comments
 (0)