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,157 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Datagrid::Filters::DateTimeFilter do
4
- {:active_record => Entry, :mongoid => MongoidEntry}.each do |orm, klass|
5
- describe "with orm #{orm}", orm => true do
6
- describe "timestamp to timestamp conversion" do
7
- let(:klass) { klass }
8
-
9
- let(:grid) do
10
- test_report(:created_at => _created_at) do
11
- scope { klass }
12
- filter(:created_at, :datetime, :range => true)
13
- end
14
- end
15
-
16
- subject do
17
- grid.assets.to_a
18
- end
19
-
20
- def entry_dated(date)
21
- klass.create(:created_at => date)
22
- end
23
-
24
- context "when single datetime paramter given" do
25
- let(:_created_at) { Time.now.change(sec: 0) }
26
- it { should include(entry_dated(_created_at)) }
27
- it { should_not include(entry_dated(_created_at - 1.second))}
28
- it { should_not include(entry_dated(_created_at + 1.second))}
29
- end
30
-
31
- context "when range datetime range given" do
32
- let(:_created_at) { [Time.now.beginning_of_day, Time.now.end_of_day] }
33
- it { should include(entry_dated(1.second.ago))}
34
- it { should include(entry_dated(Date.today.to_time))}
35
- it { should include(entry_dated(Time.now.end_of_day.to_time))}
36
- it { should_not include(entry_dated(Date.yesterday.end_of_day))}
37
- it { should_not include(entry_dated(Date.tomorrow.beginning_of_day))}
38
- end
39
- end
40
-
41
- end
42
- end
43
-
44
- it "should support datetime range given as array argument" do
45
- e1 = Entry.create!(:created_at => Time.new(2013, 1, 1, 1, 0))
46
- e2 = Entry.create!(:created_at => Time.new(2013, 1, 1, 2, 0))
47
- e3 = Entry.create!(:created_at => Time.new(2013, 1, 1, 3, 0))
48
- report = test_report(:created_at => [Time.new(2013, 1, 1, 1, 30).to_s, Time.new(2013, 1, 1, 2, 30).to_s]) do
49
- scope { Entry }
50
- filter(:created_at, :datetime, :range => true)
51
- end
52
- expect(report.assets).not_to include(e1)
53
- expect(report.assets).to include(e2)
54
- expect(report.assets).not_to include(e3)
55
- end
56
-
57
- it "should support minimum datetime argument" do
58
- e1 = Entry.create!(:created_at => Time.new(2013, 1, 1, 1, 0))
59
- e2 = Entry.create!(:created_at => Time.new(2013, 1, 1, 2, 0))
60
- e3 = Entry.create!(:created_at => Time.new(2013, 1, 1, 3, 0))
61
- report = test_report(:created_at => [Time.new(2013, 1, 1, 1, 30).to_s, nil]) do
62
- scope { Entry }
63
- filter(:created_at, :datetime, :range => true)
64
- end
65
- expect(report.assets).not_to include(e1)
66
- expect(report.assets).to include(e2)
67
- expect(report.assets).to include(e3)
68
- end
69
-
70
- it "should support maximum datetime argument" do
71
- e1 = Entry.create!(:created_at => Time.new(2013, 1, 1, 1, 0))
72
- e2 = Entry.create!(:created_at => Time.new(2013, 1, 1, 2, 0))
73
- e3 = Entry.create!(:created_at => Time.new(2013, 1, 1, 3, 0))
74
- report = test_report(:created_at => [nil, Time.new(2013, 1, 1, 2, 30).to_s]) do
75
- scope { Entry }
76
- filter(:created_at, :datetime, :range => true)
77
- end
78
- expect(report.assets).to include(e1)
79
- expect(report.assets).to include(e2)
80
- expect(report.assets).not_to include(e3)
81
- end
82
-
83
- it "should find something in one second interval" do
84
-
85
- e1 = Entry.create!(:created_at => Time.new(2013, 1, 1, 1, 0))
86
- e2 = Entry.create!(:created_at => Time.new(2013, 1, 1, 2, 0))
87
- e3 = Entry.create!(:created_at => Time.new(2013, 1, 1, 3, 0))
88
- report = test_report(:created_at => Time.new(2013, 1, 1, 2, 0)..Time.new(2013, 1, 1, 2, 0)) do
89
- scope { Entry }
90
- filter(:created_at, :datetime, :range => true)
91
- end
92
- expect(report.assets).not_to include(e1)
93
- expect(report.assets).to include(e2)
94
- expect(report.assets).not_to include(e3)
95
- end
96
- it "should reverse invalid range" do
97
-
98
- range = Time.new(2013, 1, 1, 3, 0)..Time.new(2013, 1, 1, 1, 0)
99
- e1 = Entry.create!(:created_at => Time.new(2013, 1, 1, 1, 0))
100
- e2 = Entry.create!(:created_at => Time.new(2013, 1, 1, 2, 0))
101
- e3 = Entry.create!(:created_at => Time.new(2013, 1, 1, 3, 0))
102
- report = test_report(:created_at => range) do
103
- scope { Entry }
104
- filter(:created_at, :datetime, :range => true)
105
- end
106
- expect(report.created_at).to eq([range.last, range.first])
107
- expect(report.assets).to include(e1)
108
- expect(report.assets).to include(e2)
109
- expect(report.assets).to include(e3)
110
- end
111
-
112
-
113
- it "should support block" do
114
- report = test_report(:created_at => Time.now) do
115
- scope { Entry }
116
- filter(:created_at, :datetime, :range => true) do |value|
117
- where("created_at >= ?", value)
118
- end
119
- end
120
- expect(report.assets).not_to include(Entry.create!(:created_at => 1.day.ago))
121
- expect(report.assets).to include(Entry.create!(:created_at => Time.now+1.day))
122
- end
123
-
124
-
125
- context "when datetime format is configured" do
126
- around(:each) do |example|
127
- with_datetime_format("%m/%d/%Y %H:%M") do
128
- example.run
129
- end
130
- end
131
-
132
- it "should have configurable datetime format" do
133
- report = test_report(:created_at => "10/01/2013 01:00") do
134
- scope {Entry}
135
- filter(:created_at, :datetime)
136
- end
137
- expect(report.created_at).to eq(Time.new(2013,10,01,1,0))
138
- end
139
-
140
- it "should support default explicit datetime" do
141
- report = test_report(:created_at => Time.parse("2013-10-01 01:00")) do
142
- scope {Entry}
143
- filter(:created_at, :datetime)
144
- end
145
- expect(report.created_at).to eq(Time.new(2013,10,01,1,0))
146
- end
147
- end
148
-
149
-
150
- it "should automatically reverse Array if first more than last" do
151
- report = test_report(:created_at => ["2013-01-01 01:00", "2012-01-01 01:00"]) do
152
- scope {Entry}
153
- filter(:created_at, :datetime, :range => true)
154
- end
155
- expect(report.created_at).to eq([Time.new(2012, 01, 01, 1, 0), Time.new(2013, 01, 01, 1, 0)])
156
- end
157
- end
@@ -1,175 +0,0 @@
1
- require "spec_helper"
2
-
3
-
4
- describe Datagrid::Filters::DynamicFilter do
5
- let(:report) do
6
- test_report do
7
- scope {Entry}
8
- filter(:condition, :dynamic)
9
- end
10
- end
11
-
12
- it "should support = operation" do
13
- report.condition = [:name, "=", "hello"]
14
- expect(report.assets).to include(Entry.create!(:name => 'hello'))
15
- expect(report.assets).not_to include(Entry.create!(:name => 'bye'))
16
- end
17
-
18
- it "should support >= operation" do
19
- report.condition = [:name, ">=", "d"]
20
- expect(report.assets).to include(Entry.create!(:name => 'x'))
21
- expect(report.assets).to include(Entry.create!(:name => 'd'))
22
- expect(report.assets).not_to include(Entry.create!(:name => 'a'))
23
- end
24
-
25
- it "should blank value" do
26
- report.condition = [:name, "=", ""]
27
- expect(report.assets).to include(Entry.create!(:name => 'hello'))
28
- end
29
-
30
- it "should support =~ operation on strings" do
31
- report.condition = [:name, "=~", "ell"]
32
- expect(report.assets).to include(Entry.create!(:name => 'hello'))
33
- expect(report.assets).not_to include(Entry.create!(:name => 'bye'))
34
- end
35
-
36
- it "should support =~ operation integers" do
37
- report.condition = [:group_id, "=~", 2]
38
- expect(report.assets).to include(Entry.create!(:group_id => 2))
39
- expect(report.assets).not_to include(Entry.create!(:group_id => 1))
40
- expect(report.assets).not_to include(Entry.create!(:group_id => 3))
41
- end
42
-
43
- it "should support >= operation on integer" do
44
- report.condition = [:group_id, ">=", 2]
45
- expect(report.assets).to include(Entry.create!(:group_id => 3))
46
- expect(report.assets).not_to include(Entry.create!(:group_id => 1))
47
- end
48
-
49
- it "should support <= operation on integer" do
50
- report.condition = [:group_id, "<=", 2]
51
- expect(report.assets).to include(Entry.create!(:group_id => 1))
52
- expect(report.assets).not_to include(Entry.create!(:group_id => 3))
53
- end
54
-
55
- it "should support <= operation on integer with string value" do
56
- report.condition = [:group_id, "<=", '2']
57
- expect(report.assets).to include(Entry.create!(:group_id => 1))
58
- expect(report.assets).to include(Entry.create!(:group_id => 2))
59
- expect(report.assets).not_to include(Entry.create!(:group_id => 3))
60
- end
61
-
62
- it "should nullify incorrect value for integer" do
63
- report.condition = [:group_id, "<=", 'aa']
64
- expect(report.condition).to eq([:group_id, "<=", nil])
65
- end
66
-
67
- it "should nullify incorrect value for date" do
68
- report.condition = [:shipping_date, "<=", 'aa']
69
- expect(report.condition).to eq([:shipping_date, "<=", nil])
70
- end
71
-
72
- it "should nullify incorrect value for datetime" do
73
- report.condition = [:created_at, "<=", 'aa']
74
- expect(report.condition).to eq([:created_at, "<=", nil])
75
- end
76
-
77
- it "should support date comparation operation by timestamp column" do
78
- report.condition = [:created_at, "<=", '1986-08-05']
79
- expect(report.condition).to eq([:created_at, "<=", Date.parse('1986-08-05')])
80
- expect(report.assets).to include(Entry.create!(:created_at => Time.parse('1986-08-04 01:01:01')))
81
- expect(report.assets).to include(Entry.create!(:created_at => Time.parse('1986-08-05 23:59:59')))
82
- expect(report.assets).to include(Entry.create!(:created_at => Time.parse('1986-08-05 00:00:00')))
83
- expect(report.assets).not_to include(Entry.create!(:created_at => Time.parse('1986-08-06 00:00:00')))
84
- expect(report.assets).not_to include(Entry.create!(:created_at => Time.parse('1986-08-06 23:59:59')))
85
- end
86
-
87
- it "should support date = operation by timestamp column" do
88
- report.condition = [:created_at, "=", '1986-08-05']
89
- expect(report.condition).to eq([:created_at, "=", Date.parse('1986-08-05')])
90
- expect(report.assets).not_to include(Entry.create!(:created_at => Time.parse('1986-08-04 23:59:59')))
91
- expect(report.assets).to include(Entry.create!(:created_at => Time.parse('1986-08-05 23:59:59')))
92
- expect(report.assets).to include(Entry.create!(:created_at => Time.parse('1986-08-05 00:00:01')))
93
- #TODO: investigate SQLite issue and uncomment this line
94
- #report.assets.should include(Entry.create!(:created_at => Time.parse('1986-08-05 00:00:00')))
95
- expect(report.assets).not_to include(Entry.create!(:created_at => Time.parse('1986-08-06 23:59:59')))
96
- end
97
-
98
- it "should support date =~ operation by timestamp column" do
99
- report.condition = [:created_at, "=~", '1986-08-05']
100
- expect(report.condition).to eq([:created_at, "=~", Date.parse('1986-08-05')])
101
- expect(report.assets).not_to include(Entry.create!(:created_at => Time.parse('1986-08-04 23:59:59')))
102
- expect(report.assets).to include(Entry.create!(:created_at => Time.parse('1986-08-05 23:59:59')))
103
- expect(report.assets).to include(Entry.create!(:created_at => Time.parse('1986-08-05 00:00:01')))
104
- #TODO: investigate SQLite issue and uncomment this line
105
- #report.assets.should include(Entry.create!(:created_at => Time.parse('1986-08-05 00:00:00')))
106
- expect(report.assets).not_to include(Entry.create!(:created_at => Time.parse('1986-08-06 23:59:59')))
107
- end
108
-
109
- it "should support operations for invalid date" do
110
- report.condition = [:shipping_date, "<=", '1986-08-05']
111
- expect(report.assets).to include(Entry.create!(:shipping_date => '1986-08-04'))
112
- expect(report.assets).to include(Entry.create!(:shipping_date => '1986-08-05'))
113
- expect(report.assets).not_to include(Entry.create!(:shipping_date => '1986-08-06'))
114
- end
115
- it "should support operations for invalid date" do
116
- report.condition = [:shipping_date, "<=", Date.parse('1986-08-05')]
117
- expect(report.assets).to include(Entry.create!(:shipping_date => '1986-08-04'))
118
- expect(report.assets).to include(Entry.create!(:shipping_date => '1986-08-05'))
119
- expect(report.assets).not_to include(Entry.create!(:shipping_date => '1986-08-06'))
120
- end
121
-
122
- it "should support allow_nil and allow_blank options" do
123
- grid = test_report do
124
- scope {Entry}
125
- filter(:condition, :dynamic, :allow_nil => true, :allow_blank => true, operations: ['>=', '<=']) do |(field, operation, value), scope|
126
- if value.blank?
127
- scope.where(disabled: false)
128
- else
129
- scope.where("#{field} #{operation} ?", value)
130
- end
131
- end
132
- end
133
-
134
- expect(grid.assets).to_not include(Entry.create!(disabled: true))
135
- expect(grid.assets).to include(Entry.create!(disabled: false))
136
-
137
- grid.condition = [:group_id, '>=', 3]
138
- expect(grid.assets).to include(Entry.create!(disabled: true, group_id: 4))
139
- expect(grid.assets).to_not include(Entry.create!(disabled: false, group_id: 2))
140
- end
141
-
142
- it "should support custom operations" do
143
- entry = Entry.create!(name: 'hello')
144
-
145
- grid = test_report do
146
- scope {Entry}
147
- filter(
148
- :condition, :dynamic, operations: ["=", "!="]
149
- ) do |(field, operation, value), scope|
150
- if operation == "!="
151
- scope.where("#{field} != ?", value)
152
- else
153
- default_filter
154
- end
155
- end
156
- end
157
-
158
- grid.condition = ["name", "=", "hello"]
159
- expect(grid.assets).to include(entry)
160
- grid.condition = ["name", "!=", "hello"]
161
- expect(grid.assets).to_not include(entry)
162
- grid.condition = ["name", "=", "hello1"]
163
- expect(grid.assets).to_not include(entry)
164
- grid.condition = ["name", "!=", "hello1"]
165
- expect(grid.assets).to include(entry)
166
- end
167
-
168
- it "should raise if unknown operation" do
169
- report.condition = [:shipping_date, "<>", '1996-08-05']
170
- expect{
171
- report.assets
172
- }.to raise_error(Datagrid::FilteringError)
173
- end
174
-
175
- end
@@ -1,51 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Datagrid::Filters::EnumFilter do
4
-
5
- it "should support select option" do
6
- report = test_report do
7
- scope {Entry}
8
- filter(:group_id, :enum, :select => [1,2] )
9
- end
10
- expect(report.filter_by_name(:group_id).select(report)).to eq([1,2])
11
- end
12
-
13
- it "should support select option as proc" do
14
- grid = test_report do
15
- scope {Entry}
16
- filter(:group_id, :enum, :select => proc { [1,2] })
17
- end
18
- expect(grid.filter_by_name(:group_id).select(grid)).to eq([1,2])
19
- end
20
-
21
- it "should support select option as proc with instace input" do
22
- klass = test_report do
23
- scope {Entry}
24
- filter(:group_id, :enum, :select => proc { |obj| obj.object_id })
25
- end.class
26
- instance = klass.new
27
- expect(klass.filter_by_name(:group_id).select(instance)).to eq(instance.object_id)
28
- end
29
-
30
- it "should initialize select option only on instanciation" do
31
- class ReportWithLazySelect
32
- include Datagrid
33
- scope {Entry}
34
- filter(:group_id, :enum, :select => proc { raise 'hello' })
35
- end
36
- end
37
-
38
-
39
- it "should support select given as symbol" do
40
- report = test_report do
41
- scope {Entry}
42
- filter(:group_id, :enum, :select => :selectable_group_ids)
43
- def selectable_group_ids
44
- [1,3,5]
45
- end
46
- end
47
-
48
- expect(report.filter_by_name(:group_id).select(report)).to eq([1,3,5])
49
- end
50
-
51
- end
@@ -1,46 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Datagrid::Filters::ExtendedBooleanFilter do
4
-
5
- it "should support select option" do
6
- grid = test_report do
7
- scope {Entry}
8
- filter(:disabled, :xboolean)
9
- end
10
- expect(grid.filter_by_name(:disabled).select(grid)).to eq([["Yes", "YES"], ["No", "NO"]])
11
- end
12
-
13
- it "should generate pass boolean value to filter block" do
14
- grid = test_report do
15
- scope {Entry}
16
- filter(:disabled, :xboolean)
17
- end
18
-
19
- disabled_entry = Entry.create!(:disabled => true)
20
- enabled_entry = Entry.create!(:disabled => false)
21
-
22
- expect(grid.disabled).to be_nil
23
- expect(grid.assets).to include(disabled_entry, enabled_entry)
24
- grid.disabled = "YES"
25
-
26
- expect(grid.disabled).to eq("YES")
27
- expect(grid.assets).to include(disabled_entry)
28
- expect(grid.assets).not_to include(enabled_entry)
29
- grid.disabled = "NO"
30
- expect(grid.disabled).to eq("NO")
31
- expect(grid.assets).to include(enabled_entry)
32
- expect(grid.assets).not_to include(disabled_entry)
33
- end
34
-
35
- it "should normalize true/false as YES/NO" do
36
- grid = test_report do
37
- scope {Entry}
38
- filter(:disabled, :xboolean)
39
- end
40
- grid.disabled = true
41
- expect(grid.disabled).to eq("YES")
42
- grid.disabled = false
43
- expect(grid.disabled).to eq("NO")
44
- end
45
-
46
- end
@@ -1,15 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Datagrid::Filters::FloatFilter do
4
-
5
- it "should support float values" do
6
- g1 = Group.create!(:rating => 1.5)
7
- g2 = Group.create!(:rating => 1.6)
8
- report = test_report(:rating => 1.5) do
9
- scope { Group }
10
- filter(:rating, :float)
11
- end
12
- expect(report.assets).to include(g1)
13
- expect(report.assets).not_to include(g2)
14
- end
15
- end