Sha256: d630c57f44497eb6dd2967089f5d085a872914d141b02571cd101560eed4521f

Contents?: true

Size: 1.39 KB

Versions: 40

Compression:

Stored size: 1.39 KB

Contents

require "spec_helper"

if defined?(::ActiveRecord)
  describe Timber::Integrations::ActiveRecord::LogSubscriber 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

    describe "#insert!" do
      around(:each) do |example|
        with_rails_logger(logger) do
          Timecop.freeze(time) { example.run }
        end
      end

      it "should not log if the level is not sufficient" do
        ActiveRecord::Base.connection.execute("select * from users")
        expect(io.string).to eq("")
      end

      context "with an info level" do
        around(:each) do |example|
          old_level = logger.level
          logger.level = ::Logger::DEBUG
          example.run
          logger.level = old_level
        end

        it "should log the sql query" do
          ActiveRecord::Base.connection.execute("select * from users")
          # Rails 4.X adds random spaces :/
          string = io.string.gsub("   ORDER BY", " ORDER BY")
          string = string.gsub("  ORDER BY", " ORDER BY")
          expect(string).to include("select * from users")
          expect(string).to include("@metadata")
          expect(string).to include("\"level\":\"debug\"")
          expect(string).to include("\"event\":{\"sql_query\"")
        end
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
timber-2.6.2 spec/timber/integrations/active_record/log_subscriber_spec.rb
timber-2.6.1 spec/timber/integrations/active_record/log_subscriber_spec.rb
timber-2.6.0 spec/timber/integrations/active_record/log_subscriber_spec.rb
timber-2.6.0.pre.beta2 spec/timber/integrations/active_record/log_subscriber_spec.rb
timber-2.6.0.pre.beta1 spec/timber/integrations/active_record/log_subscriber_spec.rb
timber-2.5.1 spec/timber/integrations/active_record/log_subscriber_spec.rb
timber-2.5.0 spec/timber/integrations/active_record/log_subscriber_spec.rb
timber-2.4.0 spec/timber/integrations/active_record/log_subscriber_spec.rb
timber-2.3.4 spec/timber/integrations/active_record/log_subscriber_spec.rb
timber-2.3.3 spec/timber/integrations/active_record/log_subscriber_spec.rb
timber-2.3.2 spec/timber/integrations/active_record/log_subscriber_spec.rb
timber-2.3.1 spec/timber/integrations/active_record/log_subscriber_spec.rb
timber-2.3.0 spec/timber/integrations/active_record/log_subscriber_spec.rb
timber-2.2.3 spec/timber/integrations/active_record/log_subscriber_spec.rb
timber-2.2.2 spec/timber/integrations/active_record/log_subscriber_spec.rb
timber-2.2.1 spec/timber/integrations/active_record/log_subscriber_spec.rb
timber-2.2.0 spec/timber/integrations/active_record/log_subscriber_spec.rb
timber-2.1.10 spec/timber/integrations/active_record/log_subscriber_spec.rb
timber-2.1.9 spec/timber/integrations/active_record/log_subscriber_spec.rb
timber-2.1.8 spec/timber/integrations/active_record/log_subscriber_spec.rb