Skip to content

Commit

Permalink
Cleanup old monkey patch
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan committed Nov 12, 2024
1 parent 26dabcb commit ff5193f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 20 deletions.
7 changes: 0 additions & 7 deletions lib/datagrid/drivers/abstract_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,6 @@ def default_cache_key(asset)
raise NotImplementedError
end

def where_by_timestamp_gotcha(scope, name, value)
value = Datagrid::Utils.format_date_as_timestamp(value)
scope = greater_equal(scope, name, value.first) if value.first
scope = less_equal(scope, name, value.last) if value.last
scope
end

def default_preload(scope, value)
raise NotImplementedError
end
Expand Down
8 changes: 0 additions & 8 deletions lib/datagrid/drivers/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,3 @@ def contains_predicate
end
end
end

if defined?(ActiveRecord::Base)
ActiveRecord::Base.class_eval do
def self.datagrid_where_by_timestamp(column, value)
Datagrid::Drivers::ActiveRecord.new.where_by_timestamp_gotcha(self, column, value)
end
end
end
6 changes: 3 additions & 3 deletions lib/datagrid/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ def parse_datetime(value)
def format_date_as_timestamp(value)
if !value
value
elsif value.is_a?(Array)
[value.first&.beginning_of_day, value.last&.end_of_day]
# elsif value.is_a?(Array)
# value.first&.beginning_of_day..value.last&.end_of_day
elsif value.is_a?(Range)
(value.begin&.beginning_of_day..value.end&.end_of_day)
value.begin&.beginning_of_day..value.end&.end_of_day
else
value.beginning_of_day..value.end_of_day
end
Expand Down
4 changes: 2 additions & 2 deletions spec/datagrid/drivers/active_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
end
end

describe "gotcha #datagrid_where_by_timestamp" do
describe "where by timestamp" do
subject do
test_report(created_at: 10.days.ago..5.days.ago) do
scope { Entry }

filter(:created_at, :date, range: true) do |value, scope, _grid|
scope.joins(:group).datagrid_where_by_timestamp("groups.created_at", value)
scope.joins(:group).where(groups: {created_at: value})
end
end.assets
end
Expand Down

0 comments on commit ff5193f

Please sign in to comment.