From 3ffe667f9e8ba3f2244640959c2a997ed22b2771 Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Wed, 19 Jul 2017 11:24:22 +0900 Subject: [PATCH] Allow controllers to be selected --- app/views/agents/_form.html.erb | 9 +++++---- spec/features/create_an_agent_spec.rb | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/views/agents/_form.html.erb b/app/views/agents/_form.html.erb index 5b46b060..3cb66973 100644 --- a/app/views/agents/_form.html.erb +++ b/app/views/agents/_form.html.erb @@ -51,13 +51,14 @@ -
+
<%= f.label :controllers %> -
- <%= agent_controllers(@agent) || 'None' %> -
+ <%= 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'}}) %>
diff --git a/spec/features/create_an_agent_spec.rb b/spec/features/create_an_agent_spec.rb index a9159719..e65ff593 100644 --- a/spec/features/create_an_agent_spec.rb +++ b/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