<commit_before>require 'spec_helper'

describe IB::Models::Execution do # AKA IB::Execution

  let(:properties) do
    {:account_name => "DU111110",
     :average_price => 1.31075,
     :client_id => 1111,
     :cumulative_quantity => 20000,
     :exchange => "IDEALPRO",
     :exec_id => "0001f4e8.4f5d48f1.01.01",
     :liquidation => 0,
     :order_id => 373,
     :perm_id => 1695693613,
     :price => 1.31075,
     :shares => 20000,
     :side => :buy,
     :time => "20120312  15:41:09"
    }
  end

  context "instantiation" do
    context 'empty without properties' do
      subject { IB::Execution.new }

      it { should_not be_nil }
      its(:order_id) { should == 0 }
      its(:client_id) { should == 0 }
      its(:perm_id) { should == 0 }
      its(:shares) { should == 0 }
      its(:price) { should == 0 }
      its(:liquidation) { should == 0 }
      its(:created_at) { should be_a Time }
    end

    context 'with properties' do
      subject { IB::Execution.new properties }

      it 'sets properties right' do
        properties.each do |name, value|
          subject.send(name).should == value
        end
      end
    end
  end #instantiation

  context "properties" do

    it 'allows setting properties' do
      expect {
        x = IB::Execution.new
        properties.each do |name, value|
          subject.send("#{name}=", value)
          subject.send(name).should == value
        end
      }.to_not raise_error
    end

    it 'sets side as directed by its setter' do
      @x = IB::Execution.new
      ['BOT', 'BUY', 'Buy', 'buy', :BUY, :BOT, :Buy, :buy, 'B', :b].each do |val|
        expect { @x.side = val }.to_not raise_error
        @x.side.should == :buy
      end

      ['SELL', 'SLD', 'Sel', 'sell', :SELL, :SLD, :Sell, :sell, 'S', :S].each do |val|
        expect { @x.side = val }.to_not raise_error
        @x.side.should == :sell
      end
    end
  end # properties

end # describe IB::Models::Contract<commit_msg>First spec for DB backend<commit_after>require 'spec_helper'

describe IB::Models::Execution do # AKA IB::Execution

  let(:properties) do
    {:account_name => "DU111110",
     :average_price => 1.31075,
     :client_id => 1111,
     :cumulative_quantity => 20000,
     :exchange => "IDEALPRO",
     :exec_id => "0001f4e8.4f5d48f1.01.01",
     :liquidation => 0,
     :order_id => 373,
     :perm_id => 1695693613,
     :price => 1.31075,
     :shares => 20000,
     :side => :buy,
     :time => "20120312  15:41:09"
    }
  end

  context "instantiation" do
    context 'empty without properties' do
      subject { IB::Execution.new }

      it { should_not be_nil }
      its(:order_id) { should == 0 }
      its(:client_id) { should == 0 }
      its(:perm_id) { should == 0 }
      its(:shares) { should == 0 }
      its(:price) { should == 0 }
      its(:liquidation) { should == 0 }
      its(:created_at) { should be_a Time }
    end

    context 'with properties' do
      subject { IB::Execution.new properties }

      it 'sets all properties just right' do
        properties.each do |name, value|
          subject.send(name).should == value
        end
      end

      context 'with DB backend', :db => true do
        after(:all) do
          DatabaseCleaner.clean
        end

        it 'is saved' do
          subject.save.should be_true
        end

        it 'is loaded' do
          models = described_class.find(:all)
          models.should have_exactly(1).model
          models.first.should == subject
        end
      end # DB
    end

  end #instantiation

  context "properties" do

    it 'allows setting properties' do
      expect {
        x = IB::Execution.new
        properties.each do |name, value|
          subject.send("#{name}=", value)
          subject.send(name).should == value
        end
      }.to_not raise_error
    end

    it 'sets side as directed by its setter' do
      @x = IB::Execution.new
      ['BOT', 'BUY', 'Buy', 'buy', :BUY, :BOT, :Buy, :buy, 'B', :b].each do |val|
        expect { @x.side = val }.to_not raise_error
        @x.side.should == :buy
      end

      ['SELL', 'SLD', 'Sel', 'sell', :SELL, :SLD, :Sell, :sell, 'S', :S].each do |val|
        expect { @x.side = val }.to_not raise_error
        @x.side.should == :sell
      end
    end
  end # properties
end # describe IB::Models::Contract
{'fraction_non_alphanumeric': 0.1396957123098202, 'fraction_numerical': 0.037574919317657905, 'mean_word_length': 2.2022140221402213, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 30, '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': '1672658', 'n_tokens_mistral': 1615, 'n_tokens_neox': 1426, 'n_words': 388}