change method name for a better understanding of what the befor_filter does
and correct test syntax #5324
This commit is contained in:
parent
bc75371b7a
commit
b2dc77e1e6
3 changed files with 59 additions and 59 deletions
|
|
@ -92,7 +92,7 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirect_unless_moderator
|
def redirect_unless_admin_or_moderator
|
||||||
unless current_user.moderator? || current_user.admin?
|
unless current_user.moderator? || current_user.admin?
|
||||||
redirect_to stream_url, :notice => 'you need to be an admin or moderator to do that'
|
redirect_to stream_url, :notice => 'you need to be an admin or moderator to do that'
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
class ReportController < ApplicationController
|
class ReportController < ApplicationController
|
||||||
before_filter :authenticate_user!
|
before_filter :authenticate_user!
|
||||||
before_filter :redirect_unless_moderator, :except => [:create]
|
before_filter :redirect_unless_admin_or_moderator, :except => [:create]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@reports = Report.where(reviewed: false)
|
@reports = Report.where(reviewed: false)
|
||||||
|
|
|
||||||
|
|
@ -2,138 +2,138 @@
|
||||||
# licensed under the Affero General Public License version 3 or later. See
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
|
|
||||||
describe ReportController, :type => :controller do
|
describe ReportController, type: :controller do
|
||||||
before do
|
before do
|
||||||
sign_in alice
|
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")
|
@comment = alice.comment!(@message, "flying pigs, everywhere")
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#index' do
|
describe "#index" do
|
||||||
context 'admin not signed in' do
|
context "admin not signed in" do
|
||||||
it 'is behind redirect_unless_admin' do
|
it "is behind redirect_unless_admin" do
|
||||||
get :index
|
get :index
|
||||||
expect(response).to redirect_to stream_path
|
expect(response).to redirect_to stream_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'admin signed in' do
|
context "admin signed in" do
|
||||||
before do
|
before do
|
||||||
Role.add_admin(alice.person)
|
Role.add_admin(alice.person)
|
||||||
end
|
end
|
||||||
it 'succeeds and renders index' do
|
it "succeeds and renders index" do
|
||||||
get :index
|
get :index
|
||||||
expect(response).to render_template('index')
|
expect(response).to render_template("index")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'moderator signed in' do
|
context "moderator signed in" do
|
||||||
before do
|
before do
|
||||||
Role.add_moderator(alice.person)
|
Role.add_moderator(alice.person)
|
||||||
end
|
end
|
||||||
it 'succeeds and renders index' do
|
it "succeeds and renders index" do
|
||||||
get :index
|
get :index
|
||||||
expect(response).to render_template('index')
|
expect(response).to render_template("index")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#create' do
|
describe "#create" do
|
||||||
let(:comment_hash) {
|
let(:comment_hash) {
|
||||||
{:text =>"facebook, is that you?",
|
{text: "facebook, is that you?",
|
||||||
:item_id =>"#{@post.id}"}
|
item_id: "#{@post.id}"}
|
||||||
}
|
}
|
||||||
|
|
||||||
context 'report offensive post' do
|
context "report offensive post" do
|
||||||
it 'succeeds' do
|
it "succeeds" do
|
||||||
put :create, :report => { :item_id => @message.id, :item_type => 'post', :text => 'offensive content' }
|
put :create, report: {item_id: @message.id, item_type: "post", text: "offensive content"}
|
||||||
expect(response.status).to eq(200)
|
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
|
||||||
end
|
end
|
||||||
context 'report offensive comment' do
|
context "report offensive comment" do
|
||||||
it 'succeeds' do
|
it "succeeds" do
|
||||||
put :create, :report => { :item_id => @comment.id, :item_type => 'comment', :text => 'offensive content' }
|
put :create, report: {item_id: @comment.id, item_type: "comment", text: "offensive content"}
|
||||||
expect(response.status).to eq(200)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#update' do
|
describe "#update" do
|
||||||
context 'mark post report as user' do
|
context "mark post report as user" do
|
||||||
it 'is behind redirect_unless_admin' do
|
it "is behind redirect_unless_admin_or_moderator" do
|
||||||
put :update, :id => @message.id, :type => 'post'
|
put :update, id: @message.id, type: "post"
|
||||||
expect(response).to redirect_to stream_path
|
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
|
||||||
end
|
end
|
||||||
context 'mark comment report as user' do
|
context "mark comment report as user" do
|
||||||
it 'is behind redirect_unless_admin' do
|
it "is behind redirect_unless_admin" do
|
||||||
put :update, :id => @comment.id, :type => 'comment'
|
put :update, id: @comment.id, type: "comment"
|
||||||
expect(response).to redirect_to stream_path
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'mark post report as admin' do
|
context "mark post report as admin" do
|
||||||
before do
|
before do
|
||||||
Role.add_admin(alice.person)
|
Role.add_admin(alice.person)
|
||||||
end
|
end
|
||||||
it 'succeeds' do
|
it "succeeds" do
|
||||||
put :update, :id => @message.id, :type => 'post'
|
put :update, id: @message.id, type: "post"
|
||||||
expect(response.status).to eq(302)
|
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
|
||||||
end
|
end
|
||||||
context 'mark comment report as admin' do
|
context "mark comment report as admin" do
|
||||||
before do
|
before do
|
||||||
Role.add_admin(alice.person)
|
Role.add_admin(alice.person)
|
||||||
end
|
end
|
||||||
it 'succeeds' do
|
it "succeeds" do
|
||||||
put :update, :id => @comment.id, :type => 'comment'
|
put :update, id: @comment.id, type: "comment"
|
||||||
expect(response.status).to eq(302)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#destroy' do
|
describe "#destroy" do
|
||||||
context 'destroy post as user' do
|
context "destroy post as user" do
|
||||||
it 'is behind redirect_unless_admin' do
|
it "is behind redirect_unless_admin" do
|
||||||
delete :destroy, :id => @message.id, :type => 'post'
|
delete :destroy, id: @message.id, type: "post"
|
||||||
expect(response).to redirect_to stream_path
|
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
|
||||||
end
|
end
|
||||||
context 'destroy comment as user' do
|
context "destroy comment as user" do
|
||||||
it 'is behind redirect_unless_admin' do
|
it "is behind redirect_unless_admin" do
|
||||||
delete :destroy, :id => @comment.id, :type => 'comment'
|
delete :destroy, id: @comment.id, type: "comment"
|
||||||
expect(response).to redirect_to stream_path
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'destroy post as admin' do
|
context "destroy post as admin" do
|
||||||
before do
|
before do
|
||||||
Role.add_admin(alice.person)
|
Role.add_admin(alice.person)
|
||||||
end
|
end
|
||||||
it 'succeeds' do
|
it "succeeds" do
|
||||||
delete :destroy, :id => @message.id, :type => 'post'
|
delete :destroy, id: @message.id, type: "post"
|
||||||
expect(response.status).to eq(302)
|
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
|
||||||
end
|
end
|
||||||
context 'destroy comment as admin' do
|
context "destroy comment as admin" do
|
||||||
before do
|
before do
|
||||||
Role.add_admin(alice.person)
|
Role.add_admin(alice.person)
|
||||||
end
|
end
|
||||||
it 'succeeds' do
|
it "succeeds" do
|
||||||
delete :destroy, :id => @comment.id, :type => 'comment'
|
delete :destroy, id: @comment.id, type: "comment"
|
||||||
expect(response.status).to eq(302)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue