Model refactorings and further expansion of specs
[merb_mart.git] / spec / models / address_spec.rb
blob2d1fc78a1ac19998e366d383cf1ae7edaf77e53d
1 require File.join( File.dirname(__FILE__), "..", "spec_helper" )
3 describe Address do
5   describe "associations" do
6     it "should belong to a country" do
7       address = Address.new
8       address.should respond_to(:country)
9       address.should respond_to(:country=)
10     end
11     
12     it "should belong to a state" do
13       address = Address.new
14       address.should respond_to(:state)
15       address.should respond_to(:state=)
16     end
17     
18     it "should belong to a province (alias for state)" do
19       #state = mock("state")
20       address = Address.new
21       address.should respond_to(:province)
22       address.should respond_to(:province=)
23       #address.province = state
24     end
25   end
26   
27   it "should require a zip, telephone, last name, first name and address" do
28     address = Address.new
29     address.valid?
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
39   end
40   
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"
48   end
49   
50   it "should limit the first name to be a maximum of 50 characters" do
51     address = Address.new
52     [3,50].each do |num|
53       address.first_name = "a" * num
54       address.valid?
55       address.errors.on(:first_name).should be_nil
56     end
57     
58     address.first_name = "a" * 51
59     address.valid?
60     address.errors.on(:first_name).should_not be_nil
61   end
62   
63   it "should limit the last name to be a maximum of 50 characters" do
64     address = Address.new
65     [3,50].each do |num|
66       address.last_name = "z" * num
67       address.valid?
68       address.errors.on(:last_name).should be_nil
69     end
70     
71     address.last_name = "z" * 51
72     address.valid?
73     address.errors.on(:last_name).should_not be_nil
74   end
75   
76   it "should limit the address to a maximum of 255 characters"
77   
78   #it "should not allow PO Box or variants to be entered as an address"
79   
80   it "should provide a name" do
81     address = Address.new
82     address.first_name = "John"
83     address.last_name = "Doe"
84     address.name.should == "John Doe"
85   end
87 end