grouped_validations 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  module GroupedValidations
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'
3
3
  end
@@ -60,15 +60,15 @@ module GroupedValidations
60
60
 
61
61
  with_validation_context(context) do
62
62
  _run_validate_callbacks
63
- grouped[nil] = @errors
63
+ grouped[nil] = errors
64
64
 
65
65
  validation_groups.each do |group|
66
66
  @errors = nil
67
67
  send(:"_run_validate_#{group}_callbacks")
68
- grouped[group] = @errors
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
@@ -231,6 +231,22 @@ describe GroupedValidations do
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.
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grouped_validations
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 1
10
- version: 0.3.1
9
+ - 2
10
+ version: 0.3.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam Meehan
@@ -15,7 +15,7 @@ autorequire: grouped_validations
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-03 00:00:00 +10:00
18
+ date: 2012-08-18 00:00:00 +10:00
19
19
  default_executable:
20
20
  dependencies: []
21
21