Add support for datetime filter #85

Merged
merged 3 commits into from Jan 14, 2014

2 participants

@iwiznia

Here's the pull request for the datetime filter functionality. I couldn't attach it to the previous issue #84

@bogdan bogdan commented on an outdated diff Jan 13, 2014
spec/datagrid/filters/date_time_filter_spec.rb
+ it "should support date range argument" do
+ e1 = Entry.create!(:created_at => DateTime.new(2013, 1, 1, 1, 0))
+ e2 = Entry.create!(:created_at => DateTime.new(2013, 1, 1, 2, 0))
+ e3 = Entry.create!(:created_at => DateTime.new(2013, 1, 1, 3, 0))
+ report = test_report(:created_at => DateTime.new(2013, 1, 1, 1, 30)..DateTime.new(2013, 1, 1, 2, 30)) do
+ scope { Entry }
+ filter(:created_at, :datetime)
+ end
+ report.assets.should_not include(e1)
+ report.assets.should include(e2)
+ report.assets.should_not include(e3)
+ end
+
+ {:active_record => Entry, :mongoid => MongoidEntry}.each do |orm, klass|
+ describe "with orm #{orm}" do
+ describe "date to timestamp conversion" do
@bogdan
Owner
bogdan added a note Jan 13, 2014

It looks wrong in the context of timestamp filter.
Should be: timestamp to timestamp conversion, but doesn't make that much sense.

Probably these tests cross with others in this file or we just need a different description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@bogdan bogdan commented on an outdated diff Jan 13, 2014
spec/datagrid/filters/date_time_filter_spec.rb
+ end
+
+
+ it "should support block" do
+ report = test_report(:created_at => DateTime.now) do
+ scope { Entry }
+ filter(:created_at, :datetime, :range => true) do |value|
+ where("created_at >= ?", value)
+ end
+ end
+ report.assets.should_not include(Entry.create!(:created_at => 1.day.ago))
+ report.assets.should include(Entry.create!(:created_at => DateTime.tomorrow))
+ end
+
+
+ context "when date format is configured" do
@bogdan
Owner
bogdan added a note Jan 13, 2014

*datetime format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@bogdan bogdan commented on an outdated diff Jan 13, 2014
spec/datagrid/filters/date_time_filter_spec.rb
+ where("created_at >= ?", value)
+ end
+ end
+ report.assets.should_not include(Entry.create!(:created_at => 1.day.ago))
+ report.assets.should include(Entry.create!(:created_at => DateTime.tomorrow))
+ end
+
+
+ context "when date format is configured" do
+ around(:each) do |example|
+ with_datetime_format(format = "%m/%d/%Y %H:%M") do
+ example.run
+ end
+ end
+
+ it "should have configurable date format" do
@bogdan
Owner
bogdan added a note Jan 13, 2014

date => datetime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@bogdan bogdan commented on an outdated diff Jan 13, 2014
spec/datagrid/filters/date_time_filter_spec.rb
+ context "when date format is configured" do
+ around(:each) do |example|
+ with_datetime_format(format = "%m/%d/%Y %H:%M") do
+ example.run
+ end
+ end
+
+ it "should have configurable date format" do
+ report = test_report(:created_at => "10/01/2013 01:00") do
+ scope {Entry}
+ filter(:created_at, :datetime)
+ end
+ report.created_at.should == DateTime.new(2013,10,01,1,0)
+ end
+
+ it "should support default explicit date" do
@bogdan
Owner
bogdan added a note Jan 13, 2014

date => datetime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@bogdan bogdan commented on the diff Jan 13, 2014
spec/datagrid/filters/date_time_filter_spec.rb
+ end
+ report.created_at.should == DateTime.new(2013,10,01,1,0)
+ end
+
+ it "should support default explicit date" do
+ report = test_report(:created_at => DateTime.parse("2013-10-01 01:00")) do
+ scope {Entry}
+ filter(:created_at, :datetime)
+ end
+ report.created_at.should == DateTime.new(2013,10,01,1,0)
+ end
+ end
+
+
+ it "should automatically reverse Array if first more than last" do
+ report = test_report(:created_at => ["2013-01-01 01:00", "2012-01-01 01:00"]) do
@bogdan
Owner
bogdan added a note Jan 13, 2014

Body doesn't match the description of the test.
We need to test that datagrid automatically reverses:

["2013-01-01 02:00", "2012-01-01 01:00"] to ["2013-01-01 01:00", "2012-01-01 02:00"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@iwiznia

I changed the date's to datetime in the specs descriptions... not sure if that's what you meant. Also, what's wrong with the last test? It's checking that if you pass a range with the first value grater than the second, it reverses it...

@bogdan bogdan commented on an outdated diff Jan 13, 2014
spec/datagrid/filters/date_time_filter_spec.rb
+ it "should support datetime range argument" do
+ e1 = Entry.create!(:created_at => DateTime.new(2013, 1, 1, 1, 0))
+ e2 = Entry.create!(:created_at => DateTime.new(2013, 1, 1, 2, 0))
+ e3 = Entry.create!(:created_at => DateTime.new(2013, 1, 1, 3, 0))
+ report = test_report(:created_at => DateTime.new(2013, 1, 1, 1, 30)..DateTime.new(2013, 1, 1, 2, 30)) do
+ scope { Entry }
+ filter(:created_at, :datetime)
+ end
+ report.assets.should_not include(e1)
+ report.assets.should include(e2)
+ report.assets.should_not include(e3)
+ end
+
+ {:active_record => Entry, :mongoid => MongoidEntry}.each do |orm, klass|
+ describe "with orm #{orm}" do
+ describe "timestamp to timestamp conversion" do
@bogdan
Owner
bogdan added a note Jan 13, 2014

Lets just remove this description block - it makes no sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@iwiznia

Done.

@bogdan bogdan merged commit c34fd49 into bogdan:master Jan 14, 2014
@iwiznia

Damn! I forgot to increase the version number... Is it ok if I change the version to 1.0.4?

@bogdan
Owner
@iwiznia

Ok, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment