Skip to content

Commit

Permalink
Merge pull request #243 from bdunne/empty_database_spec
Browse files Browse the repository at this point in the history
Add an empty database spec
  • Loading branch information
carbonin authored Aug 8, 2018
2 parents 664512e + db33c1b commit 3889554
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 4 additions & 3 deletions db/migrate/20171026103833_add_cores_allocated_rate_detail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ class ChargebackRateDetail < ActiveRecord::Base
end

def up
rate_detail_template = ChargebackRateDetail.where(:description => "Allocated CPU Count").first
return if rate_detail_template.nil? # No rates that need this detail.
rate_detail_template = rate_detail_template.dup

chargeable_field = ChargeableField.find_or_create_by(:metric => "derived_vm_numvcpu_cores",
:description => "Allocated CPU Cores",
:group => "cpu_cores",
:source => "allocated")

rate_detail_template = ChargebackRateDetail.where(:description => "Allocated CPU Count").first
return if rate_detail_template.nil? # No rates that need this detail.
rate_detail_template = rate_detail_template.dup
rate_detail_template.chargeable_field = chargeable_field
rate_detail_template.description = "Allocated CPU Cores"
rate_detail_template.per_unit = "cpu core"
Expand Down
11 changes: 11 additions & 0 deletions spec/automated_review/empty_database_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
describe "Empty Database" do
it "after migrated remains empty" do
counts = ActiveRecord::Base.connection.tables.each_with_object([]) do |t, array|
next if ManageIQ::Schema::SYSTEM_TABLES.include?(t)
count = ActiveRecord::Base.connection.execute("SELECT COUNT(*) FROM #{t};").getvalue(0, 0)
array << "#{t}: #{count}" if count.positive?
end

expect(counts.size).to eq(0), "Records were found in the following tables:\n#{counts.join("\n")}"
end
end

0 comments on commit 3889554

Please sign in to comment.