<commit_before>require File.dirname(__FILE__) + '/spec_helper.rb'
require 'yaml'

config_file = File.dirname(__FILE__) + '/../config/test_config.rb'

include RR

describe Session do
  before(:each) do
    Initializer.reset
    load config_file
    Session.clear_config_cache
  end

  def mock_active_record
    Left.should_receive(:establish_connection)
    Left.should_receive(:connection)
    Right.should_receive(:establish_connection)
    Right.should_receive(:connection)    
  end
  
  it "initialize should make a deep copy of the Configuration object" do
    mock_active_record
    
    session = Session.new
    session.configuration.left.should == Initializer.configuration.left
    session.configuration.right.should == Initializer.configuration.right
    
    Initializer.configuration.left[:dummy] = :dummy_value
    session.configuration.left.has_key?(:dummy).should be_false
  end
  
  it "initialize should establish the database connections" do
    mock_active_record
    
    session = Session.new
  end
    
  it "'left=' should store a Connection object and 'left' should return it" do
    mock_active_record
    
    session = Session.new
    
    session.left = :dummy
    session.left.should == :dummy
  end

  it "'right=' should store a Connection object and 'right' should return it" do
    mock_active_record
    
    session = Session.new
    
    session.right = :dummy
    session.right.should == :dummy
  end

  it "initialize shouldn't create the same database connection twice" do
    Left.should_receive(:establish_connection)
    Left.should_receive(:connection)

    Initializer.configuration.right = Initializer.configuration.left.clone
    
    session = Session.new
  end
  
  it "connections created by initializer should be alive" do
    session = Session.new
    
    session.left.active?.should be_true
    session.left.active?.should be_true
  end
  
  it "initializer should include the connection extender into connection" do
    session = Session.new
    
    session.left.kind_of?(ConnectionExtenders::PostgreSQLExtender).should be_true
  end
  
  it "initializer should raise an Exception if no fitting connection extender is available" do
    Left.should_receive(:establish_connection)
    Left.should_receive(:connection)

    Initializer.configuration.left[:adapter] = :dummy
    
    lambda {session = Session.new}.should raise_error(RuntimeError, /dummy/)<commit_msg>Corrected error in Session rspec<commit_after>require File.dirname(__FILE__) + '/spec_helper.rb'
require 'yaml'

config_file = File.dirname(__FILE__) + '/../config/test_config.rb'

include RR

describe Session do
  before(:each) do
    Initializer.reset
    load config_file
    Session.clear_config_cache
  end

  def mock_active_record
    Left.should_receive(:establish_connection)
    Left.should_receive(:connection)
    Right.should_receive(:establish_connection)
    Right.should_receive(:connection)    
  end
  
  it "initialize should make a deep copy of the Configuration object" do
    mock_active_record
    
    session = Session.new
    session.configuration.left.should == Initializer.configuration.left
    session.configuration.right.should == Initializer.configuration.right
    
    Initializer.configuration.left[:dummy] = :dummy_value
    session.configuration.left.has_key?(:dummy).should be_false
  end
  
  it "initialize should establish the database connections" do
    mock_active_record
    
    session = Session.new
  end
    
  it "'left=' should store a Connection object and 'left' should return it" do
    mock_active_record
    
    session = Session.new
    
    session.left = :dummy
    session.left.should == :dummy
  end

  it "'right=' should store a Connection object and 'right' should return it" do
    mock_active_record
    
    session = Session.new
    
    session.right = :dummy
    session.right.should == :dummy
  end

  it "initialize shouldn't create the same database connection twice" do
    Left.should_receive(:establish_connection)
    Left.should_receive(:connection)
    Right.should_not_receive(:establish_connection)

    Initializer.configuration.right = Initializer.configuration.left.clone
    
    session = Session.new
  end
  
  it "connections created by initializer should be alive" do
    session = Session.new
    
    session.left.active?.should be_true
    session.left.active?.should be_true
  end
  
  it "initializer should include the connection extender into connection" do
    session = Session.new
    
    session.left.kind_of?(ConnectionExtenders::PostgreSQLExtender).should be_true
  end
  
  it "initializer should raise an Exception if no fitting connection extender is available" do
    Left.should_receive(:establish_connection)
    Left.should_receive(:connection)

    Initializer.configuration.left[:adapter] = :dummy
    
    lambda {session = Session.new}.should raise_error(RuntimeError, /dummy/)
{'fraction_non_alphanumeric': 0.07734581721962142, 'fraction_numerical': 0.0, 'mean_word_length': 3.562674094707521, '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': '3997056', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1342, 'n_words': 356}