added one spec for twitter user agent

This commit is contained in:
Albert Sun 2013-04-08 12:10:42 -04:00
parent d001d10334
commit a6167d5803
3 changed files with 29 additions and 22 deletions

View file

@ -129,19 +129,6 @@ module Agents
}
end
# def process_tweet(filter, status)
# if options[:generate] == "counts"
# # Avoid memory pollution
# me = Agent.find(id)
# me.memory[:filter_counts] ||= {}
# me.memory[:filter_counts][filter.to_sym] ||= 0
# me.memory[:filter_counts][filter.to_sym] += 1
# me.save!
# else
# create_event :payload => status.merge(:filter => filter.to_s)
# end
# end
def check
Twitter.configure do |config|
config.consumer_key = options[:consumer_key]
@ -151,10 +138,8 @@ module Agents
end
since_id = memory[:since_id] || nil
max_id = memory[:max_id] || nil
opts = {:count => 200, :include_rts => true, :exclude_replies => false, :include_entities => true, :contributor_details => true}
opts.merge! :since_id => since_id unless since_id.nil?
opts.merge! :max_id => max_id unless max_id.nil?
tweets = Twitter.user_timeline(options[:username], opts)
@ -165,13 +150,6 @@ module Agents
end
save!
# if memory[:filter_counts] && memory[:filter_counts].length > 0
# memory[:filter_counts].each do |filter, count|
# create_event :payload => { :filter => filter.to_s, :count => count, :time => Time.now.to_i }
# end
# memory[:filter_counts] = {}
# save!
# end
end
end
end

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,28 @@
require 'spec_helper'
describe Agents::TwitterUserAgent do
before do
# intercept the twitter API request for @tectonic's user profile
stub_request(:any, /tectonic/).to_return(:body => File.read(Rails.root.join("spec/data_fixtures/user_tweets.json")), :status => 200)
@opts = {
:username => "tectonic",
:expected_update_period_in_days => "2",
:consumer_key => "---",
:consumer_secret => "---",
:oauth_token => "---",
:oauth_token_secret => "---"
}
@checker = Agents::TwitterUserAgent.new(:name => "tectonic", :options => @opts)
@checker.user = users(:bob)
@checker.save!
end
describe "#check" do
it "should check for changes" do
lambda { @checker.check }.should change { Event.count }.by(5)
end
end
end