jp_prefecture 0.11.0 → 1.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/spec/config_spec.rb DELETED
@@ -1,18 +0,0 @@
1
- # coding: utf-8
2
- require 'spec_helper'
3
-
4
- describe JpPrefecture::Config do
5
- describe '#mapping_data' do
6
- context 'カスタマイズされたprefecture.ymlを使うとき' do
7
- before do
8
- filepath = File.join(File.dirname(__FILE__), 'fixtures/prefecture.yml')
9
- @config = described_class.new
10
- @config.mapping_data = YAML.load_file filepath
11
- end
12
-
13
- it '都道府県+海外の数が48であること' do
14
- expect(@config.mapping_data.count).to eq 48
15
- end
16
- end
17
- end
18
- end
@@ -1,148 +0,0 @@
1
- # JIS X 0402 で定義されている都道府県コードと都道府県名をベースに
2
- # コードがゼロから始まるもの(09 など)を 1 ケタにし、
3
- # さらに、「海外」をcode: 48として追加したもの
4
- ---
5
- 1:
6
- :name: 北海道
7
- :name_e: hokkaido
8
- 2:
9
- :name: 青森県
10
- :name_e: aomori
11
- 3:
12
- :name: 岩手県
13
- :name_e: iwate
14
- 4:
15
- :name: 宮城県
16
- :name_e: miyagi
17
- 5:
18
- :name: 秋田県
19
- :name_e: akita
20
- 6:
21
- :name: 山形県
22
- :name_e: yamagata
23
- 7:
24
- :name: 福島県
25
- :name_e: fukushima
26
- 8:
27
- :name: 茨城県
28
- :name_e: ibaraki
29
- 9:
30
- :name: 栃木県
31
- :name_e: tochigi
32
- 10:
33
- :name: 群馬県
34
- :name_e: gunma
35
- 11:
36
- :name: 埼玉県
37
- :name_e: saitama
38
- 12:
39
- :name: 千葉県
40
- :name_e: chiba
41
- 13:
42
- :name: 東京都
43
- :name_e: tokyo
44
- 14:
45
- :name: 神奈川県
46
- :name_e: kanagawa
47
- 15:
48
- :name: 新潟県
49
- :name_e: niigata
50
- 16:
51
- :name: 富山県
52
- :name_e: toyama
53
- 17:
54
- :name: 石川県
55
- :name_e: ishikawa
56
- 18:
57
- :name: 福井県
58
- :name_e: fukui
59
- 19:
60
- :name: 山梨県
61
- :name_e: yamanashi
62
- 20:
63
- :name: 長野県
64
- :name_e: nagano
65
- 21:
66
- :name: 岐阜県
67
- :name_e: gifu
68
- 22:
69
- :name: 静岡県
70
- :name_e: shizuoka
71
- 23:
72
- :name: 愛知県
73
- :name_e: aichi
74
- 24:
75
- :name: 三重県
76
- :name_e: mie
77
- 25:
78
- :name: 滋賀県
79
- :name_e: shiga
80
- 26:
81
- :name: 京都府
82
- :name_e: kyoto
83
- 27:
84
- :name: 大阪府
85
- :name_e: osaka
86
- 28:
87
- :name: 兵庫県
88
- :name_e: hyogo
89
- 29:
90
- :name: 奈良県
91
- :name_e: nara
92
- 30:
93
- :name: 和歌山県
94
- :name_e: wakayama
95
- 31:
96
- :name: 鳥取県
97
- :name_e: tottori
98
- 32:
99
- :name: 島根県
100
- :name_e: shimane
101
- 33:
102
- :name: 岡山県
103
- :name_e: okayama
104
- 34:
105
- :name: 広島県
106
- :name_e: hiroshima
107
- 35:
108
- :name: 山口県
109
- :name_e: yamaguchi
110
- 36:
111
- :name: 徳島県
112
- :name_e: tokushima
113
- 37:
114
- :name: 香川県
115
- :name_e: kagawa
116
- 38:
117
- :name: 愛媛県
118
- :name_e: ehime
119
- 39:
120
- :name: 高知県
121
- :name_e: kochi
122
- 40:
123
- :name: 福岡県
124
- :name_e: fukuoka
125
- 41:
126
- :name: 佐賀県
127
- :name_e: saga
128
- 42:
129
- :name: 長崎県
130
- :name_e: nagasaki
131
- 43:
132
- :name: 熊本県
133
- :name_e: kumamoto
134
- 44:
135
- :name: 大分県
136
- :name_e: oita
137
- 45:
138
- :name: 宮崎県
139
- :name_e: miyazaki
140
- 46:
141
- :name: 鹿児島県
142
- :name_e: kagoshima
143
- 47:
144
- :name: 沖縄県
145
- :name_e: okinawa
146
- 48:
147
- :name: 海外
148
- :name_e: foreign_country
@@ -1,36 +0,0 @@
1
- # coding: utf-8
2
- require 'spec_helper'
3
-
4
- describe JpPrefecture do
5
- describe '.included' do
6
- subject do
7
- Class.new(ActiveRecord::Base) do
8
- include JpPrefecture
9
- end
10
- end
11
-
12
- it { is_expected.to respond_to(:jp_prefecture) }
13
- end
14
-
15
- describe 'include されていない' do
16
- subject { Class.new(ActiveRecord::Base) }
17
- it { is_expected.not_to respond_to(:jp_prefecture) }
18
- end
19
-
20
- describe '.setup' do
21
- before do
22
- filepath = File.join(File.dirname(__FILE__), 'fixtures/prefecture.yml')
23
- JpPrefecture.setup do |config|
24
- config.mapping_data = YAML.load_file filepath
25
- end
26
- end
27
-
28
- after do
29
- JpPrefecture.setup do |config|
30
- config.mapping_data = nil
31
- end
32
- end
33
-
34
- it { expect(JpPrefecture::Mapping.data.count).to eq 48 }
35
- end
36
- end
data/spec/mapping_spec.rb DELETED
@@ -1,10 +0,0 @@
1
- # coding: utf-8
2
- require 'spec_helper'
3
-
4
- describe JpPrefecture::Mapping do
5
- describe '.data' do
6
- it '都道府県の数が47であること' do
7
- expect(described_class.data.count).to eq 47
8
- end
9
- end
10
- end
@@ -1,175 +0,0 @@
1
- # coding: utf-8
2
- require 'spec_helper'
3
-
4
- describe JpPrefecture::Prefecture do
5
- describe '.build' do
6
- let(:pref) { JpPrefecture::Prefecture.build(1, '北海道', 'Hokkaido', 'ほっかいどう', 'ホッカイドウ', '北海道') }
7
- it { expect(pref.code).to eq 1 }
8
- it { expect(pref.name).to eq '北海道' }
9
- it { expect(pref.name_e).to eq 'Hokkaido' }
10
- it { expect(pref.name_h).to eq 'ほっかいどう' }
11
- it { expect(pref.name_k).to eq 'ホッカイドウ' }
12
- it { expect(pref.zips).to eq [10000..70895, 400000..996509] }
13
- it { expect(pref.area).to eq '北海道' }
14
- it { expect(pref.type).to eq '道' }
15
-
16
- let(:nil_type_pref) { JpPrefecture::Prefecture.build(13, '東京', 'Tokyo', 'とうきょう', 'トウキョウ', '関東') }
17
- it { expect(nil_type_pref.code).to eq 13 }
18
- it { expect(nil_type_pref.name).to eq '東京' }
19
- it { expect(nil_type_pref.name_e).to eq 'Tokyo' }
20
- it { expect(nil_type_pref.name_h).to eq 'とうきょう' }
21
- it { expect(nil_type_pref.name_k).to eq 'トウキョウ' }
22
- it { expect(nil_type_pref.zips).to eq [1000000..2080035] }
23
- it { expect(nil_type_pref.area).to eq '関東' }
24
- it { expect(nil_type_pref.type).to eq nil }
25
- end
26
-
27
- describe '.find' do
28
- describe '検索結果について' do
29
- shared_examples "都道府県が見つかる" do |arg|
30
- let(:pref) { JpPrefecture::Prefecture.find(arg) }
31
- it { expect(pref.code).to eq 1 }
32
- it { expect(pref.name).to eq '北海道' }
33
- it { expect(pref.name_e).to eq 'Hokkaido' }
34
- it { expect(pref.name_h).to eq 'ほっかいどう' }
35
- it { expect(pref.name_k).to eq 'ホッカイドウ' }
36
- it { expect(pref.zips).to eq [10000..70895, 400000..996509] }
37
- it { expect(pref.area).to eq '北海道' }
38
- it { expect(pref.type).to eq '道' }
39
- end
40
-
41
- shared_examples '都道府県が見つからない' do |arg|
42
- let(:pref) { JpPrefecture::Prefecture.find(arg) }
43
- it { expect(pref).to be_nil }
44
- end
45
-
46
- describe '都道府県コード' do
47
- it_behaves_like "都道府県が見つかる", 1
48
- it_behaves_like "都道府県が見つからない", 99
49
- it_behaves_like "都道府県が見つかる", "1"
50
- it_behaves_like "都道府県が見つかる", "01"
51
- it_behaves_like "都道府県が見つからない", "99"
52
- end
53
-
54
- describe '都道府県コード(キーワード引数)' do
55
- it_behaves_like "都道府県が見つかる", code: 1
56
- it_behaves_like "都道府県が見つからない", code: 99
57
- it_behaves_like "都道府県が見つかる", code: "1"
58
- it_behaves_like "都道府県が見つかる", code: "01"
59
- it_behaves_like "都道府県が見つからない", code: "99"
60
- end
61
-
62
- describe '都道府県名' do
63
- it_behaves_like "都道府県が見つかる", name: "北海道"
64
- it_behaves_like "都道府県が見つからない", name: "うどん県"
65
- end
66
-
67
- describe '都道府県名(英語表記)' do
68
- it_behaves_like "都道府県が見つかる", name: "Hokkaido"
69
- it_behaves_like "都道府県が見つからない", name: "Udon"
70
- end
71
-
72
- describe '都道府県名(英語表記-小文字)' do
73
- it_behaves_like "都道府県が見つかる", name: "hokkaido"
74
- it_behaves_like "都道府県が見つからない", name: "udon"
75
- end
76
-
77
- describe '都道府県名(ひらがな表記)' do
78
- it_behaves_like "都道府県が見つかる", name: "ほっかいどう"
79
- it_behaves_like "都道府県が見つからない", name: "うどん"
80
- end
81
-
82
- describe '都道府県名(カタカナ表記)' do
83
- it_behaves_like "都道府県が見つかる", name: "ホッカイドウ"
84
- it_behaves_like "都道府県が見つからない", name: "ウドン"
85
- end
86
-
87
- describe '都道府県名(前方一致)' do
88
- let(:pref) { JpPrefecture::Prefecture.find(name: '東京') }
89
- it { expect(pref.name).to eq '東京都' }
90
-
91
- let(:pref2) { JpPrefecture::Prefecture.find(name: '京都') }
92
- it { expect(pref2.name).to eq '京都府' }
93
-
94
- context 'マッチする都道府県が複数あった場合' do
95
- let(:pref) { JpPrefecture::Prefecture.find(name: '宮') }
96
- it { expect(pref.name).to eq '宮城県' }
97
- end
98
-
99
- context 'マッチする都道府県が複数あった場合(英語表記)' do
100
- let(:pref) { JpPrefecture::Prefecture.find(name: 'miya') }
101
- it { expect(pref.name_e).to eq 'Miyagi' }
102
-
103
- let(:pref2) { JpPrefecture::Prefecture.find(name: 'Miya') }
104
- it { expect(pref2.name_e).to eq 'Miyagi' }
105
- end
106
-
107
- context 'マッチする都道府県が複数あった場合(ひらがな表記)' do
108
- let(:pref) { JpPrefecture::Prefecture.find(name: 'みや') }
109
- it { expect(pref.name_h).to eq 'みやぎけん' }
110
- end
111
-
112
- context 'マッチする都道府県が複数あった場合(カタカナ表記)' do
113
- let(:pref) { JpPrefecture::Prefecture.find(name: 'ミヤ') }
114
- it { expect(pref.name_k).to eq 'ミヤギケン' }
115
- end
116
- end
117
- end
118
-
119
- describe '渡した変数について' do
120
- context 'string の場合' do
121
- it '値が変更されないこと' do
122
- code = '1'
123
- JpPrefecture::Prefecture.find(code)
124
- expect(code).to eq '1'
125
- end
126
- end
127
-
128
- context 'code が string の場合' do
129
- it '値が変更されないこと' do
130
- code = '1'
131
- JpPrefecture::Prefecture.find(code: code)
132
- expect(code).to eq '1'
133
- end
134
- end
135
-
136
- context 'name の場合' do
137
- it '値が変更されないこと' do
138
- name = 'hokkaido'
139
- JpPrefecture::Prefecture.find(name: name)
140
- expect(name).to eq 'hokkaido'
141
- end
142
-
143
- context '空の文字列が与えられた場合' do
144
- it 'nilを返すこと' do
145
- actual = JpPrefecture::Prefecture.find(name: '')
146
- expect(actual).to be_nil
147
- end
148
- end
149
-
150
- context 'nilが与えられた場合' do
151
- it 'nilを返すこと' do
152
- actual = JpPrefecture::Prefecture.find(name: nil)
153
- expect(actual).to be_nil
154
- end
155
- end
156
- end
157
-
158
- context 'zip の場合' do
159
- it '値が変更されないこと' do
160
- zip = '9999999'
161
- JpPrefecture::Prefecture.find(zip: zip)
162
- expect(zip).to eq '9999999'
163
- end
164
- end
165
- end
166
- end
167
-
168
- describe '.all' do
169
- let(:prefs) { JpPrefecture::Prefecture.all }
170
- it { expect(prefs.first).to be_an_instance_of(JpPrefecture::Prefecture) }
171
- it '都道府県の数が 47 であること' do
172
- expect(prefs.count).to eq 47
173
- end
174
- end
175
- end
data/spec/spec_helper.rb DELETED
@@ -1,41 +0,0 @@
1
- # coding: utf-8
2
- if ENV['CI']
3
- require 'simplecov'
4
- require 'simplecov-lcov'
5
- SimpleCov::Formatter::LcovFormatter.config do |c|
6
- c.report_with_single_file = true
7
- c.single_report_path = "coverage/lcov.info"
8
- end
9
- SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter
10
- SimpleCov.start
11
- end
12
-
13
- require "jp_prefecture"
14
- require "active_record"
15
-
16
- RSpec.configure do |config|
17
- config.before(:suite) do
18
- setup_db
19
- end
20
-
21
- config.after(:suite) do
22
- teardown_db
23
- end
24
- end
25
-
26
- def setup_db
27
- ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
28
-
29
- ActiveRecord::Schema.define(version: 1) do
30
- create_table :places do |t|
31
- t.integer :prefecture_code
32
- t.integer :prefecture_id
33
- end
34
- end
35
- end
36
-
37
- def teardown_db
38
- ActiveRecord::Base.connection.tables.each do |table|
39
- ActiveRecord::Base.connection.drop_table(table)
40
- end
41
- end
@@ -1,10 +0,0 @@
1
- # coding: utf-8
2
- require 'spec_helper'
3
-
4
- describe JpPrefecture::ZipMapping do
5
- describe '.data' do
6
- it '都道府県の数が47であること' do
7
- expect(described_class.data.count).to eq 47
8
- end
9
- end
10
- end