1 require File.join( File.dirname(__FILE__), "..", "spec_helper" )
6 DataMapper.auto_migrate!
10 describe "associations" do
11 it "should belong to a country" do
13 state.should respond_to(:country)
14 state.country.states.should include(state)
15 state.should respond_to(:country=)
16 state.should respond_to(:country_code)
21 State.auto_migrate! # clear db table
24 it "should have a composite key, made up of ISO 3166-1 alpha-2 country code
25 and state abbreviation" do
26 maine = State.new(:country_code => "US", :abbr => "ME", :name => "Maine")
27 alaska = State.new(:country_code => "US", :abbr => "AK", :name => "Alaska")
28 bremen = State.new(:country_code => "DE", :abbr => "HB", :name => "Bremen")
34 #State["US", "AK"] ## FIXME
35 alaska = State.get("US", "AK")
36 alaska.should_not be_nil
37 alaska.key.first.should == "US"
38 alaska.key.last.should == "AK"
39 alaska.name.should == "Alaska"
41 #bremen = State["DE", "HB"] ## FIXME
42 bremen = State.get("DE", "HB")
43 bremen.should_not be_nil
44 bremen.key.should == ["DE", "HB"]
45 bremen.name.should == "Bremen"