Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
34a86120
Commit
34a86120
authored
Nov 16, 2016
by
Semyon Pupkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use setter for key instead AR callback
ref:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6763
parent
d5cd0d67
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
3 deletions
+18
-3
app/models/key.rb
app/models/key.rb
+4
-3
changelogs/unreleased/setter-for-key.yml
changelogs/unreleased/setter-for-key.yml
+4
-0
spec/models/key_spec.rb
spec/models/key_spec.rb
+10
-0
No files found.
app/models/key.rb
View file @
34a86120
...
@@ -6,7 +6,7 @@ class Key < ActiveRecord::Base
...
@@ -6,7 +6,7 @@ class Key < ActiveRecord::Base
belongs_to
:user
belongs_to
:user
before_validation
:
strip_white_space
,
:
generate_fingerprint
before_validation
:generate_fingerprint
validates
:title
,
presence:
true
,
length:
{
within:
0
..
255
}
validates
:title
,
presence:
true
,
length:
{
within:
0
..
255
}
validates
:key
,
presence:
true
,
length:
{
within:
0
..
5000
},
format:
{
with:
/\A(ssh|ecdsa)-.*\Z/
}
validates
:key
,
presence:
true
,
length:
{
within:
0
..
5000
},
format:
{
with:
/\A(ssh|ecdsa)-.*\Z/
}
...
@@ -21,8 +21,9 @@ class Key < ActiveRecord::Base
...
@@ -21,8 +21,9 @@ class Key < ActiveRecord::Base
after_destroy
:remove_from_shell
after_destroy
:remove_from_shell
after_destroy
:post_destroy_hook
after_destroy
:post_destroy_hook
def
strip_white_space
def
key
=
(
value
)
self
.
key
=
key
.
strip
unless
key
.
blank?
value
.
strip!
unless
value
.
blank?
write_attribute
(
:key
,
value
)
end
end
def
publishable_key
def
publishable_key
...
...
changelogs/unreleased/setter-for-key.yml
0 → 100644
View file @
34a86120
---
title
:
Use setter for key instead AR callback
merge_request
:
7488
author
:
Semyon Pupkov
spec/models/key_spec.rb
View file @
34a86120
...
@@ -82,4 +82,14 @@ describe Key, models: true do
...
@@ -82,4 +82,14 @@ describe Key, models: true do
@key
.
destroy
@key
.
destroy
end
end
end
end
describe
'#key='
do
let
(
:valid_key
)
do
"ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0= dummy@gitlab.com"
end
it
'strips white spaces'
do
expect
(
described_class
.
new
(
key:
"
#{
valid_key
}
"
).
key
).
to
eq
(
valid_key
)
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment