Permalink
Browse files

Zero defaults for OrderState

  • Loading branch information...
1 parent 2f87f43 commit beeeac1a6d3df448616d1451cc9e1ee4f303ab4e @arvicco arvicco committed Apr 25, 2012
Showing with 20 additions and 10 deletions.
  1. +9 −8 spec/ib-ruby/models/order_spec.rb
  2. +10 −2 spec/ib-ruby/models/order_state_spec.rb
  3. +1 −0 spec/model_helper.rb
@@ -127,16 +127,17 @@
subject.init_margin.should be_nil
subject.maint_margin.should be_nil
subject.equity_with_loan.should be_nil
- # Properties arriving via OrderStatus messagesubject.
- subject.filled.should be_nil
- subject.remaining.should be_nil
- subject.price.should be_nil
- subject.last_fill_price.should be_nil
- subject.average_price.should be_nil
- subject.average_fill_price.should be_nil
+ # Properties arriving via OrderStatus message
+ subject.filled.should == 0
+ subject.remaining.should == 0
+ subject.price.should == 0
+ subject.last_fill_price.should == 0
+ subject.average_price.should == 0
+ subject.average_fill_price.should == 0
subject.why_held.should be_nil
- # Testing Order statesubject.
+ # Testing Order state
subject.should be_new
+ subject.should_not be_submitted
subject.should_not be_pending
subject.should be_active
subject.should_not be_inactive
@@ -53,17 +53,19 @@
it_behaves_like 'Self-equal Model'
context '#update_missing' do
+ let(:nil_state) { IB::OrderState.new(:filled => nil, :remaining => nil,
+ :price => nil, :average_price => nil) }
context 'updating with Hash' do
- subject { IB::OrderState.new.update_missing(props) }
+ subject { nil_state.update_missing(props) }
it_behaves_like 'Model instantiated with properties'
end
context 'updating with Model' do
- subject { IB::OrderState.new.update_missing(IB::OrderState.new(props)) }
+ subject { nil_state.update_missing(IB::OrderState.new(props)) }
it_behaves_like 'Model instantiated with properties'
@@ -74,6 +76,8 @@
it 'has extra test methods' do
empty_state = IB::OrderState.new
empty_state.should be_new
+ subject.should_not be_pending
+ subject.should_not be_submitted
empty_state.should be_active
empty_state.should_not be_inactive
empty_state.should_not be_complete_fill
@@ -86,6 +90,7 @@
state.should_not be_inactive
state.should_not be_complete_fill
state.should be_pending
+ status == 'PendingSubmit' ? state.should_not(be_submitted) : state.should(be_submitted)
end
['PendingCancel', 'Cancelled', 'ApiCancelled', 'Inactive'].each do |status|
@@ -95,6 +100,7 @@
state.should be_inactive
state.should_not be_complete_fill
state.should_not be_pending
+ subject.should_not be_submitted
end
state.status = 'Filled'
@@ -103,13 +109,15 @@
state.should be_inactive
state.should_not be_complete_fill
state.should_not be_pending
+ subject.should_not be_submitted
state.remaining = 0
state.should_not be_new
state.should_not be_active
state.should be_inactive
state.should be_complete_fill
state.should_not be_pending
+ subject.should_not be_submitted
end
end # describe IB::Order
View
@@ -190,6 +190,7 @@ def test_assigns cases, prop, name
shared_examples_for 'Model instantiated with properties' do
it 'auto-assigns all properties given to initializer' do
props.each do |name, value|
+ #p subject, name, value
subject.send(name).should == value
end
end

0 comments on commit beeeac1

Please sign in to comment.