aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/postgresql/array_test.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-06-17 16:37:08 -0600
committerSean Griffin <sean@thoughtbot.com>2014-06-17 17:01:09 -0600
commitc462c2bd07548449131359b8e507ce11a44e6cb5 (patch)
tree695411cfb1a4dd05f9fb29f4357ec351dd85ea0b /activerecord/test/cases/adapters/postgresql/array_test.rb
parent838c3d25e7ee904d7a9b084c5900491211eda0e9 (diff)
downloadrails-c462c2bd07548449131359b8e507ce11a44e6cb5.tar.gz
rails-c462c2bd07548449131359b8e507ce11a44e6cb5.tar.bz2
rails-c462c2bd07548449131359b8e507ce11a44e6cb5.zip
Ensure `OID::Array#type_cast_for_database` matches PG's quoting behavior
Also takes a step towards supporting types which use a character other than ',' for the delimiter (`box` is the only built in type for which this is the case)
Diffstat (limited to 'activerecord/test/cases/adapters/postgresql/array_test.rb')
-rw-r--r--activerecord/test/cases/adapters/postgresql/array_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/array_test.rb b/activerecord/test/cases/adapters/postgresql/array_test.rb
index 0b1e3295cc..15901b389e 100644
--- a/activerecord/test/cases/adapters/postgresql/array_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/array_test.rb
@@ -3,6 +3,7 @@ require "cases/helper"
class PostgresqlArrayTest < ActiveRecord::TestCase
include InTimeZone
+ OID = ActiveRecord::ConnectionAdapters::PostgreSQL::OID
class PgArray < ActiveRecord::Base
self.table_name = 'pg_arrays'
@@ -203,6 +204,23 @@ class PostgresqlArrayTest < ActiveRecord::TestCase
assert_equal tags, ar.tags
end
+ def test_string_quoting_rules_match_pg_behavior
+ tags = ["", "one{", "two}", %(three"), "four\\", "five ", "six\t", "seven\n", "eight,", "nine", "ten\r", "NULL"]
+ x = PgArray.create!(tags: tags)
+ x.reload
+
+ assert_equal x.tags_before_type_cast, PgArray.columns_hash['tags'].type_cast_for_database(tags)
+ end
+
+ def test_quoting_non_standard_delimiters
+ strings = ["hello,", "world;"]
+ comma_delim = OID::Array.new(ActiveRecord::Type::String.new, ',')
+ semicolon_delim = OID::Array.new(ActiveRecord::Type::String.new, ';')
+
+ assert_equal %({"hello,",world;}), comma_delim.type_cast_for_database(strings)
+ assert_equal %({hello,;"world;"}), semicolon_delim.type_cast_for_database(strings)
+ end
+
def test_datetime_with_timezone_awareness
tz = "Pacific Time (US & Canada)"