expand rspec tests
This commit is contained in:
parent
3c264f6225
commit
acd18721aa
4 changed files with 71 additions and 1 deletions
14
spec/factories/order.rb
Normal file
14
spec/factories/order.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
require 'factory_girl'
|
||||
|
||||
FactoryGirl.define do
|
||||
|
||||
# requires articles from single supplier, or supplier (with all its articles)
|
||||
factory :order do
|
||||
starts { Time.now }
|
||||
|
||||
factory :stock_order do
|
||||
supplier_id 0
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -12,7 +12,9 @@ FactoryGirl.define do
|
|||
end
|
||||
|
||||
after :create do |supplier, evaluator|
|
||||
FactoryGirl.create_list :article, evaluator.article_count, supplier: supplier
|
||||
article_count = evaluator.article_count
|
||||
article_count = rand(1..100) if article_count == true
|
||||
FactoryGirl.create_list :article, article_count, supplier: supplier
|
||||
end
|
||||
end
|
||||
|
||||
|
|
49
spec/models/order_spec.rb
Normal file
49
spec/models/order_spec.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Order do
|
||||
|
||||
it 'needs a supplier' do
|
||||
FactoryGirl.build(:order).should_not be_valid
|
||||
end
|
||||
|
||||
it 'needs order articles' do
|
||||
supplier = FactoryGirl.create :supplier, article_count: 0
|
||||
FactoryGirl.build(:order, supplier: supplier).should_not be_valid
|
||||
end
|
||||
|
||||
it 'can be created' do
|
||||
supplier = FactoryGirl.create :supplier, article_count: 1
|
||||
FactoryGirl.build(:order, supplier: supplier, article_ids: supplier.articles.map(&:id)).should be_valid
|
||||
end
|
||||
|
||||
describe 'with articles' do
|
||||
let(:supplier) { FactoryGirl.create :supplier, article_count: true }
|
||||
let(:order) { FactoryGirl.create(:order, supplier: supplier, article_ids: supplier.articles.map(&:id)).reload }
|
||||
|
||||
it 'is open by default' do order.open?.should be_true end
|
||||
it 'is not finished by default' do order.finished?.should be_false end
|
||||
it 'is not closed by default' do order.closed?.should be_false end
|
||||
|
||||
it 'has valid order articles' do
|
||||
order.order_articles.all.each {|oa| oa.should be_valid }
|
||||
end
|
||||
|
||||
it 'can be finished' do
|
||||
# TODO randomise user
|
||||
order.finish!(User.first)
|
||||
order.open?.should be_false
|
||||
order.finished?.should be_true
|
||||
order.closed?.should be_false
|
||||
end
|
||||
|
||||
it 'can be closed' do
|
||||
# TODO randomise user
|
||||
order.finish!(User.first)
|
||||
order.close!(User.first)
|
||||
order.open?.should be_false
|
||||
order.closed?.should be_true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -8,4 +8,9 @@ describe Supplier do
|
|||
supplier2.should_not be_valid
|
||||
end
|
||||
|
||||
it 'has valid articles' do
|
||||
supplier = FactoryGirl.create :supplier, article_count: true
|
||||
supplier.articles.all.should be_valid
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue