Sha256: c76f68621b2b14e7e68781bea1f2cfd5e4fb2ba82869b1fe4a9ba57f75091f0b

Contents?: true

Size: 1.47 KB

Versions: 4

Compression:

Stored size: 1.47 KB

Contents

require 'spec_helper'

require 'roqua/support/request_logger'
require 'roqua/logging/roqua_logging_railtie'

RSpec.shared_examples 'RoQua logging setup' do
  def configure_roqua_logging(log_to_stdout)
    ClimateControl.modify RAILS_LOG_TO_STDOUT_USING_ROQUA_LOGGER: log_to_stdout do
      RoquaLoggingRailtie.configure
    end
  end

  it 'attaches Roqua::Support::RequestLogger to action_controller' do
    expect(Roqua::Support::RequestLogger).to receive(:attach_to).with(:action_controller)
    configure_roqua_logging(log_to_stdout)
  end
end

Rspec.describe RoquaLoggingRailtie do
  context 'when RAILS_LOG_TO_STDOUT_USING_ROQUA_LOGGER is present' do
    include_examples 'RoQua logging setup'

    let(:log_to_stdout) { 'true' }

    it 'logs to STDOUT' do
      expect(
        ActiveSupport::Logger.logger_outputs_to?(Roqua.logger.logger, STDOUT)
      ).to be_truthy
    end

    it 'logs using a datetimeformat including timezone' do
      time = Time.zone.local(2021,10,10,16,13)
      got = Roqua.logger.logger.formatter.call 'INFO', time, 'progname', '{}'
      expect(got).to match(/I, \[2021-10-10T16:13:00.000\+0000 #\d+]  INFO -- progname: {}/)
    end
  end

  context 'when RAILS_LOG_TO_STDOUT_USING_ROQUA_LOGGER is blank' do
    include_examples 'RoQua logging setup'

    let(:log_to_stdout) { '' }

    it 'logs to a log file' do
      expect(Roqua.logger.logger.instance_variable_get("@logdev").dev.path)
        .to eql(Rails.root.join('log/test-events.log').to_s)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
roqua-support-0.4.4 spec/roqua/logging/roqua_logging_railtie_spec.rb
roqua-support-0.4.3 spec/roqua/logging/roqua_logging_railtie_spec.rb
roqua-support-0.4.2 spec/roqua/logging/roqua_logging_railtie_spec.rb
roqua-support-0.4.1 spec/roqua/logging/roqua_logging_railtie_spec.rb