taiwan_city_spec.rb 2.5 KB

123456789101112131415161718192021222324252627282930313233
  1. # encoding: utf-8
  2. require 'spec_helper'
  3. describe TaiwanCity do
  4. it 'should be list' do
  5. # 省
  6. TaiwanCity.list.should eql [["北京市", "110000"], ["天津市", "120000"], ["河北省", "130000"], ["山西省", "140000"], ["内蒙古自治区", "150000"], ["辽宁省", "210000"], ["吉林省", "220000"], ["黑龙江省", "230000"], ["上海市", "310000"], ["江苏省", "320000"], ["浙江省", "330000"], ["安徽省", "340000"], ["福建省", "350000"], ["江西省", "360000"], ["山东省", "370000"], ["河南省", "410000"], ["湖北省", "420000"], ["湖南省", "430000"], ["广东省", "440000"], ["广西壮族自治区", "450000"], ["海南省", "460000"], ["重庆市", "500000"], ["四川省", "510000"], ["贵州省", "520000"], ["云南省", "530000"], ["西藏自治区", "540000"], ["陕西省", "610000"], ["甘肃省", "620000"], ["青海省", "630000"], ["宁夏回族自治区", "640000"], ["新疆维吾尔自治区", "650000"]]
  7. #市
  8. TaiwanCity.list('440000').should eql [["广州市", "440100"], ["韶关市", "440200"], ["深圳市", "440300"], ["珠海市", "440400"], ["汕头市", "440500"], ["佛山市", "440600"], ["江门市", "440700"], ["湛江市", "440800"], ["茂名市", "440900"], ["肇庆市", "441200"], ["惠州市", "441300"], ["梅州市", "441400"], ["汕尾市", "441500"], ["河源市", "441600"], ["阳江市", "441700"], ["清远市", "441800"], ["东莞市", "441900"], ["中山市", "442000"], ["潮州市", "445100"], ["揭阳市", "445200"], ["云浮市", "445300"]]
  9. #区
  10. TaiwanCity.list('440300').should eql [["市辖区", "440301"], ["罗湖区", "440303"], ["福田区", "440304"], ["南山区", "440305"], ["宝安区", "440306"], ["龙岗区", "440307"], ["盐田区", "440308"]]
  11. end
  12. it 'should be get' do
  13. TaiwanCity.get('440000').should eql '广东省'
  14. TaiwanCity.get('440300').should eql '深圳市'
  15. TaiwanCity.get('440305').should eql '南山区'
  16. TaiwanCity.get('440000', prepend_parent: true).should eql '广东省'
  17. TaiwanCity.get('440300', prepend_parent: true).should eql '广东省深圳市'
  18. TaiwanCity.get('440305', prepend_parent: true).should eql '广东省深圳市南山区'
  19. end
  20. it 'should be parse' do # 可以直接获取省、市
  21. TaiwanCity.province('440000').should eql '440000' # 省
  22. TaiwanCity.city('440000').should eql '440000'
  23. TaiwanCity.province('440300').should eql '440000' # 市
  24. TaiwanCity.city('440300').should eql '440300'
  25. TaiwanCity.province('440305').should eql '440000' # 区
  26. TaiwanCity.city('440305').should eql '440300'
  27. end
  28. end