test, move all pg array tests into postgresql/array_test.rb
.
This commit is contained in:
parent
b95ac8a20b
commit
0b2eee453c
@ -109,19 +109,34 @@ def test_type_cast_integers
|
||||
assert_equal(['1', '2'], x.ratings)
|
||||
end
|
||||
|
||||
def test_rewrite
|
||||
@connection.execute "insert into pg_arrays (tags) VALUES ('{1,2,3}')"
|
||||
x = PgArray.first
|
||||
x.tags = ['1','2','3','4']
|
||||
assert x.save!
|
||||
end
|
||||
|
||||
def test_select
|
||||
def test_select_with_strings
|
||||
@connection.execute "insert into pg_arrays (tags) VALUES ('{1,2,3}')"
|
||||
x = PgArray.first
|
||||
assert_equal(['1','2','3'], x.tags)
|
||||
end
|
||||
|
||||
def test_rewrite_with_strings
|
||||
@connection.execute "insert into pg_arrays (tags) VALUES ('{1,2,3}')"
|
||||
x = PgArray.first
|
||||
x.tags = ['1','2','3','4']
|
||||
x.save!
|
||||
assert_equal ['1','2','3','4'], x.reload.tags
|
||||
end
|
||||
|
||||
def test_select_with_integers
|
||||
@connection.execute "insert into pg_arrays (ratings) VALUES ('{1,2,3}')"
|
||||
x = PgArray.first
|
||||
assert_equal([1, 2, 3], x.ratings)
|
||||
end
|
||||
|
||||
def test_rewrite_with_integers
|
||||
@connection.execute "insert into pg_arrays (ratings) VALUES ('{1,2,3}')"
|
||||
x = PgArray.first
|
||||
x.ratings = [2, '3', 4]
|
||||
x.save!
|
||||
assert_equal [2, 3, 4], x.reload.ratings
|
||||
end
|
||||
|
||||
def test_multi_dimensional_with_strings
|
||||
assert_cycle(:tags, [[['1'], ['2']], [['2'], ['3']]])
|
||||
end
|
||||
@ -183,6 +198,14 @@ def test_update_all
|
||||
assert_equal [], pg_array.reload.tags
|
||||
end
|
||||
|
||||
def test_escaping
|
||||
unknown = 'foo\\",bar,baz,\\'
|
||||
tags = ["hello_#{unknown}"]
|
||||
ar = PgArray.create!(tags: tags)
|
||||
ar.reload
|
||||
assert_equal tags, ar.tags
|
||||
end
|
||||
|
||||
private
|
||||
def assert_cycle field, array
|
||||
# test creation
|
||||
|
@ -38,9 +38,6 @@ def setup
|
||||
@connection = ActiveRecord::Base.connection
|
||||
@connection.execute("set lc_monetary = 'C'")
|
||||
|
||||
@connection.execute("INSERT INTO postgresql_arrays (id, commission_by_quarter, nicknames) VALUES (1, '{35000,21000,18000,17000}', '{foo,bar,baz}')")
|
||||
@first_array = PostgresqlArray.find(1)
|
||||
|
||||
@connection.execute("INSERT INTO postgresql_tsvectors (id, text_vector) VALUES (1, ' ''text'' ''vector'' ')")
|
||||
|
||||
@first_tsvector = PostgresqlTsvector.find(1)
|
||||
@ -73,23 +70,10 @@ def setup
|
||||
end
|
||||
|
||||
teardown do
|
||||
[PostgresqlArray, PostgresqlTsvector, PostgresqlMoney, PostgresqlNumber, PostgresqlTime, PostgresqlNetworkAddress,
|
||||
[PostgresqlTsvector, PostgresqlMoney, PostgresqlNumber, PostgresqlTime, PostgresqlNetworkAddress,
|
||||
PostgresqlBitString, PostgresqlOid, PostgresqlTimestampWithZone].each(&:delete_all)
|
||||
end
|
||||
|
||||
def test_array_escaping
|
||||
unknown = %(foo\\",bar,baz,\\)
|
||||
nicknames = ["hello_#{unknown}"]
|
||||
ar = PostgresqlArray.create!(nicknames: nicknames, id: 100)
|
||||
ar.reload
|
||||
assert_equal nicknames, ar.nicknames
|
||||
end
|
||||
|
||||
def test_data_type_of_array_types
|
||||
assert_equal :integer, @first_array.column_for_attribute(:commission_by_quarter).type
|
||||
assert_equal :text, @first_array.column_for_attribute(:nicknames).type
|
||||
end
|
||||
|
||||
def test_data_type_of_tsvector_types
|
||||
assert_equal :tsvector, @first_tsvector.column_for_attribute(:text_vector).type
|
||||
end
|
||||
@ -123,11 +107,6 @@ def test_data_type_of_oid_types
|
||||
assert_equal :integer, @first_oid.column_for_attribute(:obj_id).type
|
||||
end
|
||||
|
||||
def test_array_values
|
||||
assert_equal [35000,21000,18000,17000], @first_array.commission_by_quarter
|
||||
assert_equal ['foo','bar','baz'], @first_array.nicknames
|
||||
end
|
||||
|
||||
def test_tsvector_values
|
||||
assert_equal "'text' 'vector'", @first_tsvector.text_vector
|
||||
end
|
||||
@ -187,30 +166,6 @@ def test_oid_values
|
||||
assert_equal 1234, @first_oid.obj_id
|
||||
end
|
||||
|
||||
def test_update_integer_array
|
||||
new_value = [32800,95000,29350,17000]
|
||||
@first_array.commission_by_quarter = new_value
|
||||
assert @first_array.save
|
||||
assert @first_array.reload
|
||||
assert_equal new_value, @first_array.commission_by_quarter
|
||||
@first_array.commission_by_quarter = new_value
|
||||
assert @first_array.save
|
||||
assert @first_array.reload
|
||||
assert_equal new_value, @first_array.commission_by_quarter
|
||||
end
|
||||
|
||||
def test_update_text_array
|
||||
new_value = ['robby','robert','rob','robbie']
|
||||
@first_array.nicknames = new_value
|
||||
assert @first_array.save
|
||||
assert @first_array.reload
|
||||
assert_equal new_value, @first_array.nicknames
|
||||
@first_array.nicknames = new_value
|
||||
assert @first_array.save
|
||||
assert @first_array.reload
|
||||
assert_equal new_value, @first_array.nicknames
|
||||
end
|
||||
|
||||
def test_update_money
|
||||
new_value = BigDecimal.new('123.45')
|
||||
@first_money.wealth = new_value
|
||||
|
Loading…
Reference in New Issue
Block a user