Skip to content

Commit c6df93d

Browse files
committed
Add specs to document what happens if you try to only/except evaluated prop keys
1 parent a62b21a commit c6df93d

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

spec/dummy/app/controllers/inertia_render_test_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ def deeply_nested_props
3636
nested: {
3737
first: 'first nested param',
3838
second: 'second nested param',
39+
evaluated: -> do
40+
{
41+
first: 'first evaluated nested param',
42+
second: 'second evaluated nested param'
43+
}
44+
end,
3945
deeply_nested: {
4046
first: 'first deeply nested param',
4147
second: false,

spec/inertia/rendering_spec.rb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,66 @@
191191
)
192192
end
193193
end
194+
195+
context 'with only props that target transformed data' do
196+
let(:headers) do
197+
{
198+
'X-Inertia' => true,
199+
'X-Inertia-Partial-Component' => 'TestComponent',
200+
'X-Inertia-Partial-Data' => 'nested.evaluated.first',
201+
}
202+
end
203+
204+
before { get deeply_nested_props_path, headers: headers }
205+
206+
it 'filters out the entire evaluated prop' do
207+
expect(response.parsed_body['props']).to eq(
208+
'always' => 'always prop',
209+
'nested' => {
210+
'deeply_nested' => {
211+
'deeply_nested_always' => 'deeply nested always prop',
212+
},
213+
},
214+
)
215+
end
216+
end
217+
218+
context 'with except props that target transformed data' do
219+
let(:headers) do
220+
{
221+
'X-Inertia' => true,
222+
'X-Inertia-Partial-Component' => 'TestComponent',
223+
'X-Inertia-Partial-Except' => 'nested.evaluated.first',
224+
}
225+
end
226+
227+
before { get deeply_nested_props_path, headers: headers }
228+
229+
it 'renders the entire evaluated prop' do
230+
expect(response.parsed_body['props']).to eq(
231+
'always' => 'always prop',
232+
'flat' => 'flat param',
233+
'lazy' => 'lazy param',
234+
'nested_lazy' => { 'first' => 'first nested lazy param' },
235+
'nested' => {
236+
'first' => 'first nested param',
237+
'second' => 'second nested param',
238+
'evaluated' => {
239+
'first' => 'first evaluated nested param',
240+
'second' => 'second evaluated nested param',
241+
},
242+
'deeply_nested' => {
243+
'first' => 'first deeply nested param',
244+
'second' => false,
245+
'what_about_nil' => nil,
246+
'what_about_empty_hash' => {},
247+
'deeply_nested_always' => 'deeply nested always prop',
248+
'deeply_nested_lazy' => 'deeply nested lazy prop',
249+
},
250+
},
251+
)
252+
end
253+
end
194254
end
195255

196256
context 'partial except rendering' do

0 commit comments

Comments
 (0)