diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-03-09 21:22:12 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-03-09 23:09:00 +0100 |
commit | ad1a24f0e04ccff17df604c7781f4805ace2ec0f (patch) | |
tree | b1c9b814eff78b9ac15cb24f3710072f6dbfe9da /activerecord/test/cases | |
parent | 15970efb2acc7767f2f20c5d649e53ace2e2ddb5 (diff) | |
download | rails-ad1a24f0e04ccff17df604c7781f4805ace2ec0f.tar.gz rails-ad1a24f0e04ccff17df604c7781f4805ace2ec0f.tar.bz2 rails-ad1a24f0e04ccff17df604c7781f4805ace2ec0f.zip |
Uniqueness validation uses a proc to specify the `:conditions` option.
This is a follow up to #5321 and follows the general direction in
AR to make things lazy evaluated.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/validations/uniqueness_validation_test.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/activerecord/test/cases/validations/uniqueness_validation_test.rb b/activerecord/test/cases/validations/uniqueness_validation_test.rb index 46e767af1a..150e3c5461 100644 --- a/activerecord/test/cases/validations/uniqueness_validation_test.rb +++ b/activerecord/test/cases/validations/uniqueness_validation_test.rb @@ -348,7 +348,7 @@ class UniquenessValidationTest < ActiveRecord::TestCase end def test_validate_uniqueness_with_conditions - Topic.validates_uniqueness_of(:title, :conditions => Topic.where('approved = ?', true)) + Topic.validates_uniqueness_of :title, conditions: -> { where('approved = ?', true) } Topic.create("title" => "I'm a topic", "approved" => true) Topic.create("title" => "I'm an unapproved topic", "approved" => false) @@ -359,6 +359,12 @@ class UniquenessValidationTest < ActiveRecord::TestCase assert t4.valid?, "t4 should be valid" end + def test_validate_uniqueness_with_non_callable_conditions_is_not_supported + assert_raises(ArgumentError) { + Topic.validates_uniqueness_of :title, conditions: Topic.where('approved = ?', true) + } + end + def test_validate_uniqueness_with_array_column return skip "Uniqueness on arrays has only been tested in PostgreSQL so far." if !current_adapter? :PostgreSQLAdapter |