Changeset 9129
- Timestamp:
- 03/29/08 17:53:44 (4 months ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/validations.rb (modified) (2 diffs)
- trunk/activerecord/test/cases/validations_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r9127 r9129 1 1 *SVN* 2 3 * Fixed that validates_size_of :within works in associations #11295, #10019 [cavalle] 2 4 3 5 * Track changes to unsaved attributes. [Jeremy Kemper] trunk/activerecord/lib/active_record/validations.rb
r9055 r9129 554 554 555 555 validates_each(attrs, options) do |record, attr, value| 556 if value.nil? or value.split(//).size < option_value.begin 556 value = value.split(//) if value.kind_of?(String) 557 if value.nil? or value.size < option_value.begin 557 558 record.errors.add(attr, too_short) 558 elsif value.s plit(//).size > option_value.end559 elsif value.size > option_value.end 559 560 record.errors.add(attr, too_long) 560 561 end … … 570 571 571 572 validates_each(attrs, options) do |record, attr, value| 572 if value.kind_of?(String) 573 record.errors.add(attr, message) unless !value.nil? and value.split(//).size.method(validity_checks[option])[option_value] 574 else 575 record.errors.add(attr, message) unless !value.nil? and value.size.method(validity_checks[option])[option_value] 576 end 573 value = value.split(//) if value.kind_of?(String) 574 record.errors.add(attr, message) unless !value.nil? and value.size.method(validity_checks[option])[option_value] 577 575 end 578 576 end trunk/activerecord/test/cases/validations_test.rb
r9084 r9129 806 806 reply = t.replies.build('title' => 'areply', 'content' => 'whateveragain') 807 807 assert t.valid? 808 end 809 810 def test_validates_size_of_association_using_within 811 assert_nothing_raised { Topic.validates_size_of :replies, :within => 1..2 } 812 t = Topic.new('title' => 'noreplies', 'content' => 'whatever') 813 assert !t.save 814 assert t.errors.on(:replies) 815 816 reply = t.replies.build('title' => 'areply', 'content' => 'whateveragain') 817 assert t.valid? 818 819 2.times { t.replies.build('title' => 'areply', 'content' => 'whateveragain') } 820 assert !t.save 821 assert t.errors.on(:replies) 808 822 end 809 823