Sha256: 79bdfd2b5a1f9b6dc9a42d1b6cf8a91086097084fb28c0f6140d7d31e9e49182

Contents?: true

Size: 993 Bytes

Versions: 62

Compression:

Stored size: 993 Bytes

Contents

require 'test_helper'

module Mongoid
  class EachByTest < Workarea::TestCase
    class FooModel
      include Mongoid::Document
      field :name, type: Integer
    end

    def test_each_slice_of
      10.times { |i| FooModel.create!(name: i) }

      i = 0
      results = []

      FooModel.desc(:name).each_slice_of(2) do |models|
        i += 1
        results.push(*models)
      end

      assert_equal(5, i)
      assert_equal([9, 8, 7, 6, 5, 4, 3, 2, 1, 0], results.map(&:name))


      i = 0
      results = []

      FooModel.asc(:name).limit(7).each_slice_of(2) do |models|
        i += 1
        results.push(*models)
      end

      assert_equal(4, i)
      assert_equal([0, 1, 2, 3, 4, 5, 6], results.map(&:name))


      i = 0
      results = []

      FooModel.asc(:name).each_slice_of(100) do |models|
        i += 1
        results.push(*models)
      end

      assert_equal(1, i)
      assert_equal([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], results.map(&:name))
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 test/lib/workarea/ext/mongoid/each_by_test.rb
workarea-core-3.5.26 test/lib/workarea/ext/mongoid/each_by_test.rb
workarea-core-3.4.45 test/lib/workarea/ext/mongoid/each_by_test.rb
workarea-core-3.5.25 test/lib/workarea/ext/mongoid/each_by_test.rb
workarea-core-3.5.23 test/lib/workarea/ext/mongoid/each_by_test.rb
workarea-core-3.4.44 test/lib/workarea/ext/mongoid/each_by_test.rb
workarea-core-3.5.22 test/lib/workarea/ext/mongoid/each_by_test.rb
workarea-core-3.4.43 test/lib/workarea/ext/mongoid/each_by_test.rb
workarea-core-3.5.21 test/lib/workarea/ext/mongoid/each_by_test.rb
workarea-core-3.4.42 test/lib/workarea/ext/mongoid/each_by_test.rb
workarea-core-3.5.20 test/lib/workarea/ext/mongoid/each_by_test.rb
workarea-core-3.4.41 test/lib/workarea/ext/mongoid/each_by_test.rb
workarea-core-3.5.19 test/lib/workarea/ext/mongoid/each_by_test.rb
workarea-core-3.4.40 test/lib/workarea/ext/mongoid/each_by_test.rb
workarea-core-3.5.18 test/lib/workarea/ext/mongoid/each_by_test.rb
workarea-core-3.4.39 test/lib/workarea/ext/mongoid/each_by_test.rb
workarea-core-3.5.17 test/lib/workarea/ext/mongoid/each_by_test.rb
workarea-core-3.4.38 test/lib/workarea/ext/mongoid/each_by_test.rb
workarea-core-3.5.16 test/lib/workarea/ext/mongoid/each_by_test.rb
workarea-core-3.4.37 test/lib/workarea/ext/mongoid/each_by_test.rb