require File.dirname(__FILE__) + '/../test_helper' class RequestTest < Test::Unit::TestCase # context "new get request" do # setup do # @client = mock('mambanation client') # @request = MambaNation::Request.new(@client, :get, '/1/statuses/user_timeline.json', {:query => {:since_id => 1234}}) # end # # context "performing request for collection" do # setup do # response = mock('response') do # stubs(:body).returns(fixture_file('user_timeline.json')) # stubs(:code).returns('200') # end # # @client.expects(:get).returns(response) # @object = @request.perform # end # # should "return array of mashes" do # @object.size.should == 20 # @object.each { |obj| obj.class.should be(Hashie::Mash) } # @object.first.text.should == 'Colder out today than expected. Headed to the Beanery for some morning wakeup drink. Latte or coffee...hmmm...' # end # end # # context "performing a request for a single object" do # setup do # response = mock('response') do # stubs(:body).returns(fixture_file('status.json')) # stubs(:code).returns('200') # end # # @client.expects(:get).returns(response) # @object = @request.perform # end # # should "return a single mash" do # @object.class.should be(Hashie::Mash) # @object.text.should == 'Rob Dyrdek is the funniest man alive. That is all.' # end # end # # context "with no query string" do # should "not have any query string" do # request = MambaNation::Request.new(@client, :get, '/users/4.json') # request.uri.should == '/users/4.json' # end # end # # context "with blank query string" do # should "not have any query string" do # request = MambaNation::Request.new(@client, :get, '/users/4.json', :query => {}) # request.uri.should == '/users/4.json' # end # end # # should "have get shortcut to initialize and perform all in one" do # MambaNation::Request.any_instance.expects(:perform).returns(nil) # MambaNation::Request.get(@client, '/foo') # end # # should "allow setting query string and headers" do # response = mock('response') do # stubs(:body).returns('') # stubs(:code).returns('200') # end # # @client.expects(:get).with('/1/statuses/friends_timeline.json?since_id=1234', {'Foo' => 'Bar'}).returns(response) # MambaNation::Request.get(@client, '/1/statuses/friends_timeline.json?since_id=1234', :headers => {'Foo' => 'Bar'}) # end # end # # context "new post request" do # setup do # @client = mock('mambanation client') # @request = MambaNation::Request.new(@client, :post, '/1/statuses/update.json', {:body => {:status => 'Woohoo!'}}) # end # # should "allow setting body and headers" do # response = mock('response') do # stubs(:body).returns('') # stubs(:code).returns('200') # end # # @client.expects(:post).with('/1/statuses/update.json', {:status => 'Woohoo!'}, {'Foo' => 'Bar'}).returns(response) # MambaNation::Request.post(@client, '/1/statuses/update.json', :body => {:status => 'Woohoo!'}, :headers => {'Foo' => 'Bar'}) # end # # context "performing request" do # setup do # response = mock('response') do # stubs(:body).returns(fixture_file('status.json')) # stubs(:code).returns('200') # end # # @client.expects(:post).returns(response) # @object = @request.perform # end # # should "return a mash of the object" do # @object.text.should == 'Rob Dyrdek is the funniest man alive. That is all.' # end # end # # should "have post shortcut to initialize and perform all in one" do # MambaNation::Request.any_instance.expects(:perform).returns(nil) # MambaNation::Request.post(@client, '/foo') # end # end end