hashblue 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -40,4 +40,9 @@ class Hashblue::Collection
40
40
  nil
41
41
  end
42
42
  end
43
+
44
+ def each_page(&block)
45
+ yield self if block_given?
46
+ next_page.each_page(&block) if next_page?
47
+ end
43
48
  end
@@ -1,3 +1,3 @@
1
1
  module Hashblue
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/hashblue.rb CHANGED
@@ -6,5 +6,4 @@ module Hashblue
6
6
  autoload :Message, 'hashblue/message'
7
7
  autoload :Model, 'hashblue/model'
8
8
  autoload :Version, 'hashblue/version'
9
- # Your code goes here...
10
9
  end
@@ -35,6 +35,16 @@ describe Hashblue::Collection do
35
35
  subject.next_page.should be_false
36
36
  end
37
37
  end
38
+
39
+ describe '#each_page(&block)' do
40
+ it 'yields itself' do
41
+ pages = []
42
+ subject.each_page do |page|
43
+ pages << page
44
+ end
45
+ pages.should eql([subject])
46
+ end
47
+ end
38
48
  end
39
49
 
40
50
  describe "a collection with a next_page_uri" do
@@ -58,6 +68,22 @@ describe Hashblue::Collection do
58
68
  subject.next_page.should eql(collection)
59
69
  end
60
70
  end
71
+
72
+ describe '#each_page(&block)' do
73
+ it 'yields each page in turn' do
74
+ subject
75
+ response = {"contacts" => []}
76
+ client.stubs(:get).with("https://api.example.com/contacts/more").returns(response)
77
+ collection = Hashblue::Collection.new(client, Hashblue::Contact, {"contacts" => []}, "contacts")
78
+ Hashblue::Collection.expects(:new).with(client, Hashblue::Contact, response, "contacts").returns(collection)
79
+
80
+ pages = []
81
+ subject.each_page do |page|
82
+ pages << page
83
+ end
84
+ pages.should eql([subject, collection])
85
+ end
86
+ end
61
87
  end
62
88
 
63
89
  describe "a collection without a previous_page_uri" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashblue
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tom Ward