Skip to content

Commit

Permalink
Silently fails on invalid parameter type
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiokr committed Mar 5, 2012
1 parent b929d27 commit df3b6de
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
4 changes: 1 addition & 3 deletions lib/has_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 5 additions & 10 deletions test/has_scope_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit df3b6de

Please sign in to comment.