|
@@ -3,6 +3,34 @@ require 'rails_helper'
|
|
|
describe Agent do
|
|
|
it_behaves_like WorkingHelpers
|
|
|
|
|
|
+ describe '.active/inactive' do
|
|
|
+ let(:agent) { agents(:jane_website_agent) }
|
|
|
+
|
|
|
+ it 'is active per default' do
|
|
|
+ expect(Agent.active).to include(agent)
|
|
|
+ expect(Agent.inactive).not_to include(agent)
|
|
|
+ end
|
|
|
+
|
|
|
+ it 'is not active when disabled' do
|
|
|
+ agent.update_attribute(:disabled, true)
|
|
|
+ expect(Agent.active).not_to include(agent)
|
|
|
+ expect(Agent.inactive).to include(agent)
|
|
|
+ end
|
|
|
+
|
|
|
+ it 'is not active when deactivated' do
|
|
|
+ agent.update_attribute(:deactivated, true)
|
|
|
+ expect(Agent.active).not_to include(agent)
|
|
|
+ expect(Agent.inactive).to include(agent)
|
|
|
+ end
|
|
|
+
|
|
|
+ it 'is not active when disabled and deactivated' do
|
|
|
+ agent.update_attribute(:disabled, true)
|
|
|
+ agent.update_attribute(:deactivated, true)
|
|
|
+ expect(Agent.active).not_to include(agent)
|
|
|
+ expect(Agent.inactive).to include(agent)
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
describe ".bulk_check" do
|
|
|
before do
|
|
|
@weather_agent_count = Agents::WeatherAgent.where(:schedule => "midnight", :disabled => false).count
|
|
@@ -18,6 +46,12 @@ describe Agent do
|
|
|
mock(Agents::WeatherAgent).async_check(anything).times(@weather_agent_count - 1)
|
|
|
Agents::WeatherAgent.bulk_check("midnight")
|
|
|
end
|
|
|
+
|
|
|
+ it "should skip agents of deactivated accounts" do
|
|
|
+ agents(:bob_weather_agent).user.deactivate!
|
|
|
+ mock(Agents::WeatherAgent).async_check(anything).times(@weather_agent_count - 1)
|
|
|
+ Agents::WeatherAgent.bulk_check("midnight")
|
|
|
+ end
|
|
|
end
|
|
|
|
|
|
describe ".run_schedule" do
|
|
@@ -335,6 +369,13 @@ describe Agent do
|
|
|
Agent.receive! # and we receive it
|
|
|
}.to change { agents(:bob_rain_notifier_agent).reload.last_checked_event_id }
|
|
|
end
|
|
|
+
|
|
|
+ it "should not run agents of deactivated accounts" do
|
|
|
+ agents(:bob_weather_agent).user.deactivate!
|
|
|
+ Agent.async_check(agents(:bob_weather_agent).id)
|
|
|
+ mock(Agent).async_receive(agents(:bob_rain_notifier_agent).id, anything).times(0)
|
|
|
+ Agent.receive!
|
|
|
+ end
|
|
|
end
|
|
|
|
|
|
describe ".async_receive" do
|