Skip to content

Commit a306898

Browse files
improves conditional_sharing_spec.rb for edge case documentation
1 parent b7d69cc commit a306898

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed
Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
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-
})
2+
context "when there is a before_action inside a inertia_share" do
3+
it "does leak data between requests" do
4+
get conditional_share_index_path, headers: {'X-Inertia' => true}
5+
expect(JSON.parse(response.body)['props'].deep_symbolize_keys).to eq({
6+
index_only_prop: 1,
7+
normal_shared_prop: 1,
8+
})
89

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-
})
10+
# NOTE: we actually have to run the show action twice since the new implementation
11+
# sets up a before_action within a before_action to share the data.
12+
# In effect, that means that the shared data isn't rendered until the second time the action is run.
13+
get conditional_share_show_path, headers: {'X-Inertia' => true}
14+
get conditional_share_show_path, headers: {'X-Inertia' => true}
15+
expect(JSON.parse(response.body)['props'].deep_symbolize_keys).to eq({
16+
normal_shared_prop: 1,
17+
show_only_prop: 1,
18+
conditionally_shared_show_prop: 1,
19+
})
1920

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-
conditionally_shared_show_prop: 1, # TODO: Because we call before_action twice, this is leaking.
25-
})
21+
get conditional_share_index_path, headers: {'X-Inertia' => true}
22+
expect(JSON.parse(response.body)['props'].deep_symbolize_keys).to eq({
23+
index_only_prop: 1,
24+
normal_shared_prop: 1,
25+
conditionally_shared_show_prop: 1,
26+
})
27+
end
2628
end
2729
end

0 commit comments

Comments
 (0)