diff options
author | José Valim <jose.valim@gmail.com> | 2012-03-17 07:13:58 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-03-17 07:13:58 -0700 |
commit | 4711298767b3d67a15f7dadeb2d8b40bb6356ad5 (patch) | |
tree | 055772ce940da94fb48bf44f72dda809d86b6e76 /activerecord/test | |
parent | 21e530008929bc513574719b286084b025b9b036 (diff) | |
parent | 4b6daef3fc0f1edc5bfdcfb4e0a9572f1f4f56ec (diff) | |
download | rails-4711298767b3d67a15f7dadeb2d8b40bb6356ad5.tar.gz rails-4711298767b3d67a15f7dadeb2d8b40bb6356ad5.tar.bz2 rails-4711298767b3d67a15f7dadeb2d8b40bb6356ad5.zip |
Merge pull request #5321 from pfeiffer/uniqueness_validator_conditions
Add :conditions option to uniqueness validator
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/validations/uniqueness_validation_test.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/test/cases/validations/uniqueness_validation_test.rb b/activerecord/test/cases/validations/uniqueness_validation_test.rb index 79442d68b0..376c0000c7 100644 --- a/activerecord/test/cases/validations/uniqueness_validation_test.rb +++ b/activerecord/test/cases/validations/uniqueness_validation_test.rb @@ -325,4 +325,16 @@ class UniquenessValidationTest < ActiveRecord::TestCase assert w6.errors[:city].any?, "Should have errors for city" assert_equal ["has already been taken"], w6.errors[:city], "Should have uniqueness message for city" end + + def test_validate_uniqueness_with_conditions + Topic.validates_uniqueness_of(:title, :conditions => Topic.where('approved = ?', true)) + t1 = Topic.create("title" => "I'm a topic", "approved" => true) + t2 = Topic.create("title" => "I'm an unapproved topic", "approved" => false) + + t3 = Topic.new("title" => "I'm a topic", "approved" => true) + assert !t3.valid?, "t3 shouldn't be valid" + + t4 = Topic.new("title" => "I'm an unapproved topic", "approved" => false) + assert t4.valid?, "t4 should be valid" + end end |