Sha256: 8937b6d7b9627c8aafecaaa0f80f295e22bfbd5f91950020b3ac3ab69c9487cc

Contents?: true

Size: 1.94 KB

Versions: 1

Compression:

Stored size: 1.94 KB

Contents

require_relative 'helper'

class AutoJsonTest < ApiTest
  class App < Jersey::API::Base
    post '/test-params' do
      "#{params['one']}:#{params['two']}"
    end

    post '/test-json' do
      "#{request.json['one']}:#{request.json['two']}"
    end

    post "/test-array" do
      request.json.join(":")
    end

    post "/test-array-params" do
      params[0]
    end

    post "/test-auto-parse-fail" do
      request.body.read
    end
  end

  def test_form_encoded
    post('/test-params', one: "bar")
    assert_equal(200, last_response.status)
    assert_equal("bar:", last_response.body)
  end

  def test_json
    post('/test-params', {one: "bar"}.to_json)
    assert_equal(200, last_response.status)
    assert_equal("bar:", last_response.body)
  end

  def test_precedence
    post('/test-params?one=foo', one: "bar")
    assert_equal(200, last_response.status)
    assert_equal("bar:", last_response.body)
  end

  def test_body_with_json
    post('/test-params?two=foo', {one: "bar"}.to_json)
    assert_equal(200, last_response.status)
    assert_equal("bar:foo", last_response.body)
  end

  def test_query_string
    post('/test-params?one=bar')
    assert_equal(200, last_response.status)
    assert_equal("bar:", last_response.body)
  end

  def test_an_array
    post('/test-array', ['foo', 'bar'].to_json)
    assert_equal(200, last_response.status)
    assert_equal("foo:bar", last_response.body)
  end

  def test_an_array_from_params
    post('/test-array-params', ['foo', 'bar'].to_json)
    assert_equal(200, last_response.status)
    assert_equal("foo", last_response.body)
  end

  def test_passes_through_auto_parse_fails
    post('/test-auto-parse-fail', "{ HAHA")
    assert_equal(200, last_response.status)
    assert_equal("{ HAHA", last_response.body)
  end

  def test_query_string_and_body
    post('/test-params?one=bar', {two: "foo"}.to_json)
    assert_equal(200, last_response.status)
    assert_equal("bar:foo", last_response.body)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jersey-0.2.0 test/auto_json_test.rb