Files
growstuff/spec/models/order_item_spec.rb
Cjay c568498941 Refactor spec/models
- Changed before(:each) into let
- Changed :admin_ability and :cw_ability into :ability
2015-07-09 02:21:10 +08:00

29 lines
838 B
Ruby

require 'rails_helper'
describe OrderItem do
let(:order_item) { FactoryGirl.create(:order_item) }
it "has an order and a product" do
order_item.order.should be_an_instance_of Order
order_item.product.should be_an_instance_of Product
end
it "validates price > product.min_price" do
@product = FactoryGirl.create(:product)
order_item = FactoryGirl.build(:order_item, :price => @product.min_price - 1)
order_item.should_not be_valid
end
it "doesn't let you add two items to an order" do
@product = FactoryGirl.create(:product)
@order = FactoryGirl.create(:order)
order_item = FactoryGirl.build(:order_item, :order => @order)
order_item.should be_valid
order_item.save
@order_item2 = FactoryGirl.build(:order_item, :order => @order)
@order_item2.should_not be_valid
end
end