Module: TestData

Defined in:
lib/test_data.rb,
lib/test_data/log.rb,
lib/test_data/error.rb,
lib/test_data/config.rb,
lib/test_data/manager.rb,
lib/test_data/railtie.rb,
lib/test_data/version.rb,
lib/test_data/save_point.rb,
lib/test_data/statistics.rb,
lib/test_data/configurators.rb,
lib/test_data/dumps_database.rb,
lib/test_data/active_record_ext.rb,
lib/test_data/generator_support.rb,
lib/test_data/inserts_test_data.rb,
lib/test_data/truncates_test_data.rb,
lib/test_data/loads_database_dumps.rb,
lib/test_data/records_dump_metadata.rb,
lib/test_data/wrap/webpacker_config.rb,
lib/test_data/installs_configuration.rb,
lib/test_data/verifies_configuration.rb,
lib/test_data/configurators/cable_yaml.rb,
lib/test_data/configurators/initializer.rb,
lib/test_data/configuration_verification.rb,
lib/test_data/configurators/secrets_yaml.rb,
lib/test_data/detects_database_emptiness.rb,
lib/test_data/detects_database_existence.rb,
lib/test_data/configurators/database_yaml.rb,
lib/test_data/verifies_dumps_are_loadable.rb,
lib/test_data/configurators/webpacker_yaml.rb,
lib/test_data/custom_loaders/abstract_base.rb,
lib/test_data/custom_loaders/rails_fixtures.rb,
lib/test_data/configurators/environment_file.rb,
lib/generators/test_data/cable_yaml_generator.rb,
lib/generators/test_data/initializer_generator.rb,
lib/generators/test_data/secrets_yaml_generator.rb,
lib/test_data/determines_when_sql_dump_was_made.rb,
lib/generators/test_data/database_yaml_generator.rb,
lib/generators/test_data/webpacker_yaml_generator.rb,
lib/test_data/warns_if_database_is_newer_than_dump.rb,
lib/test_data/warns_if_dump_is_newer_than_database.rb,
lib/generators/test_data/environment_file_generator.rb,
lib/test_data/determines_databases_associated_dump_time.rb

Defined Under Namespace

Modules: Configurators, CustomLoaders, Wrap Classes: CableYamlGenerator, Configuration, ConfigurationVerification, DatabaseYamlGenerator, DetectsDatabaseEmptiness, DetectsDatabaseExistence, DeterminesDatabasesAssociatedDumpTime, DeterminesWhenSqlDumpWasMade, DumpsDatabase, EnvironmentFileGenerator, Error, InitializerGenerator, InsertsTestData, InstallsConfiguration, LoadsDatabaseDumps, Log, Manager, Railtie, RecordsDumpMetadata, SavePoint, SecretsYamlGenerator, Statistics, TruncatesTestData, VerifiesConfiguration, VerifiesDumpsAreLoadable, WarnsIfDatabaseIsNewerThanDump, WarnsIfDumpIsNewerThanDatabase, WebpackerYamlGenerator

Constant Summary collapse

VERSION =
"0.3.2"
BEFORE_TEST_STANZA_REGEX =
/^$\n(?:^\#.*\n)*^test:/

Class Method Summary collapse

Class Method Details

.config(pwd: Rails.root, &blk) ⇒ Object



2
3
4
5
6
7
8
# File 'lib/test_data/config.rb', line 2

def self.config(pwd: Rails.root, &blk)
  @configuration ||= Configuration.new(pwd: pwd)

  @configuration.tap do |config|
    blk&.call(config)
  end
end

.insert_test_data_dumpObject



69
70
71
72
# File 'lib/test_data.rb', line 69

def self.insert_test_data_dump
  InsertsTestData.new.call
  nil
end

.logObject



2
3
4
# File 'lib/test_data/log.rb', line 2

def self.log
  @log ||= Log.new
end

.prevent_rails_fixtures_from_loading_automatically!Object



2
3
4
5
6
7
8
9
10
# File 'lib/test_data/active_record_ext.rb', line 2

def self.prevent_rails_fixtures_from_loading_automatically!
  ActiveRecord::TestFixtures.define_method(:__test_data_gem_setup_fixtures,
    ActiveRecord::TestFixtures.instance_method(:setup_fixtures))
  ActiveRecord::TestFixtures.remove_method(:setup_fixtures)
  ActiveRecord::TestFixtures.define_method(:setup_fixtures, ->(config = nil) {})

  ActiveRecord::TestFixtures.remove_method(:teardown_fixtures)
  ActiveRecord::TestFixtures.define_method(:teardown_fixtures, -> {})
end

.statisticsObject



2
3
4
# File 'lib/test_data/statistics.rb', line 2

def self.statistics
  @statistics ||= Statistics.new
end

.uninitializeObject



44
45
46
47
48
# File 'lib/test_data.rb', line 44

def self.uninitialize
  @manager ||= Manager.new
  @manager.rollback_to_before_data_load
  nil
end

.uses_clean_slateObject



56
57
58
59
60
# File 'lib/test_data.rb', line 56

def self.uses_clean_slate
  @manager ||= Manager.new
  @manager.truncate
  nil
end

.uses_rails_fixtures(test_instance) ⇒ Object



62
63
64
65
66
67
# File 'lib/test_data.rb', line 62

def self.uses_rails_fixtures(test_instance)
  @rails_fixtures_loader ||= CustomLoaders::RailsFixtures.new
  @manager ||= Manager.new
  @manager.load_custom_data(@rails_fixtures_loader, test_instance: test_instance)
  nil
end

.uses_test_dataObject



50
51
52
53
54
# File 'lib/test_data.rb', line 50

def self.uses_test_data
  @manager ||= Manager.new
  @manager.load
  nil
end