Skip to content

Commit

Permalink
Merge pull request #228 from Shopify/record-errors
Browse files Browse the repository at this point in the history
Report errors correctly for ActiveModel 7.x
  • Loading branch information
sbfaulkner committed Feb 12, 2024
2 parents 9b29045 + a82e3b3 commit cf1dd10
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
3 changes: 3 additions & 0 deletions 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

Expand Down
6 changes: 4 additions & 2 deletions lib/record_store/cli.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/record_store/version.rb
@@ -1,3 +1,3 @@
module RecordStore
VERSION = '6.7.1'.freeze
VERSION = '6.7.2'.freeze
end
47 changes: 47 additions & 0 deletions test/cli_test.rb
Expand Up @@ -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

0 comments on commit cf1dd10

Please sign in to comment.