Skip to content

Commit

Permalink
Silences db/seeds output when running specs
Browse files Browse the repository at this point in the history
  • Loading branch information
scottolsen committed Dec 12, 2020
1 parent 9f89559 commit a4dbb60
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def initialize
end

def seed
puts "Erasing all objects from the database..."
log "Erasing all objects from the database..."
destroy_all

puts "Creating the objects in the database..."
log "Creating the objects in the database..."
db_populator.create_all_casa_admin("[email protected]")
db_populator.create_all_casa_admin("[email protected]")
db_populator.create_org(CasaOrgPopulatorPresets.for_environment.merge({org_name: "Prince George CASA"}))
Expand All @@ -35,7 +35,7 @@ def seed
post_process_data

report_object_counts
puts "\nDone.\n\n"
log "\nDone.\n\n"
end

private # -------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -78,23 +78,29 @@ def get_seed_specification

if seed_environment_value.blank?
seed = 0
puts "\nENV['DB_SEEDS_RANDOM_SEED'] not set to 'random' or a number; setting seed to 0.\n\n"
log "\nENV['DB_SEEDS_RANDOM_SEED'] not set to 'random' or a number; setting seed to 0.\n\n"
elsif seed_environment_value.casecmp("random") == 0
seed = Random.new_seed
puts "\n'random' specified in ENV['DB_SEEDS_RANDOM_SEED']; setting seed to randomly generated value #{seed}.\n\n"
log "\n'random' specified in ENV['DB_SEEDS_RANDOM_SEED']; setting seed to randomly generated value #{seed}.\n\n"
else
seed = seed_environment_value.to_i
puts "\nUsing random seed #{seed} specified in ENV['DB_SEEDS_RANDOM_SEED'].\n\n"
log "\nUsing random seed #{seed} specified in ENV['DB_SEEDS_RANDOM_SEED'].\n\n"
end
seed
end

def report_object_counts
puts "\nRecords written to the DB:\n\nCount Class Name\n----- ----------\n\n"
log "\nRecords written to the DB:\n\nCount Class Name\n----- ----------\n\n"
active_record_classes.each do |klass|
puts "%5d %s" % [klass.count, klass.name]
log "%5d %s" % [klass.count, klass.name]
end
end

def log(message)
return if Rails.env.test?

puts message
end
end

SeederMain.new.seed
Expand Down

0 comments on commit a4dbb60

Please sign in to comment.