summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2016-12-12 17:29:25 +0200
committerValery Sizov <valery@gitlab.com>2016-12-12 17:29:25 +0200
commit3a0fecb4924f1a6dbcc3e61041e0cac95ec3b21b (patch)
tree785fc6ed07680f79f04916ddea4d57f30587b817
parent314c4746bc24a31efe88b142cd83ab36c3473cc9 (diff)
downloadgitlab-ce-3a0fecb4924f1a6dbcc3e61041e0cac95ec3b21b.tar.gz
Spec for bitbucket page
-rw-r--r--lib/bitbucket/page.rb1
-rw-r--r--spec/lib/bitbucket/page_spec.rb50
2 files changed, 51 insertions, 0 deletions
diff --git a/lib/bitbucket/page.rb b/lib/bitbucket/page.rb
index 8f50f67f84d..2b0a3fe7b1a 100644
--- a/lib/bitbucket/page.rb
+++ b/lib/bitbucket/page.rb
@@ -23,6 +23,7 @@ module Bitbucket
def parse_values(raw, bitbucket_rep_class)
return [] unless raw['values'] && raw['values'].is_a?(Array)
+
bitbucket_rep_class.decorate(raw['values'])
end
diff --git a/spec/lib/bitbucket/page_spec.rb b/spec/lib/bitbucket/page_spec.rb
new file mode 100644
index 00000000000..04d5a0470b1
--- /dev/null
+++ b/spec/lib/bitbucket/page_spec.rb
@@ -0,0 +1,50 @@
+require 'spec_helper'
+
+describe Bitbucket::Page do
+ let(:response) { { 'values' => [{ 'username' => 'Ben' }], 'pagelen' => 2, 'next' => '' } }
+
+ before do
+ # Autoloading hack
+ Bitbucket::Representation::User.new({})
+ end
+
+ describe '#items' do
+ it 'returns collection of needed objects' do
+ page = described_class.new(response, :user)
+
+ expect(page.items.first).to be_a(Bitbucket::Representation::User)
+ expect(page.items.count).to eq(1)
+ end
+ end
+
+ describe '#attrs' do
+ it 'returns attributes' do
+ page = described_class.new(response, :user)
+
+ expect(page.attrs.keys).to include(:pagelen, :next)
+ end
+ end
+
+ describe '#next?' do
+ it 'returns true' do
+ page = described_class.new(response, :user)
+
+ expect(page.next?).to be_truthy
+ end
+
+ it 'returns false' do
+ response['next'] = nil
+ page = described_class.new(response, :user)
+
+ expect(page.next?).to be_falsey
+ end
+ end
+
+ describe '#next' do
+ it 'returns next attribute' do
+ page = described_class.new(response, :user)
+
+ expect(page.next).to eq('')
+ end
+ end
+end