Skip to content

Commit

Permalink
Merge pull request #4 from iNecas/array-validator-fix
Browse files Browse the repository at this point in the history
array validator not accepting boolean attributes
  • Loading branch information
Pajk committed Apr 25, 2012
2 parents 40fd278 + b495ac9 commit 5805a5a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 12 deletions.
12 changes: 1 addition & 11 deletions lib/restapi/validator.rb
Expand Up @@ -116,17 +116,7 @@ def initialize(param_description, argument)
end

def validate(value)

@array.find do |expected|
expected_class = expected.class
expected_class = Integer if expected_class == Fixnum
begin
converted_value = Kernel.send(expected_class.to_s, value)
rescue ArgumentError
false
end
converted_value === expected
end
@array.include?(value)
end

def self.build(param_description, argument, options, proc)
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/users_controller_spec.rb
Expand Up @@ -155,7 +155,7 @@
assert_response :success
get :show, :id => 5, :session => "secret_hash", :array_param => 1
assert_response :success
get :show, :id => 5, :session => "secret_hash", :array_param => "2"
get :show, :id => 5, :session => "secret_hash", :boolean_param => false
assert_response :success
end

Expand Down
1 change: 1 addition & 0 deletions spec/dummy/app/controllers/users_controller.rb
Expand Up @@ -47,6 +47,7 @@ class UsersController < ApplicationController
param :float_param, Float, :desc => "float param"
param :regexp_param, /^[0-9]* years/, :desc => "regexp param"
param :array_param, [100, "one", "two", 1, 2], :desc => "array validator"
param :boolean_param, [true, false], :desc => "array validator with boolean"
param :proc_param, lambda { |val|
val == "param value" ? true : "The only good value is 'param value'."
}, :desc => "proc validator"
Expand Down

0 comments on commit 5805a5a

Please sign in to comment.