fix imports when user quota cannot be calculated

pull/15512/head
Gonzalo Riestra 5 years ago
parent ddde7608c6
commit f4e9ece77a

@ -53,8 +53,7 @@ module CartoDB
@downloader = options.fetch(:downloader)
@user = options.fetch(:user, nil)
@available_quota =
!@user.nil? && @user.respond_to?(:remaining_quota) ? @user.remaining_quota : DEFAULT_AVAILABLE_QUOTA
@available_quota = @user&.remaining_quota || DEFAULT_AVAILABLE_QUOTA
@unpacker = options.fetch(:unpacker, nil) || Unp.new
@post_import_handler = options.fetch(:post_import_handler, nil)
@importer_config = options.fetch(:importer_config, nil)

@ -195,6 +195,28 @@ describe CartoDB::Importer2::Runner do
# Shouldn't test here a zipped file as that
end
it 'uses a default quota if the user remaining quota cannot be calculated' do
@user.stubs(:remaining_quota).returns(nil)
source_file = CartoDB::Importer2::SourceFile.new(@filepath)
job = CartoDB::Importer2::Job.new(pg_options: @pg_options, logger: @fake_log)
fake_loader = fake_loader_for(job, source_file)
def fake_loader.run(arg = nil); end
limits = {
import_file_size_instance: CartoDB::Importer2::Doubles::InputFileSizeLimit.new(max_size: 5),
table_row_count_limit_instance: CartoDB::Importer2::Doubles::TableRowCountLimit.new
}
runner = CartoDB::Importer2::Runner.new(pg: @pg_options, downloader: Object.new, log: @fake_log, user: @user,
limits: limits, job: job)
runner.send(:import, source_file, nil, fake_loader)
result = runner.results.first
result.success?.should eq true
@user.unstub(:remaining_quota)
end
end

Loading…
Cancel
Save