Skip to content

Commit ee68a10

Browse files
committed
Test remove relationship does not remove related resource
Closes gh-1261 Fixes gh-1260
1 parent 73e9e9e commit ee68a10

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
@@ -1293,6 +1293,25 @@ def test_update_relationship_to_one_singular_param
12931293
assert_equal ruby.id, post_object.section_id
12941294
end
12951295

1296+
def test_remove_relationship_to_many_belongs_to
1297+
set_content_type_header!
1298+
c = Comment.find(3)
1299+
p = Post.find(2)
1300+
total_comment_count = Comment.count
1301+
post_comment_count = p.comments.count
1302+
1303+
put :destroy_relationship, params: {post_id: "#{p.id}", relationship: 'comments', data: [{type: 'comments', id: "#{c.id}"}]}
1304+
1305+
assert_response :no_content
1306+
p = Post.find(2)
1307+
c = Comment.find(3)
1308+
1309+
assert_equal post_comment_count - 1, p.comments.length
1310+
assert_equal total_comment_count, Comment.count
1311+
1312+
assert_nil c.post_id
1313+
end
1314+
12961315
def test_update_relationship_to_many_join_table_single
12971316
set_content_type_header!
12981317
put :update_relationship, params: {post_id: 3, relationship: 'tags', data: []}

0 commit comments

Comments
 (0)