datagrid 1.6.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/datagrid.gemspec +26 -164
  4. data/lib/datagrid/columns.rb +5 -10
  5. data/lib/datagrid/filters.rb +3 -6
  6. data/lib/datagrid/filters/base_filter.rb +8 -0
  7. data/lib/datagrid/form_builder.rb +14 -13
  8. data/lib/datagrid/version.rb +3 -0
  9. metadata +10 -196
  10. data/.document +0 -5
  11. data/.rspec +0 -1
  12. data/.travis.yml +0 -23
  13. data/Gemfile +0 -33
  14. data/Rakefile +0 -43
  15. data/VERSION +0 -1
  16. data/spec/datagrid/active_model_spec.rb +0 -33
  17. data/spec/datagrid/column_names_attribute_spec.rb +0 -86
  18. data/spec/datagrid/columns/column_spec.rb +0 -19
  19. data/spec/datagrid/columns_spec.rb +0 -592
  20. data/spec/datagrid/core_spec.rb +0 -210
  21. data/spec/datagrid/drivers/active_record_spec.rb +0 -79
  22. data/spec/datagrid/drivers/array_spec.rb +0 -106
  23. data/spec/datagrid/drivers/mongo_mapper_spec.rb +0 -101
  24. data/spec/datagrid/drivers/mongoid_spec.rb +0 -109
  25. data/spec/datagrid/drivers/sequel_spec.rb +0 -111
  26. data/spec/datagrid/filters/base_filter_spec.rb +0 -19
  27. data/spec/datagrid/filters/boolean_enum_filter_spec.rb +0 -5
  28. data/spec/datagrid/filters/composite_filters_spec.rb +0 -65
  29. data/spec/datagrid/filters/date_filter_spec.rb +0 -198
  30. data/spec/datagrid/filters/date_time_filter_spec.rb +0 -157
  31. data/spec/datagrid/filters/dynamic_filter_spec.rb +0 -175
  32. data/spec/datagrid/filters/enum_filter_spec.rb +0 -51
  33. data/spec/datagrid/filters/extended_boolean_filter_spec.rb +0 -46
  34. data/spec/datagrid/filters/float_filter_spec.rb +0 -15
  35. data/spec/datagrid/filters/integer_filter_spec.rb +0 -144
  36. data/spec/datagrid/filters/string_filter_spec.rb +0 -35
  37. data/spec/datagrid/filters_spec.rb +0 -332
  38. data/spec/datagrid/form_builder_spec.rb +0 -611
  39. data/spec/datagrid/helper_spec.rb +0 -683
  40. data/spec/datagrid/ordering_spec.rb +0 -150
  41. data/spec/datagrid/scaffold_spec.rb +0 -45
  42. data/spec/datagrid/stylesheet_spec.rb +0 -12
  43. data/spec/datagrid/utils_spec.rb +0 -19
  44. data/spec/datagrid_spec.rb +0 -94
  45. data/spec/spec_helper.rb +0 -123
  46. data/spec/support/active_record.rb +0 -38
  47. data/spec/support/configuration.rb +0 -28
  48. data/spec/support/i18n_helpers.rb +0 -6
  49. data/spec/support/matchers.rb +0 -101
  50. data/spec/support/mongo_mapper.rb +0 -32
  51. data/spec/support/mongoid.rb +0 -36
  52. data/spec/support/sequel.rb +0 -39
  53. data/spec/support/simple_report.rb +0 -64
  54. data/spec/support/test_partials/_actions.html.erb +0 -1
  55. data/spec/support/test_partials/client/datagrid/_form.html.erb +0 -13
  56. data/spec/support/test_partials/client/datagrid/_head.html.erb +0 -9
  57. data/spec/support/test_partials/client/datagrid/_order_for.html.erb +0 -11
  58. data/spec/support/test_partials/client/datagrid/_row.html.erb +0 -6
  59. data/spec/support/test_partials/client/datagrid/_table.html.erb +0 -19
  60. data/spec/support/test_partials/custom_checkboxes/_enum_checkboxes.html.erb +0 -1
  61. data/spec/support/test_partials/custom_form/_form.html.erb +0 -7
  62. 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,5 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Datagrid::Filters::BooleanEnumFilter do
4
-
5
- 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,198 +0,0 @@
1
- require 'spec_helper'
2
- require "active_support/testing/time_helpers"
3
-
4
- describe Datagrid::Filters::DateFilter do
5
-
6
- it "should support date range argument" do
7
- e1 = Entry.create!(:created_at => 7.days.ago)
8
- e2 = Entry.create!(:created_at => 4.days.ago)
9
- e3 = Entry.create!(:created_at => 1.day.ago)
10
- report = test_report(:created_at => 5.day.ago..3.days.ago) do
11
- scope { Entry }
12
- filter(:created_at, :date)
13
- end
14
- expect(report.assets).not_to include(e1)
15
- expect(report.assets).to include(e2)
16
- expect(report.assets).not_to include(e3)
17
- end
18
-
19
- {:active_record => Entry, :mongoid => MongoidEntry, :sequel => SequelEntry}.each do |orm, klass|
20
- describe "with orm #{orm}", orm => true do
21
- describe "date to timestamp conversion" do
22
- let(:klass) { klass }
23
- subject do
24
- test_report(:created_at => _created_at) do
25
- scope { klass }
26
- filter(:created_at, :date, :range => true)
27
- end.assets.to_a
28
- end
29
-
30
- def entry_dated(date)
31
- klass.create(:created_at => date)
32
- end
33
-
34
- context "when single date paramter given" do
35
- let(:_created_at) { Date.today }
36
- it { should include(entry_dated(1.second.ago))}
37
- it { should include(entry_dated(Date.today.end_of_day))}
38
- it { should_not include(entry_dated(Date.today.beginning_of_day - 1.second))}
39
- it { should_not include(entry_dated(Date.today.end_of_day + 1.second))}
40
- end
41
-
42
- context "when range date range given" do
43
- let(:_created_at) { [Date.yesterday, Date.today] }
44
- it { should include(entry_dated(1.second.ago))}
45
- it { should include(entry_dated(1.day.ago))}
46
- it { should include(entry_dated(Date.today.end_of_day))}
47
- it { should include(entry_dated(Date.yesterday.beginning_of_day))}
48
- it { should_not include(entry_dated(Date.yesterday.beginning_of_day - 1.second))}
49
- it { should_not include(entry_dated(Date.today.end_of_day + 1.second))}
50
- end
51
- end
52
-
53
- end
54
- end
55
-
56
- it "should support date range given as array argument" do
57
- e1 = Entry.create!(:created_at => 7.days.ago)
58
- e2 = Entry.create!(:created_at => 4.days.ago)
59
- e3 = Entry.create!(:created_at => 1.day.ago)
60
- report = test_report(:created_at => [5.day.ago.to_date.to_s, 3.days.ago.to_date.to_s]) do
61
- scope { Entry }
62
- filter(:created_at, :date, :range => true)
63
- end
64
- expect(report.assets).not_to include(e1)
65
- expect(report.assets).to include(e2)
66
- expect(report.assets).not_to include(e3)
67
- end
68
-
69
- it "should support minimum date argument" do
70
- e1 = Entry.create!(:created_at => 7.days.ago)
71
- e2 = Entry.create!(:created_at => 4.days.ago)
72
- e3 = Entry.create!(:created_at => 1.day.ago)
73
- report = test_report(:created_at => [5.day.ago.to_date.to_s, nil]) do
74
- scope { Entry }
75
- filter(:created_at, :date, :range => true)
76
- end
77
- expect(report.assets).not_to include(e1)
78
- expect(report.assets).to include(e2)
79
- expect(report.assets).to include(e3)
80
- end
81
-
82
- it "should support maximum date argument" do
83
- e1 = Entry.create!(:created_at => 7.days.ago)
84
- e2 = Entry.create!(:created_at => 4.days.ago)
85
- e3 = Entry.create!(:created_at => 1.day.ago)
86
- report = test_report(:created_at => [nil, 3.days.ago.to_date.to_s]) do
87
- scope { Entry }
88
- filter(:created_at, :date, :range => true)
89
- end
90
- expect(report.assets).to include(e1)
91
- expect(report.assets).to include(e2)
92
- expect(report.assets).not_to include(e3)
93
- end
94
-
95
- it "should find something in one day interval" do
96
-
97
- e1 = Entry.create!(:created_at => 7.days.ago)
98
- e2 = Entry.create!(:created_at => 4.days.ago)
99
- e3 = Entry.create!(:created_at => 1.day.ago)
100
- report = test_report(:created_at => (4.days.ago.to_date..4.days.ago.to_date)) do
101
- scope { Entry }
102
- filter(:created_at, :date, :range => true)
103
- end
104
- expect(report.assets).not_to include(e1)
105
- expect(report.assets).to include(e2)
106
- expect(report.assets).not_to include(e3)
107
- end
108
-
109
- it "should invert invalid range" do
110
- range = 1.days.ago..7.days.ago
111
- e1 = Entry.create!(:created_at => 7.days.ago)
112
- e2 = Entry.create!(:created_at => 4.days.ago)
113
- e3 = Entry.create!(:created_at => 1.day.ago)
114
- report = test_report(:created_at => range) do
115
- scope { Entry }
116
- filter(:created_at, :date, :range => true)
117
- end
118
- expect(report.created_at).to eq([range.last.to_date, range.first.to_date])
119
- expect(report.assets).to include(e1)
120
- expect(report.assets).to include(e2)
121
- expect(report.assets).to include(e3)
122
- end
123
-
124
-
125
- it "should support block" do
126
- date = Date.new(2018, 01, 07)
127
- time = Time.utc(2018, 01, 07, 2, 2)
128
- report = test_report(:created_at => date) do
129
- scope { Entry }
130
- filter(:created_at, :date, :range => true) do |value|
131
- where("created_at >= ?", value)
132
- end
133
- end
134
- expect(report.assets).not_to include(Entry.create!(:created_at => time - 1.day))
135
- expect(report.assets).to include(Entry.create!(:created_at => time))
136
- end
137
-
138
-
139
- context "when date format is configured" do
140
- around(:each) do |example|
141
- with_date_format do
142
- example.run
143
- end
144
- end
145
-
146
- it "should have configurable date format" do
147
- report = test_report(:created_at => "10/01/2013") do
148
- scope {Entry}
149
- filter(:created_at, :date)
150
- end
151
- expect(report.created_at).to eq(Date.new(2013,10,01))
152
- end
153
-
154
- it "should support default explicit date" do
155
- report = test_report(:created_at => Date.parse("2013-10-01")) do
156
- scope {Entry}
157
- filter(:created_at, :date)
158
- end
159
- expect(report.created_at).to eq(Date.new(2013,10,01))
160
- end
161
- end
162
-
163
-
164
- it "should automatically reverse Array if first more than last" do
165
- report = test_report(:created_at => ["2013-01-01", "2012-01-01"]) do
166
- scope {Entry}
167
- filter(:created_at, :date, :range => true)
168
- end
169
- expect(report.created_at).to eq([Date.new(2012, 01, 01), Date.new(2013, 01, 01)])
170
- end
171
- it "should automatically reverse Array if first more than last" do
172
- report = test_report(:created_at => ["2013-01-01", "2012-01-01"]) do
173
- scope {Entry}
174
- filter(:created_at, :date, :range => true)
175
- end
176
- expect(report.created_at).to eq([Date.new(2012, 01, 01), Date.new(2013, 01, 01)])
177
- end
178
-
179
- it "should nullify blank range" do
180
- report = test_report(:created_at => [nil, nil]) do
181
- scope {Entry}
182
- filter(:created_at, :date, :range => true)
183
- end
184
-
185
- expect(report.created_at).to eq(nil)
186
- end
187
-
188
- it "should properly format date in filter_value_as_string" do
189
- with_date_format do
190
- report = test_report(:created_at => "2012-01-02") do
191
- scope {Entry}
192
- filter(:created_at, :date)
193
- end
194
- expect(report.filter_value_as_string(:created_at)).to eq("01/02/2012")
195
- end
196
- end
197
-
198
- end