Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow empty group check when all groups empty

  • Loading branch information...
commit 8f2c1e084deef586f326202f2107a8b017cd405d 1 parent 1439559
@adzap authored
Showing with 17 additions and 1 deletion.
  1. +1 −1  lib/grouped_validations.rb
  2. +16 −0 spec/grouped_validations_spec.rb
View
2  lib/grouped_validations.rb
@@ -68,7 +68,7 @@ def grouped_errors(context=nil)
grouped[group] = errors
end
end
- grouped.values.all?(&:empty?) ? {} : grouped
+ grouped.values.all?(&:empty?) ? Hash.new { |h,k| {} if validation_groups.include?(k) } : grouped
ensure
@errors = original_errors
end
View
16 spec/grouped_validations_spec.rb
@@ -231,6 +231,22 @@
person.grouped_errors.should be_empty
end
+ it 'should allow empty check on a group even when no errors for any group' do
+ person.first_name = 'Dave'
+ person.last_name = 'Smith'
+ person.sex = 'Male'
+
+ person.grouped_errors[:first_name_group].should be_empty
+ person.grouped_errors[:not_a_group].should be_nil
+ end
+
+ it 'should be empty for group with no errors while other groups have errors' do
+ person.first_name = nil
+ person.last_name = 'Smith'
+ person.sex = 'Male'
+
+ person.grouped_errors[:last_name_group].should be_empty
+ end
end
# Can no longer be done. Unless I find a work around.
Please sign in to comment.
Something went wrong with that request. Please try again.