test/request_test.rb in sinatra-1.4.0.d vs test/request_test.rb in sinatra-1.4.0
- old
+ new
@@ -36,19 +36,31 @@
request = Sinatra::Request.new(
'REQUEST_METHOD' => 'PUT',
'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
'rack.input' => StringIO.new('foo=bar')
)
- params = Sinatra::Base.new!.send(:indifferent_hash).replace(request.params)
+ Sinatra::Base.new!.send(:indifferent_hash).replace(request.params)
dumped = Marshal.dump(request.params)
assert_equal 'bar', Marshal.load(dumped)['foo']
end
it "exposes the preferred type's parameters" do
request = Sinatra::Request.new(
'HTTP_ACCEPT' => 'image/jpeg; compress=0.25'
)
assert_equal({ 'compress' => '0.25' }, request.preferred_type.params)
+ end
+
+ it "makes accept types behave like strings" do
+ request = Sinatra::Request.new('HTTP_ACCEPT' => 'image/jpeg; compress=0.25')
+ assert_equal 'image/jpeg', request.preferred_type.to_s
+ assert_equal 'image/jpeg', request.preferred_type.to_str
+ assert_equal 'image', request.preferred_type.split('/').first
+
+ String.instance_methods.each do |method|
+ next unless "".respond_to? method
+ assert request.preferred_type.respond_to?(method), "responds to #{method}"
+ end
end
it "properly decodes MIME type parameters" do
request = Sinatra::Request.new(
'HTTP_ACCEPT' => 'image/jpeg;unquoted=0.25;quoted="0.25";chartest="\";,\x"'