data_table 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@ module DataTable
3
3
  module ClassMethods
4
4
 
5
5
  def _find_objects params, fields, search_fields
6
- self.where(_where_conditions params[:sSearch], search_fields).
6
+ self.where(_where_conditions params[:ssearch], search_fields).
7
7
  includes(_discover_joins fields).
8
8
  order(_order_fields params, fields).
9
9
  paginate :page => _page(params), :per_page => _per_page(params)
@@ -95,8 +95,8 @@ module DataTable
95
95
  end
96
96
 
97
97
  def _order_fields params, fields
98
- direction = params[:sSortDir_0] == "asc" ? "ASC" : "DESC"
99
- %{#{fields[params[:iSortCol_0].to_i]} #{direction}}
98
+ direction = params[:ssortdir_0] == "asc" ? "ASC" : "DESC"
99
+ %{#{fields[params[:isortcol_0].to_i]} #{direction}}
100
100
  end
101
101
  end
102
102
  end
@@ -7,14 +7,14 @@ module DataTable
7
7
 
8
8
  module ClassMethods
9
9
  def for_data_table controller, fields, search_fields=nil, explicit_block=nil, &implicit_block
10
- params = controller.params.dup
10
+ params = Hash[*controller.params.map {|key, value| [key.to_s.downcase.to_sym, value] }.flatten]
11
11
  search_fields ||= fields
12
12
  block = (explicit_block or implicit_block)
13
13
 
14
14
  objects = _find_objects params, fields, search_fields
15
15
  matching_count = objects.respond_to?(:total_entries) ? objects.total_entries : _matching_count(params, search_fields)
16
16
 
17
- {:sEcho => params[:sEcho].to_i,
17
+ {:sEcho => params[:secho].to_i,
18
18
  :iTotalRecords => self.count,
19
19
  :iTotalDisplayRecords => matching_count,
20
20
  :aaData => _yield_and_render_array(controller, objects, block)
@@ -36,12 +36,11 @@ module DataTable
36
36
  end
37
37
 
38
38
  def _page params
39
- return 1 if params[:iDisplayLength].blank?
40
- params[:iDisplayStart].to_i / params[:iDisplayLength].to_i + 1
39
+ params[:idisplaystart].to_i / params[:idisplaylength].to_i + 1
41
40
  end
42
41
 
43
42
  def _per_page params
44
- case (display_length = params[:iDisplayLength].to_i)
43
+ case (display_length = params[:idisplaylength].to_i)
45
44
  when -1 then self.count
46
45
  when 0 then 25
47
46
  else display_length
@@ -2,14 +2,14 @@ module DataTable
2
2
  module Mongoid
3
3
  module ClassMethods
4
4
  def _find_objects params, fields, search_fields
5
- self.where(_where_conditions params[:sSearch], search_fields).
5
+ self.where(_where_conditions params[:ssearch], search_fields).
6
6
  order_by(_order_by_fields params, fields).
7
7
  page(_page params).
8
8
  per(_per_page params)
9
9
  end
10
10
 
11
11
  def _matching_count params, search_fields
12
- self.where(_where_conditions params[:sSearch], search_fields).count
12
+ self.where(_where_conditions params[:ssearch], search_fields).count
13
13
  end
14
14
 
15
15
  def _where_conditions raw_query, search_fields
@@ -30,7 +30,7 @@ module DataTable
30
30
  end
31
31
 
32
32
  def _order_by_fields params, fields
33
- [fields[params[:iSortCol_0].to_i], params[:sSortDir_0] || "asc"]
33
+ [fields[params[:isortcol_0].to_i], params[:ssortdir_0] || "asc"]
34
34
  end
35
35
 
36
36
  def _sanitize string
@@ -1,3 +1,3 @@
1
1
  module DataTable
2
- VERSION = "0.3.8"
2
+ VERSION = "0.3.9"
3
3
  end
@@ -7,7 +7,7 @@ describe DataTable do
7
7
  context "#_find_objects" do
8
8
 
9
9
  it "should find the objects required based on the params" do
10
- params = {:sSearch => "answer", :iSortCol_0 => "0", :sSortDir_0 => "desc", :iDisplayLength => 10, :sEcho => 1}
10
+ params = {:ssearch => "answer", :isortcol_0 => "0", :ssortdir_0 => "desc", :idisplaylength => 10, :secho => 1}
11
11
 
12
12
  mock(self)._discover_joins(%w(foo bar baz)) { [] }
13
13
  mock(self)._where_conditions("answer", %w(foo bar)) { "where clause" }
@@ -96,7 +96,7 @@ describe DataTable do
96
96
  context "#_order_fields" do
97
97
 
98
98
  it "should find the field name and pass the sort direction" do
99
- send(:_order_fields, {:iSortCol_0 => "1", :sSortDir_0 => "asc"}, %w(foo bar baz)).should == "bar ASC"
99
+ send(:_order_fields, {:isortcol_0 => "1", :ssortdir_0 => "asc"}, %w(foo bar baz)).should == "bar ASC"
100
100
  end
101
101
 
102
102
  end
@@ -16,7 +16,8 @@ describe DataTable do
16
16
  context "#for_data_table" do
17
17
 
18
18
  it "should produce JSON for the datatables plugin to consume" do
19
- params = {:sSearch => "answer", :iSortCol_0 => "0", :sSortDir_0 => "desc", :iDisplayLength => "10", :sEcho => "1"}
19
+ params = {sSearch: "answer", iSortCol_0: "0", sSortDir_0: "desc", iDisplayLength: "10", sEcho: "1"}
20
+ normalized_params = {ssearch: "answer", isortcol_0: "0", ssortdir_0: "desc", idisplaylength: "10", secho: "1"}
20
21
  controller = mock!.params { params }.subject
21
22
 
22
23
  fields = %w(foo bar baz)
@@ -25,7 +26,7 @@ describe DataTable do
25
26
 
26
27
  mock(self).count { 42 }
27
28
  objects = mock!.total_entries { 10 }.subject
28
- mock(self)._find_objects(params, fields, search_fields) { objects }
29
+ mock(self)._find_objects(normalized_params, fields, search_fields) { objects }
29
30
  mock(self)._yield_and_render_array(controller, objects, block) { :results }
30
31
 
31
32
  result = for_data_table(controller, fields, search_fields, block)
@@ -69,20 +70,12 @@ describe DataTable do
69
70
  context "#_page" do
70
71
 
71
72
  context "with a display length of 10" do
72
- it "should return 1 when display length is blank" do
73
- send(:_page, {:iDisplayStart => "0"}).should == 1
74
- end
75
-
76
- it "should return 1 when start is blank" do
77
- send(:_page, {:iDisplayStart => "", :iDisplayLength => "10"}).should == 1
78
- end
79
-
80
73
  it "should return 1 when start is 0" do
81
- send(:_page, {:iDisplayStart => "0", :iDisplayLength => "10"}).should == 1
74
+ send(:_page, {idisplaystart: "0", idisplaylength: "10"}).should == 1
82
75
  end
83
76
 
84
77
  it "should return 2 when start is 10" do
85
- send(:_page, {:iDisplayStart => "10", :iDisplayLength => "10"}).should == 2
78
+ send(:_page, {idisplaystart: "10", idisplaylength: "10"}).should == 2
86
79
  end
87
80
  end
88
81
 
@@ -91,16 +84,16 @@ describe DataTable do
91
84
  context "#_per_page" do
92
85
 
93
86
  it "should return 10 given an iDisplayLength of 10" do
94
- send(:_per_page, {:iDisplayLength => "10"}).should == 10
87
+ send(:_per_page, {idisplaylength: "10"}).should == 10
95
88
  end
96
89
 
97
90
  it "should return a default of 25 given an invalid iDisplayLength" do
98
- send(:_per_page, {:iDisplayLength => "foobar"}).should == 25
91
+ send(:_per_page, {idisplaylength: "foobar"}).should == 25
99
92
  end
100
93
 
101
94
  it "should return self.count given an iDisplayLength of -1" do
102
95
  mock(self).count { :all }
103
- send(:_per_page, {:iDisplayLength => "-1"}).should == :all
96
+ send(:_per_page, {idisplaylength: "-1"}).should == :all
104
97
  end
105
98
 
106
99
  end
@@ -6,7 +6,7 @@ describe DataTable do
6
6
 
7
7
  context "#_find_objects" do
8
8
  it "should find the objects required based on the params" do
9
- params = {:sSearch => "answer", :iSortCol_0 => "0", :sSortDir_0 => "desc", :iDisplayLength => 10, :sEcho => 1}
9
+ params = {:ssearch => "answer", :isortcol_0 => "0", :ssortdir_0 => "desc", :idisplaylength => 10, :secho => 1}
10
10
 
11
11
  mock(self)._where_conditions("answer", %w(foo bar)) { "where clause" }
12
12
  mock(self)._order_by_fields(params, %w(foo bar baz)) { "order by" }
@@ -48,7 +48,7 @@ describe DataTable do
48
48
  context "#_order_by_fields" do
49
49
 
50
50
  it "should find the field name and pass the sort direction" do
51
- send(:_order_by_fields, {:iSortCol_0 => "1", :sSortDir_0 => "asc"}, %w(foo bar baz)).should == ["bar", "asc"]
51
+ send(:_order_by_fields, {:isortcol_0 => "1", :ssortdir_0 => "asc"}, %w(foo bar baz)).should == ["bar", "asc"]
52
52
  end
53
53
 
54
54
  it "should use defaults if none are given" do
metadata CHANGED
@@ -1,97 +1,68 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: data_table
3
- version: !ruby/object:Gem::Version
4
- hash: 3
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 3
9
- - 8
10
- version: 0.3.8
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.9
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Jason Dew
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-09-19 00:00:00 -05:00
12
+ date: 2011-09-23 00:00:00.000000000 -04:00
19
13
  default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: rails
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &2164364780 !ruby/object:Gem::Requirement
25
18
  none: false
26
- requirements:
19
+ requirements:
27
20
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 7
30
- segments:
31
- - 3
32
- - 0
33
- - 0
21
+ - !ruby/object:Gem::Version
34
22
  version: 3.0.0
35
23
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: rspec
39
24
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *2164364780
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: &2164364280 !ruby/object:Gem::Requirement
41
29
  none: false
42
- requirements:
30
+ requirements:
43
31
  - - ~>
44
- - !ruby/object:Gem::Version
45
- hash: 15
46
- segments:
47
- - 2
48
- - 0
49
- - 0
32
+ - !ruby/object:Gem::Version
50
33
  version: 2.0.0
51
34
  type: :development
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: shoulda
55
35
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *2164364280
37
+ - !ruby/object:Gem::Dependency
38
+ name: shoulda
39
+ requirement: &2164363820 !ruby/object:Gem::Requirement
57
40
  none: false
58
- requirements:
41
+ requirements:
59
42
  - - ~>
60
- - !ruby/object:Gem::Version
61
- hash: 35
62
- segments:
63
- - 2
64
- - 11
65
- - 0
43
+ - !ruby/object:Gem::Version
66
44
  version: 2.11.0
67
45
  type: :development
68
- version_requirements: *id003
69
- - !ruby/object:Gem::Dependency
70
- name: rr
71
46
  prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
47
+ version_requirements: *2164363820
48
+ - !ruby/object:Gem::Dependency
49
+ name: rr
50
+ requirement: &2164363360 !ruby/object:Gem::Requirement
73
51
  none: false
74
- requirements:
52
+ requirements:
75
53
  - - ~>
76
- - !ruby/object:Gem::Version
77
- hash: 23
78
- segments:
79
- - 1
80
- - 0
81
- - 0
54
+ - !ruby/object:Gem::Version
82
55
  version: 1.0.0
83
56
  type: :development
84
- version_requirements: *id004
57
+ prerelease: false
58
+ version_requirements: *2164363360
85
59
  description: Simple data preparation from AR/Mongoid to the jQuery DataTables plugin
86
- email:
60
+ email:
87
61
  - jason.dew@gmail.com
88
62
  executables: []
89
-
90
63
  extensions: []
91
-
92
64
  extra_rdoc_files: []
93
-
94
- files:
65
+ files:
95
66
  - .gitignore
96
67
  - Gemfile
97
68
  - Gemfile.lock
@@ -114,38 +85,29 @@ files:
114
85
  has_rdoc: true
115
86
  homepage: http://rubygems.org/gems/data_table
116
87
  licenses: []
117
-
118
88
  post_install_message:
119
89
  rdoc_options: []
120
-
121
- require_paths:
90
+ require_paths:
122
91
  - lib
123
- required_ruby_version: !ruby/object:Gem::Requirement
92
+ required_ruby_version: !ruby/object:Gem::Requirement
124
93
  none: false
125
- requirements:
126
- - - ">="
127
- - !ruby/object:Gem::Version
128
- hash: 3
129
- segments:
130
- - 0
131
- version: "0"
132
- required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
99
  none: false
134
- requirements:
135
- - - ">="
136
- - !ruby/object:Gem::Version
137
- hash: 3
138
- segments:
139
- - 0
140
- version: "0"
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
141
104
  requirements: []
142
-
143
105
  rubyforge_project: data_table
144
- rubygems_version: 1.3.7
106
+ rubygems_version: 1.6.2
145
107
  signing_key:
146
108
  specification_version: 3
147
109
  summary: Simple data preparation from AR/Mongoid to the jQuery DataTables plugin
148
- test_files:
110
+ test_files:
149
111
  - spec/active_record_data_table_spec.rb
150
112
  - spec/data_table_spec.rb
151
113
  - spec/mongoid_data_table_spec.rb