require 'spec_helper' describe Datagrid::Filters::CompositeFilters do describe ".date_range_filters" do it "should generate from date and to date filters" do e1 = Entry.create!(:shipping_date => 6.days.ago) e2 = Entry.create!(:shipping_date => 4.days.ago) e3 = Entry.create!(:shipping_date => 1.days.ago) assets = test_report(:from_shipping_date => 5.days.ago, :to_shipping_date => 2.day.ago) do scope {Entry} date_range_filters(:shipping_date) end.assets assets.should include(e2) assets.should_not include(e1, e3) end it "should support options" do report = test_report do report = date_range_filters(:shipping_date, {:default => 10.days.ago.to_date}, {:default => Date.today}) end report.from_shipping_date.should == 10.days.ago.to_date report.to_shipping_date.should == Date.today end it "should support table name in field" do report = test_report do report = date_range_filters("entries.shipping_date", {:default => 10.days.ago.to_date}, {:default => Date.today}) end report.from_entries_shipping_date.should == 10.days.ago.to_date report.to_entries_shipping_date.should == Date.today end end describe ".integer_range_filters" do it "should generate from integer and to integer filters" do e1 = Entry.create!(:group_id => 1) e2 = Entry.create!(:group_id => 3) e3 = Entry.create!(:group_id => 5) assets = test_report(:from_group_id => 2, :to_group_id => 4) do scope {Entry} integer_range_filters(:group_id) end.assets assets.should include(e2) assets.should_not include(e1, e3) end it "should support options" do report = test_report do report = integer_range_filters(:group_id, {:default => 0}, {:default => 100}) end report.from_group_id.should == 0 report.to_group_id.should == 100 end it "should table name in field name" do report = test_report do report = integer_range_filters("entries.group_id", {:default => 0}, {:default => 100}) end report.from_entries_group_id.should == 0 report.to_entries_group_id.should == 100 end end end