autoforme 1.11.0 → 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 +10 -0
- data/README.rdoc +8 -10
- data/autoforme.js +97 -56
- data/lib/autoforme/action.rb +21 -21
- data/lib/autoforme/frameworks/rails.rb +5 -1
- data/lib/autoforme/frameworks/roda.rb +9 -3
- data/lib/autoforme/frameworks/sinatra.rb +7 -2
- data/lib/autoforme/models/sequel.rb +1 -1
- data/lib/autoforme/version.rb +1 -1
- metadata +3 -15
- data/Rakefile +0 -69
- data/spec/all.rb +0 -2
- data/spec/associations_spec.rb +0 -802
- data/spec/basic_spec.rb +0 -1168
- data/spec/mtm_spec.rb +0 -621
- data/spec/rails_spec_helper.rb +0 -108
- data/spec/roda_spec.rb +0 -72
- data/spec/roda_spec_helper.rb +0 -86
- data/spec/sequel_spec_helper.rb +0 -42
- data/spec/sinatra_spec_helper.rb +0 -54
- data/spec/spec_helper.rb +0 -78
- data/spec/unit_spec.rb +0 -511
data/spec/mtm_spec.rb
DELETED
@@ -1,621 +0,0 @@
|
|
1
|
-
require_relative 'spec_helper'
|
2
|
-
|
3
|
-
describe AutoForme do
|
4
|
-
before(:all) do
|
5
|
-
db_setup(:artists=>[[:name, :string]], :albums=>[[:name, :string]], :albums_artists=>[[:album_id, :integer, {:table=>:albums}], [:artist_id, :integer, {:table=>:artists}]])
|
6
|
-
model_setup(:Artist=>[:artists, [[:many_to_many, :albums]]], :Album=>[:albums, [[:many_to_many, :artists]]])
|
7
|
-
end
|
8
|
-
after(:all) do
|
9
|
-
Object.send(:remove_const, :Album)
|
10
|
-
Object.send(:remove_const, :Artist)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should not show MTM link if there are no many to many associations" do
|
14
|
-
app_setup do
|
15
|
-
model Artist
|
16
|
-
model Album
|
17
|
-
end
|
18
|
-
|
19
|
-
visit("/Artist/browse")
|
20
|
-
page.html.wont_include 'MTM'
|
21
|
-
visit("/Artist/mtm_edit")
|
22
|
-
page.html.must_include 'Unhandled Request'
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should have working Model#associated_object_display_name" do
|
26
|
-
mod = nil
|
27
|
-
app_setup do
|
28
|
-
model Artist
|
29
|
-
model Album do
|
30
|
-
mod = self
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
mod.associated_object_display_name(:artist, nil, Artist.load(:name=>'a')).must_equal 'a'
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should have Model#associated_object_display_name respect :name_method column option" do
|
38
|
-
mod = nil
|
39
|
-
app_setup do
|
40
|
-
model Artist
|
41
|
-
model Album do
|
42
|
-
column_options :artist=>{:name_method=>:id}
|
43
|
-
mod = self
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
mod.associated_object_display_name(:artist, nil, Artist.load(:id=>1)).must_equal 1
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should have Model#associated_object_display_name raise Error if not valid" do
|
51
|
-
mod = nil
|
52
|
-
app_setup do
|
53
|
-
model Artist
|
54
|
-
model Album do
|
55
|
-
column_options :artist=>{:name_method=>Object.new}
|
56
|
-
mod = self
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
proc{mod.associated_object_display_name(:artist, nil, Artist.load(:name=>'a'))}.must_raise AutoForme::Error
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should have basic many to many association editing working" do
|
64
|
-
app_setup do
|
65
|
-
model Artist do
|
66
|
-
mtm_associations :albums
|
67
|
-
end
|
68
|
-
model Album
|
69
|
-
end
|
70
|
-
|
71
|
-
Artist.create(:name=>'Artist1')
|
72
|
-
Album.create(:name=>'Album1')
|
73
|
-
Album.create(:name=>'Album2')
|
74
|
-
Album.create(:name=>'Album3')
|
75
|
-
|
76
|
-
visit("/Artist/mtm_edit")
|
77
|
-
page.title.must_equal 'Artist - Many To Many Edit'
|
78
|
-
click_button "Edit"
|
79
|
-
select("Artist1")
|
80
|
-
click_button "Edit"
|
81
|
-
|
82
|
-
find('h2').text.must_equal 'Edit Albums for Artist1'
|
83
|
-
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album1", "Album2", "Album3"]
|
84
|
-
page.all('select')[1].all('option').map{|s| s.text}.must_equal []
|
85
|
-
select("Album1", :from=>"Associate With")
|
86
|
-
click_button "Update"
|
87
|
-
page.html.must_include 'Updated albums association for Artist'
|
88
|
-
Artist.first.albums.map{|x| x.name}.must_equal %w'Album1'
|
89
|
-
|
90
|
-
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album2", "Album3"]
|
91
|
-
page.all('select')[1].all('option').map{|s| s.text}.must_equal ["Album1"]
|
92
|
-
select("Album2", :from=>"Associate With")
|
93
|
-
select("Album3", :from=>"Associate With")
|
94
|
-
select("Album1", :from=>"Disassociate From")
|
95
|
-
click_button "Update"
|
96
|
-
Artist.first.refresh.albums.map{|x| x.name}.must_equal %w'Album2 Album3'
|
97
|
-
|
98
|
-
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album1"]
|
99
|
-
page.all('select')[1].all('option').map{|s| s.text}.must_equal ["Album2", "Album3"]
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should have many to many association editing working with autocompletion" do
|
103
|
-
app_setup do
|
104
|
-
model Artist do
|
105
|
-
mtm_associations :albums
|
106
|
-
end
|
107
|
-
model Album do
|
108
|
-
autocomplete_options({})
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
Artist.create(:name=>'Artist1')
|
113
|
-
a1 = Album.create(:name=>'Album1')
|
114
|
-
a2 = Album.create(:name=>'Album2')
|
115
|
-
a3 = Album.create(:name=>'Album3')
|
116
|
-
|
117
|
-
visit("/Artist/mtm_edit")
|
118
|
-
select("Artist1")
|
119
|
-
click_button "Edit"
|
120
|
-
|
121
|
-
page.all('select')[0].all('option').map{|s| s.text}.must_equal []
|
122
|
-
fill_in "Associate With", :with=>a1.id
|
123
|
-
click_button "Update"
|
124
|
-
page.html.must_include 'Updated albums association for Artist'
|
125
|
-
Artist.first.albums.map{|x| x.name}.must_equal %w'Album1'
|
126
|
-
|
127
|
-
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album1"]
|
128
|
-
fill_in "Associate With", :with=>a2.id
|
129
|
-
select("Album1", :from=>"Disassociate From")
|
130
|
-
click_button "Update"
|
131
|
-
Artist.first.refresh.albums.map{|x| x.name}.must_equal %w'Album2'
|
132
|
-
|
133
|
-
visit "/Artist/autocomplete/albums?type=association&q=Album"
|
134
|
-
page.body.must_match(/#{a1.id} - Album1\n#{a2.id} - Album2\n#{a3.id} - Album3/m)
|
135
|
-
|
136
|
-
visit "/Artist/autocomplete/albums?type=association&q=3"
|
137
|
-
page.body.wont_match(/#{a1.id} - Album1\n#{a2.id} - Album2\n#{a3.id} - Album3/m)
|
138
|
-
page.body.must_match(/#{a3.id} - Album3/m)
|
139
|
-
|
140
|
-
visit "/Artist/autocomplete/albums?type=association&exclude=#{Artist.first.id}&q=Album"
|
141
|
-
page.body.must_match(/#{a1.id} - Album1\n#{a3.id} - Album3/m)
|
142
|
-
|
143
|
-
visit("/Artist/mtm_edit")
|
144
|
-
select("Artist1")
|
145
|
-
click_button "Edit"
|
146
|
-
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album2"]
|
147
|
-
select("Album2", :from=>"Disassociate From")
|
148
|
-
click_button "Update"
|
149
|
-
Artist.first.refresh.albums.map{|x| x.name}.must_equal []
|
150
|
-
page.all('select')[0].all('option').map{|s| s.text}.must_equal []
|
151
|
-
end
|
152
|
-
|
153
|
-
it "should have inline many to many association editing working" do
|
154
|
-
app_setup do
|
155
|
-
model Artist do
|
156
|
-
inline_mtm_associations :albums
|
157
|
-
end
|
158
|
-
model Album
|
159
|
-
end
|
160
|
-
|
161
|
-
Artist.create(:name=>'Artist1')
|
162
|
-
Album.create(:name=>'Album1')
|
163
|
-
Album.create(:name=>'Album2')
|
164
|
-
Album.create(:name=>'Album3')
|
165
|
-
|
166
|
-
visit("/Artist/edit")
|
167
|
-
select("Artist1")
|
168
|
-
click_button "Edit"
|
169
|
-
select 'Album1'
|
170
|
-
click_button 'Add'
|
171
|
-
page.html.must_include 'Updated albums association for Artist'
|
172
|
-
Artist.first.albums.map{|x| x.name}.must_equal %w'Album1'
|
173
|
-
|
174
|
-
select 'Album2'
|
175
|
-
click_button 'Add'
|
176
|
-
Artist.first.refresh.albums.map{|x| x.name}.sort.must_equal %w'Album1 Album2'
|
177
|
-
|
178
|
-
click_button 'Remove', :match=>:first
|
179
|
-
Artist.first.refresh.albums.map{|x| x.name}.must_equal %w'Album2'
|
180
|
-
|
181
|
-
select 'Album3'
|
182
|
-
click_button 'Add'
|
183
|
-
Artist.first.refresh.albums.map{|x| x.name}.sort.must_equal %w'Album2 Album3'
|
184
|
-
end
|
185
|
-
|
186
|
-
it "should have inline many to many association editing working with autocompletion" do
|
187
|
-
app_setup do
|
188
|
-
model Artist do
|
189
|
-
inline_mtm_associations :albums
|
190
|
-
end
|
191
|
-
model Album do
|
192
|
-
autocomplete_options({})
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
Artist.create(:name=>'Artist1')
|
197
|
-
a1 = Album.create(:name=>'Album1')
|
198
|
-
a2 = Album.create(:name=>'Album2')
|
199
|
-
a3 = Album.create(:name=>'Album3')
|
200
|
-
|
201
|
-
visit("/Artist/edit")
|
202
|
-
select("Artist1")
|
203
|
-
click_button "Edit"
|
204
|
-
fill_in 'Albums', :with=>a1.id.to_s
|
205
|
-
click_button 'Add'
|
206
|
-
page.html.must_include 'Updated albums association for Artist'
|
207
|
-
Artist.first.albums.map{|x| x.name}.must_equal %w'Album1'
|
208
|
-
|
209
|
-
fill_in 'Albums', :with=>a2.id.to_s
|
210
|
-
click_button 'Add'
|
211
|
-
Artist.first.refresh.albums.map{|x| x.name}.sort.must_equal %w'Album1 Album2'
|
212
|
-
|
213
|
-
click_button 'Remove', :match=>:first
|
214
|
-
Artist.first.refresh.albums.map{|x| x.name}.must_equal %w'Album2'
|
215
|
-
|
216
|
-
fill_in 'Albums', :with=>a3.id.to_s
|
217
|
-
click_button 'Add'
|
218
|
-
Artist.first.refresh.albums.map{|x| x.name}.sort.must_equal %w'Album2 Album3'
|
219
|
-
end
|
220
|
-
|
221
|
-
it "should have inline many to many association editing working with xhr" do
|
222
|
-
app_setup do
|
223
|
-
model Artist do
|
224
|
-
inline_mtm_associations do |req|
|
225
|
-
def req.xhr?; action_type == 'mtm_update' end
|
226
|
-
:albums
|
227
|
-
end
|
228
|
-
end
|
229
|
-
model Album
|
230
|
-
end
|
231
|
-
|
232
|
-
Artist.create(:name=>'Artist1')
|
233
|
-
album = Album.create(:name=>'Album1')
|
234
|
-
|
235
|
-
visit("/Artist/edit")
|
236
|
-
select("Artist1")
|
237
|
-
click_button "Edit"
|
238
|
-
select 'Album1'
|
239
|
-
click_button 'Add'
|
240
|
-
Artist.first.albums.map{|x| x.name}.must_equal %w'Album1'
|
241
|
-
|
242
|
-
click_button 'Remove'
|
243
|
-
Artist.first.refresh.albums.map{|x| x.name}.must_equal []
|
244
|
-
page.body.must_equal "<option value=\"#{album.id}\">Album1</option>"
|
245
|
-
end
|
246
|
-
|
247
|
-
it "should have working many to many association links on show and edit pages" do
|
248
|
-
app_setup do
|
249
|
-
model Artist do
|
250
|
-
mtm_associations :albums
|
251
|
-
association_links :all_except_mtm
|
252
|
-
end
|
253
|
-
model Album do
|
254
|
-
mtm_associations [:artists]
|
255
|
-
association_links :all
|
256
|
-
end
|
257
|
-
end
|
258
|
-
|
259
|
-
visit("/Artist/new")
|
260
|
-
fill_in 'Name', :with=>'Artist1'
|
261
|
-
click_button 'Create'
|
262
|
-
click_link 'Edit'
|
263
|
-
select 'Artist1'
|
264
|
-
click_button 'Edit'
|
265
|
-
page.html.wont_include 'Albums'
|
266
|
-
|
267
|
-
visit("/Album/new")
|
268
|
-
fill_in 'Name', :with=>'Album1'
|
269
|
-
click_button 'Create'
|
270
|
-
click_link 'Edit'
|
271
|
-
select 'Album1'
|
272
|
-
click_button 'Edit'
|
273
|
-
click_link 'associate'
|
274
|
-
select("Artist1", :from=>"Associate With")
|
275
|
-
click_button 'Update'
|
276
|
-
click_link 'Show'
|
277
|
-
select 'Album1'
|
278
|
-
click_button 'Show'
|
279
|
-
click_link 'Artist1'
|
280
|
-
page.current_path.must_match %r{Artist/show/\d+}
|
281
|
-
page.html.wont_include 'Albums'
|
282
|
-
end
|
283
|
-
|
284
|
-
it "should have many to many association editing working when associated class is not using autoforme" do
|
285
|
-
app_setup do
|
286
|
-
model Artist do
|
287
|
-
mtm_associations [:albums]
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
Artist.create(:name=>'Artist1')
|
292
|
-
Album.create(:name=>'Album1')
|
293
|
-
Album.create(:name=>'Album2')
|
294
|
-
Album.create(:name=>'Album3')
|
295
|
-
|
296
|
-
visit("/Artist/mtm_edit")
|
297
|
-
select("Artist1")
|
298
|
-
click_button "Edit"
|
299
|
-
|
300
|
-
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album1", "Album2", "Album3"]
|
301
|
-
page.all('select')[1].all('option').map{|s| s.text}.must_equal []
|
302
|
-
select("Album1", :from=>"Associate With")
|
303
|
-
click_button "Update"
|
304
|
-
Artist.first.refresh.albums.map{|x| x.name}.must_equal %w'Album1'
|
305
|
-
|
306
|
-
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album2", "Album3"]
|
307
|
-
page.all('select')[1].all('option').map{|s| s.text}.must_equal ["Album1"]
|
308
|
-
select("Album2", :from=>"Associate With")
|
309
|
-
select("Album3", :from=>"Associate With")
|
310
|
-
select("Album1", :from=>"Disassociate From")
|
311
|
-
click_button "Update"
|
312
|
-
Artist.first.refresh.albums.map{|x| x.name}.must_equal %w'Album2 Album3'
|
313
|
-
|
314
|
-
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album1"]
|
315
|
-
page.all('select')[1].all('option').map{|s| s.text}.must_equal ["Album2", "Album3"]
|
316
|
-
end
|
317
|
-
|
318
|
-
it "should use filter/order from associated class" do
|
319
|
-
app_setup do
|
320
|
-
model Artist do
|
321
|
-
mtm_associations :all
|
322
|
-
end
|
323
|
-
model Album do
|
324
|
-
filter{|ds, req| ds.where(:name=>'A'..'M')}
|
325
|
-
order :name
|
326
|
-
end
|
327
|
-
end
|
328
|
-
|
329
|
-
Artist.create(:name=>'Artist1')
|
330
|
-
Album.create(:name=>'E1')
|
331
|
-
Album.create(:name=>'B1')
|
332
|
-
Album.create(:name=>'O1')
|
333
|
-
|
334
|
-
visit("/Artist/mtm_edit")
|
335
|
-
select("Artist1")
|
336
|
-
click_button "Edit"
|
337
|
-
|
338
|
-
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["B1", "E1"]
|
339
|
-
page.all('select')[1].all('option').map{|s| s.text}.must_equal []
|
340
|
-
select("E1", :from=>"Associate With")
|
341
|
-
click_button "Update"
|
342
|
-
Artist.first.albums.map{|x| x.name}.must_equal %w'E1'
|
343
|
-
|
344
|
-
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["B1"]
|
345
|
-
page.all('select')[1].all('option').map{|s| s.text}.must_equal ["E1"]
|
346
|
-
select("B1", :from=>"Associate With")
|
347
|
-
select("E1", :from=>"Disassociate From")
|
348
|
-
click_button "Update"
|
349
|
-
Artist.first.refresh.albums.map{|x| x.name}.must_equal %w'B1'
|
350
|
-
|
351
|
-
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["E1"]
|
352
|
-
page.all('select')[1].all('option').map{|s| s.text}.must_equal ["B1"]
|
353
|
-
|
354
|
-
select("B1", :from=>"Disassociate From")
|
355
|
-
Album.where(:name=>'B1').update(:name=>'Z1')
|
356
|
-
proc{click_button "Update"}.must_raise(Sequel::NoMatchingRow)
|
357
|
-
|
358
|
-
visit('/Artist/mtm_edit')
|
359
|
-
select("Artist1")
|
360
|
-
click_button "Edit"
|
361
|
-
select("E1", :from=>"Associate With")
|
362
|
-
Album.where(:name=>'E1').update(:name=>'Y1')
|
363
|
-
proc{click_button "Update"}.must_raise(Sequel::NoMatchingRow)
|
364
|
-
|
365
|
-
visit('/Artist/mtm_edit')
|
366
|
-
select("Artist1")
|
367
|
-
click_button "Edit"
|
368
|
-
page.all('select')[0].all('option').map{|s| s.text}.must_equal []
|
369
|
-
page.all('select')[1].all('option').map{|s| s.text}.must_equal []
|
370
|
-
end
|
371
|
-
|
372
|
-
it "should support column options on mtm_edit page" do
|
373
|
-
app_setup do
|
374
|
-
model Artist do
|
375
|
-
mtm_associations :albums
|
376
|
-
column_options :albums=>{:as=>:checkbox, :remove=>{:name_method=>proc{|obj| obj.name * 2}}}
|
377
|
-
end
|
378
|
-
model Album do
|
379
|
-
display_name{|obj, req| obj.name + "2"}
|
380
|
-
end
|
381
|
-
end
|
382
|
-
|
383
|
-
Artist.create(:name=>'Artist1')
|
384
|
-
Album.create(:name=>'Album1')
|
385
|
-
Album.create(:name=>'Album2')
|
386
|
-
Album.create(:name=>'Album3')
|
387
|
-
|
388
|
-
visit("/Artist/mtm_edit")
|
389
|
-
select("Artist1")
|
390
|
-
click_button "Edit"
|
391
|
-
|
392
|
-
check "Album12"
|
393
|
-
click_button "Update"
|
394
|
-
Artist.first.albums.map{|x| x.name}.must_equal %w'Album1'
|
395
|
-
|
396
|
-
check "Album1Album1"
|
397
|
-
check "Album22"
|
398
|
-
check "Album32"
|
399
|
-
click_button "Update"
|
400
|
-
Artist.first.refresh.albums.map{|x| x.name}.must_equal %w'Album2 Album3'
|
401
|
-
|
402
|
-
check "Album12"
|
403
|
-
check "Album2Album2"
|
404
|
-
check "Album3Album3"
|
405
|
-
end
|
406
|
-
end
|
407
|
-
|
408
|
-
describe AutoForme do
|
409
|
-
before(:all) do
|
410
|
-
db_setup(:artists=>proc{primary_key :artist_id; String :name}, :albums=>[[:name, :string]], :albums_artists=>[[:album_id, :integer, {:table=>:albums}], [:artist_id, :integer, {:table=>:artists}]])
|
411
|
-
model_setup(:Artist=>[:artists, [[:many_to_many, :albums]]], :Album=>[:albums, [[:many_to_many, :artists]]])
|
412
|
-
end
|
413
|
-
after(:all) do
|
414
|
-
Object.send(:remove_const, :Album)
|
415
|
-
Object.send(:remove_const, :Artist)
|
416
|
-
end
|
417
|
-
|
418
|
-
it "should have basic many to many association editing working" do
|
419
|
-
app_setup do
|
420
|
-
model Artist do
|
421
|
-
mtm_associations :albums
|
422
|
-
end
|
423
|
-
model Album
|
424
|
-
end
|
425
|
-
|
426
|
-
Artist.create(:name=>'Artist1')
|
427
|
-
Album.create(:name=>'Album1')
|
428
|
-
Album.create(:name=>'Album2')
|
429
|
-
Album.create(:name=>'Album3')
|
430
|
-
|
431
|
-
visit("/Artist/mtm_edit")
|
432
|
-
page.title.must_equal 'Artist - Many To Many Edit'
|
433
|
-
click_button "Edit"
|
434
|
-
select("Artist1")
|
435
|
-
click_button "Edit"
|
436
|
-
|
437
|
-
find('h2').text.must_equal 'Edit Albums for Artist1'
|
438
|
-
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album1", "Album2", "Album3"]
|
439
|
-
page.all('select')[1].all('option').map{|s| s.text}.must_equal []
|
440
|
-
select("Album1", :from=>"Associate With")
|
441
|
-
click_button "Update"
|
442
|
-
page.html.must_include 'Updated albums association for Artist'
|
443
|
-
Artist.first.albums.map{|x| x.name}.must_equal %w'Album1'
|
444
|
-
|
445
|
-
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album2", "Album3"]
|
446
|
-
page.all('select')[1].all('option').map{|s| s.text}.must_equal ["Album1"]
|
447
|
-
select("Album2", :from=>"Associate With")
|
448
|
-
select("Album3", :from=>"Associate With")
|
449
|
-
select("Album1", :from=>"Disassociate From")
|
450
|
-
click_button "Update"
|
451
|
-
Artist.first.refresh.albums.map{|x| x.name}.must_equal %w'Album2 Album3'
|
452
|
-
|
453
|
-
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album1"]
|
454
|
-
page.all('select')[1].all('option').map{|s| s.text}.must_equal ["Album2", "Album3"]
|
455
|
-
end
|
456
|
-
|
457
|
-
end
|
458
|
-
|
459
|
-
describe AutoForme do
|
460
|
-
before(:all) do
|
461
|
-
db_setup(:artists=>[[:name, :string]], :albums=>[[:name, :string]], :albums_artists=>[[:album_id, :integer, {:table=>:albums}], [:artist_id, :integer, {:table=>:artists}]])
|
462
|
-
model_setup(:Artist=>[:artists, [[:many_to_many, :albums]], [[:many_to_many, :other_albums, {:clone=>:albums}]]], :Album=>[:albums, [[:many_to_many, :artists]]])
|
463
|
-
end
|
464
|
-
after(:all) do
|
465
|
-
Object.send(:remove_const, :Album)
|
466
|
-
Object.send(:remove_const, :Artist)
|
467
|
-
end
|
468
|
-
|
469
|
-
it "should have basic many to many association editing working" do
|
470
|
-
app_setup do
|
471
|
-
model Artist do
|
472
|
-
mtm_associations [:albums, :other_albums]
|
473
|
-
end
|
474
|
-
model Album
|
475
|
-
end
|
476
|
-
|
477
|
-
Artist.create(:name=>'Artist1')
|
478
|
-
Album.create(:name=>'Album1')
|
479
|
-
Album.create(:name=>'Album2')
|
480
|
-
Album.create(:name=>'Album3')
|
481
|
-
|
482
|
-
visit("/Artist/mtm_edit")
|
483
|
-
page.title.must_equal 'Artist - Many To Many Edit'
|
484
|
-
select("Artist1")
|
485
|
-
click_button "Edit"
|
486
|
-
|
487
|
-
select('albums')
|
488
|
-
click_button "Edit"
|
489
|
-
|
490
|
-
find('h2').text.must_equal 'Edit Albums for Artist1'
|
491
|
-
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album1", "Album2", "Album3"]
|
492
|
-
page.all('select')[1].all('option').map{|s| s.text}.must_equal []
|
493
|
-
select("Album1", :from=>"Associate With")
|
494
|
-
click_button "Update"
|
495
|
-
page.html.must_include 'Updated albums association for Artist'
|
496
|
-
Artist.first.albums.map{|x| x.name}.must_equal %w'Album1'
|
497
|
-
|
498
|
-
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album2", "Album3"]
|
499
|
-
page.all('select')[1].all('option').map{|s| s.text}.must_equal ["Album1"]
|
500
|
-
select("Album2", :from=>"Associate With")
|
501
|
-
select("Album3", :from=>"Associate With")
|
502
|
-
select("Album1", :from=>"Disassociate From")
|
503
|
-
click_button "Update"
|
504
|
-
Artist.first.refresh.albums.map{|x| x.name}.must_equal %w'Album2 Album3'
|
505
|
-
|
506
|
-
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album1"]
|
507
|
-
page.all('select')[1].all('option').map{|s| s.text}.must_equal ["Album2", "Album3"]
|
508
|
-
end
|
509
|
-
end
|
510
|
-
|
511
|
-
describe AutoForme do
|
512
|
-
before(:all) do
|
513
|
-
db_setup(:artists=>[[:name, :string]], :albums=>[[:name, :string]], :albums_artists=>proc{column :album_id, :integer, :table=>:albums; column :artist_id, :integer, :table=>:artists; primary_key [:album_id, :artist_id]})
|
514
|
-
model_setup(:Artist=>[:artists, [[:many_to_many, :albums]]], :Album=>[:albums, [[:many_to_many, :artists]]])
|
515
|
-
end
|
516
|
-
after(:all) do
|
517
|
-
Object.send(:remove_const, :Album)
|
518
|
-
Object.send(:remove_const, :Artist)
|
519
|
-
end
|
520
|
-
|
521
|
-
it "should handle unique constraint violation errors when adding associated objects" do
|
522
|
-
app_setup do
|
523
|
-
model Artist do
|
524
|
-
mtm_associations :albums
|
525
|
-
end
|
526
|
-
model Album
|
527
|
-
end
|
528
|
-
|
529
|
-
artist = Artist.create(:name=>'Artist1')
|
530
|
-
album = Album.create(:name=>'Album1')
|
531
|
-
|
532
|
-
visit("/Artist/mtm_edit")
|
533
|
-
page.title.must_equal 'Artist - Many To Many Edit'
|
534
|
-
select("Artist1")
|
535
|
-
click_button "Edit"
|
536
|
-
|
537
|
-
find('h2').text.must_equal 'Edit Albums for Artist1'
|
538
|
-
page.all('select')[0].all('option').map{|s| s.text}.must_equal ["Album1"]
|
539
|
-
page.all('select')[1].all('option').map{|s| s.text}.must_equal []
|
540
|
-
select("Album1", :from=>"Associate With")
|
541
|
-
artist.add_album(album)
|
542
|
-
click_button "Update"
|
543
|
-
page.html.must_include 'Updated albums association for Artist'
|
544
|
-
Artist.first.albums.map{|x| x.name}.must_equal %w'Album1'
|
545
|
-
end
|
546
|
-
|
547
|
-
it "should handle unique constraint violation errors when adding associated objects" do
|
548
|
-
app_setup do
|
549
|
-
model Artist do
|
550
|
-
mtm_associations :albums
|
551
|
-
end
|
552
|
-
model Album
|
553
|
-
end
|
554
|
-
|
555
|
-
artist = Artist.create(:name=>'Artist1')
|
556
|
-
album = Album.create(:name=>'Album1')
|
557
|
-
artist.add_album(album)
|
558
|
-
|
559
|
-
visit("/Artist/mtm_edit")
|
560
|
-
page.title.must_equal 'Artist - Many To Many Edit'
|
561
|
-
select("Artist1")
|
562
|
-
click_button "Edit"
|
563
|
-
|
564
|
-
find('h2').text.must_equal 'Edit Albums for Artist1'
|
565
|
-
page.all('select')[0].all('option').map{|s| s.text}.must_equal []
|
566
|
-
page.all('select')[1].all('option').map{|s| s.text}.must_equal ["Album1"]
|
567
|
-
select("Album1", :from=>"Disassociate From")
|
568
|
-
artist.remove_album(album)
|
569
|
-
click_button "Update"
|
570
|
-
page.html.must_include 'Updated albums association for Artist'
|
571
|
-
Artist.first.albums.map{|x| x.name}.must_equal []
|
572
|
-
end
|
573
|
-
end
|
574
|
-
|
575
|
-
describe AutoForme do
|
576
|
-
before(:all) do
|
577
|
-
db_setup(:artists=>[[:name, :string]], :albums=>[[:name, :string]], :albums_artists=>[[:album_id, :integer, {:table=>:albums}], [:artist_id, :integer, {:table=>:artists}]])
|
578
|
-
model_setup(:Artist=>[:artists, [[:many_to_many, :albums, :read_only=>true]]], :Album=>[:albums, [[:many_to_many, :artists, :read_only=>true]]])
|
579
|
-
end
|
580
|
-
after(:all) do
|
581
|
-
Object.send(:remove_const, :Album)
|
582
|
-
Object.send(:remove_const, :Artist)
|
583
|
-
end
|
584
|
-
|
585
|
-
it "should not automatically setup mtm support for read-only associations" do
|
586
|
-
app_setup do
|
587
|
-
model Artist do
|
588
|
-
mtm_associations :all
|
589
|
-
association_links :all
|
590
|
-
end
|
591
|
-
model Album do
|
592
|
-
mtm_associations :all
|
593
|
-
association_links :all
|
594
|
-
end
|
595
|
-
end
|
596
|
-
|
597
|
-
visit("/Artist/new")
|
598
|
-
page.html.wont_include 'Artist/mtm_edit'
|
599
|
-
fill_in 'Name', :with=>'Artist1'
|
600
|
-
click_button 'Create'
|
601
|
-
click_link 'Edit'
|
602
|
-
select 'Artist1'
|
603
|
-
click_button 'Edit'
|
604
|
-
page.html.must_include 'Albums'
|
605
|
-
page.html.wont_include '>associate<'
|
606
|
-
visit("/Artist/mtm_edit")
|
607
|
-
page.html.must_include 'Unhandled Request'
|
608
|
-
|
609
|
-
visit("/Album/new")
|
610
|
-
page.html.wont_include 'Album/mtm_edit'
|
611
|
-
fill_in 'Name', :with=>'Album1'
|
612
|
-
click_button 'Create'
|
613
|
-
click_link 'Edit'
|
614
|
-
select 'Album1'
|
615
|
-
click_button 'Edit'
|
616
|
-
page.html.must_include 'Artists'
|
617
|
-
page.html.wont_include '>associate<'
|
618
|
-
visit("/Album/mtm_edit")
|
619
|
-
page.html.must_include 'Unhandled Request'
|
620
|
-
end
|
621
|
-
end
|