autoforme 1.9.1 → 1.12.0

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