When the control action is `run`, control targets must be schedulable.

Akinori MUSHA 10 lat temu
rodzic
commit
23b074193f

+ 7 - 1
app/concerns/agent_controller_concern.rb

@@ -17,7 +17,13 @@ module AgentControllerConcern
17 17
 
18 18
   def validate_control_action
19 19
     case control_action
20
-    when 'run', 'enable', 'disable'
20
+    when 'run'
21
+      control_targets.each { |target|
22
+        if target.cannot_be_scheduled?
23
+          errors.add(:base, "#{target.name} cannot be scheduled")
24
+        end
25
+      }
26
+    when 'enable', 'disable'
21 27
     else
22 28
       errors.add(:base, 'invalid action')
23 29
     end

+ 14 - 0
spec/models/agents/scheduler_agent_spec.rb

@@ -78,6 +78,20 @@ describe Agents::SchedulerAgent do
78 78
         @agent.control_action.should == action
79 79
       }
80 80
     end
81
+
82
+    it "cannot be 'run' if any of the control targets cannot be scheduled" do
83
+      @agent.control_action.should == 'run'
84
+      @agent.control_targets = [agents(:bob_rain_notifier_agent)]
85
+      @agent.should_not be_valid
86
+    end
87
+
88
+    it "can be 'enable' or 'disable' no matter if control targets can be scheduled or not" do
89
+      ['enable', 'disable'].each { |action|
90
+        @agent.options['action'] = action
91
+        @agent.control_targets = [agents(:bob_rain_notifier_agent)]
92
+        @agent.should be_valid
93
+      }
94
+    end
81 95
   end
82 96
 
83 97
   describe "save" do