Sha256: d04f33d4ae1db5f9c9a92b55d12e19945a2ad43436b69bde7d68e7ed9c516aaa

Contents?: true

Size: 1.48 KB

Versions: 7

Compression:

Stored size: 1.48 KB

Contents

#
# testing rufus-jig
#
# Sat Oct 31 23:27:02 JST 2009
#

require File.join(File.dirname(__FILE__), 'base')


class UtHttpPostTest < Test::Unit::TestCase

  def setup
    @h = Rufus::Jig::Http.new('127.0.0.1', 4567)
    @h.delete('/documents')
  end
  def teardown
    @h.close
  end

  def test_post

    b = @h.post(
      '/documents', '{"msg":"hello"}', :content_type => 'application/json')

    r = @h.last_response

    l = r.headers['Location']

    assert_equal 'created.', b
    assert_equal 201, r.status
    assert_not_nil l

    if l.match(/^http:\/\//)
      l = '/' + l.split('/')[3..-1].join('/')
    end

    assert_equal({ 'msg' => 'hello' }, @h.get(l))
  end

  def test_post_and_decode_body

    b = @h.post(
      '/documents?mirror=true', '{"msg":"hello world"}', :content_type => :json)

    assert_equal({ 'msg' => 'hello world' }, b)

    assert_equal 0, @h.cache.size
  end

  def test_post_and_cache

    b = @h.post(
      '/documents?etag=true', '{"msg":"hello world"}', :content_type => :json)

    assert_equal({ 'msg' => 'hello world' }, b)

    assert_equal 0, @h.cache.size
  end

  def test_post_long_stuff

    data = 'x' * 1000

    b = @h.post('/documents', data, :content_type => 'text/plain')

    r = @h.last_response

    assert_equal 201, r.status
  end

  def test_post_image

    data = File.read(File.join(File.dirname(__FILE__), 'tweet.png'))

    b = @h.post('/documents', data, :content_type => 'image/png')

    assert_equal 201, @h.last_response.status
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rufus-jig-0.1.23 test/ut_1_http_post.rb
rufus-jig-0.1.22 test/ut_1_http_post.rb
rufus-jig-0.1.21 test/ut_1_http_post.rb
rufus-jig-0.1.20 test/ut_1_http_post.rb
rufus-jig-0.1.19 test/ut_1_http_post.rb
rufus-jig-0.1.18 test/ut_1_http_post.rb
rufus-jig-0.1.17 test/ut_1_http_post.rb