Class: RebuildRailsAppDatabase

Inherits:
RspecStarterTask show all
Defined in:
lib/rspec_starter/tasks/rebuild_rails_app_database.rb

Overview

Rebuild the database for a rails application or a rails engine. This task honors the following command line options

--skip-db-prep    Causes the task to be skipped

Instance Attribute Summary

Attributes inherited from RspecStarterStep

#exit_status, #id, #name, #options, #quiet, #run_time, #runner, #successful

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RspecStarterTask

name_for_class, register_option

Methods inherited from RspecStarterStep

default_quiet, default_stop_on_problem, #failed?, #helpers, #initialize, provide_options_to, #quiet?, #run, #stop_on_problem?, #verbose?

Constructor Details

This class inherits a constructor from RspecStarterStep

Class Method Details

.descriptionObject



4
5
6
# File 'lib/rspec_starter/tasks/rebuild_rails_app_database.rb', line 4

def self.description
  "Rebuild a Ruby on Rails application or engine database."
end

.register_optionsObject



8
9
10
11
12
13
14
# File 'lib/rspec_starter/tasks/rebuild_rails_app_database.rb', line 8

def self.register_options
  register_option default: false, switch: '--skip-db-prep',
    switch_description: "DO NOT prepare the Rails application database"
  register_option name: "command",
    default: "DISABLE_DATABASE_ENVIRONMENT_CHECK=1 RAILS_ENV=test rake db:drop db:create db:schema:load",
    description: "A command string that is used to rebuild the database."
end

Instance Method Details

#executeObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rspec_starter/tasks/rebuild_rails_app_database.rb', line 24

def execute
  if quiet?
    @stdout, @stderr, @status = Open3.capture3(options.command)
  else
    puts "\n\n"
    @verbose_command_passed = system options.command
    @status = $CHILD_STATUS
    print @starting_message
  end
  problem if command_failed?
end

#should_skip?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/rspec_starter/tasks/rebuild_rails_app_database.rb', line 16

def should_skip?
  options.skip_db_prep || options.command.nil? || options.command.empty?
end

#starting_messageObject



20
21
22
# File 'lib/rspec_starter/tasks/rebuild_rails_app_database.rb', line 20

def starting_message
  "Running #{options.command.highlight}"
end

#write_error_infoObject



36
37
38
39
40
41
# File 'lib/rspec_starter/tasks/rebuild_rails_app_database.rb', line 36

def write_error_info
  puts @stdout
  puts @stderr
  puts "\n\nThere was an error rebuilding the test database.  See the output above for details " \
       "or manually run '#{options.command}' for more information.".colorize(:red)
end