1 require File.join( File.dirname(__FILE__), "..", "spec_helper" )
5 DataMapper.auto_migrate!
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
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)
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
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)
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
39 order = Order.create(Order.gen_attrs.except(:transactions))
40 order.transactions.should be_empty
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
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)
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
64 order = Order.create(Order.gen_attrs.except(:promotion))
65 order.promotion.should be_nil