Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Allow empty group check when all groups empty

  • Loading branch information...
commit 8f2c1e084deef586f326202f2107a8b017cd405d 1 parent 1439559
Adam Meehan authored August 18, 2012
2  lib/grouped_validations.rb
@@ -68,7 +68,7 @@ def grouped_errors(context=nil)
68 68
         grouped[group] = errors
69 69
       end
70 70
     end
71  
-    grouped.values.all?(&:empty?) ? {} : grouped
  71
+    grouped.values.all?(&:empty?) ? Hash.new { |h,k| {} if validation_groups.include?(k) } : grouped
72 72
   ensure
73 73
     @errors = original_errors
74 74
   end
16  spec/grouped_validations_spec.rb
@@ -231,6 +231,22 @@
231 231
       person.grouped_errors.should be_empty
232 232
     end
233 233
 
  234
+    it 'should allow empty check on a group even when no errors for any group' do
  235
+      person.first_name = 'Dave'
  236
+      person.last_name = 'Smith'
  237
+      person.sex = 'Male'
  238
+
  239
+      person.grouped_errors[:first_name_group].should be_empty
  240
+      person.grouped_errors[:not_a_group].should be_nil
  241
+    end
  242
+
  243
+    it 'should be empty for group with no errors while other groups have errors' do
  244
+      person.first_name = nil
  245
+      person.last_name = 'Smith'
  246
+      person.sex = 'Male'
  247
+
  248
+      person.grouped_errors[:last_name_group].should be_empty
  249
+    end
234 250
   end
235 251
 
236 252
   # Can no longer be done. Unless I find a work around.

0 notes on commit 8f2c1e0

Please sign in to comment.
Something went wrong with that request. Please try again.