2013-07-14 02:49:40 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Article do
|
|
|
|
let(:supplier) { FactoryGirl.create :supplier }
|
|
|
|
let(:article) { FactoryGirl.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
|
2013-07-14 02:49:40 +02:00
|
|
|
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))
|
2013-07-14 02:49:40 +02:00
|
|
|
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))
|
2013-07-14 02:49:40 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'gross price >= net price' do
|
2013-07-24 22:46:25 +02:00
|
|
|
expect(article.gross_price).to be >= article.price
|
2013-07-14 02:49:40 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'fc-price > gross price' do
|
2013-07-24 22:46:25 +02:00
|
|
|
expect(article.fc_price).to be > article.gross_price
|
2013-07-14 02:49:40 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'knows when it is deleted' do
|
2013-07-24 22:46:25 +02:00
|
|
|
expect(supplier.deleted?).to be_false
|
2013-07-14 02:49:40 +02:00
|
|
|
supplier.mark_as_deleted
|
2013-07-24 22:46:25 +02:00
|
|
|
expect(supplier.deleted?).to be_true
|
2013-07-14 02:49:40 +02:00
|
|
|
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])
|
2013-07-14 02:49:40 +02:00
|
|
|
oldprice = article.price
|
2013-07-25 00:01:58 +02:00
|
|
|
sleep 1 # so that the new price really has a later creation time
|
2013-07-14 02:49:40 +02:00
|
|
|
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])
|
2013-07-14 02:49:40 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|