mirror of
https://github.com/Fishwaldo/huginn.git
synced 2025-03-15 19:31:26 +00:00
added one spec for twitter user agent
This commit is contained in:
parent
d001d10334
commit
a6167d5803
3 changed files with 29 additions and 22 deletions
|
@ -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
|
1
spec/data_fixtures/user_tweets.json
Normal file
1
spec/data_fixtures/user_tweets.json
Normal file
File diff suppressed because one or more lines are too long
28
spec/models/agents/twitter_user_agent_spec.rb
Normal file
28
spec/models/agents/twitter_user_agent_spec.rb
Normal 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
|
Loading…
Add table
Reference in a new issue