Fix all the errors to get our tests green on Rails 5.1.

This commit is contained in:
Guo Xiang Tan
2017-08-31 12:06:56 +08:00
parent 898ee93547
commit 77d4c4d8dc
989 changed files with 5114 additions and 3117 deletions

View File

@ -6,7 +6,7 @@ describe ExportCsvController do
context "while not logged in" do
describe ".download" do
it "returns 404 when the unauthorized user tries to export csv file" do
get :show, id: export_filename
get :show, params: { id: export_filename }
expect(response.status).to eq(404)
end
end
@ -18,19 +18,19 @@ describe ExportCsvController do
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))
xhr :post, :export_entity, entity: "user_archive"
post :export_entity, params: { entity: "user_archive" }, format: :json
expect(response).to be_success
end
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)
xhr :post, :export_entity, entity: "user_archive"
post :export_entity, params: { entity: "user_archive" }, format: :json
expect(response).not_to be_success
end
it "returns 404 when normal user tries to export admin entity" do
xhr :post, :export_entity, entity: "staff_action"
post :export_entity, params: { entity: "staff_action" }, format: :json
expect(response).not_to be_success
end
end
@ -43,18 +43,18 @@ describe ExportCsvController do
export = UserExport.new()
UserExport.expects(:get_download_path).with(file_name).returns(export)
subject.expects(:send_file).with(export)
get :show, id: file_name
get :show, params: { id: file_name }
expect(response).to be_success
end
it "returns 404 when the user tries to export another user's csv file" do
get :show, id: export_filename
get :show, params: { id: export_filename }
expect(response).to be_not_found
end
it "returns 404 when the export file does not exist" do
UserExport.expects(:get_download_path).returns(nil)
get :show, id: export_filename
get :show, params: { id: export_filename }
expect(response).to be_not_found
end
end
@ -66,14 +66,14 @@ describe ExportCsvController do
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))
xhr :post, :export_entity, entity: "staff_action"
post :export_entity, params: { entity: "staff_action" }, format: :json
expect(response).to be_success
end
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)
xhr :post, :export_entity, entity: "staff_action"
post :export_entity, params: { entity: "staff_action" }, format: :json
expect(response).to be_success
end
end
@ -86,13 +86,13 @@ describe ExportCsvController do
export = UserExport.new()
UserExport.expects(:get_download_path).with(file_name).returns(export)
subject.expects(:send_file).with(export)
get :show, id: file_name
get :show, params: { id: file_name }
expect(response).to be_success
end
it "returns 404 when the export file does not exist" do
UserExport.expects(:get_download_path).returns(nil)
get :show, id: export_filename
get :show, params: { id: export_filename }
expect(response).to be_not_found
end
end