discourse/spec/controllers/export_csv_controller_spec.rb

49 lines
1.9 KiB
Ruby
Raw Normal View History

require "rails_helper"
2014-12-23 00:17:04 +08:00
describe ExportCsvController do
let(:export_filename) { "user-archive-codinghorror-150115-234817-999.csv.gz" }
2014-12-23 00:17:04 +08:00
context "while logged in as normal user" do
before { @user = log_in(:user) }
describe ".export_entity" do
it "enqueues export job" do
Jobs.expects(:enqueue).with(:export_csv_file, has_entries(entity: "user_archive", user_id: @user.id))
post :export_entity, params: { entity: "user_archive" }, format: :json
2015-01-10 01:04:02 +08:00
expect(response).to be_success
2014-12-23 00:17:04 +08:00
end
2014-12-30 20:37:05 +08:00
it "should not enqueue export job if rate limit is reached" do
Jobs::ExportCsvFile.any_instance.expects(:execute).never
UserExport.create(file_name: "user-archive-codinghorror-150116-003249", user_id: @user.id)
post :export_entity, params: { entity: "user_archive" }, format: :json
2015-01-10 01:04:02 +08:00
expect(response).not_to be_success
2014-12-30 20:37:05 +08:00
end
2014-12-23 00:17:04 +08:00
it "returns 404 when normal user tries to export admin entity" do
post :export_entity, params: { entity: "staff_action" }, format: :json
2015-01-10 01:04:02 +08:00
expect(response).not_to be_success
2014-12-23 00:17:04 +08:00
end
end
end
context "while logged in as an admin" do
before { @admin = log_in(:admin) }
describe ".export_entity" do
it "enqueues export job" do
Jobs.expects(:enqueue).with(:export_csv_file, has_entries(entity: "staff_action", user_id: @admin.id))
post :export_entity, params: { entity: "staff_action" }, format: :json
2015-01-10 01:04:02 +08:00
expect(response).to be_success
2014-12-23 00:17:04 +08:00
end
2014-12-30 20:37:05 +08:00
it "should not rate limit export for staff" do
Jobs.expects(:enqueue).with(:export_csv_file, has_entries(entity: "staff_action", user_id: @admin.id))
UserExport.create(file_name: "screened-email-150116-010145", user_id: @admin.id)
post :export_entity, params: { entity: "staff_action" }, format: :json
2015-01-10 01:04:02 +08:00
expect(response).to be_success
2014-12-30 20:37:05 +08:00
end
2014-12-23 00:17:04 +08:00
end
end
end