twitter_user_agent_spec.rb 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. require 'spec_helper'
  2. describe Agents::TwitterUserAgent do
  3. before do
  4. # intercept the twitter API request for @tectonic's user profile
  5. stub_request(:any, /tectonic/).to_return(:body => File.read(Rails.root.join("spec/data_fixtures/user_tweets.json")), :status => 200)
  6. @opts = {
  7. :username => "tectonic",
  8. :expected_update_period_in_days => "2",
  9. :starting_at => "Jan 01 00:00:01 +0000 2000",
  10. :consumer_key => "---",
  11. :consumer_secret => "---",
  12. :oauth_token => "---",
  13. :oauth_token_secret => "---"
  14. }
  15. @checker = Agents::TwitterUserAgent.new(:name => "tectonic", :options => @opts)
  16. @checker.user = users(:bob)
  17. @checker.save!
  18. end
  19. describe "#check" do
  20. it "should check for changes" do
  21. lambda { @checker.check }.should change { Event.count }.by(5)
  22. end
  23. end
  24. describe "#check with starting_at=future date" do
  25. it "should check for changes starting_at a future date, thus not find any" do
  26. opts = @opts.merge({ :starting_at => "Jan 01 00:00:01 +0000 2999", })
  27. checker = Agents::TwitterUserAgent.new(:name => "tectonic", :options => opts)
  28. checker.user = users(:bob)
  29. checker.save!
  30. lambda { checker.check }.should change { Event.count }.by(0)
  31. end
  32. end
  33. end