From 82bf828da93b745f18eb4c624a02ebb7cbb37495 Mon Sep 17 00:00:00 2001 From: Bogdan Gusiev Date: Thu, 14 Nov 2024 11:29:26 +0100 Subject: [PATCH] Add date to timestamp conversion test --- spec/datagrid/filters/date_filter_spec.rb | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/spec/datagrid/filters/date_filter_spec.rb b/spec/datagrid/filters/date_filter_spec.rb index 865b61d..a3e9296 100644 --- a/spec/datagrid/filters/date_filter_spec.rb +++ b/spec/datagrid/filters/date_filter_spec.rb @@ -171,14 +171,14 @@ def entry_dated(date) end end - it "should automatically reverse Array if first more than last" do + it "should automatically reverse if first more than last" do report = test_report(created_at: %w[2013-01-01 2012-01-01]) do scope { Entry } filter(:created_at, :date, range: true) end expect(report.created_at).to eq([Date.new(2012, 0o1, 0o1), Date.new(2013, 0o1, 0o1)]) end - it "should automatically reverse Array if first more than last" do + it "should automatically reverse if first more than last" do report = test_report(created_at: %w[2013-01-01 2012-01-01]) do scope { Entry } filter(:created_at, :date, range: true) @@ -204,4 +204,21 @@ def entry_dated(date) expect(report.filter_value_as_string(:created_at)).to eq("01/02/2012") end end + + it "supports search by timestamp column" do + report = test_report(created_at: Date.today) do + scope {Entry} + filter(:created_at, :date) + end + e1 = Entry.create!(created_at: Date.yesterday + 23.hours) + e2 = Entry.create!(created_at: Date.today.to_time) + e3 = Entry.create!(created_at: Date.today + 12.hours) + e4 = Entry.create!(created_at: Date.today + 23.hours) + e5 = Entry.create!(created_at: Date.tomorrow) + expect(report.assets).to_not include(e1) + expect(report.assets).to include(e2) + expect(report.assets).to include(e3) + expect(report.assets).to include(e4) + expect(report.assets).to_not include(e5) + end end