Sha256: fb410d4d100b4fcc0610ffb814de8076d6794cf5ba24357db917d1cec1c6af8e

Contents?: true

Size: 1.59 KB

Versions: 2

Compression:

Stored size: 1.59 KB

Contents

require "spec_helper"

describe Paginate::Renderer::Base do
  before do
    Paginate.configure do |config|
      config.param_name = :page
      config.size  = 10
    end

    I18n.locale = :en

    @renderer = Paginate::Renderer::Base.new(nil, {
      collection: Array.new(11),
      page: 1,
      fullpath: "/some/path"
    })
  end

  it "parses simple url" do
    @renderer.options[:url] = "/some/path"
    expect(@renderer.url_for(1)).to eql("/some/path?page=1")
  end

  it "parses url with page param" do
    @renderer.options[:url] = "/some/path?page=3"
    expect(@renderer.url_for(1)).to eql("/some/path?page=1")
  end

  it "parses url with page as first param" do
    @renderer.options[:url] = "/some/path?page=3&a=1&b=2&c=3"
    expect(@renderer.url_for(1)).to eql("/some/path?a=1&b=2&c=3&page=1")
  end

  it "parses url with page as last param" do
    @renderer.options[:url] = "/some/path?a=1&b=2&c=3&page=3"
    expect(@renderer.url_for(1)).to eql("/some/path?a=1&b=2&c=3&page=1")
  end

  it "parses url with page param in the middle" do
    @renderer.options[:url] = "/some/path?a=1&b=2&page=3&c=3"
    expect(@renderer.url_for(1)).to eql("/some/path?a=1&b=2&c=3&page=1")
  end

  it "parses url with page as arbitrary string" do
    @renderer.options[:url] = "/some/path?a=1&b=2&c=3&page=abc"
    expect(@renderer.url_for(1)).to eql("/some/path?a=1&b=2&c=3&page=1")
  end

  it "escapes url from blocks" do
    @renderer.options[:url] = proc {|page| "/some/path/#{page}?a=1&b=2"}
    expect(@renderer.url_for(1)).to eql("/some/path/1?a=1&b=2")
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
paginate-4.0.0 spec/paginate/renderer/base_spec.rb
paginate-3.0.0 spec/paginate/renderer/base_spec.rb