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