Use `Rails.public_path.join`

This commit is contained in:
Karina Kwiatek 2022-12-04 22:40:36 +01:00 committed by Andreas Nedbal
parent 5b29c78496
commit 854b2fd5c6
2 changed files with 3 additions and 1 deletions

View File

@ -133,7 +133,7 @@ class Exporter
end end
def publish def publish
`tar czvf #{Rails.root.join "public", "export", "#{@export_filename}.tar.gz"} #{@export_dirname}` `tar czvf #{Rails.public_path.join "export", "#{@export_filename}.tar.gz"} #{@export_dirname}`
url = "#{APP_CONFIG['https'] ? 'https' : 'http'}://#{APP_CONFIG['hostname']}/export/#{@export_filename}.tar.gz" url = "#{APP_CONFIG['https'] ? 'https' : 'http'}://#{APP_CONFIG['hostname']}/export/#{@export_filename}.tar.gz"
@user.export_processing = false @user.export_processing = false
@user.export_url = url @user.export_url = url

View File

@ -296,11 +296,13 @@ RSpec.describe Exporter do
describe "#publish" do describe "#publish" do
let(:fake_rails_root) { Pathname(Dir.mktmpdir) } let(:fake_rails_root) { Pathname(Dir.mktmpdir) }
let(:fake_rails_public_path) { fake_rails_root.join('public') }
let(:name) { instance.instance_variable_get(:@export_filename) } let(:name) { instance.instance_variable_get(:@export_filename) }
before do before do
FileUtils.mkdir_p("#{fake_rails_root}/public/export") FileUtils.mkdir_p("#{fake_rails_root}/public/export")
allow(Rails).to receive(:root).and_return(fake_rails_root) allow(Rails).to receive(:root).and_return(fake_rails_root)
allow(Rails).to receive(:public_path).and_return(fake_rails_public_path)
user.export_processing = true user.export_processing = true
user.save! user.save!