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
a6a3df64
Commit
a6a3df64
authored
Feb 08, 2017
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dz-fix-route-rename-descendants' into 'master'
Fix route rename descendants if route.name is blank See merge request !9074
parents
b28d66c3
4d40c3c3
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 @
a6a3df64
...
@@ -15,14 +15,19 @@ class Route < ActiveRecord::Base
...
@@ -15,14 +15,19 @@ class Route < ActiveRecord::Base
descendants
=
Route
.
where
(
'path LIKE ?'
,
"
#{
path_was
}
/%"
)
descendants
=
Route
.
where
(
'path LIKE ?'
,
"
#{
path_was
}
/%"
)
descendants
.
each
do
|
route
|
descendants
.
each
do
|
route
|
attributes
=
{
attributes
=
{}
path:
route
.
path
.
sub
(
path_was
,
path
),
name:
route
.
name
.
sub
(
name_was
,
name
)
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.
# Note that update_columns skips validation and callbacks.
# We need this to avoid recursive call of rename_descendants method
# 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
end
end
end
...
...
spec/models/route_spec.rb
View file @
a6a3df64
...
@@ -20,13 +20,25 @@ describe Route, models: true do
...
@@ -20,13 +20,25 @@ describe Route, models: true do
let!
(
:similar_group
)
{
create
(
:group
,
path:
'gitlab-org'
,
name:
'gitlab-org'
)
}
let!
(
:similar_group
)
{
create
(
:group
,
path:
'gitlab-org'
,
name:
'gitlab-org'
)
}
context
'path update'
do
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
context
'when route name is nil'
do
expect
(
described_class
.
exists?
(
path:
'bar'
)).
to
be_truthy
before
do
expect
(
described_class
.
exists?
(
path:
'bar/test'
)).
to
be_truthy
route
.
update_column
(
:name
,
nil
)
expect
(
described_class
.
exists?
(
path:
'bar/test/foo'
)).
to
be_truthy
end
expect
(
described_class
.
exists?
(
path:
'gitlab-org'
)).
to
be_truthy
it
"does not fail"
do
expect
(
route
.
update_attributes
(
path:
'bar'
)).
to
be_truthy
end
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