Skip to content
Browse files

Merge pull request #1130 from fcheung/formats-helpr

[Core] fix format_helper assuming p returns nil
  • Loading branch information...
2 parents 6e0d89f + 519efbf commit eaaf335870436499fe61c62fe42f44cd9e1584d0 @fcheung fcheung committed Sep 4, 2012
Showing with 13 additions and 2 deletions.
  1. +4 −2 tests/helpers/formats_helper.rb
  2. +9 −0 tests/helpers/formats_helper_tests.rb
View
6 tests/helpers/formats_helper.rb
@@ -48,7 +48,8 @@ def formats_kernel(original_data, original_format, original = true, strict = tru
format.delete(key)
case value
when Array
- valid &&= datum.is_a?(Array) || p("#{key.inspect} not Array: #{datum.inspect}")
+ p("#{key.inspect} not Array: #{datum.inspect}") unless datum.is_a?(Array)
+ valid &&= datum.is_a?(Array)
if datum.is_a?(Array) && !value.empty?
for element in datum
type = value.first
@@ -60,7 +61,8 @@ def formats_kernel(original_data, original_format, original = true, strict = tru
end
end
when Hash
- valid &&= datum.is_a?(Hash) || p("#{key.inspect} not Hash: #{datum.inspect}")
+ p("#{key.inspect} not Hash: #{datum.inspect}") unless datum.is_a?(Hash)
+ valid &&= datum.is_a?(Hash)
valid &&= formats_kernel(datum, value, false, strict)
else
p "#{key.inspect} not #{value.inspect}: #{datum.inspect}" unless datum.is_a?(value)
View
9 tests/helpers/formats_helper_tests.rb
@@ -40,6 +40,15 @@
!formats_kernel({}, {:a => String})
end
+ test('when an array is expected but another data type is found') do
+ !formats_kernel({:a => 'not an array'}, {:a => []})
+ end
+
+ test('when a hash is expected but another data type is found') do
+ !formats_kernel({:a => 'not a hash'}, {:a => {}}, true, false)
+ end
+
+
test('non strict extra data') do
!formats_kernel({:a => :b, :b => :c}, {:z => Symbol}, true, false)
end

0 comments on commit eaaf335

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