Skip to content

Commit

Permalink
Fix LiquidOutputAgent event_limit validations (#2864)
Browse files Browse the repository at this point in the history
  • Loading branch information
monsha committed Sep 16, 2020
1 parent c79ff37 commit 8574cb5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/models/agents/liquid_output_agent.rb
Expand Up @@ -129,8 +129,8 @@ def validate_options
end

if options['event_limit'].present?
if((Integer(options['event_limit']) rescue false) == false)
errors.add(:base, "Event limit must be an integer that is less than 1001.")
if (Integer(options['event_limit']) rescue false) == false && date_limit.blank?
errors.add(:base, "Event limit must be an integer that is less than 1001 or an integer plus a valid unit.")
elsif (options['event_limit'].to_i > 1000)
errors.add(:base, "For performance reasons, you cannot have an event limit greater than 1000.")
end
Expand Down
9 changes: 8 additions & 1 deletion spec/models/agents/liquid_output_agent_spec.rb
Expand Up @@ -72,7 +72,14 @@
expect(agent).not_to be_valid
end

it "should should not allow non-integer event limits" do
it "should validate the event_limit with relative time" do
agent.options[:event_limit] = "15 minutes"
expect(agent).to be_valid
agent.options[:event_limit] = "1 century"
expect(agent).not_to be_valid
end

it "should not allow non-integer event limits" do
agent.options[:event_limit] = "abc1234"
expect(agent).not_to be_valid
end
Expand Down

0 comments on commit 8574cb5

Please sign in to comment.