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
314c4746
Commit
314c4746
authored
Dec 12, 2016
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Specs for Bitbucket::Connections and Bitbucket::Collections
parent
1d7f85ae
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
15 deletions
+60
-15
lib/bitbucket/connection.rb
lib/bitbucket/connection.rb
+8
-12
lib/bitbucket/paginator.rb
lib/bitbucket/paginator.rb
+1
-3
spec/lib/bitbucket/collection_spec.rb
spec/lib/bitbucket/collection_spec.rb
+23
-0
spec/lib/bitbucket/connection_spec.rb
spec/lib/bitbucket/connection_spec.rb
+26
-0
spec/lib/gitlab/bitbucket_import/project_creator_spec.rb
spec/lib/gitlab/bitbucket_import/project_creator_spec.rb
+2
-0
No files found.
lib/bitbucket/connection.rb
View file @
314c4746
...
...
@@ -15,18 +15,6 @@ module Bitbucket
@refresh_token
=
options
[
:refresh_token
]
end
def
client
@client
||=
OAuth2
::
Client
.
new
(
provider
.
app_id
,
provider
.
app_secret
,
options
)
end
def
connection
@connection
||=
OAuth2
::
AccessToken
.
new
(
client
,
@token
,
refresh_token:
@refresh_token
,
expires_at:
@expires_at
,
expires_in:
@expires_in
)
end
def
set_default_query_parameters
(
params
=
{})
@default_query
.
merge!
(
params
)
end
def
get
(
path
,
extra_query
=
{})
refresh!
if
expired?
...
...
@@ -52,6 +40,14 @@ module Bitbucket
attr_reader
:expires_at
,
:expires_in
,
:refresh_token
,
:token
def
client
@client
||=
OAuth2
::
Client
.
new
(
provider
.
app_id
,
provider
.
app_secret
,
options
)
end
def
connection
@connection
||=
OAuth2
::
AccessToken
.
new
(
client
,
@token
,
refresh_token:
@refresh_token
,
expires_at:
@expires_at
,
expires_in:
@expires_in
)
end
def
build_url
(
path
)
return
path
if
path
.
starts_with?
(
root_url
)
...
...
lib/bitbucket/paginator.rb
View file @
314c4746
...
...
@@ -7,8 +7,6 @@ module Bitbucket
@type
=
type
@url
=
url
@page
=
nil
connection
.
set_default_query_parameters
(
pagelen:
PAGE_LENGTH
,
sort: :created_on
)
end
def
items
...
...
@@ -31,7 +29,7 @@ module Bitbucket
end
def
fetch_next_page
parsed_response
=
connection
.
get
(
next_url
)
parsed_response
=
connection
.
get
(
next_url
,
{
pagelen:
PAGE_LENGTH
,
sort: :created_on
}
)
Page
.
new
(
parsed_response
,
type
)
end
end
...
...
spec/lib/bitbucket/collection_spec.rb
0 → 100644
View file @
314c4746
require
'spec_helper'
# Emulates paginator. It returns 2 pages with results
class
TestPaginator
def
initialize
@current_page
=
0
end
def
items
@current_page
+=
1
raise
StopIteration
if
@current_page
>
2
[
"result_1_page_
#{
@current_page
}
"
,
"result_2_page_
#{
@current_page
}
"
]
end
end
describe
Bitbucket
::
Collection
do
it
"iterates paginator"
do
collection
=
described_class
.
new
(
TestPaginator
.
new
)
expect
(
collection
.
to_a
).
to
match
([
"result_1_page_1"
,
"result_2_page_1"
,
"result_1_page_2"
,
"result_2_page_2"
])
end
end
spec/lib/bitbucket/connection_spec.rb
0 → 100644
View file @
314c4746
require
'spec_helper'
describe
Bitbucket
::
Connection
do
describe
'#get'
do
it
'calls OAuth2::AccessToken::get'
do
expect_any_instance_of
(
OAuth2
::
AccessToken
).
to
receive
(
:get
).
and_return
(
double
(
parsed:
true
))
connection
=
described_class
.
new
({})
connection
.
get
(
'/users'
)
end
end
describe
'#expired?'
do
it
'calls connection.expired?'
do
expect_any_instance_of
(
OAuth2
::
AccessToken
).
to
receive
(
:expired?
).
and_return
(
true
)
expect
(
described_class
.
new
({}).
expired?
).
to
be_truthy
end
end
describe
'#refresh!'
do
it
'calls connection.refresh!'
do
response
=
double
(
token:
nil
,
expires_at:
nil
,
expires_in:
nil
,
refresh_token:
nil
)
expect_any_instance_of
(
OAuth2
::
AccessToken
).
to
receive
(
:refresh!
).
and_return
(
response
)
described_class
.
new
({}).
refresh!
end
end
end
spec/lib/gitlab/bitbucket_import/project_creator_spec.rb
View file @
314c4746
...
...
@@ -2,6 +2,7 @@ require 'spec_helper'
describe
Gitlab
::
BitbucketImport
::
ProjectCreator
,
lib:
true
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:repo
)
do
double
(
name:
'Vim'
,
slug:
'vim'
,
...
...
@@ -12,6 +13,7 @@ describe Gitlab::BitbucketImport::ProjectCreator, lib: true do
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
,
clone_url:
'ssh://git@bitbucket.org/asd/vim.git'
)
end
let
(
:namespace
){
create
(
:group
,
owner:
user
)
}
let
(
:token
)
{
"asdasd12345"
}
let
(
:secret
)
{
"sekrettt"
}
...
...
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