Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/fix/CDB-648' into release/2.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rafacas committed Oct 4, 2013
2 parents 359c60a + dee8533 commit 648cba2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 3 additions & 7 deletions app/connectors/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize(runner, table_registrar, quota_checker, database,
def run(tracker)
runner.run(&tracker)

if table_quota_exceeded?
if quota_checker.will_be_over_table_quota?(results.length)
drop(results)
else
results.select(&:success?).each { |result| register(result) }
Expand All @@ -34,7 +34,7 @@ def register(result)
end

def success?
!table_quota_exceeded? && runner.success?
!quota_checker.over_table_quota? && runner.success?
end

def drop_all(results)
Expand Down Expand Up @@ -68,10 +68,6 @@ def rename(current_name, new_name, rename_attempts=0)
retry unless rename_attempts > 1
end

def table_quota_exceeded?
quota_checker.over_table_quota?(results.length)
end

def persist_metadata(name, data_import_id)
table_registrar.register(name, data_import_id)
self.table = table_registrar.table
Expand All @@ -83,7 +79,7 @@ def results
end

def error_code
return 8002 if table_quota_exceeded?
return 8002 if quota_checker.over_table_quota?
results.map(&:error_code).compact.first
end #errors_from

Expand Down
7 changes: 6 additions & 1 deletion app/models/quota_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ def initialize(user)
@user = user
end

def over_table_quota?(number_of_new_tables)
def will_be_over_table_quota?(number_of_new_tables)
return false unless user.remaining_table_quota
number_of_new_tables.to_i > user.remaining_table_quota.to_i
end

def over_table_quota?
return false unless user.remaining_table_quota
user.tables.count > user.table_quota.to_i
end

private

attr_reader :user
Expand Down

0 comments on commit 648cba2

Please sign in to comment.