Add specs for DELETE memory

Akinori MUSHA 10 gadi atpakaļ
vecāks
revīzija
fbca16e8d3
1 mainītis faili ar 20 papildinājumiem un 0 dzēšanām
  1. 20 0
      spec/controllers/agents_controller_spec.rb

+ 20 - 0
spec/controllers/agents_controller_spec.rb

@@ -374,4 +374,24 @@ describe AgentsController do
374 374
       }
375 375
     end
376 376
   end
377
+
378
+  describe "DELETE memory" do
379
+    it "clears memory of the agent" do
380
+      agent = agents(:bob_website_agent)
381
+      agent.update!(memory: { "test" => 42 })
382
+      sign_in users(:bob)
383
+      delete :destroy_memory, id: agent.to_param
384
+      expect(agent.reload.memory).to eq({})
385
+    end
386
+
387
+    it "does not clear memory of an agent not owned by the current user" do
388
+      agent = agents(:jane_website_agent)
389
+      agent.update!(memory: { "test" => 42 })
390
+      sign_in users(:bob)
391
+      expect {
392
+        delete :destroy_memory, id: agent.to_param
393
+      }.to raise_error(ActiveRecord::RecordNotFound)
394
+      expect(agent.reload.memory).to eq({ "test" => 42})
395
+    end
396
+  end
377 397
 end