twitter_search_agent_spec.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. require 'rails_helper'
  2. describe Agents::TwitterSearchAgent do
  3. before do
  4. # intercept the twitter API request
  5. stub_request(:any, /freebandnames.*[?&]tweet_mode=extended/).
  6. to_return(body: File.read(Rails.root.join("spec/data_fixtures/search_tweets.json")),
  7. headers: { 'Content-Type': 'application/json;charset=utf-8' },
  8. status: 200)
  9. @opts = {
  10. search: "freebandnames",
  11. expected_update_period_in_days: "2",
  12. starting_at: "Jan 01 00:00:01 +0000 2000",
  13. max_results: '3'
  14. }
  15. end
  16. let(:checker) {
  17. _checker = Agents::TwitterSearchAgent.new(name: "search freebandnames", options: @opts)
  18. _checker.service = services(:generic)
  19. _checker.user = users(:bob)
  20. _checker.save!
  21. _checker
  22. }
  23. describe "#check" do
  24. it "should check for changes" do
  25. expect { checker.check }.to change { Event.count }.by(3)
  26. end
  27. end
  28. describe "#check with starting_at=future date" do
  29. it "should check for changes starting_at a future date, thus not find any" do
  30. opts = @opts.merge({ starting_at: "Jan 01 00:00:01 +0000 2999" })
  31. checker = Agents::TwitterSearchAgent.new(name: "search freebandnames", options: opts)
  32. checker.service = services(:generic)
  33. checker.user = users(:bob)
  34. checker.save!
  35. expect { checker.check }.to change { Event.count }.by(0)
  36. end
  37. end
  38. end