-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add (an admittedly contrived) failing spec for conditionally shared data
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
spec/dummy/app/controllers/inertia_conditional_sharing_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class InertiaConditionalSharingController < ApplicationController | ||
before_action :conditionally_share_props, only: [:show] | ||
inertia_share normal_shared_prop: 1 | ||
|
||
def index | ||
render inertia: 'EmptyTestComponent', props: { | ||
index_only_prop: 1, | ||
} | ||
end | ||
|
||
def show | ||
render inertia: 'EmptyTestComponent', props: { | ||
show_only_prop: 1, | ||
} | ||
end | ||
|
||
protected | ||
|
||
def conditionally_share_props | ||
self.class.inertia_share conditionally_shared_show_prop: 1 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
RSpec.describe "conditionally shared data in a controller", type: :request do | ||
it 'does not leak data between requests' do | ||
get conditional_share_index_path, headers: {'X-Inertia' => true} | ||
expect(JSON.parse(response.body)['props'].deep_symbolize_keys).to eq({ | ||
index_only_prop: 1, | ||
normal_shared_prop: 1, | ||
}) | ||
|
||
# NOTE: we actually have to run the show action twice since the new implementation | ||
# sets up a before_action within a before_action to share the data. | ||
# In effect, that means that the shared data isn't rendered until the second time the action is run. | ||
get conditional_share_show_path, headers: {'X-Inertia' => true} | ||
get conditional_share_show_path, headers: {'X-Inertia' => true} | ||
expect(JSON.parse(response.body)['props'].deep_symbolize_keys).to eq({ | ||
normal_shared_prop: 1, | ||
show_only_prop: 1, | ||
conditionally_shared_show_prop: 1, | ||
}) | ||
|
||
get conditional_share_index_path, headers: {'X-Inertia' => true} | ||
expect(JSON.parse(response.body)['props'].deep_symbolize_keys).to eq({ | ||
index_only_prop: 1, | ||
normal_shared_prop: 1, | ||
}) | ||
end | ||
end |