Module: EffectiveTestBotControllerHelper

Defined in:
app/helpers/effective_test_bot_controller_helper.rb

Constant Summary collapse

BODY_TAG =
'</body>'

Instance Method Summary collapse

Instance Method Details

#assign_test_bot_access_denied_exception(exception) ⇒ Object

This is called in an ActionController rescue_from.



21
22
23
# File 'app/helpers/effective_test_bot_controller_helper.rb', line 21

def assign_test_bot_access_denied_exception(exception)
  assign_test_bot_payload(test_bot_access_denied(exception))
end

#assign_test_bot_payload(payload = {}) ⇒ Object

This is included automatically as an after_action in the controller



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/effective_test_bot_controller_helper.rb', line 5

def assign_test_bot_payload(payload = {})
  payload.merge!({ response_code: response.code, assigns: test_bot_view_assigns, flash: flash.to_hash })

  if response.content_type.to_s.start_with?('text/html') && response.body[BODY_TAG].present?
    payload = view_context.(:script, build_payload_javascript(payload), id: 'test_bot_payload')

    split = response.body.split(BODY_TAG)
    response.body = "#{split.first}#{payload}#{BODY_TAG}#{split.last if split.size > 1}"
  elsif response.content_type.to_s.start_with?('text/javascript') && response.body.present?
    payload = build_payload_javascript(payload)

    response.body = "#{response.body};#{payload}"
  end
end