Sha256: d0063a0f354724f77162bce28d5f93666fcc17bb5d0e07019ec5a15da62535e0

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

require "spec_helper"

describe Timber::Probes::ActionControllerUserContext 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::WARN
    logger
  end

  describe "#insert!" do
    around(:each) do |example|
      class UserContextController < ActionController::Base
        layout nil

        def index
          logger.error "test"
          render json: {}
        end

        def method_for_action(action_name)
          action_name
        end

        private
          def current_user
            @current_user ||= begin
              user_struct = Struct.new(:id, :name, :email)
              user_struct.new(1, "Ben Johnson", "hi@timber.io")
            end
          end
      end

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

      old_logger = ::ActionController::Base.logger
      ::ActionController::Base.logger = logger

      Timecop.freeze(time) { example.run }

      Object.send(:remove_const, :UserContextController)
      ::ActionController::Base.logger = old_logger
    end

    it "should capture the user context" do
      dispatch_rails_request("/user_context")
      expect(io.string).to include("\"user\":{\"id\":\"1\",\"name\":\"Ben Johnson\",\"email\":\"hi@timber.io\"}")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
timber-1.1.14 spec/timber/probes/action_controller_user_context_spec.rb