Skip to content

Commit

Permalink
Merge pull request #260 from redis/nil-to-default
Browse files Browse the repository at this point in the history
Use default when option is not specified or nil
  • Loading branch information
pietern committed Jul 24, 2012
2 parents d455841 + ab80ac0 commit a109bcf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/redis/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,10 @@ def _parse_options(options)
end
end

options = defaults.merge(options)
# Use default when option is not specified or nil
defaults.keys.each do |key|
options[key] ||= defaults[key]
end

if options[:path]
options[:scheme] = "unix"
Expand Down
18 changes: 18 additions & 0 deletions test/url_param_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ def test_overrides_url_if_another_connection_option_is_passed_with_string_key
assert_equal "secr3t", redis.client.password
end

def test_does_not_overrides_url_if_a_nil_option_is_passed
redis = Redis.new :url => "redis://:secr3t@foo.com:999/2", :port => nil

assert_equal "foo.com", redis.client.host
assert_equal 999, redis.client.port
assert_equal 2, redis.client.db
assert_equal "secr3t", redis.client.password
end

def test_does_not_overrides_url_if_a_nil_option_is_passed_with_string_key
redis = Redis.new :url => "redis://:secr3t@foo.com:999/2", "port" => nil

assert_equal "foo.com", redis.client.host
assert_equal 999, redis.client.port
assert_equal 2, redis.client.db
assert_equal "secr3t", redis.client.password
end

def test_does_not_modify_the_passed_options
options = { :url => "redis://:secr3t@foo.com:999/2" }

Expand Down

0 comments on commit a109bcf

Please sign in to comment.