test/test_helper.rb in groupdate-2.2.1 vs test/test_helper.rb in groupdate-2.3.0

- old
+ new

@@ -326,10 +326,86 @@ def test_day_of_week_start_of_day_with_time_zone_day_start_2am assert_result :day_of_week, 3, "2013-01-02 10:00:00", true, :day_start => 2 end + # day of month + + def test_day_of_month_end_of_day + assert_result :day_of_month, 31, "2013-01-31 23:59:59" + end + + def test_day_of_month_end_of_day_feb_leap_year + assert_result :day_of_month, 29, "2012-02-29 23:59:59" + end + + def test_day_of_month_start_of_day + assert_result :day_of_month, 3, "2013-01-03 00:00:00" + end + + def test_day_of_month_end_of_day_with_time_zone + assert_result :day_of_month, 31, "2013-02-01 07:59:59", true + end + + def test_day_of_month_start_of_day_with_time_zone + assert_result :day_of_month, 1, "2013-01-01 08:00:00", true + end + + # day of month starts at 2am + + def test_day_of_month_end_of_day_day_start_2am + assert_result :day_of_month, 31, "2013-01-01 01:59:59", false, :day_start => 2 + end + + def test_day_of_month_start_of_day_day_start_2am + assert_result :day_of_month, 1, "2013-01-01 02:00:00", false, :day_start => 2 + end + + def test_day_of_month_end_of_day_with_time_zone_day_start_2am + assert_result :day_of_month, 31, "2013-01-01 09:59:59", true, :day_start => 2 + end + + def test_day_of_month_start_of_day_with_time_zone_day_start_2am + assert_result :day_of_month, 1, "2013-01-01 10:00:00", true, :day_start => 2 + end + + # month of year + + def test_month_of_year_end_of_month + assert_result :month_of_year, 1, "2013-01-31 23:59:59" + end + + def test_month_of_year_start_of_month + assert_result :month_of_year, 1, "2013-01-01 00:00:00" + end + + def test_month_of_year_end_of_month_with_time_zone + assert_result :month_of_year, 1, "2013-02-01 07:59:59", true + end + + def test_month_of_year_start_of_month_with_time_zone + assert_result :month_of_year, 1, "2013-01-01 08:00:00", true + end + + # month of year starts at 2am + + def test_month_of_year_end_of_month_day_start_2am + assert_result :month_of_year, 12, "2013-01-01 01:59:59", false, :day_start => 2 + end + + def test_month_of_year_start_of_month_day_start_2am + assert_result :month_of_year, 1, "2013-01-01 02:00:00", false, :day_start => 2 + end + + def test_month_of_year_end_of_month_with_time_zone_day_start_2am + assert_result :month_of_year, 12, "2013-01-01 09:59:59", true, :day_start => 2 + end + + def test_month_of_year_start_of_month_with_time_zone_day_start_2am + assert_result :month_of_year, 1, "2013-01-01 10:00:00", true, :day_start => 2 + end + # zeros def test_zeros_second assert_zeros :second, "2013-05-01 00:00:01 UTC", ["2013-05-01 00:00:00 UTC", "2013-05-01 00:00:01 UTC", "2013-05-01 00:00:02 UTC"], "2013-05-01 00:00:00.999 UTC", "2013-05-01 00:00:02 UTC" end @@ -406,10 +482,28 @@ expected[n] = n == 20 ? 1 : 0 end assert_equal expected, call_method(:hour_of_day, :created_at, {}) end + def test_zeros_day_of_month + create_user "1978-12-18 00:00:00 UTC" + expected = {} + (1..31).each do |n| + expected[n] = n == 18 ? 1 : 0 + end + assert_equal expected, call_method(:day_of_month, :created_at, {}) + end + + def test_zeros_month_of_year + create_user "2013-05-01 00:00:00 UTC" + expected = {} + (1..12).each do |n| + expected[n] = n == 5 ? 1 : 0 + end + assert_equal expected, call_method(:month_of_year, :created_at, {}) + end + def test_zeros_excludes_end create_user "2013-05-02 00:00:00 UTC" expected = { utc.parse("2013-05-01 00:00:00 UTC") => 0 } @@ -607,10 +701,20 @@ 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 + def test_format_day_of_month + create_user "2014-03-01 00:00:00 UTC" + assert_format :day_of_month, " 1", "%e" + end + + def test_format_month_of_year + create_user "2014-01-01 00:00:00 UTC" + assert_format :month_of_year, "Jan", "%b" + end + def test_format_multiple_groups create_user "2014-03-01 00:00:00 UTC" assert_equal ({["Sun", 1] => 1}), User.group_by_week(:created_at, format: "%a").group(:score).count assert_equal ({[1, "Sun"] => 1}), User.group(:score).group_by_week(:created_at, format: "%a").count end @@ -618,9 +722,20 @@ # associations def test_associations user = create_user("2014-03-01 00:00:00 UTC") assert_empty user.posts.group_by_day(:created_at).count + end + + # activerecord default_timezone option + + def test_default_timezone_local + begin + User.default_timezone = :local + assert_raises(RuntimeError){ User.group_by_day(:created_at).count } + ensure + User.default_timezone = :utc + end end # helpers def assert_format(method, expected, format, options = {})