-
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 support for :if, :unless, :only, :except options in inertia_share
- Loading branch information
Showing
4 changed files
with
118 additions
and
11 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 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 |
---|---|---|
@@ -1,28 +1,38 @@ | ||
RSpec.describe "conditionally shared data in a controller", type: :request do | ||
context "when there is conditional data inside inertia_share" do | ||
it "does not leak data between requests" do | ||
get conditional_share_index_path, headers: {'X-Inertia' => true} | ||
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} | ||
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} | ||
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, | ||
}) | ||
get conditional_share_edit_path, headers: { 'X-Inertia' => true } | ||
expect(JSON.parse(response.body)['props'].deep_symbolize_keys).to eq({ | ||
normal_shared_prop: 1, | ||
only_block_prop: 1, | ||
except_block_prop: 1, | ||
if_proc_prop: 1, | ||
unless_proc_prop: 1, | ||
only_prop: 1, | ||
if_prop: 1, | ||
unless_prop: 1, | ||
only_if_prop: 1, | ||
except_if_prop: 1, | ||
edit_only_prop: 1, | ||
}) | ||
end | ||
end | ||
end |