apotomo-datatable 0.0.1

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.
@@ -0,0 +1,107 @@
1
+ puts "APOTOMO DATATABLE TEST"
2
+ require 'spec_helper'
3
+ require 'widget_helper'
4
+
5
+ @test_controller_options={}
6
+
7
+ describe Apotomo::DatatableWidget, "apotomo-datatable widget" do
8
+ rspecify(self)
9
+
10
+ before :each do
11
+ # The test_controller is not created here since we're testing sending different params to that method
12
+ num_items=15
13
+ (1..num_items).each {|n| FactoryGirl.create(:item)}
14
+ end
15
+
16
+ it "should be an instance of Apotomo::DatatableWidget" do
17
+ @test_controller=test_controller(:widget=>{:name=>'test_datatable_widget'},:template=>{:id=>'test_datatable'},:plugin=>{:iDisplayStart=>10})
18
+ @widget=@test_controller.apotomo_root.childrenHash[:datatable]
19
+ @widget.should be_an_instance_of(Apotomo::DatatableWidget)
20
+ end
21
+
22
+ describe "after_initialize without controller_options provided" do
23
+ before :each do
24
+ @test_controller=test_controller()
25
+ @widget=@test_controller.apotomo_root.childrenHash[:datatable]
26
+ end
27
+
28
+ it "should be using the default model" do
29
+ @widget.merged_options[:widget][:model].should == Item
30
+ end
31
+
32
+ it "should merge default options with options passed by the controller into @options" do
33
+ options=@widget.merged_options
34
+ options[:widget][:name].should == 'ItemDatatableWidget'
35
+ options[:template][:id].should == 'ItemDatatable'
36
+ options[:plugin][:iDisplayStart].should == 0
37
+ end
38
+ end
39
+
40
+ describe "after_initialize with controller_options provided" do
41
+ before :each do
42
+ @test_controller=test_controller(:widget=>{:name=>'test_datatable_widget'},:template=>{:id=>'test_datatable'},:plugin=>{:iDisplayStart=>10})
43
+ @widget=@test_controller.apotomo_root.childrenHash[:datatable]
44
+ end
45
+
46
+ it "should merge default options with options passed by the controller into @options" do
47
+ options=@widget.merged_options
48
+ options[:widget][:name].should == 'test_datatable_widget'
49
+ options[:template][:id].should == 'test_datatable'
50
+ options[:plugin][:iDisplayStart].should == 10
51
+ end
52
+ end
53
+
54
+ it "should respond to method calls" do
55
+ @test_controller=test_controller(:widget=>{:name=>'test_datatable_widget'},:template=>{:id=>'test_datatable'},:plugin=>{:iDisplayStart=>10})
56
+ @widget=@test_controller.apotomo_root.childrenHash[:datatable]
57
+
58
+ lambda{@widget.increment_test_val}.should change(@widget,:test_val).by(1)
59
+ end
60
+
61
+ it "should respond to event triggers" do
62
+ @test_controller=test_controller()
63
+ @widget=@test_controller.apotomo_root.childrenHash[:datatable]
64
+ @widget.instance_eval do
65
+ def data
66
+ render text: 'result'
67
+ end
68
+ end
69
+ @test_controller.render_widget(:datatable,:data).should == 'result'
70
+ end
71
+
72
+ it "should raise an exception without a model to use" do
73
+ class OrphanController < MockController
74
+ end
75
+ OrphanController.has_widget_with_params()
76
+ @test_controller=OrphanController.new
77
+ @test_controller.request=::ActionController::TestRequest.new
78
+ @test_controller.response=::ActionController::TestResponse.new
79
+ @test_controller.params={}
80
+ lambda {@widget=@test_controller.apotomo_root.childrenHash[:datatable]}.should raise_error
81
+ end
82
+
83
+ it "should raise an exception when provided an invalid model from the controller options" do
84
+ class OrphanController < MockController
85
+ end
86
+ OrphanController.has_widget_with_params(:widget=>{:model=>nil})
87
+ @test_controller=OrphanController.new
88
+ @test_controller.request=::ActionController::TestRequest.new
89
+ @test_controller.response=::ActionController::TestResponse.new
90
+ @test_controller.params={}
91
+ lambda {@widget=@test_controller.apotomo_root.childrenHash[:datatable]}.should raise_error
92
+ end
93
+
94
+ end
95
+
96
+ def msg(o,m)
97
+ # for brute-force debugging
98
+ # @controller.response.methods.sort.each do |m|
99
+ # puts "#{m}=#{msg(@controller.response, m)}"
100
+ # end
101
+
102
+ begin
103
+ o.send m
104
+ rescue
105
+ ""
106
+ end
107
+ end
@@ -0,0 +1,24 @@
1
+ puts "DATA EVENT TEST"
2
+ require 'spec_helper'
3
+ require 'widget_helper'
4
+
5
+ describe Apotomo::DatatableWidget, "apotomo-datatable widget" do
6
+ rspecify(self)
7
+
8
+ before :each do
9
+ @test_controller=test_controller(:widget=>{},:template=>{},:plugin=>{})
10
+ @widget=@test_controller.apotomo_root.childrenHash[:datatable]
11
+ num_items=15
12
+ (1..num_items).each {|n| FactoryGirl.create(:item)}
13
+ end
14
+
15
+ describe ":data event" do
16
+ it "should render a json string with data when the :data event is triggered" do
17
+ #This triggers the :data event, which queries the database returns a json string of the data
18
+ @test_controller.render_widget(:datatable,:data).should include("\"iTotalRecords\":15")
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+
@@ -0,0 +1,45 @@
1
+ puts "DISPLAY EVENT TEST"
2
+ require 'spec_helper'
3
+ require 'widget_helper'
4
+
5
+ describe Apotomo::DatatableWidget, "apotomo-datatable widget" do
6
+ rspecify(self)
7
+
8
+ before :each do
9
+ @controller=test_controller(:widget=>{},:template=>{},:plugin=>{})
10
+ @widget=@controller.apotomo_root.childrenHash[:datatable]
11
+ num_items=15
12
+ (1..num_items).each {|n| FactoryGirl.create(:item)}
13
+ end
14
+
15
+ describe ":display event" do
16
+
17
+ it "should respond to the triggering of the :display event"
18
+
19
+ it "should convert boolean values in @merged_options to the appropriate defaults"
20
+
21
+ it "should generate and render a json string from @merged_options[:plugin]"
22
+
23
+ it "should generate javascript to merge client-side plugin options when @merged_options[:template][:plugin_options] != nil"
24
+
25
+ it "should render display_html from the gem's path to a single-line, html_safe string when @options[:params][:format]=='js' and app/widgets/apotomo/datatable/display_html* is not present" #check for presence of "default apotomo-datatable view" in the string. Better test would be to find out which file is being used
26
+
27
+ it "should render display_html from the app's path to a single-line, html_safe string when @options[:params][:format]=='js' and app/widgets/apotomo/datatable/display_html* is present" #check for non-presence of "default apotomo-datatable view" in the string. Better test would be to find out which file is being used
28
+
29
+ it "should render display_js from the gem's path when @options[:params][:format]=='js' and app/widgets/apotomo/datatable/display_js* is not present"
30
+
31
+ it "should render display_js from the app's path when @options[:params][:format]=='js' and app/widgets/apotomo/datatable/display_js* is present"
32
+
33
+ it "should render display_html from the gem's path when @options[:params][:format]!='js' and app/widgets/apotomo/datatable/display_js* is not present"
34
+
35
+ it "should render display_html from the app's path when @options[:params][:format]!='js' and app/widgets/apotomo/datatable/display_js* is present"
36
+
37
+ describe "head_foot template" do
38
+
39
+ it "should include the approprate elements as defined by @options[:template][:header]and @options[:template][:footer]"
40
+
41
+ end
42
+ end
43
+
44
+ end
45
+
@@ -0,0 +1,38 @@
1
+ puts "INCLUDED/EXCLUDED COLUMNS TEST"
2
+ require 'spec_helper'
3
+ require 'widget_helper'
4
+
5
+ describe Apotomo::DatatableWidget, "apotomo-datatable widget" do
6
+ rspecify(self)
7
+
8
+ describe ":display event" do
9
+ it "should exclude :id, :created_at and :updated_at by default" do
10
+ @test_controller=test_controller(:widget=>{},:template=>{},:plugin=>{})
11
+ @widget=@test_controller.apotomo_root.childrenHash[:datatable]
12
+ @test_controller.render_widget(:datatable,:display).should_not include("<th>id</th>")
13
+ @test_controller.render_widget(:datatable,:display).should_not include("<th>created_at</th>")
14
+ @test_controller.render_widget(:datatable,:display).should_not include("<th>updated_at</th>")
15
+ end
16
+ it "should include non-rails-default columns default" do
17
+ @test_controller=test_controller(:widget=>{},:template=>{},:plugin=>{})
18
+ @widget=@test_controller.apotomo_root.childrenHash[:datatable]
19
+ @test_controller.render_widget(:datatable,:display).should include("<th>name</th>")
20
+ @test_controller.render_widget(:datatable,:display).should include("<th>value</th>")
21
+ end
22
+ it "should include an excluded column when added to [:template][:included_columns] option" do
23
+ @test_controller=test_controller(:widget=>{},:template=>{:included_columns=>[:id]},:plugin=>{})
24
+ @widget=@test_controller.apotomo_root.childrenHash[:datatable]
25
+ @test_controller.render_widget(:datatable,:display).should include("<th>id</th>")
26
+ end
27
+ it "should exclude additional columns passed in the [:template][:excluded_columns] option" do
28
+ @test_controller=test_controller(:widget=>{},:template=>{:included_columns=>[:id]},:plugin=>{})
29
+ @widget=@test_controller.apotomo_root.childrenHash[:datatable]
30
+ @test_controller.render_widget(:datatable,:display).should include("<th>id</th>")
31
+ end
32
+
33
+
34
+ end
35
+
36
+ end
37
+
38
+
@@ -0,0 +1,35 @@
1
+ puts "MERGE OPTIONS TESTS"
2
+ require 'spec_helper'
3
+ require 'widget_helper'
4
+
5
+ describe Apotomo::DatatableWidget, "apotomo-datatable widget" do
6
+ rspecify(self)
7
+
8
+ before :each do
9
+ @test_controller=test_controller(:widget=>{},:template=>{},:plugin=>{})
10
+ @widget=@test_controller.apotomo_root.childrenHash[:datatable]
11
+ end
12
+
13
+ describe "display method" do
14
+ it "should merge view_options into @merged_options if provided" do
15
+ @widget.display(:widget=>{:test_option=>'view'},:template=>{:test_option=>'view'},:plugin=>{:test_option=>'view'})
16
+ merged_options=@widget.merged_options
17
+ merged_options[:widget][:test_option].should == 'view'
18
+ merged_options[:template][:test_option].should == 'view'
19
+ merged_options[:plugin][:test_option].should == 'view'
20
+ end
21
+
22
+ it "should merge url_param_options into @merged_options" do
23
+ @test_controller.params={:widget=>{:test_option=>'url'},:template=>{:test_option=>'url'},:plugin=>{:test_option=>'url'}}.with_indifferent_access
24
+ @widget.display(:widget=>{:test_option=>'view'},:template=>{:test_option=>'view'},:plugin=>{:test_option=>'view'})
25
+ merged_options=@widget.merged_options
26
+ #widget options should not be overridden by URL params
27
+ merged_options[:widget][:test_option].should == 'view'
28
+ #template and plugin options should be overridden by url params
29
+ merged_options[:template][:test_option].should == 'url'
30
+ merged_options[:plugin][:test_option].should == 'url'
31
+ end
32
+ end
33
+ end
34
+
35
+
metadata ADDED
@@ -0,0 +1,359 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apotomo-datatable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jason Van Pelt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: apotomo
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.2.2
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.2.2
46
+ - !ruby/object:Gem::Dependency
47
+ name: haml
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 3.1.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 3.1.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec-apotomo
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: haml
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 3.1.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 3.1.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: sqlite3
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rspec-rails
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: database_cleaner
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: rspec-instafail
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: factory_girl
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ - !ruby/object:Gem::Dependency
175
+ name: shoulda
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ - !ruby/object:Gem::Dependency
191
+ name: capybara
192
+ requirement: !ruby/object:Gem::Requirement
193
+ none: false
194
+ requirements:
195
+ - - ! '>='
196
+ - !ruby/object:Gem::Version
197
+ version: 2.0.1
198
+ type: :development
199
+ prerelease: false
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ! '>='
204
+ - !ruby/object:Gem::Version
205
+ version: 2.0.1
206
+ - !ruby/object:Gem::Dependency
207
+ name: debugger
208
+ requirement: !ruby/object:Gem::Requirement
209
+ none: false
210
+ requirements:
211
+ - - ! '>='
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ type: :development
215
+ prerelease: false
216
+ version_requirements: !ruby/object:Gem::Requirement
217
+ none: false
218
+ requirements:
219
+ - - ! '>='
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ - !ruby/object:Gem::Dependency
223
+ name: launchy
224
+ requirement: !ruby/object:Gem::Requirement
225
+ none: false
226
+ requirements:
227
+ - - ! '>='
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ none: false
234
+ requirements:
235
+ - - ! '>='
236
+ - !ruby/object:Gem::Version
237
+ version: '0'
238
+ - !ruby/object:Gem::Dependency
239
+ name: selenium-webdriver
240
+ requirement: !ruby/object:Gem::Requirement
241
+ none: false
242
+ requirements:
243
+ - - ! '>='
244
+ - !ruby/object:Gem::Version
245
+ version: '0'
246
+ type: :development
247
+ prerelease: false
248
+ version_requirements: !ruby/object:Gem::Requirement
249
+ none: false
250
+ requirements:
251
+ - - ! '>='
252
+ - !ruby/object:Gem::Version
253
+ version: '0'
254
+ - !ruby/object:Gem::Dependency
255
+ name: coffee-rails
256
+ requirement: !ruby/object:Gem::Requirement
257
+ none: false
258
+ requirements:
259
+ - - ! '>='
260
+ - !ruby/object:Gem::Version
261
+ version: '0'
262
+ type: :development
263
+ prerelease: false
264
+ version_requirements: !ruby/object:Gem::Requirement
265
+ none: false
266
+ requirements:
267
+ - - ! '>='
268
+ - !ruby/object:Gem::Version
269
+ version: '0'
270
+ - !ruby/object:Gem::Dependency
271
+ name: actionpack
272
+ requirement: !ruby/object:Gem::Requirement
273
+ none: false
274
+ requirements:
275
+ - - ! '>='
276
+ - !ruby/object:Gem::Version
277
+ version: '0'
278
+ type: :development
279
+ prerelease: false
280
+ version_requirements: !ruby/object:Gem::Requirement
281
+ none: false
282
+ requirements:
283
+ - - ! '>='
284
+ - !ruby/object:Gem::Version
285
+ version: '0'
286
+ description: A jQuery Datatable widget built on Apotomo. Render a jQuery datatable
287
+ for a model/controller using as little as a couple lines of code.
288
+ email:
289
+ - jasonpvp@gmail.com
290
+ executables: []
291
+ extensions: []
292
+ extra_rdoc_files: []
293
+ files:
294
+ - lib/apotomo-datatable/version.rb
295
+ - lib/apotomo-datatable/railtie.rb
296
+ - lib/apotomo-datatable.rb
297
+ - lib/tasks/apotomo-datatable_tasks.rake
298
+ - lib/apotomo/datatable/head_foot.html.haml
299
+ - lib/apotomo/datatable/display_html.html.haml
300
+ - lib/apotomo/datatable/display_js.html.haml
301
+ - lib/apotomo/datatable_widget.rb
302
+ - MIT-LICENSE
303
+ - Rakefile
304
+ - README.md
305
+ - spec/widget/apotomo_datatable_widget_spec.rb
306
+ - spec/widget/merge_options_spec.rb
307
+ - spec/widget/data_event_spec.rb
308
+ - spec/widget/included_excluded_columns_spec.rb
309
+ - spec/widget/display_event_spec.rb
310
+ - spec/features/load_datatable_in_various_ways_spec.rb
311
+ - spec/features/server_side_processing_spec.rb.log
312
+ - spec/features/load_datatable_in_various_ways_spec.rb.log
313
+ - spec/features/server_side_processing_spec.rb
314
+ - spec/dummy/README.rdoc
315
+ - spec/dummy/Rakefile
316
+ - spec/dummy/config.ru
317
+ homepage: https://github.com/jasonpvp/apotomo-datatable
318
+ licenses: []
319
+ post_install_message:
320
+ rdoc_options: []
321
+ require_paths:
322
+ - lib
323
+ required_ruby_version: !ruby/object:Gem::Requirement
324
+ none: false
325
+ requirements:
326
+ - - ! '>='
327
+ - !ruby/object:Gem::Version
328
+ version: '0'
329
+ segments:
330
+ - 0
331
+ hash: 1594184290050969788
332
+ required_rubygems_version: !ruby/object:Gem::Requirement
333
+ none: false
334
+ requirements:
335
+ - - ! '>='
336
+ - !ruby/object:Gem::Version
337
+ version: '0'
338
+ segments:
339
+ - 0
340
+ hash: 1594184290050969788
341
+ requirements: []
342
+ rubyforge_project:
343
+ rubygems_version: 1.8.24
344
+ signing_key:
345
+ specification_version: 3
346
+ summary: A jQuery Datatable widget built on Apotomo
347
+ test_files:
348
+ - spec/widget/apotomo_datatable_widget_spec.rb
349
+ - spec/widget/merge_options_spec.rb
350
+ - spec/widget/data_event_spec.rb
351
+ - spec/widget/included_excluded_columns_spec.rb
352
+ - spec/widget/display_event_spec.rb
353
+ - spec/features/load_datatable_in_various_ways_spec.rb
354
+ - spec/features/server_side_processing_spec.rb.log
355
+ - spec/features/load_datatable_in_various_ways_spec.rb.log
356
+ - spec/features/server_side_processing_spec.rb
357
+ - spec/dummy/README.rdoc
358
+ - spec/dummy/Rakefile
359
+ - spec/dummy/config.ru