未验证 提交 6464683c 编写于 作者: R Rafael França 提交者: GitHub

Merge pull request #31435 from yahonda/deprecated_bigdecimal_new

Suppress `warning: BigDecimal.new is deprecated` in activerecord
......@@ -57,7 +57,7 @@ module ClassMethods
# store_listing = StoreListing.new(price_in_cents: '10.1')
#
# # before
# store_listing.price_in_cents # => BigDecimal.new(10.1)
# store_listing.price_in_cents # => BigDecimal(10.1)
#
# class StoreListing < ActiveRecord::Base
# attribute :price_in_cents, :integer
......
......@@ -6,7 +6,7 @@ module PostgreSQL
module OID # :nodoc:
class Decimal < Type::Decimal # :nodoc:
def infinity(options = {})
BigDecimal.new("Infinity") * (options[:negative] ? -1 : 1)
BigDecimal("Infinity") * (options[:negative] ? -1 : 1)
end
end
end
......
......@@ -44,6 +44,6 @@ def test_domain_acts_like_basetype
record.price = "34.15"
record.save!
assert_equal BigDecimal.new("34.15"), record.reload.price
assert_equal BigDecimal("34.15"), record.reload.price
end
end
......@@ -33,8 +33,8 @@ def test_column
end
def test_default
assert_equal BigDecimal.new("150.55"), PostgresqlMoney.column_defaults["depth"]
assert_equal BigDecimal.new("150.55"), PostgresqlMoney.new.depth
assert_equal BigDecimal("150.55"), PostgresqlMoney.column_defaults["depth"]
assert_equal BigDecimal("150.55"), PostgresqlMoney.new.depth
end
def test_money_values
......@@ -65,7 +65,7 @@ def test_create_and_update_money
money = PostgresqlMoney.create(wealth: "987.65".dup)
assert_equal 987.65, money.wealth
new_value = BigDecimal.new("123.45")
new_value = BigDecimal("123.45")
money.wealth = new_value
money.save!
money.reload
......
......@@ -134,10 +134,10 @@ def test_daterange_values
end
def test_numrange_values
assert_equal BigDecimal.new("0.1")..BigDecimal.new("0.2"), @first_range.num_range
assert_equal BigDecimal.new("0.1")...BigDecimal.new("0.2"), @second_range.num_range
assert_equal BigDecimal.new("0.1")...BigDecimal.new("Infinity"), @third_range.num_range
assert_equal BigDecimal.new("-Infinity")...BigDecimal.new("Infinity"), @fourth_range.num_range
assert_equal BigDecimal("0.1")..BigDecimal("0.2"), @first_range.num_range
assert_equal BigDecimal("0.1")...BigDecimal("0.2"), @second_range.num_range
assert_equal BigDecimal("0.1")...BigDecimal("Infinity"), @third_range.num_range
assert_equal BigDecimal("-Infinity")...BigDecimal("Infinity"), @fourth_range.num_range
assert_nil @empty_range.num_range
end
......@@ -285,14 +285,14 @@ def test_timezone_awareness_tsrange_preserve_usec
def test_create_numrange
assert_equal_round_trip(@new_range, :num_range,
BigDecimal.new("0.5")...BigDecimal.new("1"))
BigDecimal("0.5")...BigDecimal("1"))
end
def test_update_numrange
assert_equal_round_trip(@first_range, :num_range,
BigDecimal.new("0.5")...BigDecimal.new("1"))
BigDecimal("0.5")...BigDecimal("1"))
assert_nil_round_trip(@first_range, :num_range,
BigDecimal.new("0.5")...BigDecimal.new("0.5"))
BigDecimal("0.5")...BigDecimal("0.5"))
end
def test_create_daterange
......
......@@ -566,7 +566,7 @@ def test_string_defaults_in_new_schema_when_overriding_domain
end
def test_decimal_defaults_in_new_schema_when_overriding_domain
assert_equal BigDecimal.new("3.14159265358979323846"), Default.new.decimal_col, "Default of decimal column was not correctly parsed"
assert_equal BigDecimal("3.14159265358979323846"), Default.new.decimal_col, "Default of decimal column was not correctly parsed"
end
def test_bpchar_defaults_in_new_schema_when_overriding_domain
......
......@@ -38,7 +38,7 @@ def test_type_cast_false
end
def test_type_cast_bigdecimal
bd = BigDecimal.new "10.0"
bd = BigDecimal "10.0"
assert_equal bd.to_f, @conn.type_cast(bd)
end
......
......@@ -59,7 +59,7 @@ class CustomPropertiesTest < ActiveRecord::TestCase
test "nonexistent attribute" do
data = OverloadedType.new(non_existent_decimal: 1)
assert_equal BigDecimal.new(1), data.non_existent_decimal
assert_equal BigDecimal(1), data.non_existent_decimal
assert_raise ActiveRecord::UnknownAttributeError do
UnoverloadedType.new(non_existent_decimal: 1)
end
......
......@@ -53,7 +53,7 @@ def test_default_negative_integer
def test_default_decimal_number
record = DefaultNumber.new
assert_equal BigDecimal.new("2.78"), record.decimal_number
assert_equal BigDecimal("2.78"), record.decimal_number
assert_equal "2.78", record.decimal_number_before_type_cast
end
end
......
......@@ -80,7 +80,7 @@ def test_native_decimal_insert_manual_vs_automatic
TestModel.delete_all
# Now use the Rails insertion
TestModel.create wealth: BigDecimal.new("12345678901234567890.0123456789")
TestModel.create wealth: BigDecimal("12345678901234567890.0123456789")
# SELECT
row = TestModel.first
......@@ -146,7 +146,7 @@ def test_native_types
TestModel.create first_name: "bob", last_name: "bobsen",
bio: "I was born ....", age: 18, height: 1.78,
wealth: BigDecimal.new("12345678901234567890.0123456789"),
wealth: BigDecimal("12345678901234567890.0123456789"),
birthday: 18.years.ago, favorite_day: 10.days.ago,
moment_of_truth: "1782-10-10 21:40:18", male: true
......@@ -159,7 +159,7 @@ def test_native_types
# Test for 30 significant digits (beyond the 16 of float), 10 of them
# after the decimal place.
assert_equal BigDecimal.new("0012345678901234567890.0123456789"), bob.wealth
assert_equal BigDecimal("0012345678901234567890.0123456789"), bob.wealth
assert_equal true, bob.male?
......
......@@ -111,7 +111,7 @@ def test_quote_bignum
end
def test_quote_bigdecimal
bigdec = BigDecimal.new((1 << 100).to_s)
bigdec = BigDecimal((1 << 100).to_s)
assert_equal bigdec.to_s("F"), @quoter.quote(bigdec)
end
......
......@@ -265,7 +265,7 @@ def test_where_with_boolean_for_string_column
end
def test_where_with_decimal_for_string_column
count = Post.where(title: BigDecimal.new(0)).count
count = Post.where(title: BigDecimal(0)).count
assert_equal 0, count
end
......
......@@ -175,12 +175,12 @@ def self.model_name
ActiveModel::Name.new(self, nil, "Topic")
end
attribute :wibble, :decimal, scale: 2, precision: 9
validates_numericality_of :wibble, greater_than_or_equal_to: BigDecimal.new("97.18")
validates_numericality_of :wibble, greater_than_or_equal_to: BigDecimal("97.18")
end
assert_not klass.new(wibble: "97.179").valid?
assert_not klass.new(wibble: 97.179).valid?
assert_not klass.new(wibble: BigDecimal.new("97.179")).valid?
assert_not klass.new(wibble: BigDecimal("97.179")).valid?
end
def test_acceptance_validator_doesnt_require_db_connection
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册