aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/postgresql/array_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/cases/adapters/postgresql/array_test.rb')
-rw-r--r--activerecord/test/cases/adapters/postgresql/array_test.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/array_test.rb b/activerecord/test/cases/adapters/postgresql/array_test.rb
index fa7bebf08b..db302b6294 100644
--- a/activerecord/test/cases/adapters/postgresql/array_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/array_test.rb
@@ -1,7 +1,9 @@
# encoding: utf-8
require "cases/helper"
+require 'support/schema_dumping_helper'
class PostgresqlArrayTest < ActiveRecord::TestCase
+ include SchemaDumpingHelper
include InTimeZone
OID = ActiveRecord::ConnectionAdapters::PostgreSQL::OID
@@ -108,6 +110,12 @@ class PostgresqlArrayTest < ActiveRecord::TestCase
assert_equal([1, 2], x.ratings)
end
+ def test_schema_dump_with_shorthand
+ output = dump_table_schema "pg_arrays"
+ assert_match %r[t.string\s+"tags",\s+array: true], output
+ assert_match %r[t.integer\s+"ratings",\s+array: true], output
+ end
+
def test_select_with_strings
@connection.execute "insert into pg_arrays (tags) VALUES ('{1,2,3}')"
x = PgArray.first
@@ -263,6 +271,21 @@ class PostgresqlArrayTest < ActiveRecord::TestCase
assert_instance_of PG::InvalidTextRepresentation, e.original_exception
end
+ def test_uniqueness_validation
+ klass = Class.new(PgArray) do
+ validates_uniqueness_of :tags
+
+ def self.model_name; ActiveModel::Name.new(PgArray) end
+ end
+ e1 = klass.create("tags" => ["black", "blue"])
+ assert e1.persisted?, "Saving e1"
+
+ e2 = klass.create("tags" => ["black", "blue"])
+ assert !e2.persisted?, "e2 shouldn't be valid"
+ assert e2.errors[:tags].any?, "Should have errors for tags"
+ assert_equal ["has already been taken"], e2.errors[:tags], "Should have uniqueness message for tags"
+ end
+
private
def assert_cycle field, array
# test creation