|
1 | 1 | require 'spec_helper' |
2 | 2 |
|
3 | 3 | 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) } |
5 | 5 | let(:failed) { Cortex::Result.new('failed body', {}, 403) } |
6 | 6 |
|
7 | 7 | it 'should construct' do |
|
31 | 31 | end |
32 | 32 |
|
33 | 33 | 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 }) |
35 | 35 | expect(failed.raw_headers).to eq({}) |
36 | 36 | end |
37 | 37 |
|
|
40 | 40 | expect(failed.status).to eq 403 |
41 | 41 | end |
42 | 42 |
|
| 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 |
43 | 67 | end |
0 commit comments