Sha256: e1117df17a1261c354017f611538f8f2693f5d30fec8d46eb0f354f8ea449db3

Contents?: true

Size: 853 Bytes

Versions: 7

Compression:

Stored size: 853 Bytes

Contents

require 'minitest_helper'

describe Rasti::Web::Request do
  
  it 'Route params' do
    env = Rack::MockRequest.env_for '/'
    env[Rasti::Web::ROUTE_PARAMS] = {'x' => 1, 'y' => 2}

    request = Rasti::Web::Request.new env

    request['x'].must_equal 1
    request['y'].must_equal 2
  end

  it 'Json body params' do
    env = Rack::MockRequest.env_for '/', input: '{"lat": 10, "lon": 20}', 'CONTENT_TYPE' => 'application/json'

    request = Rasti::Web::Request.new env

    request.must_be :json?
    request['lat'].must_equal 10
    request['lon'].must_equal 20
  end

  it 'No json body params' do
    env = Rack::MockRequest.env_for '/', input: '{"lat": 10, "lon": 20}', 'CONTENT_TYPE' => 'other/type'

    request = Rasti::Web::Request.new env

    request.wont_be :json?
    request['lat'].must_be_nil
    request['lon'].must_be_nil
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rasti-web-0.0.7 spec/request_spec.rb
rasti-web-0.0.6 spec/request_spec.rb
rasti-web-0.0.5 spec/request_spec.rb
rasti-web-0.0.4 spec/request_spec.rb
rasti-web-0.0.3 spec/request_spec.rb
rasti-web-0.0.2 spec/request_spec.rb
rasti-web-0.0.1 spec/request_spec.rb