Skip to content

Commit

Permalink
Merge 2341bb7 into d41c857
Browse files Browse the repository at this point in the history
  • Loading branch information
gardleopard committed Jul 4, 2023
2 parents d41c857 + 2341bb7 commit 8c5d553
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/unleash/strategy/flexible_rollout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ def name
# need: params['percentage']
def is_enabled?(params = {}, context = nil)
return false unless params.is_a?(Hash)
return false unless context.instance_of?(Unleash::Context)

stickiness = params.fetch('stickiness', 'default')
return false unless context.instance_of?(Unleash::Context) || ['random', 'default'].include?(stickiness)

stickiness_id = resolve_stickiness(stickiness, context)

begin
Expand Down Expand Up @@ -41,6 +42,8 @@ def resolve_stickiness(stickiness, context)
when 'random'
random
when 'default'
return random unless context.instance_of?(Unleash::Context)

context.user_id || context.session_id || random
else
begin
Expand Down
2 changes: 2 additions & 0 deletions spec/unleash/strategy/flexible_rollout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
}

expect(strategy.is_enabled?(params, unleash_context)).to be_truthy
expect(strategy.is_enabled?(params, nil)).to be_truthy
expect(strategy.is_enabled?(params.merge({ 'rollout' => 0 }), unleash_context)).to be_falsey
expect(strategy.is_enabled?(params.merge({ 'rollout' => 0 }), nil)).to be_falsey
end

it 'should behave predictably when based on the normalized_number' do
Expand Down

0 comments on commit 8c5d553

Please sign in to comment.