autoforme 1.4.0 → 1.5.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 CHANGED
@@ -15,7 +15,7 @@ describe AutoForme do
15
15
  page.title.must_equal 'Artist - New'
16
16
  fill_in 'Name', :with=>'TestArtistNew'
17
17
  click_button 'Create'
18
- page.html.must_match /Created Artist/
18
+ page.html.must_include 'Created Artist'
19
19
  page.current_path.must_equal '/Artist/new'
20
20
 
21
21
  click_link 'Show'
@@ -23,7 +23,7 @@ describe AutoForme do
23
23
  click_button 'Show'
24
24
  select 'TestArtistNew'
25
25
  click_button 'Show'
26
- page.html.must_match /Name.+TestArtistNew/m
26
+ page.html.must_match(/Name.+TestArtistNew/m)
27
27
 
28
28
  click_link 'Edit'
29
29
  page.title.must_equal 'Artist - Edit'
@@ -32,8 +32,8 @@ describe AutoForme do
32
32
  click_button 'Edit'
33
33
  fill_in 'Name', :with=>'TestArtistUpdate'
34
34
  click_button 'Update'
35
- page.html.must_match /Updated Artist/
36
- page.html.must_match /Name.+TestArtistUpdate/m
35
+ page.html.must_include 'Updated Artist'
36
+ page.html.must_match(/Name.+TestArtistUpdate/m)
37
37
  page.current_path.must_match %r{/Artist/edit/\d+}
38
38
 
39
39
  click_link 'Search'
@@ -58,11 +58,14 @@ describe AutoForme do
58
58
  click_link 'CSV Format'
59
59
  page.body.must_equal "Name\nTestArtistUpdate\n"
60
60
 
61
+ visit("/Artist/destroy/#{Artist.first.id}")
62
+ page.html.must_include 'Unhandled Request'
63
+
61
64
  visit("/Artist/browse")
62
65
  page.all('td').last.find('a').click
63
66
  click_button 'Delete'
64
67
  page.title.must_equal 'Artist - Delete'
65
- page.html.must_match /Deleted Artist/
68
+ page.html.must_include 'Deleted Artist'
66
69
  page.current_path.must_equal '/Artist/delete'
67
70
 
68
71
  click_link 'Artist'
@@ -74,21 +77,21 @@ describe AutoForme do
74
77
  visit("/prefix/Artist/new")
75
78
  fill_in 'Name', :with=>'TestArtistNew'
76
79
  click_button 'Create'
77
- page.html.must_match /Created Artist/
80
+ page.html.must_include 'Created Artist'
78
81
  page.current_path.must_equal '/prefix/Artist/new'
79
82
 
80
83
  click_link 'Show'
81
84
  select 'TestArtistNew'
82
85
  click_button 'Show'
83
- page.html.must_match /Name.+TestArtistNew/m
86
+ page.html.must_match(/Name.+TestArtistNew/m)
84
87
 
85
88
  click_link 'Edit'
86
89
  select 'TestArtistNew'
87
90
  click_button 'Edit'
88
91
  fill_in 'Name', :with=>'TestArtistUpdate'
89
92
  click_button 'Update'
90
- page.html.must_match /Updated Artist/
91
- page.html.must_match /Name.+TestArtistUpdate/m
93
+ page.html.must_include 'Updated Artist'
94
+ page.html.must_match(/Name.+TestArtistUpdate/m)
92
95
  page.current_path.must_match %r{/prefix/Artist/edit/\d+}
93
96
 
94
97
  click_link 'Search'
@@ -107,13 +110,80 @@ describe AutoForme do
107
110
 
108
111
  page.all('td').last.find('a').click
109
112
  click_button 'Delete'
110
- page.html.must_match /Deleted Artist/
113
+ page.html.must_include 'Deleted Artist'
111
114
  page.current_path.must_equal '/prefix/Artist/delete'
112
115
 
113
116
  click_link 'Artist'
114
117
  page.all('td').map{|s| s.text}.must_equal []
115
118
  end
116
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
+
117
187
  it "should have delete button on edit page" do
118
188
  app_setup(Artist)
119
189
  visit("/Artist/new")
@@ -135,7 +205,7 @@ describe AutoForme do
135
205
  page_footer "<a href='/Artist/edit'>E</a>"
136
206
  end
137
207
  visit("/Artist/browse")
138
- page.html.wont_match /search/
208
+ page.html.wont_include 'search'
139
209
  click_link 'N'
140
210
  fill_in 'Name', :with=>'TestArtistNew'
141
211
  click_button 'Create'
@@ -212,11 +282,11 @@ describe AutoForme do
212
282
  click_link 'Show'
213
283
  select 'TestArtistNew'
214
284
  click_button 'Show'
215
- page.html.must_match /Show Artist Name.+TestArtistNew/m
285
+ page.html.must_match(/Show Artist Name.+TestArtistNew/m)
216
286
  click_button 'Edit'
217
287
  fill_in 'Edit Artist Name', :with=>'TestArtistUpdate'
218
288
  click_button 'Update'
219
- page.html.must_match /Edit Artist Name.+TestArtistUpdate/m
289
+ page.html.must_match(/Edit Artist Name.+TestArtistUpdate/m)
220
290
  page.current_path.must_match %r{/Artist/edit/\d+}
221
291
 
222
292
  click_link 'Search'
@@ -245,12 +315,12 @@ describe AutoForme do
245
315
  visit("/Artist/show")
246
316
  select 'stArtistN'
247
317
  click_button 'Show'
248
- page.html.must_match /Name.+TestArtistNew/m
318
+ page.html.must_match(/Name.+TestArtistNew/m)
249
319
 
250
320
  click_link 'Edit'
251
321
  select 'estArtistNe'
252
322
  click_button 'Edit'
253
- page.html.must_match /Name.+TestArtistNew/m
323
+ page.html.must_match(/Name.+TestArtistNew/m)
254
324
 
255
325
  click_link 'Delete'
256
326
  select 'Artist'
@@ -291,7 +361,7 @@ describe AutoForme do
291
361
  click_link 'Edit'
292
362
  select 'weNtsitrAtseT'
293
363
  click_button 'Edit'
294
- page.html.must_match /weNtsitrAtseT21/
364
+ page.html.must_include 'weNtsitrAtseT21'
295
365
  click_button 'Update'
296
366
  a.must_equal [:edit, :edit, :update, -2, 'update', 2, :edit]
297
367
  a.clear
@@ -368,15 +438,15 @@ describe AutoForme do
368
438
  fill_in 'Name', :with=>'TestArtistNew'
369
439
  click_button 'Create'
370
440
  page.current_path.must_equal '/Artist/new'
371
- page.html.wont_match /Show/
372
- page.html.wont_match /Delete/
441
+ page.html.wont_include 'Show'
442
+ page.html.wont_include 'Delete'
373
443
 
374
444
  click_link 'Edit'
375
445
  select 'TestArtistNew'
376
446
  click_button 'Edit'
377
447
  fill_in 'Name', :with=>'TestArtistUpdate'
378
448
  click_button 'Update'
379
- page.html.must_match /Name.+TestArtistUpdate/m
449
+ page.html.must_match(/Name.+TestArtistUpdate/m)
380
450
  page.current_path.must_match %r{/Artist/edit/\d+}
381
451
 
382
452
  click_link 'Search'
@@ -388,7 +458,7 @@ describe AutoForme do
388
458
  page.all('td').map{|s| s.text}.must_equal ["TestArtistUpdate", "Edit"]
389
459
  end
390
460
 
391
- it "should have basic functionality working" do
461
+ it "should have working link_name and class_display_name" do
392
462
  app_setup(Artist) do
393
463
  class_display_name "FooArtist"
394
464
  link_name "BarArtist"
@@ -396,7 +466,7 @@ describe AutoForme do
396
466
  visit("/BarArtist/new")
397
467
  fill_in 'Name', :with=>'TestArtistNew'
398
468
  click_button 'Create'
399
- page.html.must_match /Created FooArtist/
469
+ page.html.must_include 'Created FooArtist'
400
470
  page.current_path.must_equal '/BarArtist/new'
401
471
 
402
472
  click_link 'Edit'
@@ -404,14 +474,14 @@ describe AutoForme do
404
474
  click_button 'Edit'
405
475
  fill_in 'Name', :with=>'TestArtistUpdate'
406
476
  click_button 'Update'
407
- page.html.must_match /Updated FooArtist/
477
+ page.html.must_include 'Updated FooArtist'
408
478
 
409
479
  click_link 'FooArtist'
410
480
  page.all('td').map{|s| s.text}.must_equal ["TestArtistUpdate", "Show", "Edit", "Delete"]
411
481
 
412
482
  page.all('td').last.find('a').click
413
483
  click_button 'Delete'
414
- page.html.must_match /Deleted FooArtist/
484
+ page.html.must_include 'Deleted FooArtist'
415
485
  end
416
486
 
417
487
  it "should use text boxes on list page when autocompleting is enabled" do
@@ -423,7 +493,7 @@ describe AutoForme do
423
493
  visit('/Artist/show')
424
494
  fill_in 'Artist', :with=>a.id.to_s
425
495
  click_button 'Show'
426
- page.html.must_match /Name.+TestArtistNew/m
496
+ page.html.must_match(/Name.+TestArtistNew/m)
427
497
 
428
498
  click_link 'Edit'
429
499
  fill_in 'Artist', :with=>a.id.to_s
@@ -450,14 +520,14 @@ describe AutoForme do
450
520
  page.title.must_equal 'Artist - New'
451
521
  fill_in 'namenew', :with=>'TAN'
452
522
  click_button 'Create'
453
- page.html.must_match /Created Artist/
523
+ page.html.must_include 'Created Artist'
454
524
  page.current_path.must_equal '/Artist/new'
455
525
 
456
526
  click_link 'Show'
457
527
  page.title.must_equal 'Artist - Show'
458
528
  select 'TAN'
459
529
  click_button 'Show'
460
- page.html.must_match /nameshow-TANTAN/
530
+ page.html.must_include 'nameshow-TANTAN'
461
531
 
462
532
  click_link 'Edit'
463
533
  page.title.must_equal 'Artist - Edit'
@@ -465,8 +535,8 @@ describe AutoForme do
465
535
  click_button 'Edit'
466
536
  fill_in 'nameedit', :with=>'TAU'
467
537
  click_button 'Update'
468
- page.html.must_match /Updated Artist/
469
- page.html.must_match /nameedit.+TAUTAU/m
538
+ page.html.must_include 'Updated Artist'
539
+ page.html.must_match(/nameedit.+TAUTAU/m)
470
540
  page.current_path.must_match %r{/Artist/edit/\d+}
471
541
 
472
542
  click_link 'Search'
@@ -493,15 +563,48 @@ describe AutoForme do
493
563
 
494
564
  visit("/Artist/browse")
495
565
  page.all('td').last.find('a').click
496
- page.html.must_match /namedelete-TAUTAU/
566
+ page.html.must_include 'namedelete-TAUTAU'
497
567
  click_button 'Delete'
498
568
  page.title.must_equal 'Artist - Delete'
499
- page.html.must_match /Deleted Artist/
569
+ page.html.must_include 'Deleted Artist'
500
570
  page.current_path.must_equal '/Artist/delete'
501
571
 
502
572
  click_link 'Artist'
503
573
  page.all('td').map{|s| s.text}.must_equal []
504
574
  end
575
+
576
+ it "should correct 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.html.must_include 'Error Creating Artist'
587
+ page.html.must_include 'bad name'
588
+ fill_in 'Name', :with=>'TestArtistNew'
589
+ click_button 'Create'
590
+ page.html.must_include 'Created Artist'
591
+ page.current_path.must_equal '/Artist/new'
592
+
593
+ click_link 'Edit'
594
+ page.title.must_equal 'Artist - Edit'
595
+ click_button 'Edit'
596
+ select 'TestArtistNew'
597
+ click_button 'Edit'
598
+ fill_in 'Name', :with=>'Foo'
599
+ click_button 'Update'
600
+ page.html.must_include 'Error Updating Artist'
601
+ page.html.must_include 'bad name'
602
+ fill_in 'Name', :with=>'TestArtistUpdate'
603
+ click_button 'Update'
604
+ page.html.must_include 'Updated Artist'
605
+ page.html.must_match(/Name.+TestArtistUpdate/m)
606
+ page.current_path.must_match %r{/Artist/edit/\d+}
607
+ end
505
608
  end
506
609
 
507
610
  describe AutoForme do
@@ -531,18 +634,18 @@ describe AutoForme do
531
634
  fill_in 'N2', :with=>'V2'
532
635
  fill_in 'N3', :with=>'V3'
533
636
  fill_in 'N4', :with=>'V4'
534
- page.body.wont_match /<label>N5/i
637
+ page.body.wont_match(/<label>N5/i)
535
638
  click_button 'Create'
536
639
 
537
640
  click_link 'Show'
538
641
  select 'V0'
539
642
  click_button 'Show'
540
- page.body.must_match /[VN]0/i
541
- page.body.must_match /[VN]1/i
542
- page.body.must_match /[VN]2/i
543
- page.body.wont_match /[VN]3/i
544
- page.body.must_match /[VN]4/i
545
- page.body.must_match /N5/i
643
+ page.body.must_match(/[VN]0/i)
644
+ page.body.must_match(/[VN]1/i)
645
+ page.body.must_match(/[VN]2/i)
646
+ page.body.wont_match(/[VN]3/i)
647
+ page.body.must_match(/[VN]4/i)
648
+ page.body.must_match(/N5/i)
546
649
 
547
650
  click_link 'Edit'
548
651
  select 'V0'
@@ -551,13 +654,13 @@ describe AutoForme do
551
654
  fill_in 'N1', :with=>'Q1'
552
655
  fill_in 'N2', :with=>'Q2'
553
656
  fill_in 'N3', :with=>'Q3'
554
- page.body.wont_match /<label>N4/i
657
+ page.body.wont_match(/<label>N4/i)
555
658
  fill_in 'N5', :with=>'Q5'
556
659
  click_button 'Update'
557
660
 
558
661
  click_link 'Search'
559
662
  fill_in 'N0', :with=>'Q0'
560
- page.body.wont_match /<label>N1/i
663
+ page.body.wont_match(/<label>N1/i)
561
664
  fill_in 'N2', :with=>'Q2'
562
665
  fill_in 'N3', :with=>'Q3'
563
666
  fill_in 'N4', :with=>'V4'
@@ -812,14 +915,14 @@ describe AutoForme do
812
915
  page.title.must_equal 'Artist - New'
813
916
  fill_in 'Name', :with=>'TestArtistNew'
814
917
  click_button 'Create'
815
- page.html.must_match /Created Artist/
918
+ page.html.must_include 'Created Artist'
816
919
  page.current_path.must_equal '/Artist/new'
817
920
 
818
921
  click_link 'Show'
819
922
  page.title.must_equal 'Artist - Show'
820
923
  select '[-TestArtistNew-]'
821
924
  click_button 'Show'
822
- page.html.must_match /Name.+-TestArtistNew-/m
925
+ page.html.must_match(/Name.+-TestArtistNew-/m)
823
926
 
824
927
  click_link 'Edit'
825
928
  page.title.must_equal 'Artist - Edit'
@@ -827,8 +930,8 @@ describe AutoForme do
827
930
  click_button 'Edit'
828
931
  fill_in 'Name', :with=>'TestArtistUpdate'
829
932
  click_button 'Update'
830
- page.html.must_match /Updated Artist/
831
- page.html.must_match /Name.+-TestArtistUpdate-/m
933
+ page.html.must_include 'Updated Artist'
934
+ page.html.must_match(/Name.+-TestArtistUpdate-/m)
832
935
  page.current_path.must_match %r{/Artist/edit/\d+}
833
936
 
834
937
  click_link 'Search'
@@ -849,7 +952,89 @@ describe AutoForme do
849
952
 
850
953
  page.all('td').last.find('a').click
851
954
  click_button 'Delete'
852
- page.html.must_match /Deleted Artist/
955
+ page.html.must_include 'Deleted Artist'
956
+ page.current_path.must_equal '/Artist/delete'
957
+
958
+ click_link 'Artist'
959
+ page.all('td').map{|s| s.text}.must_equal []
960
+ end
961
+ end
962
+
963
+ describe AutoForme do
964
+ before(:all) do
965
+ db_setup(:artists=>[[:name, :string], [:i, :integer]])
966
+ model_setup(:Artist=>[:artists])
967
+ end
968
+ after(:all) do
969
+ Object.send(:remove_const, :Artist)
970
+ end
971
+
972
+ it "should have basic functionality working" do
973
+ app_setup(Artist)
974
+ visit("/Artist/new")
975
+ page.title.must_equal 'Artist - New'
976
+ fill_in 'Name', :with=>'TestArtistNew'
977
+ fill_in 'I', :with=>'3'
978
+ click_button 'Create'
979
+
980
+ click_link 'Search'
981
+ fill_in 'I', :with=>'2'
982
+ click_button 'Search'
983
+ page.all('th').map{|s| s.text}.must_equal ['I', 'Name', 'Show', 'Edit', 'Delete']
984
+ page.all('td').map{|s| s.text}.must_equal []
985
+
986
+ click_link 'Search'
987
+ fill_in 'I', :with=>'3'
988
+ click_button 'Search'
989
+ page.all('th').map{|s| s.text}.must_equal ['I', 'Name', 'Show', 'Edit', 'Delete']
990
+ page.all('td').map{|s| s.text}.must_equal ["3", "TestArtistNew", "Show", "Edit", "Delete"]
991
+ end
992
+ end
993
+
994
+ describe AutoForme do
995
+ before(:all) do
996
+ db_setup(:artists=>[])
997
+ model_setup(:Artist=>[:artists])
998
+ end
999
+ after(:all) do
1000
+ Object.send(:remove_const, :Artist)
1001
+ end
1002
+
1003
+ it "should have basic functionality working with no columns" do
1004
+ app_setup(Artist)
1005
+ visit("/Artist/new")
1006
+ page.title.must_equal 'Artist - New'
1007
+ click_button 'Create'
1008
+ page.html.must_include 'Created Artist'
1009
+ page.current_path.must_equal '/Artist/new'
1010
+ id = Artist.first.id.to_s
1011
+
1012
+ click_link 'Show'
1013
+ page.title.must_equal 'Artist - Show'
1014
+ click_button 'Show'
1015
+ select id
1016
+ click_button 'Show'
1017
+
1018
+ click_link 'Edit'
1019
+ page.title.must_equal 'Artist - Edit'
1020
+ click_button 'Edit'
1021
+ select id
1022
+ click_button 'Edit'
1023
+ click_button 'Update'
1024
+ page.html.must_include 'Updated Artist'
1025
+ page.current_path.must_equal "/Artist/edit/#{id}"
1026
+
1027
+ click_link 'Artist'
1028
+ page.title.must_equal 'Artist - Browse'
1029
+ page.all('td').map{|s| s.text}.must_equal ["Show", "Edit", "Delete"]
1030
+ click_link 'CSV Format'
1031
+ page.body.must_equal "\n\n"
1032
+
1033
+ visit("/Artist/browse")
1034
+ page.all('td').last.find('a').click
1035
+ click_button 'Delete'
1036
+ page.title.must_equal 'Artist - Delete'
1037
+ page.html.must_include 'Deleted Artist'
853
1038
  page.current_path.must_equal '/Artist/delete'
854
1039
 
855
1040
  click_link 'Artist'