Sha256: 815c7e1cdbf7d5293e8fe91d6072d1b8050f3feb5373d364d320327880fa779d

Contents?: true

Size: 1.08 KB

Versions: 17

Compression:

Stored size: 1.08 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Hyperdrive::Middleware::Pagination do
  def app
    inner_app = ->(env) { [200, {}, [[env['hyperdrive.page'],env['hyperdrive.per_page']].join(',')]] }
    Hyperdrive::Middleware::Pagination.new(inner_app)
  end

  after do
    hyperdrive.send(:reset!)
  end
  
  it "sets default values for page and per_page" do
    get '/', {}
    last_response.body.must_equal '1,20'
  end

  it "sets page to 1 if value is less than 1" do
    get '/', { 'page' => '' }
    last_response.body.must_equal '1,20'
  end

  it "returns page value if supplied" do
    get '/', { 'page' => '2' }
    last_response.body.must_equal '2,20'
  end

  it "returns per_page value if supplied" do
    get '/', { 'per_page' => 42 }
    last_response.body.must_equal '1,42'
  end

  it "uses configured per_page value if per_page is not supplied" do
    hyperdrive.config[:per_page] = 13
    get '/', {}
    last_response.body.must_equal '1,13'    
  end

  it "sets per_page to 20 if value is 0" do
    get '/', { 'per_page' => '' }
    last_response.body.must_equal '1,20'
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
hyperdrive-0.0.25 spec/hyperdrive/middleware/pagination_spec.rb
hyperdrive-0.0.24 spec/hyperdrive/middleware/pagination_spec.rb
hyperdrive-0.0.23 spec/hyperdrive/middleware/pagination_spec.rb
hyperdrive-0.0.22 spec/hyperdrive/middleware/pagination_spec.rb
hyperdrive-0.0.21 spec/hyperdrive/middleware/pagination_spec.rb
hyperdrive-0.0.20 spec/hyperdrive/middleware/pagination_spec.rb
hyperdrive-0.0.19 spec/hyperdrive/middleware/pagination_spec.rb
hyperdrive-0.0.18 spec/hyperdrive/middleware/pagination_spec.rb
hyperdrive-0.0.17 spec/hyperdrive/middleware/pagination_spec.rb
hyperdrive-0.0.16 spec/hyperdrive/middleware/pagination_spec.rb
hyperdrive-0.0.15 spec/hyperdrive/middleware/pagination_spec.rb
hyperdrive-0.0.14 spec/hyperdrive/middleware/pagination_spec.rb
hyperdrive-0.0.13 spec/hyperdrive/middleware/pagination_spec.rb
hyperdrive-0.0.12 spec/hyperdrive/middleware/pagination_spec.rb
hyperdrive-0.0.11 spec/hyperdrive/middleware/pagination_spec.rb
hyperdrive-0.0.10 spec/hyperdrive/middleware/pagination_spec.rb
hyperdrive-0.0.9 spec/hyperdrive/middleware/pagination_spec.rb