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 | |
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')
3 files changed, 16 insertions, 27 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 diff --git a/activerecord/test/cases/validations/uniqueness_validation_test.rb b/activerecord/test/cases/validations/uniqueness_validation_test.rb index c6b58d469d..524f59876e 100644 --- a/activerecord/test/cases/validations/uniqueness_validation_test.rb +++ b/activerecord/test/cases/validations/uniqueness_validation_test.rb @@ -30,11 +30,6 @@ class ReplyWithTitleObject < Reply def title; ReplyTitle.new; end end -class Employee < ActiveRecord::Base - self.table_name = 'postgresql_arrays' - validates_uniqueness_of :nicknames -end - class TopicWithUniqEvent < Topic belongs_to :event, foreign_key: :parent_id validates :event, uniqueness: true @@ -378,18 +373,6 @@ class UniquenessValidationTest < ActiveRecord::TestCase } end - if current_adapter? :PostgreSQLAdapter - def test_validate_uniqueness_with_array_column - e1 = Employee.create("nicknames" => ["john", "johnny"], "commission_by_quarter" => [1000, 1200]) - assert e1.persisted?, "Saving e1" - - e2 = Employee.create("nicknames" => ["john", "johnny"], "commission_by_quarter" => [2200]) - assert !e2.persisted?, "e2 shouldn't be valid" - assert e2.errors[:nicknames].any?, "Should have errors for nicknames" - assert_equal ["has already been taken"], e2.errors[:nicknames], "Should have uniqueness message for nicknames" - end - end - def test_validate_uniqueness_on_existing_relation event = Event.create assert TopicWithUniqEvent.create(event: event).valid? diff --git a/activerecord/test/schema/postgresql_specific_schema.rb b/activerecord/test/schema/postgresql_specific_schema.rb index 4488274f53..96e201a83e 100644 --- a/activerecord/test/schema/postgresql_specific_schema.rb +++ b/activerecord/test/schema/postgresql_specific_schema.rb @@ -1,7 +1,6 @@ ActiveRecord::Schema.define do - %w(postgresql_arrays postgresql_times - postgresql_oids defaults postgresql_timestamp_with_zones + %w(postgresql_times postgresql_oids defaults postgresql_timestamp_with_zones postgresql_partitioned_table postgresql_partitioned_table_parent).each do |table_name| execute "DROP TABLE IF EXISTS #{quote_table_name table_name}" end @@ -44,14 +43,6 @@ _SQL execute "CREATE DOMAIN schema_1.bpchar AS bpchar" execute <<_SQL - CREATE TABLE postgresql_arrays ( - id SERIAL PRIMARY KEY, - commission_by_quarter INTEGER[], - nicknames TEXT[] - ); -_SQL - - execute <<_SQL CREATE TABLE postgresql_times ( id SERIAL PRIMARY KEY, time_interval INTERVAL, |