Nenhuma Descrição http://j1x-huginn.herokuapp.com

twitter_publish_agent_spec.rb 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. require 'spec_helper'
  2. describe Agents::TwitterPublishAgent do
  3. before do
  4. @opts = {
  5. :username => "HuginnBot",
  6. :expected_update_period_in_days => "2",
  7. :consumer_key => "---",
  8. :consumer_secret => "---",
  9. :oauth_token => "---",
  10. :oauth_token_secret => "---",
  11. :message_path => "text"
  12. }
  13. @checker = Agents::TwitterPublishAgent.new(:name => "HuginnBot", :options => @opts)
  14. @checker.user = users(:bob)
  15. @checker.save!
  16. @event = Event.new
  17. @event.agent = agents(:bob_weather_agent)
  18. @event.payload = { :text => 'Gonna rain..' }
  19. @event.save!
  20. @sent_messages = []
  21. stub.any_instance_of(Agents::TwitterPublishAgent).publish_tweet { |message| @sent_messages << message}
  22. end
  23. describe '#receive' do
  24. it 'should publish any payload it receives' do
  25. event1 = Event.new
  26. event1.agent = agents(:bob_rain_notifier_agent)
  27. event1.payload = { :text => 'Gonna rain..' }
  28. event1.save!
  29. event2 = Event.new
  30. event2.agent = agents(:bob_weather_agent)
  31. event2.payload = { :text => 'More payload' }
  32. event2.save!
  33. Agents::TwitterPublishAgent.async_receive(@checker.id, [event1.id, event2.id])
  34. @sent_messages.count.should eq(2)
  35. @checker.events.count.should eq(2)
  36. end
  37. end
  38. describe '#working?' do
  39. it 'checks if events have been received within the expected receive period' do
  40. @checker.should_not be_working # No events received
  41. Agents::TwitterPublishAgent.async_receive(@checker.id, [@event.id])
  42. @checker.reload.should be_working # Just received events
  43. two_days_from_now = 2.days.from_now
  44. stub(Time).now { two_days_from_now }
  45. @checker.reload.should_not be_working # More time has passed than the expected receive period without any new events
  46. end
  47. end
  48. end