aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-11-08 23:55:09 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-11-09 00:05:39 +0900
commit8623223a891eb61845029f6d605ea726bb3fe179 (patch)
tree89ef1732b233110ba0af9853ed8e142575458381 /activerecord/test
parent4fe27cdc15b88fed5ae725a886b7e96202f649a8 (diff)
downloadrails-8623223a891eb61845029f6d605ea726bb3fe179.tar.gz
rails-8623223a891eb61845029f6d605ea726bb3fe179.tar.bz2
rails-8623223a891eb61845029f6d605ea726bb3fe179.zip
PostgreSQL: Properly quote all `Infinity` and `NaN`
Since quoted `Infinity` and `NaN` are valid data for PostgreSQL.
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/numeric_data_test.rb24
1 files changed, 22 insertions, 2 deletions
diff --git a/activerecord/test/cases/numeric_data_test.rb b/activerecord/test/cases/numeric_data_test.rb
index 14db63890e..304714979c 100644
--- a/activerecord/test/cases/numeric_data_test.rb
+++ b/activerecord/test/cases/numeric_data_test.rb
@@ -25,7 +25,6 @@ class NumericDataTest < ActiveRecord::TestCase
assert m.save
m1 = NumericData.find(m.id)
- assert_not_nil m1
assert_kind_of Integer, m1.world_population
assert_equal 2**62, m1.world_population
@@ -50,7 +49,6 @@ class NumericDataTest < ActiveRecord::TestCase
assert m.save
m1 = NumericData.find(m.id)
- assert_not_nil m1
assert_kind_of Integer, m1.world_population
assert_equal 2**62, m1.world_population
@@ -64,4 +62,26 @@ class NumericDataTest < ActiveRecord::TestCase
assert_kind_of BigDecimal, m1.big_bank_balance
assert_equal BigDecimal("234000567.95"), m1.big_bank_balance
end
+
+ if current_adapter?(:PostgreSQLAdapter)
+ def test_numeric_fields_with_nan
+ m = NumericData.new(
+ bank_balance: BigDecimal("NaN"),
+ big_bank_balance: BigDecimal("NaN"),
+ world_population: 2**62,
+ my_house_population: 3
+ )
+ assert_predicate m.bank_balance, :nan?
+ assert_predicate m.big_bank_balance, :nan?
+ assert m.save
+
+ m1 = NumericData.find_by(
+ bank_balance: BigDecimal("NaN"),
+ big_bank_balance: BigDecimal("NaN")
+ )
+
+ assert_predicate m1.bank_balance, :nan?
+ assert_predicate m1.big_bank_balance, :nan?
+ end
+ end
end