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
iv
gitlab-ce
Commits
917effb7
Commit
917effb7
authored
Dec 11, 2015
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure that token `ensure_*` method always returns a token
parent
28ad40d9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
3 deletions
+14
-3
app/models/concerns/token_authenticatable.rb
app/models/concerns/token_authenticatable.rb
+6
-2
spec/models/concerns/token_authenticatable_spec.rb
spec/models/concerns/token_authenticatable_spec.rb
+8
-1
No files found.
app/models/concerns/token_authenticatable.rb
View file @
917effb7
...
@@ -17,8 +17,12 @@ module TokenAuthenticatable
...
@@ -17,8 +17,12 @@ module TokenAuthenticatable
end
end
define_method
(
"ensure_
#{
token_field
}
"
)
do
define_method
(
"ensure_
#{
token_field
}
"
)
do
write_attribute
(
token_field
,
generate_token_for
(
token_field
))
if
current_token
=
read_attribute
(
token_field
)
read_attribute
(
token_field
).
blank?
if
current_token
.
blank?
write_attribute
(
token_field
,
generate_token_for
(
token_field
))
else
current_token
end
end
end
define_method
(
"reset_
#{
token_field
}
!"
)
do
define_method
(
"reset_
#{
token_field
}
!"
)
do
...
...
spec/models/concerns/token_authenticatable_spec.rb
View file @
917effb7
...
@@ -13,7 +13,7 @@ describe User, 'TokenAuthenticatable' do
...
@@ -13,7 +13,7 @@ describe User, 'TokenAuthenticatable' do
let
(
:token_field
)
{
:authentication_token
}
let
(
:token_field
)
{
:authentication_token
}
it_behaves_like
'TokenAuthenticatable'
it_behaves_like
'TokenAuthenticatable'
describe
'ensure
d
authentication token'
do
describe
'ensure
s
authentication token'
do
subject
{
create
(
:user
).
send
(
token_field
)
}
subject
{
create
(
:user
).
send
(
token_field
)
}
it
{
is_expected
.
to
be_a
String
}
it
{
is_expected
.
to
be_a
String
}
end
end
...
@@ -29,6 +29,13 @@ describe ApplicationSetting, 'TokenAuthenticatable' do
...
@@ -29,6 +29,13 @@ describe ApplicationSetting, 'TokenAuthenticatable' do
context
'token is not generated yet'
do
context
'token is not generated yet'
do
it
{
expect
(
token
).
to
be
nil
}
it
{
expect
(
token
).
to
be
nil
}
describe
'ensured token'
do
subject
{
described_class
.
new
.
send
(
"ensure_
#{
token_field
}
"
)
}
it
{
is_expected
.
to
be_a
String
}
it
{
is_expected
.
to_not
be_blank
}
end
end
end
context
'token is generated'
do
context
'token is generated'
do
...
...
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