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
4d40c3c3
Unverified
Commit
4d40c3c3
authored
Feb 08, 2017
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix route rename descendants if route.name is blank
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
d01cd84e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
11 deletions
+28
-11
route.rb
app/models/route.rb
+10
-5
route_spec.rb
spec/models/route_spec.rb
+18
-6
No files found.
app/models/route.rb
View file @
4d40c3c3
...
...
@@ -15,14 +15,19 @@ class Route < ActiveRecord::Base
descendants
=
Route
.
where
(
'path LIKE ?'
,
"
#{
path_was
}
/%"
)
descendants
.
each
do
|
route
|
attributes
=
{
path:
route
.
path
.
sub
(
path_was
,
path
),
name:
route
.
name
.
sub
(
name_was
,
name
)
}
attributes
=
{}
if
path_changed?
&&
route
.
path
.
present?
attributes
[
:path
]
=
route
.
path
.
sub
(
path_was
,
path
)
end
if
name_changed?
&&
route
.
name
.
present?
attributes
[
:name
]
=
route
.
name
.
sub
(
name_was
,
name
)
end
# Note that update_columns skips validation and callbacks.
# We need this to avoid recursive call of rename_descendants method
route
.
update_columns
(
attributes
)
route
.
update_columns
(
attributes
)
unless
attributes
.
empty?
end
end
end
...
...
spec/models/route_spec.rb
View file @
4d40c3c3
...
...
@@ -20,13 +20,25 @@ describe Route, models: true do
let!
(
:similar_group
)
{
create
(
:group
,
path:
'gitlab-org'
,
name:
'gitlab-org'
)
}
context
'path update'
do
before
{
route
.
update_attributes
(
path:
'bar'
)
}
context
'when route name is set'
do
before
{
route
.
update_attributes
(
path:
'bar'
)
}
it
"updates children routes with new path"
do
expect
(
described_class
.
exists?
(
path:
'bar'
)).
to
be_truthy
expect
(
described_class
.
exists?
(
path:
'bar/test'
)).
to
be_truthy
expect
(
described_class
.
exists?
(
path:
'bar/test/foo'
)).
to
be_truthy
expect
(
described_class
.
exists?
(
path:
'gitlab-org'
)).
to
be_truthy
end
end
it
"updates children routes with new path"
do
expect
(
described_class
.
exists?
(
path:
'bar'
)).
to
be_truthy
expect
(
described_class
.
exists?
(
path:
'bar/test'
)).
to
be_truthy
expect
(
described_class
.
exists?
(
path:
'bar/test/foo'
)).
to
be_truthy
expect
(
described_class
.
exists?
(
path:
'gitlab-org'
)).
to
be_truthy
context
'when route name is nil'
do
before
do
route
.
update_column
(
:name
,
nil
)
end
it
"does not fail"
do
expect
(
route
.
update_attributes
(
path:
'bar'
)).
to
be_truthy
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