Add a spec for how drop_pending_events= should work.

Akinori MUSHA %!s(int64=10) %!d(string=hace) años
padre
commit
faed2845c6
Se han modificado 1 ficheros con 37 adiciones y 0 borrados
  1. 37 0
      spec/models/agent_spec.rb

+ 37 - 0
spec/models/agent_spec.rb

@@ -773,6 +773,43 @@ describe Agent do
773 773
       agent.reload.drop_pending_events.should == false
774 774
     end
775 775
   end
776
+
777
+  describe ".drop_pending_events" do
778
+    before do
779
+      stub_request(:any, /wunderground/).to_return(body: File.read(Rails.root.join("spec/data_fixtures/weather.json")), status: 200)
780
+      stub.any_instance_of(Agents::WeatherAgent).is_tomorrow?(anything) { true }
781
+    end
782
+
783
+    it "should drop pending events while the agent was disabled when set to true" do
784
+      agent1 = agents(:bob_weather_agent)
785
+      agent2 = agents(:bob_rain_notifier_agent)
786
+
787
+      -> {
788
+        -> {
789
+          Agent.async_check(agent1.id)
790
+          Agent.receive!
791
+        }.should change { agent1.events.count }.by(1)
792
+      }.should change { agent2.events.count }.by(1)
793
+
794
+      agent2.disabled = true
795
+      agent2.save!
796
+
797
+      -> {
798
+        -> {
799
+          Agent.async_check(agent1.id)
800
+          Agent.receive!
801
+        }.should change { agent1.events.count }.by(1)
802
+      }.should_not change { agent2.events.count }
803
+
804
+      agent2.disabled = false
805
+      agent2.drop_pending_events = true
806
+      agent2.save!
807
+
808
+      -> {
809
+        Agent.receive!
810
+      }.should_not change { agent2.events.count }
811
+    end
812
+  end
776 813
 end
777 814
 
778 815
 describe AgentDrop do