mirror of
https://github.com/Fishwaldo/huginn.git
synced 2025-03-15 19:31:26 +00:00
Merge pull request #1551 from cantino/jsagent_fix_memory
Fix `this.memory(key, falsy)` not working in JavaScriptAgent
This commit is contained in:
commit
371bfa34b7
2 changed files with 28 additions and 7 deletions
|
@ -114,12 +114,9 @@ module Agents
|
|||
context["getOptions"] = lambda { |a, x| interpolated.to_json }
|
||||
context["doLog"] = lambda { |a, x| log x }
|
||||
context["doError"] = lambda { |a, x| error x }
|
||||
context["getMemory"] = lambda do |a, x, y|
|
||||
if x && y
|
||||
memory[x] = clean_nans(y)
|
||||
else
|
||||
memory.to_json
|
||||
end
|
||||
context["getMemory"] = lambda { |a| memory.to_json }
|
||||
context["setMemory"] = lambda do |a, x, y|
|
||||
memory[x] = clean_nans(y)
|
||||
end
|
||||
context["deleteKey"] = lambda { |a, x| memory.delete(x).to_json }
|
||||
context["escapeHtml"] = lambda { |a, x| CGI.escapeHTML(x) }
|
||||
|
@ -168,7 +165,7 @@ module Agents
|
|||
|
||||
Agent.memory = function(key, value) {
|
||||
if (typeof(key) !== "undefined" && typeof(value) !== "undefined") {
|
||||
getMemory(key, value);
|
||||
setMemory(key, value);
|
||||
} else if (typeof(key) !== "undefined") {
|
||||
return JSON.parse(getMemory())[key];
|
||||
} else {
|
||||
|
|
|
@ -186,6 +186,30 @@ describe Agents::JavaScriptAgent do
|
|||
@agent.save!
|
||||
expect { @agent.reload.memory }.not_to raise_error
|
||||
end
|
||||
|
||||
it "it stores null" do
|
||||
@agent.options['code'] = 'Agent.check = function() {
|
||||
this.memory("foo", "test");
|
||||
this.memory("foo", null);
|
||||
};'
|
||||
@agent.save!
|
||||
@agent.check
|
||||
expect(@agent.memory['foo']).to eq(nil)
|
||||
@agent.save!
|
||||
expect { @agent.reload.memory }.not_to raise_error
|
||||
end
|
||||
|
||||
it "it stores false" do
|
||||
@agent.options['code'] = 'Agent.check = function() {
|
||||
this.memory("foo", "test");
|
||||
this.memory("foo", false);
|
||||
};'
|
||||
@agent.save!
|
||||
@agent.check
|
||||
expect(@agent.memory['foo']).to eq(false)
|
||||
@agent.save!
|
||||
expect { @agent.reload.memory }.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe "deleteKey" do
|
||||
|
|
Loading…
Add table
Reference in a new issue