unidom-geo-china 0.5.7 → 0.5.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6fd4c0d9e03b26fe74231108e84f1213bcad8a3f
4
- data.tar.gz: 2b2061f680dfdcc795f8a2ab0abe8756a1e1f380
3
+ metadata.gz: f0c8fbbaead8184aba625abc654d73c50a7d9070
4
+ data.tar.gz: 1e2e037b320f0139fba69b0457825e9ecf8db5ab
5
5
  SHA512:
6
- metadata.gz: a1c6a285032be9c30d0b0dbd39fb5120e2a682b534f44165efabba458b97155dd178578ffc4f8e02d8f169344245608c72dc41576a7e037622ef26f3ef494742
7
- data.tar.gz: 997a811fb875dda09525b31b402b4da90d97ba7ed2ca38d7d196d19739d78df5bc0023da40ff7b7e57a19107110da3e16ba77aaea9a1ca39467f5a58981c80e3
6
+ metadata.gz: 2e2567f1d2bde59f0713334aec9fc5da00880a780dcca69936c88ad7cdf990ac4a6b46bb6656c5ca63e62d28ff428fb5117f4b4616269dfa66a13478746517c8
7
+ data.tar.gz: e3882b5ed976a72c8c81bce624b77640fe2622b6d58dd8dab7f7b3e6279dcb22252c593c0be89cb77dca71fe3cc0c520482c5c1e50440afb93316936360e9147
@@ -54,14 +54,20 @@ class Unidom::Geo::China::Region < Unidom::Geo::China::ApplicationRecord
54
54
  numeric_code[0..1]
55
55
  end
56
56
 
57
+ ##
58
+ # 获取行政区划代码的中间 2 位数字。
57
59
  def numeric_code_middle
58
60
  numeric_code[2..3]
59
61
  end
60
62
 
63
+ ##
64
+ # 获取行政区划代码的后 2 位数字。
61
65
  def numeric_code_suffix
62
66
  numeric_code[4..5]
63
67
  end
64
68
 
69
+ ##
70
+ # 判断行政区划代码的中间 2 位数字是否为 00 。
65
71
  def numeric_code_middle_empty?
66
72
  '00'==numeric_code_middle
67
73
  end
@@ -8,7 +8,7 @@ class Unidom::Geo::China::Town < Unidom::Geo::China::ApplicationRecord
8
8
  include Unidom::Common::Concerns::ModelExtension
9
9
 
10
10
  validates :numeric_code, length: { minimum: self.columns_hash['numeric_code'].limit }, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
11
- validates :name, presence: true, length: { in: 2..self.columns_hash['name'].limit }
11
+ validates :name, presence: true, length: { in: 2..self.columns_hash['name'].limit }
12
12
 
13
13
  belongs_to :region, class_name: 'Unidom::Geo::China::Region'
14
14
 
@@ -8,6 +8,61 @@ describe Unidom::Geo::China::Region, type: :model do
8
8
  after :each do
9
9
  end
10
10
 
11
+ it 'should consider Beijing under a municipality direct under central government' do
12
+ region = described_class.numeric_coded_as('110000').first_or_initialize
13
+ expect(region.under_mducg?).to be_truthy
14
+ end
15
+
16
+ it 'should consider Chaoyang under a municipality direct under central government' do
17
+ region = described_class.numeric_coded_as('110105').first_or_initialize
18
+ expect(region.under_mducg?).to be_truthy
19
+ end
20
+
21
+ it 'should consider Tainjin under a municipality direct under central government' do
22
+ region = described_class.numeric_coded_as('120000').first_or_initialize
23
+ expect(region.under_mducg?).to be_truthy
24
+ end
25
+
26
+ it 'should consider Nankai under a municipality direct under central government' do
27
+ region = described_class.numeric_coded_as('120104').first_or_initialize
28
+ expect(region.under_mducg?).to be_truthy
29
+ end
30
+
31
+ it 'should consider Shanghai under a municipality direct under central government' do
32
+ region = described_class.numeric_coded_as('310000').first_or_initialize
33
+ expect(region.under_mducg?).to be_truthy
34
+ end
35
+
36
+ it 'should consider Xuhui under a municipality direct under central government' do
37
+ region = described_class.numeric_coded_as('310104').first_or_initialize
38
+ expect(region.under_mducg?).to be_truthy
39
+ end
40
+
41
+ it 'should consider Chongqing under a municipality direct under central government' do
42
+ region = described_class.numeric_coded_as('500000').first_or_initialize
43
+ expect(region.under_mducg?).to be_truthy
44
+ end
45
+
46
+ it 'should consider Shapinba under a municipality direct under central government' do
47
+ region = described_class.numeric_coded_as('500106').first_or_initialize
48
+ expect(region.under_mducg?).to be_truthy
49
+ end
50
+
51
+ it 'should not consider Sichuan under a municipality direct under central government' do
52
+ region = described_class.numeric_coded_as('510000').first_or_initialize
53
+ expect(region.under_mducg?).to be_falsey
54
+ end
55
+
56
+ it 'should not consider Chengdu under a municipality direct under central government' do
57
+ region = described_class.numeric_coded_as('510100').first_or_initialize
58
+ expect(region.under_mducg?).to be_falsey
59
+ end
60
+
61
+ it 'should not consider Jinniu under a municipality direct under central government' do
62
+ region = described_class.numeric_coded_as('510106').first_or_initialize
63
+ expect(region.under_mducg?).to be_falsey
64
+ end
65
+
11
66
  context do
12
67
 
13
68
  model_attributes = {
@@ -75,6 +130,15 @@ describe Unidom::Geo::China::Region, type: :model do
75
130
  { attributes_collection: [ model_attributes.merge(scheme_id: SecureRandom.uuid, virtual: true) ], count_diff: 0, args: [ false ] }
76
131
  ]
77
132
 
133
+ it_behaves_like 'scope', :root_level, [
134
+ { attributes_collection: [ model_attributes.merge(scheme_id: SecureRandom.uuid ) ], count_diff: 0, args: [] },
135
+ { attributes_collection: [ model_attributes.merge(scheme_id: SecureRandom.uuid, numeric_code: '999900') ], count_diff: 0, args: [] },
136
+ { attributes_collection: [ model_attributes.merge(scheme_id: SecureRandom.uuid, numeric_code: '999000') ], count_diff: 0, args: [] },
137
+ { attributes_collection: [ model_attributes.merge(scheme_id: SecureRandom.uuid, numeric_code: '990000') ], count_diff: 1, args: [] },
138
+ { attributes_collection: [ model_attributes.merge(scheme_id: SecureRandom.uuid, numeric_code: '900000') ], count_diff: 1, args: [] },
139
+ { attributes_collection: [ model_attributes.merge(scheme_id: SecureRandom.uuid, numeric_code: '000000') ], count_diff: 1, args: [] }
140
+ ]
141
+
78
142
  end
79
143
 
80
144
  end
@@ -1,7 +1,7 @@
1
1
  module Unidom
2
2
  module Geo
3
3
  module China
4
- VERSION = '0.5.7'.freeze
4
+ VERSION = '0.5.8'.freeze
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unidom-geo-china
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Topbit Du
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-30 00:00:00.000000000 Z
11
+ date: 2017-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unidom-geo