From cd13fbd8d8071b822f6d4f8967ef80c617c036ba Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Sat, 5 Feb 2011 16:44:35 -0800 Subject: Optionally pass in the attribute being validated to an instance method validator --- activemodel/test/cases/validations/with_validation_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'activemodel/test/cases') diff --git a/activemodel/test/cases/validations/with_validation_test.rb b/activemodel/test/cases/validations/with_validation_test.rb index 33efedcd7c..07c1bd0533 100644 --- a/activemodel/test/cases/validations/with_validation_test.rb +++ b/activemodel/test/cases/validations/with_validation_test.rb @@ -183,4 +183,13 @@ class ValidatesWithTest < ActiveModel::TestCase assert !topic.valid? assert_equal ['is missing'], topic.errors[:title] end + + test "optionally pass in the attribute being validated when validating with an instance method" do + Topic.validates :title, :content, :with => :my_validation_with_arg + + topic = Topic.new :title => "foo" + assert !topic.valid? + assert topic.errors[:title].empty? + assert_equal ['is missing'], topic.errors[:content] + end end -- cgit v1.2.3