diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2016-02-23 12:24:07 -0700 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2016-02-23 12:24:07 -0700 |
commit | 96c1ada82d90810df92f402da0c063e8bc0d01ed (patch) | |
tree | 817df8fe90e462c1e216cf73f5c12f6dcab72eea /activerecord/test/cases/validations | |
parent | 3adc35aefa7e5f58fe0e7d6678daeaa5e47dd7df (diff) | |
parent | 55385c8a39117f5c1b78fcb703f9d7ac14d97d12 (diff) | |
download | rails-96c1ada82d90810df92f402da0c063e8bc0d01ed.tar.gz rails-96c1ada82d90810df92f402da0c063e8bc0d01ed.tar.bz2 rails-96c1ada82d90810df92f402da0c063e8bc0d01ed.zip |
Merge pull request #23628 from maclover7/fix-23625
Fix issue #23625
Diffstat (limited to 'activerecord/test/cases/validations')
-rw-r--r-- | activerecord/test/cases/validations/uniqueness_validation_test.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/activerecord/test/cases/validations/uniqueness_validation_test.rb b/activerecord/test/cases/validations/uniqueness_validation_test.rb index e601c53dbf..2217e52f4b 100644 --- a/activerecord/test/cases/validations/uniqueness_validation_test.rb +++ b/activerecord/test/cases/validations/uniqueness_validation_test.rb @@ -5,6 +5,7 @@ require 'models/warehouse_thing' require 'models/guid' require 'models/event' require 'models/dashboard' +require 'models/uuid_item' class Wizard < ActiveRecord::Base self.abstract_class = true @@ -48,6 +49,10 @@ class BigIntReverseTest < ActiveRecord::Base validates :engines_count, uniqueness: true end +class CoolTopic < Topic + validates_uniqueness_of :id +end + class UniquenessValidationTest < ActiveRecord::TestCase INT_MAX_VALUE = 2147483647 @@ -480,4 +485,25 @@ class UniquenessValidationTest < ActiveRecord::TestCase assert t.valid?, "Should be valid" assert t.save, "Should still save t as unique" end + + def test_validate_uniqueness_uuid + skip unless current_adapter?(:PostgreSQLAdapter) + item = UuidItem.create!(uuid: SecureRandom.uuid, title: 'item1') + item.update(title: 'item1-title2') + assert_empty item.errors + + item2 = UuidValidatingItem.create!(uuid: SecureRandom.uuid, title: 'item2') + item2.update(title: 'item2-title2') + assert_empty item2.errors + end + + def test_validate_uniqueness_regular_id + item = CoolTopic.create!(title: 'MyItem') + assert_empty item.errors + + item2 = CoolTopic.new(id: item.id, title: 'MyItem2') + refute item2.valid? + + assert_equal(["has already been taken"], item2.errors[:id]) + end end |