|
@@ -22,8 +22,8 @@ describe Agent do
|
|
|
|
|
|
describe ".run_schedule" do
|
|
|
before do
|
|
|
- Agents::WeatherAgent.count.should > 0
|
|
|
- Agents::WebsiteAgent.count.should > 0
|
|
|
+ expect(Agents::WeatherAgent.count).to be > 0
|
|
|
+ expect(Agents::WebsiteAgent.count).to be > 0
|
|
|
end
|
|
|
|
|
|
it "runs agents with the given schedule" do
|
|
@@ -31,7 +31,7 @@ describe Agent do
|
|
|
stub(Agents::WeatherAgent).async_check(anything) {|agent_id| weather_agent_ids.delete(agent_id) }
|
|
|
stub(Agents::WebsiteAgent).async_check(agents(:bob_website_agent).id)
|
|
|
Agent.run_schedule("midnight")
|
|
|
- weather_agent_ids.should be_empty
|
|
|
+ expect(weather_agent_ids).to be_empty
|
|
|
end
|
|
|
|
|
|
it "groups agents by type" do
|
|
@@ -54,20 +54,20 @@ describe Agent do
|
|
|
|
|
|
describe "credential" do
|
|
|
it "should return the value of the credential when credential is present" do
|
|
|
- agents(:bob_weather_agent).credential("aws_secret").should == user_credentials(:bob_aws_secret).credential_value
|
|
|
+ expect(agents(:bob_weather_agent).credential("aws_secret")).to eq(user_credentials(:bob_aws_secret).credential_value)
|
|
|
end
|
|
|
|
|
|
it "should return nil when credential is not present" do
|
|
|
- agents(:bob_weather_agent).credential("non_existing_credential").should == nil
|
|
|
+ expect(agents(:bob_weather_agent).credential("non_existing_credential")).to eq(nil)
|
|
|
end
|
|
|
|
|
|
it "should memoize the load" do
|
|
|
mock.any_instance_of(UserCredential).credential_value.twice { "foo" }
|
|
|
- agents(:bob_weather_agent).credential("aws_secret").should == "foo"
|
|
|
- agents(:bob_weather_agent).credential("aws_secret").should == "foo"
|
|
|
+ expect(agents(:bob_weather_agent).credential("aws_secret")).to eq("foo")
|
|
|
+ expect(agents(:bob_weather_agent).credential("aws_secret")).to eq("foo")
|
|
|
agents(:bob_weather_agent).reload
|
|
|
- agents(:bob_weather_agent).credential("aws_secret").should == "foo"
|
|
|
- agents(:bob_weather_agent).credential("aws_secret").should == "foo"
|
|
|
+ expect(agents(:bob_weather_agent).credential("aws_secret")).to eq("foo")
|
|
|
+ expect(agents(:bob_weather_agent).credential("aws_secret")).to eq("foo")
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -75,21 +75,21 @@ describe Agent do
|
|
|
it "validates types" do
|
|
|
source = Agent.new
|
|
|
source.type = "Agents::WeatherAgent"
|
|
|
- source.should have(0).errors_on(:type)
|
|
|
+ expect(source).to have(0).errors_on(:type)
|
|
|
source.type = "Agents::WebsiteAgent"
|
|
|
- source.should have(0).errors_on(:type)
|
|
|
+ expect(source).to have(0).errors_on(:type)
|
|
|
source.type = "Agents::Fake"
|
|
|
- source.should have(1).error_on(:type)
|
|
|
+ expect(source).to have(1).error_on(:type)
|
|
|
end
|
|
|
|
|
|
it "disallows changes to type once a record has been saved" do
|
|
|
source = agents(:bob_website_agent)
|
|
|
source.type = "Agents::WeatherAgent"
|
|
|
- source.should have(1).error_on(:type)
|
|
|
+ expect(source).to have(1).error_on(:type)
|
|
|
end
|
|
|
|
|
|
it "should know about available types" do
|
|
|
- Agent.types.should include(Agents::WeatherAgent, Agents::WebsiteAgent)
|
|
|
+ expect(Agent.types).to include(Agents::WeatherAgent, Agents::WebsiteAgent)
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -134,44 +134,44 @@ describe Agent do
|
|
|
|
|
|
describe ".short_type" do
|
|
|
it "returns a short name without 'Agents::'" do
|
|
|
- Agents::SomethingSource.new.short_type.should == "SomethingSource"
|
|
|
- Agents::CannotBeScheduled.new.short_type.should == "CannotBeScheduled"
|
|
|
+ expect(Agents::SomethingSource.new.short_type).to eq("SomethingSource")
|
|
|
+ expect(Agents::CannotBeScheduled.new.short_type).to eq("CannotBeScheduled")
|
|
|
end
|
|
|
end
|
|
|
|
|
|
describe ".default_schedule" do
|
|
|
it "stores the default on the class" do
|
|
|
- Agents::SomethingSource.default_schedule.should == "2pm"
|
|
|
- Agents::SomethingSource.new.default_schedule.should == "2pm"
|
|
|
+ expect(Agents::SomethingSource.default_schedule).to eq("2pm")
|
|
|
+ expect(Agents::SomethingSource.new.default_schedule).to eq("2pm")
|
|
|
end
|
|
|
|
|
|
it "sets the default on new instances, allows setting new schedules, and prevents invalid schedules" do
|
|
|
@checker = Agents::SomethingSource.new(:name => "something")
|
|
|
@checker.user = users(:bob)
|
|
|
- @checker.schedule.should == "2pm"
|
|
|
+ expect(@checker.schedule).to eq("2pm")
|
|
|
@checker.save!
|
|
|
- @checker.reload.schedule.should == "2pm"
|
|
|
+ expect(@checker.reload.schedule).to eq("2pm")
|
|
|
@checker.update_attribute :schedule, "5pm"
|
|
|
- @checker.reload.schedule.should == "5pm"
|
|
|
+ expect(@checker.reload.schedule).to eq("5pm")
|
|
|
|
|
|
- @checker.reload.schedule.should == "5pm"
|
|
|
+ expect(@checker.reload.schedule).to eq("5pm")
|
|
|
|
|
|
@checker.schedule = "this_is_not_real"
|
|
|
- @checker.should have(1).errors_on(:schedule)
|
|
|
+ expect(@checker).to have(1).errors_on(:schedule)
|
|
|
end
|
|
|
|
|
|
it "should have an empty schedule if it cannot_be_scheduled" do
|
|
|
@checker = Agents::CannotBeScheduled.new(:name => "something")
|
|
|
@checker.user = users(:bob)
|
|
|
- @checker.schedule.should be_nil
|
|
|
- @checker.should be_valid
|
|
|
+ expect(@checker.schedule).to be_nil
|
|
|
+ expect(@checker).to be_valid
|
|
|
@checker.schedule = "5pm"
|
|
|
@checker.save!
|
|
|
- @checker.schedule.should be_nil
|
|
|
+ expect(@checker.schedule).to be_nil
|
|
|
|
|
|
@checker.schedule = "5pm"
|
|
|
- @checker.should have(0).errors_on(:schedule)
|
|
|
- @checker.schedule.should be_nil
|
|
|
+ expect(@checker).to have(0).errors_on(:schedule)
|
|
|
+ expect(@checker.schedule).to be_nil
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -184,15 +184,15 @@ describe Agent do
|
|
|
|
|
|
it "should use the checker's user" do
|
|
|
@checker.check
|
|
|
- Event.last.user.should == @checker.user
|
|
|
+ expect(Event.last.user).to eq(@checker.user)
|
|
|
end
|
|
|
|
|
|
it "should log an error if the Agent has been marked with 'cannot_create_events!'" do
|
|
|
mock(@checker).can_create_events? { false }
|
|
|
- lambda {
|
|
|
+ expect {
|
|
|
@checker.check
|
|
|
- }.should_not change { Event.count }
|
|
|
- @checker.logs.first.message.should =~ /cannot create events/i
|
|
|
+ }.not_to change { Event.count }
|
|
|
+ expect(@checker.logs.first.message).to match(/cannot create events/i)
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -210,10 +210,10 @@ describe Agent do
|
|
|
|
|
|
mock(Agent).find(@checker.id) { @checker }
|
|
|
|
|
|
- @checker.last_check_at.should be_nil
|
|
|
+ expect(@checker.last_check_at).to be_nil
|
|
|
Agents::SomethingSource.async_check(@checker.id)
|
|
|
- @checker.reload.last_check_at.should be_within(2).of(Time.now)
|
|
|
- @checker.reload.options[:new].should be_truthy # Show that we save options
|
|
|
+ expect(@checker.reload.last_check_at).to be_within(2).of(Time.now)
|
|
|
+ expect(@checker.reload.options[:new]).to be_truthy # Show that we save options
|
|
|
end
|
|
|
|
|
|
it "should log exceptions" do
|
|
@@ -221,12 +221,12 @@ describe Agent do
|
|
|
raise "foo"
|
|
|
}
|
|
|
mock(Agent).find(@checker.id) { @checker }
|
|
|
- lambda {
|
|
|
+ expect {
|
|
|
Agents::SomethingSource.async_check(@checker.id)
|
|
|
- }.should raise_error
|
|
|
+ }.to raise_error
|
|
|
log = @checker.logs.first
|
|
|
- log.message.should =~ /Exception/
|
|
|
- log.level.should == 4
|
|
|
+ expect(log.message).to match(/Exception/)
|
|
|
+ expect(log.level).to eq(4)
|
|
|
end
|
|
|
|
|
|
it "should not run disabled Agents" do
|
|
@@ -261,24 +261,24 @@ describe Agent do
|
|
|
raise "foo"
|
|
|
}
|
|
|
Agent.async_check(agents(:bob_weather_agent).id)
|
|
|
- lambda {
|
|
|
+ expect {
|
|
|
Agent.async_receive(agents(:bob_rain_notifier_agent).id, [agents(:bob_weather_agent).events.last.id])
|
|
|
- }.should raise_error
|
|
|
+ }.to raise_error
|
|
|
log = agents(:bob_rain_notifier_agent).logs.first
|
|
|
- log.message.should =~ /Exception/
|
|
|
- log.level.should == 4
|
|
|
+ expect(log.message).to match(/Exception/)
|
|
|
+ expect(log.level).to eq(4)
|
|
|
end
|
|
|
|
|
|
it "should track when events have been seen and not received them again" do
|
|
|
mock.any_instance_of(Agents::TriggerAgent).receive(anything).once
|
|
|
Agent.async_check(agents(:bob_weather_agent).id)
|
|
|
- lambda {
|
|
|
+ expect {
|
|
|
Agent.receive!
|
|
|
- }.should change { agents(:bob_rain_notifier_agent).reload.last_checked_event_id }
|
|
|
+ }.to change { agents(:bob_rain_notifier_agent).reload.last_checked_event_id }
|
|
|
|
|
|
- lambda {
|
|
|
+ expect {
|
|
|
Agent.receive!
|
|
|
- }.should_not change { agents(:bob_rain_notifier_agent).reload.last_checked_event_id }
|
|
|
+ }.not_to change { agents(:bob_rain_notifier_agent).reload.last_checked_event_id }
|
|
|
end
|
|
|
|
|
|
it "should not run consumers that have nothing to do" do
|
|
@@ -288,7 +288,7 @@ describe Agent do
|
|
|
|
|
|
it "should group events" do
|
|
|
mock.any_instance_of(Agents::TriggerAgent).receive(anything).twice { |events|
|
|
|
- events.map(&:user).map(&:username).uniq.length.should == 1
|
|
|
+ expect(events.map(&:user).map(&:username).uniq.length).to eq(1)
|
|
|
}
|
|
|
Agent.async_check(agents(:bob_weather_agent).id)
|
|
|
Agent.async_check(agents(:jane_weather_agent).id)
|
|
@@ -304,9 +304,9 @@ describe Agent do
|
|
|
mock.any_instance_of(Agents::TriggerAgent).receive(anything).twice
|
|
|
agents(:bob_weather_agent).check # bob_weather_agent makes an event
|
|
|
|
|
|
- lambda {
|
|
|
+ expect {
|
|
|
Agent.receive! # event gets propagated
|
|
|
- }.should change { agents(:bob_rain_notifier_agent).reload.last_checked_event_id }
|
|
|
+ }.to change { agents(:bob_rain_notifier_agent).reload.last_checked_event_id }
|
|
|
|
|
|
# This agent creates a few events before we link to it, but after our last check.
|
|
|
agent2.check
|
|
@@ -314,18 +314,18 @@ describe Agent do
|
|
|
|
|
|
# Now we link to it.
|
|
|
agents(:bob_rain_notifier_agent).sources << agent2
|
|
|
- agent2.links_as_source.first.event_id_at_creation.should == agent2.events.reorder("events.id desc").first.id
|
|
|
+ expect(agent2.links_as_source.first.event_id_at_creation).to eq(agent2.events.reorder("events.id desc").first.id)
|
|
|
|
|
|
- lambda {
|
|
|
+ expect {
|
|
|
Agent.receive! # but we don't receive those events because they're too old
|
|
|
- }.should_not change { agents(:bob_rain_notifier_agent).reload.last_checked_event_id }
|
|
|
+ }.not_to change { agents(:bob_rain_notifier_agent).reload.last_checked_event_id }
|
|
|
|
|
|
# Now a new event is created by agent2
|
|
|
agent2.check
|
|
|
|
|
|
- lambda {
|
|
|
+ expect {
|
|
|
Agent.receive! # and we receive it
|
|
|
- }.should change { agents(:bob_rain_notifier_agent).reload.last_checked_event_id }
|
|
|
+ }.to change { agents(:bob_rain_notifier_agent).reload.last_checked_event_id }
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -346,19 +346,19 @@ describe Agent do
|
|
|
sender.save!
|
|
|
sender.create_event :payload => {}
|
|
|
sender.create_event :payload => {}
|
|
|
- sender.events.count.should == 2
|
|
|
+ expect(sender.events.count).to eq(2)
|
|
|
|
|
|
receiver = Agents::CannotBeScheduled.new(:name => "Receiving Agent")
|
|
|
receiver.user = users(:bob)
|
|
|
receiver.sources << sender
|
|
|
receiver.save!
|
|
|
|
|
|
- receiver.events.count.should == 0
|
|
|
+ expect(receiver.events.count).to eq(0)
|
|
|
Agent.receive!
|
|
|
- receiver.events.count.should == 0
|
|
|
+ expect(receiver.events.count).to eq(0)
|
|
|
sender.create_event :payload => {}
|
|
|
Agent.receive!
|
|
|
- receiver.events.count.should == 1
|
|
|
+ expect(receiver.events.count).to eq(1)
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -378,8 +378,8 @@ describe Agent do
|
|
|
receiver.save!
|
|
|
|
|
|
sender.create_event :payload => {"message" => "new payload"}
|
|
|
- sender.events.count.should == 1
|
|
|
- receiver.events.count.should == 1
|
|
|
+ expect(sender.events.count).to eq(1)
|
|
|
+ expect(receiver.events.count).to eq(1)
|
|
|
#should be true without calling Agent.receive!
|
|
|
end
|
|
|
|
|
@@ -405,15 +405,15 @@ describe Agent do
|
|
|
slow_receiver.save!
|
|
|
|
|
|
sender.create_event :payload => {"message" => "new payload"}
|
|
|
- sender.events.count.should == 1
|
|
|
- im_receiver.events.count.should == 1
|
|
|
+ expect(sender.events.count).to eq(1)
|
|
|
+ expect(im_receiver.events.count).to eq(1)
|
|
|
#we should get the quick one
|
|
|
#but not the slow one
|
|
|
- slow_receiver.events.count.should == 0
|
|
|
+ expect(slow_receiver.events.count).to eq(0)
|
|
|
Agent.receive!
|
|
|
#now we should have one in both
|
|
|
- im_receiver.events.count.should == 1
|
|
|
- slow_receiver.events.count.should == 1
|
|
|
+ expect(im_receiver.events.count).to eq(1)
|
|
|
+ expect(slow_receiver.events.count).to eq(1)
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -422,18 +422,18 @@ describe Agent do
|
|
|
agent = Agents::SomethingSource.new(:name => "something")
|
|
|
agent.user = users(:bob)
|
|
|
agent.options[:bad] = true
|
|
|
- agent.should have(1).error_on(:base)
|
|
|
+ expect(agent).to have(1).error_on(:base)
|
|
|
agent.options[:bad] = false
|
|
|
- agent.should have(0).errors_on(:base)
|
|
|
+ expect(agent).to have(0).errors_on(:base)
|
|
|
end
|
|
|
|
|
|
it "makes options symbol-indifferent before validating" do
|
|
|
agent = Agents::SomethingSource.new(:name => "something")
|
|
|
agent.user = users(:bob)
|
|
|
agent.options["bad"] = true
|
|
|
- agent.should have(1).error_on(:base)
|
|
|
+ expect(agent).to have(1).error_on(:base)
|
|
|
agent.options["bad"] = false
|
|
|
- agent.should have(0).errors_on(:base)
|
|
|
+ expect(agent).to have(0).errors_on(:base)
|
|
|
end
|
|
|
|
|
|
it "makes memory symbol-indifferent before validating" do
|
|
@@ -441,82 +441,82 @@ describe Agent do
|
|
|
agent.user = users(:bob)
|
|
|
agent.memory["bad"] = 2
|
|
|
agent.save
|
|
|
- agent.memory[:bad].should == 2
|
|
|
+ expect(agent.memory[:bad]).to eq(2)
|
|
|
end
|
|
|
|
|
|
it "should work when assigned a hash or JSON string" do
|
|
|
agent = Agents::SomethingSource.new(:name => "something")
|
|
|
agent.memory = {}
|
|
|
- agent.memory.should == {}
|
|
|
- agent.memory["foo"].should be_nil
|
|
|
+ expect(agent.memory).to eq({})
|
|
|
+ expect(agent.memory["foo"]).to be_nil
|
|
|
|
|
|
agent.memory = ""
|
|
|
- agent.memory["foo"].should be_nil
|
|
|
- agent.memory.should == {}
|
|
|
+ expect(agent.memory["foo"]).to be_nil
|
|
|
+ expect(agent.memory).to eq({})
|
|
|
|
|
|
agent.memory = '{"hi": "there"}'
|
|
|
- agent.memory.should == { "hi" => "there" }
|
|
|
+ expect(agent.memory).to eq({ "hi" => "there" })
|
|
|
|
|
|
agent.memory = '{invalid}'
|
|
|
- agent.memory.should == { "hi" => "there" }
|
|
|
- agent.should have(1).errors_on(:memory)
|
|
|
+ expect(agent.memory).to eq({ "hi" => "there" })
|
|
|
+ expect(agent).to have(1).errors_on(:memory)
|
|
|
|
|
|
agent.memory = "{}"
|
|
|
- agent.memory["foo"].should be_nil
|
|
|
- agent.memory.should == {}
|
|
|
- agent.should have(0).errors_on(:memory)
|
|
|
+ expect(agent.memory["foo"]).to be_nil
|
|
|
+ expect(agent.memory).to eq({})
|
|
|
+ expect(agent).to have(0).errors_on(:memory)
|
|
|
|
|
|
agent.options = "{}"
|
|
|
- agent.options["foo"].should be_nil
|
|
|
- agent.options.should == {}
|
|
|
- agent.should have(0).errors_on(:options)
|
|
|
+ expect(agent.options["foo"]).to be_nil
|
|
|
+ expect(agent.options).to eq({})
|
|
|
+ expect(agent).to have(0).errors_on(:options)
|
|
|
|
|
|
agent.options = '{"hi": 2}'
|
|
|
- agent.options["hi"].should == 2
|
|
|
- agent.should have(0).errors_on(:options)
|
|
|
+ expect(agent.options["hi"]).to eq(2)
|
|
|
+ expect(agent).to have(0).errors_on(:options)
|
|
|
|
|
|
agent.options = '{"hi": wut}'
|
|
|
- agent.options["hi"].should == 2
|
|
|
- agent.should have(1).errors_on(:options)
|
|
|
- agent.errors_on(:options).should include("was assigned invalid JSON")
|
|
|
+ expect(agent.options["hi"]).to eq(2)
|
|
|
+ expect(agent).to have(1).errors_on(:options)
|
|
|
+ expect(agent.errors_on(:options)).to include("was assigned invalid JSON")
|
|
|
|
|
|
agent.options = 5
|
|
|
- agent.options["hi"].should == 2
|
|
|
- agent.should have(1).errors_on(:options)
|
|
|
- agent.errors_on(:options).should include("cannot be set to an instance of Fixnum")
|
|
|
+ expect(agent.options["hi"]).to eq(2)
|
|
|
+ expect(agent).to have(1).errors_on(:options)
|
|
|
+ expect(agent.errors_on(:options)).to include("cannot be set to an instance of Fixnum")
|
|
|
end
|
|
|
|
|
|
it "should not allow source agents owned by other people" do
|
|
|
agent = Agents::SomethingSource.new(:name => "something")
|
|
|
agent.user = users(:bob)
|
|
|
agent.source_ids = [agents(:bob_weather_agent).id]
|
|
|
- agent.should have(0).errors_on(:sources)
|
|
|
+ expect(agent).to have(0).errors_on(:sources)
|
|
|
agent.source_ids = [agents(:jane_weather_agent).id]
|
|
|
- agent.should have(1).errors_on(:sources)
|
|
|
+ expect(agent).to have(1).errors_on(:sources)
|
|
|
agent.user = users(:jane)
|
|
|
- agent.should have(0).errors_on(:sources)
|
|
|
+ expect(agent).to have(0).errors_on(:sources)
|
|
|
end
|
|
|
|
|
|
it "should not allow controller agents owned by other people" do
|
|
|
agent = Agents::SomethingSource.new(:name => "something")
|
|
|
agent.user = users(:bob)
|
|
|
agent.controller_ids = [agents(:bob_weather_agent).id]
|
|
|
- agent.should have(0).errors_on(:controllers)
|
|
|
+ expect(agent).to have(0).errors_on(:controllers)
|
|
|
agent.controller_ids = [agents(:jane_weather_agent).id]
|
|
|
- agent.should have(1).errors_on(:controllers)
|
|
|
+ expect(agent).to have(1).errors_on(:controllers)
|
|
|
agent.user = users(:jane)
|
|
|
- agent.should have(0).errors_on(:controllers)
|
|
|
+ expect(agent).to have(0).errors_on(:controllers)
|
|
|
end
|
|
|
|
|
|
it "should not allow control target agents owned by other people" do
|
|
|
agent = Agents::CannotBeScheduled.new(:name => "something")
|
|
|
agent.user = users(:bob)
|
|
|
agent.control_target_ids = [agents(:bob_weather_agent).id]
|
|
|
- agent.should have(0).errors_on(:control_targets)
|
|
|
+ expect(agent).to have(0).errors_on(:control_targets)
|
|
|
agent.control_target_ids = [agents(:jane_weather_agent).id]
|
|
|
- agent.should have(1).errors_on(:control_targets)
|
|
|
+ expect(agent).to have(1).errors_on(:control_targets)
|
|
|
agent.user = users(:jane)
|
|
|
- agent.should have(0).errors_on(:control_targets)
|
|
|
+ expect(agent).to have(0).errors_on(:control_targets)
|
|
|
end
|
|
|
|
|
|
it "should not allow scenarios owned by other people" do
|
|
@@ -524,38 +524,38 @@ describe Agent do
|
|
|
agent.user = users(:bob)
|
|
|
|
|
|
agent.scenario_ids = [scenarios(:bob_weather).id]
|
|
|
- agent.should have(0).errors_on(:scenarios)
|
|
|
+ expect(agent).to have(0).errors_on(:scenarios)
|
|
|
|
|
|
agent.scenario_ids = [scenarios(:bob_weather).id, scenarios(:jane_weather).id]
|
|
|
- agent.should have(1).errors_on(:scenarios)
|
|
|
+ expect(agent).to have(1).errors_on(:scenarios)
|
|
|
|
|
|
agent.scenario_ids = [scenarios(:jane_weather).id]
|
|
|
- agent.should have(1).errors_on(:scenarios)
|
|
|
+ expect(agent).to have(1).errors_on(:scenarios)
|
|
|
|
|
|
agent.user = users(:jane)
|
|
|
- agent.should have(0).errors_on(:scenarios)
|
|
|
+ expect(agent).to have(0).errors_on(:scenarios)
|
|
|
end
|
|
|
|
|
|
it "validates keep_events_for" do
|
|
|
agent = Agents::SomethingSource.new(:name => "something")
|
|
|
agent.user = users(:bob)
|
|
|
- agent.should be_valid
|
|
|
+ expect(agent).to be_valid
|
|
|
agent.keep_events_for = nil
|
|
|
- agent.should have(1).errors_on(:keep_events_for)
|
|
|
+ expect(agent).to have(1).errors_on(:keep_events_for)
|
|
|
agent.keep_events_for = 1000
|
|
|
- agent.should have(1).errors_on(:keep_events_for)
|
|
|
+ expect(agent).to have(1).errors_on(:keep_events_for)
|
|
|
agent.keep_events_for = ""
|
|
|
- agent.should have(1).errors_on(:keep_events_for)
|
|
|
+ expect(agent).to have(1).errors_on(:keep_events_for)
|
|
|
agent.keep_events_for = 5
|
|
|
- agent.should be_valid
|
|
|
+ expect(agent).to be_valid
|
|
|
agent.keep_events_for = 0
|
|
|
- agent.should be_valid
|
|
|
+ expect(agent).to be_valid
|
|
|
agent.keep_events_for = 365
|
|
|
- agent.should be_valid
|
|
|
+ expect(agent).to be_valid
|
|
|
|
|
|
# Rails seems to call to_i on the input. This guards against future changes to that behavior.
|
|
|
agent.keep_events_for = "drop table;"
|
|
|
- agent.keep_events_for.should == 0
|
|
|
+ expect(agent.keep_events_for).to eq(0)
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -566,7 +566,7 @@ describe Agent do
|
|
|
@agent.user = users(:bob)
|
|
|
@agent.save!
|
|
|
@event = @agent.create_event :payload => { "hello" => "world" }
|
|
|
- @event.expires_at.to_i.should be_within(2).of(5.days.from_now.to_i)
|
|
|
+ expect(@event.expires_at.to_i).to be_within(2).of(5.days.from_now.to_i)
|
|
|
end
|
|
|
|
|
|
describe "when keep_events_for has not changed" do
|
|
@@ -584,32 +584,32 @@ describe Agent do
|
|
|
|
|
|
describe "when keep_events_for is changed" do
|
|
|
it "updates events' expires_at" do
|
|
|
- lambda {
|
|
|
+ expect {
|
|
|
@agent.options[:foo] = "bar1"
|
|
|
@agent.keep_events_for = 3
|
|
|
@agent.save!
|
|
|
- }.should change { @event.reload.expires_at }
|
|
|
- @event.expires_at.to_i.should be_within(2).of(3.days.from_now.to_i)
|
|
|
+ }.to change { @event.reload.expires_at }
|
|
|
+ expect(@event.expires_at.to_i).to be_within(2).of(3.days.from_now.to_i)
|
|
|
end
|
|
|
|
|
|
it "updates events relative to their created_at" do
|
|
|
@event.update_attribute :created_at, 2.days.ago
|
|
|
- @event.reload.created_at.to_i.should be_within(2).of(2.days.ago.to_i)
|
|
|
+ expect(@event.reload.created_at.to_i).to be_within(2).of(2.days.ago.to_i)
|
|
|
|
|
|
- lambda {
|
|
|
+ expect {
|
|
|
@agent.options[:foo] = "bar2"
|
|
|
@agent.keep_events_for = 3
|
|
|
@agent.save!
|
|
|
- }.should change { @event.reload.expires_at }
|
|
|
- @event.expires_at.to_i.should be_within(60 * 61).of(1.days.from_now.to_i) # The larger time is to deal with daylight savings
|
|
|
+ }.to change { @event.reload.expires_at }
|
|
|
+ expect(@event.expires_at.to_i).to be_within(60 * 61).of(1.days.from_now.to_i) # The larger time is to deal with daylight savings
|
|
|
end
|
|
|
|
|
|
it "nulls out expires_at when keep_events_for is set to 0" do
|
|
|
- lambda {
|
|
|
+ expect {
|
|
|
@agent.options[:foo] = "bar"
|
|
|
@agent.keep_events_for = 0
|
|
|
@agent.save!
|
|
|
- }.should change { @event.reload.expires_at }.to(nil)
|
|
|
+ }.to change { @event.reload.expires_at }.to(nil)
|
|
|
end
|
|
|
end
|
|
|
end
|
|
@@ -625,7 +625,7 @@ describe Agent do
|
|
|
@sender.save!
|
|
|
@sender.create_event :payload => {}
|
|
|
@sender.create_event :payload => {}
|
|
|
- @sender.events.count.should == 2
|
|
|
+ expect(@sender.events.count).to eq(2)
|
|
|
|
|
|
@receiver = Agents::CannotBeScheduled.new(
|
|
|
name: 'Agent',
|
|
@@ -641,21 +641,21 @@ describe Agent do
|
|
|
it "should create a clone of a given agent for editing" do
|
|
|
sender_clone = users(:bob).agents.build_clone(@sender)
|
|
|
|
|
|
- sender_clone.attributes.should == Agent.new.attributes.
|
|
|
+ expect(sender_clone.attributes).to eq(Agent.new.attributes.
|
|
|
update(@sender.slice(:user_id, :type,
|
|
|
:options, :schedule, :keep_events_for, :propagate_immediately)).
|
|
|
- update('name' => 'Agent (2) (2)', 'options' => { 'foo' => 'bar2' })
|
|
|
+ update('name' => 'Agent (2) (2)', 'options' => { 'foo' => 'bar2' }))
|
|
|
|
|
|
- sender_clone.source_ids.should == []
|
|
|
+ expect(sender_clone.source_ids).to eq([])
|
|
|
|
|
|
receiver_clone = users(:bob).agents.build_clone(@receiver)
|
|
|
|
|
|
- receiver_clone.attributes.should == Agent.new.attributes.
|
|
|
+ expect(receiver_clone.attributes).to eq(Agent.new.attributes.
|
|
|
update(@receiver.slice(:user_id, :type,
|
|
|
:options, :schedule, :keep_events_for, :propagate_immediately)).
|
|
|
- update('name' => 'Agent (3)', 'options' => { 'foo' => 'bar3' })
|
|
|
+ update('name' => 'Agent (3)', 'options' => { 'foo' => 'bar3' }))
|
|
|
|
|
|
- receiver_clone.source_ids.should == [@sender.id]
|
|
|
+ expect(receiver_clone.source_ids).to eq([@sender.id])
|
|
|
end
|
|
|
end
|
|
|
end
|
|
@@ -683,8 +683,8 @@ describe Agent do
|
|
|
|
|
|
it "calls the .receive_web_request hook, updates last_web_request_at, and saves" do
|
|
|
@agent.trigger_web_request({ :some_param => "some_value" }, "post", "text/html")
|
|
|
- @agent.reload.memory['last_request'].should == [ { "some_param" => "some_value" }, "post", "text/html" ]
|
|
|
- @agent.last_web_request_at.to_i.should be_within(1).of(Time.now.to_i)
|
|
|
+ expect(@agent.reload.memory['last_request']).to eq([ { "some_param" => "some_value" }, "post", "text/html" ])
|
|
|
+ expect(@agent.last_web_request_at.to_i).to be_within(1).of(Time.now.to_i)
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -703,8 +703,8 @@ describe Agent do
|
|
|
it "outputs a deprecation warning and calls .receive_webhook with the params" do
|
|
|
mock(Rails.logger).warn("DEPRECATED: The .receive_webhook method is deprecated, please switch your Agent to use .receive_web_request.")
|
|
|
@agent.trigger_web_request({ :some_param => "some_value" }, "post", "text/html")
|
|
|
- @agent.reload.memory['last_webhook_request'].should == { "some_param" => "some_value" }
|
|
|
- @agent.last_web_request_at.to_i.should be_within(1).of(Time.now.to_i)
|
|
|
+ expect(@agent.reload.memory['last_webhook_request']).to eq({ "some_param" => "some_value" })
|
|
|
+ expect(@agent.last_web_request_at.to_i).to be_within(1).of(Time.now.to_i)
|
|
|
end
|
|
|
end
|
|
|
end
|
|
@@ -713,23 +713,23 @@ describe Agent do
|
|
|
describe "of_type" do
|
|
|
it "should accept classes" do
|
|
|
agents = Agent.of_type(Agents::WebsiteAgent)
|
|
|
- agents.should include(agents(:bob_website_agent))
|
|
|
- agents.should include(agents(:jane_website_agent))
|
|
|
- agents.should_not include(agents(:bob_weather_agent))
|
|
|
+ expect(agents).to include(agents(:bob_website_agent))
|
|
|
+ expect(agents).to include(agents(:jane_website_agent))
|
|
|
+ expect(agents).not_to include(agents(:bob_weather_agent))
|
|
|
end
|
|
|
|
|
|
it "should accept strings" do
|
|
|
agents = Agent.of_type("Agents::WebsiteAgent")
|
|
|
- agents.should include(agents(:bob_website_agent))
|
|
|
- agents.should include(agents(:jane_website_agent))
|
|
|
- agents.should_not include(agents(:bob_weather_agent))
|
|
|
+ expect(agents).to include(agents(:bob_website_agent))
|
|
|
+ expect(agents).to include(agents(:jane_website_agent))
|
|
|
+ expect(agents).not_to include(agents(:bob_weather_agent))
|
|
|
end
|
|
|
|
|
|
it "should accept instances of an Agent" do
|
|
|
agents = Agent.of_type(agents(:bob_website_agent))
|
|
|
- agents.should include(agents(:bob_website_agent))
|
|
|
- agents.should include(agents(:jane_website_agent))
|
|
|
- agents.should_not include(agents(:bob_weather_agent))
|
|
|
+ expect(agents).to include(agents(:bob_website_agent))
|
|
|
+ expect(agents).to include(agents(:jane_website_agent))
|
|
|
+ expect(agents).not_to include(agents(:bob_weather_agent))
|
|
|
end
|
|
|
end
|
|
|
end
|
|
@@ -737,23 +737,23 @@ describe Agent do
|
|
|
describe "#create_event" do
|
|
|
describe "when the agent has keep_events_for set" do
|
|
|
before do
|
|
|
- agents(:jane_weather_agent).keep_events_for.should > 0
|
|
|
+ expect(agents(:jane_weather_agent).keep_events_for).to be > 0
|
|
|
end
|
|
|
|
|
|
it "sets expires_at on created events" do
|
|
|
event = agents(:jane_weather_agent).create_event :payload => { 'hi' => 'there' }
|
|
|
- event.expires_at.to_i.should be_within(5).of(agents(:jane_weather_agent).keep_events_for.days.from_now.to_i)
|
|
|
+ expect(event.expires_at.to_i).to be_within(5).of(agents(:jane_weather_agent).keep_events_for.days.from_now.to_i)
|
|
|
end
|
|
|
end
|
|
|
|
|
|
describe "when the agent does not have keep_events_for set" do
|
|
|
before do
|
|
|
- agents(:jane_website_agent).keep_events_for.should == 0
|
|
|
+ expect(agents(:jane_website_agent).keep_events_for).to eq(0)
|
|
|
end
|
|
|
|
|
|
it "does not set expires_at on created events" do
|
|
|
event = agents(:jane_website_agent).create_event :payload => { 'hi' => 'there' }
|
|
|
- event.expires_at.should be_nil
|
|
|
+ expect(event.expires_at).to be_nil
|
|
|
end
|
|
|
end
|
|
|
end
|
|
@@ -764,13 +764,13 @@ describe Agent do
|
|
|
agent.last_checked_event_id = nil
|
|
|
agent.save!
|
|
|
agent.update!(drop_pending_events: true)
|
|
|
- agent.reload.last_checked_event_id.should == Event.maximum(:id)
|
|
|
+ expect(agent.reload.last_checked_event_id).to eq(Event.maximum(:id))
|
|
|
end
|
|
|
|
|
|
it "should not affect a virtual attribute drop_pending_events" do
|
|
|
agent = agents(:bob_rain_notifier_agent)
|
|
|
agent.update!(drop_pending_events: true)
|
|
|
- agent.reload.drop_pending_events.should == false
|
|
|
+ expect(agent.reload.drop_pending_events).to eq(false)
|
|
|
end
|
|
|
end
|
|
|
|
|
@@ -784,30 +784,30 @@ describe Agent do
|
|
|
agent1 = agents(:bob_weather_agent)
|
|
|
agent2 = agents(:bob_rain_notifier_agent)
|
|
|
|
|
|
- -> {
|
|
|
- -> {
|
|
|
+ expect {
|
|
|
+ expect {
|
|
|
Agent.async_check(agent1.id)
|
|
|
Agent.receive!
|
|
|
- }.should change { agent1.events.count }.by(1)
|
|
|
- }.should change { agent2.events.count }.by(1)
|
|
|
+ }.to change { agent1.events.count }.by(1)
|
|
|
+ }.to change { agent2.events.count }.by(1)
|
|
|
|
|
|
agent2.disabled = true
|
|
|
agent2.save!
|
|
|
|
|
|
- -> {
|
|
|
- -> {
|
|
|
+ expect {
|
|
|
+ expect {
|
|
|
Agent.async_check(agent1.id)
|
|
|
Agent.receive!
|
|
|
- }.should change { agent1.events.count }.by(1)
|
|
|
- }.should_not change { agent2.events.count }
|
|
|
+ }.to change { agent1.events.count }.by(1)
|
|
|
+ }.not_to change { agent2.events.count }
|
|
|
|
|
|
agent2.disabled = false
|
|
|
agent2.drop_pending_events = true
|
|
|
agent2.save!
|
|
|
|
|
|
- -> {
|
|
|
+ expect {
|
|
|
Agent.receive!
|
|
|
- }.should_not change { agent2.events.count }
|
|
|
+ }.not_to change { agent2.events.count }
|
|
|
end
|
|
|
end
|
|
|
end
|
|
@@ -872,37 +872,37 @@ describe AgentDrop do
|
|
|
end
|
|
|
|
|
|
it 'should be created via Agent#to_liquid' do
|
|
|
- @wsa1.to_liquid.class.should be(AgentDrop)
|
|
|
- @wsa2.to_liquid.class.should be(AgentDrop)
|
|
|
- @efa.to_liquid.class.should be(AgentDrop)
|
|
|
+ expect(@wsa1.to_liquid.class).to be(AgentDrop)
|
|
|
+ expect(@wsa2.to_liquid.class).to be(AgentDrop)
|
|
|
+ expect(@efa.to_liquid.class).to be(AgentDrop)
|
|
|
end
|
|
|
|
|
|
it 'should have .type and .name' do
|
|
|
t = '{{agent.type}}: {{agent.name}}'
|
|
|
- interpolate(t, @wsa1).should eq('WebsiteAgent: XKCD')
|
|
|
- interpolate(t, @wsa2).should eq('WebsiteAgent: Dilbert')
|
|
|
- interpolate(t, @efa).should eq('EventFormattingAgent: Formatter')
|
|
|
+ expect(interpolate(t, @wsa1)).to eq('WebsiteAgent: XKCD')
|
|
|
+ expect(interpolate(t, @wsa2)).to eq('WebsiteAgent: Dilbert')
|
|
|
+ expect(interpolate(t, @efa)).to eq('EventFormattingAgent: Formatter')
|
|
|
end
|
|
|
|
|
|
it 'should have .options' do
|
|
|
t = '{{agent.options.url}}'
|
|
|
- interpolate(t, @wsa1).should eq('http://xkcd.com/')
|
|
|
- interpolate(t, @wsa2).should eq('http://dilbert.com/')
|
|
|
- interpolate('{{agent.options.instructions.message}}',
|
|
|
- @efa).should eq('{{agent.name}}: {{title}} {{url}}')
|
|
|
+ expect(interpolate(t, @wsa1)).to eq('http://xkcd.com/')
|
|
|
+ expect(interpolate(t, @wsa2)).to eq('http://dilbert.com/')
|
|
|
+ expect(interpolate('{{agent.options.instructions.message}}',
|
|
|
+ @efa)).to eq('{{agent.name}}: {{title}} {{url}}')
|
|
|
end
|
|
|
|
|
|
it 'should have .sources' do
|
|
|
t = '{{agent.sources.size}}: {{agent.sources | map:"name" | join:", "}}'
|
|
|
- interpolate(t, @wsa1).should eq('0: ')
|
|
|
- interpolate(t, @wsa2).should eq('0: ')
|
|
|
- interpolate(t, @efa).should eq('2: XKCD, Dilbert')
|
|
|
+ expect(interpolate(t, @wsa1)).to eq('0: ')
|
|
|
+ expect(interpolate(t, @wsa2)).to eq('0: ')
|
|
|
+ expect(interpolate(t, @efa)).to eq('2: XKCD, Dilbert')
|
|
|
end
|
|
|
|
|
|
it 'should have .receivers' do
|
|
|
t = '{{agent.receivers.size}}: {{agent.receivers | map:"name" | join:", "}}'
|
|
|
- interpolate(t, @wsa1).should eq('1: Formatter')
|
|
|
- interpolate(t, @wsa2).should eq('1: Formatter')
|
|
|
- interpolate(t, @efa).should eq('0: ')
|
|
|
+ expect(interpolate(t, @wsa1)).to eq('1: Formatter')
|
|
|
+ expect(interpolate(t, @wsa2)).to eq('1: Formatter')
|
|
|
+ expect(interpolate(t, @efa)).to eq('0: ')
|
|
|
end
|
|
|
end
|