foodsoft/spec/models/group_order_article_spec.rb

49 lines
1.9 KiB
Ruby
Raw Normal View History

2013-07-15 21:01:46 +02:00
require 'spec_helper'
describe GroupOrderArticle do
let(:user) { FactoryGirl.create :user, groups: [FactoryGirl.create(:ordergroup)] }
2013-07-25 11:16:39 +02:00
let(:order) { FactoryGirl.create(:order).reload }
2013-07-15 21:01:46 +02:00
let(:go) { FactoryGirl.create :group_order, order: order, ordergroup: user.ordergroup }
let(:goa) { FactoryGirl.create :group_order_article, group_order: go, order_article: order.order_articles.first }
2013-07-24 22:46:25 +02:00
it 'has zero quantity by default' do expect(goa.quantity).to eq(0) end
it 'has zero tolerance by default' do expect(goa.tolerance).to eq(0) end
it 'has zero result by default' do expect(goa.result).to eq(0) end
it 'is not ordered by default' do expect(GroupOrderArticle.ordered.where(:id => goa.id).exists?).to be_false end
it 'has zero total price by default' do expect(goa.total_price).to eq(0) end
2013-07-15 21:01:46 +02:00
describe do
2013-07-25 11:16:39 +02:00
let(:article) { FactoryGirl.create :article, supplier: order.supplier, unit_quantity: 1 }
let(:oa) { order.order_articles.create(:article => article) }
let(:goa) { FactoryGirl.create :group_order_article, group_order: go, order_article: oa }
2013-07-15 21:01:46 +02:00
it 'can be ordered by piece' do
goa.update_quantities(1, 0)
2013-07-24 22:46:25 +02:00
expect(goa.quantity).to eq(1)
expect(goa.tolerance).to eq(0)
2013-07-15 21:01:46 +02:00
end
it 'can be ordered in larger amounts' do
quantity, tolerance = rand(13..99), rand(0..99)
2013-07-15 21:01:46 +02:00
goa.update_quantities(quantity, tolerance)
2013-07-24 22:46:25 +02:00
expect(goa.quantity).to eq(quantity)
expect(goa.tolerance).to eq(tolerance)
2013-07-15 21:01:46 +02:00
end
it 'has a proper total price' do
quantity = rand(1..99)
2013-07-15 21:01:46 +02:00
goa.update_quantities(quantity, 0)
2013-07-24 22:46:25 +02:00
expect(goa.total_price).to eq(quantity * goa.order_article.price.fc_price)
2013-07-15 21:01:46 +02:00
end
it 'can unorder a product' do
goa.update_quantities(rand(1..99), rand(0..99))
2013-07-15 21:01:46 +02:00
goa.update_quantities(0, 0)
2013-07-24 22:46:25 +02:00
expect(goa.quantity).to eq(0)
expect(goa.tolerance).to eq(0)
2013-07-15 21:01:46 +02:00
end
end
end