foodsoft/spec/models/article_spec.rb

47 lines
1.3 KiB
Ruby
Raw Normal View History

2013-09-18 12:44:41 +02:00
require_relative '../spec_helper'
describe Article do
2013-09-18 12:44:41 +02:00
let(:supplier) { create :supplier }
let(:article) { create :article, supplier: supplier }
it 'has a unique name' do
article2 = FactoryGirl.build :article, supplier: supplier, name: article.name
2013-07-24 22:46:25 +02:00
expect(article2).to be_invalid
end
it 'computes the gross price correctly' do
article.deposit = 0
article.tax = 12
2013-07-24 22:46:25 +02:00
expect(article.gross_price).to eq((article.price * 1.12).round(2))
article.deposit = 1.20
2013-07-24 22:46:25 +02:00
expect(article.gross_price).to eq(((article.price + 1.20) * 1.12).round(2))
end
it 'gross price >= net price' do
2013-07-24 22:46:25 +02:00
expect(article.gross_price).to be >= article.price
end
it 'fc-price >= gross price' do
if article.gross_price > 0
expect(article.fc_price).to be > article.gross_price
else
expect(article.fc_price).to be >= article.gross_price
end
end
it 'knows when it is deleted' do
2013-07-24 22:46:25 +02:00
expect(supplier.deleted?).to be_false
supplier.mark_as_deleted
2013-07-24 22:46:25 +02:00
expect(supplier.deleted?).to be_true
end
it 'keeps a price history' do
2013-07-25 00:01:58 +02:00
expect(article.article_prices.all.map(&:price)).to eq([article.price])
oldprice = article.price
2013-07-25 00:01:58 +02:00
sleep 1 # so that the new price really has a later creation time
article.price += 1
article.save!
2013-07-25 00:01:58 +02:00
expect(article.article_prices.all.map(&:price)).to eq([article.price, oldprice])
end
end