Add specs that `this.memory(key, falsy)` should work

This spots a bug in `getMemory()`.

Akinori MUSHA 8 jaren geleden
bovenliggende
commit
4edb6e0866
1 gewijzigde bestanden met toevoegingen van 24 en 0 verwijderingen
  1. 24 0
      spec/models/agents/java_script_agent_spec.rb

+ 24 - 0
spec/models/agents/java_script_agent_spec.rb

@@ -186,6 +186,30 @@ describe Agents::JavaScriptAgent do
186 186
         @agent.save!
187 187
         expect { @agent.reload.memory }.not_to raise_error
188 188
       end
189
+
190
+      it "it stores null" do
191
+        @agent.options['code'] = 'Agent.check = function() {
192
+          this.memory("foo", "test");
193
+          this.memory("foo", null);
194
+          };'
195
+        @agent.save!
196
+        @agent.check
197
+        expect(@agent.memory['foo']).to eq(nil)
198
+        @agent.save!
199
+        expect { @agent.reload.memory }.not_to raise_error
200
+      end
201
+
202
+      it "it stores false" do
203
+        @agent.options['code'] = 'Agent.check = function() {
204
+          this.memory("foo", "test");
205
+          this.memory("foo", false);
206
+          };'
207
+        @agent.save!
208
+        @agent.check
209
+        expect(@agent.memory['foo']).to eq(false)
210
+        @agent.save!
211
+        expect { @agent.reload.memory }.not_to raise_error
212
+      end
189 213
     end
190 214
 
191 215
     describe "deleteKey" do