diff options
author | Sean Griffin <sean@thoughtbot.com> | 2015-07-25 13:05:05 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2015-07-25 13:05:53 -0600 |
commit | 119b9181ece399c67213543fb5227b82688b536f (patch) | |
tree | e490ef2e65f67ad884dac0f3f04d352f5edcb452 /activerecord/test/cases | |
parent | 9caf2cbf268137113447ac8156b862b5d84063b5 (diff) | |
download | rails-119b9181ece399c67213543fb5227b82688b536f.tar.gz rails-119b9181ece399c67213543fb5227b82688b536f.tar.bz2 rails-119b9181ece399c67213543fb5227b82688b536f.zip |
Properly allow uniqueness validations on primary keys.
This is an alternate implementation of #20966.
[Sean Griffin & presskey]
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/validations/uniqueness_validation_test.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/activerecord/test/cases/validations/uniqueness_validation_test.rb b/activerecord/test/cases/validations/uniqueness_validation_test.rb index 2608c84be2..ceca2c8366 100644 --- a/activerecord/test/cases/validations/uniqueness_validation_test.rb +++ b/activerecord/test/cases/validations/uniqueness_validation_test.rb @@ -427,4 +427,23 @@ class UniquenessValidationTest < ActiveRecord::TestCase assert reply.valid? assert topic.valid? end + + def test_validate_uniqueness_of_custom_primary_key + klass = Class.new(ActiveRecord::Base) do + self.table_name = "keyboards" + self.primary_key = :key_number + + validates_uniqueness_of :key_number + + def self.name + "Keyboard" + end + end + + klass.create!(key_number: 10) + key2 = klass.create!(key_number: 11) + + key2.key_number = 10 + assert_not key2.valid? + end end |