add emails method to GgpKey

This commit is contained in:
Alexis Reigel 2017-02-22 15:37:49 +01:00
parent fbf1fd1a20
commit 7b7cd6f69d
3 changed files with 20 additions and 0 deletions

View file

@ -21,6 +21,11 @@ class GpgKey < ActiveRecord::Base
write_attribute(:key, value)
end
def emails
raw_key = GPGME::Key.get(fingerprint)
raw_key.uids.map(&:email)
end
private
def extract_fingerprint

View file

@ -0,0 +1,7 @@
require_relative '../support/gpg_helpers'
FactoryGirl.define do
factory :gpg_key do
key GpgHelpers.public_key
end
end

View file

@ -38,4 +38,12 @@ describe GpgKey do
expect(described_class.new(key: " #{key} ").key).to eq(key)
end
end
describe '#emails' do
it 'returns the emails from the gpg key' do
gpg_key = create :gpg_key
expect(gpg_key.emails).to match_array %w(mail@koffeinfrei.org lex@panter.ch)
end
end
end