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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
c19b8a78
Commit
c19b8a78
authored
Mar 14, 2019
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce differences with EE in a migration spec
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
4891e8a5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
32 deletions
+51
-32
spec/migrations/delete_inconsistent_internal_id_records_spec.rb
...igrations/delete_inconsistent_internal_id_records_spec.rb
+51
-32
No files found.
spec/migrations/delete_inconsistent_internal_id_records_spec.rb
View file @
c19b8a78
# frozen_string_literal: true
# frozen_string_literal: true
# rubocop:disable RSpec/FactoriesInMigrationSpecs
require
'spec_helper'
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20180723130817_delete_inconsistent_internal_id_records.rb'
)
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20180723130817_delete_inconsistent_internal_id_records.rb'
)
describe
DeleteInconsistentInternalIdRecords
,
:migration
do
describe
DeleteInconsistentInternalIdRecords
,
:migration
do
let!
(
:project1
)
{
create
(
:project
)
}
let!
(
:namespace
)
{
table
(
:namespaces
).
create!
(
name:
'test'
,
path:
'test'
)
}
let!
(
:project2
)
{
create
(
:project
)
}
let!
(
:project1
)
{
table
(
:projects
).
create!
(
namespace_id:
namespace
.
id
)
}
let!
(
:project3
)
{
create
(
:project
)
}
let!
(
:project2
)
{
table
(
:projects
).
create!
(
namespace_id:
namespace
.
id
)
}
let!
(
:project3
)
{
table
(
:projects
).
create!
(
namespace_id:
namespace
.
id
)
}
let
(
:internal_id_query
)
{
->
(
project
)
{
InternalId
.
where
(
usage:
InternalId
.
usages
[
scope
.
to_s
.
tableize
],
project:
project
)
}
}
let
(
:internal_ids
)
{
table
(
:internal_ids
)
}
let
(
:internal_id_query
)
{
->
(
project
)
{
InternalId
.
where
(
usage:
InternalId
.
usages
[
scope
.
to_s
.
tableize
],
project_id:
project
.
id
)
}
}
let
(
:create_models
)
do
let
(
:create_models
)
do
3
.
times
{
create
(
scope
,
project:
project1
)
}
[
project1
,
project2
,
project3
].
each
do
|
project
|
3
.
times
{
create
(
scope
,
project:
project2
)
}
3
.
times
do
|
i
|
3
.
times
{
create
(
scope
,
project:
project3
)
}
attributes
=
required_attributes
.
merge
(
project_id:
project
.
id
,
iid:
i
.
succ
)
table
(
scope
.
to_s
.
pluralize
).
create!
(
attributes
)
end
end
end
end
shared_examples_for
'deleting inconsistent internal_id records'
do
shared_examples_for
'deleting inconsistent internal_id records'
do
before
do
before
do
create_models
create_models
[
project1
,
project2
,
project3
].
each
do
|
project
|
internal_ids
.
create!
(
project_id:
project
.
id
,
usage:
InternalId
.
usages
[
scope
.
to_s
.
tableize
],
last_value:
3
)
end
internal_id_query
.
call
(
project1
).
first
.
tap
do
|
iid
|
internal_id_query
.
call
(
project1
).
first
.
tap
do
|
iid
|
iid
.
last_value
=
iid
.
last_value
-
2
iid
.
last_value
=
iid
.
last_value
-
2
# This is an inconsistent record
# This is an inconsistent record
...
@@ -33,11 +44,11 @@ describe DeleteInconsistentInternalIdRecords, :migration do
...
@@ -33,11 +44,11 @@ describe DeleteInconsistentInternalIdRecords, :migration do
end
end
end
end
it
"deletes inconsistent
issue
s"
do
it
"deletes inconsistent
record
s"
do
expect
{
migrate!
}.
to
change
{
internal_id_query
.
call
(
project1
).
size
}.
from
(
1
).
to
(
0
)
expect
{
migrate!
}.
to
change
{
internal_id_query
.
call
(
project1
).
size
}.
from
(
1
).
to
(
0
)
end
end
it
"retains consistent
issue
s"
do
it
"retains consistent
record
s"
do
expect
{
migrate!
}.
not_to
change
{
internal_id_query
.
call
(
project2
).
size
}
expect
{
migrate!
}.
not_to
change
{
internal_id_query
.
call
(
project2
).
size
}
end
end
...
@@ -48,6 +59,8 @@ describe DeleteInconsistentInternalIdRecords, :migration do
...
@@ -48,6 +59,8 @@ describe DeleteInconsistentInternalIdRecords, :migration do
context
'for issues'
do
context
'for issues'
do
let
(
:scope
)
{
:issue
}
let
(
:scope
)
{
:issue
}
let
(
:required_attributes
)
{
{}
}
it_behaves_like
'deleting inconsistent internal_id records'
it_behaves_like
'deleting inconsistent internal_id records'
end
end
...
@@ -55,9 +68,17 @@ describe DeleteInconsistentInternalIdRecords, :migration do
...
@@ -55,9 +68,17 @@ describe DeleteInconsistentInternalIdRecords, :migration do
let
(
:scope
)
{
:merge_request
}
let
(
:scope
)
{
:merge_request
}
let
(
:create_models
)
do
let
(
:create_models
)
do
3
.
times
{
|
i
|
create
(
scope
,
target_project:
project1
,
source_project:
project1
,
source_branch:
i
.
to_s
)
}
[
project1
,
project2
,
project3
].
each
do
|
project
|
3
.
times
{
|
i
|
create
(
scope
,
target_project:
project2
,
source_project:
project2
,
source_branch:
i
.
to_s
)
}
3
.
times
do
|
i
|
3
.
times
{
|
i
|
create
(
scope
,
target_project:
project3
,
source_project:
project3
,
source_branch:
i
.
to_s
)
}
table
(
:merge_requests
).
create!
(
target_project_id:
project
.
id
,
source_project_id:
project
.
id
,
target_branch:
'master'
,
source_branch:
j
.
to_s
,
iid:
i
.
succ
)
end
end
end
end
it_behaves_like
'deleting inconsistent internal_id records'
it_behaves_like
'deleting inconsistent internal_id records'
...
@@ -66,13 +87,6 @@ describe DeleteInconsistentInternalIdRecords, :migration do
...
@@ -66,13 +87,6 @@ describe DeleteInconsistentInternalIdRecords, :migration do
context
'for deployments'
do
context
'for deployments'
do
let
(
:scope
)
{
:deployment
}
let
(
:scope
)
{
:deployment
}
let
(
:deployments
)
{
table
(
:deployments
)
}
let
(
:deployments
)
{
table
(
:deployments
)
}
let
(
:internal_ids
)
{
table
(
:internal_ids
)
}
before
do
internal_ids
.
create!
(
project_id:
project1
.
id
,
usage:
2
,
last_value:
2
)
internal_ids
.
create!
(
project_id:
project2
.
id
,
usage:
2
,
last_value:
2
)
internal_ids
.
create!
(
project_id:
project3
.
id
,
usage:
2
,
last_value:
2
)
end
let
(
:create_models
)
do
let
(
:create_models
)
do
3
.
times
{
|
i
|
deployments
.
create!
(
project_id:
project1
.
id
,
iid:
i
,
environment_id:
1
,
ref:
'master'
,
sha:
'a'
,
tag:
false
)
}
3
.
times
{
|
i
|
deployments
.
create!
(
project_id:
project1
.
id
,
iid:
i
,
environment_id:
1
,
ref:
'master'
,
sha:
'a'
,
tag:
false
)
}
...
@@ -85,17 +99,14 @@ describe DeleteInconsistentInternalIdRecords, :migration do
...
@@ -85,17 +99,14 @@ describe DeleteInconsistentInternalIdRecords, :migration do
context
'for milestones (by project)'
do
context
'for milestones (by project)'
do
let
(
:scope
)
{
:milestone
}
let
(
:scope
)
{
:milestone
}
let
(
:required_attributes
)
{
{
title:
'test'
}
}
it_behaves_like
'deleting inconsistent internal_id records'
it_behaves_like
'deleting inconsistent internal_id records'
end
end
context
'for ci_pipelines'
do
context
'for ci_pipelines'
do
let
(
:scope
)
{
:ci_pipeline
}
let
(
:scope
)
{
:ci_pipeline
}
let
(
:required_attributes
)
{
{
ref:
'test'
}
}
let
(
:create_models
)
do
create_list
(
:ci_empty_pipeline
,
3
,
project:
project1
)
create_list
(
:ci_empty_pipeline
,
3
,
project:
project2
)
create_list
(
:ci_empty_pipeline
,
3
,
project:
project3
)
end
it_behaves_like
'deleting inconsistent internal_id records'
it_behaves_like
'deleting inconsistent internal_id records'
end
end
...
@@ -107,12 +118,20 @@ describe DeleteInconsistentInternalIdRecords, :migration do
...
@@ -107,12 +118,20 @@ describe DeleteInconsistentInternalIdRecords, :migration do
let
(
:group2
)
{
groups
.
create
(
name:
'Group 2'
,
type:
'Group'
,
path:
'group_2'
)
}
let
(
:group2
)
{
groups
.
create
(
name:
'Group 2'
,
type:
'Group'
,
path:
'group_2'
)
}
let
(
:group3
)
{
groups
.
create
(
name:
'Group 2'
,
type:
'Group'
,
path:
'group_3'
)
}
let
(
:group3
)
{
groups
.
create
(
name:
'Group 2'
,
type:
'Group'
,
path:
'group_3'
)
}
let
(
:internal_id_query
)
{
->
(
group
)
{
InternalId
.
where
(
usage:
InternalId
.
usages
[
'milestones'
],
namespace
:
group
)
}
}
let
(
:internal_id_query
)
{
->
(
group
)
{
InternalId
.
where
(
usage:
InternalId
.
usages
[
'milestones'
],
namespace
_id:
group
.
id
)
}
}
before
do
before
do
3
.
times
{
create
(
:milestone
,
group_id:
group1
.
id
)
}
[
group1
,
group2
,
group3
].
each
do
|
group
|
3
.
times
{
create
(
:milestone
,
group_id:
group2
.
id
)
}
3
.
times
do
|
i
|
3
.
times
{
create
(
:milestone
,
group_id:
group3
.
id
)
}
table
(
:milestones
).
create!
(
group_id:
group
.
id
,
title:
'test'
,
iid:
i
.
succ
)
end
internal_ids
.
create!
(
namespace_id:
group
.
id
,
usage:
InternalId
.
usages
[
'milestones'
],
last_value:
3
)
end
internal_id_query
.
call
(
group1
).
first
.
tap
do
|
iid
|
internal_id_query
.
call
(
group1
).
first
.
tap
do
|
iid
|
iid
.
last_value
=
iid
.
last_value
-
2
iid
.
last_value
=
iid
.
last_value
-
2
...
@@ -127,11 +146,11 @@ describe DeleteInconsistentInternalIdRecords, :migration do
...
@@ -127,11 +146,11 @@ describe DeleteInconsistentInternalIdRecords, :migration do
end
end
end
end
it
"deletes inconsistent
issue
s"
do
it
"deletes inconsistent
record
s"
do
expect
{
migrate!
}.
to
change
{
internal_id_query
.
call
(
group1
).
size
}.
from
(
1
).
to
(
0
)
expect
{
migrate!
}.
to
change
{
internal_id_query
.
call
(
group1
).
size
}.
from
(
1
).
to
(
0
)
end
end
it
"retains consistent
issue
s"
do
it
"retains consistent
record
s"
do
expect
{
migrate!
}.
not_to
change
{
internal_id_query
.
call
(
group2
).
size
}
expect
{
migrate!
}.
not_to
change
{
internal_id_query
.
call
(
group2
).
size
}
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