From fcdc24a78c4adc3036d50cb169df11a5e04f76c0 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sat, 14 Apr 2018 20:28:43 +0200 Subject: [PATCH] Avoid db:dev_seed log print when run from its test The db:dev_seed rake logs info as it progresses as information for the developer. But that's not needed when ran from its tests file, and it bloats the travis/rspec output with unnecessary information. Now the task will always log info unless the rake task receives an optional argument. --- db/dev_seeds.rb | 4 +++- lib/tasks/db.rake | 3 ++- spec/lib/tasks/dev_seed_spec.rb | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 217047426..35aa3168c 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -1,7 +1,9 @@ require 'database_cleaner' DatabaseCleaner.clean_with :truncation @logger = Logger.new(STDOUT) -@logger.formatter = proc { |_severity, _datetime, _progname, msg| msg } +@logger.formatter = proc do |_severity, _datetime, _progname, msg| + msg unless @avoid_log + end def section(section_title) @logger.info section_title diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index 9731a23ef..0c036c609 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -1,6 +1,7 @@ namespace :db do desc "Resets the database and loads it from db/dev_seeds.rb" - task dev_seed: :environment do + task :dev_seed, [:print_log] => [:environment] do |t, args| + @avoid_log = args[:print_log] == "avoid_log" load(Rails.root.join("db", "dev_seeds.rb")) end end diff --git a/spec/lib/tasks/dev_seed_spec.rb b/spec/lib/tasks/dev_seed_spec.rb index b03d6f3d2..d3e69f4b9 100644 --- a/spec/lib/tasks/dev_seed_spec.rb +++ b/spec/lib/tasks/dev_seed_spec.rb @@ -5,7 +5,7 @@ Rake.application.rake_require('tasks/db') describe 'rake db:dev_seed' do let :run_rake_task do - Rake.application.invoke_task('db:dev_seed') + Rake.application.invoke_task('db:dev_seed[avoid_log]') end it 'seeds the database without errors' do