foodsoft/spec/models/article_spec.rb

44 lines
1.2 KiB
Ruby
Raw Normal View History

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
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
2013-07-24 22:46:25 +02:00
expect(article.fc_price).to be > article.gross_price
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