BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
cb2b888b
Commit
cb2b888b
authored
Sep 03, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1365 from tsigo/gitolite_identifier
Update User#identifier to conform to Gitolite 2.x's user pattern
parents
b44e9a08
d2982743
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
27 deletions
+44
-27
account.rb
app/roles/account.rb
+9
-2
factories.rb
spec/factories.rb
+1
-1
user_spec.rb
spec/models/user_spec.rb
+34
-24
No files found.
app/roles/account.rb
View file @
cb2b888b
module
Account
module
Account
# Returns a string for use as a Gitolite user identifier
#
# Note that Gitolite 2.x requires the following pattern for users:
#
# ^@?[0-9a-zA-Z][0-9a-zA-Z._\@+-]*$
def
identifier
email
.
gsub
/[^[:alnum:]]/
,
"_"
# Replace non-word chars with underscores, then make sure it starts with
# valid chars
email
.
gsub
(
/\W/
,
'_'
).
gsub
(
/\A([\W\_])+/
,
''
)
end
def
is_admin?
...
...
spec/factories.rb
View file @
cb2b888b
...
...
@@ -28,7 +28,7 @@ FactoryGirl.define do
email
{
Faker
::
Internet
.
email
}
name
password
"123456"
password_confirmation
"123456"
password_confirmation
{
password
}
trait
:admin
do
admin
true
...
...
spec/models/user_spec.rb
View file @
cb2b888b
...
...
@@ -31,36 +31,46 @@ describe User do
it
{
should
respond_to
(
:private_token
)
}
end
it
"should return valid identifier"
do
user
=
User
.
new
(
email:
"test@mail.com"
)
user
.
identifier
.
should
==
"test_mail_com"
end
describe
'#identifier'
do
it
"should return valid identifier"
do
user
=
build
(
:user
,
email:
"test@mail.com"
)
user
.
identifier
.
should
==
"test_mail_com"
end
it
"should return identifier without + sign"
do
user
=
User
.
new
(
email:
"test+foo@mail.com"
)
user
.
identifier
.
should
==
"test_foo_mail_com"
end
it
"should return identifier without + sign"
do
user
=
build
(
:user
,
email:
"test+foo@mail.com"
)
user
.
identifier
.
should
==
"test_foo_mail_com"
end
it
"should execute callback when force_random_password specified
"
do
user
=
User
.
new
(
email:
"test@mail.com"
,
force_random_password:
true
)
user
.
should_receive
(
:generate_password
)
user
.
save
it
"should conform to Gitolite's required identifier pattern
"
do
user
=
build
(
:user
,
email:
"_test@example.com"
)
user
.
identifier
.
should
==
'test_example_com'
end
end
it
"should not generate password by default"
do
user
=
Factory
(
:user
,
password:
'abcdefg'
,
password_confirmation:
'abcdefg'
)
user
.
password
.
should
==
'abcdefg'
end
describe
'#generate_password'
do
it
"should execute callback when force_random_password specified"
do
user
=
build
(
:user
,
force_random_password:
true
)
user
.
should_receive
(
:generate_password
)
user
.
save
end
it
"should not generate password by default"
do
user
=
create
(
:user
,
password:
'abcdefg'
)
user
.
password
.
should
==
'abcdefg'
end
it
"should generate password when forcing random password"
do
Devise
.
stub
(
:friendly_token
).
and_return
(
'123456789'
)
user
=
User
.
create
(
email:
"test1@mail.com"
,
force_random_password:
true
)
user
.
password
.
should
==
user
.
password_confirmation
user
.
password
.
should
==
'12345678'
it
"should generate password when forcing random password"
do
Devise
.
stub
(
:friendly_token
).
and_return
(
'123456789'
)
user
=
create
(
:user
,
password:
'abcdefg'
,
force_random_password:
true
)
user
.
password
.
should
==
'12345678'
end
end
it
"should have authentication token"
do
user
=
Factory
(
:user
)
user
.
authentication_token
.
should_not
==
""
describe
'authentication token'
do
it
"should have authentication token"
do
user
=
Factory
(
:user
)
user
.
authentication_token
.
should_not
be_blank
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