Class: TestData::DatabaseYamlGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/test_data/database_yaml_generator.rb

Instance Method Summary collapse

Instance Method Details

#callObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/generators/test_data/database_yaml_generator.rb', line 6

def call
  if Configurators::DatabaseYaml.new.verify.looks_good?
    TestData.log.info "'test_data' section already defined in config/database.yml"
  else
    app_name = Rails.application.railtie_name.chomp("_application")
    inject_into_file "config/database.yml", before: BEFORE_TEST_STANZA_REGEX do
      <<~YAML

        # Used in conjunction with the test_data gem
        test_data:
          <<: *default
          database: #{app_name}_test_data
      YAML
    end
  end
end