<commit_before>require 'perpetuity/postgres/connection'

module Perpetuity
  class Postgres
    describe Connection do
      let(:connection) { Connection.new(db: 'perpetuity_gem_test') }

      it 'sanitizes the options for the pg gem' do
        options = { db: 'db', username: 'user' }
        connection.sanitize_options(options).should == {
          dbname: 'db',
          user: 'user'
        }
      end

      it 'is only activated when it is used' do
        connection.should_not be_active
        connection.connect
        connection.should be_active
      end

      it 'executes SQL' do
        connection.execute 'CREATE TABLE IF NOT EXISTS abcdefg (name text)'
        connection.tables.should include 'abcdefg'
        connection.execute 'DROP TABLE IF EXISTS abcdefg'
        connection.tables.should_not include 'abcdefg'
      end
    end
  end
end
<commit_msg>Stub DB connection in unit test<commit_after>require 'perpetuity/postgres/connection'

module Perpetuity
  class Postgres
    describe Connection do
      let(:connection) { Connection.new(db: 'perpetuity_gem_test') }

      it 'sanitizes the options for the pg gem' do
        options = { db: 'db', username: 'user' }
        connection.sanitize_options(options).should == {
          dbname: 'db',
          user: 'user'
        }
      end

      it 'is only activated when it is used' do
        connection.should_not be_active
        PG.stub(connect: true)
        connection.connect
        connection.should be_active
      end

      it 'executes SQL' do
        connection.execute 'CREATE TABLE IF NOT EXISTS abcdefg (name text)'
        connection.tables.should include 'abcdefg'
        connection.execute 'DROP TABLE IF EXISTS abcdefg'
        connection.tables.should_not include 'abcdefg'
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.07713498622589532, 'fraction_numerical': 0.0, 'mean_word_length': 2.43289224952741, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6636191', 'n_tokens_mistral': 520, 'n_tokens_neox': 517, 'n_words': 159}