Allow controllers to be selected

This commit is contained in:
Akinori MUSHA 2017-07-19 11:24:22 +09:00
parent 0abc42fb40
commit 3ffe667f9e
2 changed files with 24 additions and 4 deletions

View file

@ -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>

View file

@ -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