Class: TestData::Configuration
- Inherits:
-
Object
- Object
- TestData::Configuration
- Defined in:
- lib/test_data/config.rb
Instance Attribute Summary collapse
-
#after_rails_fixture_load_hook ⇒ Object
readonly
Returns the value of attribute after_rails_fixture_load_hook.
-
#after_test_data_load_hook ⇒ Object
readonly
Returns the value of attribute after_test_data_load_hook.
-
#after_test_data_truncate_hook ⇒ Object
readonly
Returns the value of attribute after_test_data_truncate_hook.
-
#cable_yaml_path ⇒ Object
readonly
Returns the value of attribute cable_yaml_path.
-
#data_dump_path ⇒ Object
Where to save dumps of your test data.
-
#database_yaml_path ⇒ Object
readonly
Returns the value of attribute database_yaml_path.
-
#dont_dump_these_tables ⇒ Object
Tables to exclude from all dumps.
-
#non_test_data_dump_path ⇒ Object
Where to save dumps of data needed by the test_data env but excluded from your tests.
- #non_test_data_tables ⇒ Object
-
#pwd ⇒ Object
readonly
Returns the value of attribute pwd.
-
#schema_dump_path ⇒ Object
Where to save dumps of your test data’s schema.
-
#secrets_yaml_path ⇒ Object
readonly
Returns the value of attribute secrets_yaml_path.
-
#truncate_these_test_data_tables ⇒ Object
Tables to truncate when TestData.uses_clean_slate is called.
Class Method Summary collapse
Instance Method Summary collapse
- #after_rails_fixture_load(callable = nil, &blk) ⇒ Object
- #after_test_data_load(callable = nil, &blk) ⇒ Object
- #after_test_data_truncate(callable = nil, &blk) ⇒ Object
- #database_name ⇒ Object
- #database_yaml ⇒ Object
-
#initialize(pwd:) ⇒ Configuration
constructor
A new instance of Configuration.
-
#log_level ⇒ Object
Log level (valid values: [:debug, :info, :warn, :error, :quiet]).
- #log_level=(level) ⇒ Object
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_hook ⇒ Object (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_hook ⇒ Object (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_hook ⇒ Object (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_path ⇒ Object (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_path ⇒ Object
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_path ⇒ Object (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_tables ⇒ Object
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_path ⇒ Object
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_tables ⇒ Object
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 |
#pwd ⇒ Object (readonly)
Returns the value of attribute pwd.
44 45 46 |
# File 'lib/test_data/config.rb', line 44 def pwd @pwd end |
#schema_dump_path ⇒ Object
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_path ⇒ Object (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_tables ⇒ Object
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_name ⇒ Object
101 102 103 |
# File 'lib/test_data/config.rb', line 101 def database_name database_yaml.dig("test_data", "database") end |
#database_yaml ⇒ Object
97 98 99 |
# File 'lib/test_data/config.rb', line 97 def database_yaml YAML.load_file(database_yaml_full_path) end |