From 4edb6e08663035f12c4a40e2543259230d346ee1 Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Thu, 16 Jun 2016 19:57:33 +0900 Subject: [PATCH] Add specs that `this.memory(key, falsy)` should work This spots a bug in `getMemory()`. --- spec/models/agents/java_script_agent_spec.rb | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/models/agents/java_script_agent_spec.rb b/spec/models/agents/java_script_agent_spec.rb index c39afae3..38c0dcb3 100644 --- a/spec/models/agents/java_script_agent_spec.rb +++ b/spec/models/agents/java_script_agent_spec.rb @@ -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