mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Extract NumericDataTest
to test/cases/numeric_data_test.rb
To ease to find the numeric data tests, extract `NumericDataTest` to `test/cases/numeric_data_test.rb` dedicated file.
This commit is contained in:
parent
c13dc0f825
commit
b61227be8d
2 changed files with 71 additions and 68 deletions
|
@ -15,7 +15,6 @@ require "models/boolean"
|
|||
require "models/column_name"
|
||||
require "models/subscriber"
|
||||
require "models/comment"
|
||||
require "models/numeric_data"
|
||||
require "models/minimalistic"
|
||||
require "models/warehouse_thing"
|
||||
require "models/parrot"
|
||||
|
@ -909,73 +908,6 @@ class BasicsTest < ActiveRecord::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_big_decimal_conditions
|
||||
m = NumericData.new(
|
||||
bank_balance: 1586.43,
|
||||
big_bank_balance: BigDecimal("1000234000567.95"),
|
||||
world_population: 6000000000,
|
||||
my_house_population: 3
|
||||
)
|
||||
assert m.save
|
||||
assert_equal 0, NumericData.where("bank_balance > ?", 2000.0).count
|
||||
end
|
||||
|
||||
def test_numeric_fields
|
||||
m = NumericData.new(
|
||||
bank_balance: 1586.43,
|
||||
big_bank_balance: BigDecimal("1000234000567.95"),
|
||||
world_population: 6000000000,
|
||||
my_house_population: 3
|
||||
)
|
||||
assert m.save
|
||||
|
||||
m1 = NumericData.find(m.id)
|
||||
assert_not_nil m1
|
||||
|
||||
# As with migration_test.rb, we should make world_population >= 2**62
|
||||
# to cover 64-bit platforms and test it is a Bignum, but the main thing
|
||||
# is that it's an Integer.
|
||||
assert_kind_of Integer, m1.world_population
|
||||
assert_equal 6000000000, m1.world_population
|
||||
|
||||
assert_kind_of Integer, m1.my_house_population
|
||||
assert_equal 3, m1.my_house_population
|
||||
|
||||
assert_kind_of BigDecimal, m1.bank_balance
|
||||
assert_equal BigDecimal("1586.43"), m1.bank_balance
|
||||
|
||||
assert_kind_of BigDecimal, m1.big_bank_balance
|
||||
assert_equal BigDecimal("1000234000567.95"), m1.big_bank_balance
|
||||
end
|
||||
|
||||
def test_numeric_fields_with_scale
|
||||
m = NumericData.new(
|
||||
bank_balance: 1586.43122334,
|
||||
big_bank_balance: BigDecimal("234000567.952344"),
|
||||
world_population: 6000000000,
|
||||
my_house_population: 3
|
||||
)
|
||||
assert m.save
|
||||
|
||||
m1 = NumericData.find(m.id)
|
||||
assert_not_nil m1
|
||||
|
||||
# As with migration_test.rb, we should make world_population >= 2**62
|
||||
# to cover 64-bit platforms and test it is a Bignum, but the main thing
|
||||
# is that it's an Integer.
|
||||
assert_kind_of Integer, m1.world_population
|
||||
assert_equal 6000000000, m1.world_population
|
||||
|
||||
assert_kind_of Integer, m1.my_house_population
|
||||
assert_equal 3, m1.my_house_population
|
||||
|
||||
assert_kind_of BigDecimal, m1.bank_balance
|
||||
assert_equal BigDecimal("1586.43"), m1.bank_balance
|
||||
|
||||
assert_kind_of BigDecimal, m1.big_bank_balance
|
||||
assert_equal BigDecimal("234000567.95"), m1.big_bank_balance
|
||||
end
|
||||
|
||||
def test_auto_id
|
||||
auto = AutoId.new
|
||||
auto.save
|
||||
|
|
71
activerecord/test/cases/numeric_data_test.rb
Normal file
71
activerecord/test/cases/numeric_data_test.rb
Normal file
|
@ -0,0 +1,71 @@
|
|||
require "cases/helper"
|
||||
require "models/numeric_data"
|
||||
|
||||
class NumericDataTest < ActiveRecord::TestCase
|
||||
def test_big_decimal_conditions
|
||||
m = NumericData.new(
|
||||
bank_balance: 1586.43,
|
||||
big_bank_balance: BigDecimal("1000234000567.95"),
|
||||
world_population: 6000000000,
|
||||
my_house_population: 3
|
||||
)
|
||||
assert m.save
|
||||
assert_equal 0, NumericData.where("bank_balance > ?", 2000.0).count
|
||||
end
|
||||
|
||||
def test_numeric_fields
|
||||
m = NumericData.new(
|
||||
bank_balance: 1586.43,
|
||||
big_bank_balance: BigDecimal("1000234000567.95"),
|
||||
world_population: 6000000000,
|
||||
my_house_population: 3
|
||||
)
|
||||
assert m.save
|
||||
|
||||
m1 = NumericData.find(m.id)
|
||||
assert_not_nil m1
|
||||
|
||||
# As with migration_test.rb, we should make world_population >= 2**62
|
||||
# to cover 64-bit platforms and test it is a Bignum, but the main thing
|
||||
# is that it's an Integer.
|
||||
assert_kind_of Integer, m1.world_population
|
||||
assert_equal 6000000000, m1.world_population
|
||||
|
||||
assert_kind_of Integer, m1.my_house_population
|
||||
assert_equal 3, m1.my_house_population
|
||||
|
||||
assert_kind_of BigDecimal, m1.bank_balance
|
||||
assert_equal BigDecimal("1586.43"), m1.bank_balance
|
||||
|
||||
assert_kind_of BigDecimal, m1.big_bank_balance
|
||||
assert_equal BigDecimal("1000234000567.95"), m1.big_bank_balance
|
||||
end
|
||||
|
||||
def test_numeric_fields_with_scale
|
||||
m = NumericData.new(
|
||||
bank_balance: 1586.43122334,
|
||||
big_bank_balance: BigDecimal("234000567.952344"),
|
||||
world_population: 6000000000,
|
||||
my_house_population: 3
|
||||
)
|
||||
assert m.save
|
||||
|
||||
m1 = NumericData.find(m.id)
|
||||
assert_not_nil m1
|
||||
|
||||
# As with migration_test.rb, we should make world_population >= 2**62
|
||||
# to cover 64-bit platforms and test it is a Bignum, but the main thing
|
||||
# is that it's an Integer.
|
||||
assert_kind_of Integer, m1.world_population
|
||||
assert_equal 6000000000, m1.world_population
|
||||
|
||||
assert_kind_of Integer, m1.my_house_population
|
||||
assert_equal 3, m1.my_house_population
|
||||
|
||||
assert_kind_of BigDecimal, m1.bank_balance
|
||||
assert_equal BigDecimal("1586.43"), m1.bank_balance
|
||||
|
||||
assert_kind_of BigDecimal, m1.big_bank_balance
|
||||
assert_equal BigDecimal("234000567.95"), m1.big_bank_balance
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue