1
0

twitter_favorites_spec.rb 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. require 'rails_helper'
  2. describe Agents::TwitterFavorites do
  3. before do
  4. stub_request(:any, /tectonic.*[?&]tweet_mode=extended/)
  5. .to_return(body: File.read(Rails.root.join("spec/data_fixtures/user_fav_tweets.json")),
  6. headers: { 'Content-Type': 'application/json;charset=utf-8' },
  7. status: 200)
  8. end
  9. before do
  10. @opts = { username: "tectonic", number: "10", history: "100", expected_update_period_in_days: "2",
  11. starting_at: "Sat Feb 20 01:32:08 +0000 2016" }
  12. @agent = Agents::TwitterFavorites.new(name: "tectonic", options: @opts)
  13. @agent.service = services(:generic)
  14. @agent.events.new(payload: JSON.parse(File.read(Rails.root.join("spec/data_fixtures/one_fav_tweet.json"))))
  15. @agent.user = users(:bob)
  16. @agent.save!
  17. @event = Event.new
  18. @event.agent = agents(:tectonic_twitter_user_agent)
  19. @event.payload = JSON.parse(File.read(Rails.root.join("spec/data_fixtures/one_fav_tweet.json")))
  20. @event.save!
  21. end
  22. describe "making sure agent last event payload is equivalent to event payload" do
  23. it "expect change method to change event" do
  24. expect(@agent.events.last.payload).to eq(@event.payload)
  25. end
  26. end
  27. describe "making sure check method works" do
  28. it "expect change method to change event" do
  29. expect { @agent.check }.to change { Event.count }.by(3)
  30. Event.last(3).each_cons(2) do |t1, t2|
  31. expect(t1.payload[:id]).to be < t2.payload[:id]
  32. end
  33. end
  34. end
  35. describe "#check with starting_at=future date" do
  36. it "should check for changes starting_at a future date, thus not find any" do
  37. opts = @opts.merge({ starting_at: "Thurs Feb 23 16:12:04 +0000 2017" })
  38. @agent1 = Agents::TwitterFavorites.new(name: "tectonic", options: opts)
  39. @agent1.service = services(:generic)
  40. @agent1.user = users(:bob)
  41. @agent1.save!
  42. expect { @agent1.check }.to change { Event.count }.by(0)
  43. end
  44. end
  45. end