diff --git a/app/sidekiq/education_form/create_daily_spool_files.rb b/app/sidekiq/education_form/create_daily_spool_files.rb index a9323b5566d..2f1ff3f0d9e 100644 --- a/app/sidekiq/education_form/create_daily_spool_files.rb +++ b/app/sidekiq/education_form/create_daily_spool_files.rb @@ -115,12 +115,7 @@ def write_files(writer, structured_data:) # This mailer is intended to only work for development, staging and NOT production # Rails.env will return 'production' on the development & staging servers and which # will trip the unwary. To be safe, use Settings.hostname - email_staging_spool_files(contents) if - # local developer development - Rails.env.eql?('development') || - - # VA Staging environment where we really want this to work. - Settings.hostname.eql?('staging-api.va.gov') + email_staging_spool_files(contents) if local_or_staging_env? # track and update the records as processed once the file has been successfully written track_submissions(region_id) @@ -239,5 +234,9 @@ def log_to_email(region) def email_staging_spool_files(contents) CreateStagingSpoolFilesMailer.build(contents).deliver_now end + + def local_or_staging_env? + Rails.env.eql?('development') || Settings.hostname.eql?('staging-api.va.gov') + end end end diff --git a/spec/sidekiq/education_form/create_daily_spool_files_spec.rb b/spec/sidekiq/education_form/create_daily_spool_files_spec.rb index 2cfcc1b2f1e..49b2e9092ae 100644 --- a/spec/sidekiq/education_form/create_daily_spool_files_spec.rb +++ b/spec/sidekiq/education_form/create_daily_spool_files_spec.rb @@ -126,7 +126,6 @@ context 'with records in staging', run_at: '2016-09-16 03:00:00 EDT' do before do - ENV['HOSTNAME'] = 'staging-api.va.gov' application_1606.saved_claim.form = {}.to_json FactoryBot.create(:va1990_western_region) FactoryBot.create(:va1995_full_form) @@ -134,14 +133,12 @@ ActionMailer::Base.deliveries.clear end - after do - ENV['HOSTNAME'] = nil - end - it 'processes the valid messages' do - expect(Flipper).to receive(:enabled?).with(any_args).and_return(false).at_least(:once) - expect { subject.perform }.to change { EducationBenefitsClaim.unprocessed.count }.from(4).to(0) - expect(ActionMailer::Base.deliveries.count).to be > 0 + with_settings(Settings, hostname: 'staging-api.va.gov') do + expect(Flipper).to receive(:enabled?).with(any_args).and_return(false).at_least(:once) + expect { subject.perform }.to change { EducationBenefitsClaim.unprocessed.count }.from(4).to(0) + expect(ActionMailer::Base.deliveries.count).to be > 0 + end end end