Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2016-12-12 17:16:51 +0300
committerValery Sizov <valery@gitlab.com>2016-12-12 17:16:51 +0300
commit314c4746bc24a31efe88b142cd83ab36c3473cc9 (patch)
tree5031a8a29ddfe1078fb9baedf41dd4c865d95619
parent1d7f85aeef624a83f0b225217a23c8f5189cde54 (diff)
Specs for Bitbucket::Connections and Bitbucket::Collections
-rw-r--r--lib/bitbucket/connection.rb20
-rw-r--r--lib/bitbucket/paginator.rb4
-rw-r--r--spec/lib/bitbucket/collection_spec.rb23
-rw-r--r--spec/lib/bitbucket/connection_spec.rb26
-rw-r--r--spec/lib/gitlab/bitbucket_import/project_creator_spec.rb2
5 files changed, 60 insertions, 15 deletions
diff --git a/lib/bitbucket/connection.rb b/lib/bitbucket/connection.rb
index 692a596c057..c150a20761e 100644
--- a/lib/bitbucket/connection.rb
+++ b/lib/bitbucket/connection.rb
@@ -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)
diff --git a/lib/bitbucket/paginator.rb b/lib/bitbucket/paginator.rb
index 641a6ed79d6..b38cd99855c 100644
--- a/lib/bitbucket/paginator.rb
+++ b/lib/bitbucket/paginator.rb
@@ -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
diff --git a/spec/lib/bitbucket/collection_spec.rb b/spec/lib/bitbucket/collection_spec.rb
new file mode 100644
index 00000000000..eeed61b0488
--- /dev/null
+++ b/spec/lib/bitbucket/collection_spec.rb
@@ -0,0 +1,23 @@
+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
diff --git a/spec/lib/bitbucket/connection_spec.rb b/spec/lib/bitbucket/connection_spec.rb
new file mode 100644
index 00000000000..5242c6fac34
--- /dev/null
+++ b/spec/lib/bitbucket/connection_spec.rb
@@ -0,0 +1,26 @@
+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
diff --git a/spec/lib/gitlab/bitbucket_import/project_creator_spec.rb b/spec/lib/gitlab/bitbucket_import/project_creator_spec.rb
index bb007949557..b6d052a4612 100644
--- a/spec/lib/gitlab/bitbucket_import/project_creator_spec.rb
+++ b/spec/lib/gitlab/bitbucket_import/project_creator_spec.rb
@@ -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" }