Skip to content

Commit

Permalink
Do not use objects that don't respond to to_sym (integers, floats, da…
Browse files Browse the repository at this point in the history
…tes...) as parameters
  • Loading branch information
marcgg committed Sep 1, 2011
1 parent 03b9630 commit 28d605f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activeresource/lib/active_resource/base.rb
Expand Up @@ -955,7 +955,7 @@ def split_options(options = {})
prefix_options, query_options = {}, {}

(options || {}).each do |key, value|
next if key.blank? || [Fixnum, Date, Time, Float].include?(key.class)
next if key.blank? || !key.respond_to?(:to_sym)
(prefix_parameters.include?(key.to_sym) ? prefix_options : query_options)[key.to_sym] = value
end

Expand Down
19 changes: 19 additions & 0 deletions activeresource/test/cases/base/load_test.rb
Expand Up @@ -51,9 +51,28 @@ def setup
:votes => [ true, false, true ],
:places => [ "Columbia City", "Unknown" ]}}}


# List of books formated as [{timestamp_of_publication => name}, ...]
@books = {:books => [
{1009839600 => "Ruby in a Nutshell"},
{1199142000 => "The Ruby Programming Language"}
]}

@books_date = {:books => [
{Time.at(1009839600) => "Ruby in a Nutshell"},
{Time.at(1199142000) => "The Ruby Programming Language"}
]}
@person = Person.new
end

def test_load_hash_with_integers_as_keys
assert_nothing_raised{person = @person.load(@books)}
end

def test_load_hash_with_dates_as_keys
assert_nothing_raised{person = @person.load(@books_date)}
end

def test_load_expects_hash
assert_raise(ArgumentError) { @person.load nil }
assert_raise(ArgumentError) { @person.load '<person id="1"/>' }
Expand Down

0 comments on commit 28d605f

Please sign in to comment.