spec/request_spec.rb in rasti-web-0.0.7 vs spec/request_spec.rb in rasti-web-0.1.0
- old
+ new
@@ -1,35 +1,53 @@
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}
+ env = Rack::MockRequest.env_for '/10/20'
+ env[Rasti::Web::ROUTE_PARAMS] = {'lat' => '10', 'lon' => '20'}
request = Rasti::Web::Request.new env
- request['x'].must_equal 1
- request['y'].must_equal 2
+ request.params[:lat].must_equal '10'
+ request.params['lon'].must_equal '20'
end
+ it 'Query string params' do
+ env = Rack::MockRequest.env_for '/?lat=10&lon=20'
+
+ request = Rasti::Web::Request.new env
+
+ request.params[:lat].must_equal '10'
+ request.params['lon'].must_equal '20'
+ end
+
+ it 'Form params' do
+ env = Rack::MockRequest.env_for '/', method: 'POST', params: 'lat=10&lon=20'
+
+ request = Rasti::Web::Request.new env
+
+ request.params[:lat].must_equal '10'
+ request.params['lon'].must_equal '20'
+ 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
+ request.params[:lat].must_equal 10
+ request.params['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
+ request.params[:lat].must_be_nil
+ request.params['lon'].must_be_nil
end
end
\ No newline at end of file