summaryrefslogtreecommitdiff
path: root/app/models/key.rb
diff options
context:
space:
mode:
authorSemyon Pupkov <mail@semyonpupkov.com>2016-11-16 00:16:45 +0500
committerSemyon Pupkov <mail@semyonpupkov.com>2016-11-16 00:59:09 +0500
commit34a86120ed52b5e77ef2cd51a60bed1208671639 (patch)
treeb569a92807fb203ec3f1f8b3d1ad0564e3fd8c74 /app/models/key.rb
parentd5cd0d67f1504d773500fd1605a05ed6c1320cb3 (diff)
downloadgitlab-ce-34a86120ed52b5e77ef2cd51a60bed1208671639.tar.gz
Use setter for key instead AR callback
ref: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6763
Diffstat (limited to 'app/models/key.rb')
-rw-r--r--app/models/key.rb7
1 files changed, 4 insertions, 3 deletions
diff --git a/app/models/key.rb b/app/models/key.rb
index 568a60b8af3..ff8dda2dc89 100644
--- a/app/models/key.rb
+++ b/app/models/key.rb
@@ -6,7 +6,7 @@ class Key < ActiveRecord::Base
belongs_to :user
- before_validation :strip_white_space, :generate_fingerprint
+ before_validation :generate_fingerprint
validates :title, presence: true, length: { within: 0..255 }
validates :key, presence: true, length: { within: 0..5000 }, format: { with: /\A(ssh|ecdsa)-.*\Z/ }
@@ -21,8 +21,9 @@ class Key < ActiveRecord::Base
after_destroy :remove_from_shell
after_destroy :post_destroy_hook
- def strip_white_space
- self.key = key.strip unless key.blank?
+ def key=(value)
+ value.strip! unless value.blank?
+ write_attribute(:key, value)
end
def publishable_key