From 098c30c2b7dbfd6138de591b3ca379cb4ef9d87e Mon Sep 17 00:00:00 2001 From: realtin Date: Fri, 21 Aug 2015 14:57:30 +0200 Subject: [PATCH] adapt report spec for the moderator --- spec/controllers/report_controller_spec.rb | 48 ++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/spec/controllers/report_controller_spec.rb b/spec/controllers/report_controller_spec.rb index 528d05c31..c214e34d1 100644 --- a/spec/controllers/report_controller_spec.rb +++ b/spec/controllers/report_controller_spec.rb @@ -71,7 +71,7 @@ describe ReportController, type: :controller do end end context "mark comment report as user" do - it "is behind redirect_unless_admin" do + it "is behind redirect_unless_admin_or_moderator" do put :update, id: @comment.id, type: "comment" expect(response).to redirect_to stream_path expect(Report.where(reviewed: false, item_id: @comment.id, item_type: "comment")).to be_truthy @@ -98,18 +98,39 @@ describe ReportController, type: :controller do expect(Report.where(reviewed: true, item_id: @comment.id, item_type: "comment")).to be_truthy end end + + context "mark post report as moderator" do + before do + Role.add_moderator(alice.person) + end + it "succeeds" do + put :update, id: @message.id, type: "post" + expect(response.status).to eq(302) + expect(Report.where(reviewed: true, item_id: @message.id, item_type: "post")).to be_truthy + end + end + context "mark comment report as moderator" do + before do + Role.add_moderator(alice.person) + end + it "succeeds" do + put :update, id: @comment.id, type: "comment" + expect(response.status).to eq(302) + expect(Report.where(reviewed: true, item_id: @comment.id, item_type: "comment")).to be_truthy + end + end end describe "#destroy" do context "destroy post as user" do - it "is behind redirect_unless_admin" do + it "is behind redirect_unless_admin_or_moderator" do delete :destroy, id: @message.id, type: "post" expect(response).to redirect_to stream_path expect(Report.where(reviewed: false, item_id: @message.id, item_type: "post")).to be_truthy end end context "destroy comment as user" do - it "is behind redirect_unless_admin" do + it "is behind redirect_unless_admin_or_moderator" do delete :destroy, id: @comment.id, type: "comment" expect(response).to redirect_to stream_path expect(Report.where(reviewed: false, item_id: @comment.id, item_type: "comment")).to be_truthy @@ -136,5 +157,26 @@ describe ReportController, type: :controller do expect(Report.where(reviewed: true, item_id: @comment.id, item_type: "comment")).to be_truthy end end + + context "destroy post as moderator" do + before do + Role.add_moderator(alice.person) + end + it "succeeds" do + delete :destroy, id: @message.id, type: "post" + expect(response.status).to eq(302) + expect(Report.where(reviewed: true, item_id: @message.id, item_type: "post")).to be_truthy + end + end + context "destroy comment as moderator" do + before do + Role.add_moderator(alice.person) + end + it "succeeds" do + delete :destroy, id: @comment.id, type: "comment" + expect(response.status).to eq(302) + expect(Report.where(reviewed: true, item_id: @comment.id, item_type: "comment")).to be_truthy + end + end end end