autoforme 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +3 -0
- data/MIT-LICENSE +18 -0
- data/README.rdoc +226 -0
- data/Rakefile +79 -0
- data/autoforme.js +77 -0
- data/lib/autoforme/action.rb +629 -0
- data/lib/autoforme/framework.rb +145 -0
- data/lib/autoforme/frameworks/rails.rb +80 -0
- data/lib/autoforme/frameworks/sinatra.rb +59 -0
- data/lib/autoforme/model.rb +377 -0
- data/lib/autoforme/models/sequel.rb +344 -0
- data/lib/autoforme/opts_attributes.rb +29 -0
- data/lib/autoforme/request.rb +53 -0
- data/lib/autoforme/table.rb +70 -0
- data/lib/autoforme/version.rb +9 -0
- data/lib/autoforme.rb +57 -0
- data/spec/associations_spec.rb +505 -0
- data/spec/basic_spec.rb +661 -0
- data/spec/mtm_spec.rb +333 -0
- data/spec/rails_spec_helper.rb +75 -0
- data/spec/sequel_spec_helper.rb +44 -0
- data/spec/sinatra_spec_helper.rb +53 -0
- data/spec/spec_helper.rb +51 -0
- data/spec/unit_spec.rb +449 -0
- metadata +129 -0
data/spec/basic_spec.rb
ADDED
@@ -0,0 +1,661 @@
|
|
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.find('title').text.should == 'Artist - New'
|
16
|
+
fill_in 'Name', :with=>'TestArtistNew'
|
17
|
+
click_button 'Create'
|
18
|
+
page.html.should =~ /Created Artist/
|
19
|
+
page.current_path.should == '/Artist/new'
|
20
|
+
|
21
|
+
click_link 'Show'
|
22
|
+
page.find('title').text.should == 'Artist - Show'
|
23
|
+
select 'TestArtistNew'
|
24
|
+
click_button 'Show'
|
25
|
+
page.html.should =~ /Name.+TestArtistNew/m
|
26
|
+
|
27
|
+
click_link 'Edit'
|
28
|
+
page.find('title').text.should == 'Artist - Edit'
|
29
|
+
select 'TestArtistNew'
|
30
|
+
click_button 'Edit'
|
31
|
+
fill_in 'Name', :with=>'TestArtistUpdate'
|
32
|
+
click_button 'Update'
|
33
|
+
page.html.should =~ /Updated Artist/
|
34
|
+
page.html.should =~ /Name.+TestArtistUpdate/m
|
35
|
+
page.current_path.should =~ %r{/Artist/edit/\d+}
|
36
|
+
|
37
|
+
click_link 'Search'
|
38
|
+
page.find('title').text.should == 'Artist - Search'
|
39
|
+
fill_in 'Name', :with=>'Upd'
|
40
|
+
click_button 'Search'
|
41
|
+
all('th').map{|s| s.text}.should == ['Name', 'Show', 'Edit', 'Delete']
|
42
|
+
all('td').map{|s| s.text}.should == ["TestArtistUpdate", "Show", "Edit", "Delete"]
|
43
|
+
|
44
|
+
click_link 'Search'
|
45
|
+
fill_in 'Name', :with=>'Foo'
|
46
|
+
click_button 'Search'
|
47
|
+
all('td').map{|s| s.text}.should == []
|
48
|
+
|
49
|
+
click_link 'Artist'
|
50
|
+
page.find('title').text.should == 'Artist - Browse'
|
51
|
+
all('td').map{|s| s.text}.should == ["TestArtistUpdate", "Show", "Edit", "Delete"]
|
52
|
+
|
53
|
+
all('td').last.find('a').click
|
54
|
+
click_button 'Delete'
|
55
|
+
page.find('title').text.should == 'Artist - Delete'
|
56
|
+
page.html.should =~ /Deleted Artist/
|
57
|
+
page.current_path.should == '/Artist/delete'
|
58
|
+
|
59
|
+
click_link 'Artist'
|
60
|
+
all('td').map{|s| s.text}.should == []
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should have basic functionality working in a subdirectory" do
|
64
|
+
app_setup(Artist, :prefix=>"/prefix")
|
65
|
+
visit("/prefix/Artist/new")
|
66
|
+
fill_in 'Name', :with=>'TestArtistNew'
|
67
|
+
click_button 'Create'
|
68
|
+
page.html.should =~ /Created Artist/
|
69
|
+
page.current_path.should == '/prefix/Artist/new'
|
70
|
+
|
71
|
+
click_link 'Show'
|
72
|
+
select 'TestArtistNew'
|
73
|
+
click_button 'Show'
|
74
|
+
page.html.should =~ /Name.+TestArtistNew/m
|
75
|
+
|
76
|
+
click_link 'Edit'
|
77
|
+
select 'TestArtistNew'
|
78
|
+
click_button 'Edit'
|
79
|
+
fill_in 'Name', :with=>'TestArtistUpdate'
|
80
|
+
click_button 'Update'
|
81
|
+
page.html.should =~ /Updated Artist/
|
82
|
+
page.html.should =~ /Name.+TestArtistUpdate/m
|
83
|
+
page.current_path.should =~ %r{/prefix/Artist/edit/\d+}
|
84
|
+
|
85
|
+
click_link 'Search'
|
86
|
+
fill_in 'Name', :with=>'Upd'
|
87
|
+
click_button 'Search'
|
88
|
+
all('th').map{|s| s.text}.should == ['Name', 'Show', 'Edit', 'Delete']
|
89
|
+
all('td').map{|s| s.text}.should == ["TestArtistUpdate", "Show", "Edit", "Delete"]
|
90
|
+
|
91
|
+
click_link 'Search'
|
92
|
+
fill_in 'Name', :with=>'Foo'
|
93
|
+
click_button 'Search'
|
94
|
+
all('td').map{|s| s.text}.should == []
|
95
|
+
|
96
|
+
click_link 'Artist'
|
97
|
+
all('td').map{|s| s.text}.should == ["TestArtistUpdate", "Show", "Edit", "Delete"]
|
98
|
+
|
99
|
+
all('td').last.find('a').click
|
100
|
+
click_button 'Delete'
|
101
|
+
page.html.should =~ /Deleted Artist/
|
102
|
+
page.current_path.should == '/prefix/Artist/delete'
|
103
|
+
|
104
|
+
click_link 'Artist'
|
105
|
+
all('td').map{|s| s.text}.should == []
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should have delete button on edit page" do
|
109
|
+
app_setup(Artist)
|
110
|
+
visit("/Artist/new")
|
111
|
+
fill_in 'Name', :with=>'TestArtistNew'
|
112
|
+
click_button 'Create'
|
113
|
+
|
114
|
+
click_link 'Edit'
|
115
|
+
select 'TestArtistNew'
|
116
|
+
click_button 'Edit'
|
117
|
+
click_button 'Delete'
|
118
|
+
Artist.count.should == 1
|
119
|
+
click_button 'Delete'
|
120
|
+
Artist.count.should == 0
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should custom headers and footers" do
|
124
|
+
app_setup(Artist) do
|
125
|
+
page_header "<a href='/Artist/new'>N</a>"
|
126
|
+
page_footer "<a href='/Artist/edit'>E</a>"
|
127
|
+
end
|
128
|
+
visit("/Artist/browse")
|
129
|
+
page.html.should_not =~ /search/
|
130
|
+
click_link 'N'
|
131
|
+
fill_in 'Name', :with=>'TestArtistNew'
|
132
|
+
click_button 'Create'
|
133
|
+
click_link 'E'
|
134
|
+
select 'TestArtistNew'
|
135
|
+
click_button 'Edit'
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should custom redirects" do
|
139
|
+
app_setup(Artist) do
|
140
|
+
redirect do |obj, type, req|
|
141
|
+
case type
|
142
|
+
when :new
|
143
|
+
"/Artist/edit/#{obj.id}"
|
144
|
+
when :edit
|
145
|
+
"/Artist/show/#{obj.id}"
|
146
|
+
when :delete
|
147
|
+
"/Artist/new"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
visit("/Artist/new")
|
152
|
+
fill_in 'Name', :with=>'TestArtistNew'
|
153
|
+
click_button 'Create'
|
154
|
+
page.current_path.should =~ %r{/Artist/edit/\d}
|
155
|
+
click_button 'Update'
|
156
|
+
page.current_path.should =~ %r{/Artist/show/\d}
|
157
|
+
click_link 'Delete'
|
158
|
+
select 'TestArtistNew'
|
159
|
+
click_button 'Delete'
|
160
|
+
click_button 'Delete'
|
161
|
+
page.current_path.should == "/Artist/new"
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should custom form options and attributes" do
|
165
|
+
app_setup(Artist) do
|
166
|
+
form_attributes :class=>'foobar', :action=>'/create_artist'
|
167
|
+
form_options :input_defaults=>{'text'=>{:class=>'barfoo'}}
|
168
|
+
end
|
169
|
+
visit("/Artist/new")
|
170
|
+
find('form')[:class].should == 'foobar forme artist'
|
171
|
+
find('form')[:action].should == '/create_artist'
|
172
|
+
find('form input#artist_name')[:class].should == 'barfoo'
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should support specifying column options per type" do
|
176
|
+
app_setup(Artist) do
|
177
|
+
column_options{|column, type, req| {:label=>"#{type.to_s.capitalize} Artist #{column.to_s.capitalize}"}}
|
178
|
+
end
|
179
|
+
|
180
|
+
visit("/Artist/new")
|
181
|
+
fill_in 'New Artist Name', :with=>'TestArtistNew'
|
182
|
+
click_button 'Create'
|
183
|
+
page.current_path.should == '/Artist/new'
|
184
|
+
|
185
|
+
click_link 'Show'
|
186
|
+
select 'TestArtistNew'
|
187
|
+
click_button 'Show'
|
188
|
+
page.html.should =~ /Show Artist Name.+TestArtistNew/m
|
189
|
+
click_button 'Edit'
|
190
|
+
fill_in 'Edit Artist Name', :with=>'TestArtistUpdate'
|
191
|
+
click_button 'Update'
|
192
|
+
page.html.should =~ /Edit Artist Name.+TestArtistUpdate/m
|
193
|
+
page.current_path.should =~ %r{/Artist/edit/\d+}
|
194
|
+
|
195
|
+
click_link 'Search'
|
196
|
+
fill_in 'Search_form Artist Name', :with=>'Upd'
|
197
|
+
click_button 'Search'
|
198
|
+
all('th').map{|s| s.text}.should == ["Search Artist Name", "Show", "Edit", "Delete"]
|
199
|
+
|
200
|
+
click_link 'Artist'
|
201
|
+
all('th').map{|s| s.text}.should == ["Browse Artist Name", "Show", "Edit", "Delete"]
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should support specifying display names per type" do
|
205
|
+
app_setup(Artist) do
|
206
|
+
display_name do |obj, type|
|
207
|
+
case type
|
208
|
+
when :edit
|
209
|
+
obj.name[1..-1]
|
210
|
+
when :show
|
211
|
+
obj.name[2..-2]
|
212
|
+
when :delete
|
213
|
+
obj.send(:class)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
Artist.create(:name=>'TestArtistNew')
|
218
|
+
visit("/Artist/show")
|
219
|
+
select 'stArtistN'
|
220
|
+
click_button 'Show'
|
221
|
+
page.html.should =~ /Name.+TestArtistNew/m
|
222
|
+
|
223
|
+
click_link 'Edit'
|
224
|
+
select 'estArtistNe'
|
225
|
+
click_button 'Edit'
|
226
|
+
page.html.should =~ /Name.+TestArtistNew/m
|
227
|
+
|
228
|
+
click_link 'Delete'
|
229
|
+
select 'Artist'
|
230
|
+
click_button 'Delete'
|
231
|
+
click_button 'Delete'
|
232
|
+
Artist.count.should == 0
|
233
|
+
end
|
234
|
+
|
235
|
+
it "should support create, update, delete hooks" do
|
236
|
+
a = []
|
237
|
+
app_setup do
|
238
|
+
before_action{|type, req| a << type}
|
239
|
+
before_create{|obj, req| a << -1}
|
240
|
+
before_update{|obj, req| a << -2}
|
241
|
+
before_destroy{|obj, req| a << -3}
|
242
|
+
before_new{|obj, req| obj.name = 'weNtsitrAtseT'}
|
243
|
+
before_edit{|obj, req| obj.name << '2'}
|
244
|
+
after_create{|obj, req| a << 1 }
|
245
|
+
after_update{|obj, req| a << 2 }
|
246
|
+
after_destroy{|obj, req| a << 3 }
|
247
|
+
model Artist do
|
248
|
+
before_action{|type, req| req.redirect('/Artist/browse') if type == :show}
|
249
|
+
before_create{|obj, req| obj.name = obj.name.reverse}
|
250
|
+
before_update{|obj, req| obj.name = obj.name.upcase}
|
251
|
+
before_destroy{|obj, req| raise if obj.name == obj.name.reverse}
|
252
|
+
before_new{|obj, req| obj.name.reverse!}
|
253
|
+
before_edit{|obj, req| obj.name << '1'}
|
254
|
+
after_create{|obj, req| a << req.action_type }
|
255
|
+
after_update{|obj, req| a << req.action_type }
|
256
|
+
after_destroy{|obj, req| a << req.action_type }
|
257
|
+
end
|
258
|
+
end
|
259
|
+
visit("/Artist/new")
|
260
|
+
click_button 'Create'
|
261
|
+
a.should == [:new, :create, -1, 'create', 1, :new]
|
262
|
+
a.clear
|
263
|
+
|
264
|
+
click_link 'Edit'
|
265
|
+
select 'weNtsitrAtseT'
|
266
|
+
click_button 'Edit'
|
267
|
+
page.html.should =~ /weNtsitrAtseT21/
|
268
|
+
click_button 'Update'
|
269
|
+
a.should == [:edit, :edit, :update, -2, 'update', 2, :edit]
|
270
|
+
a.clear
|
271
|
+
|
272
|
+
click_link 'Show'
|
273
|
+
page.current_path.should == '/Artist/browse'
|
274
|
+
a.should == [:show, :browse]
|
275
|
+
a.clear
|
276
|
+
|
277
|
+
click_link 'Delete'
|
278
|
+
Artist.create(:name=>'A')
|
279
|
+
select 'WENTSITRATSET21'
|
280
|
+
click_button 'Delete'
|
281
|
+
click_button 'Delete'
|
282
|
+
a.should == [:delete, :delete, :destroy, -3, 'destroy', 3, :delete]
|
283
|
+
a.clear
|
284
|
+
|
285
|
+
select 'A'
|
286
|
+
click_button 'Delete'
|
287
|
+
proc{click_button 'Delete'}.should raise_error
|
288
|
+
a.should == [:delete, :destroy, -3]
|
289
|
+
end
|
290
|
+
|
291
|
+
it "should support specifying table class for data tables per type" do
|
292
|
+
app_setup(Artist) do
|
293
|
+
table_class{|type, req| type == :browse ? 'foo' : 'bar'}
|
294
|
+
end
|
295
|
+
visit("/Artist/browse")
|
296
|
+
first('table')['class'].should == 'foo'
|
297
|
+
click_link 'Search'
|
298
|
+
click_button 'Search'
|
299
|
+
first('table')['class'].should == 'bar'
|
300
|
+
end
|
301
|
+
|
302
|
+
it "should support specifying numbers of rows per page per type" do
|
303
|
+
app_setup(Artist) do
|
304
|
+
per_page{|type, req| type == :browse ? 2 : 3}
|
305
|
+
end
|
306
|
+
5.times{|i| Artist.create(:name=>i.to_s)}
|
307
|
+
visit("/Artist/browse")
|
308
|
+
first('li.disabled a').text.should == 'Previous'
|
309
|
+
all('tr td:first-child').map{|s| s.text}.should == %w'0 1'
|
310
|
+
click_link 'Next'
|
311
|
+
all('tr td:first-child').map{|s| s.text}.should == %w'2 3'
|
312
|
+
click_link 'Next'
|
313
|
+
all('tr td:first-child').map{|s| s.text}.should == %w'4'
|
314
|
+
first('li.disabled a').text.should == 'Next'
|
315
|
+
click_link 'Previous'
|
316
|
+
all('tr td:first-child').map{|s| s.text}.should == %w'2 3'
|
317
|
+
click_link 'Previous'
|
318
|
+
all('tr td:first-child').map{|s| s.text}.should == %w'0 1'
|
319
|
+
first('li.disabled a').text.should == 'Previous'
|
320
|
+
|
321
|
+
click_link 'Search'
|
322
|
+
click_button 'Search'
|
323
|
+
all('tr td:first-child').map{|s| s.text}.should == %w'0 1 2'
|
324
|
+
click_link 'Next'
|
325
|
+
all('tr td:first-child').map{|s| s.text}.should == %w'3 4'
|
326
|
+
first('li.disabled a').text.should == 'Next'
|
327
|
+
click_link 'Previous'
|
328
|
+
all('tr td:first-child').map{|s| s.text}.should == %w'0 1 2'
|
329
|
+
first('li.disabled a').text.should == 'Previous'
|
330
|
+
end
|
331
|
+
|
332
|
+
it "should support specifying supported actions" do
|
333
|
+
app_setup(Artist) do
|
334
|
+
supported_actions [:new, :edit, :browse, :search]
|
335
|
+
end
|
336
|
+
visit("/Artist/new")
|
337
|
+
fill_in 'Name', :with=>'TestArtistNew'
|
338
|
+
click_button 'Create'
|
339
|
+
page.current_path.should == '/Artist/new'
|
340
|
+
page.html.should_not =~ /Show/
|
341
|
+
page.html.should_not =~ /Delete/
|
342
|
+
|
343
|
+
click_link 'Edit'
|
344
|
+
select 'TestArtistNew'
|
345
|
+
click_button 'Edit'
|
346
|
+
fill_in 'Name', :with=>'TestArtistUpdate'
|
347
|
+
click_button 'Update'
|
348
|
+
page.html.should =~ /Name.+TestArtistUpdate/m
|
349
|
+
page.current_path.should =~ %r{/Artist/edit/\d+}
|
350
|
+
|
351
|
+
click_link 'Search'
|
352
|
+
fill_in 'Name', :with=>'Upd'
|
353
|
+
click_button 'Search'
|
354
|
+
all('td').map{|s| s.text}.should == ["TestArtistUpdate", "Edit"]
|
355
|
+
|
356
|
+
click_link 'Artist'
|
357
|
+
all('td').map{|s| s.text}.should == ["TestArtistUpdate", "Edit"]
|
358
|
+
end
|
359
|
+
|
360
|
+
it "should have basic functionality working" do
|
361
|
+
app_setup(Artist) do
|
362
|
+
class_display_name "FooArtist"
|
363
|
+
link_name "BarArtist"
|
364
|
+
end
|
365
|
+
visit("/BarArtist/new")
|
366
|
+
fill_in 'Name', :with=>'TestArtistNew'
|
367
|
+
click_button 'Create'
|
368
|
+
page.html.should =~ /Created FooArtist/
|
369
|
+
page.current_path.should == '/BarArtist/new'
|
370
|
+
|
371
|
+
click_link 'Edit'
|
372
|
+
select 'TestArtistNew'
|
373
|
+
click_button 'Edit'
|
374
|
+
fill_in 'Name', :with=>'TestArtistUpdate'
|
375
|
+
click_button 'Update'
|
376
|
+
page.html.should =~ /Updated FooArtist/
|
377
|
+
|
378
|
+
click_link 'FooArtist'
|
379
|
+
all('td').map{|s| s.text}.should == ["TestArtistUpdate", "Show", "Edit", "Delete"]
|
380
|
+
|
381
|
+
all('td').last.find('a').click
|
382
|
+
click_button 'Delete'
|
383
|
+
page.html.should =~ /Deleted FooArtist/
|
384
|
+
end
|
385
|
+
|
386
|
+
it "should use text boxes on list page when autocompleting is enabled" do
|
387
|
+
app_setup(Artist) do
|
388
|
+
autocomplete_options({})
|
389
|
+
end
|
390
|
+
a = Artist.create(:name=>'TestArtistNew')
|
391
|
+
|
392
|
+
visit('/Artist/show')
|
393
|
+
fill_in 'Artist', :with=>a.id.to_s
|
394
|
+
click_button 'Show'
|
395
|
+
page.html.should =~ /Name.+TestArtistNew/m
|
396
|
+
|
397
|
+
click_link 'Edit'
|
398
|
+
fill_in 'Artist', :with=>a.id.to_s
|
399
|
+
click_button 'Edit'
|
400
|
+
click_button 'Update'
|
401
|
+
|
402
|
+
click_link 'Delete'
|
403
|
+
fill_in 'Artist', :with=>a.id.to_s
|
404
|
+
click_button 'Delete'
|
405
|
+
click_button 'Delete'
|
406
|
+
Artist.count.should == 0
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
410
|
+
describe AutoForme do
|
411
|
+
before(:all) do
|
412
|
+
db_setup(:artists=>(0..5).map{|i|[:"n#{i}", :string]})
|
413
|
+
model_setup(:Artist=>[:artists])
|
414
|
+
class Artist
|
415
|
+
def forme_name
|
416
|
+
n0
|
417
|
+
end
|
418
|
+
end
|
419
|
+
end
|
420
|
+
after(:all) do
|
421
|
+
Object.send(:remove_const, :Artist)
|
422
|
+
end
|
423
|
+
|
424
|
+
it "should support specifying columns per type" do
|
425
|
+
cols = Artist.columns - [:id]
|
426
|
+
map = {:new=>:n5, :edit=>:n4, :show=>:n3, :browse=>:n2, :search_form=>:n1, :search=>:n0}
|
427
|
+
app_setup(Artist) do
|
428
|
+
columns{|type, req| cols - [map[type]]}
|
429
|
+
end
|
430
|
+
|
431
|
+
visit("/Artist/new")
|
432
|
+
fill_in 'N0', :with=>'V0'
|
433
|
+
fill_in 'N1', :with=>'V1'
|
434
|
+
fill_in 'N2', :with=>'V2'
|
435
|
+
fill_in 'N3', :with=>'V3'
|
436
|
+
fill_in 'N4', :with=>'V4'
|
437
|
+
page.body.should_not =~ /<label>N5/i
|
438
|
+
click_button 'Create'
|
439
|
+
|
440
|
+
click_link 'Show'
|
441
|
+
select 'V0'
|
442
|
+
click_button 'Show'
|
443
|
+
page.body.should =~ /[VN]0/i
|
444
|
+
page.body.should =~ /[VN]1/i
|
445
|
+
page.body.should =~ /[VN]2/i
|
446
|
+
page.body.should_not =~ /[VN]3/i
|
447
|
+
page.body.should =~ /[VN]4/i
|
448
|
+
page.body.should =~ /N5/i
|
449
|
+
|
450
|
+
click_link 'Edit'
|
451
|
+
select 'V0'
|
452
|
+
click_button 'Edit'
|
453
|
+
fill_in 'N0', :with=>'Q0'
|
454
|
+
fill_in 'N1', :with=>'Q1'
|
455
|
+
fill_in 'N2', :with=>'Q2'
|
456
|
+
fill_in 'N3', :with=>'Q3'
|
457
|
+
page.body.should_not =~ /<label>N4/i
|
458
|
+
fill_in 'N5', :with=>'Q5'
|
459
|
+
click_button 'Update'
|
460
|
+
|
461
|
+
click_link 'Search'
|
462
|
+
fill_in 'N0', :with=>'Q0'
|
463
|
+
page.body.should_not =~ /<label>N1/i
|
464
|
+
fill_in 'N2', :with=>'Q2'
|
465
|
+
fill_in 'N3', :with=>'Q3'
|
466
|
+
fill_in 'N4', :with=>'V4'
|
467
|
+
fill_in 'N5', :with=>'Q5'
|
468
|
+
click_button 'Search'
|
469
|
+
all('td').map{|s| s.text}.should == ["Q1", "Q2", "Q3", "V4", "Q5", "Show", "Edit", "Delete"]
|
470
|
+
|
471
|
+
click_link 'Artist'
|
472
|
+
all('td').map{|s| s.text}.should == ["Q0", "Q1", "Q3", "V4", "Q5", "Show", "Edit", "Delete"]
|
473
|
+
end
|
474
|
+
|
475
|
+
it "should support specifying order per type" do
|
476
|
+
map = {:edit=>:n0, :show=>[:n1, :n2], :delete=>:n3, :browse=>[:n1, :n0], :search=>:n4}
|
477
|
+
app_setup(Artist) do
|
478
|
+
order{|type, req| map[type]}
|
479
|
+
end
|
480
|
+
|
481
|
+
Artist.create(:n0=>'1', :n1=>'2', :n2=>'3', :n3=>'7', :n4=>'5')
|
482
|
+
Artist.create(:n0=>'2', :n1=>'2', :n2=>'1', :n3=>'3', :n4=>'4')
|
483
|
+
Artist.create(:n0=>'0', :n1=>'4', :n2=>'1', :n3=>'5', :n4=>'3')
|
484
|
+
|
485
|
+
visit("/Artist/show")
|
486
|
+
all('option').map{|s| s.text}.should == ['', '2', '1', '0']
|
487
|
+
|
488
|
+
click_link 'Edit'
|
489
|
+
all('option').map{|s| s.text}.should == ['', '0', '1', '2']
|
490
|
+
|
491
|
+
click_link 'Delete'
|
492
|
+
all('option').map{|s| s.text}.should == ['', '2', '0', '1']
|
493
|
+
|
494
|
+
click_link 'Search'
|
495
|
+
click_button 'Search'
|
496
|
+
all('tr td:first-child').map{|s| s.text}.should == ['0', '2', '1']
|
497
|
+
|
498
|
+
click_link 'Artist'
|
499
|
+
all('tr td:first-child').map{|s| s.text}.should == ['1', '2', '0']
|
500
|
+
end
|
501
|
+
|
502
|
+
it "should support specifying filter per type" do
|
503
|
+
app_setup(Artist) do
|
504
|
+
filter do |ds, type, req|
|
505
|
+
case type
|
506
|
+
when :edit
|
507
|
+
ds.where{n0 > 1}
|
508
|
+
when :show
|
509
|
+
ds.where{n1 > 3}
|
510
|
+
when :delete
|
511
|
+
ds.where{n2 > 2}
|
512
|
+
when :browse
|
513
|
+
ds.where{n3 > 6}
|
514
|
+
when :search
|
515
|
+
ds.where{n4 > 4}
|
516
|
+
end
|
517
|
+
end
|
518
|
+
end
|
519
|
+
|
520
|
+
Artist.create(:n0=>'1', :n1=>'2', :n2=>'3', :n3=>'7', :n4=>'5')
|
521
|
+
Artist.create(:n0=>'2', :n1=>'2', :n2=>'1', :n3=>'3', :n4=>'4')
|
522
|
+
Artist.create(:n0=>'0', :n1=>'4', :n2=>'1', :n3=>'5', :n4=>'3')
|
523
|
+
|
524
|
+
visit("/Artist/show")
|
525
|
+
all('option').map{|s| s.text}.should == ['', '0']
|
526
|
+
|
527
|
+
click_link 'Edit'
|
528
|
+
all('option').map{|s| s.text}.should == ['', '2']
|
529
|
+
select '2'
|
530
|
+
click_button 'Edit'
|
531
|
+
click_button 'Update'
|
532
|
+
|
533
|
+
click_link 'Delete'
|
534
|
+
all('option').map{|s| s.text}.should == ['', '1']
|
535
|
+
select '1'
|
536
|
+
click_button 'Delete'
|
537
|
+
click_button 'Delete'
|
538
|
+
Artist.create(:n0=>'1', :n1=>'2', :n2=>'3', :n3=>'7', :n4=>'5')
|
539
|
+
|
540
|
+
click_link 'Search'
|
541
|
+
click_button 'Search'
|
542
|
+
all('tr td:first-child').map{|s| s.text}.should == %w'1'
|
543
|
+
|
544
|
+
click_link 'Artist'
|
545
|
+
all('tr td:first-child').map{|s| s.text}.should == %w'1'
|
546
|
+
end
|
547
|
+
|
548
|
+
it "should support specifying filter per type using request params" do
|
549
|
+
app_setup(Artist) do
|
550
|
+
filter do |ds, type, req|
|
551
|
+
v = req.params[:f]
|
552
|
+
case type
|
553
|
+
when :edit
|
554
|
+
ds.where{n0 > v}
|
555
|
+
when :show
|
556
|
+
ds.where{n1 > v}
|
557
|
+
when :delete
|
558
|
+
ds.where{n2 > v}
|
559
|
+
when :browse
|
560
|
+
ds.where{n3 > v}
|
561
|
+
when :search
|
562
|
+
ds.where{n4 > v}
|
563
|
+
end
|
564
|
+
end
|
565
|
+
end
|
566
|
+
|
567
|
+
Artist.create(:n0=>'1', :n1=>'2', :n2=>'3', :n3=>'7', :n4=>'5')
|
568
|
+
Artist.create(:n0=>'2', :n1=>'2', :n2=>'1', :n3=>'3', :n4=>'4')
|
569
|
+
Artist.create(:n0=>'0', :n1=>'4', :n2=>'1', :n3=>'5', :n4=>'3')
|
570
|
+
|
571
|
+
visit("/Artist/show?f=3")
|
572
|
+
all('option').map{|s| s.text}.should == ['', '0']
|
573
|
+
|
574
|
+
visit("/Artist/edit?f=1")
|
575
|
+
all('option').map{|s| s.text}.should == ['', '2']
|
576
|
+
|
577
|
+
visit("/Artist/delete?f=2")
|
578
|
+
all('option').map{|s| s.text}.should == ['', '1']
|
579
|
+
|
580
|
+
visit("/Artist/search/1?f=4")
|
581
|
+
all('tr td:first-child').map{|s| s.text}.should == %w'1'
|
582
|
+
|
583
|
+
visit("/Artist/browse?f=6")
|
584
|
+
all('tr td:first-child').map{|s| s.text}.should == %w'1'
|
585
|
+
end
|
586
|
+
|
587
|
+
it "should support specifying filter per type using request session" do
|
588
|
+
app_setup(Artist) do
|
589
|
+
filter{|ds, type, req| ds.where(:n1=>req.session['n1'])}
|
590
|
+
order :n2
|
591
|
+
end
|
592
|
+
|
593
|
+
Artist.create(:n0=>'1', :n1=>'2', :n2=>'3', :n3=>'7', :n4=>'5')
|
594
|
+
Artist.create(:n0=>'2', :n1=>'2', :n2=>'1', :n3=>'3', :n4=>'4')
|
595
|
+
Artist.create(:n0=>'0', :n1=>'4', :n2=>'1', :n3=>'5', :n4=>'3')
|
596
|
+
visit '/session/set?n1=2'
|
597
|
+
|
598
|
+
visit("/Artist/show")
|
599
|
+
all('option').map{|s| s.text}.should == ['', '2', '1']
|
600
|
+
|
601
|
+
click_link 'Edit'
|
602
|
+
all('option').map{|s| s.text}.should == ['', '2', '1']
|
603
|
+
select '2'
|
604
|
+
click_button 'Edit'
|
605
|
+
click_button 'Update'
|
606
|
+
|
607
|
+
click_link 'Delete'
|
608
|
+
all('option').map{|s| s.text}.should == ['', '2', '1']
|
609
|
+
select '1'
|
610
|
+
click_button 'Delete'
|
611
|
+
click_button 'Delete'
|
612
|
+
Artist.create(:n0=>'1', :n1=>'2', :n2=>'3', :n3=>'7', :n4=>'5')
|
613
|
+
|
614
|
+
click_link 'Search'
|
615
|
+
click_button 'Search'
|
616
|
+
all('tr td:first-child').map{|s| s.text}.should == %w'2 1'
|
617
|
+
|
618
|
+
click_link 'Artist'
|
619
|
+
all('tr td:first-child').map{|s| s.text}.should == %w'2 1'
|
620
|
+
end
|
621
|
+
|
622
|
+
it "should support session_value for restricting access by matching session variable to column value" do
|
623
|
+
app_setup(Artist) do
|
624
|
+
session_value :n1
|
625
|
+
columns [:n0, :n2]
|
626
|
+
order :n2
|
627
|
+
end
|
628
|
+
|
629
|
+
Artist.create(:n0=>'0', :n1=>'4', :n2=>'1')
|
630
|
+
visit '/session/set?n1=2'
|
631
|
+
|
632
|
+
visit("/Artist/new")
|
633
|
+
fill_in 'N0', :with=>'1'
|
634
|
+
fill_in 'N2', :with=>'3'
|
635
|
+
click_button 'Create'
|
636
|
+
fill_in 'N0', :with=>'2'
|
637
|
+
fill_in 'N2', :with=>'1'
|
638
|
+
click_button 'Create'
|
639
|
+
|
640
|
+
click_link 'Show'
|
641
|
+
all('option').map{|s| s.text}.should == ['', '2', '1']
|
642
|
+
|
643
|
+
click_link 'Edit'
|
644
|
+
all('option').map{|s| s.text}.should == ['', '2', '1']
|
645
|
+
select '2'
|
646
|
+
click_button 'Edit'
|
647
|
+
click_button 'Update'
|
648
|
+
|
649
|
+
click_link 'Search'
|
650
|
+
click_button 'Search'
|
651
|
+
all('tr td:first-child').map{|s| s.text}.should == %w'2 1'
|
652
|
+
|
653
|
+
click_link 'Artist'
|
654
|
+
all('tr td:first-child').map{|s| s.text}.should == %w'2 1'
|
655
|
+
|
656
|
+
click_link 'Delete'
|
657
|
+
all('option').map{|s| s.text}.should == ['', '2', '1']
|
658
|
+
select '1'
|
659
|
+
click_button 'Delete'
|
660
|
+
end
|
661
|
+
end
|