diff options
author | Evgeny Li <exaspark@gmail.com> | 2013-11-05 18:36:48 +0400 |
---|---|---|
committer | Evgeny Li <exaspark@gmail.com> | 2013-11-22 22:22:34 +0400 |
commit | c449a74e8944eed75453963288ea7a8652f5ba93 (patch) | |
tree | e4c490f06fe5714c523a93b839a2e7d1c9352bb8 /activerecord/test/cases/validations | |
parent | 34c08d2ead9360e1d9577dbc491d221ab66a2151 (diff) | |
download | rails-c449a74e8944eed75453963288ea7a8652f5ba93.tar.gz rails-c449a74e8944eed75453963288ea7a8652f5ba93.tar.bz2 rails-c449a74e8944eed75453963288ea7a8652f5ba93.zip |
Fix validation on uniqueness of empty association
Diffstat (limited to 'activerecord/test/cases/validations')
-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 56d8db0be9..71cb9d7b1e 100644 --- a/activerecord/test/cases/validations/uniqueness_validation_test.rb +++ b/activerecord/test/cases/validations/uniqueness_validation_test.rb @@ -35,6 +35,11 @@ class Employee < ActiveRecord::Base validates_uniqueness_of :nicknames end +class TopicWithUniqEvent < Topic + belongs_to :event, foreign_key: :parent_id + validates :event, uniqueness: true +end + class UniquenessValidationTest < ActiveRecord::TestCase fixtures :topics, 'warehouse-things', :developers @@ -376,4 +381,18 @@ class UniquenessValidationTest < ActiveRecord::TestCase 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? + + topic = TopicWithUniqEvent.new(event: event) + assert_not topic.valid? + assert_equal ['has already been taken'], topic.errors[:event] + end + + def test_validate_uniqueness_on_empty_relation + topic = TopicWithUniqEvent.new + assert topic.valid? + end end |