diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2016-02-11 10:36:20 -0700 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2016-02-11 10:36:20 -0700 |
commit | 848f70e18406e3c9bd952074ce627e82a474dda7 (patch) | |
tree | 4e27ca0f92527bddb0aedd7980cfc2010166604f /activerecord/test/cases | |
parent | 2a56b2d90d4fed8548e3a1e7a7b206454858c872 (diff) | |
parent | f1daa2be5278bee61dfa9a6dc111b556df677ad8 (diff) | |
download | rails-848f70e18406e3c9bd952074ce627e82a474dda7.tar.gz rails-848f70e18406e3c9bd952074ce627e82a474dda7.tar.bz2 rails-848f70e18406e3c9bd952074ce627e82a474dda7.zip |
Merge pull request #23581 from diego-silva/uniqueness-validator-pk-fix
UniquenessValidator exclude itself when PK changed
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/validations/uniqueness_validation_test.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/test/cases/validations/uniqueness_validation_test.rb b/activerecord/test/cases/validations/uniqueness_validation_test.rb index 7502a55391..e601c53dbf 100644 --- a/activerecord/test/cases/validations/uniqueness_validation_test.rb +++ b/activerecord/test/cases/validations/uniqueness_validation_test.rb @@ -469,4 +469,15 @@ class UniquenessValidationTest < ActiveRecord::TestCase assert_match(/\AUnknown primary key for table dashboards in model/, e.message) assert_match(/Can not validate uniqueness for persisted record without primary key.\z/, e.message) end + + def test_validate_uniqueness_ignores_itself_when_primary_key_changed + Topic.validates_uniqueness_of(:title) + + t = Topic.new("title" => "This is a unique title") + assert t.save, "Should save t as unique" + + t.id += 1 + assert t.valid?, "Should be valid" + assert t.save, "Should still save t as unique" + end end |