test/test_helper.rb in groupdate-3.2.0 vs test/test_helper.rb in groupdate-3.2.1

- old
+ new

@@ -411,10 +411,23 @@ assert_raises(NoMethodError) do User.group_by_day(:created_at).undefined_calculation end end + # unscope + + def test_unscope + assert_equal User.all, User.group_by_day(:created_at).unscoped.all + end + + # pluck + + def test_pluck + create_user "2014-05-01" + assert_equal [0], User.group_by_hour_of_day(:created_at).pluck(0) + end + private def call_method(method, field, options) User.group_by_period(method, field, options).count end @@ -429,12 +442,11 @@ ) # hack for Redshift adapter, which doesn't return id on creation... user = User.last if user.id.nil? - # hack for MySQL & Redshift adapters - user.update_attributes(created_at: nil, created_on: nil) if created_at.nil? && is_redshift? + user.update_columns(created_at: nil, created_on: nil) if created_at.nil? user end def is_redshift? @@ -739,10 +751,20 @@ def test_hour_of_day_start_of_day_with_time_zone_day_start_2am assert_result :hour_of_day, 0, "2013-01-01 10:00:00", true, day_start: 2 end + # minute of hour + + def test_minute_of_hour_end_of_hour + assert_result :minute_of_hour, 59, "2017-02-09 23:59:59" + end + + def test_minute_of_hour_beginning_of_hour + assert_result :minute_of_hour, 0, "2017-02-09 00:00:00" + end + # day of week def test_day_of_week_end_of_day assert_result :day_of_week, 2, "2013-01-01 23:59:59" end @@ -939,10 +961,19 @@ expected[n] = n == 20 ? 1 : 0 end assert_equal expected, call_method(:hour_of_day, :created_at, {series: true}) end + def test_zeros_minute_of_hour + create_user "2017-02-09 20:05:00 UTC" + expected = {} + 60.times do |n| + expected[n] = n == 5 ? 1 : 0 + end + assert_equal expected, call_method(:minute_of_hour, :created_at, {series: true}) + end + def test_zeros_day_of_month create_user "1978-12-18" expected = {} (1..31).each do |n| expected[n] = n == 18 ? 1 : 0 @@ -1041,9 +1072,19 @@ end def test_format_hour_of_day_day_start create_user "2014-03-01" assert_format :hour_of_day, "12 am", "%-l %P", day_start: 2 + end + + def test_format_minute_of_hour + create_user "2017-02-09" + assert_format :minute_of_hour, "0", "%-M" + end + + def test_format_minute_of_hour_day_start + create_user "2017-02-09" + assert_format :minute_of_hour, "0", "%-M", day_start: 2 end def test_format_day_of_week create_user "2014-03-01" assert_format :day_of_week, "Sat", "%a"