Skip to content

Commit

Permalink
Fix assignment hash value with string keys to range filter
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan committed Nov 15, 2024
1 parent 481e3f5 commit bad5914
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/datagrid/filters/ranged_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def default_filter_where(scope, value)
protected

def parse_hash(result)
to_range(result[:from], result[:to])
to_range(result[:from] || result["from"], result[:to] || result["to"])
end

def to_range(from, to, exclusive = false)
Expand Down
8 changes: 8 additions & 0 deletions spec/datagrid/filters/date_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,22 @@
to = 3.days.ago
report.created_at = { from: from, to: to }
expect(report.created_at).to eq(from.to_date..to.to_date)

report.created_at = { "from" => from, "to" => to }
expect(report.created_at).to eq(from.to_date..to.to_date)

report.created_at = {}
expect(report.created_at).to eq(nil)

report.created_at = { from: nil, to: nil }
expect(report.created_at).to eq(nil)

report.created_at = { from: Date.today, to: nil }
expect(report.created_at).to eq(Date.today..nil)

report.created_at = { from: nil, to: Date.today }
expect(report.created_at).to eq(nil..Date.today)

report.created_at = { from: Time.now, to: Time.now }
expect(report.created_at).to eq(Date.today..Date.today)
end
Expand Down
2 changes: 1 addition & 1 deletion version-2/Readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ end

## Introduced range filter separator localization

A separator symbol between range filter inputs is now a part of localizations to avoid hardcore.
A separator symbol between range filter inputs is now a part of localizations to avoid hard coding.
Add `datagrid.filters.range.separator` to your localization file.

[See related view](https://github.com/bogdan/datagrid/blob/version-2/app/views/datagrid/_range_filter.html.erb#L2)
Expand Down

0 comments on commit bad5914

Please sign in to comment.