twitter_favorites_spec.rb 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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", :starting_at => "Sat Feb 20 01:32:08 +0000 2016"}
  11. @agent = Agents::TwitterFavorites.new(name: "tectonic", options: @opts)
  12. @agent.service = services(:generic)
  13. @agent.events.new(payload: JSON.parse(File.read(Rails.root.join("spec/data_fixtures/one_fav_tweet.json"))))
  14. @agent.user = users(:bob)
  15. @agent.save!
  16. @event = Event.new
  17. @event.agent = agents(:tectonic_twitter_user_agent)
  18. @event.payload = JSON.parse(File.read(Rails.root.join("spec/data_fixtures/one_fav_tweet.json")))
  19. @event.save!
  20. end
  21. describe "making sure agent last event payload is equivalent to event payload" do
  22. it "expect change method to change event" do
  23. expect(@agent.events.last.payload).to eq(@event.payload)
  24. end
  25. end
  26. describe "making sure check method works" do
  27. it "expect change method to change event" do
  28. expect { @agent.check }.to change {Event.count}.by(3)
  29. end
  30. end
  31. describe "#check with starting_at=future date" do
  32. it "should check for changes starting_at a future date, thus not find any" do
  33. opts = @opts.merge({ starting_at: "Thurs Feb 23 16:12:04 +0000 2017" })
  34. @agent1 = Agents::TwitterFavorites.new(name: "tectonic", options: opts)
  35. @agent1.service = services(:generic)
  36. @agent1.user = users(:bob)
  37. @agent1.save!
  38. expect { @agent1.check }.to change { Event.count }.by(0)
  39. end
  40. end
  41. end