test/api_test.rb in helmet-0.2.0 vs test/api_test.rb in helmet-0.2.1

- old
+ new

@@ -1,20 +1,25 @@ require File.join(File.dirname(__FILE__), 'test_helper') require 'uri' +require 'rack/mime' class Simple < Helmet::API use Rack::Session::Cookie, :secret => 'remove_security_warning' - before '/xx' do + before '/filtered' do halt 'filtered!' end get '/' do 'get' end + + get '/filtered' do + 'should not be here!' + end post '/' do 'post' end @@ -31,10 +36,15 @@ end get '/redirect' do redirect '/redirected' end + + get '/ct' do + ct = params['ct'].to_sym + content_type ct + end end class APITest < Test::Unit::TestCase include Goliath::TestHelper @@ -75,11 +85,11 @@ end end def test_filter with_api(Simple) do - get_request({:path => '/xx'}, @err) do |c| + get_request({:path => '/filtered'}, @err) do |c| assert_equal 'filtered!', c.response end end end @@ -90,9 +100,33 @@ uri = URI.parse(c.response_header['LOCATION']) assert_equal '/redirected', uri.path end end end + + def test_content_type_json + with_api(Simple) do + get_request({:path => '/ct', :query => {ct: 'json'}}, @err) do |c| + assert_equal c.response_header['Content-Type'], Rack::Mime.mime_type('.json') + end + end + end + + def test_content_type_js + with_api(Simple) do + get_request({:path => '/ct', :query => {ct: 'js'}}, @err) do |c| + assert_equal c.response_header['Content-Type'], Rack::Mime.mime_type('.js') + end + end + end + + def test_content_type_html + with_api(Simple) do + get_request({:path => '/ct', :query => {ct: 'html'}}, @err) do |c| + assert_equal c.response_header['Content-Type'], Rack::Mime.mime_type('.html') + end + end + end # def test_raise # with_api(Simple) do # get_request({:path => '/raise'}, @err) do |c| # assert_equal 'get', c.response