aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/postgresql/date_test.rb
blob: 1562acdcc34dda0463043c109f6abae104ff79ff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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