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
ddb2d5cf66a6
Commit
7db72e7d
authored
Jan 18, 2018
by
Rémy Coutable
Browse files
Fix spec/migrations/update_upload_paths_to_system_spec.rb to use the :migration metadata
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
01cae2ad1a83
Changes
1
Hide whitespace changes
Inline
Side-by-side
spec/migrations/update_upload_paths_to_system_spec.rb
View file @
ddb2d5cf
require
"
spec_helper
"
require
Rails
.
root
.
join
(
"
db
"
,
"
post_migrate
"
,
"
20170317162059_update_upload_paths_to_system.rb
"
)
require
'
spec_helper
'
require
Rails
.
root
.
join
(
'
db
'
,
'
post_migrate
'
,
'
20170317162059_update_upload_paths_to_system.rb
'
)
describe
UpdateUploadPathsToSystem
do
describe
UpdateUploadPathsToSystem
,
:migration
do
let
(
:migration
)
{
described_class
.
new
}
let
(
:uploads_table
)
{
table
(
:uploads
)
}
let
(
:base_upload_attributes
)
{
{
size:
42
,
uploader:
'John Doe'
}
}
before
do
allow
(
migration
).
to
receive
(
:say
)
end
describe
"
#uploads_to_switch_to_new_path
"
do
it
"
contains only uploads with the old path for the correct models
"
do
_upload_for_other_type
=
create
(
:
upload
,
model:
create
(
:ci_p
ipeline
)
,
path:
"
uploads/ci_pipeline/avatar.jpg
"
)
_upload_with_system_path
=
create
(
:
upload
,
model:
create
(
:p
roject
)
,
path:
"
uploads/-/system/project/avatar.jpg
"
)
_upload_with_other_path
=
create
(
:
upload
,
model:
create
(
:p
roject
)
,
path:
"
thelongsecretforafileupload/avatar.jpg
"
)
old_upload
=
create
(
:
upload
,
model:
create
(
:p
roject
)
,
path:
"
uploads/project/avatar.jpg
"
)
group_upload
=
create
(
:
upload
,
model:
create
(
:group
),
path:
"
uploads/group/avatar.jpg
"
)
describe
'
#uploads_to_switch_to_new_path
'
do
it
'
contains only uploads with the old path for the correct models
'
do
_upload_for_other_type
=
create
_
upload
(
'P
ipeline
'
,
'
uploads/ci_pipeline/avatar.jpg
'
)
_upload_with_system_path
=
create
_
upload
(
'P
roject
'
,
'
uploads/-/system/project/avatar.jpg
'
)
_upload_with_other_path
=
create
_
upload
(
'P
roject
'
,
'
thelongsecretforafileupload/avatar.jpg
'
)
old_upload
=
create
_
upload
(
'P
roject
'
,
'
uploads/project/avatar.jpg
'
)
group_upload
=
create
_
upload
(
'Namespace'
,
'
uploads/group/avatar.jpg
'
)
expect
(
U
pload
.
where
(
migration
.
uploads_to_switch_to_new_path
)).
to
contain_exactly
(
old_upload
,
group_upload
)
expect
(
u
pload
s_table
.
where
(
migration
.
uploads_to_switch_to_new_path
)).
to
contain_exactly
(
old_upload
,
group_upload
)
end
end
describe
"
#uploads_to_switch_to_old_path
"
do
it
"
contains only uploads with the new path for the correct models
"
do
_upload_for_other_type
=
create
(
:
upload
,
model:
create
(
:ci_p
ipeline
)
,
path:
"
uploads/ci_pipeline/avatar.jpg
"
)
upload_with_system_path
=
create
(
:
upload
,
model:
create
(
:p
roject
)
,
path:
"
uploads/-/system/project/avatar.jpg
"
)
_upload_with_other_path
=
create
(
:
upload
,
model:
create
(
:p
roject
)
,
path:
"
thelongsecretforafileupload/avatar.jpg
"
)
_old_upload
=
create
(
:
upload
,
model:
create
(
:p
roject
)
,
path:
"
uploads/project/avatar.jpg
"
)
describe
'
#uploads_to_switch_to_old_path
'
do
it
'
contains only uploads with the new path for the correct models
'
do
_upload_for_other_type
=
create
_
upload
(
'P
ipeline
'
,
'
uploads/ci_pipeline/avatar.jpg
'
)
upload_with_system_path
=
create
_
upload
(
'P
roject
'
,
'
uploads/-/system/project/avatar.jpg
'
)
_upload_with_other_path
=
create
_
upload
(
'P
roject
'
,
'
thelongsecretforafileupload/avatar.jpg
'
)
_old_upload
=
create
_
upload
(
'P
roject
'
,
'
uploads/project/avatar.jpg
'
)
expect
(
U
pload
.
where
(
migration
.
uploads_to_switch_to_old_path
)).
to
contain_exactly
(
upload_with_system_path
)
expect
(
u
pload
s_table
.
where
(
migration
.
uploads_to_switch_to_old_path
)).
to
contain_exactly
(
upload_with_system_path
)
end
end
describe
"
#up
"
,
:truncate
do
it
"
updates old upload records to the new path
"
do
old_upload
=
create
(
:
upload
,
model:
create
(
:p
roject
)
,
path:
"
uploads/project/avatar.jpg
"
)
describe
'
#up
'
do
it
'
updates old upload records to the new path
'
do
old_upload
=
create
_
upload
(
'P
roject
'
,
'
uploads/project/avatar.jpg
'
)
migration
.
up
expect
(
old_upload
.
reload
.
path
).
to
eq
(
"
uploads/-/system/project/avatar.jpg
"
)
expect
(
old_upload
.
reload
.
path
).
to
eq
(
'
uploads/-/system/project/avatar.jpg
'
)
end
end
describe
"
#down
"
,
:truncate
do
it
"
updates the new system patsh to the old paths
"
do
new_upload
=
create
(
:
upload
,
model:
create
(
:p
roject
)
,
path:
"
uploads/-/system/project/avatar.jpg
"
)
describe
'
#down
'
do
it
'
updates the new system patsh to the old paths
'
do
new_upload
=
create
_
upload
(
'P
roject
'
,
'
uploads/-/system/project/avatar.jpg
'
)
migration
.
down
expect
(
new_upload
.
reload
.
path
).
to
eq
(
"
uploads/project/avatar.jpg
"
)
expect
(
new_upload
.
reload
.
path
).
to
eq
(
'
uploads/project/avatar.jpg
'
)
end
end
def
create_upload
(
type
,
path
)
uploads_table
.
create
(
base_upload_attributes
.
merge
(
model_type:
type
,
path:
path
))
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