Skip to content

Commit

Permalink
fix stupid mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth Pollack committed Apr 12, 2016
1 parent 31cb591 commit 6269844
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/airborne/request_expectations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def expect_json_types_impl(expected, actual)

type_string = type.to_s

if type_string.include?('array_of') && !type_string.include?('or_null')
if type_string.include?('array_of') && !(type_string.include?('or_null') && value.nil?)
check_array_types(value, val_class, prop, type)
else
expect_type(type, val_class, prop)
Expand Down
36 changes: 25 additions & 11 deletions spec/airborne/expectations/expect_json_types_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,31 @@
end

it "should allow array of types to be null" do
mock_get('simple_get')
get '/simple_get'
expect_json_types(address: :array_or_null)
expect_json_types(address: :array_of_integers_or_null)
expect_json_types(address: :array_of_ints_or_null)
expect_json_types(address: :array_of_floats_or_null)
expect_json_types(address: :array_of_strings_or_null)
expect_json_types(address: :array_of_booleans_or_null)
expect_json_types(address: :array_of_bools_or_null)
expect_json_types(address: :array_of_objects_or_null)
expect_json_types(address: :array_of_arrays_or_null)
mock_get('array_of_types')
get '/array_of_types'
expect_json_types(nil_array: :array_or_null)
expect_json_types(nil_array: :array_of_integers_or_null)
expect_json_types(nil_array: :array_of_ints_or_null)
expect_json_types(nil_array: :array_of_floats_or_null)
expect_json_types(nil_array: :array_of_strings_or_null)
expect_json_types(nil_array: :array_of_booleans_or_null)
expect_json_types(nil_array: :array_of_bools_or_null)
expect_json_types(nil_array: :array_of_objects_or_null)
expect_json_types(nil_array: :array_of_arrays_or_null)
end

it "should check array types when not null" do
mock_get('array_of_types')
get '/array_of_types'
expect_json_types(array_of_ints: :array_or_null)
expect_json_types(array_of_ints: :array_of_integers_or_null)
expect_json_types(array_of_ints: :array_of_ints_or_null)
expect_json_types(array_of_floats: :array_of_floats_or_null)
expect_json_types(array_of_strings: :array_of_strings_or_null)
expect_json_types(array_of_bools: :array_of_booleans_or_null)
expect_json_types(array_of_bools: :array_of_bools_or_null)
expect_json_types(array_of_objects: :array_of_objects_or_null)
expect_json_types(array_of_arrays: :array_of_arrays_or_null)
end

it 'should allow empty array' do
Expand Down
9 changes: 9 additions & 0 deletions spec/test_responses/array_of_types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"array_of_ints": [1,2,3],
"array_of_floats": [1.2, 2.2, 3.3],
"array_of_strings": ["one", "two", "three"],
"array_of_bools": [true, false, true],
"array_of_objects": [{}, {}, {}],
"array_of_arrays": [[], [], []],
"nil_array": null
}

0 comments on commit 6269844

Please sign in to comment.