datatable 0.1.0alpha2

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.
Files changed (187) hide show
  1. data/.bundle/config +3 -0
  2. data/.gitignore +7 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +9 -0
  5. data/Gemfile.lock +83 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.md +135 -0
  8. data/Rakefile +27 -0
  9. data/TODO +71 -0
  10. data/datatable.gemspec +20 -0
  11. data/example_app/.DS_Store +0 -0
  12. data/example_app/.gitignore +6 -0
  13. data/example_app/.rspec +1 -0
  14. data/example_app/Gemfile +35 -0
  15. data/example_app/Gemfile.lock +126 -0
  16. data/example_app/Rakefile +7 -0
  17. data/example_app/app/controllers/application_controller.rb +3 -0
  18. data/example_app/app/controllers/orders_controller.rb +13 -0
  19. data/example_app/app/datatables/orders_index.rb +31 -0
  20. data/example_app/app/helpers/application_helper.rb +2 -0
  21. data/example_app/app/models/customer.rb +4 -0
  22. data/example_app/app/models/item.rb +4 -0
  23. data/example_app/app/models/order.rb +5 -0
  24. data/example_app/app/models/order_item.rb +4 -0
  25. data/example_app/app/models/sales_rep.rb +3 -0
  26. data/example_app/app/views/layouts/application.html.erb +12 -0
  27. data/example_app/app/views/orders/index.html.erb +14 -0
  28. data/example_app/config/application.rb +41 -0
  29. data/example_app/config/boot.rb +6 -0
  30. data/example_app/config/database.yml.mysql +20 -0
  31. data/example_app/config/database.yml.pg +20 -0
  32. data/example_app/config/environment.rb +5 -0
  33. data/example_app/config/environments/development.rb +28 -0
  34. data/example_app/config/environments/production.rb +49 -0
  35. data/example_app/config/environments/test.rb +35 -0
  36. data/example_app/config/initializers/backtrace_silencers.rb +7 -0
  37. data/example_app/config/initializers/datatable.rb +6 -0
  38. data/example_app/config/initializers/inflections.rb +10 -0
  39. data/example_app/config/initializers/mime_types.rb +5 -0
  40. data/example_app/config/initializers/secret_token.rb +9 -0
  41. data/example_app/config/initializers/session_store.rb +8 -0
  42. data/example_app/config/locales/en.yml +5 -0
  43. data/example_app/config/routes.rb +6 -0
  44. data/example_app/config.ru +4 -0
  45. data/example_app/db/migrate/20110429185712_create_customers.rb +15 -0
  46. data/example_app/db/migrate/20110429185742_create_sales_reps.rb +14 -0
  47. data/example_app/db/migrate/20110429185807_create_items.rb +15 -0
  48. data/example_app/db/migrate/20110429185913_create_orders.rb +15 -0
  49. data/example_app/db/migrate/20110429190005_create_order_items.rb +14 -0
  50. data/example_app/db/schema.rb +53 -0
  51. data/example_app/db/seeds.rb +49 -0
  52. data/example_app/lib/tasks/.gitkeep +0 -0
  53. data/example_app/lib/tasks/setup.rake +12 -0
  54. data/example_app/public/404.html +26 -0
  55. data/example_app/public/422.html +26 -0
  56. data/example_app/public/500.html +26 -0
  57. data/example_app/public/datatable/css/demo_page.css +99 -0
  58. data/example_app/public/datatable/css/demo_table.css +539 -0
  59. data/example_app/public/datatable/css/demo_table_jui.css +521 -0
  60. data/example_app/public/datatable/css/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  61. data/example_app/public/datatable/css/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  62. data/example_app/public/datatable/css/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  63. data/example_app/public/datatable/css/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  64. data/example_app/public/datatable/css/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  65. data/example_app/public/datatable/css/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  66. data/example_app/public/datatable/css/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  67. data/example_app/public/datatable/css/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  68. data/example_app/public/datatable/css/smoothness/images/ui-icons_222222_256x240.png +0 -0
  69. data/example_app/public/datatable/css/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  70. data/example_app/public/datatable/css/smoothness/images/ui-icons_454545_256x240.png +0 -0
  71. data/example_app/public/datatable/css/smoothness/images/ui-icons_888888_256x240.png +0 -0
  72. data/example_app/public/datatable/css/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  73. data/example_app/public/datatable/css/smoothness/jquery-ui-1.8.14.custom.css +568 -0
  74. data/example_app/public/datatable/images/back_disabled.jpg +0 -0
  75. data/example_app/public/datatable/images/back_enabled.jpg +0 -0
  76. data/example_app/public/datatable/images/favicon.ico +0 -0
  77. data/example_app/public/datatable/images/forward_disabled.jpg +0 -0
  78. data/example_app/public/datatable/images/forward_enabled.jpg +0 -0
  79. data/example_app/public/datatable/images/sort_asc.png +0 -0
  80. data/example_app/public/datatable/images/sort_asc_disabled.png +0 -0
  81. data/example_app/public/datatable/images/sort_both.png +0 -0
  82. data/example_app/public/datatable/images/sort_desc.png +0 -0
  83. data/example_app/public/datatable/images/sort_desc_disabled.png +0 -0
  84. data/example_app/public/datatable/js/jquery-ui-1.8.14.custom.min.js +789 -0
  85. data/example_app/public/datatable/js/jquery.dataTables.js +7347 -0
  86. data/example_app/public/datatable/js/jquery.dataTables.min.js +151 -0
  87. data/example_app/public/favicon.ico +0 -0
  88. data/example_app/public/flash/copy_cvs_xls.swf +0 -0
  89. data/example_app/public/flash/copy_cvs_xls_pdf.swf +0 -0
  90. data/example_app/public/images/rails.png +0 -0
  91. data/example_app/public/javascripts/application.js +2 -0
  92. data/example_app/public/javascripts/jquery.js +8936 -0
  93. data/example_app/public/javascripts/jquery.min.js +18 -0
  94. data/example_app/public/javascripts/jquery_ujs.js +316 -0
  95. data/example_app/public/robots.txt +5 -0
  96. data/example_app/public/stylesheets/.gitkeep +0 -0
  97. data/example_app/script/rails +6 -0
  98. data/example_app/spec/datatables/active_record_dsl_spec.rb +59 -0
  99. data/example_app/spec/datatables/active_record_link_to_spec.rb +22 -0
  100. data/example_app/spec/datatables/active_record_pagination_spec.rb +94 -0
  101. data/example_app/spec/datatables/active_record_table_operations_spec.rb +180 -0
  102. data/example_app/spec/datatables/config_spec.rb +10 -0
  103. data/example_app/spec/datatables/query_params_spec.rb +73 -0
  104. data/example_app/spec/datatables/sql_default_spec.rb +22 -0
  105. data/example_app/spec/datatables/sql_pagination_spec.rb +177 -0
  106. data/example_app/spec/datatables/sql_search_cast_spec.rb +6 -0
  107. data/example_app/spec/datatables/sql_search_global_spec.rb +107 -0
  108. data/example_app/spec/datatables/sql_search_individual_spec.rb +113 -0
  109. data/example_app/spec/datatables/sql_search_where_spec.rb +87 -0
  110. data/example_app/spec/datatables/sql_sorting_spec.rb +80 -0
  111. data/example_app/spec/datatables/sql_variables_spec.rb +104 -0
  112. data/example_app/spec/factories/customer_factory.rb +4 -0
  113. data/example_app/spec/factories/item_factory.rb +2 -0
  114. data/example_app/spec/factories/order_factory.rb +7 -0
  115. data/example_app/spec/factories/order_item_factory.rb +2 -0
  116. data/example_app/spec/factories/sales_rep_factory.rb +4 -0
  117. data/example_app/spec/helpers/aocolumn_spec.rb +239 -0
  118. data/example_app/spec/helpers/data_table_helper_spec.rb +148 -0
  119. data/example_app/spec/helpers/headings_spec.rb +71 -0
  120. data/example_app/spec/spec_helper.rb +29 -0
  121. data/generators.txt +6 -0
  122. data/images/datatable_screenshot.png +0 -0
  123. data/lib/datatable/active_record_dsl.rb +49 -0
  124. data/lib/datatable/errors.rb +5 -0
  125. data/lib/datatable/helper.rb +199 -0
  126. data/lib/datatable/railtie.rb +17 -0
  127. data/lib/datatable/version.rb +4 -0
  128. data/lib/datatable.rb +341 -0
  129. data/lib/generators/datatable/install_generator.rb +58 -0
  130. data/lib/generators/datatable/new_generator.rb +46 -0
  131. data/lib/generators/templates/datatable.rb +33 -0
  132. data/lib/generators/templates/datatable_initializer.rb +6 -0
  133. data/vendor/datatable/Readme.txt +11 -0
  134. data/vendor/datatable/extras/TableTools/media/css/TableTools.css +264 -0
  135. data/vendor/datatable/extras/TableTools/media/css/TableTools_JUI.css +182 -0
  136. data/vendor/datatable/extras/TableTools/media/images/background.png +0 -0
  137. data/vendor/datatable/extras/TableTools/media/images/collection.png +0 -0
  138. data/vendor/datatable/extras/TableTools/media/images/collection_hover.png +0 -0
  139. data/vendor/datatable/extras/TableTools/media/images/copy.png +0 -0
  140. data/vendor/datatable/extras/TableTools/media/images/copy_hover.png +0 -0
  141. data/vendor/datatable/extras/TableTools/media/images/csv.png +0 -0
  142. data/vendor/datatable/extras/TableTools/media/images/csv_hover.png +0 -0
  143. data/vendor/datatable/extras/TableTools/media/images/pdf.png +0 -0
  144. data/vendor/datatable/extras/TableTools/media/images/pdf_hover.png +0 -0
  145. data/vendor/datatable/extras/TableTools/media/images/print.png +0 -0
  146. data/vendor/datatable/extras/TableTools/media/images/print_hover.png +0 -0
  147. data/vendor/datatable/extras/TableTools/media/images/xls.png +0 -0
  148. data/vendor/datatable/extras/TableTools/media/images/xls_hover.png +0 -0
  149. data/vendor/datatable/extras/TableTools/media/js/TableTools.js +2410 -0
  150. data/vendor/datatable/extras/TableTools/media/js/TableTools.min.js +78 -0
  151. data/vendor/datatable/extras/TableTools/media/js/TableTools.min.js.gz +0 -0
  152. data/vendor/datatable/extras/TableTools/media/js/ZeroClipboard.js +365 -0
  153. data/vendor/datatable/extras/TableTools/media/swf/copy_cvs_xls.swf +0 -0
  154. data/vendor/datatable/extras/TableTools/media/swf/copy_cvs_xls_pdf.swf +0 -0
  155. data/vendor/datatable/license-bsd.txt +10 -0
  156. data/vendor/datatable/license-gpl2.txt +339 -0
  157. data/vendor/datatable/media/css/demo_page.css +99 -0
  158. data/vendor/datatable/media/css/demo_table.css +539 -0
  159. data/vendor/datatable/media/css/demo_table_jui.css +521 -0
  160. data/vendor/datatable/media/css/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  161. data/vendor/datatable/media/css/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  162. data/vendor/datatable/media/css/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  163. data/vendor/datatable/media/css/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  164. data/vendor/datatable/media/css/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  165. data/vendor/datatable/media/css/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  166. data/vendor/datatable/media/css/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  167. data/vendor/datatable/media/css/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  168. data/vendor/datatable/media/css/smoothness/images/ui-icons_222222_256x240.png +0 -0
  169. data/vendor/datatable/media/css/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  170. data/vendor/datatable/media/css/smoothness/images/ui-icons_454545_256x240.png +0 -0
  171. data/vendor/datatable/media/css/smoothness/images/ui-icons_888888_256x240.png +0 -0
  172. data/vendor/datatable/media/css/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  173. data/vendor/datatable/media/css/smoothness/jquery-ui-1.8.14.custom.css +568 -0
  174. data/vendor/datatable/media/images/back_disabled.jpg +0 -0
  175. data/vendor/datatable/media/images/back_enabled.jpg +0 -0
  176. data/vendor/datatable/media/images/favicon.ico +0 -0
  177. data/vendor/datatable/media/images/forward_disabled.jpg +0 -0
  178. data/vendor/datatable/media/images/forward_enabled.jpg +0 -0
  179. data/vendor/datatable/media/images/sort_asc.png +0 -0
  180. data/vendor/datatable/media/images/sort_asc_disabled.png +0 -0
  181. data/vendor/datatable/media/images/sort_both.png +0 -0
  182. data/vendor/datatable/media/images/sort_desc.png +0 -0
  183. data/vendor/datatable/media/images/sort_desc_disabled.png +0 -0
  184. data/vendor/datatable/media/js/jquery-ui-1.8.14.custom.min.js +789 -0
  185. data/vendor/datatable/media/js/jquery.dataTables.js +7347 -0
  186. data/vendor/datatable/media/js/jquery.dataTables.min.js +151 -0
  187. metadata +270 -0
@@ -0,0 +1,239 @@
1
+ require 'spec_helper'
2
+
3
+ describe "ruby_aocolumns" do
4
+
5
+ describe "using active relation" do
6
+
7
+ it "should have tests" do
8
+ pending
9
+ end
10
+
11
+ end
12
+
13
+ describe "using raw sql" do
14
+
15
+ before do
16
+ Object.send(:remove_const, :T) rescue nil
17
+ class T < Datatable::Base
18
+ sql <<-SQL
19
+ SELECT
20
+ orders.id,
21
+ orders.order_number
22
+ FROM
23
+ orders
24
+ SQL
25
+ columns(
26
+ {'orders.id' => {:type => :integer}},
27
+ {'orders.order_number' => {:type => :string}}
28
+ )
29
+ end
30
+ assign(:datatable, T)
31
+ end
32
+
33
+ it 'should return nil for all columns when no properties are set' do
34
+ T.columns(
35
+ { 'orders.id' => {:type => :integer }},
36
+ { 'orders.order_number' => {:type => :string }}
37
+ )
38
+ helper.send(:ruby_aocolumns)[0].should be_nil
39
+ helper.send(:ruby_aocolumns)[1].should be_nil
40
+ end
41
+
42
+ it 'should support asSorting' do
43
+ T.columns(
44
+ { 'orders.id' => {:type => :integer, :asSorting => 'asc' }},
45
+ { 'orders.order_number' => {:type => :string, :asSorting => 'desc' }}
46
+ )
47
+ helper.send(:ruby_aocolumns)[0]['asSorting'].should == 'asc'
48
+ helper.send(:ruby_aocolumns)[1]['asSorting'].should == 'desc'
49
+ end
50
+
51
+ it 'should support bSearchable' do
52
+ T.columns(
53
+ { 'orders.id' => {:type => :integer, :bSearchable => true }},
54
+ { 'orders.order_number' => {:type => :string, :bSearchable => false }}
55
+ )
56
+ helper.send(:ruby_aocolumns)[0]['bSearchable'].should == true
57
+ helper.send(:ruby_aocolumns)[0]['bSearchable'].should == true
58
+ helper.send(:ruby_aocolumns)[1]['bSearchable'].should == false
59
+ end
60
+
61
+ it 'should support bSortable' do
62
+ T.columns(
63
+ { 'orders.id' => {:type => :integer, :bSortable => true }},
64
+ { 'orders.order_number' => {:type => :string, :bSortable => false }}
65
+ )
66
+ helper.send(:ruby_aocolumns)[0]['bSortable'].should == true
67
+ helper.send(:ruby_aocolumns)[1]['bSortable'].should == false
68
+ end
69
+
70
+ it 'should support bUseRendered' do
71
+ T.columns(
72
+ { 'orders.id' => {:type => :integer, :bUseRendered => true }},
73
+ { 'orders.order_number' => {:type => :string, :bUseRendered => false }}
74
+ )
75
+ helper.send(:ruby_aocolumns)[0]['bUseRendered'].should == true
76
+ helper.send(:ruby_aocolumns)[1]['bUseRendered'].should == false
77
+ end
78
+
79
+ it 'should support bVisible' do
80
+ T.columns(
81
+ { 'orders.id' => {:type => :integer, :bVisible => false }},
82
+ { 'orders.order_number' => {:type => :string }}
83
+ )
84
+ helper.send(:ruby_aocolumns)[0]['bVisible'].should_not be_nil
85
+ helper.send(:ruby_aocolumns)[0]['bVisible'].should be_false
86
+ helper.send(:ruby_aocolumns)[1].should be_nil
87
+ end
88
+
89
+ it 'should support fnRender' do
90
+ T.columns(
91
+ { 'orders.id' => {:type => :integer, :fnRender => "function(oObj){'foo'}" }},
92
+ { 'orders.order_number' => {:type => :string, :fnRender => "function(oObj){'bar'}" }}
93
+ )
94
+ helper.send(:ruby_aocolumns)[0]['fnRender'].should == "function(oObj){'foo'}"
95
+ helper.send(:ruby_aocolumns)[1]['fnRender'].should == "function(oObj){'bar'}"
96
+ end
97
+
98
+ it 'should support iDataSort' do
99
+ T.columns(
100
+ { 'orders.id' => {:type => :integer, :iDataSort => 1 }},
101
+ { 'orders.order_number' => {:type => :string, :iDataSort => 0 }}
102
+ )
103
+ helper.send(:ruby_aocolumns)[0]['iDataSort'].should == 1
104
+ helper.send(:ruby_aocolumns)[1]['iDataSort'].should == 0
105
+ end
106
+
107
+ it 'should support mDataProp' do
108
+ pending "need to understand what it does before I can write a spec for it"
109
+ end
110
+
111
+ it 'should support sClass' do
112
+ T.columns(
113
+ { 'orders.id' => {:type => :integer, :sClass => 'foo' }},
114
+ { 'orders.order_number' => {:type => :string, :sClass => 'bar' }}
115
+ )
116
+ helper.send(:ruby_aocolumns)[0]['sClass'].should == 'foo'
117
+ helper.send(:ruby_aocolumns)[1]['sClass'].should == 'bar'
118
+ end
119
+
120
+ it 'should support sDefaultContent' do
121
+ T.columns(
122
+ { 'orders.id' => {:type => :integer, :sDefaultContent => 'foo' }},
123
+ { 'orders.order_number' => {:type => :string, :sDefaultContent => 'bar' }}
124
+ )
125
+ helper.send(:ruby_aocolumns)[0]['sDefaultContent'].should == 'foo'
126
+ helper.send(:ruby_aocolumns)[1]['sDefaultContent'].should == 'bar'
127
+ end
128
+
129
+ it 'should support sName' do
130
+ T.columns(
131
+ { 'orders.id' => {:type => :integer, :sName => 'foo' }},
132
+ { 'orders.order_number' => {:type => :string, :sName => 'bar' }}
133
+ )
134
+ helper.send(:ruby_aocolumns)[0]['sName'].should == 'foo'
135
+ helper.send(:ruby_aocolumns)[1]['sName'].should == 'bar'
136
+ end
137
+
138
+ it "should support sSortDataType" do
139
+ pending "figure out if this is relevant for server side sorting?"
140
+ end
141
+
142
+ it 'should support sTitle' do
143
+ T.columns(
144
+ { 'orders.id' => {:type => :integer, :sTitle => 'foo' }},
145
+ { 'orders.order_number' => {:type => :string, :sTitle => 'bar' }}
146
+ )
147
+ helper.send(:ruby_aocolumns)[0]['sTitle'].should == 'foo'
148
+ helper.send(:ruby_aocolumns)[1]['sTitle'].should == 'bar'
149
+ end
150
+
151
+ it 'should support sType' do
152
+ T.columns(
153
+ { 'orders.id' => {:type => :integer, :sType => 'string' }},
154
+ { 'orders.order_number' => {:type => :string, :sType => 'numeric' }}
155
+ )
156
+ helper.send(:ruby_aocolumns)[0]['sType'].should == 'string'
157
+ helper.send(:ruby_aocolumns)[1]['sType'].should == 'numeric'
158
+ end
159
+
160
+ it 'should support sWidth' do
161
+ T.columns(
162
+ { 'orders.id' => {:type => :integer, :sWidth => '42px' }},
163
+ { 'orders.order_number' => {:type => :string, :sWidth => '42%' }}
164
+ )
165
+ helper.send(:ruby_aocolumns)[0]['sWidth'].should == '42px'
166
+ helper.send(:ruby_aocolumns)[1]['sWidth'].should == '42%'
167
+ end
168
+
169
+ end
170
+
171
+ describe "aocolumn" do
172
+ before do
173
+ Object.send(:remove_const, :T) rescue nil
174
+ class T < Datatable::Base
175
+ sql <<-SQL
176
+ SELECT
177
+ orders.id,
178
+ orders.order_number
179
+ FROM
180
+ orders
181
+ SQL
182
+ columns(
183
+ {'orders.id' => {:type => :integer, :fnRender => "function(oObj){'foo'}" }},
184
+ {'orders.order_number' => {:type => :string}}
185
+ )
186
+ end
187
+ assign(:datatable, T)
188
+ end
189
+
190
+ it "should render functions properly" do
191
+ helper.send(:aocolumns_text).should contain("function(oObj){'foo'}")
192
+ end
193
+
194
+ it "linkto should replace fnRender" do
195
+ T.columns(
196
+ {'orders.id' => {:type => :integer, :fnRender => "function(oObj){'bar'}", :link_to => link_to('{{0}}', order_path('{{0}}')) }},
197
+ {'orders.order_number' => {:type => :string, :bVisible => false}}
198
+ )
199
+ true.should_not be_false
200
+ end
201
+
202
+ end
203
+
204
+ end
205
+
206
+ describe "fnRender" do
207
+ it "demonstrate simple exmaple"
208
+ it "use link_to when it's defined'"
209
+ it "barf when both link_to and fnRender are used"
210
+ end
211
+
212
+ #describe 'Creating links for SQL DataTables' do
213
+ #
214
+ # before do
215
+ #
216
+ # Object.send(:remove_const, :T) rescue nil
217
+ #
218
+ # class T < Datatable::Base
219
+ # sql <<-SQL
220
+ # SELECT id FROM orders
221
+ # SQL
222
+ #
223
+ # columns(
224
+ # {"orders.id" => {:type => :integer, :link_to => link_to('{{0}}', order_path('{{0}}')) }}
225
+ # )
226
+ # end
227
+ #
228
+ # @params = {
229
+ # 'iColumns' => 1,
230
+ # "bSearchable_0" => true
231
+ # }
232
+ # end
233
+ #
234
+ # it 'should provide a link HTML element' do
235
+ # t = T.query(@params)
236
+ # T.columns['orders.id'][:link_to].should == "<a href=\"/orders/%7B%7B0%7D%7D\">{{0}}</a>"
237
+ # end
238
+ #
239
+ #end
@@ -0,0 +1,148 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe Datatable::Helper do
5
+
6
+ describe "with sql defined class" do
7
+ before do
8
+ Object.send(:remove_const, :T) rescue nil
9
+ class T < Datatable::Base
10
+ sql <<-SQL
11
+ SELECT id FROM orders
12
+ SQL
13
+ columns(
14
+ {"orders.id" => {:type => :integer, :link_to => link_to('{{0}}', order_path('{{0}}')) }}
15
+ )
16
+ end
17
+ assign(:datatable, T)
18
+ end
19
+
20
+ describe "link_to" do
21
+ it "contains href" do
22
+ helper.datatable_javascript.should contain('<a href=\"/orders/%7B%7B0%7D%7D\">{{0}}</a>')
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+
29
+ describe "active record test" do
30
+
31
+ before do
32
+ Object.send(:remove_const, :OrderTable) rescue nil
33
+ class OrderTable < Datatable::Base
34
+ set_model Order
35
+ column :order_number, :link_to => link_to('{{0}}', order_path('{{0}}'))
36
+ column :memo
37
+ end
38
+ assign(:datatable, OrderTable)
39
+ end
40
+
41
+ describe "link_to" do
42
+ it "contains href" do
43
+ helper.datatable_javascript.should contain('<a href=\"/orders/%7B%7B0%7D%7D\">{{0}}</a>')
44
+ end
45
+ end
46
+
47
+ describe "html emitter" do
48
+
49
+ it "should emit table" do
50
+ helper.datatable_html.should have_selector("table#datatable")
51
+ end
52
+
53
+ it "should emit table with 2 columns" do
54
+ helper.datatable_html.should have_selector("tr th:nth-child(2)")
55
+ end
56
+
57
+ it "should be html safe" do
58
+ helper.datatable_html.html_safe?.should be_true
59
+ end
60
+
61
+ it 'should include individual column search inputs if enabled' do
62
+ helper.datatable_html.should_not have_selector('tfoot th input')
63
+
64
+ OrderTable.option('individual_column_searching', true)
65
+ helper.datatable_html.should have_selector('tfoot th input')
66
+ end
67
+
68
+ end
69
+
70
+ describe "javascript emitter" do
71
+ it "should output a javascript tag" do
72
+ helper.datatable_javascript.should match(/script/)
73
+ end
74
+
75
+ it "should ouput the options" do
76
+ helper.request.path = 'ohai'
77
+ helper.datatable_javascript.should match('sAjaxSource')
78
+ helper.datatable_javascript.should match('ohai')
79
+ end
80
+
81
+ it "should be JSON" do
82
+ helper.datatable_javascript.should match(/"bProcessing":true/)
83
+ end
84
+
85
+ it "should be HTML safe" do
86
+ helper.datatable_javascript.html_safe?.should be_true
87
+ end
88
+
89
+ end
90
+
91
+ describe "javascript options" do
92
+
93
+ it "should output default options" do
94
+ expected = {
95
+ 'oLanguage' => {
96
+ 'sInfoFiltered' => '',
97
+ 'sProcessing' => 'Loading'
98
+ },
99
+ 'sAjaxSource' => '',
100
+ 'sDom' => '<"H"lfr>t<"F"ip>',
101
+ 'iDisplayLength' => 25,
102
+ 'bProcessing' => true,
103
+ 'bServerSide' => true,
104
+ 'sPaginationType' => "full_numbers",
105
+ 'aoColumns' => "aocolumns_place_holder",
106
+ 'bJQueryUI' => Datatable::Base.config.jquery_ui ? true : false
107
+ }
108
+ if Datatable::Base.config.table_tools == true
109
+ expected['oTableTools'] = {
110
+ 'sSwfPath' => 'flash/copy_cvs_xls_pdf.swf'
111
+ }
112
+ end
113
+ helper.send(:javascript_options).should == expected
114
+ end
115
+
116
+ it "should merge defaults with others" do
117
+ class OrderTable < Datatable::Base
118
+ option 'foo', 'bar'
119
+ end
120
+ helper.send(:javascript_options)['foo'].should == 'bar'
121
+ end
122
+
123
+ it 'should automatically set the jquery ui options based on the config' do
124
+ Datatable::Base.config do |config|
125
+ config.jquery_ui = nil
126
+ end
127
+ helper.send(:javascript_options)['bJQueryUI'].should == false
128
+
129
+ Datatable::Base.config do |config|
130
+ config.jquery_ui = false
131
+ end
132
+ helper.send(:javascript_options)['bJQueryUI'].should == false
133
+
134
+ Datatable::Base.config do |config|
135
+ config.jquery_ui = true
136
+ end
137
+ helper.send(:javascript_options)['bJQueryUI'].should == true
138
+
139
+
140
+ end
141
+
142
+
143
+ end
144
+ end
145
+ end
146
+
147
+
148
+
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ describe "headings" do
4
+
5
+ describe "arel" do
6
+ before do
7
+ Object.send(:remove_const, :T) rescue nil
8
+ class T < Datatable::Base
9
+ set_model Order
10
+ column :order_number
11
+ column :memo
12
+ end
13
+ assign(:datatable, T)
14
+ end
15
+
16
+ it "should have tests"
17
+
18
+ end
19
+
20
+ describe "raw sql" do
21
+
22
+ before do
23
+ Object.send(:remove_const, :T) rescue nil
24
+ class T < Datatable::Base
25
+ sql <<-SQL
26
+ SELECT
27
+ orders.id,
28
+ orders.order_number,
29
+ customers.first_name,
30
+ customers.last_name,
31
+ orders.memo
32
+ FROM
33
+ orders
34
+ JOIN
35
+ customers
36
+ ON
37
+ customers.id = orders.customer_id
38
+ SQL
39
+ columns(
40
+ {'orders.id' => {:type => :integer}},
41
+ {'orders.order_number' => {:type => :string}},
42
+ {'customers.first_name' => {:type => :string}},
43
+ {'customers.last_name' => {:type => :string}},
44
+ {'orders.memo' => {:type => :string}}
45
+ )
46
+ end
47
+ assign(:datatable, T)
48
+ end
49
+
50
+ it 'should humanize headings by default' do
51
+ ["Order Id", "Order Order Number", "Customer First Name", "Customer Last Name", "Order Memo"].each do |heading|
52
+ helper.datatable_html.should contain(heading)
53
+ end
54
+ end
55
+
56
+ it 'should use pretty headings when they are available' do
57
+ T.columns(
58
+ {'orders.id' => {:type => :integer, :heading => "Another heading that we specify manually"}},
59
+ {'orders.order_number' => {:type => :string, :heading => 'Yet another' }},
60
+ {'customers.first_name' => {:type => :string}},
61
+ {'customers.last_name' => {:type => :string}},
62
+ {'orders.memo' => {:type => :string, :heading => 'And another'}}
63
+ )
64
+ ["Another heading that we specify manually","Yet another" , "And another"].each do |heading|
65
+ helper.datatable_html.should contain(heading)
66
+ end
67
+ end
68
+
69
+ end
70
+
71
+ end
@@ -0,0 +1,29 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require File.expand_path("../../config/environment", __FILE__)
4
+ require 'rspec/rails'
5
+
6
+ require 'webrat'
7
+
8
+ # Requires supporting ruby files with custom matchers and macros, etc,
9
+ # in spec/support/ and its subdirectories.
10
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
11
+
12
+ RSpec.configure do |config|
13
+ # == Mock Framework
14
+ #
15
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
16
+ #
17
+ # config.mock_with :mocha
18
+ # config.mock_with :flexmock
19
+ # config.mock_with :rr
20
+ config.mock_with :rspec
21
+
22
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
23
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
24
+
25
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
26
+ # examples within a transaction, remove the following line or assign false
27
+ # instead of true.
28
+ config.use_transactional_fixtures = true
29
+ end
data/generators.txt ADDED
@@ -0,0 +1,6 @@
1
+ find out about
2
+ go to the github repo
3
+ probably look for some kind of quick-start or quick-tu
4
+
5
+ #=> print out what to add to the controller
6
+ & print out what to add to the view
Binary file
@@ -0,0 +1,49 @@
1
+ module Datatable
2
+ module ActiveRecordDSL
3
+
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ def relation
10
+ @relation
11
+ end
12
+
13
+ def set_model(model)
14
+ @model = model
15
+ @relation = model
16
+ end
17
+
18
+ def current_model
19
+ @inner_model || @model
20
+ end
21
+
22
+ def column(c, options={})
23
+
24
+ raise "set_model not called on #{self.name}" unless @model
25
+
26
+ @columns ||= ActiveSupport::OrderedHash.new
27
+
28
+ column_hash = {}
29
+ column_hash[:type] = current_model.columns.detect{ |col| col.name == c.to_s}.type
30
+ column_hash[:link_to] = options[:link_to]
31
+
32
+ @columns["#{current_model.table_name}.#{c}"] = column_hash
33
+
34
+ @relation= @relation.select(current_model.arel_table[c])
35
+ end
36
+
37
+ # TODO: Change to joins to match arel
38
+ def join(association, &block)
39
+
40
+ @inner_model = current_model.reflect_on_association(association).klass
41
+ @relation = @relation.joins(association)
42
+ instance_eval(&block) if block_given?
43
+ @inner_model = nil
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,5 @@
1
+ module Datatable
2
+ class DatatableException < StandardError; end
3
+ class UknownQueryParameter < DatatableException; end
4
+ end
5
+