Sha256: 23b5678ac6db71cbecae4de938d7643dea96a2bca9c446943d613947f01a7f5f

Contents?: true

Size: 1.67 KB

Versions: 73

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe LHS::Record do
  context 'pagination' do
    let(:datastore) { 'http://local.ch/v2' }
    let(:record) { Feedback.where(entry_id: 1) }
    let(:total) { 200 }
    let(:total_pages) { total / limit }
    let(:current_page) { offset + 1 }
    let(:prev_page) { current_page - 1 }
    let(:next_page) { current_page + 1 }
    let(:offset) { 0 }
    let(:limit) { 10 }
    let(:body_json) do
      {
        items: [],
        total: total,
        offset: offset,
        limit: limit
      }.to_json
    end

    before do
      LHC.config.placeholder('datastore', datastore)
      class Feedback < LHS::Record
        endpoint '{+datastore}/feedbacks'
      end
      stub_request(:get, 'http://local.ch/v2/feedbacks?entry_id=1')
        .to_return(body: body_json)
    end

    it 'responds to limit_value' do
      expect(record.limit_value).to eq(limit)
    end

    it 'responds to total_pages' do
      expect(record.total_pages).to eq(total_pages)
    end

    it 'responds to current_page' do
      expect(record.current_page).to eq(current_page)
    end

    it 'responds to first_page' do
      expect(record.first_page).to eq(1)
    end

    it 'responds to last_page' do
      expect(record.last_page).to eq(total_pages)
    end

    it 'responds to prev_page' do
      expect(record.prev_page).to eq(prev_page)
    end

    it 'responds to next_page' do
      expect(record.next_page).to eq(next_page)
    end

    context 'when amount of total pages is not diviable by the limit' do
      let(:total) { 2738 }
      let(:limit) { 100 }

      it 'rounds up' do
        expect(record.total_pages).to eq(28)
      end
    end
  end
end

Version data entries

73 entries across 73 versions & 1 rubygems

Version Path
lhs-26.2.0 spec/record/pagination_spec.rb
lhs-26.1.0 spec/record/pagination_spec.rb
lhs-26.0.1 spec/record/pagination_spec.rb
lhs-26.0.0 spec/record/pagination_spec.rb
lhs-25.2.0 spec/record/pagination_spec.rb
lhs-25.1.0 spec/record/pagination_spec.rb
lhs-25.0.4 spec/record/pagination_spec.rb
lhs-25.0.3 spec/record/pagination_spec.rb
lhs-25.0.2 spec/record/pagination_spec.rb
lhs-25.0.1 spec/record/pagination_spec.rb
lhs-25.0.0 spec/record/pagination_spec.rb
lhs-24.1.2 spec/record/pagination_spec.rb
lhs-24.1.1 spec/record/pagination_spec.rb
lhs-24.1.0 spec/record/pagination_spec.rb
lhs-24.1.0.pre.2 spec/record/pagination_spec.rb
lhs-24.1.0.pre.1 spec/record/pagination_spec.rb
lhs-24.0.0 spec/record/pagination_spec.rb
lhs-23.0.2 spec/record/pagination_spec.rb
lhs-23.0.1 spec/record/pagination_spec.rb
lhs-23.0.0 spec/record/pagination_spec.rb