1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

pg test, move timestamp tests over to postgresql/timestamp_test.rb.

This commit is contained in:
Yves Senn 2014-05-22 09:55:24 +02:00
parent 3ac07aa1d7
commit e4cdf35d64
2 changed files with 53 additions and 43 deletions

View file

@ -16,9 +16,6 @@ end
class PostgresqlOid < ActiveRecord::Base
end
class PostgresqlTimestampWithZone < ActiveRecord::Base
end
class PostgresqlLtree < ActiveRecord::Base
end
@ -47,13 +44,11 @@ class PostgresqlDataTypeTest < ActiveRecord::TestCase
@connection.execute("INSERT INTO postgresql_oids (id, obj_id) VALUES (1, 1234)")
@first_oid = PostgresqlOid.find(1)
@connection.execute("INSERT INTO postgresql_timestamp_with_zones (id, time) VALUES (1, '2010-01-01 10:00:00-1')")
end
teardown do
[PostgresqlTsvector, PostgresqlNumber, PostgresqlTime,
PostgresqlBitString, PostgresqlOid, PostgresqlTimestampWithZone].each(&:delete_all)
PostgresqlBitString, PostgresqlOid].each(&:delete_all)
end
def test_data_type_of_tsvector_types
@ -158,32 +153,6 @@ class PostgresqlDataTypeTest < ActiveRecord::TestCase
assert @first_oid.reload
assert_equal new_value, @first_oid.obj_id
end
def test_timestamp_with_zone_values_with_rails_time_zone_support
with_timezone_config default: :utc, aware_attributes: true do
@connection.reconnect!
@first_timestamp_with_zone = PostgresqlTimestampWithZone.find(1)
assert_equal Time.utc(2010,1,1, 11,0,0), @first_timestamp_with_zone.time
assert_instance_of Time, @first_timestamp_with_zone.time
end
ensure
@connection.reconnect!
end
def test_timestamp_with_zone_values_without_rails_time_zone_support
with_timezone_config default: :local, aware_attributes: false do
@connection.reconnect!
# make sure to use a non-UTC time zone
@connection.execute("SET time zone 'America/Jamaica'", 'SCHEMA')
@first_timestamp_with_zone = PostgresqlTimestampWithZone.find(1)
assert_equal Time.utc(2010,1,1, 11,0,0), @first_timestamp_with_zone.time
assert_instance_of Time, @first_timestamp_with_zone.time
end
ensure
@connection.reconnect!
end
end
class PostgresqlInternalDataTypeTest < ActiveRecord::TestCase

View file

@ -2,6 +2,47 @@ require 'cases/helper'
require 'models/developer'
require 'models/topic'
class PostgresqlTimestampTest < ActiveRecord::TestCase
class PostgresqlTimestampWithZone < ActiveRecord::Base; end
self.use_transactional_fixtures = false
setup do
@connection = ActiveRecord::Base.connection
@connection.execute("INSERT INTO postgresql_timestamp_with_zones (id, time) VALUES (1, '2010-01-01 10:00:00-1')")
end
teardown do
PostgresqlTimestampWithZone.delete_all
end
def test_timestamp_with_zone_values_with_rails_time_zone_support
with_timezone_config default: :utc, aware_attributes: true do
@connection.reconnect!
timestamp = PostgresqlTimestampWithZone.find(1)
assert_equal Time.utc(2010,1,1, 11,0,0), timestamp.time
assert_instance_of Time, timestamp.time
end
ensure
@connection.reconnect!
end
def test_timestamp_with_zone_values_without_rails_time_zone_support
with_timezone_config default: :local, aware_attributes: false do
@connection.reconnect!
# make sure to use a non-UTC time zone
@connection.execute("SET time zone 'America/Jamaica'", 'SCHEMA')
timestamp = PostgresqlTimestampWithZone.find(1)
assert_equal Time.utc(2010,1,1, 11,0,0), timestamp.time
assert_instance_of Time, timestamp.time
end
ensure
@connection.reconnect!
end
end
class TimestampTest < ActiveRecord::TestCase
fixtures :topics
@ -84,18 +125,18 @@ class TimestampTest < ActiveRecord::TestCase
private
def pg_datetime_precision(table_name, column_name)
results = ActiveRecord::Base.connection.execute("SELECT column_name, datetime_precision FROM information_schema.columns WHERE table_name ='#{table_name}'")
result = results.find do |result_hash|
result_hash["column_name"] == column_name
end
result && result["datetime_precision"]
def pg_datetime_precision(table_name, column_name)
results = ActiveRecord::Base.connection.execute("SELECT column_name, datetime_precision FROM information_schema.columns WHERE table_name ='#{table_name}'")
result = results.find do |result_hash|
result_hash["column_name"] == column_name
end
result && result["datetime_precision"]
end
def activerecord_column_option(tablename, column_name, option)
result = ActiveRecord::Base.connection.columns(tablename).find do |column|
column.name == column_name
end
result && result.send(option)
def activerecord_column_option(tablename, column_name, option)
result = ActiveRecord::Base.connection.columns(tablename).find do |column|
column.name == column_name
end
result && result.send(option)
end
end