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
053ff3ba
Commit
053ff3ba
authored
Apr 04, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Geo avatar downloader
parent
98cd66ee
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
12 deletions
+101
-12
lib/gitlab/geo/avatar_downloader.rb
lib/gitlab/geo/avatar_downloader.rb
+13
-0
spec/lib/gitlab/geo/avatar_downloader_spec.rb
spec/lib/gitlab/geo/avatar_downloader_spec.rb
+25
-0
spec/services/geo/file_download_service_spec.rb
spec/services/geo/file_download_service_spec.rb
+63
-12
No files found.
lib/gitlab/geo/avatar_downloader.rb
0 → 100644
View file @
053ff3ba
module
Gitlab
module
Geo
class
AvatarDownloader
<
FileDownloader
def
execute
upload
=
Upload
.
find_by_id
(
object_db_id
)
return
unless
upload
.
present?
transfer
=
::
Gitlab
::
Geo
::
AvatarTransfer
.
new
(
upload
)
transfer
.
download_from_primary
end
end
end
end
spec/lib/gitlab/geo/avatar_downloader_spec.rb
0 → 100644
View file @
053ff3ba
require
'spec_helper'
describe
Gitlab
::
Geo
::
AvatarDownloader
do
let
(
:avatar
)
{
fixture_file_upload
(
Rails
.
root
+
'spec/fixtures/dk.png'
,
'image/png'
)
}
let
(
:user
)
{
create
(
:user
,
avatar:
avatar
)
}
let
(
:upload
)
{
Upload
.
find_by
(
model:
user
,
uploader:
'AvatarUploader'
)
}
context
'#download_from_primary'
do
it
'downlods the avatar'
do
allow_any_instance_of
(
Gitlab
::
Geo
::
AvatarTransfer
)
.
to
receive
(
:download_from_primary
).
and_return
(
100
)
downloader
=
described_class
.
new
(
upload
.
id
)
expect
(
downloader
.
execute
).
to
eq
(
100
)
end
it
'returns nil with unknown avatar'
do
downloader
=
described_class
.
new
(
10000
)
expect
(
downloader
).
not_to
receive
(
:download_from_primary
)
expect
(
downloader
.
execute
).
to
be_nil
end
end
end
spec/services/geo/file_download_service_spec.rb
View file @
053ff3ba
require
'spec_helper'
describe
Geo
::
FileDownloadService
,
services:
true
do
let
(
:lfs_object
)
{
create
(
:lfs_object
)
}
let
!
(
:primary
)
{
create
(
:geo_node
,
:primary
)
}
let
(
:secondary
)
{
create
(
:geo_node
)
}
subject
{
Geo
::
FileDownloadService
.
new
(
:lfs
,
lfs_object
.
id
)
}
before
do
create
(
:geo_node
,
:primary
)
allow
(
described_class
).
to
receive
(
:current_node
)
{
secondary
}
end
describe
'#execute'
do
it
'downloads an LFS object'
do
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
)
.
to
receive
(
:try_obtain
).
and_return
(
true
)
allow_any_instance_of
(
Gitlab
::
Geo
::
LfsTransfer
)
.
to
receive
(
:download_from_primary
).
and_return
(
100
)
context
'user avatar'
do
let
(
:user
)
{
create
(
:user
,
avatar:
fixture_file_upload
(
Rails
.
root
+
'spec/fixtures/dk.png'
,
'image/png'
))
}
let
(
:upload
)
{
Upload
.
find_by
(
model:
user
,
uploader:
'AvatarUploader'
)
}
subject
{
described_class
.
new
(
:avatar
,
upload
.
id
)
}
it
'downloads an user avatar'
do
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
)
.
to
receive
(
:try_obtain
).
and_return
(
true
)
allow_any_instance_of
(
Gitlab
::
Geo
::
AvatarTransfer
)
.
to
receive
(
:download_from_primary
).
and_return
(
100
)
expect
{
subject
.
execute
}.
to
change
{
Geo
::
FileRegistry
.
count
}.
by
(
1
)
end
end
context
'group avatar'
do
let
(
:group
)
{
create
(
:group
,
avatar:
fixture_file_upload
(
Rails
.
root
+
'spec/fixtures/dk.png'
,
'image/png'
))
}
let
(
:upload
)
{
Upload
.
find_by
(
model:
group
,
uploader:
'AvatarUploader'
)
}
subject
{
described_class
.
new
(
:avatar
,
upload
.
id
)
}
it
'downloads a group avatar'
do
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
)
.
to
receive
(
:try_obtain
).
and_return
(
true
)
allow_any_instance_of
(
Gitlab
::
Geo
::
AvatarTransfer
)
.
to
receive
(
:download_from_primary
).
and_return
(
100
)
expect
{
subject
.
execute
}.
to
change
{
Geo
::
FileRegistry
.
count
}.
by
(
1
)
end
end
context
'project avatar'
do
let
(
:project
)
{
create
(
:empty_project
,
avatar:
fixture_file_upload
(
Rails
.
root
+
'spec/fixtures/dk.png'
,
'image/png'
))
}
let
(
:upload
)
{
Upload
.
find_by
(
model:
project
,
uploader:
'AvatarUploader'
)
}
subject
{
described_class
.
new
(
:avatar
,
upload
.
id
)
}
it
'downloads a project avatar'
do
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
)
.
to
receive
(
:try_obtain
).
and_return
(
true
)
allow_any_instance_of
(
Gitlab
::
Geo
::
AvatarTransfer
)
.
to
receive
(
:download_from_primary
).
and_return
(
100
)
expect
{
subject
.
execute
}.
to
change
{
Geo
::
FileRegistry
.
count
}.
by
(
1
)
end
end
context
'LFS object'
do
let
(
:lfs_object
)
{
create
(
:lfs_object
)
}
subject
{
described_class
.
new
(
:lfs
,
lfs_object
.
id
)
}
it
'downloads an LFS object'
do
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
)
.
to
receive
(
:try_obtain
).
and_return
(
true
)
allow_any_instance_of
(
Gitlab
::
Geo
::
LfsTransfer
)
.
to
receive
(
:download_from_primary
).
and_return
(
100
)
expect
{
subject
.
execute
}.
to
change
{
Geo
::
FileRegistry
.
count
}.
by
(
1
)
expect
{
subject
.
execute
}.
to
change
{
Geo
::
FileRegistry
.
count
}.
by
(
1
)
end
end
it
'bad object type'
do
expect
{
described_class
.
new
(
:bad
,
lfs_object
.
id
).
execute
}.
to
raise_error
(
NameError
)
it
'
raises an error with
bad object type'
do
expect
{
described_class
.
new
(
:bad
,
1
).
execute
}.
to
raise_error
(
NameError
)
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