Skip to content

Commit

Permalink
feat: remove casting from the finder (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
seuros authored Oct 2, 2024
1 parent d4fef0f commit a16a106
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ['2.7', '3.0', '3.1', '3.2']
ruby: ['2.7', '3.0', '3.1', '3.2', '3.3']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
1 change: 0 additions & 1 deletion lib/trailblazer/finder/find.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def initialize(entity, params, filters, paging = nil, sorting = nil, config = ni

def process_filters(ctx)
@params.reduce(@entity) do |entity, (name, value)|
value = Utils::String.to_date(value) if Utils::String.date?(value)
filter = @filters[name.to_sym] || @filters[name]
new_entity = ctx.instance_exec entity, filter[:name], value, &filter[:handler]
new_entity || entity
Expand Down
15 changes: 0 additions & 15 deletions lib/trailblazer/finder/utils/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,6 @@ def self.underscore(text)
.tr(" ", "_")
.downcase
end

def self.to_date(value)
Date.parse(value).strftime("%Y-%m-%d") if date?(value)
end

def self.date?(date)
return false unless
date.is_a?(::DateTime) ||
date.is_a?(::Date) ||
date.is_a?(::String)
return false if date.is_a?(::String) && date.size == 36 # Ignore uuids that could get casted to dates

date_hash = ::Date._parse(date.to_s)
Date.valid_date?(date_hash[:year].to_i, date_hash[:mon].to_i, date_hash[:mday].to_i)
end
end
end
end
Expand Down
18 changes: 0 additions & 18 deletions test/trailblazer/finder/utils/string_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,6 @@ def test_numeric
assert String.numeric?('1')
end

def test_date
assert String.date?('2024-01-01')
refute String.date?(nil)
refute String.date?('random')
refute String.date?(1)
assert String.date?('2024/01/01')
assert String.date?('2024.01.01')
assert String.date?('21-12-2024')
refute String.date?('0fae2de1-6537-4d36-9cdb-30edf1e37990')
end

def test_to_date
assert_equal String.to_date('28/09/2024'), '2024-09-28'
assert_equal String.to_date('2024/09/28'), '2024-09-28'
assert_equal String.to_date('28 september 2024'), '2024-09-28'
assert_nil String.to_date('third month of this year')
end

def test_camelize
assert_equal String.camelize(:paging), 'Paging'
assert_equal String.camelize(:some_random_test), 'SomeRandomTest'
Expand Down

0 comments on commit a16a106

Please sign in to comment.