From 1a60826c9db0e08ca098ce89cdad624f3f7459b9 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sat, 13 Feb 2021 14:46:01 +0900 Subject: [PATCH] Add test case for `average` on the interval column --- .../test/cases/adapters/postgresql/interval_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/activerecord/test/cases/adapters/postgresql/interval_test.rb b/activerecord/test/cases/adapters/postgresql/interval_test.rb index ca1fe4bc76..fc134be532 100644 --- a/activerecord/test/cases/adapters/postgresql/interval_test.rb +++ b/activerecord/test/cases/adapters/postgresql/interval_test.rb @@ -86,6 +86,14 @@ class PostgresqlIntervalTest < ActiveRecord::PostgreSQLTestCase assert_equal "P1DT1H", i.legacy_term end + def test_average_interval_type + IntervalDataType.create!([{ maximum_term: 6.years }, { maximum_term: 4.months }]) + value = IntervalDataType.average(:maximum_term) + + assert_equal 3.years + 2.months, value + assert_instance_of ActiveSupport::Duration, value + end + def test_deprecated_legacy_type assert_deprecated do DeprecatedIntervalDataType.new