提交 b8ec014b 编写于 作者: Y Yves Senn

tests, extract pg number tests into separate file.

上级 af7c6e49
......@@ -2,9 +2,6 @@
require 'support/ddl_helper'
class PostgresqlNumber < ActiveRecord::Base
end
class PostgresqlTime < ActiveRecord::Base
end
......@@ -20,13 +17,6 @@ class PostgresqlDataTypeTest < ActiveRecord::TestCase
def setup
@connection = ActiveRecord::Base.connection
@connection.execute("INSERT INTO postgresql_numbers (id, single, double) VALUES (1, 123.456, 123456.789)")
@connection.execute("INSERT INTO postgresql_numbers (id, single, double) VALUES (2, '-Infinity', 'Infinity')")
@connection.execute("INSERT INTO postgresql_numbers (id, single, double) VALUES (3, 123.456, 'NaN')")
@first_number = PostgresqlNumber.find(1)
@second_number = PostgresqlNumber.find(2)
@third_number = PostgresqlNumber.find(3)
@connection.execute("INSERT INTO postgresql_times (id, time_interval, scaled_time_interval) VALUES (1, '1 year 2 days ago', '3 weeks ago')")
@first_time = PostgresqlTime.find(1)
......@@ -35,12 +25,7 @@ def setup
end
teardown do
[PostgresqlNumber, PostgresqlTime, PostgresqlOid].each(&:delete_all)
end
def test_data_type_of_number_types
assert_equal :float, @first_number.column_for_attribute(:single).type
assert_equal :float, @first_number.column_for_attribute(:double).type
[PostgresqlTime, PostgresqlOid].each(&:delete_all)
end
def test_data_type_of_time_types
......@@ -52,14 +37,6 @@ def test_data_type_of_oid_types
assert_equal :integer, @first_oid.column_for_attribute(:obj_id).type
end
def test_number_values
assert_equal 123.456, @first_number.single
assert_equal 123456.789, @first_number.double
assert_equal(-::Float::INFINITY, @second_number.single)
assert_equal ::Float::INFINITY, @second_number.double
assert_same ::Float::NAN, @third_number.double
end
def test_time_values
assert_equal '-1 years -2 days', @first_time.time_interval
assert_equal '-21 days', @first_time.scaled_time_interval
......@@ -69,17 +46,6 @@ def test_oid_values
assert_equal 1234, @first_oid.obj_id
end
def test_update_number
new_single = 789.012
new_double = 789012.345
@first_number.single = new_single
@first_number.double = new_double
assert @first_number.save
assert @first_number.reload
assert_equal new_single, @first_number.single
assert_equal new_double, @first_number.double
end
def test_update_time
@first_time.time_interval = '2 years 3 minutes'
assert @first_time.save
......
require "cases/helper"
class PostgresqlNumberTest < ActiveRecord::TestCase
class PostgresqlNumber < ActiveRecord::Base; end
setup do
@connection = ActiveRecord::Base.connection
@connection.create_table('postgresql_numbers') do |t|
t.column 'single', 'REAL'
t.column 'double', 'DOUBLE PRECISION'
end
end
teardown do
@connection.execute 'DROP TABLE IF EXISTS postgresql_numbers'
end
def test_data_type
assert_equal :float, PostgresqlNumber.columns_hash["single"].type
assert_equal :float, PostgresqlNumber.columns_hash["double"].type
end
def test_values
@connection.execute("INSERT INTO postgresql_numbers (id, single, double) VALUES (1, 123.456, 123456.789)")
@connection.execute("INSERT INTO postgresql_numbers (id, single, double) VALUES (2, '-Infinity', 'Infinity')")
@connection.execute("INSERT INTO postgresql_numbers (id, single, double) VALUES (3, 123.456, 'NaN')")
first, second, third = PostgresqlNumber.find(1, 2, 3)
assert_equal 123.456, first.single
assert_equal 123456.789, first.double
assert_equal(-::Float::INFINITY, second.single)
assert_equal ::Float::INFINITY, second.double
assert_same ::Float::NAN, third.double
end
def test_update
record = PostgresqlNumber.create! single: "123.456", double: "123456.789"
new_single = 789.012
new_double = 789012.345
record.single = new_single
record.double = new_double
record.save!
record.reload
assert_equal new_single, record.single
assert_equal new_double, record.double
end
end
ActiveRecord::Schema.define do
%w(postgresql_arrays postgresql_numbers postgresql_times
%w(postgresql_arrays postgresql_times
postgresql_oids defaults postgresql_timestamp_with_zones
postgresql_partitioned_table postgresql_partitioned_table_parent).each do |table_name|
execute "DROP TABLE IF EXISTS #{quote_table_name table_name}"
......@@ -51,14 +51,6 @@
);
_SQL
execute <<_SQL
CREATE TABLE postgresql_numbers (
id SERIAL PRIMARY KEY,
single REAL,
double DOUBLE PRECISION
);
_SQL
execute <<_SQL
CREATE TABLE postgresql_times (
id SERIAL PRIMARY KEY,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册