fix index check, add test cases (#1993)

This commit is contained in:
William Cheng 2019-01-27 21:18:20 +08:00 committed by GitHub
parent c438f67b66
commit 9029103c94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 6 deletions

View File

@ -261,8 +261,8 @@ module {{moduleName}}
servers = server_settings
# check array index out of bound
if (index < 0 || index > servers.size)
fail ArgumentError "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
if (index < 0 || index >= servers.size)
fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
end
server = servers[index]

View File

@ -245,8 +245,8 @@ module Petstore
servers = server_settings
# check array index out of bound
if (index < 0 || index > servers.size)
fail ArgumentError "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
if (index < 0 || index >= servers.size)
fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
end
server = servers[index]

View File

@ -278,8 +278,8 @@ module Petstore
servers = server_settings
# check array index out of bound
if (index < 0 || index > servers.size)
fail ArgumentError "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
if (index < 0 || index >= servers.size)
fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
end
server = servers[index]

View File

@ -51,5 +51,9 @@ describe Petstore::Configuration do
it 'should raise error due to invalid enum value' do
expect{config.server_url(1, version: "v6")}.to raise_error(ArgumentError)
end
it 'should raise error due to invalid index' do
expect{config.server_url(2)}.to raise_error(ArgumentError)
end
end
end