File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ class InertiaConditionalSharingController < ApplicationController
2
+ before_action :conditionally_share_props , only : [ :show ]
3
+ inertia_share normal_shared_prop : 1
4
+
5
+ def index
6
+ render inertia : 'EmptyTestComponent' , props : {
7
+ index_only_prop : 1 ,
8
+ }
9
+ end
10
+
11
+ def show
12
+ render inertia : 'EmptyTestComponent' , props : {
13
+ show_only_prop : 1 ,
14
+ }
15
+ end
16
+
17
+ protected
18
+
19
+ def conditionally_share_props
20
+ self . class . inertia_share conditionally_shared_show_prop : 1
21
+ end
22
+ end
Original file line number Diff line number Diff line change 48
48
get 'initialize_session' => 'inertia_session_continuity_test#initialize_session'
49
49
post 'submit_form_to_test_csrf' => 'inertia_session_continuity_test#submit_form_to_test_csrf'
50
50
delete 'clear_session' => 'inertia_session_continuity_test#clear_session'
51
+
52
+ get 'conditional_share_index' => 'inertia_conditional_sharing#index'
53
+ get 'conditional_share_show' => 'inertia_conditional_sharing#show'
51
54
end
Original file line number Diff line number Diff line change
1
+ RSpec . describe "conditionally shared data in a controller" , type : :request do
2
+ it 'does not leak data between requests' do
3
+ get conditional_share_index_path , headers : { 'X-Inertia' => true }
4
+ expect ( JSON . parse ( response . body ) [ 'props' ] . deep_symbolize_keys ) . to eq ( {
5
+ index_only_prop : 1 ,
6
+ normal_shared_prop : 1 ,
7
+ } )
8
+
9
+ # NOTE: we actually have to run the show action twice since the new implementation
10
+ # sets up a before_action within a before_action to share the data.
11
+ # In effect, that means that the shared data isn't rendered until the second time the action is run.
12
+ get conditional_share_show_path , headers : { 'X-Inertia' => true }
13
+ get conditional_share_show_path , headers : { 'X-Inertia' => true }
14
+ expect ( JSON . parse ( response . body ) [ 'props' ] . deep_symbolize_keys ) . to eq ( {
15
+ normal_shared_prop : 1 ,
16
+ show_only_prop : 1 ,
17
+ conditionally_shared_show_prop : 1 ,
18
+ } )
19
+
20
+ get conditional_share_index_path , headers : { 'X-Inertia' => true }
21
+ expect ( JSON . parse ( response . body ) [ 'props' ] . deep_symbolize_keys ) . to eq ( {
22
+ index_only_prop : 1 ,
23
+ normal_shared_prop : 1 ,
24
+ } )
25
+ end
26
+ end
You can’t perform that action at this time.
0 commit comments