Skip to content

Commit 8d3c9d1

Browse files
authored
Merge pull request #5 from rajneeshsharma9/utility-fix
fix(utility.rb): Fix issue when nil is passed as option to track API
2 parents d86fb82 + f239056 commit 8d3c9d1

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

lib/vwo/utils/utility.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module Utility
2525
# @param[Hash]
2626
# @return[Hash]
2727
def convert_to_symbol_hash(hashObject)
28+
hashObject ||= {}
2829
convertedHash = {}
2930
hashObject.each do |key, value|
3031
if valid_hash?(value)

tests/test_utility.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2019-2021 Wingify Software Pvt. Ltd.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
require 'json'
16+
require_relative '../lib/vwo/utils/utility'
17+
require 'test/unit'
18+
19+
class UtilityTest < Test::Unit::TestCase
20+
include VWO::Utils::Utility
21+
22+
def test_convert_to_symbol_hash_with_valid_hash
23+
hashObject = { 'name': 'CUSTOM' }
24+
expectation = { name: 'CUSTOM' }
25+
result = convert_to_symbol_hash(hashObject)
26+
assert_equal(expectation, result)
27+
end
28+
29+
def test_convert_to_symbol_hash_with_empty_hash
30+
hashObject = {}
31+
expectation = {}
32+
result = convert_to_symbol_hash(hashObject)
33+
assert_equal(expectation, result)
34+
end
35+
36+
def test_convert_to_symbol_hash_with_nil
37+
hashObject = nil
38+
expectation = {}
39+
result = convert_to_symbol_hash(hashObject)
40+
assert_equal(expectation, result)
41+
end
42+
43+
end

0 commit comments

Comments
 (0)