@@ -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 |