Fix #4982: Add route to remove a post from a favorite group

This commit is contained in:
evazion
2022-05-02 15:43:44 -05:00
parent d2502a0c40
commit 17ffe3590a
5 changed files with 47 additions and 0 deletions

View File

@@ -116,6 +116,7 @@ class FavoriteGroupsControllerTest < ActionDispatch::IntegrationTest
should "render" do
@post = create(:post)
put_auth add_post_favorite_group_path(@favgroup), @user, params: {post_id: @post.id, format: "js"}
assert_response :success
assert_equal([@post.id], @favgroup.reload.post_ids)
end
@@ -123,7 +124,33 @@ class FavoriteGroupsControllerTest < ActionDispatch::IntegrationTest
should "not add posts to favgroups belonging to other users" do
@post = create(:post)
put_auth add_post_favorite_group_path(@favgroup), create(:user), params: {post_id: @post.id, format: "js"}
assert_response 403
assert_equal([], @favgroup.reload.post_ids)
end
end
context "remove_post action" do
should "render" do
@post = create(:post)
@favgroup.add(@post)
assert_equal([@post.id], @favgroup.reload.post_ids)
put_auth remove_post_favorite_group_path(@favgroup), @user, params: { post_id: @post.id, format: "js" }
assert_response :success
assert_equal([], @favgroup.reload.post_ids)
end
should "not remove posts from favgroups belonging to other users" do
@post = create(:post)
@favgroup.add(@post)
assert_equal([@post.id], @favgroup.reload.post_ids)
put_auth remove_post_favorite_group_path(@favgroup), create(:user), params: { post_id: @post.id, format: "js" }
assert_response 403
assert_equal([@post.id], @favgroup.reload.post_ids)
end
end