From beca02c046b9d73558dbc4eb5274ddfdb563af2d Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Thu, 5 Oct 2017 14:12:07 -0400 Subject: [PATCH] FIX: moderators couldn't see flagged topics list --- config/routes.rb | 2 +- .../admin/flagged_topics_controller_spec.rb | 32 +++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 2ebd987a426..b3df2161ea5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -193,7 +193,7 @@ Discourse::Application.routes.draw do post "flags/disagree/:id" => "flags#disagree" post "flags/defer/:id" => "flags#defer" - resources :flagged_topics, constraints: AdminConstraint.new + resources :flagged_topics, constraints: StaffConstraint.new resources :themes, constraints: AdminConstraint.new post "themes/import" => "themes#import" diff --git a/spec/requests/admin/flagged_topics_controller_spec.rb b/spec/requests/admin/flagged_topics_controller_spec.rb index 594caff1ed7..8f768294bc7 100644 --- a/spec/requests/admin/flagged_topics_controller_spec.rb +++ b/spec/requests/admin/flagged_topics_controller_spec.rb @@ -1,19 +1,33 @@ require 'rails_helper' RSpec.describe Admin::FlaggedTopicsController do - let(:admin) { Fabricate(:admin) } let!(:flag) { Fabricate(:flag) } - before do - sign_in(admin) + shared_examples "successfully retrieve list of flagged topics" do + it "returns a list of flagged topics" do + get "/admin/flagged_topics.json" + expect(response).to be_success + + data = ::JSON.parse(response.body) + expect(data['flagged_topics']).to be_present + expect(data['users']).to be_present + end end - it "returns a list of flagged topics" do - get "/admin/flagged_topics.json" - expect(response).to be_success + context "as admin" do + before do + sign_in(Fabricate(:admin)) + end - data = ::JSON.parse(response.body) - expect(data['flagged_topics']).to be_present - expect(data['users']).to be_present + include_examples "successfully retrieve list of flagged topics" end + + context "as moderator" do + before do + sign_in(Fabricate(:moderator)) + end + + include_examples "successfully retrieve list of flagged topics" + end + end