discourse/spec/requests/admin/flagged_topics_controller_spec.rb
Daniel Waterworth e219588142 DEV: Prefabrication (test optimization) (#7414)
* Introduced fab!, a helper that creates database state for a group

It's almost identical to let_it_be, except:

 1. It creates a new object for each test by default,
 2. You can disable it using PREFABRICATION=0
2019-05-07 13:12:20 +10:00

43 lines
934 B
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Admin::FlaggedTopicsController do
fab!(:post) { Fabricate(:post) }
fab!(:user) { Fabricate(:user) }
before do
PostActionCreator.spam(user, post)
end
fab!(:flag) { Fabricate(:flag) }
shared_examples "successfully retrieve list of flagged topics" do
it "returns a list of flagged topics" do
get "/admin/flagged_topics.json"
expect(response.status).to eq(200)
data = ::JSON.parse(response.body)
expect(data['flagged_topics']).to be_present
expect(data['users']).to be_present
end
end
context "as admin" do
before do
sign_in(Fabricate(:admin))
end
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