1 require File.join( File.dirname(__FILE__), "..", "spec_helper" )
5 describe "associations" do
6 it "should belong to a country" do
8 address.should respond_to(:country)
9 address.should respond_to(:country=)
12 it "should belong to a state" do
14 address.should respond_to(:state)
15 address.should respond_to(:state=)
18 it "should belong to a province (alias for state)" do
19 #state = mock("state")
21 address.should respond_to(:province)
22 address.should respond_to(:province=)
23 #address.province = state
27 it "should require a zip, telephone, last name, first name and address" do
30 address.errors.on(:first_name).should_not be_nil
31 address.errors.on(:last_name).should_not be_nil
32 address.errors.on(:address1).should_not be_nil
33 address.errors.on(:postal_code).should_not be_nil
34 address.first_name = "John"
35 address.last_name = "Doe"
36 address.address1 = "1012 E 87th St"
37 address.postal_code = "10021"
38 address.should be_valid
41 it "should provide the zipcode alias for postal code" do
42 address1 = Address.new
43 address1.postal_code = "91210"
44 address1.zipcode.should == "91210"
45 address2 = Address.new
46 address2.zipcode = "10004"
47 address2.postal_code.should == "10004"
50 it "should limit the first name to be a maximum of 50 characters" do
53 address.first_name = "a" * num
55 address.errors.on(:first_name).should be_nil
58 address.first_name = "a" * 51
60 address.errors.on(:first_name).should_not be_nil
63 it "should limit the last name to be a maximum of 50 characters" do
66 address.last_name = "z" * num
68 address.errors.on(:last_name).should be_nil
71 address.last_name = "z" * 51
73 address.errors.on(:last_name).should_not be_nil
76 it "should limit the address to a maximum of 255 characters"
78 #it "should not allow PO Box or variants to be entered as an address"
80 it "should provide a name" do
82 address.first_name = "John"
83 address.last_name = "Doe"
84 address.name.should == "John Doe"