Skip to content

Commit

Permalink
Don't serialize nil to an empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad Sherif committed Aug 28, 2013
1 parent febf2be commit 8eee487
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/airbrake/utils/params_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def clean_unserializable_data(data, stack = [])
clean_unserializable_data(value, stack + [data.object_id])
end
else
data.to_s
data.nil? ? nil : data.to_s
end
end
end
Expand Down
9 changes: 5 additions & 4 deletions test/params_cleaner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def clean(opts = {})
end

def assert_serializes_hash(attribute)
[File.open(__FILE__), Proc.new { puts "boo!" }, Module.new].each do |object|
[File.open(__FILE__), Proc.new { puts "boo!" }, Module.new, nil].each do |object|
hash = {
:strange_object => object,
:sub_hash => {
Expand All @@ -19,11 +19,12 @@ def assert_serializes_hash(attribute)
}
clean_params = clean(attribute => hash)
hash = clean_params.send(attribute)
assert_equal object.to_s, hash[:strange_object], "objects should be serialized"
object_serialized = object.nil? ? nil : object.to_s
assert_equal object_serialized, hash[:strange_object], "objects should be serialized"
assert_kind_of Hash, hash[:sub_hash], "subhashes should be kept"
assert_equal object.to_s, hash[:sub_hash][:sub_object], "subhash members should be serialized"
assert_equal object_serialized, hash[:sub_hash][:sub_object], "subhash members should be serialized"
assert_kind_of Array, hash[:array], "arrays should be kept"
assert_equal object.to_s, hash[:array].first, "array members should be serialized"
assert_equal object_serialized, hash[:array].first, "array members should be serialized"
end
end

Expand Down

0 comments on commit 8eee487

Please sign in to comment.