forked from piotrmurach/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresult_spec.rb
More file actions
135 lines (110 loc) · 3.64 KB
/
result_spec.rb
File metadata and controls
135 lines (110 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# encoding: utf-8
require 'spec_helper'
describe Github::Result do
let(:github) { Github.new }
let(:user) { 'wycats' }
let(:res) { github.activity.events.public({ 'per_page' => 20 }) }
let(:pages) { ['1', '5', '6'] }
let(:link) {
"<https://api.github.com/users/wycats/repos?page=6&per_page=20>; rel=\"last\", <https://api.github.com/users/wycats/repos?page=1&per_page=20>; rel=\"first\""
}
before do
stub_get("/events").
with(:query => { 'per_page' => '20' }).
to_return(:body => fixture('events/events.json'),
:status => 200,
:headers => {
:content_type => "application/json; charset=utf-8",
'X-RateLimit-Remaining' => '4999',
'X-RateLimit-Limit' => '5000',
'content-length' => '344',
'etag' => "\"d9a88f20567726e29d35c6fae87cef2f\"",
'server' => "nginx/1.0.4",
'Date' => "Sun, 05 Feb 2012 15:02:34 GMT",
'Link' => link
})
['', '1', '5', '6'].each do |page|
params = page.empty? ? {'per_page'=>'20'} : {'per_page'=>'20', 'page'=>page}
stub_get("/users/#{user}/repos").
with(:query => params).
to_return(:body => fixture('events/events.json'),
:status => 200,
:headers => {
:content_type => "application/json; charset=utf-8",
'X-RateLimit-Remaining' => '4999',
'X-RateLimit-Limit' => '5000',
'content-length' => '344',
'Date' => "Sun, 05 Feb 2012 15:02:34 GMT",
'Link' => link
})
end
end
it "should read response content_type " do
res.content_type.should match 'application/json'
end
it "should read response content_length " do
res.content_length.should match '344'
end
it "should read response ratelimit limit" do
res.ratelimit_limit.should == '5000'
end
it "should read response ratelimit remaining" do
res.ratelimit_remaining.should == '4999'
end
it "should read response status" do
res.status.should be 200
end
it 'should read response etag' do
res.etag.should eql "\"d9a88f20567726e29d35c6fae87cef2f\""
end
it 'should read response date' do
res.date.should eql "Sun, 05 Feb 2012 15:02:34 GMT"
end
it 'should read response server' do
res.server.should eql "nginx/1.0.4"
end
it "should assess successful" do
res.success?.should be_true
end
it "should read response body" do
res.body.should_not be_empty
end
context "pagination methods" do
let(:env) { {:response_headers => {}}}
let(:iterator) { Github::PageIterator.new(env) }
before do
described_class.stub(:page_iterator).and_return iterator
end
it "should respond to links" do
res.links.should be_a Github::PageLinks
end
%w[ next prev ].each do |link|
context "#{link}_page" do
it "should return collection of resources" do
res.send(:"#{link}_page").should be_an Array
end
it 'should have no link information' do
res.links.send(:"#{link}").should be_nil
end
end
end
%w[ first last].each do |link|
context "#{link}_page" do
it "should return resource if exists" do
res.send(:"#{link}_page").should_not be_empty
end
it "should have link information" do
res.send(:"#{link}_page").should_not be_nil
end
end
end
it 'finds single page successfully' do
iterator.stub(:get_page).and_return res
res.page(5).should eq res
end
it 'checks if there are more pages' do
res.should_receive(:has_next_page?).and_return true
res.has_next_page?.should be_true
end
end # pagination
end # Github::Result