aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2013-08-07 18:21:45 +0200
committerYves Senn <yves.senn@gmail.com>2013-08-07 20:28:14 +0200
commit806bc2add8a0807ca45fb0945856bec89a321fc8 (patch)
tree110f833ad13c44202fceffe25233e2e2b343e80b /activerecord/test
parent4343e2dda25222d3586835bb25009e1a490cda8f (diff)
downloadrails-806bc2add8a0807ca45fb0945856bec89a321fc8.tar.gz
rails-806bc2add8a0807ca45fb0945856bec89a321fc8.tar.bz2
rails-806bc2add8a0807ca45fb0945856bec89a321fc8.zip
Fix multidimensional PG arrays containing non-string items
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/adapters/postgresql/array_test.rb33
1 files changed, 19 insertions, 14 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/array_test.rb b/activerecord/test/cases/adapters/postgresql/array_test.rb
index c537b08c3e..ecdbefcd03 100644
--- a/activerecord/test/cases/adapters/postgresql/array_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/array_test.rb
@@ -12,7 +12,8 @@ class PostgresqlArrayTest < ActiveRecord::TestCase
@connection = ActiveRecord::Base.connection
@connection.transaction do
@connection.create_table('pg_arrays') do |t|
- t.string 'tags', :array => true
+ t.string 'tags', array: true
+ t.integer 'ratings', array: true
end
end
@column = PgArray.columns.find { |c| c.name == 'tags' }
@@ -78,28 +79,32 @@ class PostgresqlArrayTest < ActiveRecord::TestCase
assert_equal(['1','2','3'], x.tags)
end
- def test_multi_dimensional
- assert_cycle([['1','2'],['2','3']])
+ def test_multi_dimensional_with_strings
+ assert_cycle(:tags, [[['1'], ['2']], [['2'], ['3']]])
+ end
+
+ def test_multi_dimensional_with_integers
+ assert_cycle(:ratings, [[[1], [7]], [[8], [10]]])
end
def test_strings_with_quotes
- assert_cycle(['this has','some "s that need to be escaped"'])
+ assert_cycle(:tags, ['this has','some "s that need to be escaped"'])
end
def test_strings_with_commas
- assert_cycle(['this,has','many,values'])
+ assert_cycle(:tags, ['this,has','many,values'])
end
def test_strings_with_array_delimiters
- assert_cycle(['{','}'])
+ assert_cycle(:tags, ['{','}'])
end
def test_strings_with_null_strings
- assert_cycle(['NULL','NULL'])
+ assert_cycle(:tags, ['NULL','NULL'])
end
def test_contains_nils
- assert_cycle(['1',nil,nil])
+ assert_cycle(:tags, ['1',nil,nil])
end
def test_insert_fixture
@@ -109,17 +114,17 @@ class PostgresqlArrayTest < ActiveRecord::TestCase
end
private
- def assert_cycle array
+ def assert_cycle field, array
# test creation
- x = PgArray.create!(:tags => array)
+ x = PgArray.create!(field => array)
x.reload
- assert_equal(array, x.tags)
+ assert_equal(array, x.public_send(field))
# test updating
- x = PgArray.create!(:tags => [])
- x.tags = array
+ x = PgArray.create!(field => [])
+ x.public_send("#{field}=", array)
x.save!
x.reload
- assert_equal(array, x.tags)
+ assert_equal(array, x.public_send(field))
end
end