diff --git a/app/services/gpo_confirmation_uploader.rb b/app/services/gpo_confirmation_uploader.rb index 23fb6f37ae2..b3cda1ebbf2 100644 --- a/app/services/gpo_confirmation_uploader.rb +++ b/app/services/gpo_confirmation_uploader.rb @@ -1,6 +1,6 @@ class GpoConfirmationUploader - def initialize - @now = Time.zone.now + def initialize(now = Time.zone.now) + @now = now end def run diff --git a/spec/services/gpo_confirmation_uploader_spec.rb b/spec/services/gpo_confirmation_uploader_spec.rb index f4b45e0815a..294311ac9e9 100644 --- a/spec/services/gpo_confirmation_uploader_spec.rb +++ b/spec/services/gpo_confirmation_uploader_spec.rb @@ -1,7 +1,8 @@ require 'rails_helper' RSpec.describe GpoConfirmationUploader do - let(:uploader) { described_class.new } + let(:uploader) { described_class.new(now) } + let(:now) { Time.zone.now } let(:export) { 'foo|bar' } let(:confirmations) do @@ -52,12 +53,13 @@ subject { uploader.send(:upload_export, export) } let(:sftp_connection) { instance_double('Net::SFTP::Session') } - let(:string_io) { StringIO.new(export) } it 'uploads the export via sftp' do expect(Net::SFTP).to receive(:start).with(*sftp_options).and_yield(sftp_connection) - expect(StringIO).to receive(:new).with(export).and_return(string_io) - expect(sftp_connection).to receive(:upload!).with(string_io, upload_folder) + expect(sftp_connection).to receive(:upload!) do |string_io, folder| + expect(string_io.string).to eq(export) + expect(folder).to eq(upload_folder) + end subject end @@ -115,7 +117,7 @@ def sftp_options end def upload_folder - timestamp = Time.zone.now.strftime('%Y%m%d-%H%M%S') + timestamp = now.strftime('%Y%m%d-%H%M%S') File.join(IdentityConfig.store.usps_upload_sftp_directory, "batch#{timestamp}.psv") end