1 require File.join( File.dirname(__FILE__), "..", "spec_helper" )
6 DataMapper.auto_migrate!
9 describe "associations" do
10 it "should belong to a country" do
12 address.should respond_to(:country)
13 address.should respond_to(:country=)
16 it "should belong to a state" do
18 address.should respond_to(:state)
19 address.should respond_to(:state=)
22 it "should belong to a province (alias for state)" do
23 #state = mock("state")
25 address.should respond_to(:province)
26 address.should respond_to(:province=)
27 #address.province = state
31 it "should require a postal_code, last name, first name and address" do
32 Address.create(Address.gen_attrs.except(:postal_code)).should_not be_valid
33 Address.create(Address.gen_attrs.except(:last_name)).should_not be_valid
34 Address.create(Address.gen_attrs.except(:first_name)).should_not be_valid
35 Address.create(Address.gen_attrs.except(:address1)).should_not be_valid
38 it "should provide the zipcode alias for postal code" do
40 address.zipcode.should == address.postal_code
43 it "should limit the first name to be a maximum of 50 characters" do
45 Address.gen(:first_name => "a" * num).should be_valid
48 Address.gen(:first_name => "a" * 51).should_not be_valid
51 it "should limit the last name to be a maximum of 50 characters" do
53 Address.gen(:last_name => "a" * num).should be_valid
56 Address.gen(:last_name => "a" * 51).should_not be_valid
59 it "should limit the address to a maximum of 200 characters" do
61 Address.gen(:address1 => "a" * num).should be_valid
64 Address.gen(:address1 => "a" * 201).should_not be_valid
67 #it "should not allow PO Box or variants to be entered as an address"
69 it "should provide a name" do
70 Address.gen(:first_name => 'John', :last_name => 'Doe').name.should == 'John Doe'