diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-12-02 11:53:18 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-12-02 11:53:18 +0100 |
commit | 90e396ce65a563be90729de1f06a32535821bebb (patch) | |
tree | 75687611ca84080fce2acca61a233e55e81d6a84 /activerecord/test/cases/adapters/postgresql | |
parent | b8ec014b2d9f7cd740800a8a99839ad79f196bf8 (diff) | |
download | rails-90e396ce65a563be90729de1f06a32535821bebb.tar.gz rails-90e396ce65a563be90729de1f06a32535821bebb.tar.bz2 rails-90e396ce65a563be90729de1f06a32535821bebb.zip |
pg tests, move uniqueness validation test to array tests.
Diffstat (limited to 'activerecord/test/cases/adapters/postgresql')
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/array_test.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/array_test.rb b/activerecord/test/cases/adapters/postgresql/array_test.rb index 4408356910..db302b6294 100644 --- a/activerecord/test/cases/adapters/postgresql/array_test.rb +++ b/activerecord/test/cases/adapters/postgresql/array_test.rb @@ -271,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 |