Commit ab4120de authored by Alexis Reigel's avatar Alexis Reigel

only validate gpg_key#fingerprint "internally"

parent 7b7cd6f6
......@@ -3,17 +3,21 @@ class GpgKey < ActiveRecord::Base
belongs_to :user
validates :fingerprint,
presence: true,
uniqueness: true
validates :key,
presence: true,
uniqueness: true,
format: {
with: /\A#{KEY_PREFIX}((?!#{KEY_PREFIX}).)+\Z/m
with: /\A#{KEY_PREFIX}((?!#{KEY_PREFIX}).)+\Z/m,
message: "is invalid. A valid public GPG key begins with '#{KEY_PREFIX}'"
}
validates :fingerprint,
presence: true,
uniqueness: true,
# only validate when the `key` is valid, as we don't want the user to show
# the error about the fingerprint
unless: -> { errors.has_key?(:key) }
before_validation :extract_fingerprint
def key=(value)
......
......@@ -6,8 +6,6 @@ describe GpgKey do
end
describe "validation" do
it { is_expected.to validate_presence_of(:fingerprint) }
it { is_expected.to validate_presence_of(:key) }
it { is_expected.to validate_uniqueness_of(:key) }
it { is_expected.to allow_value("-----BEGIN PGP PUBLIC KEY BLOCK-----\nkey").for(:key) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment