Sha256: f8d94e4b9193e89b8149cd911352964eb3921eb56029bcaac659848490101b91

Contents?: true

Size: 844 Bytes

Versions: 5

Compression:

Stored size: 844 Bytes

Contents

require File.expand_path('../abstract_unit', __FILE__)

class TestFindInBatches < ActiveSupport::TestCase
  fixtures :capitols

  def test_in_batches
    capitols = []
    Capitol.find_in_batches do |chunk|
      capitols += chunk.map(&:country)
    end
    assert_equal(capitols, ['Canada', 'France', 'Mexico', 'The Netherlands'])
  end

  def test_in_small_batches
    capitols = []
    Capitol.find_in_batches(batch_size: 2) do |chunk|
        capitols += chunk.map(&:country)
      end

    assert_equal(capitols, ['Canada', 'France', 'Mexico', 'The Netherlands'])
  end

  def test_in_one_unit_batch
    capitols = []
    Capitol.find_in_batches(batch_size: 1) do |chunk|
        capitols += chunk.map(&:country)
      end
    assert_equal(capitols, ['Canada', 'France', 'Mexico', 'The Netherlands'])
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
composite_primary_keys-8.1.8 test/test_find_in_batches.rb
composite_primary_keys-8.1.7 test/test_find_in_batches.rb
composite_primary_keys-8.1.6 test/test_find_in_batches.rb
composite_primary_keys-8.1.5 test/test_find_in_batches.rb
composite_primary_keys-8.1.4 test/test_find_in_batches.rb