Fixing asset class tests 💃

pull/1187/head
Javier Álvarez Medina 10 years ago
parent c0b042435a
commit 2f2b60292e

@ -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)

@ -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

Loading…
Cancel
Save