datagrid 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +8 -6
- data/VERSION +1 -1
- data/app/views/datagrid/_form.html.erb +3 -1
- data/datagrid.gemspec +6 -6
- data/lib/datagrid.rb +1 -0
- data/lib/datagrid/columns.rb +14 -7
- data/lib/datagrid/columns/column.rb +7 -4
- data/lib/datagrid/renderer.rb +1 -1
- data/spec/datagrid/active_model_spec.rb +4 -4
- data/spec/datagrid/column_names_attribute_spec.rb +15 -11
- data/spec/datagrid/columns_spec.rb +80 -62
- data/spec/datagrid/core_spec.rb +6 -6
- data/spec/datagrid/drivers/active_record_spec.rb +4 -4
- data/spec/datagrid/drivers/array_spec.rb +41 -8
- data/spec/datagrid/drivers/mongo_mapper_spec.rb +42 -10
- data/spec/datagrid/drivers/mongoid_spec.rb +43 -11
- data/spec/datagrid/filters/composite_filters_spec.rb +12 -12
- data/spec/datagrid/filters/date_filter_spec.rb +25 -25
- data/spec/datagrid/filters/date_time_filter_spec.rb +20 -20
- data/spec/datagrid/filters/dynamic_filter_spec.rb +43 -43
- data/spec/datagrid/filters/enum_filter_spec.rb +6 -6
- data/spec/datagrid/filters/extended_boolean_filter_spec.rb +10 -10
- data/spec/datagrid/filters/float_filter_spec.rb +2 -2
- data/spec/datagrid/filters/integer_filter_spec.rb +34 -34
- data/spec/datagrid/filters/string_filter_spec.rb +7 -7
- data/spec/datagrid/filters_spec.rb +20 -20
- data/spec/datagrid/form_builder_spec.rb +5 -5
- data/spec/datagrid/helper_spec.rb +41 -40
- data/spec/datagrid/ordering_spec.rb +22 -22
- data/spec/datagrid/scaffold_spec.rb +2 -2
- data/spec/datagrid/utils_spec.rb +3 -3
- data/spec/datagrid_spec.rb +10 -7
- data/spec/support/matchers.rb +6 -3
- metadata +30 -30
data/spec/datagrid/core_spec.rb
CHANGED
@@ -15,7 +15,7 @@ describe Datagrid::Core do
|
|
15
15
|
context 'in the class' do
|
16
16
|
let(:report) { report_class.new }
|
17
17
|
|
18
|
-
it { expect(report.scope.to_a).to
|
18
|
+
it { expect(report.scope.to_a.size).to eq(2) }
|
19
19
|
end
|
20
20
|
|
21
21
|
context 'changes scope on the fly' do
|
@@ -25,26 +25,26 @@ describe Datagrid::Core do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
it { expect(report.scope.to_a).to
|
28
|
+
it { expect(report.scope.to_a.size).to eq(1) }
|
29
29
|
end
|
30
30
|
|
31
31
|
context 'overriding scope by initializer' do
|
32
32
|
let(:report) { report_class.new { Entry.limit(1) } }
|
33
33
|
|
34
|
-
it { expect(report.scope.to_a).to
|
34
|
+
it { expect(report.scope.to_a.size).to eq(1) }
|
35
35
|
|
36
36
|
context "reset scope to default" do
|
37
37
|
before do
|
38
38
|
report.reset_scope
|
39
39
|
end
|
40
|
-
it { expect(report.scope.to_a).to
|
40
|
+
it { expect(report.scope.to_a.size).to eq(2) }
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
context "appending scope by initializer " do
|
45
45
|
let(:report) { report_class.new {|scope| scope.limit(1)} }
|
46
|
-
it { expect(report.scope.to_a).to
|
47
|
-
it { expect(report.scope.order_values).to
|
46
|
+
it { expect(report.scope.to_a.size).to eq(1) }
|
47
|
+
it { expect(report.scope.order_values.size).to eq(1) }
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -11,13 +11,13 @@ describe Datagrid::Drivers::ActiveRecord do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should convert any scope to AR::Relation" do
|
14
|
-
subject.to_scope(Entry).
|
15
|
-
subject.to_scope(Entry.limit(5)).
|
16
|
-
subject.to_scope(Group.create!.entries).
|
14
|
+
expect(subject.to_scope(Entry)).to be_a(ActiveRecord::Relation)
|
15
|
+
expect(subject.to_scope(Entry.limit(5))).to be_a(ActiveRecord::Relation)
|
16
|
+
expect(subject.to_scope(Group.create!.entries)).to be_a(ActiveRecord::Relation)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should support append_column_queries" do
|
20
20
|
scope = subject.append_column_queries(Entry.scoped, [Datagrid::Columns::Column.new(SimpleReport, :sum_group_id, 'sum(entries.group_id)')])
|
21
|
-
scope.to_sql.strip.
|
21
|
+
expect(scope.to_sql.strip).to eq('SELECT "entries".*, sum(entries.group_id) AS sum_group_id FROM "entries"')
|
22
22
|
end
|
23
23
|
end
|
@@ -38,23 +38,56 @@ describe Datagrid::Drivers::Array do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
describe '#assets' do
|
42
|
+
subject { super().assets }
|
43
|
+
describe '#size' do
|
44
|
+
subject { super().size }
|
45
|
+
it {should == 3}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#rows' do
|
50
|
+
subject { super().rows }
|
51
|
+
it {should == [["Vasya", 15], ["Petya", 12], ["Vova", 13]]}
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#header' do
|
55
|
+
subject { super().header }
|
56
|
+
it {should ==[ "Name", "Age"]}
|
57
|
+
end
|
44
58
|
|
45
|
-
|
59
|
+
describe '#data' do
|
60
|
+
subject { super().data }
|
61
|
+
it {should == [[ "Name", "Age"], ["Vasya", 15], ["Petya", 12], ["Vova", 13]]}
|
62
|
+
end
|
46
63
|
|
47
64
|
|
48
65
|
describe "when some filters specified" do
|
49
66
|
let(:_attributes) { {:age => [12,14]} }
|
50
|
-
|
51
|
-
|
52
|
-
|
67
|
+
|
68
|
+
describe '#assets' do
|
69
|
+
subject { super().assets }
|
70
|
+
it {should_not include(first)}
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#assets' do
|
74
|
+
subject { super().assets }
|
75
|
+
it {should include(second)}
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '#assets' do
|
79
|
+
subject { super().assets }
|
80
|
+
it {should include(third)}
|
81
|
+
end
|
53
82
|
end
|
54
83
|
|
55
84
|
describe "when reverse ordering is specified" do
|
56
85
|
let(:_attributes) { {:order => :name, :descending => true} }
|
57
|
-
|
86
|
+
|
87
|
+
describe '#assets' do
|
88
|
+
subject { super().assets }
|
89
|
+
it {should == [third, first, second]}
|
90
|
+
end
|
58
91
|
end
|
59
92
|
end
|
60
93
|
end
|
@@ -34,32 +34,64 @@ describe Datagrid::Drivers::MongoMapper, :mongomapper do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
|
37
|
-
|
37
|
+
describe '#assets' do
|
38
|
+
subject { super().assets }
|
39
|
+
it {should include(first, second)}
|
40
|
+
end
|
38
41
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
+
describe '#assets' do
|
43
|
+
subject { super().assets }
|
44
|
+
describe '#size' do
|
45
|
+
subject { super().size }
|
46
|
+
it {should == 2}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#rows' do
|
51
|
+
subject { super().rows }
|
52
|
+
it {should == [["Main First", 2, false], ["Main Second", 3, true]]}
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#header' do
|
56
|
+
subject { super().header }
|
57
|
+
it {should ==[ "Name", "Group", "Disabled"]}
|
58
|
+
end
|
42
59
|
|
43
|
-
|
60
|
+
describe '#data' do
|
61
|
+
subject { super().data }
|
62
|
+
it {should == [[ "Name", "Group", "Disabled"], ["Main First", 2, false], ["Main Second", 3, true]]}
|
63
|
+
end
|
44
64
|
|
45
65
|
|
46
66
|
describe "when some filters specified" do
|
47
67
|
let(:_attributes) { {:from_group_id => 3} }
|
48
|
-
|
49
|
-
|
68
|
+
|
69
|
+
describe '#assets' do
|
70
|
+
subject { super().assets }
|
71
|
+
it {should_not include(first)}
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#assets' do
|
75
|
+
subject { super().assets }
|
76
|
+
it {should include(second)}
|
77
|
+
end
|
50
78
|
end
|
51
79
|
|
52
80
|
describe "when reverse ordering is specified" do
|
53
81
|
let(:_attributes) { {:order => :name, :descending => true} }
|
54
|
-
|
82
|
+
|
83
|
+
describe '#rows' do
|
84
|
+
subject { super().rows }
|
85
|
+
it {should == [["Main Second", 3, true], ["Main First", 2, false]]}
|
86
|
+
end
|
55
87
|
end
|
56
88
|
it "should not provide default order for non declared fields" do
|
57
|
-
|
89
|
+
expect {
|
58
90
|
test_report(:order => :test) do
|
59
91
|
scope { MongoMapperEntry }
|
60
92
|
column(:test)
|
61
93
|
end
|
62
|
-
}.
|
94
|
+
}.to raise_error(Datagrid::OrderUnsupported)
|
63
95
|
end
|
64
96
|
end
|
65
97
|
end
|
@@ -33,33 +33,65 @@ describe Datagrid::Drivers::Mongoid, :mongoid do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
|
36
|
-
|
36
|
+
describe '#assets' do
|
37
|
+
subject { super().assets }
|
38
|
+
it {should include(first, second)}
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#assets' do
|
42
|
+
subject { super().assets }
|
43
|
+
describe '#size' do
|
44
|
+
subject { super().size }
|
45
|
+
it {should == 2}
|
46
|
+
end
|
47
|
+
end
|
37
48
|
|
38
|
-
|
39
|
-
|
40
|
-
|
49
|
+
describe '#rows' do
|
50
|
+
subject { super().rows }
|
51
|
+
it {should == [["Main First", 2, false], ["Main Second", 3, true]]}
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#header' do
|
55
|
+
subject { super().header }
|
56
|
+
it {should ==[ "Name", "Group", "Disabled"]}
|
57
|
+
end
|
41
58
|
|
42
|
-
|
59
|
+
describe '#data' do
|
60
|
+
subject { super().data }
|
61
|
+
it {should == [[ "Name", "Group", "Disabled"], ["Main First", 2, false], ["Main Second", 3, true]]}
|
62
|
+
end
|
43
63
|
|
44
64
|
|
45
65
|
describe "when some filters specified" do
|
46
66
|
let(:_attributes) { {:from_group_id => 3} }
|
47
|
-
|
48
|
-
|
67
|
+
|
68
|
+
describe '#assets' do
|
69
|
+
subject { super().assets }
|
70
|
+
it {should_not include(first)}
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#assets' do
|
74
|
+
subject { super().assets }
|
75
|
+
it {should include(second)}
|
76
|
+
end
|
49
77
|
end
|
50
78
|
|
51
79
|
describe "when reverse ordering is specified" do
|
52
80
|
let(:_attributes) { {:order => :name, :descending => true} }
|
53
|
-
|
81
|
+
|
82
|
+
describe '#rows' do
|
83
|
+
subject { super().rows }
|
84
|
+
it {should == [["Main Second", 3, true], ["Main First", 2, false]]}
|
85
|
+
end
|
54
86
|
end
|
55
87
|
|
56
88
|
it "should not provide default order for non declared fields" do
|
57
|
-
|
89
|
+
expect {
|
58
90
|
test_report(:order => :test) do
|
59
91
|
scope { MongoidEntry }
|
60
92
|
column(:test)
|
61
93
|
end
|
62
|
-
}.
|
94
|
+
}.to raise_error(Datagrid::OrderUnsupported)
|
63
95
|
end
|
64
96
|
|
65
97
|
it "should support batch_size" do
|
@@ -69,7 +101,7 @@ describe Datagrid::Drivers::Mongoid, :mongoid do
|
|
69
101
|
column(:name)
|
70
102
|
end
|
71
103
|
|
72
|
-
report.data.
|
104
|
+
expect(report.data).to eq([["Name"], ["Main First"], ["Main Second"]])
|
73
105
|
end
|
74
106
|
end
|
75
107
|
end
|
@@ -13,23 +13,23 @@ describe Datagrid::Filters::CompositeFilters do
|
|
13
13
|
date_range_filters(:shipping_date)
|
14
14
|
end.assets
|
15
15
|
|
16
|
-
assets.
|
17
|
-
assets.
|
16
|
+
expect(assets).to include(e2)
|
17
|
+
expect(assets).not_to include(e1, e3)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should support options" do
|
21
21
|
report = test_report do
|
22
22
|
report = date_range_filters(:shipping_date, {:default => 10.days.ago.to_date}, {:default => Date.today})
|
23
23
|
end
|
24
|
-
report.from_shipping_date.
|
25
|
-
report.to_shipping_date.
|
24
|
+
expect(report.from_shipping_date).to eq(10.days.ago.to_date)
|
25
|
+
expect(report.to_shipping_date).to eq(Date.today)
|
26
26
|
end
|
27
27
|
it "should support table name in field" do
|
28
28
|
report = test_report do
|
29
29
|
report = date_range_filters("entries.shipping_date", {:default => 10.days.ago.to_date}, {:default => Date.today})
|
30
30
|
end
|
31
|
-
report.from_entries_shipping_date.
|
32
|
-
report.to_entries_shipping_date.
|
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
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -44,22 +44,22 @@ describe Datagrid::Filters::CompositeFilters do
|
|
44
44
|
integer_range_filters(:group_id)
|
45
45
|
end.assets
|
46
46
|
|
47
|
-
assets.
|
48
|
-
assets.
|
47
|
+
expect(assets).to include(e2)
|
48
|
+
expect(assets).not_to include(e1, e3)
|
49
49
|
end
|
50
50
|
it "should support options" do
|
51
51
|
report = test_report do
|
52
52
|
report = integer_range_filters(:group_id, {:default => 0}, {:default => 100})
|
53
53
|
end
|
54
|
-
report.from_group_id.
|
55
|
-
report.to_group_id.
|
54
|
+
expect(report.from_group_id).to eq(0)
|
55
|
+
expect(report.to_group_id).to eq(100)
|
56
56
|
end
|
57
57
|
it "should table name in field name" do
|
58
58
|
report = test_report do
|
59
59
|
report = integer_range_filters("entries.group_id", {:default => 0}, {:default => 100})
|
60
60
|
end
|
61
|
-
report.from_entries_group_id.
|
62
|
-
report.to_entries_group_id.
|
61
|
+
expect(report.from_entries_group_id).to eq(0)
|
62
|
+
expect(report.to_entries_group_id).to eq(100)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
@@ -10,9 +10,9 @@ describe Datagrid::Filters::DateFilter do
|
|
10
10
|
scope { Entry }
|
11
11
|
filter(:created_at, :date)
|
12
12
|
end
|
13
|
-
report.assets.
|
14
|
-
report.assets.
|
15
|
-
report.assets.
|
13
|
+
expect(report.assets).not_to include(e1)
|
14
|
+
expect(report.assets).to include(e2)
|
15
|
+
expect(report.assets).not_to include(e3)
|
16
16
|
end
|
17
17
|
|
18
18
|
{:active_record => Entry, :mongoid => MongoidEntry}.each do |orm, klass|
|
@@ -60,9 +60,9 @@ describe Datagrid::Filters::DateFilter do
|
|
60
60
|
scope { Entry }
|
61
61
|
filter(:created_at, :date, :range => true)
|
62
62
|
end
|
63
|
-
report.assets.
|
64
|
-
report.assets.
|
65
|
-
report.assets.
|
63
|
+
expect(report.assets).not_to include(e1)
|
64
|
+
expect(report.assets).to include(e2)
|
65
|
+
expect(report.assets).not_to include(e3)
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should support minimum date argument" do
|
@@ -73,9 +73,9 @@ describe Datagrid::Filters::DateFilter do
|
|
73
73
|
scope { Entry }
|
74
74
|
filter(:created_at, :date, :range => true)
|
75
75
|
end
|
76
|
-
report.assets.
|
77
|
-
report.assets.
|
78
|
-
report.assets.
|
76
|
+
expect(report.assets).not_to include(e1)
|
77
|
+
expect(report.assets).to include(e2)
|
78
|
+
expect(report.assets).to include(e3)
|
79
79
|
end
|
80
80
|
|
81
81
|
it "should support maximum date argument" do
|
@@ -86,9 +86,9 @@ describe Datagrid::Filters::DateFilter do
|
|
86
86
|
scope { Entry }
|
87
87
|
filter(:created_at, :date, :range => true)
|
88
88
|
end
|
89
|
-
report.assets.
|
90
|
-
report.assets.
|
91
|
-
report.assets.
|
89
|
+
expect(report.assets).to include(e1)
|
90
|
+
expect(report.assets).to include(e2)
|
91
|
+
expect(report.assets).not_to include(e3)
|
92
92
|
end
|
93
93
|
|
94
94
|
it "should find something in one day interval" do
|
@@ -100,9 +100,9 @@ describe Datagrid::Filters::DateFilter do
|
|
100
100
|
scope { Entry }
|
101
101
|
filter(:created_at, :date, :range => true)
|
102
102
|
end
|
103
|
-
report.assets.
|
104
|
-
report.assets.
|
105
|
-
report.assets.
|
103
|
+
expect(report.assets).not_to include(e1)
|
104
|
+
expect(report.assets).to include(e2)
|
105
|
+
expect(report.assets).not_to include(e3)
|
106
106
|
end
|
107
107
|
it "should support invalid range" do
|
108
108
|
|
@@ -113,9 +113,9 @@ describe Datagrid::Filters::DateFilter do
|
|
113
113
|
scope { Entry }
|
114
114
|
filter(:created_at, :date, :range => true)
|
115
115
|
end
|
116
|
-
report.assets.
|
117
|
-
report.assets.
|
118
|
-
report.assets.
|
116
|
+
expect(report.assets).not_to include(e1)
|
117
|
+
expect(report.assets).not_to include(e2)
|
118
|
+
expect(report.assets).not_to include(e3)
|
119
119
|
end
|
120
120
|
|
121
121
|
|
@@ -126,8 +126,8 @@ describe Datagrid::Filters::DateFilter do
|
|
126
126
|
where("created_at >= ?", value)
|
127
127
|
end
|
128
128
|
end
|
129
|
-
report.assets.
|
130
|
-
report.assets.
|
129
|
+
expect(report.assets).not_to include(Entry.create!(:created_at => 1.day.ago))
|
130
|
+
expect(report.assets).to include(Entry.create!(:created_at => DateTime.now))
|
131
131
|
end
|
132
132
|
|
133
133
|
|
@@ -143,7 +143,7 @@ describe Datagrid::Filters::DateFilter do
|
|
143
143
|
scope {Entry}
|
144
144
|
filter(:created_at, :date)
|
145
145
|
end
|
146
|
-
report.created_at.
|
146
|
+
expect(report.created_at).to eq(Date.new(2013,10,01))
|
147
147
|
end
|
148
148
|
|
149
149
|
it "should support default explicit date" do
|
@@ -151,7 +151,7 @@ describe Datagrid::Filters::DateFilter do
|
|
151
151
|
scope {Entry}
|
152
152
|
filter(:created_at, :date)
|
153
153
|
end
|
154
|
-
report.created_at.
|
154
|
+
expect(report.created_at).to eq(Date.new(2013,10,01))
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
@@ -161,14 +161,14 @@ describe Datagrid::Filters::DateFilter do
|
|
161
161
|
scope {Entry}
|
162
162
|
filter(:created_at, :date, :range => true)
|
163
163
|
end
|
164
|
-
report.created_at.
|
164
|
+
expect(report.created_at).to eq([Date.new(2012, 01, 01), Date.new(2013, 01, 01)])
|
165
165
|
end
|
166
166
|
it "should automatically reverse Array if first more than last" do
|
167
167
|
report = test_report(:created_at => ["2013-01-01", "2012-01-01"]) do
|
168
168
|
scope {Entry}
|
169
169
|
filter(:created_at, :date, :range => true)
|
170
170
|
end
|
171
|
-
report.created_at.
|
171
|
+
expect(report.created_at).to eq([Date.new(2012, 01, 01), Date.new(2013, 01, 01)])
|
172
172
|
end
|
173
173
|
|
174
174
|
it "should properly format date in filter_value_as_string" do
|
@@ -177,7 +177,7 @@ describe Datagrid::Filters::DateFilter do
|
|
177
177
|
scope {Entry}
|
178
178
|
filter(:created_at, :date)
|
179
179
|
end
|
180
|
-
report.filter_value_as_string(:created_at).
|
180
|
+
expect(report.filter_value_as_string(:created_at)).to eq("01/02/2012")
|
181
181
|
end
|
182
182
|
end
|
183
183
|
|