Skip to content

Commit 1488f42

Browse files
committed
Add specs
1 parent 5468b88 commit 1488f42

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

spec/result_spec.rb

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper'
22

33
RSpec.describe Cortex::Result do
4-
let(:result) { Cortex::Result.new('body', {'X-Total' => 10, 'X-Page' => "1", "X-Per-Page" => "10"}, 200) }
4+
let(:result) { Cortex::Result.new('body', { 'X-Total' => '40', 'X-Page' => "1", 'X-Per-Page' => "10", 'X-Total-Pages' => '4', 'X-Next-Page' => '2', 'X-Prev-Page' => nil }, 200) }
55
let(:failed) { Cortex::Result.new('failed body', {}, 403) }
66

77
it 'should construct' do
@@ -31,7 +31,7 @@
3131
end
3232

3333
it 'should expose the headers' do
34-
expect(result.raw_headers).to eq({ 'X-Total' => 10, 'X-Page' => "1", "X-Per-Page" => "10" })
34+
expect(result.raw_headers).to eq({ 'X-Total' => '40', 'X-Page' => "1", 'X-Per-Page' => "10", 'X-Total-Pages' => '4', 'X-Next-Page' => '2', 'X-Prev-Page' => nil })
3535
expect(failed.raw_headers).to eq({})
3636
end
3737

@@ -40,4 +40,28 @@
4040
expect(failed.status).to eq 403
4141
end
4242

43+
describe '#total_pages' do
44+
it 'returns the value of "X-Total-Pages"' do
45+
expect(result.total_pages).to eq '4'
46+
end
47+
end
48+
49+
describe '#next_page' do
50+
it 'returns_the_value of "X-Next-Page"' do
51+
expect(result.next_page).to eq '2'
52+
end
53+
end
54+
55+
describe '#prev_page' do
56+
it 'returns nil when on the first page' do
57+
expect(result.prev_page).to be_nil
58+
end
59+
60+
context 'on the 2nd page' do
61+
let(:result) { Cortex::Result.new('body', { 'X-Total' => '40', 'X-Page' => "2", 'X-Per-Page' => "10", 'X-Total-Pages' => '4', 'X-Next-Page' => '3', 'X-Prev-Page' => '1' }, 200) }
62+
it 'returns the value if "X-Prev-Page"' do
63+
expect(result.prev_page).to eq '1'
64+
end
65+
end
66+
end
4367
end

0 commit comments

Comments
 (0)