diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2018-11-07 20:48:40 +0000 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2018-11-07 20:48:40 +0000 |
commit | 5fcd7a87ab15bfeb15377918b93994699eb56c2e (patch) | |
tree | 4afb9b6735b7cb5ab23597b68d526a1f306effa3 /spec | |
parent | 829e452588575c634b2a3dd778e702a6b21465e1 (diff) | |
parent | 5b6d5301d9589b694fea0820a2b6cf165642669b (diff) | |
download | gitlab-ce-5fcd7a87ab15bfeb15377918b93994699eb56c2e.tar.gz |
Merge branch 'sh-paginate-bitbucket-server-imports' into 'master'
Paginate Bitbucket Server importer projects
See merge request gitlab-org/gitlab-ce!22825
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/import/bitbucket_server_controller_spec.rb | 11 | ||||
-rw-r--r-- | spec/lib/bitbucket_server/client_spec.rb | 12 | ||||
-rw-r--r-- | spec/lib/bitbucket_server/collection_spec.rb | 29 | ||||
-rw-r--r-- | spec/lib/bitbucket_server/paginator_spec.rb | 10 |
4 files changed, 57 insertions, 5 deletions
diff --git a/spec/controllers/import/bitbucket_server_controller_spec.rb b/spec/controllers/import/bitbucket_server_controller_spec.rb index 5024ef71771..77060fdc3be 100644 --- a/spec/controllers/import/bitbucket_server_controller_spec.rb +++ b/spec/controllers/import/bitbucket_server_controller_spec.rb @@ -121,12 +121,19 @@ describe Import::BitbucketServerController do @repo = double(slug: 'vim', project_key: 'asd', full_name: 'asd/vim', "valid?" => true, project_name: 'asd', browse_url: 'http://test', name: 'vim') @invalid_repo = double(slug: 'invalid', project_key: 'foobar', full_name: 'asd/foobar', "valid?" => false, browse_url: 'http://bad-repo') + @created_repo = double(slug: 'created', project_key: 'existing', full_name: 'group/created', "valid?" => true, browse_url: 'http://existing') assign_session_tokens end it 'assigns repository categories' do - created_project = create(:project, import_type: 'bitbucket_server', creator_id: user.id, import_source: 'foo/bar', import_status: 'finished') - expect(client).to receive(:repos).and_return([@repo, @invalid_repo]) + created_project = create(:project, import_type: 'bitbucket_server', creator_id: user.id, import_status: 'finished', import_source: @created_repo.browse_url) + repos = instance_double(BitbucketServer::Collection) + + expect(repos).to receive(:partition).and_return([[@repo, @created_repo], [@invalid_repo]]) + expect(repos).to receive(:current_page).and_return(1) + expect(repos).to receive(:next_page).and_return(2) + expect(repos).to receive(:prev_page).and_return(nil) + expect(client).to receive(:repos).and_return(repos) get :status diff --git a/spec/lib/bitbucket_server/client_spec.rb b/spec/lib/bitbucket_server/client_spec.rb index f926ae963a4..5de0a9a65b5 100644 --- a/spec/lib/bitbucket_server/client_spec.rb +++ b/spec/lib/bitbucket_server/client_spec.rb @@ -13,7 +13,7 @@ describe BitbucketServer::Client do let(:path) { "/projects/#{project}/repos/#{repo_slug}/pull-requests?state=ALL" } it 'requests a collection' do - expect(BitbucketServer::Paginator).to receive(:new).with(anything, path, :pull_request) + expect(BitbucketServer::Paginator).to receive(:new).with(anything, path, :pull_request, page_offset: 0, limit: nil) subject.pull_requests(project, repo_slug) end @@ -29,7 +29,7 @@ describe BitbucketServer::Client do let(:path) { "/projects/#{project}/repos/#{repo_slug}/pull-requests/1/activities" } it 'requests a collection' do - expect(BitbucketServer::Paginator).to receive(:new).with(anything, path, :activity) + expect(BitbucketServer::Paginator).to receive(:new).with(anything, path, :activity, page_offset: 0, limit: nil) subject.activities(project, repo_slug, 1) end @@ -52,10 +52,16 @@ describe BitbucketServer::Client do let(:path) { "/repos" } it 'requests a collection' do - expect(BitbucketServer::Paginator).to receive(:new).with(anything, path, :repo) + expect(BitbucketServer::Paginator).to receive(:new).with(anything, path, :repo, page_offset: 0, limit: nil) subject.repos end + + it 'requests a collection with an offset and limit' do + expect(BitbucketServer::Paginator).to receive(:new).with(anything, path, :repo, page_offset: 10, limit: 25) + + subject.repos(page_offset: 10, limit: 25) + end end describe '#create_branch' do diff --git a/spec/lib/bitbucket_server/collection_spec.rb b/spec/lib/bitbucket_server/collection_spec.rb new file mode 100644 index 00000000000..ddd02bac88a --- /dev/null +++ b/spec/lib/bitbucket_server/collection_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe BitbucketServer::Collection do + let(:connection) { instance_double(BitbucketServer::Connection) } + let(:page) { 1 } + let(:paginator) { BitbucketServer::Paginator.new(connection, 'http://more-data', :pull_request, page_offset: page) } + + subject { described_class.new(paginator) } + + describe '#current_page' do + it 'returns 1' do + expect(subject.current_page).to eq(1) + end + end + + describe '#prev_page' do + it 'returns nil' do + expect(subject.prev_page).to be_nil + end + end + + describe '#next_page' do + it 'returns 2' do + expect(subject.next_page).to eq(2) + end + end +end diff --git a/spec/lib/bitbucket_server/paginator_spec.rb b/spec/lib/bitbucket_server/paginator_spec.rb index 2de50eba3c4..d268d4f23cf 100644 --- a/spec/lib/bitbucket_server/paginator_spec.rb +++ b/spec/lib/bitbucket_server/paginator_spec.rb @@ -20,6 +20,16 @@ describe BitbucketServer::Paginator do expect { paginator.items }.to raise_error(StopIteration) end + it 'obeys limits' do + limited = described_class.new(connection, 'http://more-data', :pull_request, page_offset: 0, limit: 1) + allow(limited).to receive(:fetch_next_page).and_return(first_page) + + expect(limited.has_next_page?).to be_truthy + expect(limited.items).to match(['item_1']) + expect(limited.has_next_page?).to be_truthy + expect { limited.items }.to raise_error(StopIteration) + end + it 'calls the connection with different offsets' do expect(connection).to receive(:get).with('http://more-data', start: 0, limit: BitbucketServer::Paginator::PAGE_LENGTH).and_return(page_attrs) |