datagrid 1.5.1 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +3 -3
- data/Gemfile +7 -4
- data/Rakefile +15 -13
- data/VERSION +1 -1
- data/app/views/datagrid/_enum_checkboxes.html.erb +1 -1
- data/datagrid.gemspec +47 -50
- data/lib/datagrid.rb +2 -2
- data/lib/datagrid/columns/column.rb +1 -5
- data/lib/datagrid/core.rb +6 -0
- data/lib/datagrid/drivers/abstract_driver.rb +1 -1
- data/lib/datagrid/drivers/active_record.rb +3 -11
- data/lib/datagrid/drivers/array.rb +4 -0
- data/lib/datagrid/drivers/mongoid.rb +1 -6
- data/lib/datagrid/drivers/sequel.rb +1 -5
- data/lib/datagrid/filters/base_filter.rb +1 -5
- data/lib/datagrid/filters/extended_boolean_filter.rb +10 -5
- data/lib/datagrid/filters/integer_filter.rb +4 -0
- data/lib/datagrid/filters/select_options.rb +4 -3
- data/lib/datagrid/form_builder.rb +5 -9
- data/lib/datagrid/utils.rb +4 -0
- data/spec/datagrid/core_spec.rb +26 -1
- data/spec/datagrid/drivers/active_record_spec.rb +2 -2
- data/spec/datagrid/drivers/mongo_mapper_spec.rb +77 -75
- data/spec/datagrid/filters/enum_filter_spec.rb +2 -2
- data/spec/datagrid/filters/integer_filter_spec.rb +19 -10
- data/spec/datagrid/form_builder_spec.rb +87 -81
- data/spec/datagrid/helper_spec.rb +4 -4
- data/spec/spec_helper.rb +22 -11
- data/spec/support/active_record.rb +2 -2
- data/spec/support/mongo_mapper.rb +23 -23
- metadata +9 -23
@@ -19,10 +19,6 @@ module Datagrid
|
|
19
19
|
label(filter.name, text, options, &block)
|
20
20
|
end
|
21
21
|
|
22
|
-
def datagrid_extra_checkbox_options
|
23
|
-
::ActionPack::VERSION::MAJOR >= 4 ? {:include_hidden => false} : {}
|
24
|
-
end
|
25
|
-
|
26
22
|
protected
|
27
23
|
def datagrid_boolean_enum_filter(attribute_or_filter, options = {})
|
28
24
|
datagrid_enum_filter(attribute_or_filter, options)
|
@@ -62,18 +58,18 @@ module Datagrid
|
|
62
58
|
@template.render(
|
63
59
|
:partial => partial,
|
64
60
|
:locals => {
|
65
|
-
:elements => elements,
|
66
|
-
:form => self,
|
61
|
+
:elements => elements,
|
62
|
+
:form => self,
|
67
63
|
:filter => filter,
|
68
64
|
:options => options,
|
69
|
-
}
|
65
|
+
}
|
70
66
|
)
|
71
67
|
else
|
72
68
|
if !options.has_key?(:multiple) && filter.multiple?
|
73
69
|
options[:multiple] = true
|
74
70
|
end
|
75
71
|
select(
|
76
|
-
filter.name,
|
72
|
+
filter.name,
|
77
73
|
object.select_options(filter) || [],
|
78
74
|
{:include_blank => filter.include_blank,
|
79
75
|
:prompt => filter.prompt,
|
@@ -219,7 +215,7 @@ module Datagrid
|
|
219
215
|
def partial_path(options, name)
|
220
216
|
if partials = options.delete(:partials)
|
221
217
|
partial_name = File.join(partials, name)
|
222
|
-
# Second argument is []: no magical namespaces to lookup added from controller
|
218
|
+
# Second argument is []: no magical namespaces to lookup added from controller
|
223
219
|
if @template.lookup_context.template_exists?(partial_name, [], true)
|
224
220
|
return partial_name
|
225
221
|
end
|
data/lib/datagrid/utils.rb
CHANGED
@@ -132,6 +132,10 @@ module Datagrid
|
|
132
132
|
!property_availability(grid, unless_option, false)
|
133
133
|
end
|
134
134
|
|
135
|
+
def callable(value)
|
136
|
+
value.respond_to?(:call) ? value.call : value
|
137
|
+
end
|
138
|
+
|
135
139
|
protected
|
136
140
|
def property_availability(grid, option, default)
|
137
141
|
case option
|
data/spec/datagrid/core_spec.rb
CHANGED
@@ -71,7 +71,7 @@ describe Datagrid::Core do
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
describe "
|
74
|
+
describe "#inspect" do
|
75
75
|
it "should show all attribute values" do
|
76
76
|
class InspectTest
|
77
77
|
include Datagrid
|
@@ -84,4 +84,29 @@ describe Datagrid::Core do
|
|
84
84
|
expect(grid.inspect).to eq('#<InspectTest order: :name, descending: true, created_at: [Wed, 01 Jan 2014, Tue, 05 Aug 2014]>')
|
85
85
|
end
|
86
86
|
end
|
87
|
+
|
88
|
+
describe "#==" do
|
89
|
+
class EqualTest
|
90
|
+
include Datagrid
|
91
|
+
scope {Entry}
|
92
|
+
filter(:created_at, :date)
|
93
|
+
column(:name)
|
94
|
+
column(:created_at)
|
95
|
+
end
|
96
|
+
it "work on empty objects" do
|
97
|
+
expect(EqualTest.new).to eq(EqualTest.new)
|
98
|
+
end
|
99
|
+
it "sees the difference on the filter value" do
|
100
|
+
expect(EqualTest.new(created_at: Date.yesterday)).to_not eq(EqualTest.new(created_at: Date.today))
|
101
|
+
end
|
102
|
+
it "sees the difference on order" do
|
103
|
+
expect(EqualTest.new(order: :created_at)).to_not eq(EqualTest.new(order: :name))
|
104
|
+
end
|
105
|
+
it "doesn't destinguish between String and Symbol order" do
|
106
|
+
expect(EqualTest.new(order: :created_at)).to eq(EqualTest.new(order: "created_at"))
|
107
|
+
end
|
108
|
+
it "checks for redefined scope" do
|
109
|
+
expect(EqualTest.new).to_not eq(EqualTest.new {|s| s.reorder(:name)})
|
110
|
+
end
|
111
|
+
end
|
87
112
|
end
|
@@ -25,12 +25,12 @@ describe Datagrid::Drivers::ActiveRecord do
|
|
25
25
|
subject do
|
26
26
|
test_report(:order => :test, :descending => true) do
|
27
27
|
scope { Entry }
|
28
|
-
column(:test, order:
|
28
|
+
column(:test, order: Entry.arel_table[:group_id].count)
|
29
29
|
end.assets
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should support ordering by Arel columns" do
|
33
|
-
expect(subject.to_sql.strip).to include
|
33
|
+
expect(subject.to_sql.strip).to include 'ORDER BY COUNT("entries"."group_id") DESC'
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -2,98 +2,100 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Datagrid::Drivers::MongoMapper, :mongomapper do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
subject { described_class }
|
5
|
+
if defined?(MongoMapper)
|
6
|
+
describe ".match?" do
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
subject { described_class }
|
9
|
+
|
10
|
+
it {should be_match(MongoMapperEntry)}
|
11
|
+
# MongoMapper doesn't have a scoped method, instead it has a query method which returns a Plucky::Query object
|
12
|
+
it {should be_match(MongoMapperEntry.query)}
|
13
|
+
it {should_not be_match(Entry.where(:id => 1))}
|
13
14
|
|
14
|
-
end
|
15
|
-
describe "api" do
|
16
|
-
|
17
|
-
subject do
|
18
|
-
MongoMapperGrid.new(
|
19
|
-
defined?(_attributes) ? _attributes : {}
|
20
|
-
)
|
21
|
-
end
|
22
|
-
|
23
|
-
let!(:first) do
|
24
|
-
MongoMapperEntry.create!(
|
25
|
-
:group_id => 2,
|
26
|
-
:name => "Main First",
|
27
|
-
:disabled => false
|
28
|
-
)
|
29
|
-
end
|
30
|
-
let!(:second) do
|
31
|
-
MongoMapperEntry.create!(
|
32
|
-
:group_id => 3,
|
33
|
-
:name => "Main Second",
|
34
|
-
:disabled => true
|
35
|
-
)
|
36
|
-
end
|
37
|
-
|
38
|
-
|
39
|
-
describe '#assets' do
|
40
|
-
subject { super().assets }
|
41
|
-
it {should include(first, second)}
|
42
15
|
end
|
43
|
-
|
44
|
-
|
45
|
-
subject
|
46
|
-
|
47
|
-
|
48
|
-
|
16
|
+
describe "api" do
|
17
|
+
|
18
|
+
subject do
|
19
|
+
MongoMapperGrid.new(
|
20
|
+
defined?(_attributes) ? _attributes : {}
|
21
|
+
)
|
49
22
|
end
|
50
|
-
end
|
51
23
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
24
|
+
let!(:first) do
|
25
|
+
MongoMapperEntry.create!(
|
26
|
+
:group_id => 2,
|
27
|
+
:name => "Main First",
|
28
|
+
:disabled => false
|
29
|
+
)
|
30
|
+
end
|
31
|
+
let!(:second) do
|
32
|
+
MongoMapperEntry.create!(
|
33
|
+
:group_id => 3,
|
34
|
+
:name => "Main Second",
|
35
|
+
:disabled => true
|
36
|
+
)
|
37
|
+
end
|
56
38
|
|
57
|
-
describe '#header' do
|
58
|
-
subject { super().header }
|
59
|
-
it {should ==[ "Name", "Group", "Disabled"]}
|
60
|
-
end
|
61
|
-
|
62
|
-
describe '#data' do
|
63
|
-
subject { super().data }
|
64
|
-
it {should == [[ "Name", "Group", "Disabled"], ["Main First", 2, false], ["Main Second", 3, true]]}
|
65
|
-
end
|
66
|
-
|
67
|
-
|
68
|
-
describe "when some filters specified" do
|
69
|
-
let(:_attributes) { {:from_group_id => 3} }
|
70
39
|
|
71
40
|
describe '#assets' do
|
72
41
|
subject { super().assets }
|
73
|
-
it {
|
42
|
+
it {should include(first, second)}
|
74
43
|
end
|
75
44
|
|
76
45
|
describe '#assets' do
|
77
46
|
subject { super().assets }
|
78
|
-
|
47
|
+
describe '#size' do
|
48
|
+
subject { super().size }
|
49
|
+
it {should == 2}
|
50
|
+
end
|
79
51
|
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe "when reverse ordering is specified" do
|
83
|
-
let(:_attributes) { {:order => :name, :descending => true} }
|
84
52
|
|
85
53
|
describe '#rows' do
|
86
54
|
subject { super().rows }
|
87
|
-
it {should == [["Main
|
55
|
+
it {should == [["Main First", 2, false], ["Main Second", 3, true]]}
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#header' do
|
59
|
+
subject { super().header }
|
60
|
+
it {should ==[ "Name", "Group", "Disabled"]}
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#data' do
|
64
|
+
subject { super().data }
|
65
|
+
it {should == [[ "Name", "Group", "Disabled"], ["Main First", 2, false], ["Main Second", 3, true]]}
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
describe "when some filters specified" do
|
70
|
+
let(:_attributes) { {:from_group_id => 3} }
|
71
|
+
|
72
|
+
describe '#assets' do
|
73
|
+
subject { super().assets }
|
74
|
+
it {should_not include(first)}
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#assets' do
|
78
|
+
subject { super().assets }
|
79
|
+
it {should include(second)}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "when reverse ordering is specified" do
|
84
|
+
let(:_attributes) { {:order => :name, :descending => true} }
|
85
|
+
|
86
|
+
describe '#rows' do
|
87
|
+
subject { super().rows }
|
88
|
+
it {should == [["Main Second", 3, true], ["Main First", 2, false]]}
|
89
|
+
end
|
90
|
+
end
|
91
|
+
it "should not provide default order for non declared fields" do
|
92
|
+
expect {
|
93
|
+
test_report(:order => :test) do
|
94
|
+
scope { MongoMapperEntry }
|
95
|
+
column(:test)
|
96
|
+
end.assets
|
97
|
+
}.to raise_error(Datagrid::OrderUnsupported)
|
98
|
+
end
|
88
99
|
end
|
89
|
-
end
|
90
|
-
it "should not provide default order for non declared fields" do
|
91
|
-
expect {
|
92
|
-
test_report(:order => :test) do
|
93
|
-
scope { MongoMapperEntry }
|
94
|
-
column(:test)
|
95
|
-
end.assets
|
96
|
-
}.to raise_error(Datagrid::OrderUnsupported)
|
97
100
|
end
|
98
101
|
end
|
99
|
-
end
|
@@ -26,7 +26,7 @@ describe Datagrid::Filters::EnumFilter do
|
|
26
26
|
instance = klass.new
|
27
27
|
expect(klass.filter_by_name(:group_id).select(instance)).to eq(instance.object_id)
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
it "should initialize select option only on instanciation" do
|
31
31
|
class ReportWithLazySelect
|
32
32
|
include Datagrid
|
@@ -37,7 +37,7 @@ describe Datagrid::Filters::EnumFilter do
|
|
37
37
|
|
38
38
|
|
39
39
|
it "should support select given as symbol" do
|
40
|
-
report = test_report do
|
40
|
+
report = test_report do
|
41
41
|
scope {Entry}
|
42
42
|
filter(:group_id, :enum, :select => :selectable_group_ids)
|
43
43
|
def selectable_group_ids
|
@@ -2,7 +2,6 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Datagrid::Filters::IntegerFilter do
|
4
4
|
|
5
|
-
|
6
5
|
let(:entry1) { Entry.create!(:group_id => 1) }
|
7
6
|
let(:entry2) { Entry.create!(:group_id => 2) }
|
8
7
|
let(:entry3) { Entry.create!(:group_id => 3) }
|
@@ -12,7 +11,7 @@ describe Datagrid::Filters::IntegerFilter do
|
|
12
11
|
|
13
12
|
it "should support integer range argument" do
|
14
13
|
report = test_report(:group_id => 3..5) do
|
15
|
-
scope { Entry }
|
14
|
+
scope { Entry }
|
16
15
|
filter(:group_id, :integer)
|
17
16
|
end
|
18
17
|
expect(report.assets).not_to include(entry1)
|
@@ -22,7 +21,7 @@ describe Datagrid::Filters::IntegerFilter do
|
|
22
21
|
|
23
22
|
it "should support integer range given as array argument" do
|
24
23
|
report = test_report(:group_id => [3.to_s, 5.to_s]) do
|
25
|
-
scope { Entry }
|
24
|
+
scope { Entry }
|
26
25
|
filter(:group_id, :integer, :range => true)
|
27
26
|
end
|
28
27
|
expect(report.assets).not_to include(entry7)
|
@@ -32,7 +31,7 @@ describe Datagrid::Filters::IntegerFilter do
|
|
32
31
|
|
33
32
|
it "should support minimum integer argument" do
|
34
33
|
report = test_report(:group_id => [5.to_s, nil]) do
|
35
|
-
scope { Entry }
|
34
|
+
scope { Entry }
|
36
35
|
filter(:group_id, :integer, :range => true)
|
37
36
|
end
|
38
37
|
expect(report.assets).not_to include(entry1)
|
@@ -42,7 +41,7 @@ describe Datagrid::Filters::IntegerFilter do
|
|
42
41
|
|
43
42
|
it "should support maximum integer argument" do
|
44
43
|
report = test_report(:group_id => [nil, 5.to_s]) do
|
45
|
-
scope { Entry }
|
44
|
+
scope { Entry }
|
46
45
|
filter(:group_id, :integer, :range => true)
|
47
46
|
end
|
48
47
|
expect(report.assets).to include(entry1)
|
@@ -53,7 +52,7 @@ describe Datagrid::Filters::IntegerFilter do
|
|
53
52
|
it "should find something in one integer interval" do
|
54
53
|
|
55
54
|
report = test_report(:group_id => (4..4)) do
|
56
|
-
scope { Entry }
|
55
|
+
scope { Entry }
|
57
56
|
filter(:group_id, :integer, :range => true)
|
58
57
|
end
|
59
58
|
expect(report.assets).not_to include(entry7)
|
@@ -63,7 +62,7 @@ describe Datagrid::Filters::IntegerFilter do
|
|
63
62
|
it "should support invalid range" do
|
64
63
|
|
65
64
|
report = test_report(:group_id => (7..1)) do
|
66
|
-
scope { Entry }
|
65
|
+
scope { Entry }
|
67
66
|
filter(:group_id, :integer, :range => true)
|
68
67
|
end
|
69
68
|
expect(report.assets).not_to include(entry7)
|
@@ -74,7 +73,7 @@ describe Datagrid::Filters::IntegerFilter do
|
|
74
73
|
|
75
74
|
it "should support block" do
|
76
75
|
report = test_report(:group_id => 5) do
|
77
|
-
scope { Entry }
|
76
|
+
scope { Entry }
|
78
77
|
filter(:group_id, :integer, :range => true) do |value|
|
79
78
|
where("group_id >= ?", value)
|
80
79
|
end
|
@@ -86,7 +85,7 @@ describe Datagrid::Filters::IntegerFilter do
|
|
86
85
|
|
87
86
|
it "should not prefix table name if column is joined" do
|
88
87
|
report = test_report(:rating => [4,nil]) do
|
89
|
-
scope { Entry.joins(:group) }
|
88
|
+
scope { Entry.joins(:group) }
|
90
89
|
filter(:rating, :integer, :range => true)
|
91
90
|
end
|
92
91
|
expect(report.rating).to eq([4,nil])
|
@@ -114,7 +113,7 @@ describe Datagrid::Filters::IntegerFilter do
|
|
114
113
|
expect(report.assets).to include(entry2)
|
115
114
|
expect(report.assets).not_to include(entry3)
|
116
115
|
end
|
117
|
-
|
116
|
+
|
118
117
|
it "should support multiple with allow_blank allow_nil options" do
|
119
118
|
report = test_report do
|
120
119
|
scope {Entry}
|
@@ -130,4 +129,14 @@ describe Datagrid::Filters::IntegerFilter do
|
|
130
129
|
expect(report.assets).to include(entry1)
|
131
130
|
expect(report.assets).to include(entry2)
|
132
131
|
end
|
132
|
+
|
133
|
+
it "normalizes AR object to ID" do
|
134
|
+
group = Group.create!
|
135
|
+
report = test_report(group_id: group) do
|
136
|
+
scope {Entry}
|
137
|
+
filter(:group_id, :integer)
|
138
|
+
end
|
139
|
+
|
140
|
+
expect(report.group_id).to eq(group.id)
|
141
|
+
end
|
133
142
|
end
|
@@ -18,7 +18,7 @@ describe Datagrid::FormBuilder do
|
|
18
18
|
v.view_paths << File.expand_path("../../support/test_partials", __FILE__)
|
19
19
|
end
|
20
20
|
end
|
21
|
-
let(:view) { ActionView::Helpers::FormBuilder.new(:report, _grid, template, {}
|
21
|
+
let(:view) { ActionView::Helpers::FormBuilder.new(:report, _grid, template, {})}
|
22
22
|
|
23
23
|
|
24
24
|
describe ".datagrid_filter" do
|
@@ -44,7 +44,7 @@ describe Datagrid::FormBuilder do
|
|
44
44
|
}
|
45
45
|
let(:_filter) { :name }
|
46
46
|
it { should equal_to_dom(
|
47
|
-
'<input class="name default_filter"
|
47
|
+
'<input class="name default_filter" type="text" name="report[name]" id="report_name"/>'
|
48
48
|
)}
|
49
49
|
end
|
50
50
|
context "with integer filter type" do
|
@@ -56,13 +56,13 @@ describe Datagrid::FormBuilder do
|
|
56
56
|
end
|
57
57
|
}
|
58
58
|
it { should equal_to_dom(
|
59
|
-
'<input class="group_id integer_filter"
|
59
|
+
'<input class="group_id integer_filter" type="text" name="report[group_id]" id="report_group_id"/>'
|
60
60
|
)}
|
61
61
|
|
62
62
|
context "when partials option is passed for filter that don't support range" do
|
63
63
|
let(:_filter_options) { {partials: 'anything' } }
|
64
64
|
it { should equal_to_dom(
|
65
|
-
'<input class="group_id integer_filter"
|
65
|
+
'<input class="group_id integer_filter" type="text" name="report[group_id]" id="report_group_id"/>'
|
66
66
|
)}
|
67
67
|
end
|
68
68
|
end
|
@@ -76,7 +76,7 @@ describe Datagrid::FormBuilder do
|
|
76
76
|
end
|
77
77
|
}
|
78
78
|
it { should equal_to_dom(
|
79
|
-
'<input class="created_at date_filter"
|
79
|
+
'<input class="created_at date_filter" type="text" name="report[created_at]" id="report_created_at"/>'
|
80
80
|
)}
|
81
81
|
context "when special date format specified" do
|
82
82
|
around(:each) do |example|
|
@@ -86,7 +86,7 @@ describe Datagrid::FormBuilder do
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
it { should equal_to_dom(
|
89
|
-
'<input class="created_at date_filter"
|
89
|
+
'<input value="01/02/2012" class="created_at date_filter" type="text" name="report[created_at]" id="report_created_at"/>'
|
90
90
|
)}
|
91
91
|
end
|
92
92
|
end
|
@@ -103,27 +103,27 @@ describe Datagrid::FormBuilder do
|
|
103
103
|
let(:_filter_options) { {:id => "hello"} }
|
104
104
|
let(:_range) { [1,2]}
|
105
105
|
it { should equal_to_dom(
|
106
|
-
'<input class="group_id integer_filter from"
|
106
|
+
'<input id="from_hello" class="group_id integer_filter from" multiple value="1" type="text" name="report[group_id][]"/>' +
|
107
107
|
'<span class="separator integer"> - </span>' +
|
108
|
-
'<input class="group_id integer_filter to"
|
108
|
+
'<input id="to_hello" class="group_id integer_filter to" multiple value="2" type="text" name="report[group_id][]"/>'
|
109
109
|
)}
|
110
110
|
end
|
111
111
|
context "with only left bound" do
|
112
112
|
|
113
113
|
let(:_range) { [10, nil]}
|
114
114
|
it { should equal_to_dom(
|
115
|
-
'<input class="group_id integer_filter from" multiple
|
115
|
+
'<input class="group_id integer_filter from" multiple value="10" type="text" name="report[group_id][]"/>' +
|
116
116
|
'<span class="separator integer"> - </span>' +
|
117
|
-
'<input class="group_id integer_filter to" multiple name="report[group_id][]"
|
117
|
+
'<input class="group_id integer_filter to" multiple type="text" name="report[group_id][]"/>'
|
118
118
|
)}
|
119
119
|
it { should be_html_safe }
|
120
120
|
end
|
121
121
|
context "with only right bound" do
|
122
122
|
let(:_range) { [nil, 10]}
|
123
123
|
it { should equal_to_dom(
|
124
|
-
'<input class="group_id integer_filter from" multiple name="report[group_id][]"
|
124
|
+
'<input class="group_id integer_filter from" multiple type="text" name="report[group_id][]"/>' +
|
125
125
|
'<span class="separator integer"> - </span>' +
|
126
|
-
'<input class="group_id integer_filter to" multiple
|
126
|
+
'<input class="group_id integer_filter to" multiple value="10" type="text" name="report[group_id][]"/>'
|
127
127
|
)}
|
128
128
|
it { should be_html_safe }
|
129
129
|
end
|
@@ -131,9 +131,9 @@ describe Datagrid::FormBuilder do
|
|
131
131
|
context "with invalid range value" do
|
132
132
|
let(:_range) { 2..1 }
|
133
133
|
it { should equal_to_dom(
|
134
|
-
'<input class="group_id integer_filter from" multiple
|
134
|
+
'<input class="group_id integer_filter from" multiple value="2" type="text" name="report[group_id][]"/>' +
|
135
135
|
'<span class="separator integer"> - </span>' +
|
136
|
-
'<input class="group_id integer_filter to" multiple
|
136
|
+
'<input class="group_id integer_filter to" multiple value="1" type="text" name="report[group_id][]"/>'
|
137
137
|
)}
|
138
138
|
end
|
139
139
|
|
@@ -149,7 +149,7 @@ describe Datagrid::FormBuilder do
|
|
149
149
|
let(:_filter_options) { { :partials => 'not_existed' } }
|
150
150
|
let(:_range) { nil }
|
151
151
|
it { should equal_to_dom(
|
152
|
-
'<input class="group_id integer_filter from" multiple name="report[group_id][]"
|
152
|
+
'<input class="group_id integer_filter from" multiple type="text" name="report[group_id][]"><span class="separator integer"> - </span><input class="group_id integer_filter to" multiple type="text" name="report[group_id][]">'
|
153
153
|
) }
|
154
154
|
|
155
155
|
end
|
@@ -164,7 +164,7 @@ describe Datagrid::FormBuilder do
|
|
164
164
|
end
|
165
165
|
end
|
166
166
|
it { should equal_to_dom(
|
167
|
-
'from <input class="group_id integer_filter from" multiple name="report[group_id][]"
|
167
|
+
'from <input class="group_id integer_filter from" multiple type="text" name="report[group_id][]"> to <input class="group_id integer_filter to" multiple type="text" name="report[group_id][]">'
|
168
168
|
)}
|
169
169
|
end
|
170
170
|
context "when deprecated separator is specified" do
|
@@ -177,7 +177,7 @@ describe Datagrid::FormBuilder do
|
|
177
177
|
end
|
178
178
|
end
|
179
179
|
it { should equal_to_dom(
|
180
|
-
'<input class="group_id integer_filter from" multiple name="report[group_id][]"
|
180
|
+
'<input class="group_id integer_filter from" multiple type="text" name="report[group_id][]"> | <input class="group_id integer_filter to" multiple type="text" name="report[group_id][]">'
|
181
181
|
)}
|
182
182
|
end
|
183
183
|
end
|
@@ -191,9 +191,9 @@ describe Datagrid::FormBuilder do
|
|
191
191
|
}
|
192
192
|
let(:_range) { [1.5,2.5]}
|
193
193
|
it { should equal_to_dom(
|
194
|
-
'<input class="rating float_filter from" multiple
|
194
|
+
'<input class="rating float_filter from" multiple value="1.5" type="text" name="report[rating][]"/>' +
|
195
195
|
'<span class="separator float"> - </span>' +
|
196
|
-
'<input class="rating float_filter to" multiple
|
196
|
+
'<input class="rating float_filter to" multiple value="2.5" type="text" name="report[rating][]"/>'
|
197
197
|
)}
|
198
198
|
end
|
199
199
|
|
@@ -210,9 +210,9 @@ describe Datagrid::FormBuilder do
|
|
210
210
|
|
211
211
|
let(:_range) { ["2012-01-03", nil]}
|
212
212
|
it { should equal_to_dom(
|
213
|
-
'<input class="created_at date_filter from" multiple
|
213
|
+
'<input class="created_at date_filter from" multiple value="2012-01-03" type="text" name="report[created_at][]"/>' +
|
214
214
|
'<span class="separator date"> - </span>' +
|
215
|
-
'<input class="created_at date_filter to" multiple name="report[created_at][]"
|
215
|
+
'<input class="created_at date_filter to" multiple type="text" name="report[created_at][]"/>'
|
216
216
|
)}
|
217
217
|
it { should be_html_safe }
|
218
218
|
end
|
@@ -224,18 +224,18 @@ describe Datagrid::FormBuilder do
|
|
224
224
|
end
|
225
225
|
let(:_range) { ["2013/01/01", '2013/02/02']}
|
226
226
|
it { should equal_to_dom(
|
227
|
-
'<input class="created_at date_filter from" multiple
|
227
|
+
'<input class="created_at date_filter from" multiple value="01/01/2013" type="text" name="report[created_at][]"/>' +
|
228
228
|
'<span class="separator date"> - </span>' +
|
229
|
-
'<input class="created_at date_filter to" multiple
|
229
|
+
'<input class="created_at date_filter to" multiple value="02/02/2013" type="text" name="report[created_at][]"/>'
|
230
230
|
)}
|
231
231
|
end
|
232
232
|
context "with only right bound" do
|
233
233
|
|
234
234
|
let(:_range) { [nil, "2012-01-03"]}
|
235
235
|
it { should equal_to_dom(
|
236
|
-
'<input class="created_at date_filter from" multiple name="report[created_at][]"
|
236
|
+
'<input class="created_at date_filter from" multiple type="text" name="report[created_at][]"/>' +
|
237
237
|
'<span class="separator date"> - </span>' +
|
238
|
-
'<input class="created_at date_filter to" multiple
|
238
|
+
'<input class="created_at date_filter to" multiple value="2012-01-03" type="text" name="report[created_at][]"/>'
|
239
239
|
)}
|
240
240
|
it { should be_html_safe }
|
241
241
|
end
|
@@ -243,9 +243,9 @@ describe Datagrid::FormBuilder do
|
|
243
243
|
context "with invalid range value" do
|
244
244
|
let(:_range) { Date.parse('2012-01-02')..Date.parse('2012-01-01') }
|
245
245
|
it { should equal_to_dom(
|
246
|
-
'<input class="created_at date_filter from" multiple
|
246
|
+
'<input class="created_at date_filter from" multiple value="2012-01-02" type="text" name="report[created_at][]"/>' +
|
247
247
|
'<span class="separator date"> - </span>' +
|
248
|
-
'<input class="created_at date_filter to" multiple
|
248
|
+
'<input class="created_at date_filter to" multiple value="2012-01-01" type="text" name="report[created_at][]"/>'
|
249
249
|
)}
|
250
250
|
end
|
251
251
|
context "with blank range value" do
|
@@ -256,9 +256,9 @@ describe Datagrid::FormBuilder do
|
|
256
256
|
end
|
257
257
|
let(:_range) { [nil, nil] }
|
258
258
|
it { should equal_to_dom(
|
259
|
-
'<input class="created_at date_filter from" multiple name="report[created_at][]"
|
259
|
+
'<input class="created_at date_filter from" multiple type="text" name="report[created_at][]"/>' +
|
260
260
|
'<span class="separator date"> - </span>' +
|
261
|
-
'<input class="created_at date_filter to" multiple name="report[created_at][]"
|
261
|
+
'<input class="created_at date_filter to" multiple type="text" name="report[created_at][]"/>'
|
262
262
|
)}
|
263
263
|
end
|
264
264
|
end
|
@@ -273,7 +273,7 @@ describe Datagrid::FormBuilder do
|
|
273
273
|
end
|
274
274
|
}
|
275
275
|
it { should equal_to_dom(
|
276
|
-
'<select class="category enum_filter"
|
276
|
+
'<select class="category enum_filter" name="report[category]" id="report_category"><option value=""></option>
|
277
277
|
<option value="first">first</option>
|
278
278
|
<option value="second">second</option></select>'
|
279
279
|
)}
|
@@ -282,9 +282,14 @@ describe Datagrid::FormBuilder do
|
|
282
282
|
before(:each) do
|
283
283
|
skip("not supported by rails < 4.1") if Rails.version < '4.1'
|
284
284
|
end
|
285
|
-
let(:_filter_block )
|
285
|
+
let(:_filter_block ) do
|
286
|
+
proc do
|
287
|
+
template.content_tag(:option, 'block option', :value => 'block_value')
|
288
|
+
end
|
289
|
+
end
|
286
290
|
it { should equal_to_dom(
|
287
|
-
'<select class="category enum_filter"
|
291
|
+
'<select class="category enum_filter" name="report[category]" id="report_category"><option value=""></option>
|
292
|
+
<option value="block_value">block option</option></select>'
|
288
293
|
)}
|
289
294
|
end
|
290
295
|
context "when first option is selected" do
|
@@ -292,23 +297,39 @@ describe Datagrid::FormBuilder do
|
|
292
297
|
_grid.category = "first"
|
293
298
|
end
|
294
299
|
it { should equal_to_dom(
|
295
|
-
'<select class="category enum_filter"
|
296
|
-
<option value="first"
|
300
|
+
'<select class="category enum_filter" name="report[category]" id="report_category"><option value=""></option>
|
301
|
+
<option selected value="first">first</option>
|
297
302
|
<option value="second">second</option></select>'
|
298
303
|
)}
|
299
304
|
end
|
300
305
|
context "with include_blank option set to false" do
|
301
306
|
let(:_filter) { :category_without_include_blank }
|
302
307
|
it { should equal_to_dom(
|
303
|
-
'<select class="category_without_include_blank enum_filter"
|
308
|
+
'<select class="category_without_include_blank enum_filter" name="report[category_without_include_blank]" id="report_category_without_include_blank">
|
304
309
|
<option value="first">first</option>
|
305
310
|
<option value="second">second</option></select>'
|
306
311
|
)}
|
307
312
|
end
|
313
|
+
context "with dynamic include_blank option" do
|
314
|
+
let(:_grid) do
|
315
|
+
test_report do
|
316
|
+
scope {Entry}
|
317
|
+
filter(:category, :enum, :select => ["first", "second"], :include_blank => proc { "Choose plz" })
|
318
|
+
end
|
319
|
+
end
|
320
|
+
let(:_filter) { :category }
|
321
|
+
it { should equal_to_dom(
|
322
|
+
'<select class="category enum_filter" name="report[category]" id="report_category">
|
323
|
+
<option value="">Choose plz</option>
|
324
|
+
<option value="first">first</option>
|
325
|
+
<option value="second">second</option></select>'
|
326
|
+
)}
|
327
|
+
end
|
328
|
+
|
308
329
|
context "with prompt option" do
|
309
330
|
let(:_filter) { :category_with_prompt }
|
310
331
|
it { should equal_to_dom(
|
311
|
-
'<select class="category_with_prompt enum_filter"
|
332
|
+
'<select class="category_with_prompt enum_filter" name="report[category_with_prompt]" id="report_category_with_prompt"><option value="">My Prompt</option>
|
312
333
|
<option value="first">first</option>
|
313
334
|
<option value="second">second</option></select>'
|
314
335
|
)}
|
@@ -324,8 +345,8 @@ describe Datagrid::FormBuilder do
|
|
324
345
|
if Rails.version >= "4.1"
|
325
346
|
it { should equal_to_dom(
|
326
347
|
'
|
327
|
-
<label class="category enum_filter checkboxes" for="report_category_first"><input id="report_category_first"
|
328
|
-
<label class="category enum_filter checkboxes" for="report_category_second"><input id="report_category_second"
|
348
|
+
<label class="category enum_filter checkboxes" for="report_category_first"><input id="report_category_first" type="checkbox" value="first" name="report[category][]" />first</label>
|
349
|
+
<label class="category enum_filter checkboxes" for="report_category_second"><input id="report_category_second" type="checkbox" value="second" name="report[category][]" />second</label>
|
329
350
|
'
|
330
351
|
)}
|
331
352
|
else
|
@@ -356,7 +377,7 @@ describe Datagrid::FormBuilder do
|
|
356
377
|
end
|
357
378
|
it { should equal_to_dom(
|
358
379
|
# hidden is important when default is set to true
|
359
|
-
'<input name="report[disabled]" type="hidden" value="0"><input
|
380
|
+
'<input name="report[disabled]" type="hidden" value="0"><input class="disabled boolean_filter" type="checkbox" value="1" checked name="report[disabled]" id="report_disabled">'
|
360
381
|
)}
|
361
382
|
end
|
362
383
|
context "with xboolean filter type" do
|
@@ -368,7 +389,7 @@ describe Datagrid::FormBuilder do
|
|
368
389
|
end
|
369
390
|
end
|
370
391
|
it { should equal_to_dom(
|
371
|
-
'<select class="disabled extended_boolean_filter"
|
392
|
+
'<select class="disabled extended_boolean_filter" name="report[disabled]" id="report_disabled"><option value=""></option>
|
372
393
|
<option value="YES">Yes</option>
|
373
394
|
<option value="NO">No</option></select>'
|
374
395
|
)}
|
@@ -383,7 +404,7 @@ describe Datagrid::FormBuilder do
|
|
383
404
|
|
384
405
|
let(:_filter) { :name }
|
385
406
|
|
386
|
-
it {should equal_to_dom('<input class="name string_filter"
|
407
|
+
it {should equal_to_dom('<input class="name string_filter" type="text" name="report[name]" id="report_name">')}
|
387
408
|
|
388
409
|
context "when multiple option is set" do
|
389
410
|
let(:_grid) do
|
@@ -395,7 +416,7 @@ describe Datagrid::FormBuilder do
|
|
395
416
|
|
396
417
|
let(:_filter) { :name }
|
397
418
|
|
398
|
-
it {should equal_to_dom('<input class="name string_filter"
|
419
|
+
it {should equal_to_dom('<input value="one,two" class="name string_filter" type="text" name="report[name]" id="report_name">')}
|
399
420
|
end
|
400
421
|
end
|
401
422
|
|
@@ -412,7 +433,7 @@ describe Datagrid::FormBuilder do
|
|
412
433
|
end
|
413
434
|
end
|
414
435
|
let(:_filter) { :name }
|
415
|
-
it {should equal_to_dom('<select class="name enum_filter"
|
436
|
+
it {should equal_to_dom('<select class="name enum_filter" name="report[name]" id="report_name"></select>')}
|
416
437
|
end
|
417
438
|
context "with float filter type" do
|
418
439
|
let(:_grid) {
|
@@ -423,7 +444,7 @@ describe Datagrid::FormBuilder do
|
|
423
444
|
}
|
424
445
|
let(:_filter) { :group_id }
|
425
446
|
it { should equal_to_dom(
|
426
|
-
'<input class="group_id float_filter"
|
447
|
+
'<input class="group_id float_filter" type="text" name="report[group_id]" id="report_group_id"/>'
|
427
448
|
)}
|
428
449
|
|
429
450
|
end
|
@@ -437,17 +458,10 @@ describe Datagrid::FormBuilder do
|
|
437
458
|
end
|
438
459
|
let(:_filter) { :group_id }
|
439
460
|
let(:expected_html) do
|
440
|
-
|
441
|
-
|
442
|
-
<select class="group_id enum_filter" id="report_group_id" multiple name="report[group_id][]">
|
443
|
-
<option value="hello">hello</option></select>
|
444
|
-
HTML
|
445
|
-
else
|
446
|
-
<<-HTML
|
447
|
-
<input name="report[group_id][]" type="hidden" value=""><select class="group_id enum_filter" id="report_group_id" multiple name="report[group_id][]">
|
461
|
+
<<-HTML
|
462
|
+
<select class="group_id enum_filter" multiple name="report[group_id][]" id="report_group_id">
|
448
463
|
<option value="hello">hello</option></select>
|
449
|
-
|
450
|
-
end
|
464
|
+
HTML
|
451
465
|
end
|
452
466
|
|
453
467
|
it { should equal_to_dom(expected_html) }
|
@@ -467,19 +481,11 @@ describe Datagrid::FormBuilder do
|
|
467
481
|
end
|
468
482
|
let(:_filter) { :column_names }
|
469
483
|
let(:expected_html) do
|
470
|
-
|
471
|
-
|
472
|
-
<
|
473
|
-
<option value="name" selected>Name</option>
|
484
|
+
<<-HTML
|
485
|
+
<select class="column_names enum_filter" multiple name="report[column_names][]" id="report_column_names"><option selected value="id">Id</option>
|
486
|
+
<option selected value="name">Name</option>
|
474
487
|
<option value="category">Category</option></select>
|
475
|
-
|
476
|
-
else
|
477
|
-
<<-HTML
|
478
|
-
<input name="report[column_names][]" type="hidden" value=""><select class="column_names enum_filter" id="report_column_names" multiple name="report[column_names][]"><option value="id" selected>Id</option>
|
479
|
-
<option value="name" selected>Name</option>
|
480
|
-
<option value="category">Category</option></select>
|
481
|
-
HTML
|
482
|
-
end
|
488
|
+
HTML
|
483
489
|
end
|
484
490
|
|
485
491
|
it { should equal_to_dom(expected_html) }
|
@@ -499,9 +505,9 @@ describe Datagrid::FormBuilder do
|
|
499
505
|
let(:_filter) { :column_names }
|
500
506
|
let(:expected_html) do
|
501
507
|
<<DOM
|
502
|
-
<label class="column_names enum_filter checkboxes" for="report_column_names_id"><input
|
503
|
-
<label class="column_names enum_filter checkboxes" for="report_column_names_name"><input
|
504
|
-
<label class="column_names enum_filter checkboxes" for="report_column_names_category"><input id="report_column_names_category"
|
508
|
+
<label class="column_names enum_filter checkboxes" for="report_column_names_id"><input id="report_column_names_id" type="checkbox" value="id" checked name="report[column_names][]">Id</label>
|
509
|
+
<label class="column_names enum_filter checkboxes" for="report_column_names_name"><input id="report_column_names_name" type="checkbox" value="name" checked name="report[column_names][]">Name</label>
|
510
|
+
<label class="column_names enum_filter checkboxes" for="report_column_names_category"><input id="report_column_names_category" type="checkbox" value="category" name="report[column_names][]">Category</label>
|
505
511
|
DOM
|
506
512
|
end
|
507
513
|
|
@@ -526,7 +532,7 @@ DOM
|
|
526
532
|
context "with no options" do
|
527
533
|
let(:expected_html) do
|
528
534
|
<<-HTML
|
529
|
-
<select class="condition dynamic_filter field"
|
535
|
+
<select class="condition dynamic_filter field" name="report[condition][]" id="report_condition"><option value="id">Id</option>
|
530
536
|
<option value="group_id">Group</option>
|
531
537
|
<option value="name">Name</option>
|
532
538
|
<option value="category">Category</option>
|
@@ -536,10 +542,10 @@ DOM
|
|
536
542
|
<option value="confirmed">Confirmed</option>
|
537
543
|
<option value="shipping_date">Shipping date</option>
|
538
544
|
<option value="created_at">Created at</option>
|
539
|
-
<option value="updated_at">Updated at</option></select><select class="condition dynamic_filter operation"
|
545
|
+
<option value="updated_at">Updated at</option></select><select class="condition dynamic_filter operation" name="report[condition][]" id="report_condition"><option value="=">=</option>
|
540
546
|
<option value="=~">≈</option>
|
541
547
|
<option value=">=">≥</option>
|
542
|
-
<option value="<=">≤</option></select><input class="condition dynamic_filter value"
|
548
|
+
<option value="<=">≤</option></select><input class="condition dynamic_filter value" name="report[condition][]" type="text" id="report_condition">
|
543
549
|
HTML
|
544
550
|
end
|
545
551
|
it {should equal_to_dom(expected_html)}
|
@@ -551,11 +557,11 @@ DOM
|
|
551
557
|
end
|
552
558
|
let(:expected_html) do
|
553
559
|
<<-HTML
|
554
|
-
<select class="condition dynamic_filter field"
|
555
|
-
<option value="name">name</option></select><select class="condition dynamic_filter operation"
|
560
|
+
<select class="condition dynamic_filter field" name="report[condition][]" id="report_condition"><option selected value="id">id</option>
|
561
|
+
<option value="name">name</option></select><select class="condition dynamic_filter operation" name="report[condition][]" id="report_condition"><option value="=">=</option>
|
556
562
|
<option value="=~">≈</option>
|
557
|
-
<option value=">="
|
558
|
-
<option value="<=">≤</option></select><input class="condition dynamic_filter value"
|
563
|
+
<option selected value=">=">≥</option>
|
564
|
+
<option value="<=">≤</option></select><input class="condition dynamic_filter value" name="report[condition][]" value="1" type="text" id="report_condition">
|
559
565
|
HTML
|
560
566
|
end
|
561
567
|
it {should equal_to_dom(expected_html)}
|
@@ -567,11 +573,11 @@ DOM
|
|
567
573
|
end
|
568
574
|
let(:expected_html) do
|
569
575
|
<<-HTML
|
570
|
-
<select class="condition dynamic_filter field"
|
571
|
-
<option value="name">name</option></select><select class="condition dynamic_filter operation"
|
576
|
+
<select class="condition dynamic_filter field" name="report[condition][]" id="report_condition"><option value="id">id</option>
|
577
|
+
<option value="name">name</option></select><select class="condition dynamic_filter operation" name="report[condition][]" id="report_condition"><option value="=">=</option>
|
572
578
|
<option value="=~">≈</option>
|
573
579
|
<option value=">=">≥</option>
|
574
|
-
<option value="<=">≤</option></select><input class="condition dynamic_filter value"
|
580
|
+
<option value="<=">≤</option></select><input class="condition dynamic_filter value" name="report[condition][]" type="text" id="report_condition">
|
575
581
|
HTML
|
576
582
|
end
|
577
583
|
it {should equal_to_dom(expected_html)}
|
@@ -584,8 +590,8 @@ DOM
|
|
584
590
|
end
|
585
591
|
let(:expected_html) do
|
586
592
|
<<-HTML
|
587
|
-
<select class="condition dynamic_filter field"
|
588
|
-
<option value="<=">≤</option></select><input class="condition dynamic_filter value"
|
593
|
+
<select class="condition dynamic_filter field" name="report[condition][]" id="report_condition"><option value="id">id</option></select><select class="condition dynamic_filter operation" name="report[condition][]" id="report_condition"><option value=">=">≥</option>
|
594
|
+
<option value="<=">≤</option></select><input class="condition dynamic_filter value" name="report[condition][]" type="text" id="report_condition">
|
589
595
|
HTML
|
590
596
|
end
|
591
597
|
it {should equal_to_dom(expected_html)}
|