Whitespace cleanup
[merb_mart.git] / spec / models / order_spec.rb
blob6a158d41d7eed29b46863a49a7e5ea8eedd8dd70
1 require File.join( File.dirname(__FILE__), "..", "spec_helper" )
3 describe Order do
4   before(:each) do
5     DataMapper.auto_migrate!
6   end
8   describe "associations" do
9     it "should belong to a customer" do
10       customer = Customer.gen
11       order = Order.create(Order.gen_attrs.merge(:customer => customer))
12       order.customer.should == customer
13       order.should be_valid
15       order = Order.create(Order.gen_attrs.except(:customer))
16       order.customer.should be_nil
17       order.should_not be_valid
18       order.errors.should include(:customer)
19     end
21     it "should have 1..n line_items" do
22       line_items = (1..10).of {LineItem.gen}
23       order = Order.create(Order.gen_attrs.merge(:line_items => line_items))
24       order.line_items.should == line_items
25       order.should be_valid
27       order = Order.create(Order.gen_attrs.except(:line_items))
28       order.line_items.should be_empty
29       order.should_not be_valid
30       order.errors.should include(:line_items)
31     end
33     it "should have 1..n transactions" do
34       transactions = (1..10).of {Transaction.gen}
35       order = Order.create(Order.gen_attrs.merge(:transactions => transactions))
36       order.transactions.should == transactions
37       order.should be_valid
39       order = Order.create(Order.gen_attrs.except(:transactions))
40       order.transactions.should be_empty
41       order.should be_valid
42     end
44     it "should have 1 shipping info" do
45       shipping_info = ShippingInfo.gen
46       order = Order.create(Order.gen_attrs.merge(:shipping_info => shipping_info))
47       order.shipping_info.should == shipping_info
48       order.should be_valid
50       order = Order.create(Order.gen_attrs.except(:shipping_info))
51       order.shipping_info.should be_nil
52       order.should_not be_valid
53       order.errors.should include(:shipping_info)
54     end
56     it "should have 0..1 promotion" do
57       pending "many to many in DM core"
59       promotion = Promotion.gen
60       order = Order.create(Order.gen_attrs.merge(:promotion => promotion))
61       order.promotion.should == promotion
62       order.should be_valid
64       order = Order.create(Order.gen_attrs.except(:promotion))
65       order.promotion.should be_nil
66       order.should be_valid
67     end
68   end
69 end