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



183
184
185
186
187
# File 'lib/inertia_rails/testing.rb', line 183

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

#inertia_load_deferred_props(group = nil) ⇒ Object



207
208
209
210
211
212
213
# File 'lib/inertia_rails/testing.rb', line 207

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



198
199
200
201
202
203
204
205
# File 'lib/inertia_rails/testing.rb', line 198

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

#inertia_reload_only(*props) ⇒ Object



189
190
191
192
193
194
195
196
# File 'lib/inertia_rails/testing.rb', line 189

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