[ARVADOS] updated: 333402104e6b7a163bf3f8483a928dbe571b5c2c
git at public.curoverse.com
git at public.curoverse.com
Mon Nov 24 14:16:16 EST 2014
Summary of changes:
.../api/app/controllers/application_controller.rb | 8 ++---
.../test/functional/application_controller_test.rb | 35 +++++++++++++++++++++-
2 files changed, 38 insertions(+), 5 deletions(-)
via 333402104e6b7a163bf3f8483a928dbe571b5c2c (commit)
from 60cf64002cee6af43fe8b6a122c104a12c1fd7bf (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 333402104e6b7a163bf3f8483a928dbe571b5c2c
Author: Tom Clegg <tom at curoverse.com>
Date: Mon Nov 24 14:07:26 2014 -0500
4651: Fix exceptions. Accept 0 for false, 1 for true.
diff --git a/services/api/app/controllers/application_controller.rb b/services/api/app/controllers/application_controller.rb
index 5013c09..459adff 100644
--- a/services/api/app/controllers/application_controller.rb
+++ b/services/api/app/controllers/application_controller.rb
@@ -451,18 +451,18 @@ class ApplicationController < ActionController::Base
(self.class.send "_#{params[:action]}_requires_parameters" rescue {}).
each do |key, info|
if info[:required] and not params.include?(key)
- raise ArgumentError("#{key} parameter is required")
+ raise ArgumentError.new("#{key} parameter is required")
elsif info[:type] == 'boolean'
# Make sure params[key] is either true or false -- not a
# string, not nil, etc.
if not params.include?(key)
params[key] = info[:default]
- elsif [false, 'false'].include? params[key]
+ elsif [false, 'false', '0', 0].include? params[key]
params[key] = false
- elsif [true, 'true'].include? params[key]
+ elsif [true, 'true', '1', 1].include? params[key]
params[key] = true
else
- raise TypeError("#{key} parameter must be a boolean, true or false")
+ raise TypeError.new("#{key} parameter must be a boolean, true or false")
end
end
end
diff --git a/services/api/test/functional/application_controller_test.rb b/services/api/test/functional/application_controller_test.rb
index 9aad981..3a4a244 100644
--- a/services/api/test/functional/application_controller_test.rb
+++ b/services/api/test/functional/application_controller_test.rb
@@ -49,12 +49,45 @@ class ApplicationControllerTest < ActionController::TestCase
['foo', '', 'FALSE', 'TRUE', nil, [true], {a:true}, '"true"'].each do |bogus|
test "bogus boolean parameter #{bogus.inspect} returns error" do
+ @controller = Arvados::V1::GroupsController.new
authorize_with :active
post :create, {
- specimen: {},
+ group: {},
ensure_unique_name: bogus
}
assert_response 422
+ assert_match(/parameter must be a boolean/, json_response['errors'].first,
+ 'Helpful error message not found')
+ end
+ end
+
+ [[true, [true, 'true', 1, '1']],
+ [false, [false, 'false', 0, '0']]].each do |bool, boolparams|
+ boolparams.each do |boolparam|
+ # Ensure boolparam is acceptable as a boolean
+ test "boolean parameter #{boolparam.inspect} acceptable" do
+ @controller = Arvados::V1::GroupsController.new
+ authorize_with :active
+ post :create, {
+ group: {},
+ ensure_unique_name: boolparam
+ }
+ assert_response :success
+ end
+
+ # Ensure boolparam is acceptable as the _intended_ boolean
+ test "boolean parameter #{boolparam.inspect} accepted as #{bool.inspect}" do
+ @controller = Arvados::V1::GroupsController.new
+ authorize_with :active
+ post :create, {
+ group: {
+ name: groups(:aproject).name,
+ owner_uuid: groups(:aproject).owner_uuid
+ },
+ ensure_unique_name: boolparam
+ }
+ assert_response (bool ? :success : 422)
+ end
end
end
end
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list