Sha256: 5faf37a29d9905344c126d2086844e4e471a73dec3500cceca918d88c1ade6d0
Contents?: true
Size: 1.07 KB
Versions: 1
Compression:
Stored size: 1.07 KB
Contents
require_relative "test_helper" require "ostruct" class TestEnumerable < Minitest::Test include TestGroupdate def test_enumerable user_a = create_user("2014-01-21") user_b = create_user("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[@users.group_by_period(method, options) { |u| u.send(field) }.map { |k, v| [k, v.size] }] end def create_user(created_at, score = 1) user = OpenStruct.new( name: "Andrew", score: score, created_at: created_at ? utc.parse(created_at) : nil, created_on: created_at ? Date.parse(created_at) : nil ) @users << user user end def setup super @users = [] end def teardown # do nothing end def enumerable_test? true end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
groupdate-2.5.3 | test/enumerable_test.rb |