Make Language methods more resilient to non-String input (#3752)

* Add failing test for finding with non-String input

Show the failing behaviour of find_by_alias, find_by_name, and []
when non-String input is provided.

* Return nil rather than erroring on non-String input
This commit is contained in:
James Dennes
2017-08-02 14:07:44 +02:00
committed by GitHub
parent f75c5707a6
commit 3391dcce6a
2 changed files with 9 additions and 3 deletions

View File

@@ -270,6 +270,12 @@ class TestLanguage < Minitest::Test
assert_nil Language[""]
end
def test_does_not_blow_up_with_non_string_lookup
assert_nil Language.find_by_alias(true)
assert_nil Language.find_by_name(true)
assert_nil Language[true]
end
def test_name
assert_equal 'Perl', Language['Perl'].name
assert_equal 'Python', Language['Python'].name