diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 14996d4c0fc2f05ca4b1bef090ed5f643f777c6d..951638b30199c1652654dc86f0d98514bbdfd5ef 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -92,7 +92,7 @@ class ApplicationController < ActionController::Base end end - def redirect_unless_moderator + def redirect_unless_admin_or_moderator unless current_user.moderator? || current_user.admin? redirect_to stream_url, :notice => 'you need to be an admin or moderator to do that' return diff --git a/app/controllers/report_controller.rb b/app/controllers/report_controller.rb index c560d2e82659e77779e71a13d8ef7691b783e11f..f0603ecebfaba5e5c88de8cad99f5a593f7ba3f1 100644 --- a/app/controllers/report_controller.rb +++ b/app/controllers/report_controller.rb @@ -4,7 +4,7 @@ class ReportController < ApplicationController before_filter :authenticate_user! - before_filter :redirect_unless_moderator, :except => [:create] + before_filter :redirect_unless_admin_or_moderator, :except => [:create] def index @reports = Report.where(reviewed: false) diff --git a/spec/controllers/report_controller_spec.rb b/spec/controllers/report_controller_spec.rb index a10505a207409518d3f4d74f8860afb26f7062f0..528d05c31f81a0ba1243730666296a6bd170426e 100644 --- a/spec/controllers/report_controller_spec.rb +++ b/spec/controllers/report_controller_spec.rb @@ -2,138 +2,138 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -require 'spec_helper' +require "spec_helper" -describe ReportController, :type => :controller do +describe ReportController, type: :controller do before do sign_in alice - @message = alice.post(:status_message, :text => "hey", :to => alice.aspects.first.id) + @message = alice.post(:status_message, text: "hey", to: alice.aspects.first.id) @comment = alice.comment!(@message, "flying pigs, everywhere") end - describe '#index' do - context 'admin not signed in' do - it 'is behind redirect_unless_admin' do + describe "#index" do + context "admin not signed in" do + it "is behind redirect_unless_admin" do get :index expect(response).to redirect_to stream_path end end - context 'admin signed in' do + context "admin signed in" do before do Role.add_admin(alice.person) end - it 'succeeds and renders index' do + it "succeeds and renders index" do get :index - expect(response).to render_template('index') + expect(response).to render_template("index") end end - context 'moderator signed in' do + context "moderator signed in" do before do Role.add_moderator(alice.person) end - it 'succeeds and renders index' do + it "succeeds and renders index" do get :index - expect(response).to render_template('index') + expect(response).to render_template("index") end end end - describe '#create' do + describe "#create" do let(:comment_hash) { - {:text =>"facebook, is that you?", - :item_id =>"#{@post.id}"} + {text: "facebook, is that you?", + item_id: "#{@post.id}"} } - context 'report offensive post' do - it 'succeeds' do - put :create, :report => { :item_id => @message.id, :item_type => 'post', :text => 'offensive content' } + context "report offensive post" do + it "succeeds" do + put :create, report: {item_id: @message.id, item_type: "post", text: "offensive content"} expect(response.status).to eq(200) - expect(Report.exists?(:item_id => @message.id, :item_type => 'post')).to be true + expect(Report.exists?(item_id: @message.id, item_type: "post")).to be true end end - context 'report offensive comment' do - it 'succeeds' do - put :create, :report => { :item_id => @comment.id, :item_type => 'comment', :text => 'offensive content' } + context "report offensive comment" do + it "succeeds" do + put :create, report: {item_id: @comment.id, item_type: "comment", text: "offensive content"} expect(response.status).to eq(200) - expect(Report.exists?(:item_id => @comment.id, :item_type => 'comment')).to be true + expect(Report.exists?(item_id: @comment.id, item_type: "comment")).to be true end end end - describe '#update' do - context 'mark post report as user' do - it 'is behind redirect_unless_admin' do - put :update, :id => @message.id, :type => 'post' + describe "#update" do + context "mark post report as user" do + it "is behind redirect_unless_admin_or_moderator" do + put :update, 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 + expect(Report.where(reviewed: false, item_id: @message.id, item_type: "post")).to be_truthy end end - context 'mark comment report as user' do - it 'is behind redirect_unless_admin' do - put :update, :id => @comment.id, :type => 'comment' + context "mark comment report as user" do + it "is behind redirect_unless_admin" 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 + expect(Report.where(reviewed: false, item_id: @comment.id, item_type: "comment")).to be_truthy end end - context 'mark post report as admin' do + context "mark post report as admin" do before do Role.add_admin(alice.person) end - it 'succeeds' do - put :update, :id => @message.id, :type => 'post' + 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 + expect(Report.where(reviewed: true, item_id: @message.id, item_type: "post")).to be_truthy end end - context 'mark comment report as admin' do + context "mark comment report as admin" do before do Role.add_admin(alice.person) end - it 'succeeds' do - put :update, :id => @comment.id, :type => 'comment' + 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 + 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 - delete :destroy, :id => @message.id, :type => 'post' + describe "#destroy" do + context "destroy post as user" do + it "is behind redirect_unless_admin" 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 + 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 - delete :destroy, :id => @comment.id, :type => 'comment' + context "destroy comment as user" do + it "is behind redirect_unless_admin" 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 + expect(Report.where(reviewed: false, item_id: @comment.id, item_type: "comment")).to be_truthy end end - context 'destroy post as admin' do + context "destroy post as admin" do before do Role.add_admin(alice.person) end - it 'succeeds' do - delete :destroy, :id => @message.id, :type => 'post' + 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 + expect(Report.where(reviewed: true, item_id: @message.id, item_type: "post")).to be_truthy end end - context 'destroy comment as admin' do + context "destroy comment as admin" do before do Role.add_admin(alice.person) end - it 'succeeds' do - delete :destroy, :id => @comment.id, :type => 'comment' + 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 + expect(Report.where(reviewed: true, item_id: @comment.id, item_type: "comment")).to be_truthy end end end