Module: EffectiveTestBotControllerHelper
- Defined in:
- app/helpers/effective_test_bot_controller_helper.rb
Constant Summary collapse
- BODY_TAG =
'</body>'
Instance Method Summary collapse
-
#assign_test_bot_access_denied_exception(exception) ⇒ Object
This is called in an ActionController rescue_from.
-
#assign_test_bot_payload(payload = {}) ⇒ Object
This is included as an after_action in the controller.
Instance Method Details
#assign_test_bot_access_denied_exception(exception) ⇒ Object
This is called in an ActionController rescue_from.
25 26 27 |
# File 'app/helpers/effective_test_bot_controller_helper.rb', line 25 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 as an after_action in the controller
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/helpers/effective_test_bot_controller_helper.rb', line 5 def assign_test_bot_payload(payload = {}) return unless response.content_type == 'text/html'.freeze return unless !!(response.body[BODY_TAG]) payload.merge!({ response_code: response.code, assigns: test_bot_view_assigns, flash: flash.to_hash }) payload = view_context.content_tag(:script, id: 'test_bot_payload') do [ '', 'window.effective_test_bot = {};', payload.map { |k, v| "window.effective_test_bot.#{k} = #{v.respond_to?(:to_json) ? v.to_json : ("'" + v + "'")};" }, '', ].join("\n").html_safe end split = response.body.split(BODY_TAG) response.body = "#{split.first}#{payload}#{BODY_TAG}#{split.last if split.size > 1}" end |