forked from rubyforgood/casa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Silences db/seeds output when running specs
Resolves rubyforgood#1447
- Loading branch information
1 parent
9f89559
commit a4dbb60
Showing
1 changed file
with
14 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"})) | ||
|
@@ -35,7 +35,7 @@ def seed | |
post_process_data | ||
|
||
report_object_counts | ||
puts "\nDone.\n\n" | ||
log "\nDone.\n\n" | ||
end | ||
|
||
private # ------------------------------------------------------------------------------------------------------- | ||
|
@@ -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 | ||
|