Added Weight specs. Shuffling things around.
[merb_mart.git] / spec / models / state_spec.rb
blob80579537d3d20d69666ded01fa60f9b9abf1aaa1
1 require File.join( File.dirname(__FILE__), "..", "spec_helper" )
3 describe State do
4   before(:each) do
5     DataMapper.auto_migrate!
6     @state = State.gen
7   end
9   describe "associations" do
10     it "should belong to a country" do
11       state = State.gen
12       state.should respond_to(:country)
13       state.country.states.should include(state)
14       state.should respond_to(:country=)
15       state.should respond_to(:country_code)
16     end
17   end
19   before(:each) do
20     State.auto_migrate!  # clear db table
21   end
23   it "should have a composite key, made up of ISO 3166-1 alpha-2 country code
24       and state abbreviation" do
25     maine  = State.new(:country_code => "US", :abbr => "ME", :name => "Maine")
26     alaska = State.new(:country_code => "US", :abbr => "AK", :name => "Alaska")
27     bremen = State.new(:country_code => "DE", :abbr => "HB", :name => "Bremen")
29     maine.save
30     alaska.save
31     bremen.save
33     #State["US", "AK"]  ## FIXME
34     alaska = State.get("US", "AK")
35     alaska.should_not be_nil
36     alaska.key.first.should == "US"
37     alaska.key.last.should == "AK"
38     alaska.name.should == "Alaska"
40     #bremen = State["DE", "HB"]  ## FIXME
41     bremen = State.get("DE", "HB")
42     bremen.should_not be_nil
43     bremen.key.should == ["DE", "HB"]
44     bremen.name.should == "Bremen"
45   end
47 end