Skip to content

Commit 4873804

Browse files
authored
Fix rspec failure on X-Inertia requests (#94)
* add failing test * fix rspec helper fail on Inertia requests
1 parent fac9eba commit 4873804

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

lib/inertia_rails/rspec.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,16 @@ def wrap_render(render_method)
2525
protected
2626

2727
def set_values(params)
28-
@view_data = params[:locals].except(:page)
29-
@props = params[:locals][:page][:props]
30-
@component = params[:locals][:page][:component]
28+
if params[:locals].present?
29+
@view_data = params[:locals].except(:page)
30+
@props = params[:locals][:page][:props]
31+
@component = params[:locals][:page][:component]
32+
else
33+
# Sequential Inertia request
34+
@view_data = {}
35+
@props = params[:json][:props]
36+
@component = params[:json][:component]
37+
end
3138
end
3239
end
3340

spec/inertia/rspec_helper_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ def puts(thing)
3434
end
3535
end
3636

37+
context 'with props during sequential request' do
38+
before { get props_path, headers: {'X-Inertia': true} }
39+
40+
it 'has props' do
41+
expect_inertia.to have_exact_props({name: 'Brandon', sport: 'hockey'})
42+
end
43+
44+
it 'includes props' do
45+
expect_inertia.to include_props({sport: 'hockey'})
46+
end
47+
48+
it 'can retrieve props' do
49+
expect(inertia.props[:name]).to eq 'Brandon'
50+
end
51+
end
52+
3753
context 'with view data' do
3854
before { get view_data_path }
3955

0 commit comments

Comments
 (0)