Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def convert_string(value)
else
klass.parse(value) || value
end
rescue ArgumentError
rescue ArgumentError, TypeError
value
end

Expand Down
2 changes: 1 addition & 1 deletion lib/active_interaction/filters/abstract_numeric_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def converter(value)

def safe_converter(value)
converter(value)
rescue ArgumentError
rescue ArgumentError, TypeError
value
end
end
Expand Down
16 changes: 16 additions & 0 deletions spec/active_interaction/filters/date_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ def to_str
end
end

context 'with a #to_str that returns a non-String' do
let(:value) do
Class.new do
def to_str
:not_a_string
end
end.new
end

it 'returns a filter error instead of raising TypeError' do
expect { result }.not_to raise_error
expect(result.errors.first).to be_an_instance_of ActiveInteraction::Filter::Error
expect(result.errors.first.type).to be :invalid_type
end
end

context 'with a blank String' do
let(:value) do
Class.new do
Expand Down
16 changes: 16 additions & 0 deletions spec/active_interaction/filters/integer_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ def to_str
end
end

context 'with a #to_str that returns a non-String' do
let(:value) do
Class.new do
def to_str
:not_a_string
end
end.new
end

it 'returns a filter error instead of raising TypeError' do
expect { result }.not_to raise_error
expect(result.errors.first).to be_an_instance_of ActiveInteraction::Filter::Error
expect(result.errors.first.type).to be :invalid_type
end
end

context 'with a blank String' do
let(:value) do
Class.new do
Expand Down