1 require File.join( File.dirname(__FILE__), "..", "spec_helper" )
5 describe "associations" do
6 it "should have many (0..*) states" do
8 country.should respond_to(:states)
11 it "should have many (0..*) provinces (alias for states)" do
13 country.should respond_to(:provinces)
18 @country = Country.new
19 #Country.auto_migrate! # clear db table
22 it "should be valid" do
23 @country.name = "Andorra"
24 @country.should be_valid
27 it "should have a name field" do
29 @country.errors.on(:name).should_not be_nil
32 it "should have a unique name field" do
33 country1 = Country.new(:code => "FR", :name => "France")
34 country2 = Country.new(:code => "ZZ", :name => "France")
35 country1.save.should be_true
36 country1.name = "France"
37 country2.save.should be_false
38 country2.errors.on(:name).should_not be_nil
41 it "should have a code field" do
42 @country.name = "Lithuania"
44 @country.should be_valid