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