@@ -384,6 +384,125 @@ def page2
384
384
385
385
end
386
386
387
+ specify "Example 7 - Async delete request with confirm option" do
388
+
389
+ class ActionTestController < TestController
390
+ def destroy
391
+ render json : { } , status : 200
392
+ end
393
+ end
394
+
395
+ Rails . application . routes . append do
396
+ delete '/action_test' , to : 'action_test#destroy' , as : 'action_destroy_test'
397
+ end
398
+ Rails . application . reload_routes!
399
+
400
+ class ExamplePage < Matestack ::Ui ::Page
401
+
402
+ def response
403
+ components {
404
+ action action_config do
405
+ button text : "Click me!"
406
+ end
407
+ async show_on : "my_action_success" , hide_after : 300 do
408
+ plain "Well done!"
409
+ end
410
+ }
411
+ end
412
+
413
+ def action_config
414
+ return {
415
+ method : :delete ,
416
+ path : :action_destroy_test_path ,
417
+ data : {
418
+ foo : "bar"
419
+ } ,
420
+ confirm : {
421
+ text : "Are you sure?"
422
+ } ,
423
+ success : {
424
+ emit : "my_action_success"
425
+ }
426
+ }
427
+ end
428
+
429
+ end
430
+
431
+ visit "/example"
432
+
433
+ # https://stackoverflow.com/a/34888404/2066546
434
+ # https://github.com/teamcapybara/capybara#modals
435
+ dismiss_confirm do
436
+ click_button "Click me!"
437
+ end
438
+
439
+ expect ( page ) . to have_no_text "Well done!"
440
+
441
+ accept_confirm do
442
+ click_button "Click me!"
443
+ end
444
+
445
+ expect ( page ) . to have_text "Well done!"
446
+ end
447
+
448
+ end
449
+
450
+ it 'does not require a confirm text option' do
451
+ # When no confirm text is given, the default "Are you sure?" will be used.
452
+
453
+ class ActionTestController < TestController
454
+ def destroy
455
+ render json : { } , status : 200
456
+ end
457
+ end
458
+
459
+ Rails . application . routes . append do
460
+ delete '/action_test' , to : 'action_test#destroy' , as : 'action_destroy_test'
461
+ end
462
+ Rails . application . reload_routes!
463
+
464
+ class ExamplePage < Matestack ::Ui ::Page
465
+
466
+ def response
467
+ components {
468
+ action action_config do
469
+ button text : "Click me!"
470
+ end
471
+ async show_on : "my_action_success" , hide_after : 300 do
472
+ plain "Well done!"
473
+ end
474
+ }
475
+ end
476
+
477
+ def action_config
478
+ return {
479
+ method : :delete ,
480
+ path : :action_destroy_test_path ,
481
+ data : {
482
+ foo : "bar"
483
+ } ,
484
+ confirm : true ,
485
+ success : {
486
+ emit : "my_action_success"
487
+ }
488
+ }
489
+ end
490
+
491
+ end
492
+
493
+ visit "/example"
494
+
495
+ dismiss_confirm do
496
+ click_button "Click me!"
497
+ end
498
+
499
+ expect ( page ) . to have_no_text "Well done!"
500
+
501
+ accept_confirm do
502
+ click_button "Click me!"
503
+ end
504
+
505
+ expect ( page ) . to have_text "Well done!"
387
506
end
388
507
389
508
it 'accepts class and id attributes and returns them as the corresponding HTML attributes' do
0 commit comments