@@ -619,4 +619,90 @@ def response
619619 #
620620 # end
621621
622+ specify "follow_response option makes a transition follow controller redirects" do
623+
624+ class TestModelsController < ExampleController
625+ include Matestack ::Ui ::Core ::ApplicationHelper
626+
627+ def index
628+ responder_for Pages ::FollowResponseExampleApp ::ExamplePage
629+ end
630+
631+ def create
632+ @test_model = TestModel . create title : params [ :title ]
633+ render json : {
634+ transition_to : test_model_path ( id : @test_model . id )
635+ } , status : :ok
636+ end
637+
638+ def show
639+ @test_model = TestModel . find params [ :id ]
640+ responder_for Pages ::FollowResponseExampleApp ::TestModelPage
641+ end
642+ end
643+
644+ Rails . application . routes . append do
645+ resources :test_models
646+ end
647+ Rails . application . reload_routes!
648+
649+ class Apps ::FollowResponseExampleApp < Matestack ::Ui ::App
650+ def response
651+ components {
652+ heading size : 1 , text : "My Example App Layout"
653+ main do
654+ page_content
655+ end
656+ }
657+ end
658+ end
659+
660+ module Pages ::FollowResponseExampleApp
661+ end
662+
663+ class Pages ::FollowResponseExampleApp ::ExamplePage < Matestack ::Ui ::Page
664+ def response
665+ components {
666+ action action_config do
667+ button text : "Click me!"
668+ end
669+ }
670+ end
671+
672+ def action_config
673+ return {
674+ method : :post ,
675+ path : :test_models_path ,
676+ data : {
677+ title : "A title for my new test object"
678+ } ,
679+ success : {
680+ transition : {
681+ follow_response : true
682+ }
683+ }
684+ }
685+ end
686+
687+ end
688+
689+ class Pages ::FollowResponseExampleApp ::TestModelPage < Matestack ::Ui ::Page
690+ def response
691+ components {
692+ heading text : @test_model . title , size : 1
693+ plain "This page has been loaded via redirect_to and follow_response."
694+ }
695+ end
696+ end
697+
698+ visit "/test_models"
699+
700+ click_button "Click me!"
701+
702+ expect ( page ) . to have_no_text "Click me"
703+ expect ( page ) . to have_text "A title for my new test object"
704+ expect ( page ) . to have_text "This page has been loaded via redirect_to and follow_response."
705+
706+ end
707+
622708end
0 commit comments