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
7fb2172d
Commit
7fb2172d
authored
Nov 17, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for Projects::UpdateMirrorService
parent
31b1ffd5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
102 additions
and
0 deletions
+102
-0
spec/services/projects/update_mirror_service_spec.rb
spec/services/projects/update_mirror_service_spec.rb
+102
-0
No files found.
spec/services/projects/update_mirror_service_spec.rb
0 → 100644
View file @
7fb2172d
require
'spec_helper'
describe
Projects
::
UpdateMirrorService
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:repository
)
{
project
.
repository
}
let
(
:mirror_user
)
{
project
.
owner
}
subject
{
described_class
.
new
(
project
,
mirror_user
)
}
before
do
project
.
import_url
=
Project
::
UNKNOWN_IMPORT_URL
project
.
mirror
=
true
project
.
mirror_user
=
mirror_user
project
.
save
end
describe
"#execute"
do
it
"fetches the upstream repository"
do
expect
(
project
).
to
receive
(
:fetch_mirror
)
subject
.
execute
end
it
"succeeds"
do
allow
(
project
).
to
receive
(
:fetch_mirror
)
{
fetch_mirror
(
repository
)
}
result
=
subject
.
execute
expect
(
result
[
:status
]).
to
eq
(
:success
)
end
describe
"updating tags"
do
it
"creates new tags"
do
allow
(
project
).
to
receive
(
:fetch_mirror
)
{
fetch_mirror
(
repository
)
}
subject
.
execute
expect
(
repository
.
tag_names
).
to
include
(
'new-tag'
)
end
end
describe
"updating branches"
do
it
"creates new branches"
do
allow
(
project
).
to
receive
(
:fetch_mirror
)
{
fetch_mirror
(
repository
)
}
subject
.
execute
expect
(
repository
.
branch_names
).
to
include
(
'new-branch'
)
end
it
"updates existing branches"
do
allow
(
project
).
to
receive
(
:fetch_mirror
)
{
fetch_mirror
(
repository
)
}
subject
.
execute
expect
(
repository
.
find_branch
(
'existing-branch'
).
target
).
to
eq
(
repository
.
find_branch
(
'master'
).
target
)
end
it
"doesn't update diverged branches"
do
allow
(
project
).
to
receive
(
:fetch_mirror
)
{
fetch_mirror
(
repository
)
}
subject
.
execute
expect
(
repository
.
find_branch
(
'markdown'
).
target
).
not_to
eq
(
repository
.
find_branch
(
'master'
).
target
)
end
end
describe
"when the mirror user doesn't have access"
do
let
(
:mirror_user
)
{
create
(
:user
)
}
it
"fails"
do
allow
(
project
).
to
receive
(
:fetch_mirror
)
{
fetch_mirror
(
repository
)
}
result
=
subject
.
execute
expect
(
result
[
:status
]).
to
eq
(
:error
)
end
end
end
def
fetch_mirror
(
repository
)
rugged
=
repository
.
rugged
masterrev
=
repository
.
find_branch
(
'master'
).
target
parentrev
=
repository
.
commit
(
masterrev
).
parent_id
rugged
.
references
.
create
(
'refs/heads/existing-branch'
,
parentrev
)
repository
.
expire_branches_cache
repository
.
branches
# New branch
rugged
.
references
.
create
(
'refs/remotes/upstream/new-branch'
,
masterrev
)
# Updated existing branch
rugged
.
references
.
create
(
'refs/remotes/upstream/existing-branch'
,
masterrev
)
# Diverged branch
rugged
.
references
.
create
(
'refs/remotes/upstream/markdown'
,
masterrev
)
# New tag
rugged
.
references
.
create
(
'refs/tags/new-tag'
,
masterrev
)
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