diff --git a/app/models/dnskey.rb b/app/models/dnskey.rb index 58d4d9e31..e9e15802f 100644 --- a/app/models/dnskey.rb +++ b/app/models/dnskey.rb @@ -60,19 +60,19 @@ class Dnskey < ApplicationRecord def validate_algorithm return if alg.blank? return if ALGORITHMS.include?(alg.to_s) - errors.add(:alg, :invalid, values: ALGORITHMS.join(', ')) + errors.add(:alg, :invalid, values: "Valid algorithms are: #{ALGORITHMS.join(', ')}") end def validate_protocol return if protocol.blank? return if PROTOCOLS.include?(protocol.to_s) - errors.add(:protocol, :invalid, values: PROTOCOLS.join(', ')) + errors.add(:protocol, :invalid, values: "Valid protocols are: #{PROTOCOLS.join(', ')}") end def validate_flags return if flags.blank? return if FLAGS.include?(flags.to_s) - errors.add(:flags, :invalid, values: FLAGS.join(', ')) + errors.add(:flags, :invalid, values: "Valid flags are: #{FLAGS.join(', ')}") end def generate_digest diff --git a/test/models/dnskey_test.rb b/test/models/dnskey_test.rb index 2f4eff3af..57869309c 100644 --- a/test/models/dnskey_test.rb +++ b/test/models/dnskey_test.rb @@ -15,29 +15,29 @@ class DnskeyTest < ActiveSupport::TestCase dns.protocol = 3 dns.alg = 8 dns.public_key = @dnskey - + assert dns.save end def test_invalid_algrorithm dns = Dnskey.new dns.alg = 666 - errors = dns.validate_algorithm - assert_equal errors, ['Valid algorithms are: 3, 5, 6, 7, 8, 10, 13, 14'] + errors = dns.validate_algorithm.options[:values] + assert_equal errors, 'Valid algorithms are: 3, 5, 6, 7, 8, 10, 13, 14' end def test_invalid_protocol dns = Dnskey.new dns.protocol = 666 - errors = dns.validate_protocol - assert_equal errors, ['Valid protocols are: 3'] + errors = dns.validate_protocol.options[:values] + assert_equal errors, 'Valid protocols are: 3' end def test_invalid_flags dns = Dnskey.new dns.flags = 666 - errors = dns.validate_flags - assert_equal errors, ['Valid flags are: 0, 256, 257'] + errors = dns.validate_flags.options[:values] + assert_equal errors, 'Valid flags are: 0, 256, 257' end def test_ds_digest_type_one @@ -49,10 +49,10 @@ class DnskeyTest < ActiveSupport::TestCase dns.protocol = 3 dns.alg = 8 dns.public_key = @dnskey - + assert dns.save assert_equal dns.ds_digest_type, 1 assert_equal dns.ds_digest, '640D173A44D9AF2856FBE282EE64CE11A76DBB84' end -end \ No newline at end of file +end