Skip to content
Browse files

Merge pull request #24 from fabiokr/silently_fail_on_invalid_type

Silently fails on invalid parameter type
  • Loading branch information...
2 parents b929d27 + df3b6de commit 8d145149109b021a5f96c9cacc158847fb01de1c @josevalim josevalim committed
Showing with 6 additions and 13 deletions.
  1. +1 −3 lib/has_scope.rb
  2. +5 −10 test/has_scope_test.rb
View
4 lib/has_scope.rb
@@ -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
15 test/has_scope_test.rb
@@ -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 8d14514

Please sign in to comment.
Something went wrong with that request. Please try again.