add specs for disabled agents

Andrew Cantino 10 years ago
parent
commit
ac8d879940
1 changed files with 42 additions and 2 deletions
  1. 42 2
      spec/models/agent_spec.rb

+ 42 - 2
spec/models/agent_spec.rb

@@ -4,6 +4,23 @@ require 'models/concerns/working_helpers'
4 4
 describe Agent do
5 5
   it_behaves_like WorkingHelpers
6 6
 
7
+  describe ".bulk_check" do
8
+    before do
9
+      @weather_agent_count = Agents::WeatherAgent.where(:schedule => "midnight", :disabled => false).count
10
+    end
11
+
12
+    it "should run all Agents with the given schedule" do
13
+      mock(Agents::WeatherAgent).async_check(anything).times(@weather_agent_count)
14
+      Agents::WeatherAgent.bulk_check("midnight")
15
+    end
16
+
17
+    it "should skip disabled Agents" do
18
+      agents(:bob_weather_agent).update_attribute :disabled, true
19
+      mock(Agents::WeatherAgent).async_check(anything).times(@weather_agent_count - 1)
20
+      Agents::WeatherAgent.bulk_check("midnight")
21
+    end
22
+  end
23
+
7 24
   describe ".run_schedule" do
8 25
     before do
9 26
       Agents::WeatherAgent.count.should > 0
@@ -194,17 +211,31 @@ describe Agent do
194 211
         log.message.should =~ /Exception/
195 212
         log.level.should == 4
196 213
       end
214
+
215
+      it "should not run disabled Agents" do
216
+        mock(Agent).find(agents(:bob_weather_agent).id) { agents(:bob_weather_agent) }
217
+        do_not_allow(agents(:bob_weather_agent)).check
218
+        agents(:bob_weather_agent).update_attribute :disabled, true
219
+        Agent.async_check(agents(:bob_weather_agent).id)
220
+      end
197 221
     end
198 222
 
199
-    describe ".receive! and .async_receive" do
223
+    describe ".receive!" do
200 224
       before do
201 225
         stub_request(:any, /wunderground/).to_return(:body => File.read(Rails.root.join("spec/data_fixtures/weather.json")), :status => 200)
202 226
         stub.any_instance_of(Agents::WeatherAgent).is_tomorrow?(anything) { true }
203 227
       end
204 228
 
205 229
       it "should use available events" do
206
-        mock.any_instance_of(Agents::TriggerAgent).receive(anything).once
207 230
         Agent.async_check(agents(:bob_weather_agent).id)
231
+        mock(Agent).async_receive(agents(:bob_rain_notifier_agent).id, anything).times(1)
232
+        Agent.receive!
233
+      end
234
+
235
+      it "should not propogate to disabled Agents" do
236
+        Agent.async_check(agents(:bob_weather_agent).id)
237
+        agents(:bob_rain_notifier_agent).update_attribute :disabled, true
238
+        mock(Agent).async_receive(agents(:bob_rain_notifier_agent).id, anything).times(0)
208 239
         Agent.receive!
209 240
       end
210 241
 
@@ -281,6 +312,15 @@ describe Agent do
281 312
       end
282 313
     end
283 314
 
315
+    describe ".async_receive" do
316
+      it "should not run disabled Agents" do
317
+        mock(Agent).find(agents(:bob_rain_notifier_agent).id) { agents(:bob_rain_notifier_agent) }
318
+        do_not_allow(agents(:bob_rain_notifier_agent)).receive
319
+        agents(:bob_rain_notifier_agent).update_attribute :disabled, true
320
+        Agent.async_receive(agents(:bob_rain_notifier_agent).id, [1, 2, 3])
321
+      end
322
+    end
323
+
284 324
     describe "creating a new agent and then calling .receive!" do
285 325
       it "should not backfill events for a newly created agent" do
286 326
         Event.delete_all