Skip to content

Commit

Permalink
Coerce empty arrays to nil (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthinea committed Dec 6, 2023
1 parent cfc163a commit 695f7b9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/superstore/types/array_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Superstore
module Types
class ArrayType < Base
def cast_value(value)
Array(value)
value.present? ? Array(value) : nil
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions test/unit/types/array_type_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ class Superstore::Types::ArrayTypeTest < Superstore::Types::TestCase
test 'cast_value' do
assert_equal ['x', 'y'], type.cast_value(['x', 'y'].to_set)
assert_equal ['x'], type.cast_value('x')
assert_nil type.cast_value(nil)
assert_nil type.cast_value([])
end
end

0 comments on commit 695f7b9

Please sign in to comment.