Class: TestData::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/test_data/config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pwd:) ⇒ Configuration

Returns a new instance of Configuration.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/test_data/config.rb', line 57

def initialize(pwd:)
  @pwd = pwd
  @schema_dump_path = "test/support/test_data/schema.sql"
  @data_dump_path = "test/support/test_data/data.sql"
  @non_test_data_dump_path = "test/support/test_data/non_test_data.sql"
  @cable_yaml_path = "config/cable.yml"
  @database_yaml_path = "config/database.yml"
  @secrets_yaml_path = "config/secrets.yml"
  @non_test_data_tables = []
  @dont_dump_these_tables = []
  @truncate_these_test_data_tables = nil
  @after_test_data_load_hook = -> {}
  @after_test_data_truncate_hook = -> {}
  @after_rails_fixture_load_hook = -> {}
end

Instance Attribute Details

#after_rails_fixture_load_hookObject (readonly)

Returns the value of attribute after_rails_fixture_load_hook.



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

def after_rails_fixture_load_hook
  @after_rails_fixture_load_hook
end

#after_test_data_load_hookObject (readonly)

Returns the value of attribute after_test_data_load_hook.



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

def after_test_data_load_hook
  @after_test_data_load_hook
end

#after_test_data_truncate_hookObject (readonly)

Returns the value of attribute after_test_data_truncate_hook.



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

def after_test_data_truncate_hook
  @after_test_data_truncate_hook
end

#cable_yaml_pathObject (readonly)

Returns the value of attribute cable_yaml_path.



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

def cable_yaml_path
  @cable_yaml_path
end

#data_dump_pathObject

Where to save dumps of your test data



15
16
17
# File 'lib/test_data/config.rb', line 15

def data_dump_path
  @data_dump_path
end

#database_yaml_pathObject (readonly)

Returns the value of attribute database_yaml_path.



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

def database_yaml_path
  @database_yaml_path
end

#dont_dump_these_tablesObject

Tables to exclude from all dumps



30
31
32
# File 'lib/test_data/config.rb', line 30

def dont_dump_these_tables
  @dont_dump_these_tables
end

#non_test_data_dump_pathObject

Where to save dumps of data needed by the test_data env but excluded from your tests



18
19
20
# File 'lib/test_data/config.rb', line 18

def non_test_data_dump_path
  @non_test_data_dump_path
end

#non_test_data_tablesObject



22
23
24
25
26
27
# File 'lib/test_data/config.rb', line 22

def non_test_data_tables
  (@non_test_data_tables + [
    ActiveRecord::Base.connection.schema_migration.table_name,
    ActiveRecord::InternalMetadata.table_name
  ]).uniq
end

#pwdObject (readonly)

Returns the value of attribute pwd.



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

def pwd
  @pwd
end

#schema_dump_pathObject

Where to save dumps of your test data’s schema



12
13
14
# File 'lib/test_data/config.rb', line 12

def schema_dump_path
  @schema_dump_path
end

#secrets_yaml_pathObject (readonly)

Returns the value of attribute secrets_yaml_path.



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

def secrets_yaml_path
  @secrets_yaml_path
end

#truncate_these_test_data_tablesObject

Tables to truncate when TestData.uses_clean_slate is called



33
34
35
# File 'lib/test_data/config.rb', line 33

def truncate_these_test_data_tables
  @truncate_these_test_data_tables
end

Class Method Details

.full_path_reader(*relative_path_readers) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/test_data/config.rb', line 47

def self.full_path_reader(*relative_path_readers)
  relative_path_readers.each do |relative_path_reader|
    define_method(relative_path_reader.to_s.gsub(/_path$/, "_full_path")) do
      "#{pwd}/#{send(relative_path_reader)}"
    end
  end
end

Instance Method Details

#after_rails_fixture_load(callable = nil, &blk) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/test_data/config.rb', line 89

def after_rails_fixture_load(callable = nil, &blk)
  hook = callable || blk
  if !hook.respond_to?(:call)
    raise Error.new("after_rails_fixture_load must be passed a callable (e.g. a Proc) or called with a block")
  end
  @after_rails_fixture_load_hook = hook
end

#after_test_data_load(callable = nil, &blk) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/test_data/config.rb', line 73

def after_test_data_load(callable = nil, &blk)
  hook = callable || blk
  if !hook.respond_to?(:call)
    raise Error.new("after_test_data_load must be passed a callable (e.g. a Proc) or called with a block")
  end
  @after_test_data_load_hook = hook
end

#after_test_data_truncate(callable = nil, &blk) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/test_data/config.rb', line 81

def after_test_data_truncate(callable = nil, &blk)
  hook = callable || blk
  if !hook.respond_to?(:call)
    raise Error.new("after_test_data_truncate must be passed a callable (e.g. a Proc) or called with a block")
  end
  @after_test_data_truncate_hook = hook
end

#database_nameObject



101
102
103
# File 'lib/test_data/config.rb', line 101

def database_name
  database_yaml.dig("test_data", "database")
end

#database_yamlObject



97
98
99
# File 'lib/test_data/config.rb', line 97

def database_yaml
  YAML.load_file(database_yaml_full_path)
end

#log_levelObject

Log level (valid values: [:debug, :info, :warn, :error, :quiet])



36
37
38
# File 'lib/test_data/config.rb', line 36

def log_level
  TestData.log.level
end

#log_level=(level) ⇒ Object



40
41
42
# File 'lib/test_data/config.rb', line 40

def log_level=(level)
  TestData.log.level = level
end