Permalink
Browse files

Silently fails on invalid parameter type

  • Loading branch information...
1 parent b929d27 commit df3b6de7fa7d956b7c226854e3cd5849e1e4d619 @fabiokr fabiokr committed Mar 5, 2012
Showing with 6 additions and 13 deletions.
  1. +1 −3 lib/has_scope.rb
  2. +5 −10 test/has_scope_test.rb
View
@@ -129,9 +129,7 @@ def apply_scopes(target, hash=params)
def parse_value(type, key, value) #:nodoc:
if type == :boolean
TRUE_VALUES.include?(value)
- elsif value && ALLOWED_TYPES[type].none?{ |klass| value.is_a?(klass) }
- raise "Expected type :#{type} in params[:#{key}], got #{value.class}"
- else
+ elsif value && ALLOWED_TYPES[type].any?{ |klass| value.is_a?(klass) }
value
end
end
View
@@ -170,16 +170,11 @@ def test_scope_of_type_array
assert_equal({ :categories => array }, current_scopes)
end
- def test_invalid_type_hash_for_default_type_scope
- assert_raise RuntimeError do
- get :index, :color => { :blue => :red }
- end
- end
-
- def test_invalid_type_string_for_hash_type_scope
- assert_raise RuntimeError do
- get :index, :paginate => "1"
- end
+ def test_scope_of_invalid_type_silently_fails
+ Tree.expects(:all).returns([mock_tree])
+ get :index, :paginate => "1"
+ assert_equal([mock_tree], assigns(:trees))
+ assert_equal({}, current_scopes)
end
def test_scope_is_called_with_default_value

0 comments on commit df3b6de

Please sign in to comment.