Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
0a8ec46ea04d
Commit
0a8ec46e
authored
Jul 26, 2016
by
Douglas Barbosa Alexandre
Browse files
Fix Project#to_param to keep invalid project suitable for use in URLs
parent
01e44e420275
Changes
6
Hide whitespace changes
Inline
Side-by-side
app/models/project.rb
View file @
0a8ec46e
...
...
@@ -586,7 +586,11 @@
end
def
to_param
path
if
persisted?
&&
errors
.
include?
(
:path
)
path_was
else
path
end
end
def
to_reference
(
_from_project
=
nil
)
...
...
app/services/projects/update_service.rb
View file @
0a8ec46e
...
...
@@ -23,8 +23,5 @@
if
project
.
previous_changes
.
include?
(
'path'
)
project
.
rename_repo
end
else
restore_attributes
false
end
end
...
...
@@ -29,11 +26,4 @@
end
end
private
def
restore_attributes
project
.
path
=
project
.
path_was
if
project
.
errors
.
include?
(
:path
)
project
.
name
=
project
.
name_was
if
project
.
errors
.
include?
(
:name
)
end
end
end
app/views/projects/update.js.haml
View file @
0a8ec46e
-
if
@project
.
errors
.
blank
?
-
if
@project
.
valid
?
:plain
location.href = "
#{
edit_namespace_project_path
(
@project
.
namespace
,
@project
)
}
";
-
else
...
...
spec/features/projects/project_settings_spec.rb
View file @
0a8ec46e
...
...
@@ -32,8 +32,8 @@
click_button
'Rename project'
expect
(
page
).
to
have_field
'Project name'
,
with:
'
sample
'
expect
(
page
).
to
have_field
'Path'
,
with:
'
gitlab
'
expect
(
page
).
to
have_field
'Project name'
,
with:
'
foo&bar
'
expect
(
page
).
to
have_field
'Path'
,
with:
'
foo&bar
'
expect
(
page
).
to
have_content
"Name can contain only letters, digits, '_', '.', dash and space. It must start with letter, digit or '_'."
expect
(
page
).
to
have_content
"Path can contain only letters, digits, '_', '-' and '.'. Cannot start with '-', end in '.git' or end in '.atom'"
end
...
...
spec/models/project_spec.rb
View file @
0a8ec46e
...
...
@@ -372,6 +372,24 @@
it
{
expect
(
@project
.
to_param
).
to
eq
(
'gitlabhq'
)
}
end
context
'with invalid path'
do
it
'returns previous path to keep project suitable for use in URLs when persisted'
do
project
=
create
(
:empty_project
,
path:
'gitlab'
)
project
.
path
=
'foo&bar'
expect
(
project
).
not_to
be_valid
expect
(
project
.
to_param
).
to
eq
'gitlab'
end
it
'returns current path when new record'
do
project
=
build
(
:empty_project
,
path:
'gitlab'
)
project
.
path
=
'foo&bar'
expect
(
project
).
not_to
be_valid
expect
(
project
.
to_param
).
to
eq
'foo&bar'
end
end
end
describe
'#repository'
do
...
...
spec/services/projects/update_service_spec.rb
View file @
0a8ec46e
...
...
@@ -139,27 +139,6 @@
end
end
context
'for invalid project path/name'
do
let
(
:user
)
{
create
(
:user
,
admin:
true
)
}
let
(
:project
)
{
create
(
:empty_project
,
path:
'gitlab'
,
name:
'sample'
)
}
let
(
:params
)
{
{
path:
'foo&bar'
,
name:
'foo&bar'
}
}
it
'resets to previous values to keep project in a valid state'
do
update_project
(
project
,
user
,
params
)
expect
(
project
.
path
).
to
eq
'gitlab'
expect
(
project
.
name
).
to
eq
'sample'
end
it
'keeps error messages'
do
update_project
(
project
,
user
,
params
)
expect
(
project
.
errors
).
not_to
be_blank
expect
(
project
.
errors
[
:name
]).
to
include
(
"can contain only letters, digits, '_', '.', dash and space. It must start with letter, digit or '_'."
)
expect
(
project
.
errors
[
:path
]).
to
include
(
"can contain only letters, digits, '_', '-' and '.'. Cannot start with '-', end in '.git' or end in '.atom'"
)
end
end
def
update_project
(
project
,
user
,
opts
)
Projects
::
UpdateService
.
new
(
project
,
user
,
opts
).
execute
end
...
...
Write
Preview
Supports
Markdown
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