spec move functionality into factory
This commit is contained in:
parent
b302cbde4f
commit
7dafcf714a
4 changed files with 22 additions and 12 deletions
|
@ -2,12 +2,25 @@ require 'factory_girl'
|
|||
|
||||
FactoryGirl.define do
|
||||
|
||||
# requires articles from single supplier, or supplier (with all its articles)
|
||||
factory :order do
|
||||
starts { Time.now }
|
||||
supplier { FactoryGirl.create :supplier, article_count: (article_count.nil? ? true : article_count) }
|
||||
article_ids { supplier.articles.map(&:id) unless supplier.nil? }
|
||||
|
||||
ignore do
|
||||
article_count true
|
||||
end
|
||||
|
||||
# for an order from stock; need to add articles
|
||||
factory :stock_order do
|
||||
supplier_id 0
|
||||
# article_ids needs to be supplied
|
||||
end
|
||||
|
||||
# In the order's after_save callback order articles are created, so
|
||||
# until the order is saved, these articles do not yet exist.
|
||||
after :create do |order|
|
||||
order.reload
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,8 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe GroupOrderArticle do
|
||||
let(:user) { FactoryGirl.create :user, groups: [FactoryGirl.create(:ordergroup)] }
|
||||
let(:supplier) { FactoryGirl.create :supplier, article_count: true }
|
||||
let(:order) { FactoryGirl.create(:order, supplier: supplier, article_ids: supplier.articles.map(&:id)).reload }
|
||||
let(:order) { FactoryGirl.create(:order).reload }
|
||||
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 }
|
||||
|
||||
|
@ -14,8 +13,9 @@ describe GroupOrderArticle do
|
|||
it 'has zero total price by default' do expect(goa.total_price).to eq(0) end
|
||||
|
||||
describe do
|
||||
let(:article) { FactoryGirl.create :article, supplier: supplier, unit_quantity: 1 }
|
||||
let(:goa) { article; FactoryGirl.create :group_order_article, group_order: go, order_article: order.order_articles.find_by_article_id(article.id) }
|
||||
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 }
|
||||
|
||||
it 'can be ordered by piece' do
|
||||
goa.update_quantities(1, 0)
|
||||
|
|
|
@ -2,8 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe GroupOrder do
|
||||
let(:user) { FactoryGirl.create :user, groups: [FactoryGirl.create(:ordergroup)] }
|
||||
let(:supplier) { FactoryGirl.create :supplier, article_count: true }
|
||||
let(:order) { FactoryGirl.create(:order, supplier: supplier, article_ids: supplier.articles.map(&:id)).reload }
|
||||
let(:order) { FactoryGirl.create :order }
|
||||
|
||||
# the following two tests are currently disabled - https://github.com/foodcoops/foodsoft/issues/158
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
|||
describe Order do
|
||||
|
||||
it 'needs a supplier' do
|
||||
expect(FactoryGirl.build(:order)).to be_invalid
|
||||
expect(FactoryGirl.build(:order, supplier: nil)).to be_invalid
|
||||
end
|
||||
|
||||
it 'needs order articles' do
|
||||
|
@ -12,13 +12,11 @@ describe Order do
|
|||
end
|
||||
|
||||
it 'can be created' do
|
||||
supplier = FactoryGirl.create :supplier, article_count: 1
|
||||
expect(FactoryGirl.build(:order, supplier: supplier, article_ids: supplier.articles.map(&:id))).to be_valid
|
||||
expect(FactoryGirl.build(:order, article_count: 1)).to 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 }
|
||||
let(:order) { FactoryGirl.create :order }
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue