Skip to content

Commit

Permalink
TriggerAgent allows an empty value in a rule
Browse files Browse the repository at this point in the history
It actually makes sense to use an empty value for the rule types `field==value` and `field!=value`.
  • Loading branch information
knu committed Jun 27, 2023
1 parent ba93bdf commit b85793a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions app/models/agents/trigger_agent.rb
Expand Up @@ -53,8 +53,9 @@ class TriggerAgent < Agent
when String
true
when Hash
rule.values_at('type', 'value', 'path').all?(&:present?) &&
VALID_COMPARISON_TYPES.include?(rule['type'])
VALID_COMPARISON_TYPES.include?(rule['type']) &&
rule['path'].match?(/\S/) &&
rule['value'].is_a?(String)
else
false
end
Expand Down
4 changes: 3 additions & 1 deletion spec/models/agents/trigger_agent_spec.rb
Expand Up @@ -82,10 +82,12 @@
it "should validate the three fields in each rule" do
@checker.options['rules'] << { 'path' => "foo", 'type' => "fake", 'value' => "6" }
expect(@checker).not_to be_valid
@checker.options['rules'].last['type'] = "field>=value"
@checker.options['rules'].last['type'] = "field!=value"
expect(@checker).to be_valid
@checker.options['rules'].last.delete('value')
expect(@checker).not_to be_valid
@checker.options['rules'].last['value'] = ''
expect(@checker).to be_valid
end

it "should validate non-hash rules" do
Expand Down

0 comments on commit b85793a

Please sign in to comment.