Add test for `Exporter#publish`

This commit is contained in:
Karina Kwiatek 2022-07-10 20:11:48 +02:00 committed by Karina Kwiatek
parent bc07a9fbb0
commit 428db25c71
2 changed files with 36 additions and 3 deletions

View File

@ -133,11 +133,11 @@ class Exporter
end
def publish
`tar czvf #{Rails.root.join "public", "export", "#{@export_filename}.tar.gz"} -C /tmp/rs_export #{@export_dirname}`
url = "#{APP_CONFIG[:https] ? 'https' : 'http'}://#{APP_CONFIG[:hostname]}/export/#{@export_filename}"
`tar czvf #{Rails.root.join "public", "export", @export_filename} -C /tmp/rs_export #{@export_dirname}`
url = "#{APP_CONFIG['https'] ? 'https' : 'http'}://#{APP_CONFIG['hostname']}/export/#{@export_filename}"
@user.export_processing = false
@user.export_url = url
@user.export_created_at = Time.now
@user.export_created_at = Time.now.utc
@user.save validate: false
url
end

View File

@ -227,6 +227,10 @@ RSpec.describe Exporter do
allow(Rails).to receive(:root).and_return(fake_rails_root)
end
after do
FileUtils.rm_r(fake_rails_root)
end
subject { instance.send(:finalize) }
context "exporting a user without a profile picture or header" do
@ -287,4 +291,33 @@ RSpec.describe Exporter do
end
end
end
describe "#publish" do
let(:fake_rails_root) { Pathname(Dir.mktmpdir) }
let(:name) { instance.instance_variable_get(:@export_filename) }
before do
FileUtils.mkdir_p("#{fake_rails_root}/public/export")
allow(Rails).to receive(:root).and_return(fake_rails_root)
user.export_processing = true
user.save!
end
after do
FileUtils.rm_r(fake_rails_root)
end
subject { instance.send(:publish) }
it "publishes an archive" do
Timecop.freeze do
expect { subject }.to change { user.export_processing }.from(true).to(false)
expect(File.exist?("#{fake_rails_root}/public/export/#{name}")).to eq(true)
expect(user.export_url).to eq("https://example.com/export/#{name}")
expect(user.export_created_at).to eq(Time.now.utc)
expect(user).to be_persisted
end
end
end
end