Skip to content

Commit

Permalink
Merge pull request #8 from thewatts/fix-yaml-loading
Browse files Browse the repository at this point in the history
Fix yaml loading
  • Loading branch information
radglob authored Jan 19, 2024
2 parents 23a5900 + 8200c85 commit 73db6b9
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/test_data/config.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative "./yaml_loader"

module TestData
def self.config(pwd: Rails.root, &blk)
@configuration ||= Configuration.new(pwd: pwd)
Expand Down Expand Up @@ -95,7 +97,7 @@ def after_rails_fixture_load(callable = nil, &blk)
end

def database_yaml
YAML.load_file(database_yaml_full_path)
YAMLLoader.load_file(database_yaml_full_path)
end

def database_name
Expand Down
4 changes: 3 additions & 1 deletion lib/test_data/configurators/cable_yaml.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative "../yaml_loader"

module TestData
module Configurators
class CableYaml
Expand All @@ -8,7 +10,7 @@ def initialize

def verify
if !File.exist?(@config.cable_yaml_full_path) ||
YAML.load_file(@config.cable_yaml_full_path).key?("test_data")
YAMLLoader.load_file(@config.cable_yaml_full_path).key?("test_data")
ConfigurationVerification.new(looks_good?: true)
else
ConfigurationVerification.new(problems: [
Expand Down
4 changes: 3 additions & 1 deletion lib/test_data/configurators/secrets_yaml.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative "../yaml_loader"

module TestData
module Configurators
class SecretsYaml
Expand All @@ -8,7 +10,7 @@ def initialize

def verify
if !File.exist?(@config.secrets_yaml_full_path) ||
YAML.load_file(@config.secrets_yaml_full_path).key?("test_data")
YAMLLoader.load_file(@config.secrets_yaml_full_path).key?("test_data")
ConfigurationVerification.new(looks_good?: true)
else
ConfigurationVerification.new(problems: [
Expand Down
2 changes: 1 addition & 1 deletion lib/test_data/dumps_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def prepend_set_replication_role!(data_dump_path)

def log_size_info_and_warnings(before_size:, after_size:)
percent_change = percent_change(before_size, after_size)
TestData.log.info " Size: #{to_size(after_size)}#{" (#{percent_change}% #{before_size > after_size ? "decrease" : "increase"})" if percent_change}"
TestData.log.info " Size: #{to_size(after_size)}#{" (#{percent_change}% #{(before_size > after_size) ? "decrease" : "increase"})" if percent_change}"
if after_size > 5242880
TestData.log.warn " WARNING: file size exceeds 5MB. Be sure to only persist what data you need to sufficiently test your application"
end
Expand Down
4 changes: 3 additions & 1 deletion lib/test_data/wrap/webpacker_config.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative "../yaml_loader"

module TestData
module Wrap
class WebpackerConfig
Expand Down Expand Up @@ -34,7 +36,7 @@ def required_entries_missing_from_test_data_config
private

def load_yaml(path)
YAML.load_file(path)
YAMLLoader.load_file(path)
rescue
end
end
Expand Down
11 changes: 11 additions & 0 deletions lib/test_data/yaml_loader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module TestData
module YAMLLoader
def self.load_file(path)
begin
YAML.load_file(path, aliases: true)
rescue ArgumentError
YAML.load_file(path)
end
end
end
end

0 comments on commit 73db6b9

Please sign in to comment.