datagrid 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/Readme.markdown CHANGED
@@ -20,7 +20,8 @@ In order to create a report, you need to define:
20
20
 
21
21
  ### Working grid example
22
22
 
23
- [Datagrid DEMO application](https://github.com/bogdan/datagrid-demo) is available.
23
+ [Datagrid DEMO application](http://datagrid.heroku.com) is available live!
24
+ [Demo source code](https://github.com/bogdan/datagrid-demo).
24
25
 
25
26
  In order to create a grid:
26
27
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.5
1
+ 0.3.6
data/datagrid.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{datagrid}
8
- s.version = "0.3.5"
8
+ s.version = "0.3.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bogdan Gusiev"]
12
- s.date = %q{2011-08-15}
12
+ s.date = %q{2011-08-22}
13
13
  s.description = %q{This allows you to easily build datagrid aka data tables with sortable columns and filters}
14
14
  s.email = %q{agresso@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -48,6 +48,7 @@ Gem::Specification.new do |s|
48
48
  "lib/datagrid/utils.rb",
49
49
  "spec/datagrid/active_model_spec.rb",
50
50
  "spec/datagrid/columns_spec.rb",
51
+ "spec/datagrid/filters/composite_filters_spec.rb",
51
52
  "spec/datagrid/filters/enum_filter_spec.rb",
52
53
  "spec/datagrid/filters_spec.rb",
53
54
  "spec/datagrid/form_builder_spec.rb",
@@ -15,10 +15,10 @@ module Datagrid
15
15
 
16
16
  def date_range_filters(field, from_name = :"from_#{field}", to_name = :"to_#{field}")
17
17
  filter(from_name, :date) do |date|
18
- self.from_date(date, field)
18
+ self.scoped(:conditions => ["#{field} >= ?", date])
19
19
  end
20
20
  filter(to_name, :date) do |date|
21
- self.to_date(date, field)
21
+ self.scoped(:conditions => ["#{field} <= ?", date])
22
22
  end
23
23
  end
24
24
 
@@ -15,9 +15,12 @@ class Datagrid::Filters::EnumFilter < Datagrid::Filters::BaseFilter
15
15
  option.respond_to?(:call) ? option.call : option
16
16
  end
17
17
 
18
-
19
18
  def include_blank
20
- self.options.has_key?(:include_blank) ? options[:include_blank] : true
19
+ self.options.has_key?(:include_blank) ? options[:include_blank] : true unless self.prompt
20
+ end
21
+
22
+ def prompt
23
+ self.options.has_key?(:prompt) ? options[:prompt] : false
21
24
  end
22
25
 
23
26
  def strict
@@ -39,7 +39,7 @@ module Datagrid
39
39
  if !options.has_key?(:multiple) && filter.multiple
40
40
  options[:multiple] = true
41
41
  end
42
- select filter.name, filter.select || [], {:include_blank => filter.include_blank}, options
42
+ select filter.name, filter.select || [], {:include_blank => filter.include_blank, :prompt => filter.prompt}, options
43
43
  end
44
44
 
45
45
  def datagrid_integer_filter(attribute_or_filter, options = {})
@@ -20,13 +20,20 @@ describe Datagrid::Columns do
20
20
  subject.header.should == ["Group", "Name"]
21
21
  end
22
22
 
23
- it "should generate data" do
23
+ it "should generate table data" do
24
24
  subject.data.should == [
25
25
  subject.header,
26
26
  subject.row_for(entry)
27
27
  ]
28
28
  end
29
29
 
30
+ it "should generate hash for given asset" do
31
+ subject.hash_for(entry).should == {
32
+ :group => "Pop",
33
+ :name => "Star"
34
+ }
35
+ end
36
+
30
37
  it "should support csv export" do
31
38
  subject.to_csv.should == "Group,Name\nPop,Star\n"
32
39
  end
@@ -0,0 +1,36 @@
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
+ assets.should include(e2)
17
+ assets.should_not include(e1, e3)
18
+ end
19
+ end
20
+
21
+ describe ".integer_range_filters" do
22
+
23
+ it "should generate from integer and to integer filters" do
24
+ e1 = Entry.create!(:group_id => 1)
25
+ e2 = Entry.create!(:group_id => 3)
26
+ e3 = Entry.create!(:group_id => 5)
27
+ assets = test_report(:from_group_id => 2, :to_group_id => 4) do
28
+ scope {Entry}
29
+ integer_range_filters(:group_id)
30
+ end.assets
31
+
32
+ assets.should include(e2)
33
+ assets.should_not include(e1, e3)
34
+ end
35
+ end
36
+ end
@@ -34,11 +34,9 @@ describe Datagrid::Filters do
34
34
  end
35
35
 
36
36
  describe "allow_blank and allow_nil options" do
37
- before(:each) do
38
- $FILTER_PERFORMED = false
39
- end
40
37
 
41
38
  def check_performed(value, result, options)
39
+ $FILTER_PERFORMED = false
42
40
  report = test_report(:name => value) do
43
41
  scope {Entry}
44
42
  filter(:name, options) do |value|
@@ -57,7 +55,7 @@ describe Datagrid::Filters do
57
55
  end
58
56
  end
59
57
 
60
- it "should support allow_blank argument" do
58
+ it "should support allow_nil argument" do
61
59
  check_performed(nil, true, :allow_nil => true)
62
60
  end
63
61
 
@@ -13,8 +13,7 @@ end
13
13
  describe Datagrid::FormBuilder do
14
14
 
15
15
  let(:template) { ActionView::Base.new}
16
- let(:grid) { SimpleReport.new }
17
- let(:view) { ActionView::Helpers::FormBuilder.new(:report, grid, template, {}, Proc.new {|f| })}
16
+ let(:view) { ActionView::Helpers::FormBuilder.new(:report, _grid, template, {}, Proc.new {|f| })}
18
17
  subject { view }
19
18
 
20
19
 
@@ -22,6 +21,12 @@ describe Datagrid::FormBuilder do
22
21
 
23
22
  subject { view.datagrid_filter(_filter)}
24
23
  context "with default filter type" do
24
+ let(:_grid) {
25
+ test_report do
26
+ scope {Entry}
27
+ filter(:name)
28
+ end
29
+ }
25
30
  let(:_filter) { :name }
26
31
  it { should equal_to_dom(
27
32
  '<input class="name default_filter" id="report_name" name="report[name]" size="30" type="text"/>'
@@ -29,12 +34,26 @@ describe Datagrid::FormBuilder do
29
34
  end
30
35
  context "with integer filter type" do
31
36
  let(:_filter) { :group_id }
37
+ let(:_grid) {
38
+ test_report do
39
+ scope {Entry}
40
+ filter(:group_id, :integer)
41
+ end
42
+ }
32
43
  it { should equal_to_dom(
33
- '<input class="group_id integer_filter" id="report_group_id" name="report[group_id]" size="30" type="text" value=""/>'
44
+ '<input class="group_id integer_filter" id="report_group_id" name="report[group_id]" size="30" type="text"/>'
34
45
  )}
35
46
  end
36
47
  context "with enum filter type" do
37
48
  let(:_filter) { :category }
49
+ let(:_grid) {
50
+ test_report do
51
+ scope {Entry}
52
+ filter(:category, :enum, :select => ["first", "second"])
53
+ filter(:category_without_include_blank, :enum, :select => ["first", "second"], :include_blank => false)
54
+ filter(:category_with_prompt, :enum, :select => ["first", "second"], :prompt => "My Prompt")
55
+ end
56
+ }
38
57
  it { should equal_to_dom(
39
58
  '<select class="category enum_filter" id="report_category" name="report[category]"><option value=""></option>
40
59
  <option value="first">first</option>
@@ -42,7 +61,7 @@ describe Datagrid::FormBuilder do
42
61
  )}
43
62
  context "when first option is selected" do
44
63
  before(:each) do
45
- grid.category = "first"
64
+ _grid.category = "first"
46
65
  end
47
66
  it { should equal_to_dom(
48
67
  '<select class="category enum_filter" id="report_category" name="report[category]"><option value=""></option>
@@ -50,10 +69,32 @@ describe Datagrid::FormBuilder do
50
69
  <option value="second">second</option></select>'
51
70
  )}
52
71
  end
72
+ context "with include_blank option set to false" do
73
+ let(:_filter) { :category_without_include_blank }
74
+ it { should equal_to_dom(
75
+ '<select class="category_without_include_blank enum_filter" id="report_category_without_include_blank" name="report[category_without_include_blank]">
76
+ <option value="first">first</option>
77
+ <option value="second">second</option></select>'
78
+ )}
79
+ end
80
+ context "with prompt option" do
81
+ let(:_filter) { :category_with_prompt }
82
+ it { should equal_to_dom(
83
+ '<select class="category_with_prompt enum_filter" id="report_category_with_prompt" name="report[category_with_prompt]"><option value="">My Prompt</option>
84
+ <option value="first">first</option>
85
+ <option value="second">second</option></select>'
86
+ )}
87
+ end
53
88
  end
54
89
 
55
90
  context "with eboolean filter type" do
56
91
  let(:_filter) { :disabled }
92
+ let(:_grid) do
93
+ test_report do
94
+ scope {Entry}
95
+ filter(:disabled, :eboolean)
96
+ end
97
+ end
57
98
  it { should equal_to_dom(
58
99
  '<select class="disabled boolean_enum_filter" id="report_disabled" name="report[disabled]"><option value=""></option>
59
100
  <option value="YES">YES</option>
@@ -61,7 +102,7 @@ describe Datagrid::FormBuilder do
61
102
  )}
62
103
  end
63
104
  context "with string filter" do
64
- let(:grid) do
105
+ let(:_grid) do
65
106
  test_report do
66
107
  scope {Entry}
67
108
  filter(:name, :string)
@@ -74,7 +115,7 @@ describe Datagrid::FormBuilder do
74
115
  end
75
116
 
76
117
  context "with non multiple filter" do
77
- let(:grid) do
118
+ let(:_grid) do
78
119
  test_report do
79
120
  scope {Entry}
80
121
  filter(
@@ -91,6 +132,12 @@ describe Datagrid::FormBuilder do
91
132
  end
92
133
 
93
134
  describe ".datagrid_label" do
135
+ let(:_grid) do
136
+ test_report do
137
+ scope {Entry}
138
+ filter(:name, :string)
139
+ end
140
+ end
94
141
  it "should generate label for filter" do
95
142
  view.datagrid_label(:name).should equal_to_dom(
96
143
  '<label for="report_name">Name</label>'
@@ -25,8 +25,8 @@ describe Datagrid::Helper do
25
25
  subject.stub!(:datagrid_order_for).and_return(subject.content_tag(:div, "", :class => "order"))
26
26
  end
27
27
  it "should return data table html" do
28
- subject.datagrid_table(grid).should equal_to_dom(
29
- '<table class="datagrid">
28
+ subject.datagrid_table(grid).should equal_to_dom(<<-HTML)
29
+ <table class="datagrid">
30
30
  <tr>
31
31
  <th>Group<div class="order"></div>
32
32
  </th>
@@ -38,16 +38,17 @@ describe Datagrid::Helper do
38
38
  <td>Pop</td>
39
39
  <td>Star</td>
40
40
  </tr>
41
- </table>')
41
+ </table>
42
+ HTML
42
43
  end
43
44
 
44
45
  it "should support cycle option" do
45
- subject.datagrid_rows(grid, [entry], :cycle => ["odd", "even"]).should equal_to_dom(
46
- '<tr class="odd">
46
+ subject.datagrid_rows(grid, [entry], :cycle => ["odd", "even"]).should equal_to_dom(<<-HTML)
47
+ <tr class="odd">
47
48
  <td>Pop</td>
48
49
  <td>Star</td>
49
- </tr>'
50
- )
50
+ </tr>
51
+ HTML
51
52
  end
52
53
  end
53
54
 
@@ -40,13 +40,8 @@ describe SimpleReport do
40
40
 
41
41
 
42
42
  context "when not defined on class level" do
43
- before(:each) do
44
- @scope = SimpleReport.instance_variable_get("@scope")
45
- SimpleReport.instance_variable_set("@scope", nil)
46
- end
47
-
48
- after(:each) do
49
- SimpleReport.instance_variable_set("@scope", @scope)
43
+ subject do
44
+ test_report {}
50
45
  end
51
46
 
52
47
  it "should raise ConfigurationError" do
@@ -19,6 +19,7 @@ ActiveRecord::Schema.define(:version => 1) do
19
19
  t.string :category
20
20
  t.boolean :disabled, :null => false, :default => false
21
21
  t.boolean :confirmed, :null => false, :default => false
22
+ t.date :shipping_date
22
23
  t.timestamps
23
24
  end
24
25
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datagrid
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 5
10
- version: 0.3.5
9
+ - 6
10
+ version: 0.3.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bogdan Gusiev
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-15 00:00:00 +03:00
18
+ date: 2011-08-22 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -251,6 +251,7 @@ files:
251
251
  - lib/datagrid/utils.rb
252
252
  - spec/datagrid/active_model_spec.rb
253
253
  - spec/datagrid/columns_spec.rb
254
+ - spec/datagrid/filters/composite_filters_spec.rb
254
255
  - spec/datagrid/filters/enum_filter_spec.rb
255
256
  - spec/datagrid/filters_spec.rb
256
257
  - spec/datagrid/form_builder_spec.rb