Allow users to delete their own comments

This commit is contained in:
Julian Herrero
2020-09-24 11:53:48 +07:00
committed by Javi Martín
parent fa14976cfd
commit 0698c0ff4f
12 changed files with 100 additions and 8 deletions

View File

@@ -235,6 +235,58 @@ describe "Commenting debates" do
expect(page).to have_content "Can't be blank"
end
describe "Hide" do
scenario "Without replies" do
create(:comment, commentable: debate, user: user, body: "This was a mistake")
login_as(user)
visit debate_path(debate)
accept_confirm("Are you sure? This action will delete this comment. You can't undo this action.") do
within(".comment-body", text: "This was a mistake") { click_link "Delete comment" }
end
expect(page).not_to have_content "This was a mistake"
expect(page).not_to have_link "Delete comment"
visit debate_path(debate)
expect(page).not_to have_content "This was a mistake"
expect(page).not_to have_link "Delete comment"
logout
login_as(create(:administrator).user)
visit admin_hidden_comments_path
expect(page).to have_content "This was a mistake"
end
scenario "With replies" do
comment = create(:comment, commentable: debate, user: user, body: "Wrong comment")
create(:comment, commentable: debate, parent: comment, body: "Right reply")
login_as(user)
visit debate_path(debate)
accept_confirm("Are you sure? This action will delete this comment. You can't undo this action.") do
within(".comment-body", text: "Wrong comment") { click_link "Delete comment" }
end
within "#comments > .comment-list > li", text: "Right reply" do
expect(page).to have_content "This comment has been deleted"
expect(page).not_to have_content "Wrong comment"
end
visit debate_path(debate)
within "#comments > .comment-list > li", text: "Right reply" do
expect(page).to have_content "This comment has been deleted"
expect(page).not_to have_content "Wrong comment"
end
end
end
scenario "Reply" do
citizen = create(:user, username: "Ana")
manuela = create(:user, username: "Manuela")