From 2e05847cf70692b760c45dd54b6bad820176c9bd Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Thu, 23 Sep 2010 17:10:12 -0700 Subject: [PATCH] Add test to ensure fetch doesn't overwrite @query[:q] (@pjdavis) --- test/fixtures/search_milk_cheeze.json | 1 + test/twitter/search_test.rb | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/search_milk_cheeze.json diff --git a/test/fixtures/search_milk_cheeze.json b/test/fixtures/search_milk_cheeze.json new file mode 100644 index 000000000..6d2badba4 --- /dev/null +++ b/test/fixtures/search_milk_cheeze.json @@ -0,0 +1 @@ +{"results":[{"profile_image_url":"http://a1.twimg.com/profile_images/1112199761/fromfbmeeee_normal.jpg","created_at":"Wed, 22 Sep 2010 20:51:02 +0000","from_user":"Daniel_Duane","metadata":{"result_type":"recent"},"to_user_id":null,"text":"i have an addiction. milk & cheeze-its. they go great together. at first i thought it happened by accident. wrong, it was destiny.","id":25244302463,"from_user_id":10268592,"geo":null,"iso_language_code":"en","source":"<a href="http://twitter.com/">web</a>"},{"profile_image_url":"http://a2.twimg.com/profile_images/1123057706/IMG00303-20100913-2303_normal.jpg","created_at":"Wed, 22 Sep 2010 01:58:15 +0000","from_user":"melissacheong","metadata":{"result_type":"recent"},"to_user_id":null,"text":"Gonna get me some ham n cheeze croissant, and fresh milk. Perfect!","id":25173325934,"from_user_id":15807145,"geo":null,"iso_language_code":"en","source":"<a href="http://blackberry.com/twitter" rel="nofollow">Twitter for BlackBerry\u00ae</a>"},{"profile_image_url":"http://a0.twimg.com/profile_images/228430036/l_54e9479b67ec4e7eb004eca3c8fb1f0a_normal.jpg","created_at":"Tue, 21 Sep 2010 04:19:45 +0000","from_user":"5keaton5","metadata":{"result_type":"recent"},"to_user_id":null,"text":"Chocolate Milk, and Cheeze-Its :) haha so good!","id":25089376852,"from_user_id":18554394,"geo":null,"iso_language_code":"en","source":"<a href="/devices" rel="nofollow">txt</a>"}],"max_id":25350311391,"since_id":0,"refresh_url":"?since_id=25350311391&q=milk+cheeze","total":3,"results_per_page":15,"page":1,"completed_in":0.307357,"query":"milk+cheeze"} \ No newline at end of file diff --git a/test/twitter/search_test.rb b/test/twitter/search_test.rb index 865a45bf3..b7ed798b7 100644 --- a/test/twitter/search_test.rb +++ b/test/twitter/search_test.rb @@ -58,7 +58,7 @@ class SearchTest < Test::Unit::TestCase end should "should be able to specify not containing" do - @search.containing('milk',true).query[:q].should include('-milk') + @search.containing('milk', true).query[:q].should include('-milk') end should "should alias contains to containing" do @@ -155,6 +155,14 @@ class SearchTest < Test::Unit::TestCase @search.query[:geocode].should == '40.757929,-73.985506,25mi' end + should "should not replace the current query when fetching" do + stub_get('http://search.twitter.com/search.json?q=milk%20cheeze', 'search_milk_cheeze.json') + @search.containing('milk').containing('cheeze') + @search.query[:q].should == ['milk', 'cheeze'] + @search.fetch + @search.query[:q].should == ['milk', 'cheeze'] + end + context "fetching" do setup do stub_get('http://search.twitter.com/search.json?q=%40jnunemaker', 'search.json') @@ -172,12 +180,12 @@ class SearchTest < Test::Unit::TestCase first.from_user.should == 'PatParslow' end - should "cache fetched results so multiple fetches don't keep hitting api" do + should "cache fetched results so multiple fetches don't keep hitting API" do Twitter::Search.expects(:get).never @search.fetch end - should "rehit api if fetch is called with true" do + should "rehit API if fetch is called with true" do Twitter::Search.expects(:get).once @search.fetch(true) end