<commit_before>require 'spec_helper'

begin
  require 'active_support'
  require 'action_controller'
  require 'action_controller/test_process'
  require 'honeybadger/rails'

  describe Honeybadger::Rails::ActionControllerCatcher do
    include DefinesConstants

    before(:each) do
      reset_config
      Honeybadger.sender = CollectingSender.new
      define_constant('RAILS_ROOT', '/path/to/rails/root')
    end

    def ignore(exception_class)
      Honeybadger.configuration.ignore << exception_class
    end

    def build_controller_class(&definition)
      Class.new(ActionController::Base).tap do |klass|
        klass.__send__(:include, Honeybadger::Rails::ActionControllerCatcher)
        klass.class_eval(&definition) if definition
        define_constant('HoneybadgerTestController', klass)
      end
    end

    def assert_sent_hash(hash, &block)
      hash.each do |key, value|
        next if key.match(/^honeybadger\./) # We added this key.

        new_block = Proc.new {
          block.call(last_sent_notice_payload)[key]
        }

        if value.respond_to?(:to_hash)
          assert_sent_hash(value.to_hash, &new_block)
        else
          assert_sent_element(value, &new_block)
        end
      end
    end

    def assert_sent_element(value, &block)
      expect(yield(last_sent_notice_payload)).to eq stringify_array_elements(value)
    end

    def stringify_array_elements(data)
      if data.is_a?(Array)
        data.collect do |value|
          stringify_array_elements(value)
        end
      else<commit_msg>Expect whitelisted objects in Rails 2 spec.<commit_after>require 'spec_helper'

begin
  require 'active_support'
  require 'action_controller'
  require 'action_controller/test_process'
  require 'honeybadger/rails'

  describe Honeybadger::Rails::ActionControllerCatcher do
    include DefinesConstants

    before(:each) do
      reset_config
      Honeybadger.sender = CollectingSender.new
      define_constant('RAILS_ROOT', '/path/to/rails/root')
    end

    def ignore(exception_class)
      Honeybadger.configuration.ignore << exception_class
    end

    def build_controller_class(&definition)
      Class.new(ActionController::Base).tap do |klass|
        klass.__send__(:include, Honeybadger::Rails::ActionControllerCatcher)
        klass.class_eval(&definition) if definition
        define_constant('HoneybadgerTestController', klass)
      end
    end

    def assert_sent_hash(hash, &block)
      hash.each do |key, value|
        next if key.match(/^honeybadger\./) # We added this key.

        new_block = Proc.new {
          block.call(last_sent_notice_payload)[key]
        }

        if value.respond_to?(:to_hash)
          assert_sent_hash(value.to_hash, &new_block)
        else
          assert_sent_element(value, &new_block)
        end
      end
    end

    def assert_sent_element(value, &block)
      expect(yield(last_sent_notice_payload)).to eq stringify_array_elements(value)
    end

    def stringify_array_elements(data)
      if data.is_a?(Array)
        data.collect do |value|
          stringify_array_elements(value)
        end
      elsif Honeybadger::Payload::OBJECT_WHITELIST.any? {|c| data.kind_of?(c) }
        data
      else
{'fraction_non_alphanumeric': 0.08764323319913286, 'fraction_numerical': 0.0003096934035305048, 'mean_word_length': 3.0680100755667508, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6808733', 'n_tokens_mistral': 1005, 'n_tokens_neox': 968, 'n_words': 184}