diff options
author | Valery Sizov <valery@gitlab.com> | 2016-12-12 16:16:51 +0200 |
---|---|---|
committer | Valery Sizov <valery@gitlab.com> | 2016-12-12 16:16:51 +0200 |
commit | 314c4746bc24a31efe88b142cd83ab36c3473cc9 (patch) | |
tree | 5031a8a29ddfe1078fb9baedf41dd4c865d95619 /spec/lib/bitbucket | |
parent | 1d7f85aeef624a83f0b225217a23c8f5189cde54 (diff) | |
download | gitlab-ce-314c4746bc24a31efe88b142cd83ab36c3473cc9.tar.gz |
Specs for Bitbucket::Connections and Bitbucket::Collections
Diffstat (limited to 'spec/lib/bitbucket')
-rw-r--r-- | spec/lib/bitbucket/collection_spec.rb | 23 | ||||
-rw-r--r-- | spec/lib/bitbucket/connection_spec.rb | 26 |
2 files changed, 49 insertions, 0 deletions
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 |