Module: InertiaRails::Testing::Helpers

Included in:
Minitest::Helpers, RSpec::Helpers
Defined in:
lib/inertia_rails/testing.rb

Instance Method Summary collapse

Instance Method Details

#inertiaObject



197
198
199
200
201
# File 'lib/inertia_rails/testing.rb', line 197

def inertia
  response = InertiaRails::Testing.current_response
  validate_inertia_helper_type!(response)
  response
end

#inertia_load_deferred_props(group = nil) ⇒ Object



221
222
223
224
225
226
227
# File 'lib/inertia_rails/testing.rb', line 221

def inertia_load_deferred_props(group = nil)
  deferred = inertia&.deferred_props || {}
  keys = group ? (deferred[group] || []) : deferred.values.flatten
  return if keys.empty?

  inertia_reload_only(*keys)
end

#inertia_reload_except(*props) ⇒ Object



212
213
214
215
216
217
218
219
# File 'lib/inertia_rails/testing.rb', line 212

def inertia_reload_except(*props)
  partial_headers = {
    'X-Inertia' => 'true',
    'X-Inertia-Partial-Except' => props.join(','),
    'X-Inertia-Partial-Component' => inertia.component,
  }
  get request.fullpath, headers: partial_headers
end

#inertia_reload_only(*props) ⇒ Object



203
204
205
206
207
208
209
210
# File 'lib/inertia_rails/testing.rb', line 203

def inertia_reload_only(*props)
  partial_headers = {
    'X-Inertia' => 'true',
    'X-Inertia-Partial-Data' => props.join(','),
    'X-Inertia-Partial-Component' => inertia.component,
  }
  get request.fullpath, headers: partial_headers
end