Sha256: 067f88c0b92f5120b3dab4b2e86baebc50eef36bb15cc20fdee00d507c3725be

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

require 'spec_helper'

describe DataMapper::ChunkedQuery::Chunks do
  let(:per_chunk) { 10 }

  subject { TestModel.chunks(per_chunk) }

  it "should count the number of total resources" do
    subject.count.should == TestModel.count
  end

  it "should calculate how many chunks are available" do
    subject.length.should == (TestModel.count / per_chunk)
  end

  it "should round-up when calculate the number of available chunks" do
    TestModel.chunks(TestModel.count * 0.75).length.should == 2
  end

  it "should allow direct access to individual chunks" do
    resources = subject[1]
    numbers = resources.map { |resource| resource.number }

    numbers.should == (11..20).to_a
  end

  it "should allow direct access to a range of chunks" do
    resources = subject[1..2]
    numbers = resources.map { |resource| resource.number }

    numbers.should == (11..30).to_a
  end

  it "should allow enumerating through every chunk" do
    resources = []
    subject.each { |chunk| resources += chunk }

    TestModel.all.should == resources
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dm-chunked_query-0.1.1 spec/chunks_spec.rb
dm-chunked_query-0.1.0 spec/chunks_spec.rb