2013-07-15 00:17:07 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Order do
|
|
|
|
|
|
|
|
it 'needs a supplier' do
|
2013-07-25 11:16:39 +02:00
|
|
|
expect(FactoryGirl.build(:order, supplier: nil)).to be_invalid
|
2013-07-15 00:17:07 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'needs order articles' do
|
|
|
|
supplier = FactoryGirl.create :supplier, article_count: 0
|
2013-07-24 22:46:25 +02:00
|
|
|
expect(FactoryGirl.build(:order, supplier: supplier)).to be_invalid
|
2013-07-15 00:17:07 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can be created' do
|
2013-07-25 11:16:39 +02:00
|
|
|
expect(FactoryGirl.build(:order, article_count: 1)).to be_valid
|
2013-07-15 00:17:07 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with articles' do
|
2013-07-25 11:16:39 +02:00
|
|
|
let(:order) { FactoryGirl.create :order }
|
2013-07-15 00:17:07 +02:00
|
|
|
|
2013-07-24 22:46:25 +02:00
|
|
|
it 'is open by default' do expect(order).to be_open end
|
|
|
|
it 'is not finished by default' do expect(order).to_not be_finished end
|
|
|
|
it 'is not closed by default' do expect(order).to_not be_closed end
|
2013-07-15 00:17:07 +02:00
|
|
|
|
|
|
|
it 'has valid order articles' do
|
2013-07-24 22:46:25 +02:00
|
|
|
order.order_articles.all.each {|oa| expect(oa).to be_valid }
|
2013-07-15 00:17:07 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can be finished' do
|
|
|
|
# TODO randomise user
|
|
|
|
order.finish!(User.first)
|
2013-07-24 22:46:25 +02:00
|
|
|
expect(order).to_not be_open
|
|
|
|
expect(order).to be_finished
|
|
|
|
expect(order).to_not be_closed
|
2013-07-15 00:17:07 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can be closed' do
|
|
|
|
# TODO randomise user
|
|
|
|
order.finish!(User.first)
|
|
|
|
order.close!(User.first)
|
2013-07-24 22:46:25 +02:00
|
|
|
expect(order).to_not be_open
|
|
|
|
expect(order).to be_closed
|
2013-07-15 00:17:07 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|