datagrid 1.5.9 → 1.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/Readme.markdown +6 -4
- data/app/views/datagrid/_table.html.erb +1 -1
- data/datagrid.gemspec +29 -166
- data/lib/datagrid/column_names_attribute.rb +15 -16
- data/lib/datagrid/columns.rb +34 -37
- data/lib/datagrid/columns/column.rb +4 -0
- data/lib/datagrid/core.rb +13 -1
- data/lib/datagrid/drivers/active_record.rb +2 -1
- data/lib/datagrid/drivers/mongoid.rb +5 -1
- data/lib/datagrid/filters.rb +3 -6
- data/lib/datagrid/filters/base_filter.rb +8 -0
- data/lib/datagrid/filters/composite_filters.rb +4 -4
- data/lib/datagrid/form_builder.rb +18 -15
- data/lib/datagrid/helper.rb +3 -3
- data/lib/datagrid/renderer.rb +2 -5
- data/lib/datagrid/utils.rb +2 -6
- data/lib/datagrid/version.rb +3 -0
- metadata +15 -201
- data/.document +0 -5
- data/.rspec +0 -1
- data/.travis.yml +0 -21
- data/Gemfile +0 -29
- data/Rakefile +0 -43
- data/VERSION +0 -1
- data/spec/datagrid/active_model_spec.rb +0 -33
- data/spec/datagrid/column_names_attribute_spec.rb +0 -86
- data/spec/datagrid/columns/column_spec.rb +0 -19
- data/spec/datagrid/columns_spec.rb +0 -592
- data/spec/datagrid/core_spec.rb +0 -196
- data/spec/datagrid/drivers/active_record_spec.rb +0 -79
- data/spec/datagrid/drivers/array_spec.rb +0 -106
- data/spec/datagrid/drivers/mongo_mapper_spec.rb +0 -101
- data/spec/datagrid/drivers/mongoid_spec.rb +0 -109
- data/spec/datagrid/drivers/sequel_spec.rb +0 -111
- data/spec/datagrid/filters/base_filter_spec.rb +0 -19
- data/spec/datagrid/filters/boolean_enum_filter_spec.rb +0 -5
- data/spec/datagrid/filters/composite_filters_spec.rb +0 -65
- data/spec/datagrid/filters/date_filter_spec.rb +0 -195
- data/spec/datagrid/filters/date_time_filter_spec.rb +0 -157
- data/spec/datagrid/filters/dynamic_filter_spec.rb +0 -175
- data/spec/datagrid/filters/enum_filter_spec.rb +0 -51
- data/spec/datagrid/filters/extended_boolean_filter_spec.rb +0 -46
- data/spec/datagrid/filters/float_filter_spec.rb +0 -15
- data/spec/datagrid/filters/integer_filter_spec.rb +0 -144
- data/spec/datagrid/filters/string_filter_spec.rb +0 -35
- data/spec/datagrid/filters_spec.rb +0 -332
- data/spec/datagrid/form_builder_spec.rb +0 -614
- data/spec/datagrid/helper_spec.rb +0 -640
- data/spec/datagrid/ordering_spec.rb +0 -150
- data/spec/datagrid/scaffold_spec.rb +0 -45
- data/spec/datagrid/stylesheet_spec.rb +0 -12
- data/spec/datagrid/utils_spec.rb +0 -19
- data/spec/datagrid_spec.rb +0 -83
- data/spec/spec_helper.rb +0 -114
- data/spec/support/active_record.rb +0 -38
- data/spec/support/configuration.rb +0 -28
- data/spec/support/i18n_helpers.rb +0 -6
- data/spec/support/matchers.rb +0 -101
- data/spec/support/mongo_mapper.rb +0 -32
- data/spec/support/mongoid.rb +0 -36
- data/spec/support/sequel.rb +0 -39
- data/spec/support/simple_report.rb +0 -64
- data/spec/support/test_partials/_actions.html.erb +0 -1
- data/spec/support/test_partials/client/datagrid/_form.html.erb +0 -13
- data/spec/support/test_partials/client/datagrid/_head.html.erb +0 -9
- data/spec/support/test_partials/client/datagrid/_order_for.html.erb +0 -11
- data/spec/support/test_partials/client/datagrid/_row.html.erb +0 -6
- data/spec/support/test_partials/client/datagrid/_table.html.erb +0 -19
- data/spec/support/test_partials/custom_checkboxes/_enum_checkboxes.html.erb +0 -1
- data/spec/support/test_partials/custom_form/_form.html.erb +0 -7
- data/spec/support/test_partials/custom_range/_range_filter.html.erb +0 -1
@@ -1,109 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Datagrid::Drivers::Mongoid, :mongoid do
|
4
|
-
|
5
|
-
describe ".match?" do
|
6
|
-
|
7
|
-
subject { described_class }
|
8
|
-
|
9
|
-
it {should be_match(MongoidEntry)}
|
10
|
-
it {should be_match(MongoidEntry.scoped)}
|
11
|
-
it {should_not be_match(Entry.where(:id => 1))}
|
12
|
-
|
13
|
-
end
|
14
|
-
describe "api" do
|
15
|
-
|
16
|
-
subject do
|
17
|
-
MongoidGrid.new(
|
18
|
-
defined?(_attributes) ? _attributes : {}
|
19
|
-
)
|
20
|
-
end
|
21
|
-
|
22
|
-
let!(:first) do
|
23
|
-
MongoidEntry.create!(
|
24
|
-
:group_id => 2,
|
25
|
-
:name => "Main First",
|
26
|
-
:disabled => false
|
27
|
-
)
|
28
|
-
end
|
29
|
-
let!(:second) do
|
30
|
-
MongoidEntry.create!(
|
31
|
-
:group_id => 3,
|
32
|
-
:name => "Main Second",
|
33
|
-
:disabled => true
|
34
|
-
)
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
describe '#assets' do
|
39
|
-
subject { super().assets }
|
40
|
-
it {should include(first, second)}
|
41
|
-
end
|
42
|
-
|
43
|
-
describe '#assets' do
|
44
|
-
subject { super().assets }
|
45
|
-
describe '#size' do
|
46
|
-
subject { super().size }
|
47
|
-
it {should == 2}
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe '#rows' do
|
52
|
-
subject { super().rows }
|
53
|
-
it {should == [["Main First", 2, false], ["Main Second", 3, true]]}
|
54
|
-
end
|
55
|
-
|
56
|
-
describe '#header' do
|
57
|
-
subject { super().header }
|
58
|
-
it {should ==[ "Name", "Group", "Disabled"]}
|
59
|
-
end
|
60
|
-
|
61
|
-
describe '#data' do
|
62
|
-
subject { super().data }
|
63
|
-
it {should == [[ "Name", "Group", "Disabled"], ["Main First", 2, false], ["Main Second", 3, true]]}
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
describe "when some filters specified" do
|
68
|
-
let(:_attributes) { {:from_group_id => 3} }
|
69
|
-
|
70
|
-
describe '#assets' do
|
71
|
-
subject { super().assets.map(&:_id) }
|
72
|
-
it {should_not include(first.id)}
|
73
|
-
end
|
74
|
-
|
75
|
-
describe '#assets' do
|
76
|
-
subject { super().assets }
|
77
|
-
it {should include(second)}
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe "when reverse ordering is specified" do
|
82
|
-
let(:_attributes) { {:order => :name, :descending => true} }
|
83
|
-
|
84
|
-
describe '#rows' do
|
85
|
-
subject { super().rows }
|
86
|
-
it {should == [["Main Second", 3, true], ["Main First", 2, false]]}
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should not provide default order for non declared fields" do
|
91
|
-
expect {
|
92
|
-
test_report(:order => :test) do
|
93
|
-
scope { MongoidEntry }
|
94
|
-
column(:test)
|
95
|
-
end.assets
|
96
|
-
}.to raise_error(Datagrid::OrderUnsupported)
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should support batch_size" do
|
100
|
-
report = test_report do
|
101
|
-
scope { MongoidEntry }
|
102
|
-
self.batch_size = 1
|
103
|
-
column(:name)
|
104
|
-
end
|
105
|
-
|
106
|
-
expect(report.data).to eq([["Name"], ["Main First"], ["Main Second"]])
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
@@ -1,111 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Datagrid::Drivers::Sequel do
|
4
|
-
|
5
|
-
describe ".match?" do
|
6
|
-
|
7
|
-
subject { described_class }
|
8
|
-
|
9
|
-
it {should be_match(SequelEntry)}
|
10
|
-
it {should be_match(SequelEntry.where(:id => 1))}
|
11
|
-
it {should_not be_match(Entry.where(:id => 1))}
|
12
|
-
|
13
|
-
end
|
14
|
-
describe "api" do
|
15
|
-
|
16
|
-
subject do
|
17
|
-
SequelGrid.new(
|
18
|
-
defined?(_attributes) ? _attributes : {}
|
19
|
-
)
|
20
|
-
end
|
21
|
-
|
22
|
-
let!(:first) do
|
23
|
-
SequelEntry.create(
|
24
|
-
:group_id => 2,
|
25
|
-
:name => "Main First",
|
26
|
-
:disabled => false
|
27
|
-
)
|
28
|
-
end
|
29
|
-
let!(:second) do
|
30
|
-
SequelEntry.create(
|
31
|
-
:group_id => 3,
|
32
|
-
:name => "Main Second",
|
33
|
-
:disabled => true
|
34
|
-
)
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
describe '#assets' do
|
39
|
-
subject { super().assets }
|
40
|
-
it {should include(first, second)}
|
41
|
-
end
|
42
|
-
|
43
|
-
describe '#assets' do
|
44
|
-
subject { super().assets }
|
45
|
-
describe '#size' do
|
46
|
-
subject { super().count }
|
47
|
-
it {should == 2}
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe '#rows' do
|
52
|
-
subject { super().rows }
|
53
|
-
it {should == [["Main First", 2, false], ["Main Second", 3, true]]}
|
54
|
-
end
|
55
|
-
|
56
|
-
describe '#header' do
|
57
|
-
subject { super().header }
|
58
|
-
it {should ==[ "Name", "Group", "Disabled"]}
|
59
|
-
end
|
60
|
-
|
61
|
-
describe '#data' do
|
62
|
-
subject { super().data }
|
63
|
-
it {should == [[ "Name", "Group", "Disabled"], ["Main First", 2, false], ["Main Second", 3, true]]}
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
describe "when some filters specified" do
|
68
|
-
let(:_attributes) { {:from_group_id => 3} }
|
69
|
-
|
70
|
-
describe '#assets' do
|
71
|
-
subject { super().assets.map(&:id) }
|
72
|
-
it {should_not include(first.id)}
|
73
|
-
end
|
74
|
-
|
75
|
-
describe '#assets' do
|
76
|
-
subject { super().assets }
|
77
|
-
it {should include(second)}
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe "when reverse ordering is specified" do
|
82
|
-
let(:_attributes) { {:order => :name, :descending => true} }
|
83
|
-
|
84
|
-
describe '#rows' do
|
85
|
-
subject { super().rows }
|
86
|
-
it {should == [["Main Second", 3, true], ["Main First", 2, false]]}
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should provide default order for non declared fields" do
|
91
|
-
expect {
|
92
|
-
test_report(:order => :test) do
|
93
|
-
scope { SequelEntry }
|
94
|
-
column(:test) do
|
95
|
-
'test'
|
96
|
-
end
|
97
|
-
end.assets
|
98
|
-
}.to raise_error(Datagrid::OrderUnsupported)
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should support batch_size" do
|
102
|
-
report = test_report do
|
103
|
-
scope { SequelEntry }
|
104
|
-
self.batch_size = 1
|
105
|
-
column(:name)
|
106
|
-
end
|
107
|
-
|
108
|
-
expect(report.data).to eq([["Name"], ["Main First"], ["Main Second"]])
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Datagrid::Filters::BaseFilter do
|
4
|
-
|
5
|
-
|
6
|
-
it "should support default option as block" do
|
7
|
-
report = test_report do
|
8
|
-
scope {Entry}
|
9
|
-
filter(:name, :string, :default => :name_default)
|
10
|
-
def name_default
|
11
|
-
'hello'
|
12
|
-
end
|
13
|
-
end
|
14
|
-
expect(report.assets).to include(Entry.create!(:name => "hello"))
|
15
|
-
expect(report.assets).not_to include(Entry.create!(:name => "world"))
|
16
|
-
expect(report.assets).not_to include(Entry.create!(:name => ""))
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Datagrid::Filters::CompositeFilters do
|
4
|
-
|
5
|
-
describe ".date_range_filters" do
|
6
|
-
|
7
|
-
it "should generate from date and to date filters" do
|
8
|
-
e1 = Entry.create!(:shipping_date => 6.days.ago)
|
9
|
-
e2 = Entry.create!(:shipping_date => 4.days.ago)
|
10
|
-
e3 = Entry.create!(:shipping_date => 1.days.ago)
|
11
|
-
assets = test_report(:from_shipping_date => 5.days.ago, :to_shipping_date => 2.day.ago) do
|
12
|
-
scope {Entry}
|
13
|
-
date_range_filters(:shipping_date)
|
14
|
-
end.assets
|
15
|
-
|
16
|
-
expect(assets).to include(e2)
|
17
|
-
expect(assets).not_to include(e1, e3)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should support options" do
|
21
|
-
report = test_report do
|
22
|
-
report = date_range_filters(:shipping_date, {:default => 10.days.ago.to_date}, {:default => Date.today})
|
23
|
-
end
|
24
|
-
expect(report.from_shipping_date).to eq(10.days.ago.to_date)
|
25
|
-
expect(report.to_shipping_date).to eq(Date.today)
|
26
|
-
end
|
27
|
-
it "should support table name in field" do
|
28
|
-
report = test_report do
|
29
|
-
report = date_range_filters("entries.shipping_date", {:default => 10.days.ago.to_date}, {:default => Date.today})
|
30
|
-
end
|
31
|
-
expect(report.from_entries_shipping_date).to eq(10.days.ago.to_date)
|
32
|
-
expect(report.to_entries_shipping_date).to eq(Date.today)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe ".integer_range_filters" do
|
37
|
-
|
38
|
-
it "should generate from integer and to integer filters" do
|
39
|
-
e1 = Entry.create!(:group_id => 1)
|
40
|
-
e2 = Entry.create!(:group_id => 3)
|
41
|
-
e3 = Entry.create!(:group_id => 5)
|
42
|
-
assets = test_report(:from_group_id => 2, :to_group_id => 4) do
|
43
|
-
scope {Entry}
|
44
|
-
integer_range_filters(:group_id)
|
45
|
-
end.assets
|
46
|
-
|
47
|
-
expect(assets).to include(e2)
|
48
|
-
expect(assets).not_to include(e1, e3)
|
49
|
-
end
|
50
|
-
it "should support options" do
|
51
|
-
report = test_report do
|
52
|
-
report = integer_range_filters(:group_id, {:default => 0}, {:default => 100})
|
53
|
-
end
|
54
|
-
expect(report.from_group_id).to eq(0)
|
55
|
-
expect(report.to_group_id).to eq(100)
|
56
|
-
end
|
57
|
-
it "should table name in field name" do
|
58
|
-
report = test_report do
|
59
|
-
report = integer_range_filters("entries.group_id", {:default => 0}, {:default => 100})
|
60
|
-
end
|
61
|
-
expect(report.from_entries_group_id).to eq(0)
|
62
|
-
expect(report.to_entries_group_id).to eq(100)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,195 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Datagrid::Filters::DateFilter do
|
4
|
-
|
5
|
-
it "should support date range argument" do
|
6
|
-
e1 = Entry.create!(:created_at => 7.days.ago)
|
7
|
-
e2 = Entry.create!(:created_at => 4.days.ago)
|
8
|
-
e3 = Entry.create!(:created_at => 1.day.ago)
|
9
|
-
report = test_report(:created_at => 5.day.ago..3.days.ago) do
|
10
|
-
scope { Entry }
|
11
|
-
filter(:created_at, :date)
|
12
|
-
end
|
13
|
-
expect(report.assets).not_to include(e1)
|
14
|
-
expect(report.assets).to include(e2)
|
15
|
-
expect(report.assets).not_to include(e3)
|
16
|
-
end
|
17
|
-
|
18
|
-
{:active_record => Entry, :mongoid => MongoidEntry, :sequel => SequelEntry}.each do |orm, klass|
|
19
|
-
describe "with orm #{orm}", orm => true do
|
20
|
-
describe "date to timestamp conversion" do
|
21
|
-
let(:klass) { klass }
|
22
|
-
subject do
|
23
|
-
test_report(:created_at => _created_at) do
|
24
|
-
scope { klass }
|
25
|
-
filter(:created_at, :date, :range => true)
|
26
|
-
end.assets.to_a
|
27
|
-
end
|
28
|
-
|
29
|
-
def entry_dated(date)
|
30
|
-
klass.create(:created_at => date)
|
31
|
-
end
|
32
|
-
|
33
|
-
context "when single date paramter given" do
|
34
|
-
let(:_created_at) { Date.today }
|
35
|
-
it { should include(entry_dated(1.second.ago))}
|
36
|
-
it { should include(entry_dated(Date.today.end_of_day))}
|
37
|
-
it { should_not include(entry_dated(Date.today.beginning_of_day - 1.second))}
|
38
|
-
it { should_not include(entry_dated(Date.today.end_of_day + 1.second))}
|
39
|
-
end
|
40
|
-
|
41
|
-
context "when range date range given" do
|
42
|
-
let(:_created_at) { [Date.yesterday, Date.today] }
|
43
|
-
it { should include(entry_dated(1.second.ago))}
|
44
|
-
it { should include(entry_dated(1.day.ago))}
|
45
|
-
it { should include(entry_dated(Date.today.end_of_day))}
|
46
|
-
it { should include(entry_dated(Date.yesterday.beginning_of_day))}
|
47
|
-
it { should_not include(entry_dated(Date.yesterday.beginning_of_day - 1.second))}
|
48
|
-
it { should_not include(entry_dated(Date.today.end_of_day + 1.second))}
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should support date range given as array argument" do
|
56
|
-
e1 = Entry.create!(:created_at => 7.days.ago)
|
57
|
-
e2 = Entry.create!(:created_at => 4.days.ago)
|
58
|
-
e3 = Entry.create!(:created_at => 1.day.ago)
|
59
|
-
report = test_report(:created_at => [5.day.ago.to_date.to_s, 3.days.ago.to_date.to_s]) do
|
60
|
-
scope { Entry }
|
61
|
-
filter(:created_at, :date, :range => true)
|
62
|
-
end
|
63
|
-
expect(report.assets).not_to include(e1)
|
64
|
-
expect(report.assets).to include(e2)
|
65
|
-
expect(report.assets).not_to include(e3)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should support minimum date argument" do
|
69
|
-
e1 = Entry.create!(:created_at => 7.days.ago)
|
70
|
-
e2 = Entry.create!(:created_at => 4.days.ago)
|
71
|
-
e3 = Entry.create!(:created_at => 1.day.ago)
|
72
|
-
report = test_report(:created_at => [5.day.ago.to_date.to_s, nil]) do
|
73
|
-
scope { Entry }
|
74
|
-
filter(:created_at, :date, :range => true)
|
75
|
-
end
|
76
|
-
expect(report.assets).not_to include(e1)
|
77
|
-
expect(report.assets).to include(e2)
|
78
|
-
expect(report.assets).to include(e3)
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should support maximum date argument" do
|
82
|
-
e1 = Entry.create!(:created_at => 7.days.ago)
|
83
|
-
e2 = Entry.create!(:created_at => 4.days.ago)
|
84
|
-
e3 = Entry.create!(:created_at => 1.day.ago)
|
85
|
-
report = test_report(:created_at => [nil, 3.days.ago.to_date.to_s]) do
|
86
|
-
scope { Entry }
|
87
|
-
filter(:created_at, :date, :range => true)
|
88
|
-
end
|
89
|
-
expect(report.assets).to include(e1)
|
90
|
-
expect(report.assets).to include(e2)
|
91
|
-
expect(report.assets).not_to include(e3)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should find something in one day interval" do
|
95
|
-
|
96
|
-
e1 = Entry.create!(:created_at => 7.days.ago)
|
97
|
-
e2 = Entry.create!(:created_at => 4.days.ago)
|
98
|
-
e3 = Entry.create!(:created_at => 1.day.ago)
|
99
|
-
report = test_report(:created_at => (4.days.ago.to_date..4.days.ago.to_date)) do
|
100
|
-
scope { Entry }
|
101
|
-
filter(:created_at, :date, :range => true)
|
102
|
-
end
|
103
|
-
expect(report.assets).not_to include(e1)
|
104
|
-
expect(report.assets).to include(e2)
|
105
|
-
expect(report.assets).not_to include(e3)
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should invert invalid range" do
|
109
|
-
range = 1.days.ago..7.days.ago
|
110
|
-
e1 = Entry.create!(:created_at => 7.days.ago)
|
111
|
-
e2 = Entry.create!(:created_at => 4.days.ago)
|
112
|
-
e3 = Entry.create!(:created_at => 1.day.ago)
|
113
|
-
report = test_report(:created_at => range) do
|
114
|
-
scope { Entry }
|
115
|
-
filter(:created_at, :date, :range => true)
|
116
|
-
end
|
117
|
-
expect(report.created_at).to eq([range.last.to_date, range.first.to_date])
|
118
|
-
expect(report.assets).to include(e1)
|
119
|
-
expect(report.assets).to include(e2)
|
120
|
-
expect(report.assets).to include(e3)
|
121
|
-
end
|
122
|
-
|
123
|
-
|
124
|
-
it "should support block" do
|
125
|
-
report = test_report(:created_at => Date.today) do
|
126
|
-
scope { Entry }
|
127
|
-
filter(:created_at, :date, :range => true) do |value|
|
128
|
-
where("created_at >= ?", value)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
expect(report.assets).not_to include(Entry.create!(:created_at => 1.day.ago))
|
132
|
-
expect(report.assets).to include(Entry.create!(:created_at => Time.now))
|
133
|
-
end
|
134
|
-
|
135
|
-
|
136
|
-
context "when date format is configured" do
|
137
|
-
around(:each) do |example|
|
138
|
-
with_date_format do
|
139
|
-
example.run
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
it "should have configurable date format" do
|
144
|
-
report = test_report(:created_at => "10/01/2013") do
|
145
|
-
scope {Entry}
|
146
|
-
filter(:created_at, :date)
|
147
|
-
end
|
148
|
-
expect(report.created_at).to eq(Date.new(2013,10,01))
|
149
|
-
end
|
150
|
-
|
151
|
-
it "should support default explicit date" do
|
152
|
-
report = test_report(:created_at => Date.parse("2013-10-01")) do
|
153
|
-
scope {Entry}
|
154
|
-
filter(:created_at, :date)
|
155
|
-
end
|
156
|
-
expect(report.created_at).to eq(Date.new(2013,10,01))
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
|
161
|
-
it "should automatically reverse Array if first more than last" do
|
162
|
-
report = test_report(:created_at => ["2013-01-01", "2012-01-01"]) do
|
163
|
-
scope {Entry}
|
164
|
-
filter(:created_at, :date, :range => true)
|
165
|
-
end
|
166
|
-
expect(report.created_at).to eq([Date.new(2012, 01, 01), Date.new(2013, 01, 01)])
|
167
|
-
end
|
168
|
-
it "should automatically reverse Array if first more than last" do
|
169
|
-
report = test_report(:created_at => ["2013-01-01", "2012-01-01"]) do
|
170
|
-
scope {Entry}
|
171
|
-
filter(:created_at, :date, :range => true)
|
172
|
-
end
|
173
|
-
expect(report.created_at).to eq([Date.new(2012, 01, 01), Date.new(2013, 01, 01)])
|
174
|
-
end
|
175
|
-
|
176
|
-
it "should nullify blank range" do
|
177
|
-
report = test_report(:created_at => [nil, nil]) do
|
178
|
-
scope {Entry}
|
179
|
-
filter(:created_at, :date, :range => true)
|
180
|
-
end
|
181
|
-
|
182
|
-
expect(report.created_at).to eq(nil)
|
183
|
-
end
|
184
|
-
|
185
|
-
it "should properly format date in filter_value_as_string" do
|
186
|
-
with_date_format do
|
187
|
-
report = test_report(:created_at => "2012-01-02") do
|
188
|
-
scope {Entry}
|
189
|
-
filter(:created_at, :date)
|
190
|
-
end
|
191
|
-
expect(report.filter_value_as_string(:created_at)).to eq("01/02/2012")
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
end
|