-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from PedroAugustoRamalhoDuarte/fix-data-sharing
Refactor inertia share to use instance variables
- Loading branch information
Showing
16 changed files
with
128 additions
and
93 deletions.
There are no files selected for viewing
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 was deleted.
Oops, something went wrong.
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
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
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
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 |
---|---|---|
|
@@ -34,4 +34,3 @@ class Application < Rails::Application | |
config.secret_key_base = SecureRandom.hex | ||
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
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,29 @@ | ||
RSpec.describe "conditionally shared data in a controller", type: :request do | ||
context "when there is a before_action inside a inertia_share" do | ||
it "does 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, | ||
conditionally_shared_show_prop: 1, | ||
}) | ||
end | ||
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
Oops, something went wrong.