autoforme 1.9.1 → 1.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +26 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +72 -12
- data/autoforme.js +97 -56
- data/lib/autoforme/action.rb +29 -24
- data/lib/autoforme/frameworks/rails.rb +10 -2
- data/lib/autoforme/frameworks/roda.rb +16 -5
- data/lib/autoforme/frameworks/sinatra.rb +9 -2
- data/lib/autoforme/model.rb +1 -1
- data/lib/autoforme/models/sequel.rb +36 -7
- data/lib/autoforme/version.rb +2 -2
- data/lib/autoforme.rb +7 -8
- data/lib/roda/plugins/autoforme.rb +1 -1
- metadata +26 -19
- data/Rakefile +0 -69
- data/spec/all.rb +0 -2
- data/spec/associations_spec.rb +0 -802
- data/spec/basic_spec.rb +0 -1150
- data/spec/mtm_spec.rb +0 -509
- data/spec/rails_spec_helper.rb +0 -78
- data/spec/roda_spec.rb +0 -72
- data/spec/roda_spec_helper.rb +0 -87
- data/spec/sequel_spec_helper.rb +0 -43
- data/spec/sinatra_spec_helper.rb +0 -55
- data/spec/spec_helper.rb +0 -79
- data/spec/unit_spec.rb +0 -511
data/spec/associations_spec.rb
DELETED
@@ -1,802 +0,0 @@
|
|
1
|
-
require './spec/spec_helper'
|
2
|
-
|
3
|
-
describe AutoForme do
|
4
|
-
before(:all) do
|
5
|
-
db_setup(:artists=>[[:name, :string]], :albums=>[[:name, :string], [:artist_id, :integer, {:table=>:artists}]])
|
6
|
-
model_setup(:Artist=>[:artists, [[:one_to_many, :albums]]], :Album=>[:albums, [[:many_to_one, :artist]]])
|
7
|
-
end
|
8
|
-
after(:all) do
|
9
|
-
Object.send(:remove_const, :Album)
|
10
|
-
Object.send(:remove_const, :Artist)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should have basic many to one associations working" do
|
14
|
-
app_setup do
|
15
|
-
model Artist
|
16
|
-
model Album do
|
17
|
-
columns [:name, :artist]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
visit("/Artist/new")
|
22
|
-
fill_in 'Name', :with=>'Artist1'
|
23
|
-
click_button 'Create'
|
24
|
-
fill_in 'Name', :with=>'Artist2'
|
25
|
-
click_button 'Create'
|
26
|
-
|
27
|
-
visit("/Album/new")
|
28
|
-
fill_in 'Name', :with=>'Album1'
|
29
|
-
click_button 'Create'
|
30
|
-
|
31
|
-
click_link 'Edit'
|
32
|
-
select 'Album1'
|
33
|
-
click_button 'Edit'
|
34
|
-
fill_in 'Name', :with=>'Album1b'
|
35
|
-
select 'Artist2'
|
36
|
-
click_button 'Update'
|
37
|
-
|
38
|
-
click_link 'Show'
|
39
|
-
select 'Album1'
|
40
|
-
click_button 'Show'
|
41
|
-
page.html.must_match(/Name.+Album1b/m)
|
42
|
-
page.html.must_match(/Artist.+Artist2/m)
|
43
|
-
|
44
|
-
click_link 'Search'
|
45
|
-
fill_in 'Name', :with=>'1b'
|
46
|
-
select 'Artist2'
|
47
|
-
click_button 'Search'
|
48
|
-
page.all('td').map{|s| s.text}.must_equal ["Album1b", "Artist2", "Show", "Edit", "Delete"]
|
49
|
-
|
50
|
-
click_link 'Album'
|
51
|
-
page.all('td').map{|s| s.text}.must_equal ["Album1b", "Artist2", "Show", "Edit", "Delete"]
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should escape display names in association links" do
|
55
|
-
app_setup do
|
56
|
-
model Artist
|
57
|
-
model Album do
|
58
|
-
columns [:name, :artist]
|
59
|
-
end
|
60
|
-
association_links :all
|
61
|
-
end
|
62
|
-
|
63
|
-
visit("/Artist/new")
|
64
|
-
fill_in 'Name', :with=>'Art&"ist2'
|
65
|
-
click_button 'Create'
|
66
|
-
|
67
|
-
visit("/Album/new")
|
68
|
-
fill_in 'Name', :with=>'Album1'
|
69
|
-
select 'Art&"ist2'
|
70
|
-
click_button 'Create'
|
71
|
-
|
72
|
-
click_link 'Edit'
|
73
|
-
select 'Album1'
|
74
|
-
click_button 'Edit'
|
75
|
-
page.html.must_match(%r{- <a href="/Artist/edit/\d+">Art&"ist2})
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should escape display names in association links" do
|
79
|
-
app_setup do
|
80
|
-
model Album do
|
81
|
-
columns [:name, :artist]
|
82
|
-
end
|
83
|
-
association_links :all
|
84
|
-
end
|
85
|
-
|
86
|
-
Artist.create(:name=>'Art&"ist2')
|
87
|
-
visit("/Album/new")
|
88
|
-
fill_in 'Name', :with=>'Album1'
|
89
|
-
select 'Art&"ist2'
|
90
|
-
click_button 'Create'
|
91
|
-
|
92
|
-
click_link 'Edit'
|
93
|
-
select 'Album1'
|
94
|
-
click_button 'Edit'
|
95
|
-
page.html.must_include("- Art&"ist2")
|
96
|
-
end
|
97
|
-
|
98
|
-
it "should use text boxes for associated objects on new/edit/search forms if associated model uses autocompleting" do
|
99
|
-
app_setup do
|
100
|
-
model Artist do
|
101
|
-
autocomplete_options({})
|
102
|
-
end
|
103
|
-
model Album do
|
104
|
-
columns [:name, :artist]
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
a = Artist.create(:name=>'TestArtist')
|
109
|
-
b = Artist.create(:name=>'TestArtist2')
|
110
|
-
|
111
|
-
visit("/Album/new")
|
112
|
-
fill_in 'Name', :with=>'Album1'
|
113
|
-
fill_in 'Artist', :with=>a.id.to_s
|
114
|
-
click_button 'Create'
|
115
|
-
Album.first.artist_id.must_equal a.id
|
116
|
-
|
117
|
-
click_link 'Show'
|
118
|
-
select 'Album1'
|
119
|
-
click_button 'Show'
|
120
|
-
page.body.must_include 'TestArtist'
|
121
|
-
|
122
|
-
click_link 'Edit'
|
123
|
-
select 'Album1'
|
124
|
-
click_button 'Edit'
|
125
|
-
fill_in 'Name', :with=>'Album1b'
|
126
|
-
fill_in 'Artist', :with=>b.id.to_s
|
127
|
-
click_button 'Update'
|
128
|
-
Album.first.artist_id.must_equal b.id
|
129
|
-
|
130
|
-
click_link 'Search'
|
131
|
-
fill_in 'Name', :with=>'1b'
|
132
|
-
fill_in 'Artist', :with=>b.id.to_s
|
133
|
-
click_button 'Search'
|
134
|
-
page.all('td').map{|s| s.text}.must_equal ["Album1b", "TestArtist2", "Show", "Edit", "Delete"]
|
135
|
-
|
136
|
-
visit '/Artist/autocomplete?q=Test'
|
137
|
-
page.body.must_match(/\d+ - TestArtist\n\d+ - TestArtist2/m)
|
138
|
-
|
139
|
-
visit '/Album/autocomplete/artist?q=Test'
|
140
|
-
page.body.must_match(/\d+ - TestArtist\n\d+ - TestArtist2/m)
|
141
|
-
|
142
|
-
visit '/Album/autocomplete/artist?type=edit&q=Test'
|
143
|
-
page.body.must_match(/\d+ - TestArtist\n\d+ - TestArtist2/m)
|
144
|
-
end
|
145
|
-
|
146
|
-
it "should be able to used specified name formatting in other model" do
|
147
|
-
app_setup do
|
148
|
-
model Artist do
|
149
|
-
display_name{|obj| obj.name * 2}
|
150
|
-
end
|
151
|
-
model Album do
|
152
|
-
columns [:name, :artist]
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
visit("/Artist/new")
|
157
|
-
fill_in 'Name', :with=>'A1'
|
158
|
-
click_button 'Create'
|
159
|
-
fill_in 'Name', :with=>'A2'
|
160
|
-
click_button 'Create'
|
161
|
-
|
162
|
-
visit("/Album/new")
|
163
|
-
fill_in 'Name', :with=>'Album1'
|
164
|
-
select 'A1A1'
|
165
|
-
click_button 'Create'
|
166
|
-
|
167
|
-
click_link 'Show'
|
168
|
-
select 'Album1'
|
169
|
-
click_button 'Show'
|
170
|
-
page.html.must_match(/Name.+Album1/m)
|
171
|
-
page.html.must_match(/Artist.+A1A1/m)
|
172
|
-
|
173
|
-
click_link 'Edit'
|
174
|
-
select 'Album1'
|
175
|
-
click_button 'Edit'
|
176
|
-
fill_in 'Name', :with=>'Album1b'
|
177
|
-
select 'A2A2'
|
178
|
-
click_button 'Update'
|
179
|
-
|
180
|
-
click_link 'Search'
|
181
|
-
fill_in 'Name', :with=>'1b'
|
182
|
-
select 'A2A2'
|
183
|
-
click_button 'Search'
|
184
|
-
page.all('td').map{|s| s.text}.must_equal ["Album1b", "A2A2", "Show", "Edit", "Delete"]
|
185
|
-
|
186
|
-
click_link 'Album'
|
187
|
-
page.all('td').map{|s| s.text}.must_equal ["Album1b", "A2A2", "Show", "Edit", "Delete"]
|
188
|
-
end
|
189
|
-
|
190
|
-
it "should be able to used specified name formatting for current association" do
|
191
|
-
app_setup do
|
192
|
-
model Artist
|
193
|
-
model Album do
|
194
|
-
columns [:name, :artist]
|
195
|
-
column_options :artist=>{:name_method=>lambda{|obj| obj.name * 2}}
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
visit("/Artist/new")
|
200
|
-
fill_in 'Name', :with=>'A1'
|
201
|
-
click_button 'Create'
|
202
|
-
fill_in 'Name', :with=>'A2'
|
203
|
-
click_button 'Create'
|
204
|
-
|
205
|
-
visit("/Album/new")
|
206
|
-
fill_in 'Name', :with=>'Album1'
|
207
|
-
select 'A1A1'
|
208
|
-
click_button 'Create'
|
209
|
-
|
210
|
-
click_link 'Show'
|
211
|
-
select 'Album1'
|
212
|
-
click_button 'Show'
|
213
|
-
page.html.must_match(/Name.+Album1/m)
|
214
|
-
page.html.must_match(/Artist.+A1A1/m)
|
215
|
-
|
216
|
-
click_link 'Edit'
|
217
|
-
select 'Album1'
|
218
|
-
click_button 'Edit'
|
219
|
-
fill_in 'Name', :with=>'Album1b'
|
220
|
-
select 'A2A2'
|
221
|
-
click_button 'Update'
|
222
|
-
|
223
|
-
click_link 'Search'
|
224
|
-
fill_in 'Name', :with=>'1b'
|
225
|
-
select 'A2A2'
|
226
|
-
click_button 'Search'
|
227
|
-
page.all('td').map{|s| s.text}.must_equal ["Album1b", "A2A2", "Show", "Edit", "Delete"]
|
228
|
-
|
229
|
-
click_link 'Album'
|
230
|
-
page.all('td').map{|s| s.text}.must_equal ["Album1b", "A2A2", "Show", "Edit", "Delete"]
|
231
|
-
end
|
232
|
-
|
233
|
-
it "should be able to used specified name formatting for current association" do
|
234
|
-
app_setup do
|
235
|
-
model Artist
|
236
|
-
model Album do
|
237
|
-
columns [:name, :artist]
|
238
|
-
column_options :artist=>{:name_method=>:name}
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
visit("/Artist/new")
|
243
|
-
fill_in 'Name', :with=>'A1'
|
244
|
-
click_button 'Create'
|
245
|
-
fill_in 'Name', :with=>'A2'
|
246
|
-
click_button 'Create'
|
247
|
-
|
248
|
-
visit("/Album/new")
|
249
|
-
fill_in 'Name', :with=>'Album1'
|
250
|
-
select 'A1'
|
251
|
-
click_button 'Create'
|
252
|
-
|
253
|
-
click_link 'Show'
|
254
|
-
select 'Album1'
|
255
|
-
click_button 'Show'
|
256
|
-
page.html.must_match(/Name.+Album1/m)
|
257
|
-
page.html.must_match(/Artist.+A1/m)
|
258
|
-
|
259
|
-
click_link 'Edit'
|
260
|
-
select 'Album1'
|
261
|
-
click_button 'Edit'
|
262
|
-
fill_in 'Name', :with=>'Album1b'
|
263
|
-
select 'A2'
|
264
|
-
click_button 'Update'
|
265
|
-
|
266
|
-
click_link 'Search'
|
267
|
-
fill_in 'Name', :with=>'1b'
|
268
|
-
select 'A2'
|
269
|
-
click_button 'Search'
|
270
|
-
page.all('td').map{|s| s.text}.must_equal ["Album1b", "A2", "Show", "Edit", "Delete"]
|
271
|
-
|
272
|
-
click_link 'Album'
|
273
|
-
page.all('td').map{|s| s.text}.must_equal ["Album1b", "A2", "Show", "Edit", "Delete"]
|
274
|
-
end
|
275
|
-
|
276
|
-
it "should be able to eager load associations when loading model" do
|
277
|
-
app_setup do
|
278
|
-
model Artist
|
279
|
-
model Album do
|
280
|
-
columns [:name, :artist]
|
281
|
-
eager :artist
|
282
|
-
display_name{|obj| "#{obj.associations[:artist].name}-#{obj.name}"}
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
visit("/Artist/new")
|
287
|
-
fill_in 'Name', :with=>'A1'
|
288
|
-
click_button 'Create'
|
289
|
-
fill_in 'Name', :with=>'A2'
|
290
|
-
click_button 'Create'
|
291
|
-
|
292
|
-
visit("/Album/new")
|
293
|
-
fill_in 'Name', :with=>'Album1'
|
294
|
-
select 'A1'
|
295
|
-
click_button 'Create'
|
296
|
-
|
297
|
-
click_link 'Show'
|
298
|
-
select 'A1-Album1'
|
299
|
-
click_button 'Show'
|
300
|
-
page.html.must_match(/Name.+Album1/m)
|
301
|
-
page.html.must_match(/Artist.+A1/m)
|
302
|
-
|
303
|
-
click_link 'Edit'
|
304
|
-
select 'A1-Album1'
|
305
|
-
click_button 'Edit'
|
306
|
-
fill_in 'Name', :with=>'Album1b'
|
307
|
-
select 'A2'
|
308
|
-
click_button 'Update'
|
309
|
-
|
310
|
-
click_link 'Search'
|
311
|
-
fill_in 'Name', :with=>'1b'
|
312
|
-
select 'A2'
|
313
|
-
click_button 'Search'
|
314
|
-
page.all('td').map{|s| s.text}.must_equal ["Album1b", "A2", "Show", "Edit", "Delete"]
|
315
|
-
|
316
|
-
click_link 'Album'
|
317
|
-
page.all('td').map{|s| s.text}.must_equal ["Album1b", "A2", "Show", "Edit", "Delete"]
|
318
|
-
|
319
|
-
click_link 'Delete', :match=>:first
|
320
|
-
select 'A2-Album1b'
|
321
|
-
click_button 'Delete'
|
322
|
-
end
|
323
|
-
|
324
|
-
it "should be able to eager load associations when loading model without autoforme for associated model" do
|
325
|
-
app_setup do
|
326
|
-
model Album do
|
327
|
-
columns [:name, :artist]
|
328
|
-
eager :artist
|
329
|
-
display_name{|obj| "#{obj.associations[:artist].name}-#{obj.name}"}
|
330
|
-
end
|
331
|
-
end
|
332
|
-
|
333
|
-
Artist.create(:name=>'A1')
|
334
|
-
Artist.create(:name=>'A2')
|
335
|
-
|
336
|
-
visit("/Album/new")
|
337
|
-
fill_in 'Name', :with=>'Album1'
|
338
|
-
select 'A1'
|
339
|
-
click_button 'Create'
|
340
|
-
|
341
|
-
click_link 'Show'
|
342
|
-
select 'A1-Album1'
|
343
|
-
click_button 'Show'
|
344
|
-
page.html.must_match(/Name.+Album1/m)
|
345
|
-
page.html.must_match(/Artist.+A1/m)
|
346
|
-
|
347
|
-
click_link 'Edit'
|
348
|
-
select 'A1-Album1'
|
349
|
-
click_button 'Edit'
|
350
|
-
fill_in 'Name', :with=>'Album1b'
|
351
|
-
select 'A2'
|
352
|
-
click_button 'Update'
|
353
|
-
|
354
|
-
click_link 'Search'
|
355
|
-
fill_in 'Name', :with=>'1b'
|
356
|
-
select 'A2'
|
357
|
-
click_button 'Search'
|
358
|
-
page.all('td').map{|s| s.text}.must_equal ["Album1b", "A2", "Show", "Edit", "Delete"]
|
359
|
-
|
360
|
-
click_link 'Album'
|
361
|
-
page.all('td').map{|s| s.text}.must_equal ["Album1b", "A2", "Show", "Edit", "Delete"]
|
362
|
-
|
363
|
-
click_link 'Delete', :match=>:first
|
364
|
-
select 'A2-Album1b'
|
365
|
-
click_button 'Delete'
|
366
|
-
end
|
367
|
-
|
368
|
-
it "should handle case when setting many_to_one association for associated class that eagerly graphs" do
|
369
|
-
app_setup do
|
370
|
-
model Artist do
|
371
|
-
eager_graph :albums
|
372
|
-
end
|
373
|
-
model Album do
|
374
|
-
columns [:name, :artist]
|
375
|
-
eager_graph :artist
|
376
|
-
order{|type, req| type == :edit ? [Sequel[:albums][:name], Sequel[:artist][:name]] : [Sequel[:artist][:name], Sequel[:albums][:name]]}
|
377
|
-
display_name{|obj, type| type == :edit ? "#{obj.name} (#{obj.artist.name})" : "#{obj.artist.name}-#{obj.name}"}
|
378
|
-
end
|
379
|
-
end
|
380
|
-
|
381
|
-
visit("/Artist/new")
|
382
|
-
fill_in 'Name', :with=>'B'
|
383
|
-
click_button 'Create'
|
384
|
-
visit("/Album/new")
|
385
|
-
fill_in 'Name', :with=>'A'
|
386
|
-
select 'B'
|
387
|
-
click_button 'Create'
|
388
|
-
end
|
389
|
-
|
390
|
-
it "should be able to order on eager_graphed associations when loading model" do
|
391
|
-
app_setup do
|
392
|
-
model Artist
|
393
|
-
model Album do
|
394
|
-
columns [:name, :artist]
|
395
|
-
eager_graph :artist
|
396
|
-
order{|type, req| type == :edit ? [Sequel[:albums][:name], Sequel[:artist][:name]] : [Sequel[:artist][:name], Sequel[:albums][:name]]}
|
397
|
-
display_name{|obj, type| type == :edit ? "#{obj.name} (#{obj.artist.name})" : "#{obj.artist.name}-#{obj.name}"}
|
398
|
-
end
|
399
|
-
end
|
400
|
-
|
401
|
-
visit("/Artist/new")
|
402
|
-
fill_in 'Name', :with=>'B'
|
403
|
-
click_button 'Create'
|
404
|
-
fill_in 'Name', :with=>'A'
|
405
|
-
click_button 'Create'
|
406
|
-
|
407
|
-
visit("/Album/new")
|
408
|
-
fill_in 'Name', :with=>'Z'
|
409
|
-
select 'B'
|
410
|
-
click_button 'Create'
|
411
|
-
fill_in 'Name', :with=>'Y'
|
412
|
-
select 'A'
|
413
|
-
click_button 'Create'
|
414
|
-
fill_in 'Name', :with=>'X'
|
415
|
-
select 'B'
|
416
|
-
click_button 'Create'
|
417
|
-
|
418
|
-
click_link 'Show'
|
419
|
-
page.all('select option').map{|s| s.text}.must_equal ['', 'A-Y', 'B-X', 'B-Z']
|
420
|
-
select 'B-X'
|
421
|
-
click_button 'Show'
|
422
|
-
page.html.must_match(/Name.+X/m)
|
423
|
-
page.html.must_match(/Artist.+B/m)
|
424
|
-
|
425
|
-
click_link 'Edit'
|
426
|
-
page.all('select option').map{|s| s.text}.must_equal ['', 'X (B)', 'Y (A)', 'Z (B)']
|
427
|
-
select 'Z (B)'
|
428
|
-
click_button 'Edit'
|
429
|
-
fill_in 'Name', :with=>'ZZ'
|
430
|
-
select 'A'
|
431
|
-
click_button 'Update'
|
432
|
-
|
433
|
-
click_link 'Search'
|
434
|
-
select 'A'
|
435
|
-
click_button 'Search'
|
436
|
-
page.all('tr td:first-child').map{|s| s.text}.must_equal %w'Y ZZ'
|
437
|
-
|
438
|
-
click_link 'Album'
|
439
|
-
page.all('tr td:first-child').map{|s| s.text}.must_equal %w'Y ZZ X'
|
440
|
-
|
441
|
-
click_link 'Delete', :match=>:first
|
442
|
-
page.all('select option').map{|s| s.text}.must_equal ['', 'A-Y', 'A-ZZ', 'B-X']
|
443
|
-
select 'B-X'
|
444
|
-
click_button 'Delete'
|
445
|
-
end
|
446
|
-
|
447
|
-
it "should have many_to_one association lookup use order/eager/eager_graph/filter for associated model" do
|
448
|
-
app_setup do
|
449
|
-
model Artist do
|
450
|
-
order :name
|
451
|
-
eager :albums
|
452
|
-
filter{|ds, action| ds.where{name > 'M'}}
|
453
|
-
display_name{|obj| "#{obj.name} #{obj.albums.length}"}
|
454
|
-
end
|
455
|
-
model Album do
|
456
|
-
columns [:name, :artist]
|
457
|
-
order [:name]
|
458
|
-
end
|
459
|
-
end
|
460
|
-
|
461
|
-
visit("/Artist/new")
|
462
|
-
fill_in 'Name', :with=>'J'
|
463
|
-
click_button 'Create'
|
464
|
-
fill_in 'Name', :with=>'Z'
|
465
|
-
click_button 'Create'
|
466
|
-
fill_in 'Name', :with=>'Y'
|
467
|
-
click_button 'Create'
|
468
|
-
fill_in 'Name', :with=>'X'
|
469
|
-
click_button 'Create'
|
470
|
-
|
471
|
-
visit("/Album/new")
|
472
|
-
fill_in 'Name', :with=>'E'
|
473
|
-
page.all('select option').map{|s| s.text}.must_equal ['', 'X 0', 'Y 0', 'Z 0']
|
474
|
-
select 'X 0'
|
475
|
-
click_button 'Create'
|
476
|
-
fill_in 'Name', :with=>'D'
|
477
|
-
page.all('select option').map{|s| s.text}.must_equal ['', 'X 1', 'Y 0', 'Z 0']
|
478
|
-
select 'Y 0'
|
479
|
-
click_button 'Create'
|
480
|
-
fill_in 'Name', :with=>'C'
|
481
|
-
page.all('select option').map{|s| s.text}.must_equal ['', 'X 1', 'Y 1', 'Z 0']
|
482
|
-
select 'Y 1'
|
483
|
-
click_button 'Create'
|
484
|
-
|
485
|
-
click_link 'Show'
|
486
|
-
select 'D'
|
487
|
-
click_button 'Show'
|
488
|
-
page.html.must_match(/Name.+D/m)
|
489
|
-
page.html.must_match(/Artist.+Y 2/m)
|
490
|
-
|
491
|
-
click_link 'Edit'
|
492
|
-
select 'C'
|
493
|
-
click_button 'Edit'
|
494
|
-
page.all('select option').map{|s| s.text}.must_equal ['', 'X 1', 'Y 2', 'Z 0']
|
495
|
-
select 'X 1'
|
496
|
-
click_button 'Update'
|
497
|
-
|
498
|
-
click_link 'Search'
|
499
|
-
page.all('select option').map{|s| s.text}.must_equal ['', 'X 2', 'Y 1', 'Z 0']
|
500
|
-
select 'X 2'
|
501
|
-
click_button 'Search'
|
502
|
-
page.all('tr td:first-child').map{|s| s.text}.must_equal %w'C E'
|
503
|
-
|
504
|
-
click_link 'Album'
|
505
|
-
page.all('tr td:first-child').map{|s| s.text}.must_equal %w'C D E'
|
506
|
-
|
507
|
-
click_link 'Delete', :match=>:first
|
508
|
-
page.all('select option').map{|s| s.text}.must_equal ['', 'C', 'D', 'E']
|
509
|
-
select 'C'
|
510
|
-
click_button 'Delete'
|
511
|
-
click_button 'Delete'
|
512
|
-
|
513
|
-
visit("/Album/new")
|
514
|
-
Artist.where(:name=>'Y').update(:name=>'A')
|
515
|
-
fill_in 'Name', :with=>'F'
|
516
|
-
select 'Y 1'
|
517
|
-
proc{click_button 'Create'}.must_raise(Sequel::NoMatchingRow)
|
518
|
-
|
519
|
-
visit("/Album/search")
|
520
|
-
select 'X 1'
|
521
|
-
Artist.where(:name=>'X').update(:name=>'B')
|
522
|
-
click_button 'Search'
|
523
|
-
page.all('tr td:first-child').map{|s| s.text}.must_equal []
|
524
|
-
end
|
525
|
-
|
526
|
-
it "should have working one to many and many to one association links on show and edit pages" do
|
527
|
-
app_setup do
|
528
|
-
model Artist do
|
529
|
-
association_links :all
|
530
|
-
end
|
531
|
-
model Album do
|
532
|
-
association_links :all
|
533
|
-
columns [:name, :artist]
|
534
|
-
end
|
535
|
-
end
|
536
|
-
|
537
|
-
visit("/Artist/new")
|
538
|
-
fill_in 'Name', :with=>'Artist1'
|
539
|
-
click_button 'Create'
|
540
|
-
|
541
|
-
click_link 'Edit'
|
542
|
-
select 'Artist1'
|
543
|
-
click_button 'Edit'
|
544
|
-
click_link 'create'
|
545
|
-
fill_in 'Name', :with=>'Album1'
|
546
|
-
click_button 'Create'
|
547
|
-
|
548
|
-
click_link 'Show'
|
549
|
-
select 'Album1'
|
550
|
-
click_button 'Show'
|
551
|
-
click_link 'Artist1'
|
552
|
-
page.current_path.must_match %r{Artist/show/\d+}
|
553
|
-
click_link 'Album1'
|
554
|
-
page.current_path.must_match %r{Album/show/\d+}
|
555
|
-
click_link 'Artist'
|
556
|
-
page.current_path.must_equal '/Artist/browse'
|
557
|
-
|
558
|
-
click_link 'Edit', :match=>:first
|
559
|
-
select 'Artist1'
|
560
|
-
click_button 'Edit'
|
561
|
-
click_link 'Album1'
|
562
|
-
page.current_path.must_match %r{Album/edit/\d+}
|
563
|
-
click_link 'Artist1'
|
564
|
-
page.current_path.must_match %r{Artist/edit/\d+}
|
565
|
-
click_link 'Albums'
|
566
|
-
page.current_path.must_equal '/Album/browse'
|
567
|
-
|
568
|
-
visit "/Album/association_links/#{Artist.first.id}"
|
569
|
-
click_link 'Artist1'
|
570
|
-
click_button 'Update'
|
571
|
-
page.current_path.must_match %r{Artist/edit/\d+}
|
572
|
-
end
|
573
|
-
|
574
|
-
it "should have working associations listed without links if there is no autoforme for other model" do
|
575
|
-
app_setup do
|
576
|
-
model Artist do
|
577
|
-
association_links :all
|
578
|
-
end
|
579
|
-
end
|
580
|
-
|
581
|
-
visit("/Artist/new")
|
582
|
-
fill_in 'Name', :with=>'Artist1'
|
583
|
-
click_button 'Create'
|
584
|
-
|
585
|
-
Artist.first.add_album(:name=>'Album1')
|
586
|
-
click_link 'Edit'
|
587
|
-
select 'Artist1'
|
588
|
-
click_button 'Edit'
|
589
|
-
page.html.must_include 'Album1'
|
590
|
-
page.html.wont_include 'create'
|
591
|
-
page.html.wont_include '/Album'
|
592
|
-
end
|
593
|
-
|
594
|
-
it "should display but not link if the action is not supported " do
|
595
|
-
app_setup do
|
596
|
-
model Artist do
|
597
|
-
association_links :all
|
598
|
-
end
|
599
|
-
model Album do
|
600
|
-
association_links :all
|
601
|
-
supported_actions [:new]
|
602
|
-
display_name{|o| o.name.to_sym}
|
603
|
-
end
|
604
|
-
end
|
605
|
-
|
606
|
-
visit("/Artist/new")
|
607
|
-
fill_in 'Name', :with=>'Artist1'
|
608
|
-
click_button 'Create'
|
609
|
-
|
610
|
-
click_link 'Edit'
|
611
|
-
select 'Artist1'
|
612
|
-
click_button 'Edit'
|
613
|
-
click_link 'create'
|
614
|
-
fill_in 'Name', :with=>'Album1'
|
615
|
-
click_button 'Create'
|
616
|
-
|
617
|
-
visit("/Artist/edit")
|
618
|
-
select 'Artist1'
|
619
|
-
click_button 'Edit'
|
620
|
-
page.html.must_include 'Album1'
|
621
|
-
page.html.wont_include '>edit<'
|
622
|
-
end
|
623
|
-
|
624
|
-
it "should support lazy loading association links on show and edit pages" do
|
625
|
-
app_setup do
|
626
|
-
model Artist do
|
627
|
-
lazy_load_association_links true
|
628
|
-
association_links :all
|
629
|
-
end
|
630
|
-
model Album do
|
631
|
-
lazy_load_association_links true
|
632
|
-
association_links :all
|
633
|
-
columns [:name, :artist]
|
634
|
-
end
|
635
|
-
end
|
636
|
-
|
637
|
-
visit("/Artist/new")
|
638
|
-
fill_in 'Name', :with=>'Artist1'
|
639
|
-
click_button 'Create'
|
640
|
-
|
641
|
-
click_link 'Edit'
|
642
|
-
select 'Artist1'
|
643
|
-
click_button 'Edit'
|
644
|
-
page.html.wont_include 'create'
|
645
|
-
click_link 'Show Associations'
|
646
|
-
click_link 'create'
|
647
|
-
fill_in 'Name', :with=>'Album1'
|
648
|
-
click_button 'Create'
|
649
|
-
|
650
|
-
click_link 'Show'
|
651
|
-
select 'Album1'
|
652
|
-
click_button 'Show'
|
653
|
-
click_link 'Show Associations'
|
654
|
-
click_link 'Artist1'
|
655
|
-
page.current_path.must_match %r{Artist/show/\d+}
|
656
|
-
click_link 'Show Associations'
|
657
|
-
click_link 'Album1'
|
658
|
-
page.current_path.must_match %r{Album/show/\d+}
|
659
|
-
click_link 'Show Associations'
|
660
|
-
click_link 'Artist'
|
661
|
-
page.current_path.must_equal '/Artist/browse'
|
662
|
-
|
663
|
-
click_link 'Edit', :match=>:first
|
664
|
-
select 'Artist1'
|
665
|
-
click_button 'Edit'
|
666
|
-
click_link 'Show Associations'
|
667
|
-
click_link 'Album1'
|
668
|
-
page.current_path.must_match %r{Album/edit/\d+}
|
669
|
-
click_link 'Show Associations'
|
670
|
-
click_link 'Artist1'
|
671
|
-
page.current_path.must_match %r{Artist/edit/\d+}
|
672
|
-
click_link 'Show Associations'
|
673
|
-
click_link 'Albums'
|
674
|
-
page.current_path.must_equal '/Album/browse'
|
675
|
-
end
|
676
|
-
end
|
677
|
-
|
678
|
-
describe AutoForme do
|
679
|
-
before(:all) do
|
680
|
-
db_setup(:artists=>[[:name, :string], [:artist_id, :integer]], :albums=>[[:name, :string], [:artist_id, :integer, {:table=>:artists}]])
|
681
|
-
model_setup(:Artist=>[:artists, [[:one_to_many, :albums]]], :Album=>[:albums, [[:many_to_one, :artist]]])
|
682
|
-
end
|
683
|
-
after(:all) do
|
684
|
-
Object.send(:remove_const, :Album)
|
685
|
-
Object.send(:remove_const, :Artist)
|
686
|
-
end
|
687
|
-
|
688
|
-
it "should have basic many to one associations working" do
|
689
|
-
app_setup do
|
690
|
-
model Artist
|
691
|
-
model Album do
|
692
|
-
columns [:name, :artist]
|
693
|
-
eager_graph :artist
|
694
|
-
order Sequel[:artist][:name]
|
695
|
-
end
|
696
|
-
end
|
697
|
-
|
698
|
-
visit("/Artist/new")
|
699
|
-
fill_in 'Name', :with=>'Artist1'
|
700
|
-
click_button 'Create'
|
701
|
-
fill_in 'Name', :with=>'Artist2'
|
702
|
-
click_button 'Create'
|
703
|
-
|
704
|
-
visit("/Album/new")
|
705
|
-
fill_in 'Name', :with=>'Album1'
|
706
|
-
click_button 'Create'
|
707
|
-
|
708
|
-
click_link 'Edit'
|
709
|
-
select 'Album1'
|
710
|
-
click_button 'Edit'
|
711
|
-
fill_in 'Name', :with=>'Album1b'
|
712
|
-
select 'Artist2'
|
713
|
-
click_button 'Update'
|
714
|
-
|
715
|
-
click_link 'Show'
|
716
|
-
select 'Album1'
|
717
|
-
click_button 'Show'
|
718
|
-
page.html.must_match(/Name.+Album1b/m)
|
719
|
-
page.html.must_match(/Artist.+Artist2/m)
|
720
|
-
|
721
|
-
click_link 'Search'
|
722
|
-
fill_in 'Name', :with=>'1b'
|
723
|
-
select 'Artist2'
|
724
|
-
click_button 'Search'
|
725
|
-
page.all('td').map{|s| s.text}.must_equal ["Album1b", "Artist2", "Show", "Edit", "Delete"]
|
726
|
-
|
727
|
-
click_link 'Album'
|
728
|
-
page.all('td').map{|s| s.text}.must_equal ["Album1b", "Artist2", "Show", "Edit", "Delete"]
|
729
|
-
end
|
730
|
-
|
731
|
-
it "should have basic many to one associations working" do
|
732
|
-
app_setup do
|
733
|
-
model Artist do
|
734
|
-
eager_graph :albums
|
735
|
-
order Sequel[:albums][:name]
|
736
|
-
end
|
737
|
-
model Album do
|
738
|
-
columns [:name, :artist]
|
739
|
-
end
|
740
|
-
end
|
741
|
-
|
742
|
-
visit("/Artist/new")
|
743
|
-
fill_in 'Name', :with=>'Artist1'
|
744
|
-
click_button 'Create'
|
745
|
-
fill_in 'Name', :with=>'Artist2'
|
746
|
-
click_button 'Create'
|
747
|
-
|
748
|
-
visit("/Album/new")
|
749
|
-
fill_in 'Name', :with=>'Album1'
|
750
|
-
click_button 'Create'
|
751
|
-
|
752
|
-
click_link 'Edit'
|
753
|
-
select 'Album1'
|
754
|
-
click_button 'Edit'
|
755
|
-
fill_in 'Name', :with=>'Album1b'
|
756
|
-
select 'Artist2'
|
757
|
-
click_button 'Update'
|
758
|
-
|
759
|
-
click_link 'Show'
|
760
|
-
select 'Album1'
|
761
|
-
click_button 'Show'
|
762
|
-
page.html.must_match(/Name.+Album1b/m)
|
763
|
-
page.html.must_match(/Artist.+Artist2/m)
|
764
|
-
|
765
|
-
click_link 'Search'
|
766
|
-
fill_in 'Name', :with=>'1b'
|
767
|
-
select 'Artist2'
|
768
|
-
click_button 'Search'
|
769
|
-
page.all('td').map{|s| s.text}.must_equal ["Album1b", "Artist2", "Show", "Edit", "Delete"]
|
770
|
-
|
771
|
-
click_link 'Album'
|
772
|
-
page.all('td').map{|s| s.text}.must_equal ["Album1b", "Artist2", "Show", "Edit", "Delete"]
|
773
|
-
end
|
774
|
-
end
|
775
|
-
|
776
|
-
describe AutoForme do
|
777
|
-
before(:all) do
|
778
|
-
db_setup(:artists=>[[:name, :string]], :albums=>[[:name, :string], [:artist_id, :integer, {:table=>:artists}]])
|
779
|
-
model_setup(:Artist=>[:artists, [[:one_to_many, :albums]]], :Album=>[:albums, [[:many_to_one, :artist, {:conditions=>{:name=>'A'..'M'}, :order=>:name}]]])
|
780
|
-
end
|
781
|
-
after(:all) do
|
782
|
-
Object.send(:remove_const, :Album)
|
783
|
-
Object.send(:remove_const, :Artist)
|
784
|
-
end
|
785
|
-
|
786
|
-
it "should have select options respect association options" do
|
787
|
-
app_setup do
|
788
|
-
model Artist
|
789
|
-
model Album do
|
790
|
-
columns [:name, :artist]
|
791
|
-
column_options{|col, type, req| {:dataset=>proc{|ds| ds.where(:name=>'B'..'O').reverse_order(:name)}} if type == :edit && col == :artist}
|
792
|
-
end
|
793
|
-
end
|
794
|
-
|
795
|
-
%w'A1 E1 L1 N1'.each{|n| Artist.create(:name=>n)}
|
796
|
-
visit("/Album/new")
|
797
|
-
page.all('select option').map{|s| s.text}.must_equal ["", "A1", "E1", "L1"]
|
798
|
-
|
799
|
-
visit("/Album/edit/#{Album.create(:name=>'Album1').id}")
|
800
|
-
page.all('select option').map{|s| s.text}.must_equal ["", "L1", "E1"]
|
801
|
-
end
|
802
|
-
end
|