<commit_before>module MagicLamp
  class FixtureCreator
    include Callbacks

    attr_accessor :render_arguments

    def generate_template(controller_class, extensions, &block)
      fixture = execute_callbacks_around do
        controller = new_controller(controller_class, extensions, &block)
        controller.request.env["action_dispatch.request.path_parameters"] = { action: "index", controller: controller.controller_name }
        fetch_rendered(controller, block)
      end

      if fixture.empty?
        raise EmptyFixtureError, "Fixture was an empty string. This is probably not what you meant to have happen."
      end

      fixture
    end

    def new_controller(controller_class, extensions, &block)
      controller = controller_class.new
      redefine_view_context(controller, extensions)
      extensions.each { |extension| controller.extend(extension) }
      controller.request = ActionDispatch::TestRequest.new
      redefine_redirect_to(controller)
      redefine_render(controller)
      controller
    end

    def munge_arguments(arguments)
      first_arg, second_arg = arguments

      if first_arg.is_a?(Hash)
        first_arg[:layout] ||= false
      elsif second_arg.is_a?(Hash)<commit_msg>Use TestRequest.create in Rails 5<commit_after>module MagicLamp
  class FixtureCreator
    include Callbacks

    attr_accessor :render_arguments

    def generate_template(controller_class, extensions, &block)
      fixture = execute_callbacks_around do
        controller = new_controller(controller_class, extensions, &block)
        controller.request.env["action_dispatch.request.path_parameters"] = { action: "index", controller: controller.controller_name }
        fetch_rendered(controller, block)
      end

      if fixture.empty?
        raise EmptyFixtureError, "Fixture was an empty string. This is probably not what you meant to have happen."
      end

      fixture
    end

    def new_controller(controller_class, extensions, &block)
      controller = controller_class.new
      redefine_view_context(controller, extensions)
      extensions.each { |extension| controller.extend(extension) }
      test_request_class = ActionDispatch::TestRequest
      controller.request = test_request_class.respond_to?(:create) ? test_request_class.create : test_request_class.new
      redefine_redirect_to(controller)
      redefine_render(controller)
      controller
    end

    def munge_arguments(arguments)
      first_arg, second_arg = arguments

      if first_arg.is_a?(Hash)
        first_arg[:layout] ||= false
      elsif second_arg.is_a?(Hash)
{'fraction_non_alphanumeric': 0.07175925925925926, 'fraction_numerical': 0.00038580246913580245, 'mean_word_length': 3.638640429338104, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5504831', 'n_tokens_mistral': 701, 'n_tokens_neox': 693, 'n_words': 161}