Sha256: 4c73bd94e8ebf6ae180fa20df248ccb650b0c470458438a185202a26fbee0938

Contents?: true

Size: 1.94 KB

Versions: 2

Compression:

Stored size: 1.94 KB

Contents

require "spec_helper"

describe SunspotKaminariSupport do
  subject {SunspotStub.new(:query => query, :total => total)}
  let(:query) {double('query')}
  let(:total) {nil}
  it "#current_page delegates to query" do
    query.should_receive :page
    subject.current_page
  end
  context "#total_pages" do
    it "uses query.per_page" do
      query.should_receive(:per_page).and_return(3)
      subject.total_pages
    end
    it "returns correct number" do
      query.stub(:per_page => 3)
      expect(subject.total_pages).to eq(2)
    end
  end
  context '#limit_value' do
    it "returns per_page" do
      query.should_receive(:per_page).and_return(3)
      expect(subject.limit_value).to eq(3)
    end
  end
  context '#empty?' do
    it "returns true when total eq 0" do
      subject.stub(:total => 0)
      expect(subject.empty?).to be_true
    end
    it "returns false when total > 0" do
      subject.stub(:total => 1)
      expect(subject.empty?).to be_false
    end
  end

  context '#any?' do
    it "returns false when total eq 0" do
      subject.stub(:total => 0)
      expect(subject.any?).to be_false
    end
    it "returns true when total > 0" do
      subject.stub(:total => 1)
      expect(subject.any?).to be_true
    end
  end

  context '#last_page?' do
    it "returns true when current_page is last" do
      subject.stub(:total_pages => 1)
      query.stub(:page => 1)
      expect(subject.last_page?).to be_true
    end
    it "returns false when current page isn't last" do
      subject.stub(:total_pages => 2)
      query.stub(:page => 1)
      expect(subject.last_page?).to be_false
    end
  end

  context '#offset_value' do
    it "returns numbre of records before current page" do
      query.stub(:per_page => 3, :page => 2)
      expect(subject.offset_value).to eq(3)
    end
  end

  context '#total_count' do
    it "returns total" do
      subject.should_receive(:total).and_return(6)
      expect(subject.total_count).to eq 6
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sunspot_kaminari_support-0.0.2 spec/lib/sunspot_kaminari_support_spec.rb
sunspot_kaminari_support-0.0.1 spec/lib/sunspot_kaminari_support_spec.rb