Skip to content

Commit

Permalink
fix an issue where constraints would bubble an exception when context…
Browse files Browse the repository at this point in the history
… was nil (#127)
  • Loading branch information
sighphyre committed Dec 7, 2022
1 parent 74568fc commit 62bf565
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/unleash/constraint.rb
Expand Up @@ -43,6 +43,7 @@ def initialize(context_name, operator, value = [], inverted: false, case_insensi

def matches_context?(context)
Unleash.logger.debug "Unleash::Constraint matches_context? value: #{self.value} context.get_by_name(#{self.context_name})"
return false if context.nil?

match = matches_constraint?(context)
self.inverted ? !match : match
Expand Down
5 changes: 5 additions & 0 deletions spec/unleash/constraint_spec.rb
Expand Up @@ -451,4 +451,9 @@
end
end
end

it 'does resolves to false rather than crashing when passed a nil context' do
constraint = Unleash::Constraint.new('anything', 'NUM_GTE', '6.282')
expect(constraint.matches_context?(nil)).to be false
end
end

0 comments on commit 62bf565

Please sign in to comment.