Преглед на файлове

Add validations for `mode` values

Fix conditional event_description. Should check for `merge` instead of
`merged`.
Christian Hein преди 7 години
родител
ревизия
4565c73a33
променени са 2 файла, в които са добавени 11 реда и са изтрити 1 реда
  1. 5 1
      app/models/agents/event_formatting_agent.rb
  2. 6 0
      spec/models/agents/event_formatting_agent_spec.rb

+ 5 - 1
app/models/agents/event_formatting_agent.rb

@@ -84,7 +84,7 @@ module Agents
     event_description do
       "Events will have the following fields%s:\n\n    %s" % [
         case options['mode'].to_s
-        when 'merged'
+        when 'merge'
           ', merged with the original contents'
         when /\{/
           ', conditionally merged with the original contents'
@@ -98,6 +98,10 @@ module Agents
     def validate_options
       errors.add(:base, "instructions and mode need to be present.") unless options['instructions'].present? && options['mode'].present?
 
+      if options['mode'].present? && !options['mode'].to_s.include?('{{') && !%[clean merge].include?(options['mode'].to_s)
+        errors.add(:base, "mode must be 'clean' or 'merge'")
+      end
+
       validate_matchers
     end
 

+ 6 - 0
spec/models/agents/event_formatting_agent_spec.rb

@@ -74,6 +74,12 @@ describe Agents::EventFormattingAgent do
       expect(Event.last.payload[:content]).not_to eq(nil)
     end
 
+    it "should handle Liquid templating in mode" do
+      @checker.options[:mode] = "{{'merge'}}"
+      @checker.receive([@event])
+      expect(Event.last.payload[:content]).not_to eq(nil)
+    end
+
     it "should handle Liquid templating in instructions" do
       @checker.receive([@event])
       expect(Event.last.payload[:message]).to eq("Received Some Lorem Ipsum from somevalue .")