Allow users to delete their own comments
This commit is contained in:
committed by
Javi Martín
parent
fa14976cfd
commit
0698c0ff4f
@@ -65,9 +65,6 @@ describe Abilities::Common do
|
||||
it { should be_able_to(:show, user) }
|
||||
it { should be_able_to(:edit, user) }
|
||||
|
||||
it { should be_able_to(:create, Comment) }
|
||||
it { should be_able_to(:vote, Comment) }
|
||||
|
||||
it { should be_able_to(:index, Proposal) }
|
||||
it { should be_able_to(:show, proposal) }
|
||||
it { should_not be_able_to(:vote, Proposal) }
|
||||
@@ -97,6 +94,14 @@ describe Abilities::Common do
|
||||
|
||||
it { should_not be_able_to(:manage, LocalCensusRecord) }
|
||||
|
||||
describe "Comment" do
|
||||
it { should be_able_to(:create, Comment) }
|
||||
it { should be_able_to(:vote, Comment) }
|
||||
|
||||
it { should be_able_to(:hide, own_comment) }
|
||||
it { should_not be_able_to(:hide, comment) }
|
||||
end
|
||||
|
||||
describe "flagging content" do
|
||||
it { should be_able_to(:flag, debate) }
|
||||
it { should be_able_to(:unflag, debate) }
|
||||
|
||||
@@ -54,7 +54,7 @@ describe Abilities::Moderator do
|
||||
it { should be_able_to(:hide, comment) }
|
||||
it { should be_able_to(:hide_in_moderation_screen, comment) }
|
||||
it { should_not be_able_to(:hide, hidden_comment) }
|
||||
it { should_not be_able_to(:hide, own_comment) }
|
||||
it { should be_able_to(:hide, own_comment) }
|
||||
|
||||
it { should be_able_to(:moderate, comment) }
|
||||
it { should_not be_able_to(:moderate, own_comment) }
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user