Module: EffectiveTestBotControllerHelper

Defined in:
app/helpers/effective_test_bot_controller_helper.rb

Instance Method Summary collapse

Instance Method Details

#assign_test_bot_http_headersObject

This is included as an after_filter



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/helpers/effective_test_bot_controller_helper.rb', line 3

def assign_test_bot_http_headers
  response.headers['Test-Bot-Flash'] = Base64.encode64(flash.to_hash.to_json)

  # Assign the Assigns now
  # With the assigns, we're a little bit more selective
  # Anything that's a simple object can be serialized
  test_bot_assigns = {}

  view_assigns.each do |key, object|
    case object
    when ActiveRecord::Base
      test_bot_assigns[key] = object.attributes
      test_bot_assigns[key][:errors] = object.errors.messages.delete_if { |_, v| v.blank? } if object.errors.present?
    when TrueClass, FalseClass, NilClass, String, Symbol, Numeric
      test_bot_assigns[key] = object
    else
      # We don't want to serialize them, but they should be present
      test_bot_assigns[key] = :present_but_not_serialized
    end
  end

  response.headers['Test-Bot-Assigns'] = Base64.encode64(test_bot_assigns.to_hash.to_json)
end

#assign_test_bot_unpermitted_params_header(exception) ⇒ Object

We get here if ApplicationController raised a ActionController::UnpermittedParameters error



28
29
30
31
32
# File 'app/helpers/effective_test_bot_controller_helper.rb', line 28

def assign_test_bot_unpermitted_params_header(exception)
  if exception.kind_of?(ActionController::UnpermittedParameters)
    response.headers['Test-Bot-Unpermitted-Params'] = Base64.encode64(exception.params.to_json)
  end
end