Skip to content

Commit

Permalink
Merge pull request #19 from k-motoyan/issue_18
Browse files Browse the repository at this point in the history
JpPrefecture::Prefecture.find(name: xxx)の挙動を修正
  • Loading branch information
chocoby committed Mar 30, 2016
2 parents 84ba9dd + 38db914 commit 31c506a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/jp_prefecture/prefecture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def self.all
# @return [Integer] 見つかった場合は都道府県コード
# @return [nil] 見つからない場合は nil
def self.find_code_by_name(name)
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

0 comments on commit 31c506a

Please sign in to comment.