diff --git a/app/jobs/import_census_job.rb b/app/jobs/import_census_job.rb index 4c9f66f0ed..ad34121758 100644 --- a/app/jobs/import_census_job.rb +++ b/app/jobs/import_census_job.rb @@ -2,7 +2,7 @@ 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 diff --git a/app/jobs/import_student_loans_data_job.rb b/app/jobs/import_student_loans_data_job.rb index fa3b53b56e..106d6f72eb 100644 --- a/app/jobs/import_student_loans_data_job.rb +++ b/app/jobs/import_student_loans_data_job.rb @@ -7,6 +7,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 diff --git a/config/application.rb b/config/application.rb index 04b8d65fe8..379e695c5a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -16,6 +16,7 @@ # require "rails/test_unit/railtie" require_relative "../lib/student_loan" +require_relative "../lib/analytics_importer" require_relative "../lib/csv_importer" require_relative "../lib/dfe_sign_in" require_relative "../lib/hmrc" diff --git a/lib/analytics_importer.rb b/lib/analytics_importer.rb new file mode 100644 index 0000000000..0e6d8274d4 --- /dev/null +++ b/lib/analytics_importer.rb @@ -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 diff --git a/lib/csv_importer/base.rb b/lib/csv_importer/base.rb index ad4d06e7c5..264ac1b00e 100644 --- a/lib/csv_importer/base.rb +++ b/lib/csv_importer/base.rb @@ -33,7 +33,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 diff --git a/spec/jobs/import_census_job_spec.rb b/spec/jobs/import_census_job_spec.rb index ba261fa7ee..46f3eb686f 100644 --- a/spec/jobs/import_census_job_spec.rb +++ b/spec/jobs/import_census_job_spec.rb @@ -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 diff --git a/spec/jobs/import_student_loans_data_job_spec.rb b/spec/jobs/import_student_loans_data_job_spec.rb index 5554943913..33a3433777 100644 --- a/spec/jobs/import_student_loans_data_job_spec.rb +++ b/spec/jobs/import_student_loans_data_job_spec.rb @@ -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 diff --git a/spec/lib/csv_importer/base_spec.rb b/spec/lib/csv_importer/base_spec.rb index 3d641872a0..cd1b64a6f9 100644 --- a/spec/lib/csv_importer/base_spec.rb +++ b/spec/lib/csv_importer/base_spec.rb @@ -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 diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 4e33fc6c46..8256c112ff 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -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 diff --git a/spec/support/dfe_analytics.rb b/spec/support/dfe_analytics.rb deleted file mode 100644 index 59b6a74f43..0000000000 --- a/spec/support/dfe_analytics.rb +++ /dev/null @@ -1,8 +0,0 @@ -RSpec.shared_context "with DfE Analytics enabled", shared_context: :metadata do - before { allow(DfE::Analytics).to receive(:enabled?).and_return(true) } - after { allow(DfE::Analytics).to receive(:enabled?).and_return(false) } -end - -RSpec.configure do |rspec| - rspec.include_context "with DfE Analytics enabled", with_dfe_analytics_enabled: true -end