Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/mutations/integer_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ def filter(data)

# Ensure it's the correct data type (Integer)
if !data.is_a?(Integer)
if data.is_a?(String) && data =~ /^-?\d/
data = data.to_i
if data.is_a?(String)
begin
data = Integer(data)
rescue ArgumentError
return [data, :integer]
end
else
return [data, :integer]
end
Expand Down
2 changes: 1 addition & 1 deletion spec/integer_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

it "doesnt't allow other strings, nor does it allow random objects or symbols" do
f = Mutations::IntegerFilter.new
["zero","a1", {}, [], Object.new, :d].each do |thing|
["zero", "6iamnotanumber", "a1", {}, [], Object.new, :d].each do |thing|
_filtered, errors = f.filter(thing)
assert_equal :integer, errors
end
Expand Down