Explorar o código

Allow controllers to be selected

Akinori MUSHA %!s(int64=7) %!d(string=hai) anos
pai
achega
3ffe667f9e
Modificáronse 2 ficheiros con 24 adicións e 4 borrados
  1. 5 4
      app/views/agents/_form.html.erb
  2. 19 0
      spec/features/create_an_agent_spec.rb

+ 5 - 4
app/views/agents/_form.html.erb

@@ -51,13 +51,14 @@
               </div>
             </div>
 
-            <div class="controller-region" data-has-controllers="<%= !@agent.controllers.empty? %>">
+            <div class="controller-region">
               <div class="form-group">
                 <%= f.label :controllers %>
                 <span class="glyphicon glyphicon-question-sign hover-help" data-content="Other than the system-defined schedule above, this agent may be run or controlled by these user-defined Agents."></span>
-                <div class="controller-list">
-                  <%= agent_controllers(@agent) || 'None' %>
-                </div>
+                <%= f.select(:controller_ids,
+                             options_for_select(current_user.agents.select(&:can_control_other_agents?).pluck(:name, :id),
+                                                @agent.controller_ids),
+                             {}, { multiple: true, size: 5, class: 'select2-linked-tags form-control', data: {url_prefix: '/agents'}}) %>
               </div>
             </div>
 

+ 19 - 0
spec/features/create_an_agent_spec.rb

@@ -80,6 +80,25 @@ describe "Creating a new agent", js: true do
 
       expect(agent.control_targets).to eq([bob_weather_agent])
     end
+
+    it "creates an agent with a controller" do
+      visit "/"
+      page.find("a", text: "Agents").trigger(:mouseover)
+      click_on("New Agent")
+
+      select_agent_type("Weather Agent")
+      fill_in(:agent_name, with: "Test Weather Agent")
+
+      select2("Example Scheduler", from: 'Controllers')
+
+      click_on "Save"
+
+      expect(page).to have_text("Test Weather Agent")
+
+      agent = Agent.find_by(name: "Test Weather Agent")
+
+      expect(agent.controllers).to eq([bob_scheduler_agent])
+    end
   end
 
   it "creates an alert if a new agent with invalid json is submitted" do