<commit_before>require 'rails/all'
require 'logstash-logger'
require 'logstash-logger/railtie'

module Test
  class Application < ::Rails::Application
    config.eager_load = false

    config.logstash.port = PORT
    config.log_level = :info
  end
end

Test::Application.initialize!

describe LogStashLogger do
  describe "Rails integration" do
    let(:app) { Rails.application }
    let(:config) { app.config }

    describe 'Railtie' do
      describe 'Rails.logger' do
        subject { Rails.logger }

        it { should be_a LogStashLogger }
        its(:level) { should eq(::Logger::INFO) }
      end
    end

    describe '#setup' do
      it "defaults logstash host to localhost" do
        expect(config.logstash.host).to eq("localhost")
      end

      it "defaults logstash type to :udp" do
        expect(config.logstash.type).to eq(:udp)
      end

      context "when logstash is not configured" do
        let(:app) { ::Test::Application.new }

        it "does not configure anything" do
          expect(app.config.logger).to be_nil
        end
      end

      context "when port is not specified" do
        let(:app) { ::Test::Application.new }

        before do
          app.config.logstash = ActiveSupport::OrderedOptions.new
          app.config.logstash.host = 'localhost'
        end

        it "raises an exception" do
          expect { LogStashLogger.setup(app) }.to raise_error(ArgumentError)
        end
      end
    end
  end
end<commit_msg>Fixed Rails specs for Rails 3.2<commit_after>require 'rails/all'
require 'logstash-logger'
require 'logstash-logger/railtie'

module Test
  class Application < ::Rails::Application
    config.eager_load = false

    config.logstash.port = PORT
    config.log_level = :info
  end
end

Test::Application.initialize!

describe LogStashLogger do
  describe "Rails integration", Test::Application do
    let(:app) { Rails.application }
    let(:config) { app.config }

    describe 'Railtie' do
      describe 'Rails.logger' do
        subject { Rails.logger }

        it { should be_a LogStashLogger }
        its(:level) { should eq(::Logger::INFO) }
      end
    end

    describe '#setup' do
      before do
        app.config.logstash.port = PORT
        LogStashLogger.setup(app)
      end

      it "defaults logstash host to localhost" do
        expect(config.logstash.host).to eq("localhost")
      end

      it "defaults logstash type to :udp" do
        expect(config.logstash.type).to eq(:udp)
      end

      context "when logstash is not configured" do
        before do
          app.config.logstash.clear
          app.config.logger = nil
          LogStashLogger.setup(app)
        end

        it "does not configure anything" do
          expect(app.config.logger).to be_nil
        end
      end

      context "when port is not specified" do
        before(:each) do
          app.config.logstash.clear
          app.config.logstash.host = 'localhost'
        end

        it "raises an exception" do
          expect { LogStashLogger.setup(app) }.to raise_error(ArgumentError)
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09172546504169339, 'fraction_numerical': 0.0006414368184733803, 'mean_word_length': 2.3005291005291006, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5479904', 'n_tokens_mistral': 964, 'n_tokens_neox': 925, 'n_words': 253}