Skip to content

Commit

Permalink
Small reliability improvement in context, revert one rspec test for i…
Browse files Browse the repository at this point in the history
…ncreased coverage
  • Loading branch information
rarruda committed Jan 3, 2019
1 parent a91fa1c commit 02303f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions lib/unleash/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ def to_s
# key names as in the other clients.
def fetch(params, camelcase_key, default_ret = '')
return default_ret unless params.is_a?(Hash)
return params.fetch(camelcase_key, nil) || params.fetch(snakesym(camelcase_key), nil) || default_ret
return default_ret unless camelcase_key.is_a?(String) or camelcase_key.is_a?(Symbol)

params.fetch(camelcase_key, nil) || params.fetch(snake_sym(camelcase_key), nil) || default_ret
end

# transform CamelCase to snake_case and make it a sym
def snakesym(key)
key.dup.gsub(/(.)([A-Z])/,'\1_\2').downcase.to_sym
# transform CamelCase to snake_case and make it a sym, if it is a string
def snake_sym(key)
key.is_a?(String) ? key.gsub(/(.)([A-Z])/,'\1_\2').downcase.to_sym : key
end
end
end
end
2 changes: 1 addition & 1 deletion spec/unleash/strategy/gradual_rollout_sessionid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
RSpec.describe Unleash::Strategy::GradualRolloutSessionId do
describe '#is_enabled?' do
let(:strategy) { Unleash::Strategy::GradualRolloutSessionId.new }
let(:unleash_context) { Unleash::Context.new({'sessionId' => 'secretsessionidhashgoeshere'}) }
let(:unleash_context) { Unleash::Context.new(session_id: 'secretsessionidhashgoeshere') }
let(:percentage) { Unleash::Strategy::Util.get_normalized_number(unleash_context.session_id, "") }

it 'return true when percentage set is gt the number returned by the hash function' do
Expand Down

0 comments on commit 02303f8

Please sign in to comment.