Skip to content
Browse files

Fixed that search was ignoring many options when making request. Stup…

…id mistake. Changed the tests to test stuff farther down the chain so this doesn't happen again.
  • Loading branch information...
1 parent 2da4913 commit 096d56ed9a62a0ea53bfe3a8df588ddef71df1c9 @jnunemaker jnunemaker committed Apr 8, 2009
Showing with 24 additions and 7 deletions.
  1. +6 −1 examples/search.rb
  2. +3 −1 lib/twitter/search.rb
  3. +15 −5 test/twitter/search_test.rb
View
7 examples/search.rb
@@ -7,4 +7,9 @@
search.each { |result| pp result }
puts '*'*50, 'Second Run', '*'*50
-search.each { |result| pp result }
+search.each { |result| pp result }
+
+puts '*'*50, 'Parameter Check', '*'*50
+pp Twitter::Search.new('#austineats').fetch().results.first
+pp Twitter::Search.new('#austineats').page(2).fetch().results.first
+pp Twitter::Search.new('#austineats').since(1412737343).fetch().results.first
View
4 lib/twitter/search.rb
@@ -85,7 +85,9 @@ def clear
def fetch(force=false)
if @fetch.nil? || force
- response = self.class.get('http://search.twitter.com/search.json', :query => {:q => @query[:q].dup.join(' ')}, :format => :json)
+ query = @query.dup
+ query[:q] = query[:q].join(' ')
+ response = self.class.get('http://search.twitter.com/search.json', :query => query, :format => :json)
@fetch = Mash.new(response)
end
View
20 test/twitter/search_test.rb
@@ -43,23 +43,33 @@ class SearchTest < Test::Unit::TestCase
end
should "should be able to specify the language" do
- @search.lang('en').query[:lang].should == 'en'
+ @search.lang('en')
+ @search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:lang => 'en', :q => ''}, :format => :json).returns({'foo' => 'bar'})
+ @search.fetch()
end
should "should be able to specify the number of results per page" do
- @search.per_page(25).query[:rpp].should == 25
+ @search.per_page(25)
+ @search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:rpp => 25, :q => ''}, :format => :json).returns({'foo' => 'bar'})
+ @search.fetch()
end
should "should be able to specify the page number" do
- @search.page(20).query[:page].should == 20
+ @search.page(20)
+ @search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:page => 20, :q => ''}, :format => :json).returns({'foo' => 'bar'})
+ @search.fetch()
end
should "should be able to specify only returning results greater than an id" do
- @search.since(1234).query[:since_id].should == 1234
+ @search.since(1234)
+ @search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:since_id => 1234, :q => ''}, :format => :json).returns({'foo' => 'bar'})
+ @search.fetch()
end
should "should be able to specify geo coordinates" do
- @search.geocode('40.757929', '-73.985506', '25mi').query[:geocode].should == '40.757929,-73.985506,25mi'
+ @search.geocode('40.757929', '-73.985506', '25mi')
+ @search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:geocode => '40.757929,-73.985506,25mi', :q => ''}, :format => :json).returns({'foo' => 'bar'})
+ @search.fetch()
end
should "should be able to clear the filters set" do

2 comments on commit 096d56e

@larrywright

Have you tested the pagination of search results much? Unless I’m missing something, the twitter search functionality you have ignores the data that comes back from Twitter about the next_page and since_id you need to request next.

@jnunemaker
Collaborator

I don’t assume how you are going to use the pagination information. I return it and you can use that for another search but I haven’t taken the time to actually implement next page and such. Doesn’t seem like it would be super hard.

Please sign in to comment.
Something went wrong with that request. Please try again.