Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JpPrefecture::Prefecture.find(name: xxx)の挙動を修正 #19

Merged
merged 3 commits into from
Mar 30, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/jp_prefecture/prefecture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ def self.all
# @return [Integer] 見つかった場合は都道府県コード
# @return [nil] 見つからない場合は nil
def self.find_code_by_name(name)
# nameがnil、空文字の場合は見つからないと判断してnilを返す。
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コードだけで説明できていますので、コメントは削除してもらっても良いですか?

return nil if name.nil? || name.empty?

name = name.downcase

Mapping.data.each do |m|
Expand Down
14 changes: 14 additions & 0 deletions spec/prefecture_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,20 @@
JpPrefecture::Prefecture.find(name: name)
expect(name).to eq 'hokkaido'
end

context '空の文字列が与えられた場合' do
it 'nilを返すこと' do
actual = JpPrefecture::Prefecture.find(name: '')
expect(actual).to be_nil
end
end

context 'nilが与えられた場合' do
it 'nilを返すこと' do
actual = JpPrefecture::Prefecture.find(name: nil)
expect(actual).to be_nil
end
end
end

context 'zip の場合' do
Expand Down