|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe NumbersController do |
| 4 | + describe 'GET #index' do |
| 5 | + context 'without enough items to give more than one page' do |
| 6 | + it 'should not paginate' do |
| 7 | + get :index, count: 20 |
| 8 | + response.headers['Link'].should be_blank |
| 9 | + end |
| 10 | + end |
| 11 | + |
| 12 | + context 'with enough items to paginate' do |
| 13 | + context 'when on the first page' do |
| 14 | + before(:each) do |
| 15 | + get :index, count: 100 |
| 16 | + |
| 17 | + @links = response.headers['Link'].split(', ') |
| 18 | + end |
| 19 | + |
| 20 | + it 'should not give a link with rel "first"' do |
| 21 | + @links.should_not include('rel="first"') |
| 22 | + end |
| 23 | + |
| 24 | + it 'should not give a link with rel "prev"' do |
| 25 | + @links.should_not include('rel="prev"') |
| 26 | + end |
| 27 | + |
| 28 | + it 'should give a link with rel "last"' do |
| 29 | + @links.should include('<http://test.host/numbers?count=100&page=4>; rel="last"') |
| 30 | + end |
| 31 | + |
| 32 | + it 'should give a link with rel "next"' do |
| 33 | + @links.should include('<http://test.host/numbers?count=100&page=2>; rel="next"') |
| 34 | + end |
| 35 | + end |
| 36 | + |
| 37 | + context 'when on the last page' do |
| 38 | + before(:each) do |
| 39 | + get :index, count: 100, page: 4 |
| 40 | + |
| 41 | + @links = response.headers['Link'].split(', ') |
| 42 | + end |
| 43 | + |
| 44 | + it 'should not give a link with rel "last"' do |
| 45 | + @links.should_not include('rel="last"') |
| 46 | + end |
| 47 | + |
| 48 | + it 'should not give a link with rel "next"' do |
| 49 | + @links.should_not include('rel="next"') |
| 50 | + end |
| 51 | + |
| 52 | + it 'should give a link with rel "first"' do |
| 53 | + @links.should include('<http://test.host/numbers?count=100&page=1>; rel="first"') |
| 54 | + end |
| 55 | + |
| 56 | + it 'should give a link with rel "prev"' do |
| 57 | + @links.should include('<http://test.host/numbers?count=100&page=3>; rel="prev"') |
| 58 | + end |
| 59 | + end |
| 60 | + |
| 61 | + context 'when somewhere comfortably in the middle' do |
| 62 | + it 'should give all pagination links' do |
| 63 | + get :index, count: 100, page: 2 |
| 64 | + |
| 65 | + links = response.headers['Link'].split(', ') |
| 66 | + |
| 67 | + links.should include('<http://test.host/numbers?count=100&page=1>; rel="first"') |
| 68 | + links.should include('<http://test.host/numbers?count=100&page=4>; rel="last"') |
| 69 | + links.should include('<http://test.host/numbers?count=100&page=3>; rel="next"') |
| 70 | + links.should include('<http://test.host/numbers?count=100&page=1>; rel="prev"') |
| 71 | + end |
| 72 | + end |
| 73 | + end |
| 74 | + end |
| 75 | +end |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | + |
0 commit comments