Skip to content

Commit

Permalink
Refactor to avoid invoking Rake task in specs (which is unreliable in…
Browse files Browse the repository at this point in the history
… CI)
  • Loading branch information
slorek committed Nov 8, 2024
1 parent d7384d3 commit 2277fc5
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 25 deletions.
4 changes: 3 additions & 1 deletion app/jobs/import_census_job.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
require "analytics_importer"

class ImportCensusJob < FileImporterJob
import_with SchoolWorkforceCensusDataImporter
rescue_with -> do
SchoolWorkforceCensus.delete_all
Rake::Task["dfe:analytics:import_entity"].invoke(SchoolWorkforceCensus.table_name) if DfE::Analytics.enabled?
AnalyticsImporter.import(SchoolWorkforceCensus)
end
notify_with AdminMailer, success: :census_csv_processing_success, failure: :census_csv_processing_error
end
4 changes: 3 additions & 1 deletion app/jobs/import_student_loans_data_job.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "analytics_importer"

class ImportStudentLoansDataJob < FileImporterJob
import_with StudentLoansDataImporter do
Rails.logger.info "SLC data imported; student loan verifiers will re-run where necessary"
Expand All @@ -7,6 +9,6 @@ class ImportStudentLoansDataJob < FileImporterJob
end
rescue_with -> do
StudentLoansData.delete_all
Rake::Task["dfe:analytics:import_entity"].invoke(StudentLoansData.table_name) if DfE::Analytics.enabled?
AnalyticsImporter.import(StudentLoansData)
end
end
5 changes: 5 additions & 0 deletions lib/analytics_importer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AnalyticsImporter
def self.import(model)
Rake::Task["dfe:analytics:import_entity"].invoke(model.table_name) if DfE::Analytics.enabled?
end
end
3 changes: 2 additions & 1 deletion lib/csv_importer/base.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "csv"
require "analytics_importer"

module CsvImporter
class Base
Expand Down Expand Up @@ -33,7 +34,7 @@ def run
target_data_model.insert_all(record_hashes) unless record_hashes.empty?
end

Rake::Task["dfe:analytics:import_entity"].invoke(target_data_model.table_name) if DfE::Analytics.enabled?
AnalyticsImporter.import(target_data_model)
end

def rows_with_data_count
Expand Down
6 changes: 2 additions & 4 deletions spec/jobs/import_census_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@
expect(FileUpload.find_by_id(file_upload.id)).to be_present
end

describe "dfe-analytics syncing", :with_dfe_analytics_enabled do
let(:dbl) { double(run: true) }
describe "dfe-analytics syncing" do
it "invokes the relevant import entity job" do
expect(DfE::Analytics::LoadEntities).to receive(:new).with(entity_name: SchoolWorkforceCensus.table_name).and_return(dbl)
expect(dbl).to receive(:run)
expect(AnalyticsImporter).to receive(:import).with(SchoolWorkforceCensus)
subject.perform(file_upload.id)
end
end
Expand Down
6 changes: 2 additions & 4 deletions spec/jobs/import_student_loans_data_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@
expect { upload }.not_to have_enqueued_job(StudentLoanPlanCheckJob)
end

describe "dfe-analytics syncing", :with_dfe_analytics_enabled do
let(:dbl) { double(run: true) }
describe "dfe-analytics syncing" do
it "invokes the relevant import entity job" do
expect(DfE::Analytics::LoadEntities).to receive(:new).with(entity_name: StudentLoansData.table_name).and_return(dbl)
expect(dbl).to receive(:run)
expect(AnalyticsImporter).to receive(:import).with(StudentLoansData)
upload
end
end
Expand Down
6 changes: 2 additions & 4 deletions spec/lib/csv_importer/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@
end
end

describe "dfe-analytics syncing", :with_dfe_analytics_enabled do
let(:dbl) { double(run: true) }
describe "dfe-analytics syncing" do
it "invokes the relevant import entity job" do
expect(DfE::Analytics::LoadEntities).to receive(:new).with(entity_name: target_data_model.table_name).and_return(dbl)
expect(dbl).to receive(:run)
expect(AnalyticsImporter).to receive(:import).with(target_data_model)
importer.run
end
end
Expand Down
2 changes: 0 additions & 2 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,3 @@
config.filter_run_excluding js: true unless ENV["RUN_JS_SPECS"] == "true"
config.filter_run_excluding slow: true unless ENV["RUN_SLOW_SPECS"] == "true"
end

Rails.application.load_tasks
8 changes: 0 additions & 8 deletions spec/support/dfe_analytics.rb

This file was deleted.

0 comments on commit 2277fc5

Please sign in to comment.