From 2f2b60292e101ae2e2dc7b2b169a0351f29d684c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20=C3=81lvarez=20Medina?= Date: Tue, 18 Nov 2014 17:20:05 +0100 Subject: [PATCH] Fixing asset class tests :dancer: --- app/models/asset.rb | 3 ++- spec/models/asset_spec.rb | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/models/asset.rb b/app/models/asset.rb index 66a1455927..0f4667f9c6 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -92,7 +92,8 @@ class Asset < Sequel::Model def remove unless use_s3? - FileUtils.rm("#{Rails.root}/public#{public_url}") rescue '' + local_url = public_url.gsub(/http:\/\/#{Cartodb.config[:account_host]}/,'') + FileUtils.rm("#{Rails.root}/public#{local_url}") rescue '' return end basename = File.basename(public_url) diff --git a/spec/models/asset_spec.rb b/spec/models/asset_spec.rb index 2f72df0672..2ccf9633a9 100644 --- a/spec/models/asset_spec.rb +++ b/spec/models/asset_spec.rb @@ -52,13 +52,15 @@ describe Asset do it 'should save the file when passing a full path as an argument' do asset = Asset.create user_id: @user.id, asset_file: (Rails.root + 'db/fake_data/simple.json').to_s - File.exists?("#{Rails.root}/public#{asset.public_url}").should be_true + local_url = asset.public_url.gsub(/http:\/\/#{Cartodb.config[:account_host]}/,'') + File.exists?("#{Rails.root}/public#{local_url}").should be_true asset.public_url.should =~ /.*test\/#{@user.username}\/assets\/\d+simple\.json.*/ end it 'should save the file when passing an UploadedFile as an argument' do asset = Asset.create user_id: @user.id, asset_file: Rack::Test::UploadedFile.new(Rails.root.join('db/fake_data/column_number_to_boolean.csv'), 'text/csv') - File.exists?("#{Rails.root}/public#{asset.public_url}").should be_true + local_url = asset.public_url.gsub(/http:\/\/#{Cartodb.config[:account_host]}/,'') + File.exists?("#{Rails.root}/public#{local_url}").should be_true asset.public_url.should =~ /.*test\/#{@user.username}\/assets\/\d+column_number_to_boolean.csv.*/ end @@ -74,7 +76,8 @@ describe Asset do file = Rails.root.join('spec/support/data/cartofante_blue.png') serve_file file do |url| asset = Asset.create(user_id: @user.id, url: url) - File.exists?("#{Rails.root}/public#{asset.public_url}").should be_true + local_url = asset.public_url.gsub(/http:\/\/#{Cartodb.config[:account_host]}/,'') + File.exists?("#{Rails.root}/public#{local_url}").should be_true asset.public_url.should =~ /\/test\/test\/assets\/\d+cartofante_blue\.png/ end end @@ -86,7 +89,8 @@ describe Asset do it 'removes the file from storage if needed' do Asset.any_instance.stubs("use_s3?").returns(false) asset = Asset.create user_id: @user.id, asset_file: (Rails.root + 'db/fake_data/simple.json').to_s - path = "#{Rails.root}/public#{asset.public_url}" + local_url = asset.public_url.gsub(/http:\/\/#{Cartodb.config[:account_host]}/,'') + path = "#{Rails.root}/public#{local_url}" File.exists?(path).should be_true asset.destroy File.exists?(path).should be_false