Skip to content
This repository
Browse code

Merge pull request #1130 from fcheung/formats-helpr

[Core] fix format_helper assuming p returns nil
  • Loading branch information...
commit eaaf335870436499fe61c62fe42f44cd9e1584d0 2 parents 6e0d89f + 519efbf
Frederick Cheung fcheung authored
6 tests/helpers/formats_helper.rb
@@ -48,7 +48,8 @@ def formats_kernel(original_data, original_format, original = true, strict = tru
48 48 format.delete(key)
49 49 case value
50 50 when Array
51   - valid &&= datum.is_a?(Array) || p("#{key.inspect} not Array: #{datum.inspect}")
  51 + p("#{key.inspect} not Array: #{datum.inspect}") unless datum.is_a?(Array)
  52 + valid &&= datum.is_a?(Array)
52 53 if datum.is_a?(Array) && !value.empty?
53 54 for element in datum
54 55 type = value.first
@@ -60,7 +61,8 @@ def formats_kernel(original_data, original_format, original = true, strict = tru
60 61 end
61 62 end
62 63 when Hash
63   - valid &&= datum.is_a?(Hash) || p("#{key.inspect} not Hash: #{datum.inspect}")
  64 + p("#{key.inspect} not Hash: #{datum.inspect}") unless datum.is_a?(Hash)
  65 + valid &&= datum.is_a?(Hash)
64 66 valid &&= formats_kernel(datum, value, false, strict)
65 67 else
66 68 p "#{key.inspect} not #{value.inspect}: #{datum.inspect}" unless datum.is_a?(value)
9 tests/helpers/formats_helper_tests.rb
@@ -40,6 +40,15 @@
40 40 !formats_kernel({}, {:a => String})
41 41 end
42 42
  43 + test('when an array is expected but another data type is found') do
  44 + !formats_kernel({:a => 'not an array'}, {:a => []})
  45 + end
  46 +
  47 + test('when a hash is expected but another data type is found') do
  48 + !formats_kernel({:a => 'not a hash'}, {:a => {}}, true, false)
  49 + end
  50 +
  51 +
43 52 test('non strict extra data') do
44 53 !formats_kernel({:a => :b, :b => :c}, {:z => Symbol}, true, false)
45 54 end

0 comments on commit eaaf335

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