spec/paginate_responder_spec.rb in paginate-responder-2.0.0 vs spec/paginate_responder_spec.rb in paginate-responder-2.1.0

- old
+ new

@@ -19,18 +19,19 @@ else self.resource = ArModel.scoped end end + let(:method) { :get } let(:response) { action.call; @response } let(:json) { JSON.parse response.body } let(:params) { {format: :json} } if ActionPack::VERSION::MAJOR >= 5 - let(:action) { -> { get :index, params: params } } + let(:action) { -> { send(method, :index, params: params) } } else - let(:action) { -> { get :index, params } } + let(:action) { -> { send(method, :index, params) } } end context 'with AR resource' do it { expect(json).to eq (1..50).to_a } @@ -161,16 +162,34 @@ it { expect(subject.size).to eq 3 } it { is_expected.to include 'first' => 'http://test.host/index.json?page=1&per_page=50' } it { is_expected.to include 'next' => 'http://test.host/index.json?page=2&per_page=50' } it { is_expected.to include 'last' => 'http://test.host/index.json?page=14&per_page=50' } end + + context 'when method is HEAD' do + let(:method) { :head } + + it { expect(subject.size).to eq 3 } + it { is_expected.to include 'first' => 'http://test.host/index.json?page=1' } + it { is_expected.to include 'next' => 'http://test.host/index.json?page=2' } + it { is_expected.to include 'last' => 'http://test.host/index.json?page=14' } + end end describe 'headers' do subject { response.headers.to_h } it { is_expected.to include 'X-Total-Pages' => '14' } it { is_expected.to include 'X-Total-Count' => '676' } it { is_expected.to include 'X-Per-Page' => '50' } it { is_expected.to include 'X-Current-Page' => '1' } + + context 'when method is HEAD' do + let(:method) { :head } + + it { is_expected.to include 'X-Total-Pages' => '14' } + it { is_expected.to include 'X-Total-Count' => '676' } + it { is_expected.to include 'X-Per-Page' => '50' } + it { is_expected.to include 'X-Current-Page' => '1' } + end end end