Skip to content

Commit

Permalink
Ensure that we provide integer user ids to the streaming API connection
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemelia committed May 15, 2012
1 parent c82c6b9 commit cdc3a90
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
7 changes: 4 additions & 3 deletions lib/weeter/twitter/tweet_consumer.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ def reconnect(filter_params)
end end


protected protected

def clean_filter_params(p) def clean_filter_params(p)
return {} if p.nil? return {} if p.nil?
cleaned_params = {} cleaned_params = {}
cleaned_params['follow'] = p['follow'] if (p['follow'] || []).any? cleaned_params['follow'] = p['follow'] if (p['follow'] || []).any?
cleaned_params['follow'] = cleaned_params['follow'].map(&:to_i)
cleaned_params['track'] = p['track'] if (p['track'] || []).any? cleaned_params['track'] = p['track'] if (p['track'] || []).any?
cleaned_params cleaned_params
end end

def ignore_tweet(tweet_item) def ignore_tweet(tweet_item)
id = tweet_item['id_str'] id = tweet_item['id_str']
text = tweet_item['text'] text = tweet_item['text']
Expand All @@ -64,4 +65,4 @@ def ignore_tweet(tweet_item)


end end
end end
end end
12 changes: 6 additions & 6 deletions spec/weeter/twitter/tweet_consumer_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@client_proxy = mock('NotificationPlugin', :publish_tweet => nil) @client_proxy = mock('NotificationPlugin', :publish_tweet => nil)
@consumer = Weeter::Twitter::TweetConsumer.new(Weeter::Configuration::TwitterConfig.instance, @client_proxy) @consumer = Weeter::Twitter::TweetConsumer.new(Weeter::Configuration::TwitterConfig.instance, @client_proxy)
end end

after(:each) do after(:each) do
@consumer.connect(@filter_params) @consumer.connect(@filter_params)
end end
Expand All @@ -39,26 +39,26 @@


it "should connect to a Twitter JSON stream" do it "should connect to a Twitter JSON stream" do
Twitter::JSONStream.should_receive(:connect). Twitter::JSONStream.should_receive(:connect).
with(:ssl => true, :foo => :bar, :params => @filter_params, :method => 'POST') with(:ssl => true, :foo => :bar, :params => {'follow' => [1,2,3]}, :method => 'POST')
end end

it "should publish new tweet if publishable" do it "should publish new tweet if publishable" do
mock_tweet = mock('tweet', :deletion? => false, :publishable? => true) mock_tweet = mock('tweet', :deletion? => false, :publishable? => true)
tweet_item = Weeter::TweetItem.stub!(:new).and_return mock_tweet tweet_item = Weeter::TweetItem.stub!(:new).and_return mock_tweet
@client_proxy.should_receive(:publish_tweet).with(mock_tweet) @client_proxy.should_receive(:publish_tweet).with(mock_tweet)
end end

it "should not publish unpublishable tweets" do it "should not publish unpublishable tweets" do
mock_tweet = mock('tweet', :deletion? => false, :publishable? => false, :[] => '') mock_tweet = mock('tweet', :deletion? => false, :publishable? => false, :[] => '')
tweet_item = Weeter::TweetItem.stub!(:new).and_return mock_tweet tweet_item = Weeter::TweetItem.stub!(:new).and_return mock_tweet
@client_proxy.should_not_receive(:publish_tweet).with(mock_tweet) @client_proxy.should_not_receive(:publish_tweet).with(mock_tweet)
end end

it "should delete deletion tweets" do it "should delete deletion tweets" do
mock_tweet = mock('tweet', :deletion? => true, :publishable? => false) mock_tweet = mock('tweet', :deletion? => true, :publishable? => false)
tweet_item = Weeter::TweetItem.stub!(:new).and_return mock_tweet tweet_item = Weeter::TweetItem.stub!(:new).and_return mock_tweet
@client_proxy.should_receive(:delete_tweet).with(mock_tweet) @client_proxy.should_receive(:delete_tweet).with(mock_tweet)
end end
end end


end end

0 comments on commit cdc3a90

Please sign in to comment.