Sha256: e94f9487dd48cd71d80b170ef0e609294bf1871a09f70c6d4521d20c79eb0194

Contents?: true

Size: 711 Bytes

Versions: 3

Compression:

Stored size: 711 Bytes

Contents

require_relative "test_helper"

class TestEnumerable < Minitest::Test
  include TestGroupdate

  def test_enumerable
    user_a = User.new(created_at: utc.parse("2014-01-21"))
    user_b = User.new(created_at: utc.parse("2014-03-14"))
    expected = {
      utc.parse("2014-01-01") => [user_a],
      utc.parse("2014-02-01") => [],
      utc.parse("2014-03-01") => [user_b]
    }
    assert_equal expected, [user_a, user_b].group_by_month(&:created_at)
  end

  def test_no_block
    assert_raises(ArgumentError) { [].group_by_day(:created_at) }
  end

  def call_method(method, field, options)
    Hash[User.all.to_a.group_by_period(method, options) { |u| u.send(field) }.map { |k, v| [k, v.size] }]
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
groupdate-2.5.2 test/enumerable_test.rb
groupdate-2.5.1 test/enumerable_test.rb
groupdate-2.5.0 test/enumerable_test.rb