Sha256: be4c751ef4ac25668966c82af6588a64d7a74d17e2ed7e66af009438b988eed1

Contents?: true

Size: 1.42 KB

Versions: 10

Compression:

Stored size: 1.42 KB

Contents

require "spec_helper"

describe Timber::Probes::ActionControllerUserContext do
  describe described_class::AroundFilter 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

    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

    describe "#index" do
      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
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
timber-1.1.13 spec/timber/probes/action_controller_user_context_spec.rb
timber-1.1.12 spec/timber/probes/action_controller_user_context_spec.rb
timber-1.1.11 spec/timber/probes/action_controller_user_context_spec.rb
timber-1.1.10 spec/timber/probes/action_controller_user_context_spec.rb
timber-1.1.9 spec/timber/probes/action_controller_user_context_spec.rb
timber-1.1.8 spec/timber/probes/action_controller_user_context_spec.rb
timber-1.1.7 spec/timber/probes/action_controller_user_context_spec.rb
timber-1.1.6 spec/timber/probes/action_controller_user_context_spec.rb
timber-1.1.5 spec/timber/probes/action_controller_user_context_spec.rb
timber-1.1.4 spec/timber/probes/action_controller_user_context_spec.rb