Sha256: 79727c2a1bfa62eb67bb4df5def5e07bf941d4931452142e21e7491c03719aab

Contents?: true

Size: 946 Bytes

Versions: 9

Compression:

Stored size: 946 Bytes

Contents

# frozen_string_literal: true

require "action_view"
require "web_console"
require "web_console/testing/helper"

module WebConsole
  module Testing
    class FakeMiddleware
      I18n.load_path.concat(Dir[Helper.gem_root.join("lib/web_console/locales/*.yml")])

      DEFAULT_HEADERS = { "Content-Type" => "application/javascript" }

      def initialize(opts)
        @headers        = opts.fetch(:headers, DEFAULT_HEADERS)
        @req_path_regex = opts[:req_path_regex]
        @view_path      = opts[:view_path]
      end

      def call(env)
        [ 200, @headers, [ render(req_path(env)) ] ]
      end

      def view
        @view = View.new(@view_path)
      end

      private

        # extract target path from REQUEST_PATH
        def req_path(env)
          env["REQUEST_PATH"].match(@req_path_regex)[1]
        end

        def render(template)
          view.render(template: template, layout: nil)
        end
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
web-console-4.2.0 lib/web_console/testing/fake_middleware.rb
web-console-4.1.0 lib/web_console/testing/fake_middleware.rb
web-console-4.0.4 lib/web_console/testing/fake_middleware.rb
web-console-4.0.3 lib/web_console/testing/fake_middleware.rb
web-console-4.0.2 lib/web_console/testing/fake_middleware.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/web-console-4.0.1/lib/web_console/testing/fake_middleware.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/web-console-4.0.1/lib/web_console/testing/fake_middleware.rb
web-console-4.0.1 lib/web_console/testing/fake_middleware.rb
web-console-4.0.0 lib/web_console/testing/fake_middleware.rb