Преглед на файлове

DeDuplicationAgent properly handles destruction of memory

Dominik Sander преди 9 години
родител
ревизия
ba91676d76
променени са 2 файла, в които са добавени 24 реда и са изтрити 2 реда
  1. 2 2
      app/models/agents/de_duplication_agent.rb
  2. 22 0
      spec/models/agents/de_duplication_agent_spec.rb

+ 2 - 2
app/models/agents/de_duplication_agent.rb

@@ -29,10 +29,10 @@ module Agents
     form_configurable :lookback
     form_configurable :expected_update_period_in_days
 
-    before_create :initialize_memory
+    after_initialize :initialize_memory
 
     def initialize_memory
-      memory['properties'] = []
+      memory['properties'] ||= []
     end
 
     def validate_options

+ 22 - 0
spec/models/agents/de_duplication_agent_spec.rb

@@ -40,6 +40,19 @@ describe Agents::DeDuplicationAgent do
     end
   end
 
+  describe '#initialize_memory' do
+    it 'sets properties to an empty array' do
+      expect(@checker.memory['properties']).to eq([])
+    end
+
+    it 'does not override an existing value' do
+      @checker.memory['properties'] = [1,2,3]
+      @checker.save
+      @checker.reload
+      expect(@checker.memory['properties']).to eq([1,2,3])
+    end
+  end
+
   describe "#working?" do
     before :each do
       # Need to create an event otherwise event_created_within? returns nil
@@ -123,5 +136,14 @@ describe Agents::DeDuplicationAgent do
       }.to change(Event, :count).by(1)
       expect(@checker.memory['properties'].last).to eq('3023526198')
     end
+
+    it "should still work after the memory was cleared" do
+      @checker.memory = {}
+      @checker.save
+      @checker.reload
+      expect {
+        @checker.receive([@event])
+      }.not_to raise_error
+    end
   end
 end