Skip to content

Commit

Permalink
Fix rspec failure on X-Inertia requests (#94)
Browse files Browse the repository at this point in the history
* add failing test

* fix rspec helper fail on Inertia requests
  • Loading branch information
iatanas0v authored Oct 25, 2024
1 parent fac9eba commit 4873804
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/inertia_rails/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@ def wrap_render(render_method)
protected

def set_values(params)
@view_data = params[:locals].except(:page)
@props = params[:locals][:page][:props]
@component = params[:locals][:page][:component]
if params[:locals].present?
@view_data = params[:locals].except(:page)
@props = params[:locals][:page][:props]
@component = params[:locals][:page][:component]
else
# Sequential Inertia request
@view_data = {}
@props = params[:json][:props]
@component = params[:json][:component]
end
end
end

Expand Down
16 changes: 16 additions & 0 deletions spec/inertia/rspec_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ def puts(thing)
end
end

context 'with props during sequential request' do
before { get props_path, headers: {'X-Inertia': true} }

it 'has props' do
expect_inertia.to have_exact_props({name: 'Brandon', sport: 'hockey'})
end

it 'includes props' do
expect_inertia.to include_props({sport: 'hockey'})
end

it 'can retrieve props' do
expect(inertia.props[:name]).to eq 'Brandon'
end
end

context 'with view data' do
before { get view_data_path }

Expand Down

0 comments on commit 4873804

Please sign in to comment.