mirror of
https://github.com/Fishwaldo/huginn.git
synced 2025-03-15 19:31:26 +00:00
There is a button to add a new Agent directly in a Scenario; deleting an Agent from its show page no longer 404s; there is a button to destroy all delayed_jobs
This commit is contained in:
parent
16e9504a88
commit
ce84f159e0
7 changed files with 60 additions and 16 deletions
|
@ -148,6 +148,9 @@ class AgentsController < ApplicationController
|
|||
else
|
||||
@agent = agents.build
|
||||
end
|
||||
|
||||
@agent.scenario_ids = [params[:scenario_id]] if params[:scenario_id] && current_user.scenarios.find_by(id: params[:scenario_id])
|
||||
|
||||
initialize_presenter
|
||||
|
||||
respond_to do |format|
|
||||
|
@ -237,14 +240,14 @@ class AgentsController < ApplicationController
|
|||
if @agent && !@agent.destroyed?
|
||||
path = agent_path(@agent)
|
||||
end
|
||||
when /\A#{Regexp::escape scenarios_path}\/\d+\Z/, agents_path
|
||||
when /\A#{Regexp::escape scenarios_path}\/\d+\z/, agents_path
|
||||
path = ret
|
||||
end
|
||||
|
||||
if path
|
||||
redirect_to path, notice: message
|
||||
else
|
||||
super agents_path, notice: message
|
||||
redirect_to agents_path, notice: message
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -48,6 +48,15 @@ class JobsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def destroy_all
|
||||
Delayed::Job.delete_all
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to jobs_path, notice: "All jobs removed." }
|
||||
format.json { render json: '', status: :ok }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def running?
|
||||
|
|
|
@ -79,6 +79,10 @@
|
|||
<%= link_to destroy_failed_jobs_path, class: "btn btn-default", method: :delete do %>
|
||||
<span class="glyphicon glyphicon-trash"></span> Remove failed jobs
|
||||
<% end %>
|
||||
|
||||
<%= link_to destroy_all_jobs_path, class: "btn btn-default", method: :delete, data: { confirm: "Are you sure you want to delete ALL pending jobs for all Huginn users?" } do %>
|
||||
<span class="glyphicon glyphicon-remove"></span> Remove all jobs
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -16,10 +16,11 @@
|
|||
|
||||
<div class="btn-group">
|
||||
<%= link_to icon_tag('glyphicon-chevron-left') + ' Back', scenarios_path, class: "btn btn-default" %>
|
||||
<%= link_to icon_tag('glyphicon-plus') + ' New Agent', new_agent_path(scenario_id: @scenario.id), class: "btn btn-default" %>
|
||||
<%= link_to icon_tag('glyphicon-random') + ' View Diagram', scenario_diagram_path(@scenario), class: "btn btn-default" %>
|
||||
<%= link_to icon_tag('glyphicon-edit') + ' Edit', edit_scenario_path(@scenario), class: "btn btn-default" %>
|
||||
<% if @scenario.source_url.present? %>
|
||||
<%= link_to icon_tag('glyphicon-plus') + ' Update', new_scenario_imports_path(url: @scenario.source_url), class: "btn btn-default" %>
|
||||
<%= link_to icon_tag('glyphicon-refresh') + ' Update', new_scenario_imports_path(url: @scenario.source_url), class: "btn btn-default" %>
|
||||
<% end %>
|
||||
<%= link_to icon_tag('glyphicon-share-alt') + ' Share', share_scenario_path(@scenario), class: "btn btn-default" %>
|
||||
<%= link_to icon_tag('glyphicon-trash') + ' Delete', scenario_path(@scenario), method: :delete, data: { confirm: "This will remove the '#{@scenario.name}' Scenerio from all Agents and delete it. Are you sure?" }, class: "btn btn-default" %>
|
||||
|
|
|
@ -62,6 +62,7 @@ Huginn::Application.routes.draw do
|
|||
end
|
||||
collection do
|
||||
delete :destroy_failed
|
||||
delete :destroy_all
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -87,19 +87,35 @@ describe AgentsController do
|
|||
end
|
||||
end
|
||||
|
||||
describe "GET new with :id" do
|
||||
it "opens a clone of a given Agent" do
|
||||
sign_in users(:bob)
|
||||
get :new, :id => agents(:bob_website_agent).to_param
|
||||
expect(assigns(:agent).attributes).to eq(users(:bob).agents.build_clone(agents(:bob_website_agent)).attributes)
|
||||
describe "GET new" do
|
||||
describe "with :id" do
|
||||
it "opens a clone of a given Agent" do
|
||||
sign_in users(:bob)
|
||||
get :new, :id => agents(:bob_website_agent).to_param
|
||||
expect(assigns(:agent).attributes).to eq(users(:bob).agents.build_clone(agents(:bob_website_agent)).attributes)
|
||||
end
|
||||
|
||||
it "only allows the current user to clone his own Agent" do
|
||||
sign_in users(:bob)
|
||||
|
||||
expect {
|
||||
get :new, :id => agents(:jane_website_agent).to_param
|
||||
}.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
it "only allows the current user to clone his own Agent" do
|
||||
sign_in users(:bob)
|
||||
describe "with a scenario_id" do
|
||||
it 'populates the assigned agent with the scenario' do
|
||||
sign_in users(:bob)
|
||||
get :new, :scenario_id => scenarios(:bob_weather).id
|
||||
expect(assigns(:agent).scenario_ids).to eq([scenarios(:bob_weather).id])
|
||||
end
|
||||
|
||||
expect {
|
||||
get :new, :id => agents(:jane_website_agent).to_param
|
||||
}.to raise_error(ActiveRecord::RecordNotFound)
|
||||
it "does not see other user's scenarios" do
|
||||
sign_in users(:bob)
|
||||
get :new, :scenario_id => scenarios(:jane_weather).id
|
||||
expect(assigns(:agent).scenario_ids).to eq([])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe JobsController do
|
||||
|
||||
describe "GET index" do
|
||||
before do
|
||||
async_handler_yaml =
|
||||
|
@ -75,8 +74,19 @@ describe JobsController do
|
|||
end
|
||||
|
||||
it "just destroy failed jobs" do
|
||||
expect { delete :destroy_failed, id: @failed.id }.to change(Delayed::Job, :count).by(-1)
|
||||
expect { delete :destroy_failed, id: @running.id }.to change(Delayed::Job, :count).by(0)
|
||||
expect { delete :destroy_failed }.to change(Delayed::Job, :count).by(-1)
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE destroy_all" do
|
||||
before do
|
||||
@failed = Delayed::Job.create(failed_at: Time.now - 1.minute)
|
||||
@running = Delayed::Job.create(locked_at: Time.now, locked_by: 'test')
|
||||
sign_in users(:jane)
|
||||
end
|
||||
|
||||
it "destroys all jobs" do
|
||||
expect { delete :destroy_all }.to change(Delayed::Job, :count).by(-2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue