autoforme 1.11.0 → 1.13.0

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.
data/spec/basic_spec.rb DELETED
@@ -1,1168 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe AutoForme do
4
- before(:all) do
5
- db_setup(:artists=>[[:name, :string]])
6
- model_setup(:Artist=>[:artists])
7
- end
8
- after(:all) do
9
- Object.send(:remove_const, :Artist)
10
- end
11
-
12
- it "should have basic functionality working" do
13
- app_setup(Artist)
14
- visit("/Artist/new")
15
- page.html.must_include '<!DOCTYPE html>'
16
- page.title.must_equal 'Artist - New'
17
- fill_in 'Name', :with=>'TestArtistNew'
18
- click_button 'Create'
19
- page.html.must_include 'Created Artist'
20
- page.current_path.must_equal '/Artist/new'
21
-
22
- click_link 'Show'
23
- page.title.must_equal 'Artist - Show'
24
- click_button 'Show'
25
- select 'TestArtistNew'
26
- click_button 'Show'
27
- page.html.must_match(/Name.+TestArtistNew/m)
28
-
29
- click_link 'Edit'
30
- page.title.must_equal 'Artist - Edit'
31
- click_button 'Edit'
32
- select 'TestArtistNew'
33
- click_button 'Edit'
34
- fill_in 'Name', :with=>'TestArtistUpdate'
35
- click_button 'Update'
36
- page.html.must_include 'Updated Artist'
37
- page.html.must_match(/Name.+TestArtistUpdate/m)
38
- page.current_path.must_match %r{/Artist/edit/\d+}
39
-
40
- click_link 'Search'
41
- page.title.must_equal 'Artist - Search'
42
- fill_in 'Name', :with=>'Upd'
43
- click_button 'Search'
44
- page.all('table').first['id'].must_equal 'autoforme_table'
45
- page.all('th').map{|s| s.text}.must_equal ['Name', 'Show', 'Edit', 'Delete']
46
- page.all('td').map{|s| s.text}.must_equal ["TestArtistUpdate", "Show", "Edit", "Delete"]
47
- click_link 'CSV Format'
48
- page.body.must_equal "Name\nTestArtistUpdate\n"
49
-
50
- visit("/Artist/browse")
51
- click_link 'Search'
52
- fill_in 'Name', :with=>'Foo'
53
- click_button 'Search'
54
- page.all('td').map{|s| s.text}.must_equal []
55
-
56
- click_link 'Artist'
57
- page.title.must_equal 'Artist - Browse'
58
- page.all('td').map{|s| s.text}.must_equal ["TestArtistUpdate", "Show", "Edit", "Delete"]
59
- click_link 'CSV Format'
60
- page.body.must_equal "Name\nTestArtistUpdate\n"
61
-
62
- visit("/Artist/destroy/#{Artist.first.id}")
63
- page.html.must_include 'Unhandled Request'
64
-
65
- visit("/Artist/browse")
66
- page.all('td').last.find('a').click
67
- click_button 'Delete'
68
- page.title.must_equal 'Artist - Delete'
69
- page.html.must_include 'Deleted Artist'
70
- page.current_path.must_equal '/Artist/delete'
71
-
72
- click_link 'Artist'
73
- page.all('td').map{|s| s.text}.must_equal []
74
- end
75
-
76
- it "should have basic functionality working in a subdirectory" do
77
- app_setup(Artist, :prefix=>"/prefix")
78
- visit("/prefix/Artist/new")
79
- fill_in 'Name', :with=>'TestArtistNew'
80
- click_button 'Create'
81
- page.html.must_include 'Created Artist'
82
- page.current_path.must_equal '/prefix/Artist/new'
83
-
84
- click_link 'Show'
85
- select 'TestArtistNew'
86
- click_button 'Show'
87
- page.html.must_match(/Name.+TestArtistNew/m)
88
-
89
- click_link 'Edit'
90
- select 'TestArtistNew'
91
- click_button 'Edit'
92
- fill_in 'Name', :with=>'TestArtistUpdate'
93
- click_button 'Update'
94
- page.html.must_include 'Updated Artist'
95
- page.html.must_match(/Name.+TestArtistUpdate/m)
96
- page.current_path.must_match %r{/prefix/Artist/edit/\d+}
97
-
98
- click_link 'Search'
99
- fill_in 'Name', :with=>'Upd'
100
- click_button 'Search'
101
- page.all('th').map{|s| s.text}.must_equal ['Name', 'Show', 'Edit', 'Delete']
102
- page.all('td').map{|s| s.text}.must_equal ["TestArtistUpdate", "Show", "Edit", "Delete"]
103
-
104
- click_link 'Search'
105
- fill_in 'Name', :with=>'Foo'
106
- click_button 'Search'
107
- page.all('td').map{|s| s.text}.must_equal []
108
-
109
- click_link 'Artist'
110
- page.all('td').map{|s| s.text}.must_equal ["TestArtistUpdate", "Show", "Edit", "Delete"]
111
-
112
- page.all('td').last.find('a').click
113
- click_button 'Delete'
114
- page.html.must_include 'Deleted Artist'
115
- page.current_path.must_equal '/prefix/Artist/delete'
116
-
117
- click_link 'Artist'
118
- page.all('td').map{|s| s.text}.must_equal []
119
- end
120
-
121
- it "should have basic functionality working with namespaced models" do
122
- begin
123
- def Artist.name; "Object::Artist"; end
124
- app_setup(Artist)
125
- visit("/Object::Artist/new")
126
- page.title.must_equal 'Object::Artist - New'
127
- fill_in 'Name', :with=>'TestArtistNew'
128
- click_button 'Create'
129
- page.html.must_include 'Created Object::Artist'
130
- page.current_path.must_equal '/Object::Artist/new'
131
-
132
- click_link 'Show'
133
- page.title.must_equal 'Object::Artist - Show'
134
- click_button 'Show'
135
- select 'TestArtistNew'
136
- click_button 'Show'
137
- page.html.must_match(/Name.+TestArtistNew/m)
138
-
139
- click_link 'Edit'
140
- page.title.must_equal 'Object::Artist - Edit'
141
- click_button 'Edit'
142
- select 'TestArtistNew'
143
- click_button 'Edit'
144
- fill_in 'Name', :with=>'TestArtistUpdate'
145
- click_button 'Update'
146
- page.html.must_include 'Updated Object::Artist'
147
- page.html.must_match(/Name.+TestArtistUpdate/m)
148
- page.current_path.must_match %r{/Object::Artist/edit/\d+}
149
-
150
- click_link 'Search'
151
- page.title.must_equal 'Object::Artist - Search'
152
- fill_in 'Name', :with=>'Upd'
153
- click_button 'Search'
154
- page.all('table').first['id'].must_equal 'autoforme_table'
155
- page.all('th').map{|s| s.text}.must_equal ['Name', 'Show', 'Edit', 'Delete']
156
- page.all('td').map{|s| s.text}.must_equal ["TestArtistUpdate", "Show", "Edit", "Delete"]
157
- click_link 'CSV Format'
158
- page.body.must_equal "Name\nTestArtistUpdate\n"
159
-
160
- visit("/Object::Artist/browse")
161
- click_link 'Search'
162
- fill_in 'Name', :with=>'Foo'
163
- click_button 'Search'
164
- page.all('td').map{|s| s.text}.must_equal []
165
-
166
- click_link 'Object::Artist'
167
- page.title.must_equal 'Object::Artist - Browse'
168
- page.all('td').map{|s| s.text}.must_equal ["TestArtistUpdate", "Show", "Edit", "Delete"]
169
- click_link 'CSV Format'
170
- page.body.must_equal "Name\nTestArtistUpdate\n"
171
-
172
- visit("/Object::Artist/browse")
173
- page.all('td').last.find('a').click
174
- click_button 'Delete'
175
- page.title.must_equal 'Object::Artist - Delete'
176
- page.html.must_include 'Deleted Object::Artist'
177
- page.current_path.must_equal '/Object::Artist/delete'
178
-
179
- click_link 'Object::Artist'
180
- page.all('td').map{|s| s.text}.must_equal []
181
- ensure
182
- class << Artist
183
- remove_method :name
184
- end
185
- end
186
- end
187
-
188
- it "should have delete button on edit page" do
189
- app_setup(Artist)
190
- visit("/Artist/new")
191
- fill_in 'Name', :with=>'TestArtistNew'
192
- click_button 'Create'
193
-
194
- click_link 'Edit'
195
- select 'TestArtistNew'
196
- click_button 'Edit'
197
- click_button 'Delete'
198
- Artist.count.must_equal 1
199
- click_button 'Delete'
200
- Artist.count.must_equal 0
201
- end
202
-
203
- it "should support custom headers and footers" do
204
- app_setup(Artist) do
205
- page_header "<a href='/Artist/new'>N</a>"
206
- page_footer "<a href='/Artist/edit'>E</a>"
207
- end
208
- visit("/Artist/browse")
209
- page.html.wont_include 'search'
210
- click_link 'N'
211
- fill_in 'Name', :with=>'TestArtistNew'
212
- click_button 'Create'
213
- click_link 'E'
214
- select 'TestArtistNew'
215
- click_button 'Edit'
216
- end
217
-
218
- it "should support showing models with custom ids" do
219
- db_setup(:tracks => proc do
220
- column :id, String, :primary_key => true
221
- column :name, String
222
- end)
223
-
224
- model_setup(:Track => [:tracks])
225
- Track.unrestrict_primary_key
226
- app_setup(Track)
227
-
228
- Track.create(:id => 'dark-side', :name => 'The Dark Side of the Moon')
229
-
230
- visit("/Track/show/dark-side")
231
-
232
- page.html.must_include 'The Dark Side of the Moon'
233
- end
234
-
235
- it "should support custom redirects" do
236
- app_setup(Artist) do
237
- redirect do |obj, type, req|
238
- case type
239
- when :new
240
- "/Artist/edit/#{obj.id}"
241
- when :edit
242
- "/Artist/show/#{obj.id}"
243
- when :delete
244
- "/Artist/new"
245
- end
246
- end
247
- end
248
- visit("/Artist/new")
249
- fill_in 'Name', :with=>'TestArtistNew'
250
- click_button 'Create'
251
- page.current_path.must_match %r{/Artist/edit/\d}
252
- click_button 'Update'
253
- page.current_path.must_match %r{/Artist/show/\d}
254
- click_link 'Delete'
255
- click_button 'Delete'
256
- select 'TestArtistNew'
257
- click_button 'Delete'
258
- click_button 'Delete'
259
- page.current_path.must_equal "/Artist/new"
260
- end
261
-
262
- it "should support custom form options and attributes" do
263
- app_setup(Artist) do
264
- form_attributes :class=>'foobar', :action=>'/create_artist'
265
- form_options :input_defaults=>{'text'=>{:class=>'barfoo'}}
266
- end
267
- visit("/Artist/new")
268
- find('form')[:class].must_equal 'foobar forme artist'
269
- find('form')[:action].must_equal '/create_artist'
270
- find('form input#artist_name')[:class].must_equal 'barfoo'
271
- end
272
-
273
- it "should support support specifying column options per type" do
274
- app_setup(Artist) do
275
- column_options{|column, type, req| {:label=>"#{type.to_s.capitalize} Artist #{column.to_s.capitalize}"}}
276
- end
277
-
278
- visit("/Artist/new")
279
- fill_in 'New Artist Name', :with=>'TestArtistNew'
280
- click_button 'Create'
281
- page.current_path.must_equal '/Artist/new'
282
-
283
- click_link 'Show'
284
- select 'TestArtistNew'
285
- click_button 'Show'
286
- page.html.must_match(/Show Artist Name.+TestArtistNew/m)
287
- click_button 'Edit'
288
- fill_in 'Edit Artist Name', :with=>'TestArtistUpdate'
289
- click_button 'Update'
290
- page.html.must_match(/Edit Artist Name.+TestArtistUpdate/m)
291
- page.current_path.must_match %r{/Artist/edit/\d+}
292
-
293
- click_link 'Search'
294
- fill_in 'Search_form Artist Name', :with=>'Upd'
295
- click_button 'Search'
296
- page.all('th').map{|s| s.text}.must_equal ["Search Artist Name", "Show", "Edit", "Delete"]
297
-
298
- click_link 'Artist'
299
- page.all('th').map{|s| s.text}.must_equal ["Browse Artist Name", "Show", "Edit", "Delete"]
300
- end
301
-
302
- it "should support specifying display names per type" do
303
- app_setup(Artist) do
304
- display_name do |obj, type|
305
- case type
306
- when :edit
307
- obj.name[1..-1]
308
- when :show
309
- obj.name[2..-2]
310
- when :delete
311
- obj.send(:class)
312
- end
313
- end
314
- end
315
- Artist.create(:name=>'TestArtistNew')
316
- visit("/Artist/show")
317
- select 'stArtistN'
318
- click_button 'Show'
319
- page.html.must_match(/Name.+TestArtistNew/m)
320
-
321
- click_link 'Edit'
322
- select 'estArtistNe'
323
- click_button 'Edit'
324
- page.html.must_match(/Name.+TestArtistNew/m)
325
-
326
- click_link 'Delete'
327
- select 'Artist'
328
- click_button 'Delete'
329
- click_button 'Delete'
330
- Artist.count.must_equal 0
331
- end
332
-
333
- it "should support create, update, delete hooks" do
334
- a = []
335
- app_setup do
336
- before_action{|type, req| a << type}
337
- before_create{|obj, req| a << -1}
338
- before_update{|obj, req| a << -2}
339
- before_destroy{|obj, req| a << -3}
340
- before_new{|obj, req| obj.name = 'weNtsitrAtseT'.dup}
341
- before_edit{|obj, req| obj.name << '2'}
342
- after_create{|obj, req| a << 1 }
343
- after_update{|obj, req| a << 2 }
344
- after_destroy{|obj, req| a << 3 }
345
- model Artist do
346
- before_action{|type, req| req.redirect('/Artist/browse') if type == :show}
347
- before_create{|obj, req| obj.name = obj.name.reverse}
348
- before_update{|obj, req| obj.name = obj.name.upcase}
349
- before_destroy{|obj, req| raise if obj.name == obj.name.reverse}
350
- before_new{|obj, req| obj.name.reverse!}
351
- before_edit{|obj, req| obj.name << '1'}
352
- after_create{|obj, req| a << req.action_type }
353
- after_update{|obj, req| a << req.action_type }
354
- after_destroy{|obj, req| a << req.action_type }
355
- end
356
- end
357
- visit("/Artist/new")
358
- click_button 'Create'
359
- a.must_equal [:new, :create, -1, 'create', 1, :new]
360
- a.clear
361
-
362
- click_link 'Edit'
363
- select 'weNtsitrAtseT'
364
- click_button 'Edit'
365
- page.html.must_include 'weNtsitrAtseT21'
366
- click_button 'Update'
367
- a.must_equal [:edit, :edit, :update, -2, 'update', 2, :edit]
368
- a.clear
369
-
370
- click_link 'Show'
371
- page.current_path.must_equal '/Artist/browse'
372
- a.must_equal [:show, :browse]
373
- a.clear
374
-
375
- click_link 'Delete', :match=>:first
376
- Artist.create(:name=>'A')
377
- select 'WENTSITRATSET21'
378
- click_button 'Delete'
379
- click_button 'Delete'
380
- a.must_equal [:delete, :delete, :destroy, -3, 'destroy', 3, :delete]
381
- a.clear
382
-
383
- select 'A'
384
- click_button 'Delete'
385
- proc{click_button 'Delete'}.must_raise RuntimeError
386
- a.must_equal [:delete, :destroy, -3]
387
- end
388
-
389
- it "should support specifying table class for data tables per type" do
390
- app_setup(Artist) do
391
- table_class{|type, req| type == :browse ? 'foo' : 'bar'}
392
- end
393
- visit("/Artist/browse")
394
- first('table')['class'].must_equal 'foo'
395
- click_link 'Search'
396
- click_button 'Search'
397
- first('table')['class'].must_equal 'bar'
398
- end
399
-
400
- it "should support specifying numbers of rows per page per type" do
401
- app_setup(Artist) do
402
- per_page{|type, req| type == :browse ? 2 : 3}
403
- end
404
- 5.times{|i| Artist.create(:name=>i.to_s)}
405
- visit("/Artist/browse")
406
- pager_class = lambda do |text|
407
- node = all('ul.pager li').select{|n| n[:class] if n.find('a').text == text}.first
408
- node[:class] if node
409
- end
410
- pager_class.call("Previous").must_equal 'disabled'
411
- page.all('tr td:first-child').map{|s| s.text}.must_equal %w'0 1'
412
- click_link 'Next'
413
- page.all('tr td:first-child').map{|s| s.text}.must_equal %w'2 3'
414
- click_link 'Next'
415
- page.all('tr td:first-child').map{|s| s.text}.must_equal %w'4'
416
- pager_class.call("Next").must_equal 'disabled'
417
- click_link 'Previous'
418
- page.all('tr td:first-child').map{|s| s.text}.must_equal %w'2 3'
419
- click_link 'Previous'
420
- page.all('tr td:first-child').map{|s| s.text}.must_equal %w'0 1'
421
- pager_class.call("Previous").must_equal 'disabled'
422
-
423
- click_link 'Search'
424
- click_button 'Search'
425
- page.all('tr td:first-child').map{|s| s.text}.must_equal %w'0 1 2'
426
- click_link 'Next'
427
- page.all('tr td:first-child').map{|s| s.text}.must_equal %w'3 4'
428
- pager_class.call("Next").must_equal 'disabled'
429
- click_link 'Previous'
430
- page.all('tr td:first-child').map{|s| s.text}.must_equal %w'0 1 2'
431
- pager_class.call("Previous").must_equal 'disabled'
432
- end
433
-
434
- it "should support specifying supported actions" do
435
- app_setup(Artist) do
436
- supported_actions [:new, :edit, :browse, :search]
437
- end
438
- visit("/Artist/new")
439
- fill_in 'Name', :with=>'TestArtistNew'
440
- click_button 'Create'
441
- page.current_path.must_equal '/Artist/new'
442
- page.html.wont_include 'Show'
443
- page.html.wont_include 'Delete'
444
-
445
- click_link 'Edit'
446
- select 'TestArtistNew'
447
- click_button 'Edit'
448
- fill_in 'Name', :with=>'TestArtistUpdate'
449
- click_button 'Update'
450
- page.html.must_match(/Name.+TestArtistUpdate/m)
451
- page.current_path.must_match %r{/Artist/edit/\d+}
452
-
453
- click_link 'Search'
454
- fill_in 'Name', :with=>'Upd'
455
- click_button 'Search'
456
- page.all('td').map{|s| s.text}.must_equal ["TestArtistUpdate", "Edit"]
457
-
458
- click_link 'Artist'
459
- page.all('td').map{|s| s.text}.must_equal ["TestArtistUpdate", "Edit"]
460
- end
461
-
462
- it "should have working link_name and class_display_name" do
463
- app_setup(Artist) do
464
- class_display_name "FooArtist"
465
- link_name "BarArtist"
466
- end
467
- visit("/BarArtist/new")
468
- fill_in 'Name', :with=>'TestArtistNew'
469
- click_button 'Create'
470
- page.html.must_include 'Created FooArtist'
471
- page.current_path.must_equal '/BarArtist/new'
472
-
473
- click_link 'Edit'
474
- select 'TestArtistNew'
475
- click_button 'Edit'
476
- fill_in 'Name', :with=>'TestArtistUpdate'
477
- click_button 'Update'
478
- page.html.must_include 'Updated FooArtist'
479
-
480
- click_link 'FooArtist'
481
- page.all('td').map{|s| s.text}.must_equal ["TestArtistUpdate", "Show", "Edit", "Delete"]
482
-
483
- page.all('td').last.find('a').click
484
- click_button 'Delete'
485
- page.html.must_include 'Deleted FooArtist'
486
- end
487
-
488
- it "should use text boxes on list page when autocompleting is enabled" do
489
- app_setup(Artist) do
490
- autocomplete_options({})
491
- end
492
- a = Artist.create(:name=>'TestArtistNew')
493
-
494
- visit('/Artist/show')
495
- fill_in 'Artist', :with=>a.id.to_s
496
- click_button 'Show'
497
- page.html.must_match(/Name.+TestArtistNew/m)
498
-
499
- click_link 'Edit'
500
- fill_in 'Artist', :with=>a.id.to_s
501
- click_button 'Edit'
502
- click_button 'Update'
503
-
504
- click_link 'Delete'
505
- fill_in 'Artist', :with=>a.id.to_s
506
- click_button 'Delete'
507
- click_button 'Delete'
508
- Artist.count.must_equal 0
509
- end
510
-
511
- it "should support show_html and edit_html" do
512
- app_setup(Artist) do
513
- show_html do |obj, c, t, req|
514
- "#{c}#{t}-#{obj.send(c).to_s*2}"
515
- end
516
- edit_html do |obj, c, t, req|
517
- "<label for='artist_#{c}'>#{c}#{t}</label><input type='text' id='artist_#{c}' name='#{t == :search_form ? c : "artist[#{c}]"}' value='#{obj.send(c).to_s*2}'/>"
518
- end
519
- end
520
- visit("/Artist/new")
521
- page.title.must_equal 'Artist - New'
522
- fill_in 'namenew', :with=>'TAN'
523
- click_button 'Create'
524
- page.html.must_include 'Created Artist'
525
- page.current_path.must_equal '/Artist/new'
526
-
527
- click_link 'Show'
528
- page.title.must_equal 'Artist - Show'
529
- select 'TAN'
530
- click_button 'Show'
531
- page.html.must_include 'nameshow-TANTAN'
532
-
533
- click_link 'Edit'
534
- page.title.must_equal 'Artist - Edit'
535
- select 'TAN'
536
- click_button 'Edit'
537
- fill_in 'nameedit', :with=>'TAU'
538
- click_button 'Update'
539
- page.html.must_include 'Updated Artist'
540
- page.html.must_match(/nameedit.+TAUTAU/m)
541
- page.current_path.must_match %r{/Artist/edit/\d+}
542
-
543
- click_link 'Search'
544
- page.title.must_equal 'Artist - Search'
545
- fill_in 'namesearch_form', :with=>'AU'
546
- click_button 'Search'
547
- page.all('table').first['id'].must_equal 'autoforme_table'
548
- page.all('th').map{|s| s.text}.must_equal ['Name', 'Show', 'Edit', 'Delete']
549
- page.all('td').map{|s| s.text}.must_equal ["namesearch-TAUTAU", "Show", "Edit", "Delete"]
550
- click_link 'CSV Format'
551
- page.body.must_equal "Name\nTAU\n"
552
-
553
- visit("/Artist/browse")
554
- click_link 'Search'
555
- fill_in 'namesearch_form', :with=>'TAUTAU'
556
- click_button 'Search'
557
- page.all('td').map{|s| s.text}.must_equal []
558
-
559
- click_link 'Artist'
560
- page.title.must_equal 'Artist - Browse'
561
- page.all('td').map{|s| s.text}.must_equal ["namebrowse-TAUTAU", "Show", "Edit", "Delete"]
562
- click_link 'CSV Format'
563
- page.body.must_equal "Name\nTAU\n"
564
-
565
- visit("/Artist/browse")
566
- page.all('td').last.find('a').click
567
- page.html.must_include 'namedelete-TAUTAU'
568
- click_button 'Delete'
569
- page.title.must_equal 'Artist - Delete'
570
- page.html.must_include 'Deleted Artist'
571
- page.current_path.must_equal '/Artist/delete'
572
-
573
- click_link 'Artist'
574
- page.all('td').map{|s| s.text}.must_equal []
575
- end
576
-
577
- it "should correctly handle validation errors" do
578
- app_setup(Artist)
579
- Artist.send(:define_method, :validate) do
580
- errors.add(:name, "bad name") if name == 'Foo'
581
- end
582
-
583
- visit("/Artist/new")
584
- page.title.must_equal 'Artist - New'
585
- fill_in 'Name', :with=>'Foo'
586
- click_button 'Create'
587
- page.title.must_equal 'Artist - New'
588
- page.html.must_include 'Error Creating Artist'
589
- page.html.must_include 'bad name'
590
- fill_in 'Name', :with=>'TestArtistNew'
591
- click_button 'Create'
592
- page.html.must_include 'Created Artist'
593
- page.current_path.must_equal '/Artist/new'
594
-
595
- click_link 'Edit'
596
- page.title.must_equal 'Artist - Edit'
597
- click_button 'Edit'
598
- select 'TestArtistNew'
599
- click_button 'Edit'
600
- fill_in 'Name', :with=>'Foo'
601
- click_button 'Update'
602
- page.title.must_equal 'Artist - Edit'
603
- page.html.must_include 'Error Updating Artist'
604
- page.html.must_include 'bad name'
605
- fill_in 'Name', :with=>'TestArtistUpdate'
606
- click_button 'Update'
607
- page.html.must_include 'Updated Artist'
608
- page.html.must_match(/Name.+TestArtistUpdate/m)
609
- page.current_path.must_match %r{/Artist/edit/\d+}
610
- end
611
-
612
- it "should support view_options" do
613
- app_setup(Artist, view_options: {:layout=>false}){}
614
- visit("/Artist/browse")
615
- page.html.wont_include '<!DOCTYPE html>'
616
- page.all('table').first['id'].must_equal 'autoforme_table'
617
- end
618
- end
619
-
620
- describe AutoForme do
621
- before(:all) do
622
- db_setup(:artists=>[[:name, :string], [:active, :boolean]])
623
- model_setup(:Artist=>[:artists])
624
- end
625
- after(:all) do
626
- Object.send(:remove_const, :Artist)
627
- end
628
-
629
- it "should typecast when searching" do
630
- app_setup(Artist)
631
- Artist.plugin(:typecast_on_load, :active) if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
632
- visit("/Artist/new")
633
- page.title.must_equal 'Artist - New'
634
- select 'True'
635
- fill_in 'Name', :with=>'TestArtistNew'
636
- click_button 'Create'
637
- page.html.must_include 'Created Artist'
638
- page.current_path.must_equal '/Artist/new'
639
-
640
- click_link 'Show'
641
- page.title.must_equal 'Artist - Show'
642
- click_button 'Show'
643
- select 'TestArtistNew'
644
- click_button 'Show'
645
- page.html.must_match(/Active.+True.+Name.+TestArtistNew/m)
646
-
647
- click_link 'Edit'
648
- page.title.must_equal 'Artist - Edit'
649
- click_button 'Edit'
650
- select 'TestArtistNew'
651
- click_button 'Edit'
652
- select 'False'
653
- fill_in 'Name', :with=>'TestArtistUpdate'
654
- click_button 'Update'
655
- page.html.must_include 'Updated Artist'
656
- page.html.must_match(/Active.+False.+Name.+TestArtistUpdate/m)
657
- page.current_path.must_match %r{/Artist/edit/\d+}
658
-
659
- click_link 'Search'
660
- page.title.must_equal 'Artist - Search'
661
- fill_in 'Name', :with=>'Upd'
662
- select 'False'
663
- click_button 'Search'
664
- page.all('table').first['id'].must_equal 'autoforme_table'
665
- page.all('th').map{|s| s.text}.must_equal ['Active', 'Name', 'Show', 'Edit', 'Delete']
666
- page.all('td').map{|s| s.text}.must_equal ['false', "TestArtistUpdate", "Show", "Edit", "Delete"]
667
- click_link 'CSV Format'
668
- page.body.must_equal "Active,Name\nfalse,TestArtistUpdate\n"
669
-
670
- visit("/Artist/browse")
671
- click_link 'Search'
672
- fill_in 'Name', :with=>'Foo'
673
- click_button 'Search'
674
- page.all('td').map{|s| s.text}.must_equal []
675
-
676
- visit("/Artist/browse")
677
- click_link 'Search'
678
- select 'True'
679
- click_button 'Search'
680
- page.all('td').map{|s| s.text}.must_equal []
681
-
682
- click_link 'Artist'
683
- page.title.must_equal 'Artist - Browse'
684
- page.all('td').map{|s| s.text}.must_equal ["false", "TestArtistUpdate", "Show", "Edit", "Delete"]
685
- click_link 'CSV Format'
686
- page.body.must_equal "Active,Name\nfalse,TestArtistUpdate\n"
687
-
688
- visit("/Artist/browse")
689
- page.all('td').last.find('a').click
690
- click_button 'Delete'
691
- page.title.must_equal 'Artist - Delete'
692
- page.html.must_include 'Deleted Artist'
693
- page.current_path.must_equal '/Artist/delete'
694
-
695
- click_link 'Artist'
696
- page.all('td').map{|s| s.text}.must_equal []
697
- end
698
- end
699
-
700
- describe AutoForme do
701
- before(:all) do
702
- db_setup(:artists=>(0..5).map{|i|[:"n#{i}", :string]})
703
- model_setup(:Artist=>[:artists])
704
- class Artist
705
- def forme_name
706
- n0
707
- end
708
- end
709
- end
710
- after(:all) do
711
- Object.send(:remove_const, :Artist)
712
- end
713
-
714
- it "should support specifying columns per type" do
715
- cols = Artist.columns - [:id]
716
- map = {:new=>:n5, :edit=>:n4, :show=>:n3, :browse=>:n2, :search_form=>:n1, :search=>:n0}
717
- app_setup(Artist) do
718
- columns{|type, req| cols - [map[type]]}
719
- end
720
-
721
- visit("/Artist/new")
722
- fill_in 'N0', :with=>'V0'
723
- fill_in 'N1', :with=>'V1'
724
- fill_in 'N2', :with=>'V2'
725
- fill_in 'N3', :with=>'V3'
726
- fill_in 'N4', :with=>'V4'
727
- page.body.wont_match(/<label>N5/i)
728
- click_button 'Create'
729
-
730
- click_link 'Show'
731
- select 'V0'
732
- click_button 'Show'
733
- page.body.must_match(/[VN]0/i)
734
- page.body.must_match(/[VN]1/i)
735
- page.body.must_match(/[VN]2/i)
736
- page.body.wont_match(/[VN]3/i)
737
- page.body.must_match(/[VN]4/i)
738
- page.body.must_match(/N5/i)
739
-
740
- click_link 'Edit'
741
- select 'V0'
742
- click_button 'Edit'
743
- fill_in 'N0', :with=>'Q0'
744
- fill_in 'N1', :with=>'Q1'
745
- fill_in 'N2', :with=>'Q2'
746
- fill_in 'N3', :with=>'Q3'
747
- page.body.wont_match(/<label>N4/i)
748
- fill_in 'N5', :with=>'Q5'
749
- click_button 'Update'
750
-
751
- click_link 'Search'
752
- fill_in 'N0', :with=>'Q0'
753
- page.body.wont_match(/<label>N1/i)
754
- fill_in 'N2', :with=>'Q2'
755
- fill_in 'N3', :with=>'Q3'
756
- fill_in 'N4', :with=>'V4'
757
- fill_in 'N5', :with=>'Q5'
758
- click_button 'Search'
759
- page.all('td').map{|s| s.text}.must_equal ["Q1", "Q2", "Q3", "V4", "Q5", "Show", "Edit", "Delete"]
760
- click_link 'CSV Format'
761
- page.body.must_equal "N1,N2,N3,N4,N5\nQ1,Q2,Q3,V4,Q5\n"
762
-
763
- visit '/Artist/browse'
764
- page.all('td').map{|s| s.text}.must_equal ["Q0", "Q1", "Q3", "V4", "Q5", "Show", "Edit", "Delete"]
765
- click_link 'CSV Format'
766
- page.body.must_equal "N0,N1,N3,N4,N5\nQ0,Q1,Q3,V4,Q5\n"
767
- end
768
-
769
- it "should support specifying order per type" do
770
- map = {:edit=>:n0, :show=>[:n1, :n2], :delete=>:n3, :browse=>[:n1, :n0], :search=>:n4}
771
- app_setup(Artist) do
772
- order{|type, req| map[type]}
773
- end
774
-
775
- Artist.create(:n0=>'1', :n1=>'2', :n2=>'3', :n3=>'7', :n4=>'5')
776
- Artist.create(:n0=>'2', :n1=>'2', :n2=>'1', :n3=>'3', :n4=>'4')
777
- Artist.create(:n0=>'0', :n1=>'4', :n2=>'1', :n3=>'5', :n4=>'3')
778
-
779
- visit("/Artist/show")
780
- page.all('option').map{|s| s.text}.must_equal ['', '2', '1', '0']
781
-
782
- click_link 'Edit'
783
- page.all('option').map{|s| s.text}.must_equal ['', '0', '1', '2']
784
-
785
- click_link 'Delete'
786
- page.all('option').map{|s| s.text}.must_equal ['', '2', '0', '1']
787
-
788
- click_link 'Search'
789
- click_button 'Search'
790
- page.all('tr td:first-child').map{|s| s.text}.must_equal ['0', '2', '1']
791
-
792
- click_link 'Artist'
793
- page.all('tr td:first-child').map{|s| s.text}.must_equal ['1', '2', '0']
794
- end
795
-
796
- it "should support specifying filter per type" do
797
- app_setup(Artist) do
798
- filter do |ds, type, req|
799
- case type
800
- when :edit
801
- ds.where{n0 > 1}
802
- when :show
803
- ds.where{n1 > 3}
804
- when :delete
805
- ds.where{n2 > 2}
806
- when :browse
807
- ds.where{n3 > 6}
808
- when :search
809
- ds.where{n4 > 4}
810
- end
811
- end
812
- end
813
-
814
- Artist.create(:n0=>'1', :n1=>'2', :n2=>'3', :n3=>'7', :n4=>'5')
815
- Artist.create(:n0=>'2', :n1=>'2', :n2=>'1', :n3=>'3', :n4=>'4')
816
- Artist.create(:n0=>'0', :n1=>'4', :n2=>'1', :n3=>'5', :n4=>'3')
817
-
818
- visit("/Artist/show")
819
- page.all('option').map{|s| s.text}.must_equal ['', '0']
820
-
821
- click_link 'Edit'
822
- page.all('option').map{|s| s.text}.must_equal ['', '2']
823
- select '2'
824
- click_button 'Edit'
825
- click_button 'Update'
826
-
827
- click_link 'Delete'
828
- page.all('option').map{|s| s.text}.must_equal ['', '1']
829
- select '1'
830
- click_button 'Delete'
831
- click_button 'Delete'
832
- Artist.create(:n0=>'1', :n1=>'2', :n2=>'3', :n3=>'7', :n4=>'5')
833
-
834
- click_link 'Search'
835
- click_button 'Search'
836
- page.all('tr td:first-child').map{|s| s.text}.must_equal %w'1'
837
-
838
- click_link 'Artist'
839
- page.all('tr td:first-child').map{|s| s.text}.must_equal %w'1'
840
- end
841
-
842
- it "should support specifying filter per type using request params" do
843
- app_setup(Artist) do
844
- filter do |ds, type, req|
845
- v = req.params['f']
846
- case type
847
- when :edit
848
- ds.where{n0 > v}
849
- when :show
850
- ds.where{n1 > v}
851
- when :delete
852
- ds.where{n2 > v}
853
- when :browse
854
- ds.where{n3 > v}
855
- when :search
856
- ds.where{n4 > v}
857
- end
858
- end
859
- end
860
-
861
- Artist.create(:n0=>'1', :n1=>'2', :n2=>'3', :n3=>'7', :n4=>'5')
862
- Artist.create(:n0=>'2', :n1=>'2', :n2=>'1', :n3=>'3', :n4=>'4')
863
- Artist.create(:n0=>'0', :n1=>'4', :n2=>'1', :n3=>'5', :n4=>'3')
864
-
865
- visit("/Artist/show?f=3")
866
- page.all('option').map{|s| s.text}.must_equal ['', '0']
867
-
868
- visit("/Artist/edit?f=1")
869
- page.all('option').map{|s| s.text}.must_equal ['', '2']
870
-
871
- visit("/Artist/delete?f=2")
872
- page.all('option').map{|s| s.text}.must_equal ['', '1']
873
-
874
- visit("/Artist/search/1?f=4")
875
- page.all('tr td:first-child').map{|s| s.text}.must_equal %w'1'
876
-
877
- visit("/Artist/browse?f=6")
878
- page.all('tr td:first-child').map{|s| s.text}.must_equal %w'1'
879
- end
880
-
881
- it "should support specifying filter per type using request session" do
882
- app_setup(Artist) do
883
- filter{|ds, type, req| ds.where(:n1=>req.session['n1'])}
884
- order :n2
885
- end
886
-
887
- Artist.create(:n0=>'1', :n1=>'2', :n2=>'3', :n3=>'7', :n4=>'5')
888
- Artist.create(:n0=>'2', :n1=>'2', :n2=>'1', :n3=>'3', :n4=>'4')
889
- Artist.create(:n0=>'0', :n1=>'4', :n2=>'1', :n3=>'5', :n4=>'3')
890
- visit '/session/set?n1=2'
891
-
892
- visit("/Artist/show")
893
- page.all('option').map{|s| s.text}.must_equal ['', '2', '1']
894
-
895
- click_link 'Edit'
896
- page.all('option').map{|s| s.text}.must_equal ['', '2', '1']
897
- select '2'
898
- click_button 'Edit'
899
- click_button 'Update'
900
-
901
- click_link 'Delete'
902
- page.all('option').map{|s| s.text}.must_equal ['', '2', '1']
903
- select '1'
904
- click_button 'Delete'
905
- click_button 'Delete'
906
- Artist.create(:n0=>'1', :n1=>'2', :n2=>'3', :n3=>'7', :n4=>'5')
907
-
908
- click_link 'Search'
909
- click_button 'Search'
910
- page.all('tr td:first-child').map{|s| s.text}.must_equal %w'2 1'
911
-
912
- click_link 'Artist'
913
- page.all('tr td:first-child').map{|s| s.text}.must_equal %w'2 1'
914
- end
915
-
916
- it "should support session_value for restricting access by matching session variable to column value" do
917
- app_setup(Artist) do
918
- session_value :n1
919
- columns [:n0, :n2]
920
- order :n2
921
- end
922
-
923
- Artist.create(:n0=>'0', :n1=>'4', :n2=>'1')
924
- visit '/session/set?n1=2'
925
-
926
- visit("/Artist/new")
927
- fill_in 'N0', :with=>'1'
928
- fill_in 'N2', :with=>'3'
929
- click_button 'Create'
930
- fill_in 'N0', :with=>'2'
931
- fill_in 'N2', :with=>'1'
932
- click_button 'Create'
933
-
934
- click_link 'Show'
935
- page.all('option').map{|s| s.text}.must_equal ['', '2', '1']
936
-
937
- click_link 'Edit'
938
- page.all('option').map{|s| s.text}.must_equal ['', '2', '1']
939
- select '2'
940
- click_button 'Edit'
941
- click_button 'Update'
942
-
943
- click_link 'Search'
944
- click_button 'Search'
945
- page.all('tr td:first-child').map{|s| s.text}.must_equal %w'2 1'
946
-
947
- click_link 'Artist'
948
- page.all('tr td:first-child').map{|s| s.text}.must_equal %w'2 1'
949
-
950
- click_link 'Delete', :match=>:first
951
- page.all('option').map{|s| s.text}.must_equal ['', '2', '1']
952
- select '1'
953
- click_button 'Delete'
954
- end
955
- end
956
-
957
- describe AutoForme do
958
- before(:all) do
959
- db_setup(:artists=>[[:num, :decimal]])
960
- model_setup(:Artist=>[:artists])
961
- end
962
- after(:all) do
963
- Object.send(:remove_const, :Artist)
964
- end
965
- before do
966
- app_setup(Artist)
967
- visit("/Artist/new")
968
- page.title.must_equal 'Artist - New'
969
- fill_in 'Num', :with=>'1.01'
970
- click_button 'Create'
971
- visit("/Artist/browse")
972
- end
973
-
974
- it "should display decimals in float format in tables" do
975
- click_link 'Artist'
976
- page.all('tr td:first-child').map{|s| s.text}.must_equal %w'1.01'
977
- click_link 'Search'
978
- click_button 'Search'
979
- page.all('tr td:first-child').map{|s| s.text}.must_equal %w'1.01'
980
- end
981
-
982
- it "should treat invalid search fields as returning no results" do
983
- click_link 'Search'
984
- fill_in 'Num', :with=>'3/3/2020'
985
- click_button 'Search'
986
- page.all('tr td:first-child').map{|s| s.text}.must_equal []
987
- end
988
- end
989
-
990
- describe AutoForme do
991
- before(:all) do
992
- db_setup(:artists=>[[:name, :string]])
993
- model_setup(:Artist=>[:artists])
994
- end
995
- after(:all) do
996
- Object.send(:remove_const, :Artist)
997
- end
998
-
999
- it "should have basic functionality working when reloading code" do
1000
- app_setup do
1001
- register_by_name
1002
- model Artist
1003
- end
1004
- artist_class = Artist
1005
- Object.send(:remove_const, :Artist)
1006
- ::Artist = Class.new(artist_class) do
1007
- def name
1008
- "-#{super}-"
1009
- end
1010
- def forme_name
1011
- "[#{name}]"
1012
- end
1013
- end
1014
- visit("/Artist/new")
1015
- page.title.must_equal 'Artist - New'
1016
- fill_in 'Name', :with=>'TestArtistNew'
1017
- click_button 'Create'
1018
- page.html.must_include 'Created Artist'
1019
- page.current_path.must_equal '/Artist/new'
1020
-
1021
- click_link 'Show'
1022
- page.title.must_equal 'Artist - Show'
1023
- select '[-TestArtistNew-]'
1024
- click_button 'Show'
1025
- page.html.must_match(/Name.+-TestArtistNew-/m)
1026
-
1027
- click_link 'Edit'
1028
- page.title.must_equal 'Artist - Edit'
1029
- select '[-TestArtistNew-]'
1030
- click_button 'Edit'
1031
- fill_in 'Name', :with=>'TestArtistUpdate'
1032
- click_button 'Update'
1033
- page.html.must_include 'Updated Artist'
1034
- page.html.must_match(/Name.+-TestArtistUpdate-/m)
1035
- page.current_path.must_match %r{/Artist/edit/\d+}
1036
-
1037
- click_link 'Search'
1038
- page.title.must_equal 'Artist - Search'
1039
- fill_in 'Name', :with=>'Upd'
1040
- click_button 'Search'
1041
- page.all('th').map{|s| s.text}.must_equal ['Name', 'Show', 'Edit', 'Delete']
1042
- page.all('td').map{|s| s.text}.must_equal ["-TestArtistUpdate-", "Show", "Edit", "Delete"]
1043
-
1044
- click_link 'Search'
1045
- fill_in 'Name', :with=>'Foo'
1046
- click_button 'Search'
1047
- page.all('td').map{|s| s.text}.must_equal []
1048
-
1049
- click_link 'Artist'
1050
- page.title.must_equal 'Artist - Browse'
1051
- page.all('td').map{|s| s.text}.must_equal ["-TestArtistUpdate-", "Show", "Edit", "Delete"]
1052
-
1053
- page.all('td').last.find('a').click
1054
- click_button 'Delete'
1055
- page.html.must_include 'Deleted Artist'
1056
- page.current_path.must_equal '/Artist/delete'
1057
-
1058
- click_link 'Artist'
1059
- page.all('td').map{|s| s.text}.must_equal []
1060
- end
1061
- end
1062
-
1063
- describe AutoForme do
1064
- before(:all) do
1065
- db_setup(:artists=>[[:name, :string], [:i, :integer]])
1066
- model_setup(:Artist=>[:artists])
1067
- end
1068
- after(:all) do
1069
- Object.send(:remove_const, :Artist)
1070
- end
1071
-
1072
- it "should have basic functionality working" do
1073
- app_setup(Artist)
1074
- visit("/Artist/new")
1075
- page.title.must_equal 'Artist - New'
1076
- fill_in 'Name', :with=>'TestArtistNew'
1077
- fill_in 'I', :with=>'3'
1078
- click_button 'Create'
1079
-
1080
- click_link 'Search'
1081
- fill_in 'I', :with=>'2'
1082
- click_button 'Search'
1083
- page.all('th').map{|s| s.text}.must_equal ['I', 'Name', 'Show', 'Edit', 'Delete']
1084
- page.all('td').map{|s| s.text}.must_equal []
1085
-
1086
- click_link 'Search'
1087
- fill_in 'I', :with=>'3'
1088
- click_button 'Search'
1089
- page.all('th').map{|s| s.text}.must_equal ['I', 'Name', 'Show', 'Edit', 'Delete']
1090
- page.all('td').map{|s| s.text}.must_equal ["3", "TestArtistNew", "Show", "Edit", "Delete"]
1091
- end
1092
- end
1093
-
1094
- describe AutoForme do
1095
- before(:all) do
1096
- db_setup(:artists=>[])
1097
- model_setup(:Artist=>[:artists])
1098
- end
1099
- after(:all) do
1100
- Object.send(:remove_const, :Artist)
1101
- end
1102
-
1103
- it "should have basic functionality working with no columns" do
1104
- app_setup(Artist)
1105
- visit("/Artist/new")
1106
- page.title.must_equal 'Artist - New'
1107
- click_button 'Create'
1108
- page.html.must_include 'Created Artist'
1109
- page.current_path.must_equal '/Artist/new'
1110
- id = Artist.first.id.to_s
1111
-
1112
- click_link 'Show'
1113
- page.title.must_equal 'Artist - Show'
1114
- click_button 'Show'
1115
- select id
1116
- click_button 'Show'
1117
-
1118
- click_link 'Edit'
1119
- page.title.must_equal 'Artist - Edit'
1120
- click_button 'Edit'
1121
- select id
1122
- click_button 'Edit'
1123
- click_button 'Update'
1124
- page.html.must_include 'Updated Artist'
1125
- page.current_path.must_equal "/Artist/edit/#{id}"
1126
-
1127
- click_link 'Artist'
1128
- page.title.must_equal 'Artist - Browse'
1129
- page.all('td').map{|s| s.text}.must_equal ["Show", "Edit", "Delete"]
1130
- click_link 'CSV Format'
1131
- page.body.must_equal "\n\n"
1132
-
1133
- visit("/Artist/browse")
1134
- page.all('td').last.find('a').click
1135
- click_button 'Delete'
1136
- page.title.must_equal 'Artist - Delete'
1137
- page.html.must_include 'Deleted Artist'
1138
- page.current_path.must_equal '/Artist/delete'
1139
-
1140
- click_link 'Artist'
1141
- page.all('td').map{|s| s.text}.must_equal []
1142
- end
1143
- end
1144
-
1145
- describe AutoForme do
1146
- before(:all) do
1147
- db_setup(:artists=>[[:name, :string]])
1148
- Namespace = Module.new
1149
-
1150
- class Namespace::Artist < Sequel::Model(db[:artists])
1151
- def forme_namespace
1152
- "artist"
1153
- end
1154
- end
1155
- end
1156
- after(:all) do
1157
- Object.send(:remove_const, :Namespace)
1158
- end
1159
-
1160
- it "respects the forme_namespace method on the model" do
1161
- app_setup(Namespace::Artist)
1162
- visit("/Namespace::Artist/new")
1163
- fill_in 'Name', :with=>'TestArtistNew'
1164
- click_button 'Create'
1165
- page.html.must_include 'Created Namespace::Artist'
1166
- page.current_path.must_equal '/Namespace::Artist/new'
1167
- end
1168
- end