test/test_helper.rb in groupdate-2.0.4 vs test/test_helper.rb in groupdate-2.1.0

- old
+ new

@@ -547,10 +547,60 @@ def test_respond_to_bad_method assert !User.group_by_day(:created_at).respond_to?(:no_such_method) end + def test_last + create_user "2011-05-01 00:00:00 UTC" + create_user "2013-05-01 00:00:00 UTC" + expected = { + utc.parse("2012-01-01 00:00:00 UTC") => 0, + utc.parse("2013-01-01 00:00:00 UTC") => 1, + utc.parse("2014-01-01 00:00:00 UTC") => 0 + } + assert_equal expected, User.group_by_year(:created_at, last: 3).count + end + + def test_format_day + create_user "2014-03-01 00:00:00 UTC" + assert_format :day, "March 1, 2014", "%B %-e, %Y" + end + + def test_format_month + create_user "2014-03-01 00:00:00 UTC" + assert_format :month, "March 2014", "%B %Y" + end + + def test_format_year + create_user "2014-03-01 00:00:00 UTC" + assert_format :year, "2014", "%Y" + end + + def test_format_hour_of_day + create_user "2014-03-01 00:00:00 UTC" + assert_format :hour_of_day, "12 am", "%-l %P" + end + + def test_format_hour_of_day_day_start + create_user "2014-03-01 00:00:00 UTC" + assert_format :hour_of_day, "2 am", "%-l %P", day_start: 2 + end + + def test_format_day_of_week + create_user "2014-03-01 00:00:00 UTC" + assert_format :day_of_week, "Sun", "%a" + end + + def test_format_day_of_week_week_start + create_user "2014-03-01 00:00:00 UTC" + assert_format :day_of_week, "Sun", "%a", week_start: :sat + end + # helpers + + def assert_format(method, expected, format, options = {}) + assert_equal expected, User.send(:"group_by_#{method}", :created_at, options.merge(format: format)).count.keys.first + end def assert_result_time(method, expected, time_str, time_zone = false, options = {}) expected = {utc.parse(expected).in_time_zone(time_zone ? "Pacific Time (US & Canada)" : utc) => 1} assert_equal expected, result(method, time_str, time_zone, options) end