Sha256: 3cada2fec4272441c8f1c10a69dd059c83bd489a5ab8ea3be5f0a17a7e0ffcda

Contents?: true

Size: 1.41 KB

Versions: 15

Compression:

Stored size: 1.41 KB

Contents

require "spec_helper"

describe Timber::RackMiddlewares::HTTPContext do
  let(:time) { Time.utc(2016, 9, 1, 12, 0, 0) }
  let(:io) { StringIO.new }
  let(:logger) do
    logger = Timber::Logger.new(io)
    logger.level = ::Logger::INFO
    logger
  end

  around(:each) do |example|
    class RackHttpController < ActionController::Base
      layout nil

      def index
        Thread.current[:_timber_context] = Timber::CurrentContext.instance.snapshot
        render json: {}
      end

      def method_for_action(action_name)
        action_name
      end
    end

    ::RailsApp.routes.draw do
      get '/rack_http' => 'rack_http#index'
    end

    Timecop.freeze(time) { example.run }

    Object.send(:remove_const, :RackHttpController)
  end

  describe "#process" do
    it "should set the context" do
      allow(Benchmark).to receive(:ms).and_return(1).and_yield
      allow_any_instance_of(Timber::Probes::ActionControllerLogSubscriber::LogSubscriber).to receive(:logger).and_return(logger)

      dispatch_rails_request("/rack_http")
      http_context = Thread.current[:_timber_context][:http]

      expect(http_context).to eq({:method=>"GET", :path=>"/rack_http", :remote_addr=>"123.456.789.10", :request_id=>"unique-request-id-1234"})
      expect(io.string).to include("\"http\":{\"method\":\"GET\",\"path\":\"/rack_http\",\"remote_addr\":\"123.456.789.10\",\"request_id\":\"unique-request-id-1234\"}")
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
timber-1.1.14 spec/timber/rack_middlewares/http_context_spec.rb
timber-1.1.13 spec/timber/rack_middlewares/http_context_spec.rb
timber-1.1.12 spec/timber/rack_middlewares/http_context_spec.rb
timber-1.1.11 spec/timber/rack_middlewares/http_context_spec.rb
timber-1.1.10 spec/timber/rack_middlewares/http_context_spec.rb
timber-1.1.9 spec/timber/rack_middlewares/http_context_spec.rb
timber-1.1.8 spec/timber/rack_middlewares/http_context_spec.rb
timber-1.1.7 spec/timber/rack_middlewares/http_context_spec.rb
timber-1.1.6 spec/timber/rack_middlewares/http_context_spec.rb
timber-1.1.5 spec/timber/rack_middlewares/http_context_spec.rb
timber-1.1.4 spec/timber/rack_middlewares/http_context_spec.rb
timber-1.1.3 spec/timber/rack_middlewares/http_context_spec.rb
timber-1.1.2 spec/timber/rack_middlewares/http_context_spec.rb
timber-1.1.1 spec/timber/rack_middlewares/http_context_spec.rb
timber-1.1.0 spec/timber/rack_middlewares/http_context_spec.rb