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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
941485ef
Commit
941485ef
authored
Jan 17, 2018
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add the :migration metadata, and don't use factories in FixWronglyRenamedRoutes spec
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
5392568e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
26 deletions
+39
-26
spec/migrations/fix_wrongly_renamed_routes_spec.rb
spec/migrations/fix_wrongly_renamed_routes_spec.rb
+39
-26
No files found.
spec/migrations/fix_wrongly_renamed_routes_spec.rb
View file @
941485ef
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20170518231126_fix_wrongly_renamed_routes.rb'
)
describe
FixWronglyRenamedRoutes
,
truncate:
true
do
describe
FixWronglyRenamedRoutes
,
:truncate
,
:migration
do
let
(
:subject
)
{
described_class
.
new
}
let
(
:namespaces_table
)
{
table
(
:namespaces
)
}
let
(
:projects_table
)
{
table
(
:projects
)
}
let
(
:routes_table
)
{
table
(
:routes
)
}
let
(
:broken_namespace
)
do
namespace
=
create
(
:group
,
name:
'apiis'
)
namespace
.
route
.
update_attribute
(
:path
,
'api0is'
)
namespace
namespace
s_table
.
create!
(
name:
'apiis'
,
path:
'apiis'
).
tap
do
|
namespace
|
routes_table
.
create!
(
source_type:
'Namespace'
,
source_id:
namespace
.
id
,
name:
'api0is'
,
path:
'api0is'
)
end
end
let
(
:broken_namespace_route
)
{
routes_table
.
where
(
source_type:
'Namespace'
,
source_id:
broken_namespace
.
id
).
first
}
describe
'#wrongly_renamed'
do
it
"includes routes that have names that don't match their namespace"
do
broken_namespace
_other_namespace
=
create
(
:group
,
name:
'api0'
)
other_namespace
=
namespaces_table
.
create!
(
name:
'api0'
,
path:
'api0'
)
routes_table
.
create!
(
source_type:
'Namespace'
,
source_id:
other_namespace
.
id
,
name:
'api0'
,
path:
'api0'
)
expect
(
subject
.
wrongly_renamed
.
map
(
&
:id
))
.
to
contain_exactly
(
broken_namespace
.
route
.
id
)
.
to
contain_exactly
(
broken_namespace
_
route
.
id
)
end
end
describe
"#paths_and_corrections"
do
it
'finds the wrong path and gets the correction from the namespace'
do
broken_namespace
namespace
=
create
(
:group
,
name:
'uploads-test'
)
namespace
.
route
.
update_attribute
(
:path
,
'uploads0-test'
)
namespaces_table
.
create!
(
name:
'uploads-test'
,
path:
'uploads-test'
).
tap
do
|
namespace
|
routes_table
.
create!
(
source_type:
'Namespace'
,
source_id:
namespace
.
id
,
name:
'uploads-test'
,
path:
'uploads0-test'
)
end
expected_result
=
[
{
'namespace_path'
=>
'apiis'
,
'path'
=>
'api0is'
},
...
...
@@ -36,38 +42,45 @@ describe FixWronglyRenamedRoutes, truncate: true do
describe
'#routes_in_namespace_query'
do
it
'includes only the required routes'
do
namespace
=
create
(
:group
,
path:
'hello'
)
project
=
create
(
:project
,
namespace:
namespace
)
_other_namespace
=
create
(
:group
,
path:
'hello0'
)
result
=
Route
.
where
(
subject
.
routes_in_namespace_query
(
'hello'
))
expect
(
result
).
to
contain_exactly
(
namespace
.
route
,
project
.
route
)
namespace
=
namespaces_table
.
create!
(
name:
'hello'
,
path:
'hello'
)
namespace_route
=
routes_table
.
create!
(
source_type:
'Namespace'
,
source_id:
namespace
.
id
,
name:
'hello'
,
path:
'hello'
)
project
=
projects_table
.
new
(
name:
'my-project'
,
path:
'my-project'
,
namespace_id:
namespace
.
id
).
tap
do
|
project
|
project
.
save!
(
validate:
false
)
end
routes_table
.
create!
(
source_type:
'Project'
,
source_id:
project
.
id
,
name:
'my-project'
,
path:
'hello/my-project'
)
_other_namespace
=
namespaces_table
.
create!
(
name:
'hello0'
,
path:
'hello0'
)
result
=
routes_table
.
where
(
subject
.
routes_in_namespace_query
(
'hello'
))
project_route
=
routes_table
.
where
(
source_type:
'Project'
,
source_id:
project
.
id
).
first
expect
(
result
).
to
contain_exactly
(
namespace_route
,
project_route
)
end
end
describe
'#up'
do
let
(
:broken_project
)
do
project
=
create
(
:project
,
namespace:
broken_namespace
,
path:
'broken-project'
)
project
.
route
.
update_attribute
(
:path
,
'api0is/broken-project'
)
project
end
it
'renames incorrectly named routes'
do
broken_project
broken_project
=
projects_table
.
new
(
name:
'broken-project'
,
path:
'broken-project'
,
namespace_id:
broken_namespace
.
id
).
tap
do
|
project
|
project
.
save!
(
validate:
false
)
routes_table
.
create!
(
source_type:
'Project'
,
source_id:
project
.
id
,
name:
'broken-project'
,
path:
'api0is/broken-project'
)
end
subject
.
up
expect
(
broken_project
.
route
.
reload
.
path
).
to
eq
(
'apiis/broken-project'
)
expect
(
broken_namespace
.
route
.
reload
.
path
).
to
eq
(
'apiis'
)
broken_project_route
=
routes_table
.
where
(
source_type:
'Project'
,
source_id:
broken_project
.
id
).
first
expect
(
broken_project_route
.
path
).
to
eq
(
'apiis/broken-project'
)
expect
(
broken_namespace_route
.
reload
.
path
).
to
eq
(
'apiis'
)
end
it
"doesn't touch namespaces that look like something that should be renamed"
do
namespace
=
create
(
:group
,
path:
'api0'
)
namespaces_table
.
create!
(
name:
'apiis'
,
path:
'apiis'
)
namespace
=
namespaces_table
.
create!
(
name:
'hello'
,
path:
'api0'
)
namespace_route
=
routes_table
.
create!
(
source_type:
'Namespace'
,
source_id:
namespace
.
id
,
name:
'hello'
,
path:
'api0'
)
subject
.
up
expect
(
namespace
.
route
.
reload
.
path
).
to
eq
(
'api0'
)
expect
(
namespace
_
route
.
reload
.
path
).
to
eq
(
'api0'
)
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