DryRunMemory (#1550)

This commit is contained in:
Enfop 2016-06-19 00:53:58 +02:00 committed by Andrew Cantino
parent e4e2782ebe
commit 5cdc37f716
2 changed files with 18 additions and 0 deletions

View file

@ -18,6 +18,7 @@ module Agents
if agent = current_user.agents.find_by(id: params[:agent_id])
# POST /agents/:id/dry_run
if attrs.present?
attrs.merge!(memory: agent.memory)
type = agent.type
agent = Agent.build_for_type(type, current_user, attrs)
end

View file

@ -100,5 +100,22 @@ describe Agents::DryRunsController do
results = assigns(:results)
expect(results[:log]).to match(/^\[\d\d:\d\d:\d\d\] INFO -- : Fetching #{Regexp.quote(url_from_event)}$/)
end
it "uses the memory of an existing Agent" do
valid_params = {
:name => "somename",
:options => {
:code => "Agent.check = function() { this.createEvent({ 'message': this.memory('fu') }); };",
}
}
agent = Agents::JavaScriptAgent.new(valid_params)
agent.memory = {fu: "bar"}
agent.user = users(:bob)
agent.save!
post :create, agent_id: agent, agent: valid_params
results = assigns(:results)
expect(results[:events][0]).to eql({"message" => "bar"})
end
end
end