Fix exceptions when name searches receive non-String values - #89
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JpPrefecture::Prefecture.findのメソッドドキュメントのall_fieldsに Integer を許容すると書いていたが、実装は String 前提のempty?/downcaseを呼ぶため例外になっていた。find(all_fields: 13)→ NoMethodErrorfind(name: 1)→ NoMethodErrorfind(name_e: :hokkaido)→ TypeErrorfind_codeの String 系の分岐でvalueをto_sして渡すようにした。あわせて
JpPrefecture::Prefecture.findのドキュメントから Integer を削除。マッピングの検索対象は:name/:name_e/:name_r/:name_h/:name_k/:areaの 6 つで都道府県コードを含まないため、Integer を渡しても必ず nil になり実態と合っていなかった。互換性
破壊的変更はない。これまで例外だった入力が nil または検索成功に変わる。
なお
find(code: :foo)/find(zip: :foo)はSymbol#to_iがないため引き続き NoMethodError が発生する。数値系フィールドに Symbol を渡すのは想定外の使い方と判断し、今回は対象外としている。