aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/postgresql/date_test.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-02-19 03:38:50 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-02-23 11:15:00 +0900
commit5d78256ee31edddf9e5deb9a50f2633482279bc3 (patch)
tree80e51a75de8f179c2b397abc79ae281130d4d2a5 /activerecord/test/cases/adapters/postgresql/date_test.rb
parent6d63b5e49a399fe246afcebad45c3c962de268fa (diff)
downloadrails-5d78256ee31edddf9e5deb9a50f2633482279bc3.tar.gz
rails-5d78256ee31edddf9e5deb9a50f2633482279bc3.tar.bz2
rails-5d78256ee31edddf9e5deb9a50f2633482279bc3.zip
PostgreSQL: Treat infinite values in date like datetime consistently
The values infinity and -infinity are supported by both date and timestamp types. https://www.postgresql.org/docs/current/static/datatype-datetime.html#DATATYPE-DATETIME-SPECIAL-TABLE And also, it can not be known whether a value is infinity correctly unless cast a value. I've added `QueryAttribute#infinity?` to handle that case. Closes #27585.
Diffstat (limited to 'activerecord/test/cases/adapters/postgresql/date_test.rb')
-rw-r--r--activerecord/test/cases/adapters/postgresql/date_test.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/date_test.rb b/activerecord/test/cases/adapters/postgresql/date_test.rb
new file mode 100644
index 0000000000..1562acdcc3
--- /dev/null
+++ b/activerecord/test/cases/adapters/postgresql/date_test.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+require "cases/helper"
+require "models/topic"
+
+class PostgresqlDateTest < ActiveRecord::PostgreSQLTestCase
+ def test_load_infinity_and_beyond
+ topic = Topic.find_by_sql("SELECT 'infinity'::date AS last_read").first
+ assert topic.last_read.infinite?, "timestamp should be infinite"
+ assert_operator topic.last_read, :>, 0
+
+ topic = Topic.find_by_sql("SELECT '-infinity'::date AS last_read").first
+ assert topic.last_read.infinite?, "timestamp should be infinite"
+ assert_operator topic.last_read, :<, 0
+ end
+
+ def test_save_infinity_and_beyond
+ topic = Topic.create!(last_read: 1.0 / 0.0)
+ assert_equal(1.0 / 0.0, topic.last_read)
+
+ topic = Topic.create!(last_read: -1.0 / 0.0)
+ assert_equal(-1.0 / 0.0, topic.last_read)
+ end
+end