diff --git a/app/models/gpg_key.rb b/app/models/gpg_key.rb index 0d35baa7ade..009a93ce1a8 100644 --- a/app/models/gpg_key.rb +++ b/app/models/gpg_key.rb @@ -46,8 +46,7 @@ class GpgKey < ActiveRecord::Base end def key=(value) - value.strip! unless value.blank? - write_attribute(:key, value) + super(value&.strip) end def user_infos diff --git a/spec/models/gpg_key_spec.rb b/spec/models/gpg_key_spec.rb index 06bdbb59a11..1242f0b2e2a 100644 --- a/spec/models/gpg_key_spec.rb +++ b/spec/models/gpg_key_spec.rb @@ -44,6 +44,10 @@ describe GpgKey do expect(described_class.new(key: " #{key} ").key).to eq(key) end + + it 'does not strip when the key is nil' do + expect(described_class.new(key: nil).key).to be_nil + end end describe '#user_infos' do