From cd69a7deb5726eb9321e9727008ed98049d8a416 Mon Sep 17 00:00:00 2001 From: "S. Brent Faulkner" Date: Mon, 12 Feb 2024 13:25:53 -0500 Subject: [PATCH 1/3] add test for invalid record error messages --- test/cli_test.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/test/cli_test.rb b/test/cli_test.rb index 3555007..bf940a7 100644 --- a/test/cli_test.rb +++ b/test/cli_test.rb @@ -60,8 +60,55 @@ def test_applies_no_changes_if_any_zone_invalid # pass: CLI is expected to `abort`. Prevent the Minitest reporter from dying. end + def test_validate_records_reports_record_errors + with_configuration(zones: ["invalid.com"]) do |config_path, zones_path| + zone_path = File.join(zones_path, "invalid.com.yml") + zone_yaml = <<~YAML + invalid.com: + config: + providers: + - DNSimple + records: + - type: TXT + fqdn: invalid.com. + ttl: "3600" + txtdata: "asdf;asdf" + YAML + + File.write(zone_path, zone_yaml) + + RecordStore::CLI.start(["validate_records", "--config", config_path]) + end + + assert_equal("The following zones were invalid: invalid.com\n", $stderr.string) + + assert_equal(<<~ERROR, $stdout.string) + invalid.com definition is not valid: + - Records invalid record: [TXTRecord] invalid.com. 3600 IN TXT "asdf;asdf" + Invalid records + [TXTRecord] invalid.com. 3600 IN TXT "asdf;asdf" + - txtdata: has unescaped semicolons (See RFC 1035). + ERROR + end + def test_returns_nonzero_exit_status Thor.expects(:exit).with(false) RecordStore::CLI.start(%w(does not exist)) end + + private + + def with_configuration(zones: []) + Dir.mktmpdir do |dir| + config_path = File.join(dir, "config.yml") + zones_path = File.join(dir, "zones") + + Dir.mkdir(zones_path) + File.write(config_path, build_record_store_config(zones_path: zones_path, zones: zones)) + + yield config_path, zones_path + end + rescue SystemExit + # pass: CLI is expected to `abort`. Prevent the Minitest reporter from dying. + end end From ca63daaac55a3ee1090ac7dee54c0263a40b3e59 Mon Sep 17 00:00:00 2001 From: "S. Brent Faulkner" Date: Mon, 12 Feb 2024 13:36:26 -0500 Subject: [PATCH 2/3] support newer activemodel errors correctly --- lib/record_store/cli.rb | 6 ++++-- test/cli_test.rb | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/record_store/cli.rb b/lib/record_store/cli.rb index 53e82dd..a141f34 100644 --- a/lib/record_store/cli.rb +++ b/lib/record_store/cli.rb @@ -289,8 +289,10 @@ def validate_records invalid_records.each do |record| puts " #{record}" - record.errors.each do |field, msg| - puts " - #{field}: #{msg}" + record.errors.messages.each do |field, errors| + errors.each do |msg| + puts " - #{field}: #{msg}" + end end end end diff --git a/test/cli_test.rb b/test/cli_test.rb index bf940a7..a839a81 100644 --- a/test/cli_test.rb +++ b/test/cli_test.rb @@ -71,7 +71,7 @@ def test_validate_records_reports_record_errors records: - type: TXT fqdn: invalid.com. - ttl: "3600" + ttl: 3600 txtdata: "asdf;asdf" YAML From a82e3b3a6f03366fd3250c483f5cff6b896f8400 Mon Sep 17 00:00:00 2001 From: "S. Brent Faulkner" Date: Mon, 12 Feb 2024 13:38:38 -0500 Subject: [PATCH 3/3] version bump --- CHANGELOG.md | 3 +++ lib/record_store/version.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0207fc..c041bda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # CHANGELOG +## 6.7.2 +- Fix ActiveModel::Error usage for validate_records (behaviour change in ActiveModel 7) + # 6.7.1 - Change update_record to update_zone_record for DNSimple diff --git a/lib/record_store/version.rb b/lib/record_store/version.rb index 1bcf07a..b69e60f 100644 --- a/lib/record_store/version.rb +++ b/lib/record_store/version.rb @@ -1,3 +1,3 @@ module RecordStore - VERSION = '6.7.1'.freeze + VERSION = '6.7.2'.freeze end