From 9adcf951ea7e5342c913dda40594cbb382995e3b Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 8 Dec 2008 19:19:48 -0800 Subject: Fix failing test introduced by optional-format routes --- actionpack/test/controller/caching_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index 7e7f488df6..ddf140ac3a 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -48,6 +48,7 @@ class PageCachingTest < ActionController::TestCase ActionController::Routing::Routes.draw do |map| map.main '', :controller => 'posts' + map.formatted_posts 'posts.:format', :controller => 'posts' map.resources :posts map.connect ':controller/:action/:id' end -- cgit v1.2.3 From 69387ce0169b95d3a170cfb1c66a7570b1746e37 Mon Sep 17 00:00:00 2001 From: Christos Zisopoulos Date: Wed, 10 Dec 2008 18:38:28 -0600 Subject: Fix for Integration::Session follow_redirect! headers['location'] bug with Rack [#1555 state:resolved] Signed-off-by: Joshua Peek --- actionpack/test/controller/integration_test.rb | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 4735b2927b..6a793c8bb6 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -30,14 +30,6 @@ class SessionTest < Test::Unit::TestCase assert_raise(RuntimeError) { @session.follow_redirect! } end - def test_follow_redirect_calls_get_and_returns_status - @session.stubs(:redirect?).returns(true) - @session.stubs(:headers).returns({"location" => ["www.google.com"]}) - @session.stubs(:status).returns(200) - @session.expects(:get) - assert_equal 200, @session.follow_redirect! - end - def test_request_via_redirect_uses_given_method path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue"} @session.expects(:put).with(path, args, headers) @@ -323,6 +315,10 @@ class IntegrationProcessTest < ActionController::IntegrationTest assert_equal "You are being redirected.", response.body assert_kind_of HTML::Document, html_document assert_equal 1, request_count + + follow_redirect! + assert_response :success + assert_equal "/get", path end end -- cgit v1.2.3 From 49306ccacf01e36d444771d42321965616e226f0 Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 11 Dec 2008 11:06:35 -0600 Subject: Add :partial option to assert_template [#1550 state:resolved] Signed-off-by: Joshua Peek --- actionpack/test/controller/action_pack_assertions_test.rb | 6 +++--- actionpack/test/controller/render_test.rb | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index ea56048f37..87c12ee4ee 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -326,11 +326,11 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase # check if we were rendered by a file-based template? def test_rendered_action process :nothing - assert_nil @response.rendered_template + assert_nil @response.rendered[:template] process :hello_world - assert @response.rendered_template - assert 'hello_world', @response.rendered_template.to_s + assert @response.rendered[:template] + assert 'hello_world', @response.rendered[:template].to_s end # check the redirection location diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index c5496a9af5..87733c2d33 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -1310,21 +1310,28 @@ class RenderTest < ActionController::TestCase def test_partial_collection_with_spacer get :partial_collection_with_spacer assert_equal "Hello: davidonly partialHello: mary", @response.body + assert_template :partial => 'test/_partial_only' + assert_template :partial => '_customer' end def test_partial_collection_shorthand_with_locals get :partial_collection_shorthand_with_locals assert_equal "Bonjour: davidBonjour: mary", @response.body + assert_template :partial => 'customers/_customer', :count => 2 + assert_template :partial => '_completely_fake_and_made_up_template_that_cannot_possibly_be_rendered', :count => 0 end def test_partial_collection_shorthand_with_different_types_of_records get :partial_collection_shorthand_with_different_types_of_records assert_equal "Bonjour bad customer: mark0Bonjour good customer: craig1Bonjour bad customer: john2Bonjour good customer: zach3Bonjour good customer: brandon4Bonjour bad customer: dan5", @response.body + assert_template :partial => 'good_customers/_good_customer', :count => 3 + assert_template :partial => 'bad_customers/_bad_customer', :count => 3 end def test_empty_partial_collection get :empty_partial_collection assert_equal " ", @response.body + assert_template :partial => false end def test_partial_with_hash_object -- cgit v1.2.3 From f36dafa492e3de66e624d81d6860f5f0536de6b0 Mon Sep 17 00:00:00 2001 From: Seth Fitzsimmons Date: Mon, 15 Dec 2008 12:00:55 -0600 Subject: Implement Mime::Type.=~ to match all synonyms against arg [#1573 state:resolved] Signed-off-by: Joshua Peek --- actionpack/test/controller/mime_type_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/mime_type_test.rb b/actionpack/test/controller/mime_type_test.rb index 21ae0419f1..9c4416ecf0 100644 --- a/actionpack/test/controller/mime_type_test.rb +++ b/actionpack/test/controller/mime_type_test.rb @@ -81,4 +81,12 @@ class MimeTypeTest < Test::Unit::TestCase assert verified.each { |type| assert Mime.const_get(type.to_s.upcase).verify_request?, "Verifiable Mime Type is not verified: #{type.inspect}" } assert unverified.each { |type| assert !Mime.const_get(type.to_s.upcase).verify_request?, "Nonverifiable Mime Type is verified: #{type.inspect}" } end + + def test_regexp_matcher + assert Mime::JS =~ "text/javascript" + assert Mime::JS =~ "application/javascript" + assert Mime::JS !~ "text/html" + assert !(Mime::JS !~ "text/javascript") + assert !(Mime::JS !~ "application/javascript") + end end -- cgit v1.2.3 From ed708307137c811d14e5fd2cb4ea550add381a82 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 15 Dec 2008 16:33:31 -0600 Subject: Switch to Rack based session stores. --- actionpack/test/controller/integration_test.rb | 2 - .../test/controller/integration_upload_test.rb | 2 - actionpack/test/controller/rack_test.rb | 26 +- .../test/controller/session/cookie_store_test.rb | 348 ++++++--------------- .../controller/session/mem_cache_store_test.rb | 207 ++++-------- .../test/controller/session_fixation_test.rb | 168 +++++----- .../test/controller/session_management_test.rb | 178 ----------- actionpack/test/controller/webservice_test.rb | 2 - 8 files changed, 239 insertions(+), 694 deletions(-) delete mode 100644 actionpack/test/controller/session_management_test.rb (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 6a793c8bb6..fd985a9a46 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -231,8 +231,6 @@ end class IntegrationProcessTest < ActionController::IntegrationTest class IntegrationController < ActionController::Base - session :off - def get respond_to do |format| format.html { render :text => "OK", :status => 200 } diff --git a/actionpack/test/controller/integration_upload_test.rb b/actionpack/test/controller/integration_upload_test.rb index b1dd6a6341..39d2e164e4 100644 --- a/actionpack/test/controller/integration_upload_test.rb +++ b/actionpack/test/controller/integration_upload_test.rb @@ -6,8 +6,6 @@ unless defined? ApplicationController end class UploadTestController < ActionController::Base - session :off - def update SessionUploadTest.last_request_type = ActionController::Base.param_parsers[request.content_type] render :text => "got here" diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb index 641ef9626e..e2ec686c41 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/controller/rack_test.rb @@ -229,7 +229,7 @@ end class RackResponseTest < BaseRackTest def setup super - @response = ActionController::RackResponse.new(@request) + @response = ActionController::RackResponse.new end def test_simple_output @@ -265,34 +265,12 @@ class RackResponseTest < BaseRackTest body.each { |part| parts << part } assert_equal ["0", "1", "2", "3", "4"], parts end - - def test_set_session_cookie - cookie = CGI::Cookie.new({"name" => "name", "value" => "Josh"}) - @request.cgi.send :instance_variable_set, '@output_cookies', [cookie] - - @response.body = "Hello, World!" - @response.prepare! - - status, headers, body = @response.out - assert_equal "200 OK", status - assert_equal({ - "Content-Type" => "text/html; charset=utf-8", - "Cache-Control" => "private, max-age=0, must-revalidate", - "ETag" => '"65a8e27d8879283831b664bd8b7f0ad4"', - "Set-Cookie" => ["name=Josh; path="], - "Content-Length" => "13" - }, headers) - - parts = [] - body.each { |part| parts << part } - assert_equal ["Hello, World!"], parts - end end class RackResponseHeadersTest < BaseRackTest def setup super - @response = ActionController::RackResponse.new(@request) + @response = ActionController::RackResponse.new @response.headers['Status'] = "200 OK" end diff --git a/actionpack/test/controller/session/cookie_store_test.rb b/actionpack/test/controller/session/cookie_store_test.rb index b5f14acc1f..8098059d46 100644 --- a/actionpack/test/controller/session/cookie_store_test.rb +++ b/actionpack/test/controller/session/cookie_store_test.rb @@ -1,298 +1,146 @@ require 'abstract_unit' require 'stringio' +class CookieStoreTest < ActionController::IntegrationTest + SessionKey = '_myapp_session' + SessionSecret = 'b3c631c314c0bbca50c1b2843150fe33' -class CGI::Session::CookieStore - def ensure_secret_secure_with_test_hax(secret) - if secret == CookieStoreTest.default_session_options['secret'] - return true - else - ensure_secret_secure_without_test_hax(secret) - end - end - alias_method_chain :ensure_secret_secure, :test_hax -end + DispatcherApp = ActionController::Dispatcher.new + CookieStoreApp = ActionController::Session::CookieStore.new(DispatcherApp, + :key => SessionKey, :secret => SessionSecret) + SignedBar = "BAh7BjoIZm9vIghiYXI%3D--" + + "fef868465920f415f2c0652d6910d3af288a0367" -# Expose for tests. -class CGI - attr_reader :output_cookies, :output_hidden - - class Session - attr_reader :dbman + class TestController < ActionController::Base + def no_session_access + head :ok + end - class CookieStore - attr_reader :data, :original, :cookie_options + def set_session_value + session[:foo] = "bar" + head :ok end - end -end -class CookieStoreTest < Test::Unit::TestCase - def self.default_session_options - { 'database_manager' => CGI::Session::CookieStore, - 'session_key' => '_myapp_session', - 'secret' => 'Keep it secret; keep it safe.', - 'no_cookies' => true, - 'no_hidden' => true, - 'session_http_only' => true - } - end + def get_session_value + render :text => "foo: #{session[:foo].inspect}" + end - def self.cookies - { :empty => ['BAgw--0686dcaccc01040f4bd4f35fe160afe9bc04c330', {}], - :a_one => ['BAh7BiIGYWkG--5689059497d7f122a7119f171aef81dcfd807fec', { 'a' => 1 }], - :typical => ['BAh7ByIMdXNlcl9pZGkBeyIKZmxhc2h7BiILbm90aWNlIgxIZXkgbm93--9d20154623b9eeea05c62ab819be0e2483238759', { 'user_id' => 123, 'flash' => { 'notice' => 'Hey now' }}], - :flashed => ['BAh7ByIMdXNlcl9pZGkBeyIKZmxhc2h7AA==--bf9785a666d3c4ac09f7fe3353496b437546cfbf', { 'user_id' => 123, 'flash' => {} }] - } + def raise_data_overflow + session[:foo] = 'bye!' * 1024 + head :ok + end + def rescue_action(e) raise end end def setup - ENV.delete('HTTP_COOKIE') + @integration_session = open_session(CookieStoreApp) end def test_raises_argument_error_if_missing_session_key - [nil, ''].each do |blank| - assert_raise(ArgumentError, blank.inspect) { new_session 'session_key' => blank } - end + assert_raise(ArgumentError, nil.inspect) { + ActionController::Session::CookieStore.new(nil, + :key => nil, :secret => SessionSecret) + } + + assert_raise(ArgumentError, ''.inspect) { + ActionController::Session::CookieStore.new(nil, + :key => '', :secret => SessionSecret) + } end def test_raises_argument_error_if_missing_secret - [nil, ''].each do |blank| - assert_raise(ArgumentError, blank.inspect) { new_session 'secret' => blank } - end - end + assert_raise(ArgumentError, nil.inspect) { + ActionController::Session::CookieStore.new(nil, + :key => SessionKey, :secret => nil) + } - def test_raises_argument_error_if_secret_is_probably_insecure - ["password", "secret", "12345678901234567890123456789"].each do |blank| - assert_raise(ArgumentError, blank.inspect) { new_session 'secret' => blank } - end + assert_raise(ArgumentError, ''.inspect) { + ActionController::Session::CookieStore.new(nil, + :key => SessionKey, :secret => '') + } end - def test_reconfigures_session_to_omit_id_cookie_and_hidden_field - new_session do |session| - assert_equal true, @options['no_hidden'] - assert_equal true, @options['no_cookies'] - end - end + def test_raises_argument_error_if_secret_is_probably_insecure + assert_raise(ArgumentError, "password".inspect) { + ActionController::Session::CookieStore.new(nil, + :key => SessionKey, :secret => "password") + } - def test_restore_unmarshals_missing_cookie_as_empty_hash - new_session do |session| - assert_nil session.dbman.data - assert_nil session['test'] - assert_equal Hash.new, session.dbman.data - end - end + assert_raise(ArgumentError, "secret".inspect) { + ActionController::Session::CookieStore.new(nil, + :key => SessionKey, :secret => "secret") + } - def test_restore_unmarshals_good_cookies - cookies(:empty, :a_one, :typical).each do |value, expected| - set_cookie! value - new_session do |session| - assert_nil session['lazy loads the data hash'] - assert_equal expected, session.dbman.data - end - end + assert_raise(ArgumentError, "12345678901234567890123456789".inspect) { + ActionController::Session::CookieStore.new(nil, + :key => SessionKey, :secret => "12345678901234567890123456789") + } end - def test_restore_deletes_tampered_cookies - set_cookie! 'a--b' - new_session do |session| - assert_raise(CGI::Session::CookieStore::TamperedWithCookie) { session['fail'] } - assert_cookie_deleted session - end + def test_setting_session_value + with_test_route_set do + get '/set_session_value' + assert_response :success + assert_equal ["_myapp_session=#{SignedBar}; path=/"], + headers['Set-Cookie'] + end end - def test_close_doesnt_write_cookie_if_data_is_blank - new_session do |session| - assert_no_cookies session - session.close - assert_no_cookies session - end + def test_getting_session_value + with_test_route_set do + cookies[SessionKey] = SignedBar + get '/get_session_value' + assert_response :success + assert_equal 'foo: "bar"', response.body + end end - def test_close_doesnt_write_cookie_if_data_is_unchanged - set_cookie! cookie_value(:typical) - new_session do |session| - assert_no_cookies session - session['user_id'] = session['user_id'] - session.close - assert_no_cookies session + def test_disregards_tampered_sessions + with_test_route_set do + cookies[SessionKey] = "BAh7BjoIZm9vIghiYXI%3D--123456780" + get '/get_session_value' + assert_response :success + assert_equal 'foo: nil', response.body end end def test_close_raises_when_data_overflows - set_cookie! cookie_value(:empty) - new_session do |session| - session['overflow'] = 'bye!' * 1024 - assert_raise(CGI::Session::CookieStore::CookieOverflow) { session.close } - assert_no_cookies session - end - end - - def test_close_marshals_and_writes_cookie - set_cookie! cookie_value(:typical) - new_session do |session| - assert_no_cookies session - session['flash'] = {} - assert_no_cookies session - session.close - assert_equal 1, session.cgi.output_cookies.size - cookie = session.cgi.output_cookies.first - assert_cookie cookie, cookie_value(:flashed) - assert_http_only_cookie cookie - assert_secure_cookie cookie, false - end - end - - def test_writes_non_secure_cookie_by_default - set_cookie! cookie_value(:typical) - new_session do |session| - session['flash'] = {} - session.close - cookie = session.cgi.output_cookies.first - assert_secure_cookie cookie,false - end - end - - def test_writes_secure_cookie - set_cookie! cookie_value(:typical) - new_session('session_secure'=>true) do |session| - session['flash'] = {} - session.close - cookie = session.cgi.output_cookies.first - assert_secure_cookie cookie + with_test_route_set do + assert_raise(ActionController::Session::CookieStore::CookieOverflow) { + get '/raise_data_overflow' + } end end - def test_http_only_cookie_by_default - set_cookie! cookie_value(:typical) - new_session do |session| - session['flash'] = {} - session.close - cookie = session.cgi.output_cookies.first - assert_http_only_cookie cookie + def test_doesnt_write_session_cookie_if_session_is_not_accessed + with_test_route_set do + get '/no_session_access' + assert_response :success + assert_equal [], headers['Set-Cookie'] end end - def test_overides_http_only_cookie - set_cookie! cookie_value(:typical) - new_session('session_http_only'=>false) do |session| - session['flash'] = {} - session.close - cookie = session.cgi.output_cookies.first - assert_http_only_cookie cookie, false - end - end - - def test_delete_writes_expired_empty_cookie_and_sets_data_to_nil - set_cookie! cookie_value(:typical) - new_session do |session| - assert_no_cookies session - session.delete - assert_cookie_deleted session - - # @data is set to nil so #close doesn't send another cookie. - session.close - assert_cookie_deleted session - end - end - - def test_new_session_doesnt_reuse_deleted_cookie_data - set_cookie! cookie_value(:typical) - - new_session do |session| - assert_not_nil session['user_id'] - session.delete - - # Start a new session using the same CGI instance. - post_delete_session = CGI::Session.new(session.cgi, self.class.default_session_options) - assert_nil post_delete_session['user_id'] + def test_doesnt_write_session_cookie_if_session_is_unchanged + with_test_route_set do + cookies[SessionKey] = "BAh7BjoIZm9vIghiYXI%3D--" + + "fef868465920f415f2c0652d6910d3af288a0367" + get '/no_session_access' + assert_response :success + assert_equal [], headers['Set-Cookie'] end end private - def assert_no_cookies(session) - assert_nil session.cgi.output_cookies, session.cgi.output_cookies.inspect - end - - def assert_cookie_deleted(session, message = 'Expected session deletion cookie to be set') - assert_equal 1, session.cgi.output_cookies.size - cookie = session.cgi.output_cookies.first - assert_cookie cookie, nil, 1.year.ago.to_date, "#{message}: #{cookie.name} => #{cookie.value}" - end - - def assert_cookie(cookie, value = nil, expires = nil, message = nil) - assert_equal '_myapp_session', cookie.name, message - assert_equal [value].compact, cookie.value, message - assert_equal expires, cookie.expires ? cookie.expires.to_date : cookie.expires, message - end - - def assert_secure_cookie(cookie,value=true) - assert cookie.secure==value - end - - def assert_http_only_cookie(cookie,value=true) - assert cookie.http_only==value - end - - def cookies(*which) - self.class.cookies.values_at(*which) - end - - def cookie_value(which) - self.class.cookies[which].first - end - - def set_cookie!(value) - ENV['HTTP_COOKIE'] = "_myapp_session=#{value}" - end - - def new_session(options = {}) - with_cgi do |cgi| - assert_nil cgi.output_hidden, "Output hidden params should be empty: #{cgi.output_hidden.inspect}" - assert_nil cgi.output_cookies, "Output cookies should be empty: #{cgi.output_cookies.inspect}" - - @options = self.class.default_session_options.merge(options) - session = CGI::Session.new(cgi, @options) - ObjectSpace.undefine_finalizer(session) - - assert_nil cgi.output_hidden, "Output hidden params should be empty: #{cgi.output_hidden.inspect}" - assert_nil cgi.output_cookies, "Output cookies should be empty: #{cgi.output_cookies.inspect}" - - yield session if block_given? - session + def with_test_route_set + with_routing do |set| + set.draw do |map| + map.with_options :controller => "cookie_store_test/test" do |c| + c.connect "/:action" + end + end + yield end end - - def with_cgi - ENV['REQUEST_METHOD'] = 'GET' - ENV['HTTP_HOST'] = 'example.com' - ENV['QUERY_STRING'] = '' - - cgi = CGI.new('query', StringIO.new('')) - yield cgi if block_given? - cgi - end -end - - -class CookieStoreWithBlockAsSecretTest < CookieStoreTest - def self.default_session_options - CookieStoreTest.default_session_options.merge 'secret' => Proc.new { 'Keep it secret; keep it safe.' } - end -end - - -class CookieStoreWithMD5DigestTest < CookieStoreTest - def self.default_session_options - CookieStoreTest.default_session_options.merge 'digest' => 'MD5' - end - - def self.cookies - { :empty => ['BAgw--0415cc0be9579b14afc22ee2d341aa21', {}], - :a_one => ['BAh7BiIGYWkG--5a0ed962089cc6600ff44168a5d59bc8', { 'a' => 1 }], - :typical => ['BAh7ByIMdXNlcl9pZGkBeyIKZmxhc2h7BiILbm90aWNlIgxIZXkgbm93--f426763f6ef435b3738b493600db8d64', { 'user_id' => 123, 'flash' => { 'notice' => 'Hey now' }}], - :flashed => ['BAh7ByIMdXNlcl9pZGkBeyIKZmxhc2h7AA==--0af9156650dab044a53a91a4ddec2c51', { 'user_id' => 123, 'flash' => {} }], - :double_escaped => [CGI.escape('BAh7ByIMdXNlcl9pZGkBeyIKZmxhc2h7AA%3D%3D--0af9156650dab044a53a91a4ddec2c51'), { 'user_id' => 123, 'flash' => {} }] } - end end diff --git a/actionpack/test/controller/session/mem_cache_store_test.rb b/actionpack/test/controller/session/mem_cache_store_test.rb index 9ab927a01f..52e31b78da 100644 --- a/actionpack/test/controller/session/mem_cache_store_test.rb +++ b/actionpack/test/controller/session/mem_cache_store_test.rb @@ -1,178 +1,81 @@ require 'abstract_unit' -class CGI::Session - def cache - dbman.instance_variable_get(:@cache) - end -end - - -uses_mocha 'MemCacheStore tests' do -if defined? MemCache::MemCacheError +# You need to start a memcached server inorder to run these tests +class MemCacheStoreTest < ActionController::IntegrationTest + class TestController < ActionController::Base + def no_session_access + head :ok + end -class MemCacheStoreTest < Test::Unit::TestCase - SESSION_KEY_RE = /^session:[0-9a-z]+/ - CONN_TEST_KEY = 'connection_test' - MULTI_TEST_KEY = '0123456789' - TEST_DATA = 'Hello test' + def set_session_value + session[:foo] = "bar" + head :ok + end - def self.get_mem_cache_if_available - begin - require 'memcache' - cache = MemCache.new('127.0.0.1') - # Test availability of the connection - cache.set(CONN_TEST_KEY, 1) - unless cache.get(CONN_TEST_KEY) == 1 - puts 'Warning: memcache server available but corrupted.' - return nil - end - rescue LoadError, MemCache::MemCacheError - return nil + def get_session_value + render :text => "foo: #{session[:foo].inspect}" end - return cache + + def rescue_action(e) raise end end - CACHE = get_mem_cache_if_available + begin + DispatcherApp = ActionController::Dispatcher.new + MemCacheStoreApp = ActionController::Session::MemCacheStore.new( + DispatcherApp, :key => '_session_id') - def test_initialization - assert_raise(ArgumentError) { new_session('session_id' => '!invalid_id') } - new_session do |s| - assert_equal Hash.new, s.cache.get('session:' + s.session_id) + def setup + @integration_session = open_session(MemCacheStoreApp) end - end + def test_setting_and_getting_session_value + with_test_route_set do + get '/set_session_value' + assert_response :success + assert cookies['_session_id'] - def test_storage - d = rand(0xffff) - new_session do |s| - session_key = 'session:' + s.session_id - unless CACHE - s.cache.expects(:get).with(session_key) \ - .returns(:test => d) - s.cache.expects(:set).with(session_key, - has_entry(:test, d), - 0) - end - s[:test] = d - s.close - assert_equal d, s.cache.get(session_key)[:test] - assert_equal d, s[:test] - end - end - - def test_deletion - new_session do |s| - session_key = 'session:' + s.session_id - unless CACHE - s.cache.expects(:delete) - s.cache.expects(:get).with(session_key) \ - .returns(nil) + get '/get_session_value' + assert_response :success + assert_equal 'foo: "bar"', response.body end - s[:test] = rand(0xffff) - s.delete - assert_nil s.cache.get(session_key) end - end - - def test_other_session_retrieval - new_session do |sa| - unless CACHE - sa.cache.expects(:set).with('session:' + sa.session_id, - has_entry(:test, TEST_DATA), - 0) - end - sa[:test] = TEST_DATA - sa.close - new_session('session_id' => sa.session_id) do |sb| - unless CACHE - sb.cache.expects(:[]).with('session:' + sb.session_id) \ - .returns(:test => TEST_DATA) - end - assert_equal(TEST_DATA, sb[:test]) + def test_getting_nil_session_value + with_test_route_set do + get '/get_session_value' + assert_response :success + assert_equal 'foo: nil', response.body end end - end + def test_prevents_session_fixation + with_test_route_set do + get '/get_session_value' + assert_response :success + assert_equal 'foo: nil', response.body + session_id = cookies['_session_id'] - def test_multiple_sessions - s_slots = Array.new(10) - operation = :write - last_data = nil - reads = writes = 0 - 50.times do - current = rand(10) - s_slots[current] ||= new_session('session_id' => MULTI_TEST_KEY, - 'new_session' => true) - s = s_slots[current] - case operation - when :write - last_data = rand(0xffff) - unless CACHE - s.cache.expects(:set).with('session:' + MULTI_TEST_KEY, - { :test => last_data }, - 0) - end - s[:test] = last_data - s.close - writes += 1 - when :read - # Make CGI::Session#[] think there was no data retrieval yet. - # Normally, the session caches the data during its lifetime. - s.instance_variable_set(:@data, nil) - unless CACHE - s.cache.expects(:[]).with('session:' + MULTI_TEST_KEY) \ - .returns(:test => last_data) - end - d = s[:test] - assert_equal(last_data, d, "OK reads: #{reads}, OK writes: #{writes}") - reads += 1 + reset! + + get '/set_session_value', :_session_id => session_id + assert_response :success + assert_equal nil, cookies['_session_id'] end - operation = rand(5) == 0 ? :write : :read end + rescue LoadError, RuntimeError + $stderr.puts "Skipping MemCacheStoreTest tests. Start memcached and try again." end - - private - def obtain_session_options - options = { 'database_manager' => CGI::Session::MemCacheStore, - 'session_key' => '_test_app_session' - } - # if don't have running memcache server we use mock instead - unless CACHE - options['cache'] = c = mock - c.stubs(:[]).with(regexp_matches(SESSION_KEY_RE)) - c.stubs(:get).with(regexp_matches(SESSION_KEY_RE)) \ - .returns(Hash.new) - c.stubs(:add).with(regexp_matches(SESSION_KEY_RE), - instance_of(Hash), - 0) - end - options - end - - - def new_session(options = {}) - with_cgi do |cgi| - @options = obtain_session_options.merge(options) - session = CGI::Session.new(cgi, @options) - yield session if block_given? - return session + def with_test_route_set + with_routing do |set| + set.draw do |map| + map.with_options :controller => "mem_cache_store_test/test" do |c| + c.connect "/:action" + end + end + yield + end end - end - - def with_cgi - ENV['REQUEST_METHOD'] = 'GET' - ENV['HTTP_HOST'] = 'example.com' - ENV['QUERY_STRING'] = '' - - cgi = CGI.new('query', StringIO.new('')) - yield cgi if block_given? - cgi - end end - -end # defined? MemCache -end # uses_mocha diff --git a/actionpack/test/controller/session_fixation_test.rb b/actionpack/test/controller/session_fixation_test.rb index e8dc8bd295..9e5b45dc3d 100644 --- a/actionpack/test/controller/session_fixation_test.rb +++ b/actionpack/test/controller/session_fixation_test.rb @@ -1,84 +1,84 @@ -require 'abstract_unit' - -class SessionFixationTest < ActionController::IntegrationTest - class TestController < ActionController::Base - session :session_key => '_myapp_session_id', - :secret => CGI::Session.generate_unique_id, - :except => :default_session_key - - session :cookie_only => false, - :only => :allow_session_fixation - - def default_session_key - render :text => "default_session_key" - end - - def custom_session_key - render :text => "custom_session_key: #{params[:id]}" - end - - def allow_session_fixation - render :text => "allow_session_fixation" - end - - def rescue_action(e) raise end - end - - def setup - @controller = TestController.new - end - - def test_should_be_able_to_make_a_successful_request - with_test_route_set do - assert_nothing_raised do - get '/custom_session_key', :id => "1" - end - assert_equal 'custom_session_key: 1', @controller.response.body - assert_not_nil @controller.session - end - end - - def test_should_catch_session_fixation_attempt - with_test_route_set do - assert_raises(ActionController::RackRequest::SessionFixationAttempt) do - get '/custom_session_key', :_myapp_session_id => "42" - end - assert_nil @controller.session - end - end - - def test_should_not_catch_session_fixation_attempt_when_cookie_only_setting_is_disabled - with_test_route_set do - assert_nothing_raised do - get '/allow_session_fixation', :_myapp_session_id => "42" - end - assert !@controller.response.body.blank? - assert_not_nil @controller.session - end - end - - def test_should_catch_session_fixation_attempt_with_default_session_key - # using the default session_key is not possible with cookie store - ActionController::Base.session_store = :p_store - - with_test_route_set do - assert_raises ActionController::RackRequest::SessionFixationAttempt do - get '/default_session_key', :_session_id => "42" - end - assert_nil @controller.response - assert_nil @controller.session - end - end - - private - def with_test_route_set - with_routing do |set| - set.draw do |map| - map.with_options :controller => "session_fixation_test/test" do |c| - c.connect "/:action" - end - end - yield - end - end -end +# require 'abstract_unit' +# +# class SessionFixationTest < ActionController::IntegrationTest +# class TestController < ActionController::Base +# session :session_key => '_myapp_session_id', +# :secret => CGI::Session.generate_unique_id, +# :except => :default_session_key +# +# session :cookie_only => false, +# :only => :allow_session_fixation +# +# def default_session_key +# render :text => "default_session_key" +# end +# +# def custom_session_key +# render :text => "custom_session_key: #{params[:id]}" +# end +# +# def allow_session_fixation +# render :text => "allow_session_fixation" +# end +# +# def rescue_action(e) raise end +# end +# +# def setup +# @controller = TestController.new +# end +# +# def test_should_be_able_to_make_a_successful_request +# with_test_route_set do +# assert_nothing_raised do +# get '/custom_session_key', :id => "1" +# end +# assert_equal 'custom_session_key: 1', @controller.response.body +# assert_not_nil @controller.session +# end +# end +# +# def test_should_catch_session_fixation_attempt +# with_test_route_set do +# assert_raises(ActionController::RackRequest::SessionFixationAttempt) do +# get '/custom_session_key', :_myapp_session_id => "42" +# end +# assert_nil @controller.session +# end +# end +# +# def test_should_not_catch_session_fixation_attempt_when_cookie_only_setting_is_disabled +# with_test_route_set do +# assert_nothing_raised do +# get '/allow_session_fixation', :_myapp_session_id => "42" +# end +# assert !@controller.response.body.blank? +# assert_not_nil @controller.session +# end +# end +# +# def test_should_catch_session_fixation_attempt_with_default_session_key +# # using the default session_key is not possible with cookie store +# ActionController::Base.session_store = :p_store +# +# with_test_route_set do +# assert_raises ActionController::RackRequest::SessionFixationAttempt do +# get '/default_session_key', :_session_id => "42" +# end +# assert_nil @controller.response +# assert_nil @controller.session +# end +# end +# +# private +# def with_test_route_set +# with_routing do |set| +# set.draw do |map| +# map.with_options :controller => "session_fixation_test/test" do |c| +# c.connect "/:action" +# end +# end +# yield +# end +# end +# end diff --git a/actionpack/test/controller/session_management_test.rb b/actionpack/test/controller/session_management_test.rb deleted file mode 100644 index 592b0b549d..0000000000 --- a/actionpack/test/controller/session_management_test.rb +++ /dev/null @@ -1,178 +0,0 @@ -require 'abstract_unit' - -class SessionManagementTest < Test::Unit::TestCase - class SessionOffController < ActionController::Base - session :off - - def show - render :text => "done" - end - - def tell - render :text => "done" - end - end - - class SessionOffOnController < ActionController::Base - session :off - session :on, :only => :tell - - def show - render :text => "done" - end - - def tell - render :text => "done" - end - end - - class TestController < ActionController::Base - session :off, :only => :show - session :session_secure => true, :except => :show - session :off, :only => :conditional, - :if => Proc.new { |r| r.parameters[:ws] } - - def show - render :text => "done" - end - - def tell - render :text => "done" - end - - def conditional - render :text => ">>>#{params[:ws]}<<<" - end - end - - class SpecializedController < SessionOffController - session :disabled => false, :only => :something - - def something - render :text => "done" - end - - def another - render :text => "done" - end - end - - class AssociationCachingTestController < ActionController::Base - class ObjectWithAssociationCache - def initialize - @cached_associations = false - end - - def fetch_associations - @cached_associations = true - end - - def clear_association_cache - @cached_associations = false - end - - def has_cached_associations? - @cached_associations - end - end - - def show - session[:object] = ObjectWithAssociationCache.new - session[:object].fetch_associations - if session[:object].has_cached_associations? - render :text => "has cached associations" - else - render :text => "does not have cached associations" - end - end - - def tell - if session[:object] - if session[:object].has_cached_associations? - render :text => "has cached associations" - else - render :text => "does not have cached associations" - end - else - render :text => "there is no object" - end - end - end - - - def setup - @request, @response = ActionController::TestRequest.new, - ActionController::TestResponse.new - end - - def test_session_off_globally - @controller = SessionOffController.new - get :show - assert_equal false, @request.session_options - get :tell - assert_equal false, @request.session_options - end - - def test_session_off_then_on_globally - @controller = SessionOffOnController.new - get :show - assert_equal false, @request.session_options - get :tell - assert_instance_of Hash, @request.session_options - assert_equal false, @request.session_options[:disabled] - end - - def test_session_off_conditionally - @controller = TestController.new - get :show - assert_equal false, @request.session_options - get :tell - assert_instance_of Hash, @request.session_options - assert @request.session_options[:session_secure] - end - - def test_controller_specialization_overrides_settings - @controller = SpecializedController.new - get :something - assert_instance_of Hash, @request.session_options - get :another - assert_equal false, @request.session_options - end - - def test_session_off_with_if - @controller = TestController.new - get :conditional - assert_instance_of Hash, @request.session_options - get :conditional, :ws => "ws" - assert_equal false, @request.session_options - end - - def test_session_store_setting - ActionController::Base.session_store = :drb_store - assert_equal CGI::Session::DRbStore, ActionController::Base.session_store - - if Object.const_defined?(:ActiveRecord) - ActionController::Base.session_store = :active_record_store - assert_equal CGI::Session::ActiveRecordStore, ActionController::Base.session_store - end - end - - def test_process_cleanup_with_session_management_support - @controller = AssociationCachingTestController.new - get :show - assert_equal "has cached associations", @response.body - get :tell - assert_equal "does not have cached associations", @response.body - end - - def test_session_is_enabled - @controller = TestController.new - get :show - assert_nothing_raised do - assert_equal false, @controller.session_enabled? - end - - get :tell - assert @controller.session_enabled? - end -end diff --git a/actionpack/test/controller/webservice_test.rb b/actionpack/test/controller/webservice_test.rb index 4c44ea4205..e89d6bb960 100644 --- a/actionpack/test/controller/webservice_test.rb +++ b/actionpack/test/controller/webservice_test.rb @@ -2,8 +2,6 @@ require 'abstract_unit' class WebServiceTest < ActionController::IntegrationTest class TestController < ActionController::Base - session :off - def assign_parameters if params[:full] render :text => dump_params_keys -- cgit v1.2.3 From 9e2b4a10f7f091868b3c3701efb4c04048455706 Mon Sep 17 00:00:00 2001 From: "Hongli Lai (Phusion" Date: Mon, 15 Dec 2008 21:36:33 +0100 Subject: Do not output an ETag header if response body is blank or when sending files with send_file(... :xsendfile => true) [#1578 state:committed] Signed-off-by: David Heinemeier Hansson --- actionpack/test/controller/render_test.rb | 9 +++++++++ actionpack/test/controller/send_file_test.rb | 1 + 2 files changed, 10 insertions(+) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 87733c2d33..a6721fd903 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -208,6 +208,10 @@ class TestController < ActionController::Base def greeting # let's just rely on the template end + + def blank_response + render :text => ' ' + end def layout_test render :action => "hello_world" @@ -1380,6 +1384,11 @@ class EtagRenderTest < ActionController::TestCase @request.host = "www.nextangle.com" @expected_bang_etag = etag_for(expand_key([:foo, 123])) end + + def test_render_blank_body_shouldnt_set_etag + get :blank_response + assert !@response.etag? + end def test_render_200_should_set_etag get :render_hello_world_from_variable diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb index c003abf094..ffbaa457f8 100644 --- a/actionpack/test/controller/send_file_test.rb +++ b/actionpack/test/controller/send_file_test.rb @@ -69,6 +69,7 @@ class SendFileTest < Test::Unit::TestCase assert_equal @controller.file_path, response.headers['X-Sendfile'] assert response.body.blank? + assert !response.etag? end def test_data -- cgit v1.2.3 From ec1bd987054479d279a181eec26827ec694a61cd Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 16 Dec 2008 16:28:39 -0600 Subject: Session Fixation tests have been rolled into the session cookie tests --- .../test/controller/session_fixation_test.rb | 84 ---------------------- 1 file changed, 84 deletions(-) delete mode 100644 actionpack/test/controller/session_fixation_test.rb (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/session_fixation_test.rb b/actionpack/test/controller/session_fixation_test.rb deleted file mode 100644 index 9e5b45dc3d..0000000000 --- a/actionpack/test/controller/session_fixation_test.rb +++ /dev/null @@ -1,84 +0,0 @@ -# require 'abstract_unit' -# -# class SessionFixationTest < ActionController::IntegrationTest -# class TestController < ActionController::Base -# session :session_key => '_myapp_session_id', -# :secret => CGI::Session.generate_unique_id, -# :except => :default_session_key -# -# session :cookie_only => false, -# :only => :allow_session_fixation -# -# def default_session_key -# render :text => "default_session_key" -# end -# -# def custom_session_key -# render :text => "custom_session_key: #{params[:id]}" -# end -# -# def allow_session_fixation -# render :text => "allow_session_fixation" -# end -# -# def rescue_action(e) raise end -# end -# -# def setup -# @controller = TestController.new -# end -# -# def test_should_be_able_to_make_a_successful_request -# with_test_route_set do -# assert_nothing_raised do -# get '/custom_session_key', :id => "1" -# end -# assert_equal 'custom_session_key: 1', @controller.response.body -# assert_not_nil @controller.session -# end -# end -# -# def test_should_catch_session_fixation_attempt -# with_test_route_set do -# assert_raises(ActionController::RackRequest::SessionFixationAttempt) do -# get '/custom_session_key', :_myapp_session_id => "42" -# end -# assert_nil @controller.session -# end -# end -# -# def test_should_not_catch_session_fixation_attempt_when_cookie_only_setting_is_disabled -# with_test_route_set do -# assert_nothing_raised do -# get '/allow_session_fixation', :_myapp_session_id => "42" -# end -# assert !@controller.response.body.blank? -# assert_not_nil @controller.session -# end -# end -# -# def test_should_catch_session_fixation_attempt_with_default_session_key -# # using the default session_key is not possible with cookie store -# ActionController::Base.session_store = :p_store -# -# with_test_route_set do -# assert_raises ActionController::RackRequest::SessionFixationAttempt do -# get '/default_session_key', :_session_id => "42" -# end -# assert_nil @controller.response -# assert_nil @controller.session -# end -# end -# -# private -# def with_test_route_set -# with_routing do |set| -# set.draw do |map| -# map.with_options :controller => "session_fixation_test/test" do |c| -# c.connect "/:action" -# end -# end -# yield -# end -# end -# end -- cgit v1.2.3 From 97a178bfa4d5101dca73ae931cc9c77385d8c97e Mon Sep 17 00:00:00 2001 From: Jesse Newland Date: Wed, 17 Dec 2008 09:21:20 -0500 Subject: Decorate responses from Rack Middleware and Rails Metal for the purposes of integration testing. A test for the following Metal: class Poller < Rails::Rack::Metal def call(env) if env["PATH_INFO"] =~ /^\/poller/ [200, {"Content-Type" => "text/plain"}, "Hello World!"] else super end end end might be tested like so: class PollerTest < ActionController::IntegrationTest test "poller returns hello world" do get "/poller" assert_response 200 assert_response :success assert_response :ok assert_equal "Hello World!", response.body end end [#1588 state:committed] Signed-off-by: David Heinemeier Hansson --- actionpack/test/controller/integration_test.rb | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index fd985a9a46..90afbfb9bc 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -373,4 +373,39 @@ class IntegrationProcessTest < ActionController::IntegrationTest end end +class MetalTest < ActionController::IntegrationTest + require(File.dirname(__FILE__) + "/../../../railties/lib/rails/rack/metal.rb") + + class Poller < ::Rails::Rack::Metal + def call(env) + if env["PATH_INFO"] =~ /^\/success/ + [200, {"Content-Type" => "text/plain"}, "Hello World!"] + elsif env["PATH_INFO"] =~ /^\/failure/ + [404, {"Content-Type" => "text/plain"}, ''] + else + super + end + end + end + + def setup + @integration_session = ActionController::Integration::Session.new(Poller) + end + + def test_successful_get + get "/success" + assert_response 200 + assert_response :success + assert_response :ok + assert_equal "Hello World!", response.body + end + + def test_failed_get + get "/failure" + assert_response 404 + assert_response :not_found + assert_equal '', response.body + end +end + end -- cgit v1.2.3 From 175cb7a963a31cf9caecdc40331df4cdc5aa86e2 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 17 Dec 2008 10:10:24 -0600 Subject: Fix metal tests --- actionpack/test/controller/integration_test.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 90afbfb9bc..c28050fe0d 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -374,16 +374,12 @@ class IntegrationProcessTest < ActionController::IntegrationTest end class MetalTest < ActionController::IntegrationTest - require(File.dirname(__FILE__) + "/../../../railties/lib/rails/rack/metal.rb") - - class Poller < ::Rails::Rack::Metal - def call(env) + class Poller + def self.call(env) if env["PATH_INFO"] =~ /^\/success/ [200, {"Content-Type" => "text/plain"}, "Hello World!"] - elsif env["PATH_INFO"] =~ /^\/failure/ - [404, {"Content-Type" => "text/plain"}, ''] else - super + [404, {"Content-Type" => "text/plain"}, ''] end end end -- cgit v1.2.3 From 3ff6b00ee30d0961f57e3c4b64ec8ff0155aaf2d Mon Sep 17 00:00:00 2001 From: Lourens Naude Date: Thu, 18 Dec 2008 11:33:53 -0600 Subject: Persistent session identifier support for CookieSessionStore and API compat. with the server side stores [#1591 state:resolved] Signed-off-by: Joshua Peek --- .../test/controller/session/cookie_store_test.rb | 26 ++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/session/cookie_store_test.rb b/actionpack/test/controller/session/cookie_store_test.rb index 8098059d46..ad8ff09884 100644 --- a/actionpack/test/controller/session/cookie_store_test.rb +++ b/actionpack/test/controller/session/cookie_store_test.rb @@ -9,6 +9,8 @@ class CookieStoreTest < ActionController::IntegrationTest CookieStoreApp = ActionController::Session::CookieStore.new(DispatcherApp, :key => SessionKey, :secret => SessionSecret) + Verifier = ActiveSupport::MessageVerifier.new(SessionSecret, 'SHA1') + SignedBar = "BAh7BjoIZm9vIghiYXI%3D--" + "fef868465920f415f2c0652d6910d3af288a0367" @@ -17,9 +19,13 @@ class CookieStoreTest < ActionController::IntegrationTest head :ok end + def persistent_session_id + render :text => session[:session_id] + end + def set_session_value session[:foo] = "bar" - head :ok + render :text => Marshal.dump(session.to_hash) end def get_session_value @@ -83,7 +89,8 @@ class CookieStoreTest < ActionController::IntegrationTest with_test_route_set do get '/set_session_value' assert_response :success - assert_equal ["_myapp_session=#{SignedBar}; path=/"], + session_payload = Verifier.generate( Marshal.load(response.body) ) + assert_equal ["_myapp_session=#{session_payload}; path=/"], headers['Set-Cookie'] end end @@ -132,6 +139,21 @@ class CookieStoreTest < ActionController::IntegrationTest end end + def test_persistent_session_id + with_test_route_set do + cookies[SessionKey] = SignedBar + get '/persistent_session_id' + assert_response :success + assert_equal response.body.size, 32 + session_id = response.body + get '/persistent_session_id' + assert_equal session_id, response.body + reset! + get '/persistent_session_id' + assert_not_equal session_id, response.body + end + end + private def with_test_route_set with_routing do |set| -- cgit v1.2.3 From 2eb2ec9e635c740684673495ed547d1c0769038d Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 18 Dec 2008 12:00:54 -0600 Subject: Move gaint lock into middleware --- actionpack/test/controller/dispatcher_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb index 30dda87bb4..a183b69c99 100644 --- a/actionpack/test/controller/dispatcher_test.rb +++ b/actionpack/test/controller/dispatcher_test.rb @@ -50,7 +50,7 @@ class DispatcherTest < Test::Unit::TestCase end def test_failsafe_response - Dispatcher.any_instance.expects(:dispatch_unlocked).raises('b00m') + Dispatcher.any_instance.expects(:dispatch).raises('b00m') ActionController::Failsafe.any_instance.expects(:log_failsafe_exception) assert_nothing_raised do -- cgit v1.2.3 From a9fde9a2abd6a6505d5fd197ad9640470d8df9be Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 18 Dec 2008 13:14:09 -0600 Subject: Cleanup dispatch path --- actionpack/test/controller/dispatcher_test.rb | 4 +++- actionpack/test/controller/rack_test.rb | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb index a183b69c99..fd06b4ea99 100644 --- a/actionpack/test/controller/dispatcher_test.rb +++ b/actionpack/test/controller/dispatcher_test.rb @@ -96,7 +96,9 @@ class DispatcherTest < Test::Unit::TestCase private def dispatch(cache_classes = true) - Dispatcher.any_instance.stubs(:handle_request).returns([200, {}, 'response']) + controller = mock() + controller.stubs(:process).returns([200, {}, 'response']) + ActionController::Routing::Routes.stubs(:recognize).returns(controller) Dispatcher.define_dispatcher_callbacks(cache_classes) @dispatcher.call({}) end diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb index e2ec686c41..3a8a00b7d7 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/controller/rack_test.rb @@ -236,7 +236,7 @@ class RackResponseTest < BaseRackTest @response.body = "Hello, World!" @response.prepare! - status, headers, body = @response.out + status, headers, body = @response.to_a assert_equal "200 OK", status assert_equal({ "Content-Type" => "text/html; charset=utf-8", @@ -257,7 +257,7 @@ class RackResponseTest < BaseRackTest end @response.prepare! - status, headers, body = @response.out + status, headers, body = @response.to_a assert_equal "200 OK", status assert_equal({"Content-Type" => "text/html; charset=utf-8", "Cache-Control" => "no-cache", "Set-Cookie" => []}, headers) @@ -293,6 +293,6 @@ class RackResponseHeadersTest < BaseRackTest private def response_headers @response.prepare! - @response.out[1] + @response.to_a[1] end end -- cgit v1.2.3 From 3da1b94d07fbbd6cff342a822af1631ae167a9b8 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 19 Dec 2008 15:05:51 -0600 Subject: Use status response accessor instead of the 'Status' header --- actionpack/test/controller/caching_test.rb | 2 +- actionpack/test/controller/rack_test.rb | 6 +++--- actionpack/test/controller/render_test.rb | 4 ++-- actionpack/test/controller/send_file_test.rb | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index ddf140ac3a..e24bb00bc7 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -169,7 +169,7 @@ class ActionCachingTestController < ActionController::Base def forbidden render :text => "Forbidden" - headers["Status"] = "403 Forbidden" + response.status = "403 Forbidden" end def with_layout diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb index 3a8a00b7d7..51f43290d2 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/controller/rack_test.rb @@ -271,17 +271,17 @@ class RackResponseHeadersTest < BaseRackTest def setup super @response = ActionController::RackResponse.new - @response.headers['Status'] = "200 OK" + @response.status = "200 OK" end def test_content_type [204, 304].each do |c| - @response.headers['Status'] = c.to_s + @response.status = c.to_s assert !response_headers.has_key?("Content-Type"), "#{c} should not have Content-Type header" end [200, 302, 404, 500].each do |c| - @response.headers['Status'] = c.to_s + @response.status = c.to_s assert response_headers.has_key?("Content-Type"), "#{c} did not have Content-Type header" end end diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index a6721fd903..e0f05d654c 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -1147,11 +1147,11 @@ class RenderTest < ActionController::TestCase def test_head_with_symbolic_status get :head_with_symbolic_status, :status => "ok" - assert_equal "200 OK", @response.headers["Status"] + assert_equal "200 OK", @response.status assert_response :ok get :head_with_symbolic_status, :status => "not_found" - assert_equal "404 Not Found", @response.headers["Status"] + assert_equal "404 Not Found", @response.status assert_response :not_found ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE.each do |status, code| diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb index ffbaa457f8..c4349bfc7f 100644 --- a/actionpack/test/controller/send_file_test.rb +++ b/actionpack/test/controller/send_file_test.rb @@ -123,13 +123,13 @@ class SendFileTest < Test::Unit::TestCase define_method "test_send_#{method}_status" do @controller.options = { :stream => false, :status => 500 } assert_nothing_raised { assert_not_nil process(method) } - assert_equal '500 Internal Server Error', @response.headers['Status'] + assert_equal '500 Internal Server Error', @response.status end define_method "test_default_send_#{method}_status" do @controller.options = { :stream => false } assert_nothing_raised { assert_not_nil process(method) } - assert_equal ActionController::Base::DEFAULT_RENDER_STATUS_CODE, @response.headers['Status'] + assert_equal ActionController::Base::DEFAULT_RENDER_STATUS_CODE, @response.status end end end -- cgit v1.2.3 From cbee72d21630f8949c4575cd1fd5a6f2e13d7827 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 19 Dec 2008 16:35:23 -0600 Subject: Improve cookie test coverage --- actionpack/test/controller/cookie_test.rb | 43 +++++++++++++++++-------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/cookie_test.rb b/actionpack/test/controller/cookie_test.rb index 5a6fb49861..67f31ba36b 100644 --- a/actionpack/test/controller/cookie_test.rb +++ b/actionpack/test/controller/cookie_test.rb @@ -18,7 +18,7 @@ class CookieTest < Test::Unit::TestCase cookies["user_name"] = { "value" => "david", "expires" => Time.local(2005, 10, 10) } cookies["login"] = "XJ-122" end - + def access_frozen_cookies cookies["will"] = "work" end @@ -36,8 +36,8 @@ class CookieTest < Test::Unit::TestCase cookies["user_name"] = { :value => "david", :http_only => true } end - def rescue_action(e) - raise unless ActionView::MissingTemplate # No templates here, and we don't care about the output + def rescue_action(e) + raise unless ActionView::MissingTemplate # No templates here, and we don't care about the output end end @@ -51,40 +51,46 @@ class CookieTest < Test::Unit::TestCase def test_setting_cookie get :authenticate - assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david") ], @response.headers["cookie"] + assert_equal "user_name=david; path=/", @response.headers["cookie"].to_s + assert_equal({"user_name" => ["david"]}, @response.cookies) end def test_setting_cookie_for_fourteen_days get :authenticate_for_fourteen_days - assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david", "expires" => Time.local(2005, 10, 10)) ], @response.headers["cookie"] - end + assert_equal "user_name=david; path=/; expires=Mon, 10 Oct 2005 05:00:00 GMT", @response.headers["cookie"].to_s + assert_equal({"user_name" => ["david"]}, @response.cookies) + end def test_setting_cookie_for_fourteen_days_with_symbols get :authenticate_for_fourteen_days_with_symbols - assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david", "expires" => Time.local(2005, 10, 10)) ], @response.headers["cookie"] + assert_equal "user_name=david; path=/; expires=Mon, 10 Oct 2005 05:00:00 GMT", @response.headers["cookie"].to_s + assert_equal({"user_name" => ["david"]}, @response.cookies) end def test_setting_cookie_with_http_only get :authenticate_with_http_only - assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david", "http_only" => true) ], @response.headers["cookie"] - assert_equal CGI::Cookie::new("name" => "user_name", "value" => "david", "path" => "/", "http_only" => true).to_s, @response.headers["cookie"][0].to_s - end + assert_equal "user_name=david; path=/; HttpOnly", @response.headers["cookie"].to_s + assert_equal({"user_name" => ["david"]}, @response.cookies) + end def test_multiple_cookies get :set_multiple_cookies assert_equal 2, @response.cookies.size - end + assert_equal "user_name=david; path=/; expires=Mon, 10 Oct 2005 05:00:00 GMT", @response.headers["cookie"][0].to_s + assert_equal "login=XJ-122; path=/", @response.headers["cookie"][1].to_s + assert_equal({"login" => ["XJ-122"], "user_name" => ["david"]}, @response.cookies) + end def test_setting_test_cookie assert_nothing_raised { get :access_frozen_cookies } end - + def test_expiring_cookie get :logout - assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "", "expires" => Time.at(0)) ], @response.headers["cookie"] - assert_equal CGI::Cookie::new("name" => "user_name", "value" => "", "expires" => Time.at(0)).value, [] - end - + assert_equal "user_name=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT", @response.headers["cookie"].to_s + assert_equal({"user_name" => []}, @response.cookies) + end + def test_cookiejar_accessor @request.cookies["user_name"] = CGI::Cookie.new("name" => "user_name", "value" => "david", "expires" => Time.local(2025, 10, 10)) @controller.request = @request @@ -100,11 +106,10 @@ class CookieTest < Test::Unit::TestCase jar = ActionController::CookieJar.new(@controller) assert_equal a, jar["pages"] end - + def test_delete_cookie_with_path get :delete_cookie_with_path - assert_equal "/beaten", @response.headers["cookie"].first.path - assert_not_equal "/", @response.headers["cookie"].first.path + assert_equal "user_name=; path=/beaten; expires=Thu, 01 Jan 1970 00:00:00 GMT", @response.headers["cookie"].to_s end def test_cookie_to_s_simple_values -- cgit v1.2.3 From a14bbd7a8574c3b485d4b71e0950b2b9ff4e90d7 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 19 Dec 2008 16:49:06 -0600 Subject: Process CGI 'cookie' header into 'Set-Cookie' for all responses. This mostly affects response.headers['cookie'] for test requests. Use response.cookies instead. --- actionpack/test/controller/cookie_test.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/cookie_test.rb b/actionpack/test/controller/cookie_test.rb index 67f31ba36b..cfe5726253 100644 --- a/actionpack/test/controller/cookie_test.rb +++ b/actionpack/test/controller/cookie_test.rb @@ -51,33 +51,33 @@ class CookieTest < Test::Unit::TestCase def test_setting_cookie get :authenticate - assert_equal "user_name=david; path=/", @response.headers["cookie"].to_s + assert_equal ["user_name=david; path=/"], @response.headers["Set-Cookie"] assert_equal({"user_name" => ["david"]}, @response.cookies) end def test_setting_cookie_for_fourteen_days get :authenticate_for_fourteen_days - assert_equal "user_name=david; path=/; expires=Mon, 10 Oct 2005 05:00:00 GMT", @response.headers["cookie"].to_s + assert_equal ["user_name=david; path=/; expires=Mon, 10 Oct 2005 05:00:00 GMT"], @response.headers["Set-Cookie"] assert_equal({"user_name" => ["david"]}, @response.cookies) end def test_setting_cookie_for_fourteen_days_with_symbols get :authenticate_for_fourteen_days_with_symbols - assert_equal "user_name=david; path=/; expires=Mon, 10 Oct 2005 05:00:00 GMT", @response.headers["cookie"].to_s + assert_equal ["user_name=david; path=/; expires=Mon, 10 Oct 2005 05:00:00 GMT"], @response.headers["Set-Cookie"] assert_equal({"user_name" => ["david"]}, @response.cookies) end def test_setting_cookie_with_http_only get :authenticate_with_http_only - assert_equal "user_name=david; path=/; HttpOnly", @response.headers["cookie"].to_s + assert_equal ["user_name=david; path=/; HttpOnly"], @response.headers["Set-Cookie"] assert_equal({"user_name" => ["david"]}, @response.cookies) end def test_multiple_cookies get :set_multiple_cookies assert_equal 2, @response.cookies.size - assert_equal "user_name=david; path=/; expires=Mon, 10 Oct 2005 05:00:00 GMT", @response.headers["cookie"][0].to_s - assert_equal "login=XJ-122; path=/", @response.headers["cookie"][1].to_s + assert_equal "user_name=david; path=/; expires=Mon, 10 Oct 2005 05:00:00 GMT", @response.headers["Set-Cookie"][0] + assert_equal "login=XJ-122; path=/", @response.headers["Set-Cookie"][1] assert_equal({"login" => ["XJ-122"], "user_name" => ["david"]}, @response.cookies) end @@ -87,7 +87,7 @@ class CookieTest < Test::Unit::TestCase def test_expiring_cookie get :logout - assert_equal "user_name=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT", @response.headers["cookie"].to_s + assert_equal ["user_name=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT"], @response.headers["Set-Cookie"] assert_equal({"user_name" => []}, @response.cookies) end @@ -109,7 +109,7 @@ class CookieTest < Test::Unit::TestCase def test_delete_cookie_with_path get :delete_cookie_with_path - assert_equal "user_name=; path=/beaten; expires=Thu, 01 Jan 1970 00:00:00 GMT", @response.headers["cookie"].to_s + assert_equal ["user_name=; path=/beaten; expires=Thu, 01 Jan 1970 00:00:00 GMT"], @response.headers["Set-Cookie"] end def test_cookie_to_s_simple_values -- cgit v1.2.3 From fda62ecf707b4023b30303dd0baf303f1ef8d344 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 19 Dec 2008 17:15:22 -0600 Subject: Rename AbstractResponse to Response and inheirt from Rack::Response --- actionpack/test/controller/action_pack_assertions_test.rb | 6 +++--- actionpack/test/controller/cookie_test.rb | 8 ++++---- actionpack/test/controller/rack_test.rb | 8 ++++---- actionpack/test/controller/render_test.rb | 10 +++++----- 4 files changed, 16 insertions(+), 16 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index 87c12ee4ee..cb7922efd2 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -500,17 +500,17 @@ class ActionPackHeaderTest < ActionController::TestCase def test_rendering_xml_sets_content_type process :hello_xml_world - assert_equal('application/xml; charset=utf-8', @response.headers['type']) + assert_equal('application/xml; charset=utf-8', @response.headers['Content-Type']) end def test_rendering_xml_respects_content_type @response.headers['type'] = 'application/pdf' process :hello_xml_world - assert_equal('application/pdf; charset=utf-8', @response.headers['type']) + assert_equal('application/pdf; charset=utf-8', @response.headers['Content-Type']) end def test_render_text_with_custom_content_type get :render_text_with_custom_content_type - assert_equal 'application/rss+xml; charset=utf-8', @response.headers['type'] + assert_equal 'application/rss+xml; charset=utf-8', @response.headers['Content-Type'] end end diff --git a/actionpack/test/controller/cookie_test.rb b/actionpack/test/controller/cookie_test.rb index cfe5726253..4b969519c6 100644 --- a/actionpack/test/controller/cookie_test.rb +++ b/actionpack/test/controller/cookie_test.rb @@ -59,7 +59,7 @@ class CookieTest < Test::Unit::TestCase get :authenticate_for_fourteen_days assert_equal ["user_name=david; path=/; expires=Mon, 10 Oct 2005 05:00:00 GMT"], @response.headers["Set-Cookie"] assert_equal({"user_name" => ["david"]}, @response.cookies) - end + end def test_setting_cookie_for_fourteen_days_with_symbols get :authenticate_for_fourteen_days_with_symbols @@ -71,7 +71,7 @@ class CookieTest < Test::Unit::TestCase get :authenticate_with_http_only assert_equal ["user_name=david; path=/; HttpOnly"], @response.headers["Set-Cookie"] assert_equal({"user_name" => ["david"]}, @response.cookies) - end + end def test_multiple_cookies get :set_multiple_cookies @@ -79,7 +79,7 @@ class CookieTest < Test::Unit::TestCase assert_equal "user_name=david; path=/; expires=Mon, 10 Oct 2005 05:00:00 GMT", @response.headers["Set-Cookie"][0] assert_equal "login=XJ-122; path=/", @response.headers["Set-Cookie"][1] assert_equal({"login" => ["XJ-122"], "user_name" => ["david"]}, @response.cookies) - end + end def test_setting_test_cookie assert_nothing_raised { get :access_frozen_cookies } @@ -89,7 +89,7 @@ class CookieTest < Test::Unit::TestCase get :logout assert_equal ["user_name=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT"], @response.headers["Set-Cookie"] assert_equal({"user_name" => []}, @response.cookies) - end + end def test_cookiejar_accessor @request.cookies["user_name"] = CGI::Cookie.new("name" => "user_name", "value" => "david", "expires" => Time.local(2025, 10, 10)) diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb index 51f43290d2..81d103f0f9 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/controller/rack_test.rb @@ -229,7 +229,7 @@ end class RackResponseTest < BaseRackTest def setup super - @response = ActionController::RackResponse.new + @response = ActionController::Response.new end def test_simple_output @@ -237,7 +237,7 @@ class RackResponseTest < BaseRackTest @response.prepare! status, headers, body = @response.to_a - assert_equal "200 OK", status + assert_equal 200, status assert_equal({ "Content-Type" => "text/html; charset=utf-8", "Cache-Control" => "private, max-age=0, must-revalidate", @@ -258,7 +258,7 @@ class RackResponseTest < BaseRackTest @response.prepare! status, headers, body = @response.to_a - assert_equal "200 OK", status + assert_equal 200, status assert_equal({"Content-Type" => "text/html; charset=utf-8", "Cache-Control" => "no-cache", "Set-Cookie" => []}, headers) parts = [] @@ -270,7 +270,7 @@ end class RackResponseHeadersTest < BaseRackTest def setup super - @response = ActionController::RackResponse.new + @response = ActionController::Response.new @response.status = "200 OK" end diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index e0f05d654c..8e08a5a8e9 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -208,7 +208,7 @@ class TestController < ActionController::Base def greeting # let's just rely on the template end - + def blank_response render :text => ' ' end @@ -1099,14 +1099,14 @@ class RenderTest < ActionController::TestCase def test_update_page get :update_page assert_template nil - assert_equal 'text/javascript; charset=utf-8', @response.headers['type'] + assert_equal 'text/javascript; charset=utf-8', @response.headers['Content-Type'] assert_equal 2, @response.body.split($/).length end def test_update_page_with_instance_variables get :update_page_with_instance_variables assert_template nil - assert_equal 'text/javascript; charset=utf-8', @response.headers['type'] + assert_equal 'text/javascript; charset=utf-8', @response.headers["Content-Type"] assert_match /balance/, @response.body assert_match /\$37/, @response.body end @@ -1114,7 +1114,7 @@ class RenderTest < ActionController::TestCase def test_update_page_with_view_method get :update_page_with_view_method assert_template nil - assert_equal 'text/javascript; charset=utf-8', @response.headers['type'] + assert_equal 'text/javascript; charset=utf-8', @response.headers["Content-Type"] assert_match /2 people/, @response.body end @@ -1384,7 +1384,7 @@ class EtagRenderTest < ActionController::TestCase @request.host = "www.nextangle.com" @expected_bang_etag = etag_for(expand_key([:foo, 123])) end - + def test_render_blank_body_shouldnt_set_etag get :blank_response assert !@response.etag? -- cgit v1.2.3 From 7b249b67e9df9f375eaad9e6eb41be73338faaa7 Mon Sep 17 00:00:00 2001 From: Matt Bauer Date: Sat, 20 Dec 2008 14:37:51 -0600 Subject: Fix reset_session with lazy cookie stores [#1601 state:resolved] Signed-off-by: Joshua Peek --- .../test/controller/session/cookie_store_test.rb | 26 +++++++++++++++++++++- .../controller/session/mem_cache_store_test.rb | 21 +++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/session/cookie_store_test.rb b/actionpack/test/controller/session/cookie_store_test.rb index ad8ff09884..69aec59dc0 100644 --- a/actionpack/test/controller/session/cookie_store_test.rb +++ b/actionpack/test/controller/session/cookie_store_test.rb @@ -32,6 +32,11 @@ class CookieStoreTest < ActionController::IntegrationTest render :text => "foo: #{session[:foo].inspect}" end + def call_reset_session + reset_session + head :ok + end + def raise_data_overflow session[:foo] = 'bye!' * 1024 head :ok @@ -89,7 +94,7 @@ class CookieStoreTest < ActionController::IntegrationTest with_test_route_set do get '/set_session_value' assert_response :success - session_payload = Verifier.generate( Marshal.load(response.body) ) + session_payload = Verifier.generate(Marshal.load(response.body)) assert_equal ["_myapp_session=#{session_payload}; path=/"], headers['Set-Cookie'] end @@ -139,6 +144,25 @@ class CookieStoreTest < ActionController::IntegrationTest end end + def test_setting_session_value_after_session_reset + with_test_route_set do + get '/set_session_value' + assert_response :success + session_payload = Verifier.generate(Marshal.load(response.body)) + assert_equal ["_myapp_session=#{session_payload}; path=/"], + headers['Set-Cookie'] + + get '/call_reset_session' + assert_response :success + assert_not_equal [], headers['Set-Cookie'] + assert_not_equal session_payload, cookies[SessionKey] + + get '/get_session_value' + assert_response :success + assert_equal 'foo: nil', response.body + end + end + def test_persistent_session_id with_test_route_set do cookies[SessionKey] = SignedBar diff --git a/actionpack/test/controller/session/mem_cache_store_test.rb b/actionpack/test/controller/session/mem_cache_store_test.rb index 52e31b78da..eb896a344c 100644 --- a/actionpack/test/controller/session/mem_cache_store_test.rb +++ b/actionpack/test/controller/session/mem_cache_store_test.rb @@ -16,6 +16,11 @@ class MemCacheStoreTest < ActionController::IntegrationTest render :text => "foo: #{session[:foo].inspect}" end + def call_reset_session + reset_session + head :ok + end + def rescue_action(e) raise end end @@ -63,6 +68,22 @@ class MemCacheStoreTest < ActionController::IntegrationTest assert_equal nil, cookies['_session_id'] end end + + def test_setting_session_value_after_session_reset + with_test_route_set do + get '/set_session_value' + assert_response :success + assert cookies['_session_id'] + + get '/call_reset_session' + assert_response :success + assert_not_equal [], headers['Set-Cookie'] + + get '/get_session_value' + assert_response :success + assert_equal 'foo: nil', response.body + end + end rescue LoadError, RuntimeError $stderr.puts "Skipping MemCacheStoreTest tests. Start memcached and try again." end -- cgit v1.2.3 From 606cd61b9a2a710a27c2e482b5dace100cce9779 Mon Sep 17 00:00:00 2001 From: Frederick Cheung Date: Sun, 21 Dec 2008 02:11:39 +0000 Subject: Fix Mime::Type#=~ not using Regexp.quote Signed-off-by: Pratik Naik --- actionpack/test/controller/mime_type_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/mime_type_test.rb b/actionpack/test/controller/mime_type_test.rb index 9c4416ecf0..c7faa621d9 100644 --- a/actionpack/test/controller/mime_type_test.rb +++ b/actionpack/test/controller/mime_type_test.rb @@ -88,5 +88,6 @@ class MimeTypeTest < Test::Unit::TestCase assert Mime::JS !~ "text/html" assert !(Mime::JS !~ "text/javascript") assert !(Mime::JS !~ "application/javascript") + assert Mime::HTML =~ 'application/xhtml+xml' end end -- cgit v1.2.3 From 3b317b7100c9a416f4e3545f3844f0c0743acdb2 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 20 Dec 2008 21:25:09 -0600 Subject: Switch to Rack::Response#set_cookie instead of using CGI::Cookie to build cookie headers --- actionpack/test/controller/cookie_test.rb | 66 +++++++------------------------ 1 file changed, 14 insertions(+), 52 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/cookie_test.rb b/actionpack/test/controller/cookie_test.rb index 4b969519c6..84d272b1c7 100644 --- a/actionpack/test/controller/cookie_test.rb +++ b/actionpack/test/controller/cookie_test.rb @@ -52,33 +52,33 @@ class CookieTest < Test::Unit::TestCase def test_setting_cookie get :authenticate assert_equal ["user_name=david; path=/"], @response.headers["Set-Cookie"] - assert_equal({"user_name" => ["david"]}, @response.cookies) + assert_equal({"user_name" => "david"}, @response.cookies) end def test_setting_cookie_for_fourteen_days get :authenticate_for_fourteen_days - assert_equal ["user_name=david; path=/; expires=Mon, 10 Oct 2005 05:00:00 GMT"], @response.headers["Set-Cookie"] - assert_equal({"user_name" => ["david"]}, @response.cookies) + assert_equal ["user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT"], @response.headers["Set-Cookie"] + assert_equal({"user_name" => "david"}, @response.cookies) end def test_setting_cookie_for_fourteen_days_with_symbols get :authenticate_for_fourteen_days_with_symbols - assert_equal ["user_name=david; path=/; expires=Mon, 10 Oct 2005 05:00:00 GMT"], @response.headers["Set-Cookie"] - assert_equal({"user_name" => ["david"]}, @response.cookies) + assert_equal ["user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT"], @response.headers["Set-Cookie"] + assert_equal({"user_name" => "david"}, @response.cookies) end def test_setting_cookie_with_http_only get :authenticate_with_http_only assert_equal ["user_name=david; path=/; HttpOnly"], @response.headers["Set-Cookie"] - assert_equal({"user_name" => ["david"]}, @response.cookies) + assert_equal({"user_name" => "david"}, @response.cookies) end def test_multiple_cookies get :set_multiple_cookies assert_equal 2, @response.cookies.size - assert_equal "user_name=david; path=/; expires=Mon, 10 Oct 2005 05:00:00 GMT", @response.headers["Set-Cookie"][0] + assert_equal "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT", @response.headers["Set-Cookie"][0] assert_equal "login=XJ-122; path=/", @response.headers["Set-Cookie"][1] - assert_equal({"login" => ["XJ-122"], "user_name" => ["david"]}, @response.cookies) + assert_equal({"login" => "XJ-122", "user_name" => "david"}, @response.cookies) end def test_setting_test_cookie @@ -87,12 +87,12 @@ class CookieTest < Test::Unit::TestCase def test_expiring_cookie get :logout - assert_equal ["user_name=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT"], @response.headers["Set-Cookie"] - assert_equal({"user_name" => []}, @response.cookies) + assert_equal ["user_name=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT"], @response.headers["Set-Cookie"] + assert_equal({"user_name" => nil}, @response.cookies) end def test_cookiejar_accessor - @request.cookies["user_name"] = CGI::Cookie.new("name" => "user_name", "value" => "david", "expires" => Time.local(2025, 10, 10)) + @request.cookies["user_name"] = "david" @controller.request = @request jar = ActionController::CookieJar.new(@controller) assert_equal "david", jar["user_name"] @@ -100,52 +100,14 @@ class CookieTest < Test::Unit::TestCase end def test_cookiejar_accessor_with_array_value - a = %w{1 2 3} - @request.cookies["pages"] = CGI::Cookie.new("name" => "pages", "value" => a, "expires" => Time.local(2025, 10, 10)) + @request.cookies["pages"] = %w{1 2 3} @controller.request = @request jar = ActionController::CookieJar.new(@controller) - assert_equal a, jar["pages"] + assert_equal %w{1 2 3}, jar["pages"] end def test_delete_cookie_with_path get :delete_cookie_with_path - assert_equal ["user_name=; path=/beaten; expires=Thu, 01 Jan 1970 00:00:00 GMT"], @response.headers["Set-Cookie"] - end - - def test_cookie_to_s_simple_values - assert_equal 'myname=myvalue; path=', CGI::Cookie.new('myname', 'myvalue').to_s - end - - def test_cookie_to_s_hash - cookie_str = CGI::Cookie.new( - 'name' => 'myname', - 'value' => 'myvalue', - 'domain' => 'mydomain', - 'path' => 'mypath', - 'expires' => Time.utc(2007, 10, 20), - 'secure' => true, - 'http_only' => true).to_s - assert_equal 'myname=myvalue; domain=mydomain; path=mypath; expires=Sat, 20 Oct 2007 00:00:00 GMT; secure; HttpOnly', cookie_str - end - - def test_cookie_to_s_hash_default_not_secure_not_http_only - cookie_str = CGI::Cookie.new( - 'name' => 'myname', - 'value' => 'myvalue', - 'domain' => 'mydomain', - 'path' => 'mypath', - 'expires' => Time.utc(2007, 10, 20)) - assert cookie_str !~ /secure/ - assert cookie_str !~ /HttpOnly/ - end - - def test_cookies_should_not_be_split_on_ampersand_values - cookies = CGI::Cookie.parse('return_to=http://rubyonrails.org/search?term=api&scope=all&global=true') - assert_equal({"return_to" => ["http://rubyonrails.org/search?term=api&scope=all&global=true"]}, cookies) - end - - def test_cookies_should_not_be_split_on_values_with_newlines - cookies = CGI::Cookie.new("name" => "val", "value" => "this\nis\na\ntest") - assert cookies.size == 1 + assert_equal ["user_name=; path=/beaten; expires=Thu, 01-Jan-1970 00:00:00 GMT"], @response.headers["Set-Cookie"] end end -- cgit v1.2.3 From cf9c36834a8d11ef05da7bd7d2dce7c3e121501a Mon Sep 17 00:00:00 2001 From: Frederick Cheung Date: Sun, 21 Dec 2008 12:35:29 +0000 Subject: Fix failing cookie store test --- actionpack/test/controller/cookie_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/cookie_test.rb b/actionpack/test/controller/cookie_test.rb index 84d272b1c7..3ddc5768a9 100644 --- a/actionpack/test/controller/cookie_test.rb +++ b/actionpack/test/controller/cookie_test.rb @@ -7,15 +7,15 @@ class CookieTest < Test::Unit::TestCase end def authenticate_for_fourteen_days - cookies["user_name"] = { "value" => "david", "expires" => Time.local(2005, 10, 10) } + cookies["user_name"] = { "value" => "david", "expires" => Time.utc(2005, 10, 10,5) } end def authenticate_for_fourteen_days_with_symbols - cookies[:user_name] = { :value => "david", :expires => Time.local(2005, 10, 10) } + cookies[:user_name] = { :value => "david", :expires => Time.utc(2005, 10, 10,5) } end def set_multiple_cookies - cookies["user_name"] = { "value" => "david", "expires" => Time.local(2005, 10, 10) } + cookies["user_name"] = { "value" => "david", "expires" => Time.utc(2005, 10, 10,5) } cookies["login"] = "XJ-122" end -- cgit v1.2.3 From fcd58dc27a99085b161f2463988d4ee373d44ec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=3D=3Futf-8=3Fq=3FAdam=3D20Cig=3DC3=3DA1nek=3F=3D?= Date: Sun, 21 Dec 2008 18:58:55 +0000 Subject: Allow use of symbols for :type option of ActionController::Streaming#send_file/#send_data [#1232 state:resolved] Signed-off-by: Frederick Cheung --- actionpack/test/controller/send_file_test.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb index c4349bfc7f..1b7486ad34 100644 --- a/actionpack/test/controller/send_file_test.rb +++ b/actionpack/test/controller/send_file_test.rb @@ -119,6 +119,31 @@ class SendFileTest < Test::Unit::TestCase assert_equal 'private', h['Cache-Control'] end + def test_send_file_headers_with_mime_lookup_with_symbol + options = { + :length => 1, + :type => :png + } + + @controller.headers = {} + @controller.send(:send_file_headers!, options) + + headers = @controller.headers + + assert_equal 'image/png', headers['Content-Type'] + end + + + def test_send_file_headers_with_bad_symbol + options = { + :length => 1, + :type => :this_type_is_not_registered + } + + @controller.headers = {} + assert_raises(ArgumentError){ @controller.send(:send_file_headers!, options) } + end + %w(file data).each do |method| define_method "test_send_#{method}_status" do @controller.options = { :stream => false, :status => 500 } -- cgit v1.2.3 From 7e1751111ecf3886eba313fef183d73ff1f07eb6 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Mon, 22 Dec 2008 22:36:38 +0000 Subject: Rename RackRequest to Request --- actionpack/test/controller/rack_test.rb | 6 +++--- actionpack/test/controller/request_test.rb | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb index 81d103f0f9..f58a9c53e5 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/controller/rack_test.rb @@ -43,10 +43,10 @@ class BaseRackTest < Test::Unit::TestCase "REDIRECT_STATUS" => "200", "REQUEST_METHOD" => "GET" } - @request = ActionController::RackRequest.new(@env) + @request = ActionController::Request.new(@env) # some Nokia phone browsers omit the space after the semicolon separator. # some developers have grown accustomed to using comma in cookie values. - @alt_cookie_fmt_request = ActionController::RackRequest.new(@env.merge({"HTTP_COOKIE"=>"_session_id=c84ace847,96670c052c6ceb2451fb0f2;is_admin=yes"})) + @alt_cookie_fmt_request = ActionController::Request.new(@env.merge({"HTTP_COOKIE"=>"_session_id=c84ace847,96670c052c6ceb2451fb0f2;is_admin=yes"})) end def default_test; end @@ -218,7 +218,7 @@ class RackRequestNeedsRewoundTest < BaseRackTest @env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8' # Read the request body by parsing params. - request = ActionController::RackRequest.new(@env) + request = ActionController::Request.new(@env) request.request_parameters # Should have rewound the body. diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb index 71da50fab0..694771dfe8 100644 --- a/actionpack/test/controller/request_test.rb +++ b/actionpack/test/controller/request_test.rb @@ -856,7 +856,7 @@ class XmlParamsParsingTest < ActiveSupport::TestCase env = { 'rack.input' => StringIO.new(body), 'CONTENT_TYPE' => 'application/xml', 'CONTENT_LENGTH' => body.size.to_s } - ActionController::RackRequest.new(env).request_parameters + ActionController::Request.new(env).request_parameters end end @@ -866,7 +866,7 @@ class LegacyXmlParamsParsingTest < XmlParamsParsingTest env = { 'rack.input' => StringIO.new(body), 'HTTP_X_POST_DATA_FORMAT' => 'xml', 'CONTENT_LENGTH' => body.size.to_s } - ActionController::RackRequest.new(env).request_parameters + ActionController::Request.new(env).request_parameters end end @@ -888,6 +888,6 @@ class JsonParamsParsingTest < ActiveSupport::TestCase env = { 'rack.input' => StringIO.new(body), 'CONTENT_TYPE' => content_type, 'CONTENT_LENGTH' => body.size.to_s } - ActionController::RackRequest.new(env).request_parameters + ActionController::Request.new(env).request_parameters end end -- cgit v1.2.3 From 293bb02f91390088890104335c76c51b8990cc49 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Tue, 23 Dec 2008 00:15:08 +0000 Subject: Unify ActionController::AbstractRequest and ActionController::Request --- actionpack/test/controller/request_test.rb | 68 +++++++++++++++--------------- 1 file changed, 34 insertions(+), 34 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb index 694771dfe8..c2c35ad6fe 100644 --- a/actionpack/test/controller/request_test.rb +++ b/actionpack/test/controller/request_test.rb @@ -426,95 +426,95 @@ class UrlEncodedRequestParameterParsingTest < ActiveSupport::TestCase def test_query_string assert_equal( { "action" => "create_customer", "full_name" => "David Heinemeier Hansson", "customerId" => "1"}, - ActionController::AbstractRequest.parse_query_parameters(@query_string) + ActionController::Request.parse_query_parameters(@query_string) ) end def test_deep_query_string expected = {'x' => {'y' => {'z' => '10'}}} - assert_equal(expected, ActionController::AbstractRequest.parse_query_parameters('x[y][z]=10')) + assert_equal(expected, ActionController::Request.parse_query_parameters('x[y][z]=10')) end def test_deep_query_string_with_array - assert_equal({'x' => {'y' => {'z' => ['10']}}}, ActionController::AbstractRequest.parse_query_parameters('x[y][z][]=10')) - assert_equal({'x' => {'y' => {'z' => ['10', '5']}}}, ActionController::AbstractRequest.parse_query_parameters('x[y][z][]=10&x[y][z][]=5')) + assert_equal({'x' => {'y' => {'z' => ['10']}}}, ActionController::Request.parse_query_parameters('x[y][z][]=10')) + assert_equal({'x' => {'y' => {'z' => ['10', '5']}}}, ActionController::Request.parse_query_parameters('x[y][z][]=10&x[y][z][]=5')) end def test_deep_query_string_with_array_of_hash - assert_equal({'x' => {'y' => [{'z' => '10'}]}}, ActionController::AbstractRequest.parse_query_parameters('x[y][][z]=10')) - assert_equal({'x' => {'y' => [{'z' => '10', 'w' => '10'}]}}, ActionController::AbstractRequest.parse_query_parameters('x[y][][z]=10&x[y][][w]=10')) + assert_equal({'x' => {'y' => [{'z' => '10'}]}}, ActionController::Request.parse_query_parameters('x[y][][z]=10')) + assert_equal({'x' => {'y' => [{'z' => '10', 'w' => '10'}]}}, ActionController::Request.parse_query_parameters('x[y][][z]=10&x[y][][w]=10')) end def test_deep_query_string_with_array_of_hashes_with_one_pair - assert_equal({'x' => {'y' => [{'z' => '10'}, {'z' => '20'}]}}, ActionController::AbstractRequest.parse_query_parameters('x[y][][z]=10&x[y][][z]=20')) - assert_equal("10", ActionController::AbstractRequest.parse_query_parameters('x[y][][z]=10&x[y][][z]=20')["x"]["y"].first["z"]) - assert_equal("10", ActionController::AbstractRequest.parse_query_parameters('x[y][][z]=10&x[y][][z]=20').with_indifferent_access[:x][:y].first[:z]) + assert_equal({'x' => {'y' => [{'z' => '10'}, {'z' => '20'}]}}, ActionController::Request.parse_query_parameters('x[y][][z]=10&x[y][][z]=20')) + assert_equal("10", ActionController::Request.parse_query_parameters('x[y][][z]=10&x[y][][z]=20')["x"]["y"].first["z"]) + assert_equal("10", ActionController::Request.parse_query_parameters('x[y][][z]=10&x[y][][z]=20').with_indifferent_access[:x][:y].first[:z]) end def test_deep_query_string_with_array_of_hashes_with_multiple_pairs assert_equal( {'x' => {'y' => [{'z' => '10', 'w' => 'a'}, {'z' => '20', 'w' => 'b'}]}}, - ActionController::AbstractRequest.parse_query_parameters('x[y][][z]=10&x[y][][w]=a&x[y][][z]=20&x[y][][w]=b') + ActionController::Request.parse_query_parameters('x[y][][z]=10&x[y][][w]=a&x[y][][z]=20&x[y][][w]=b') ) end def test_query_string_with_nil assert_equal( { "action" => "create_customer", "full_name" => ''}, - ActionController::AbstractRequest.parse_query_parameters(@query_string_with_empty) + ActionController::Request.parse_query_parameters(@query_string_with_empty) ) end def test_query_string_with_array assert_equal( { "action" => "create_customer", "selected" => ["1", "2", "3"]}, - ActionController::AbstractRequest.parse_query_parameters(@query_string_with_array) + ActionController::Request.parse_query_parameters(@query_string_with_array) ) end def test_query_string_with_amps assert_equal( { "action" => "create_customer", "name" => "Don't & Does"}, - ActionController::AbstractRequest.parse_query_parameters(@query_string_with_amps) + ActionController::Request.parse_query_parameters(@query_string_with_amps) ) end def test_query_string_with_many_equal assert_equal( { "action" => "create_customer", "full_name" => "abc=def=ghi"}, - ActionController::AbstractRequest.parse_query_parameters(@query_string_with_many_equal) + ActionController::Request.parse_query_parameters(@query_string_with_many_equal) ) end def test_query_string_without_equal assert_equal( { "action" => nil }, - ActionController::AbstractRequest.parse_query_parameters(@query_string_without_equal) + ActionController::Request.parse_query_parameters(@query_string_without_equal) ) end def test_query_string_with_empty_key assert_equal( { "action" => "create_customer", "full_name" => "David Heinemeier Hansson" }, - ActionController::AbstractRequest.parse_query_parameters(@query_string_with_empty_key) + ActionController::Request.parse_query_parameters(@query_string_with_empty_key) ) end def test_query_string_with_many_ampersands assert_equal( { "action" => "create_customer", "full_name" => "David Heinemeier Hansson"}, - ActionController::AbstractRequest.parse_query_parameters(@query_string_with_many_ampersands) + ActionController::Request.parse_query_parameters(@query_string_with_many_ampersands) ) end def test_unbalanced_query_string_with_array assert_equal( {'location' => ["1", "2"], 'age_group' => ["2"]}, - ActionController::AbstractRequest.parse_query_parameters("location[]=1&location[]=2&age_group[]=2") + ActionController::Request.parse_query_parameters("location[]=1&location[]=2&age_group[]=2") ) assert_equal( {'location' => ["1", "2"], 'age_group' => ["2"]}, - ActionController::AbstractRequest.parse_request_parameters({'location[]' => ["1", "2"], + ActionController::Request.parse_request_parameters({'location[]' => ["1", "2"], 'age_group[]' => ["2"]}) ) end @@ -527,7 +527,7 @@ class UrlEncodedRequestParameterParsingTest < ActiveSupport::TestCase expected = { "note" => { "viewers"=>{"viewer"=>[{ "id"=>"1", "type"=>"User"}, {"type"=>"Group", "id"=>"2"} ]} } } - assert_equal(expected, ActionController::AbstractRequest.parse_request_parameters(query)) + assert_equal(expected, ActionController::Request.parse_request_parameters(query)) end def test_parse_params @@ -566,7 +566,7 @@ class UrlEncodedRequestParameterParsingTest < ActiveSupport::TestCase } } - assert_equal expected_output, ActionController::AbstractRequest.parse_request_parameters(input) + assert_equal expected_output, ActionController::Request.parse_request_parameters(input) end UploadedStringIO = ActionController::UploadedStringIO @@ -621,7 +621,7 @@ class UrlEncodedRequestParameterParsingTest < ActiveSupport::TestCase "text_part" => "abc" } - params = ActionController::AbstractRequest.parse_request_parameters(input) + params = ActionController::Request.parse_request_parameters(input) assert_equal expected_output, params # Lone filenames are preserved. @@ -652,7 +652,7 @@ class UrlEncodedRequestParameterParsingTest < ActiveSupport::TestCase "logo" => File.new(File.dirname(__FILE__) + "/rack_test.rb").path, } - assert_equal expected_output, ActionController::AbstractRequest.parse_request_parameters(input) + assert_equal expected_output, ActionController::Request.parse_request_parameters(input) end def test_parse_params_with_array @@ -660,55 +660,55 @@ class UrlEncodedRequestParameterParsingTest < ActiveSupport::TestCase expected_output = { "selected" => [ "1", "2", "3" ] } - assert_equal expected_output, ActionController::AbstractRequest.parse_request_parameters(input) + assert_equal expected_output, ActionController::Request.parse_request_parameters(input) end def test_parse_params_with_non_alphanumeric_name input = { "a/b[c]" => %w(d) } expected = { "a/b" => { "c" => "d" }} - assert_equal expected, ActionController::AbstractRequest.parse_request_parameters(input) + assert_equal expected, ActionController::Request.parse_request_parameters(input) end def test_parse_params_with_single_brackets_in_middle input = { "a/b[c]d" => %w(e) } expected = { "a/b" => {} } - assert_equal expected, ActionController::AbstractRequest.parse_request_parameters(input) + assert_equal expected, ActionController::Request.parse_request_parameters(input) end def test_parse_params_with_separated_brackets input = { "a/b@[c]d[e]" => %w(f) } expected = { "a/b@" => { }} - assert_equal expected, ActionController::AbstractRequest.parse_request_parameters(input) + assert_equal expected, ActionController::Request.parse_request_parameters(input) end def test_parse_params_with_separated_brackets_and_array input = { "a/b@[c]d[e][]" => %w(f) } expected = { "a/b@" => { }} - assert_equal expected , ActionController::AbstractRequest.parse_request_parameters(input) + assert_equal expected , ActionController::Request.parse_request_parameters(input) end def test_parse_params_with_unmatched_brackets_and_array input = { "a/b@[c][d[e][]" => %w(f) } expected = { "a/b@" => { "c" => { }}} - assert_equal expected, ActionController::AbstractRequest.parse_request_parameters(input) + assert_equal expected, ActionController::Request.parse_request_parameters(input) end def test_parse_params_with_nil_key input = { nil => nil, "test2" => %w(value1) } expected = { "test2" => "value1" } - assert_equal expected, ActionController::AbstractRequest.parse_request_parameters(input) + assert_equal expected, ActionController::Request.parse_request_parameters(input) end def test_parse_params_with_array_prefix_and_hashes input = { "a[][b][c]" => %w(d) } expected = {"a" => [{"b" => {"c" => "d"}}]} - assert_equal expected, ActionController::AbstractRequest.parse_request_parameters(input) + assert_equal expected, ActionController::Request.parse_request_parameters(input) end def test_parse_params_with_complex_nesting input = { "a[][b][c][][d][]" => %w(e) } expected = {"a" => [{"b" => {"c" => [{"d" => ["e"]}]}}]} - assert_equal expected, ActionController::AbstractRequest.parse_request_parameters(input) + assert_equal expected, ActionController::Request.parse_request_parameters(input) end end @@ -770,7 +770,7 @@ class MultipartRequestParameterParsingTest < ActiveSupport::TestCase # Ensures that parse_multipart_form_parameters works with streams that cannot be rewound file = File.open(File.join(FIXTURE_PATH, 'large_text_file'), 'rb') file.expects(:rewind).raises(Errno::ESPIPE) - params = ActionController::AbstractRequest.parse_multipart_form_parameters(file, 'AaB03x', file.stat.size, {}) + params = ActionController::Request.parse_multipart_form_parameters(file, 'AaB03x', file.stat.size, {}) assert_not_equal 0, file.pos # file was not rewound after reading end end @@ -809,7 +809,7 @@ class MultipartRequestParameterParsingTest < ActiveSupport::TestCase private def parse_multipart(name) File.open(File.join(FIXTURE_PATH, name), 'rb') do |file| - params = ActionController::AbstractRequest.parse_multipart_form_parameters(file, 'AaB03x', file.stat.size, {}) + params = ActionController::Request.parse_multipart_form_parameters(file, 'AaB03x', file.stat.size, {}) assert_equal 0, file.pos # file was rewound after reading params end -- cgit v1.2.3 From 9c1e48eaea921efa67fbeed1ff1876dc710f8fd2 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 23 Dec 2008 13:36:05 -0600 Subject: ActionController::VerbPiggybacking middleware --- actionpack/test/controller/rack_test.rb | 23 ----------------------- actionpack/test/controller/request_test.rb | 6 ++---- 2 files changed, 2 insertions(+), 27 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb index f58a9c53e5..406e2b2818 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/controller/rack_test.rb @@ -187,29 +187,6 @@ class RackRequestContentTypeTest < BaseRackTest end end -class RackRequestMethodTest < BaseRackTest - def test_get - assert_equal :get, @request.request_method - end - - def test_post - @request.env['REQUEST_METHOD'] = 'POST' - assert_equal :post, @request.request_method - end - - def test_put - set_content_data '_method=put' - - assert_equal :put, @request.request_method - end - - def test_delete - set_content_data '_method=delete' - - assert_equal :delete, @request.request_method - end -end - class RackRequestNeedsRewoundTest < BaseRackTest def test_body_should_be_rewound data = 'foo' diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb index c2c35ad6fe..3e10a4665e 100644 --- a/actionpack/test/controller/request_test.rb +++ b/actionpack/test/controller/request_test.rb @@ -303,18 +303,16 @@ class RequestTest < ActiveSupport::TestCase end def test_allow_method_hacking_on_post - self.request_method = :post [:get, :head, :options, :put, :post, :delete].each do |method| - @request.instance_eval { @parameters = { :_method => method.to_s } ; @request_method = nil } + self.request_method = method @request.request_method(true) assert_equal(method == :head ? :get : method, @request.method) end end def test_invalid_method_hacking_on_post_raises_exception - self.request_method = :post - @request.instance_eval { @parameters = { :_method => :random_method } ; @request_method = nil } assert_raises(ActionController::UnknownHttpMethod) do + self.request_method = :_random_method @request.request_method(true) end end -- cgit v1.2.3 From e898f82a743063652aed802d99ea8b5deac2ec3c Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Thu, 25 Dec 2008 03:51:04 +0000 Subject: Move request parsing related code to ActionController::RequestParser --- actionpack/test/controller/request_test.rb | 68 +++++++++++++++--------------- 1 file changed, 34 insertions(+), 34 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb index 3e10a4665e..349cea268f 100644 --- a/actionpack/test/controller/request_test.rb +++ b/actionpack/test/controller/request_test.rb @@ -424,95 +424,95 @@ class UrlEncodedRequestParameterParsingTest < ActiveSupport::TestCase def test_query_string assert_equal( { "action" => "create_customer", "full_name" => "David Heinemeier Hansson", "customerId" => "1"}, - ActionController::Request.parse_query_parameters(@query_string) + ActionController::RequestParser.parse_query_parameters(@query_string) ) end def test_deep_query_string expected = {'x' => {'y' => {'z' => '10'}}} - assert_equal(expected, ActionController::Request.parse_query_parameters('x[y][z]=10')) + assert_equal(expected, ActionController::RequestParser.parse_query_parameters('x[y][z]=10')) end def test_deep_query_string_with_array - assert_equal({'x' => {'y' => {'z' => ['10']}}}, ActionController::Request.parse_query_parameters('x[y][z][]=10')) - assert_equal({'x' => {'y' => {'z' => ['10', '5']}}}, ActionController::Request.parse_query_parameters('x[y][z][]=10&x[y][z][]=5')) + assert_equal({'x' => {'y' => {'z' => ['10']}}}, ActionController::RequestParser.parse_query_parameters('x[y][z][]=10')) + assert_equal({'x' => {'y' => {'z' => ['10', '5']}}}, ActionController::RequestParser.parse_query_parameters('x[y][z][]=10&x[y][z][]=5')) end def test_deep_query_string_with_array_of_hash - assert_equal({'x' => {'y' => [{'z' => '10'}]}}, ActionController::Request.parse_query_parameters('x[y][][z]=10')) - assert_equal({'x' => {'y' => [{'z' => '10', 'w' => '10'}]}}, ActionController::Request.parse_query_parameters('x[y][][z]=10&x[y][][w]=10')) + assert_equal({'x' => {'y' => [{'z' => '10'}]}}, ActionController::RequestParser.parse_query_parameters('x[y][][z]=10')) + assert_equal({'x' => {'y' => [{'z' => '10', 'w' => '10'}]}}, ActionController::RequestParser.parse_query_parameters('x[y][][z]=10&x[y][][w]=10')) end def test_deep_query_string_with_array_of_hashes_with_one_pair - assert_equal({'x' => {'y' => [{'z' => '10'}, {'z' => '20'}]}}, ActionController::Request.parse_query_parameters('x[y][][z]=10&x[y][][z]=20')) - assert_equal("10", ActionController::Request.parse_query_parameters('x[y][][z]=10&x[y][][z]=20')["x"]["y"].first["z"]) - assert_equal("10", ActionController::Request.parse_query_parameters('x[y][][z]=10&x[y][][z]=20').with_indifferent_access[:x][:y].first[:z]) + assert_equal({'x' => {'y' => [{'z' => '10'}, {'z' => '20'}]}}, ActionController::RequestParser.parse_query_parameters('x[y][][z]=10&x[y][][z]=20')) + assert_equal("10", ActionController::RequestParser.parse_query_parameters('x[y][][z]=10&x[y][][z]=20')["x"]["y"].first["z"]) + assert_equal("10", ActionController::RequestParser.parse_query_parameters('x[y][][z]=10&x[y][][z]=20').with_indifferent_access[:x][:y].first[:z]) end def test_deep_query_string_with_array_of_hashes_with_multiple_pairs assert_equal( {'x' => {'y' => [{'z' => '10', 'w' => 'a'}, {'z' => '20', 'w' => 'b'}]}}, - ActionController::Request.parse_query_parameters('x[y][][z]=10&x[y][][w]=a&x[y][][z]=20&x[y][][w]=b') + ActionController::RequestParser.parse_query_parameters('x[y][][z]=10&x[y][][w]=a&x[y][][z]=20&x[y][][w]=b') ) end def test_query_string_with_nil assert_equal( { "action" => "create_customer", "full_name" => ''}, - ActionController::Request.parse_query_parameters(@query_string_with_empty) + ActionController::RequestParser.parse_query_parameters(@query_string_with_empty) ) end def test_query_string_with_array assert_equal( { "action" => "create_customer", "selected" => ["1", "2", "3"]}, - ActionController::Request.parse_query_parameters(@query_string_with_array) + ActionController::RequestParser.parse_query_parameters(@query_string_with_array) ) end def test_query_string_with_amps assert_equal( { "action" => "create_customer", "name" => "Don't & Does"}, - ActionController::Request.parse_query_parameters(@query_string_with_amps) + ActionController::RequestParser.parse_query_parameters(@query_string_with_amps) ) end def test_query_string_with_many_equal assert_equal( { "action" => "create_customer", "full_name" => "abc=def=ghi"}, - ActionController::Request.parse_query_parameters(@query_string_with_many_equal) + ActionController::RequestParser.parse_query_parameters(@query_string_with_many_equal) ) end def test_query_string_without_equal assert_equal( { "action" => nil }, - ActionController::Request.parse_query_parameters(@query_string_without_equal) + ActionController::RequestParser.parse_query_parameters(@query_string_without_equal) ) end def test_query_string_with_empty_key assert_equal( { "action" => "create_customer", "full_name" => "David Heinemeier Hansson" }, - ActionController::Request.parse_query_parameters(@query_string_with_empty_key) + ActionController::RequestParser.parse_query_parameters(@query_string_with_empty_key) ) end def test_query_string_with_many_ampersands assert_equal( { "action" => "create_customer", "full_name" => "David Heinemeier Hansson"}, - ActionController::Request.parse_query_parameters(@query_string_with_many_ampersands) + ActionController::RequestParser.parse_query_parameters(@query_string_with_many_ampersands) ) end def test_unbalanced_query_string_with_array assert_equal( {'location' => ["1", "2"], 'age_group' => ["2"]}, - ActionController::Request.parse_query_parameters("location[]=1&location[]=2&age_group[]=2") + ActionController::RequestParser.parse_query_parameters("location[]=1&location[]=2&age_group[]=2") ) assert_equal( {'location' => ["1", "2"], 'age_group' => ["2"]}, - ActionController::Request.parse_request_parameters({'location[]' => ["1", "2"], + ActionController::RequestParser.parse_request_parameters({'location[]' => ["1", "2"], 'age_group[]' => ["2"]}) ) end @@ -525,7 +525,7 @@ class UrlEncodedRequestParameterParsingTest < ActiveSupport::TestCase expected = { "note" => { "viewers"=>{"viewer"=>[{ "id"=>"1", "type"=>"User"}, {"type"=>"Group", "id"=>"2"} ]} } } - assert_equal(expected, ActionController::Request.parse_request_parameters(query)) + assert_equal(expected, ActionController::RequestParser.parse_request_parameters(query)) end def test_parse_params @@ -564,7 +564,7 @@ class UrlEncodedRequestParameterParsingTest < ActiveSupport::TestCase } } - assert_equal expected_output, ActionController::Request.parse_request_parameters(input) + assert_equal expected_output, ActionController::RequestParser.parse_request_parameters(input) end UploadedStringIO = ActionController::UploadedStringIO @@ -619,7 +619,7 @@ class UrlEncodedRequestParameterParsingTest < ActiveSupport::TestCase "text_part" => "abc" } - params = ActionController::Request.parse_request_parameters(input) + params = ActionController::RequestParser.parse_request_parameters(input) assert_equal expected_output, params # Lone filenames are preserved. @@ -650,7 +650,7 @@ class UrlEncodedRequestParameterParsingTest < ActiveSupport::TestCase "logo" => File.new(File.dirname(__FILE__) + "/rack_test.rb").path, } - assert_equal expected_output, ActionController::Request.parse_request_parameters(input) + assert_equal expected_output, ActionController::RequestParser.parse_request_parameters(input) end def test_parse_params_with_array @@ -658,55 +658,55 @@ class UrlEncodedRequestParameterParsingTest < ActiveSupport::TestCase expected_output = { "selected" => [ "1", "2", "3" ] } - assert_equal expected_output, ActionController::Request.parse_request_parameters(input) + assert_equal expected_output, ActionController::RequestParser.parse_request_parameters(input) end def test_parse_params_with_non_alphanumeric_name input = { "a/b[c]" => %w(d) } expected = { "a/b" => { "c" => "d" }} - assert_equal expected, ActionController::Request.parse_request_parameters(input) + assert_equal expected, ActionController::RequestParser.parse_request_parameters(input) end def test_parse_params_with_single_brackets_in_middle input = { "a/b[c]d" => %w(e) } expected = { "a/b" => {} } - assert_equal expected, ActionController::Request.parse_request_parameters(input) + assert_equal expected, ActionController::RequestParser.parse_request_parameters(input) end def test_parse_params_with_separated_brackets input = { "a/b@[c]d[e]" => %w(f) } expected = { "a/b@" => { }} - assert_equal expected, ActionController::Request.parse_request_parameters(input) + assert_equal expected, ActionController::RequestParser.parse_request_parameters(input) end def test_parse_params_with_separated_brackets_and_array input = { "a/b@[c]d[e][]" => %w(f) } expected = { "a/b@" => { }} - assert_equal expected , ActionController::Request.parse_request_parameters(input) + assert_equal expected , ActionController::RequestParser.parse_request_parameters(input) end def test_parse_params_with_unmatched_brackets_and_array input = { "a/b@[c][d[e][]" => %w(f) } expected = { "a/b@" => { "c" => { }}} - assert_equal expected, ActionController::Request.parse_request_parameters(input) + assert_equal expected, ActionController::RequestParser.parse_request_parameters(input) end def test_parse_params_with_nil_key input = { nil => nil, "test2" => %w(value1) } expected = { "test2" => "value1" } - assert_equal expected, ActionController::Request.parse_request_parameters(input) + assert_equal expected, ActionController::RequestParser.parse_request_parameters(input) end def test_parse_params_with_array_prefix_and_hashes input = { "a[][b][c]" => %w(d) } expected = {"a" => [{"b" => {"c" => "d"}}]} - assert_equal expected, ActionController::Request.parse_request_parameters(input) + assert_equal expected, ActionController::RequestParser.parse_request_parameters(input) end def test_parse_params_with_complex_nesting input = { "a[][b][c][][d][]" => %w(e) } expected = {"a" => [{"b" => {"c" => [{"d" => ["e"]}]}}]} - assert_equal expected, ActionController::Request.parse_request_parameters(input) + assert_equal expected, ActionController::RequestParser.parse_request_parameters(input) end end @@ -768,7 +768,7 @@ class MultipartRequestParameterParsingTest < ActiveSupport::TestCase # Ensures that parse_multipart_form_parameters works with streams that cannot be rewound file = File.open(File.join(FIXTURE_PATH, 'large_text_file'), 'rb') file.expects(:rewind).raises(Errno::ESPIPE) - params = ActionController::Request.parse_multipart_form_parameters(file, 'AaB03x', file.stat.size, {}) + params = ActionController::RequestParser.parse_multipart_form_parameters(file, 'AaB03x', file.stat.size, {}) assert_not_equal 0, file.pos # file was not rewound after reading end end @@ -807,7 +807,7 @@ class MultipartRequestParameterParsingTest < ActiveSupport::TestCase private def parse_multipart(name) File.open(File.join(FIXTURE_PATH, name), 'rb') do |file| - params = ActionController::Request.parse_multipart_form_parameters(file, 'AaB03x', file.stat.size, {}) + params = ActionController::RequestParser.parse_multipart_form_parameters(file, 'AaB03x', file.stat.size, {}) assert_equal 0, file.pos # file was rewound after reading params end -- cgit v1.2.3 From 6e2a771661a47fb682108648244837f8616e350d Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Thu, 25 Dec 2008 17:54:44 +0000 Subject: Undry ActionController::TestCase# for better documentation --- actionpack/test/controller/caching_test.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index e24bb00bc7..7f8e47ba58 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -121,8 +121,7 @@ class PageCachingTest < ActionController::TestCase [:get, :post, :put, :delete].each do |method| unless method == :get and status == :ok define_method "test_shouldnt_cache_#{method}_with_#{status}_status" do - @request.env['REQUEST_METHOD'] = method.to_s.upcase - process status + send(method, status) assert_response status assert_page_not_cached status, "#{method} with #{status} status shouldn't have been cached" end -- cgit v1.2.3 From 04a8b2362deb37f33c0a9060510f194286b6822a Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Thu, 25 Dec 2008 19:28:08 +0000 Subject: Make render_test.rb run in isolation --- actionpack/test/controller/render_test.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 8e08a5a8e9..57827aaab7 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -21,6 +21,8 @@ class MockLogger end class TestController < ActionController::Base + protect_from_forgery + class LabellingFormBuilder < ActionView::Helpers::FormBuilder end -- cgit v1.2.3 From 061952392afd1dae1aa97a816e9a0c79df7c4514 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Thu, 25 Dec 2008 21:27:56 +0000 Subject: Make ActionController#render(string) work as a shortcut for render :file => string. [#1435] Examples: # Instead of render(:file => '/Users/lifo/home.html.erb') render('/Users/lifo/home.html.erb') Note : Filename must begin with a forward slash ('/') --- actionpack/test/controller/render_test.rb | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 57827aaab7..f2393e695a 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -104,6 +104,12 @@ class TestController < ActionController::Base render :file => path end + def render_file_as_string_with_instance_variables + @secret = 'in the sauce' + path = File.expand_path(File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb')) + render path + end + def render_file_not_using_full_path @secret = 'in the sauce' render :file => 'test/render_file_with_ivar' @@ -124,6 +130,11 @@ class TestController < ActionController::Base render :file => path, :locals => {:secret => 'in the sauce'} end + def render_file_as_string_with_locals + path = File.expand_path(File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_locals.erb')) + render path, :locals => {:secret => 'in the sauce'} + end + def accessing_request_in_template render :inline => "Hello: <%= request.host %>" end @@ -182,10 +193,6 @@ class TestController < ActionController::Base render :text => "appended" end - def render_invalid_args - render("test/hello") - end - def render_vanilla_js_hello render :js => "alert('hello')" end @@ -751,6 +758,11 @@ class RenderTest < ActionController::TestCase assert_equal "The secret is in the sauce\n", @response.body end + def test_render_file_as_string_with_instance_variables + get :render_file_as_string_with_instance_variables + assert_equal "The secret is in the sauce\n", @response.body + end + def test_render_file_not_using_full_path get :render_file_not_using_full_path assert_equal "The secret is in the sauce\n", @response.body @@ -766,6 +778,11 @@ class RenderTest < ActionController::TestCase assert_equal "The secret is in the sauce\n", @response.body end + def test_render_file_as_string_with_locals + get :render_file_as_string_with_locals + assert_equal "The secret is in the sauce\n", @response.body + end + def test_render_file_from_template get :render_file_from_template assert_equal "The secret is in the sauce\n", @response.body @@ -831,10 +848,6 @@ class RenderTest < ActionController::TestCase assert_equal 'appended', @response.body end - def test_attempt_to_render_with_invalid_arguments - assert_raises(ActionController::RenderError) { get :render_invalid_args } - end - def test_attempt_to_access_object_method assert_raises(ActionController::UnknownAction, "No action responded to [clone]") { get :clone } end -- cgit v1.2.3 From d67e03871eabb912434dafac3eeb8e6ea7c5585f Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Thu, 25 Dec 2008 22:11:06 +0000 Subject: Make ActionController#render(string) work as a shortcut for render :template => string. [#1435] Examples: # Instead of render(:template => 'controller/action') render('controller/action') Note : Argument must not begin with a '/', but have at least one '/' --- actionpack/test/controller/render_test.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index f2393e695a..ce9756a060 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -202,6 +202,11 @@ class TestController < ActionController::Base render :template => "test/hello" end + def render_xml_hello_as_string_template + @name = "David" + render "test/hello" + end + def render_xml_with_custom_content_type render :xml => "", :content_type => "application/atomsvc+xml" end @@ -332,6 +337,10 @@ class TestController < ActionController::Base render :template => "test/hello_world" end + def render_with_explicit_string_template + render "test/hello_world" + end + def render_with_explicit_template_with_locals render :template => "test/render_file_with_locals", :locals => { :secret => 'area51' } end @@ -654,6 +663,7 @@ class TestController < ActionController::Base "accessing_params_in_template", "accessing_params_in_template_with_layout", "render_with_explicit_template", + "render_with_explicit_string_template", "render_js_with_explicit_template", "render_js_with_explicit_action_template", "delete_with_js", "update_page", "update_page_with_instance_variables" @@ -888,6 +898,12 @@ class RenderTest < ActionController::TestCase assert_equal "application/xml", @response.content_type end + def test_render_xml_as_string_template + get :render_xml_hello_as_string_template + assert_equal "\n

Hello David

\n

This is grand!

\n\n", @response.body + assert_equal "application/xml", @response.content_type + end + def test_render_xml_with_default get :greeting assert_equal "

This is grand!

\n", @response.body @@ -1073,6 +1089,11 @@ class RenderTest < ActionController::TestCase assert_response :success end + def test_render_with_explicit_string_template + get :render_with_explicit_string_template + assert_equal "Hello world!", @response.body + end + def test_double_render assert_raises(ActionController::DoubleRenderError) { get :double_render } end -- cgit v1.2.3 From cd1d6e8768ae13b11bc343701037b20ad35e6f1e Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Thu, 25 Dec 2008 23:01:17 +0000 Subject: Make ActionController#render(string) work as a shortcut for render :action => string. [#1435] Examples: # Instead of render(:action => 'other_action') render('other_action') Note : Argument must not have any '/' --- actionpack/test/controller/render_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index ce9756a060..d097cf496f 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -81,6 +81,10 @@ class TestController < ActionController::Base render :action => "hello_world" end + def render_action_hello_world_as_string + render "hello_world" + end + def render_action_hello_world_with_symbol render :action => :hello_world end @@ -296,6 +300,10 @@ class TestController < ActionController::Base render :action => "hello_world", :layout => "standard" end + def layout_test_with_different_layout_and_string_action + render "hello_world", :layout => "standard" + end + def rendering_without_layout render :action => "hello_world", :layout => false end @@ -743,6 +751,12 @@ class RenderTest < ActionController::TestCase assert_template "test/hello_world" end + def test_render_action_hello_world_as_string + get :render_action_hello_world_as_string + assert_equal "Hello world!", @response.body + assert_template "test/hello_world" + end + def test_render_action_with_symbol get :render_action_hello_world_with_symbol assert_template "test/hello_world" @@ -1043,6 +1057,11 @@ class RenderTest < ActionController::TestCase assert_equal "Hello world!", @response.body end + def test_layout_test_with_different_layout + get :layout_test_with_different_layout_and_string_action + assert_equal "Hello world!", @response.body + end + def test_rendering_without_layout get :rendering_without_layout assert_equal "Hello world!", @response.body -- cgit v1.2.3 From 80307c8b0a889acc7abb7f4e52fd4c02e1063ba8 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Fri, 26 Dec 2008 01:03:18 +0000 Subject: Make ActionController#render(symbol) behave same as ActionController#render(string) [#1435] --- actionpack/test/controller/render_test.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index d097cf496f..5fd41d8eec 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -304,6 +304,10 @@ class TestController < ActionController::Base render "hello_world", :layout => "standard" end + def layout_test_with_different_layout_and_symbol_action + render :hello_world, :layout => "standard" + end + def rendering_without_layout render :action => "hello_world", :layout => false end @@ -1057,11 +1061,16 @@ class RenderTest < ActionController::TestCase assert_equal "Hello world!", @response.body end - def test_layout_test_with_different_layout + def test_layout_test_with_different_layout_and_string_action get :layout_test_with_different_layout_and_string_action assert_equal "Hello world!", @response.body end + def test_layout_test_with_different_layout_and_symbol_action + get :layout_test_with_different_layout_and_symbol_action + assert_equal "Hello world!", @response.body + end + def test_rendering_without_layout get :rendering_without_layout assert_equal "Hello world!", @response.body -- cgit v1.2.3 From d7b6e48c70076a7760e22c381e48834ecddfa6e3 Mon Sep 17 00:00:00 2001 From: Frederick Cheung Date: Thu, 25 Dec 2008 12:10:28 +0000 Subject: Fix randomly failing cookie store tests Marshal.dump(Marshal.load(marshaled_hash)) is not guarenteed to be equal to marshaled_hash because of the lack of ordering of hash --- actionpack/test/controller/session/cookie_store_test.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/session/cookie_store_test.rb b/actionpack/test/controller/session/cookie_store_test.rb index 69aec59dc0..d349c18d1d 100644 --- a/actionpack/test/controller/session/cookie_store_test.rb +++ b/actionpack/test/controller/session/cookie_store_test.rb @@ -25,7 +25,7 @@ class CookieStoreTest < ActionController::IntegrationTest def set_session_value session[:foo] = "bar" - render :text => Marshal.dump(session.to_hash) + render :text => Verifier.generate(session.to_hash) end def get_session_value @@ -94,8 +94,7 @@ class CookieStoreTest < ActionController::IntegrationTest with_test_route_set do get '/set_session_value' assert_response :success - session_payload = Verifier.generate(Marshal.load(response.body)) - assert_equal ["_myapp_session=#{session_payload}; path=/"], + assert_equal ["_myapp_session=#{response.body}; path=/"], headers['Set-Cookie'] end end @@ -148,8 +147,8 @@ class CookieStoreTest < ActionController::IntegrationTest with_test_route_set do get '/set_session_value' assert_response :success - session_payload = Verifier.generate(Marshal.load(response.body)) - assert_equal ["_myapp_session=#{session_payload}; path=/"], + session_payload = response.body + assert_equal ["_myapp_session=#{response.body}; path=/"], headers['Set-Cookie'] get '/call_reset_session' -- cgit v1.2.3 From dce0da77e7ef602f7420f43c0d1aba5a99a00bdb Mon Sep 17 00:00:00 2001 From: Frederick Cheung Date: Thu, 25 Dec 2008 11:11:00 +0000 Subject: Fix assert_select_rjs not checking id for inserts [#540 state:resolved] --- actionpack/test/controller/assert_select_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/assert_select_test.rb b/actionpack/test/controller/assert_select_test.rb index ed8c4427c9..99c57c0c91 100644 --- a/actionpack/test/controller/assert_select_test.rb +++ b/actionpack/test/controller/assert_select_test.rb @@ -248,6 +248,14 @@ class AssertSelectTest < ActionController::TestCase end end + def test_assert_select_rjs_for_positioned_insert_should_fail_when_mixing_arguments + render_rjs do |page| + page.insert_html :top, "test1", "
foo
" + page.insert_html :bottom, "test2", "
foo
" + end + assert_raises(Assertion) {assert_select_rjs :insert, :top, "test2"} + end + # # Test css_select. # -- cgit v1.2.3 From fdaa9ed0336634c33b5a529dfe4f5ed506a1fc5e Mon Sep 17 00:00:00 2001 From: Yaroslav Markin Date: Sat, 27 Dec 2008 20:28:28 +0300 Subject: Fix ActionPack build on Windows: we really should not test anything regarding symlinks on Windows. Signed-off-by: Pratik Naik --- actionpack/test/controller/layout_test.rb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb index 18c01f755c..c2efe9d00b 100644 --- a/actionpack/test/controller/layout_test.rb +++ b/actionpack/test/controller/layout_test.rb @@ -165,15 +165,17 @@ class LayoutStatusIsRenderedTest < ActionController::TestCase end end -class LayoutSymlinkedTest < LayoutTest - layout "symlinked/symlinked_layout" -end - -class LayoutSymlinkedIsRenderedTest < ActionController::TestCase - def test_symlinked_layout_is_rendered - @controller = LayoutSymlinkedTest.new - get :hello - assert_response 200 - assert_equal "layouts/symlinked/symlinked_layout", @response.layout +unless RUBY_PLATFORM =~ /(:?mswin|mingw|bccwin)/ + class LayoutSymlinkedTest < LayoutTest + layout "symlinked/symlinked_layout" + end + + class LayoutSymlinkedIsRenderedTest < ActionController::TestCase + def test_symlinked_layout_is_rendered + @controller = LayoutSymlinkedTest.new + get :hello + assert_response 200 + assert_equal "layouts/symlinked/symlinked_layout", @response.layout + end end end -- cgit v1.2.3 From 5138f755ff31a8f317d649a6f256c74bc371db70 Mon Sep 17 00:00:00 2001 From: Mark Reginald James Date: Sun, 28 Dec 2008 01:15:48 +0000 Subject: Fixed incorrect parsing of query parameters with mixed-depth nesting inside an array [#1622 state:resolved] Signed-off-by: Frederick Cheung --- actionpack/test/controller/request_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb index 349cea268f..c93d3152b8 100644 --- a/actionpack/test/controller/request_test.rb +++ b/actionpack/test/controller/request_test.rb @@ -441,6 +441,7 @@ class UrlEncodedRequestParameterParsingTest < ActiveSupport::TestCase def test_deep_query_string_with_array_of_hash assert_equal({'x' => {'y' => [{'z' => '10'}]}}, ActionController::RequestParser.parse_query_parameters('x[y][][z]=10')) assert_equal({'x' => {'y' => [{'z' => '10', 'w' => '10'}]}}, ActionController::RequestParser.parse_query_parameters('x[y][][z]=10&x[y][][w]=10')) + assert_equal({'x' => {'y' => [{'z' => '10', 'v' => {'w' => '10'}}]}}, ActionController::RequestParser.parse_query_parameters('x[y][][z]=10&x[y][][v][w]=10')) end def test_deep_query_string_with_array_of_hashes_with_one_pair -- cgit v1.2.3 From fec0ea9d6d4ca56a09e3e83002c38d69c8ad924e Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sun, 28 Dec 2008 17:05:12 +0000 Subject: Request#env['SERVER_NAME'] does not contain port number --- actionpack/test/controller/rack_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb index 406e2b2818..31bff4ae6d 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/controller/rack_test.rb @@ -4,7 +4,7 @@ class BaseRackTest < Test::Unit::TestCase def setup @env = { "HTTP_MAX_FORWARDS" => "10", - "SERVER_NAME" => "glu.ttono.us:8007", + "SERVER_NAME" => "glu.ttono.us", "FCGI_ROLE" => "RESPONDER", "AUTH_TYPE" => "Basic", "HTTP_X_FORWARDED_HOST" => "glu.ttono.us", @@ -145,7 +145,7 @@ class RackRequestTest < BaseRackTest assert_equal "kevin", @request.remote_user assert_equal :get, @request.request_method assert_equal "/dispatch.fcgi", @request.script_name - assert_equal "glu.ttono.us:8007", @request.server_name + assert_equal "glu.ttono.us", @request.server_name assert_equal 8007, @request.server_port assert_equal "HTTP/1.1", @request.server_protocol assert_equal "lighttpd", @request.server_software -- cgit v1.2.3 From 45dee3842d68359a189fe7c0729359bd5a905ea4 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 28 Dec 2008 15:13:16 -0600 Subject: HTTP Digest authentication [#1230 state:resolved] --- .../controller/http_digest_authentication_test.rb | 73 ++++++++++++++++++ actionpack/test/controller/integration_test.rb | 88 ++++++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 actionpack/test/controller/http_digest_authentication_test.rb (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/http_digest_authentication_test.rb b/actionpack/test/controller/http_digest_authentication_test.rb new file mode 100644 index 0000000000..d5c8636a9e --- /dev/null +++ b/actionpack/test/controller/http_digest_authentication_test.rb @@ -0,0 +1,73 @@ +require 'abstract_unit' + +class HttpDigestAuthenticationTest < Test::Unit::TestCase + include ActionController::HttpAuthentication::Digest + + class DummyController + attr_accessor :headers, :renders, :request, :response + + def initialize + @headers, @renders = {}, [] + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + request.session.session_id = "test_session" + end + + def render(options) + self.renderers << options + end + end + + def setup + @controller = DummyController.new + @credentials = { + :username => "dhh", + :realm => "testrealm@host.com", + :nonce => ActionController::HttpAuthentication::Digest.nonce(@controller.request), + :qop => "auth", + :nc => "00000001", + :cnonce => "0a4f113b", + :opaque => ActionController::HttpAuthentication::Digest.opaque(@controller.request), + :uri => "http://test.host/" + } + @encoded_credentials = ActionController::HttpAuthentication::Digest.encode_credentials("GET", @credentials, "secret") + end + + def test_decode_credentials + set_headers + assert_equal @credentials, decode_credentials(@controller.request) + end + + def test_nonce_format + assert_nothing_thrown do + validate_nonce(@controller.request, nonce(@controller.request)) + end + end + + def test_authenticate_should_raise_for_nil_password + set_headers ActionController::HttpAuthentication::Digest.encode_credentials(:get, @credentials, nil) + assert_raise ActionController::HttpAuthentication::Error do + authenticate(@controller, @credentials[:realm]) { |user| user == "dhh" && "secret" } + end + end + + def test_authenticate_should_raise_for_incorrect_password + set_headers + assert_raise ActionController::HttpAuthentication::Error do + authenticate(@controller, @credentials[:realm]) { |user| user == "dhh" && "bad password" } + end + end + + def test_authenticate_should_not_raise_for_correct_password + set_headers + assert_nothing_thrown do + authenticate(@controller, @credentials[:realm]) { |user| user == "dhh" && "secret" } + end + end + + private + def set_headers(value = @encoded_credentials, name = 'HTTP_AUTHORIZATION', method = "GET") + @controller.request.env[name] = value + @controller.request.env["REQUEST_METHOD"] = method + end +end diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index c28050fe0d..53cebf768e 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -8,7 +8,25 @@ class SessionTest < Test::Unit::TestCase } def setup + @credentials = { + :username => "username", + :realm => "MyApp", + :nonce => ActionController::HttpAuthentication::Digest.nonce("session_id"), + :qop => "auth", + :nc => "00000001", + :cnonce => "0a4f113b", + :opaque => ActionController::HttpAuthentication::Digest.opaque("session_id"), + :uri => "/index" + } + @session = ActionController::Integration::Session.new(StubApp) + @session.nonce = @credentials[:nonce] + @session.opaque = @credentials[:opaque] + @session.realm = @credentials[:realm] + end + + def encoded_credentials(method) + ActionController::HttpAuthentication::Digest.encode_credentials(method, @credentials, "password") end def test_https_bang_works_and_sets_truth_by_default @@ -132,6 +150,76 @@ class SessionTest < Test::Unit::TestCase @session.head(path,params,headers) end + def test_get_with_basic + path = "/index"; params = "blah"; headers = {:location => 'blah'} + expected_headers = headers.merge(:authorization => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=\n") + @session.expects(:process).with(:get,path,params,expected_headers) + @session.get_with_basic(path,params,headers,'username','password') + end + + def test_post_with_basic + path = "/index"; params = "blah"; headers = {:location => 'blah'} + expected_headers = headers.merge(:authorization => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=\n") + @session.expects(:process).with(:post,path,params,expected_headers) + @session.post_with_basic(path,params,headers,'username','password') + end + + def test_put_with_basic + path = "/index"; params = "blah"; headers = {:location => 'blah'} + expected_headers = headers.merge(:authorization => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=\n") + @session.expects(:process).with(:put,path,params,expected_headers) + @session.put_with_basic(path,params,headers,'username','password') + end + + def test_delete_with_basic + path = "/index"; params = "blah"; headers = {:location => 'blah'} + expected_headers = headers.merge(:authorization => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=\n") + @session.expects(:process).with(:delete,path,params,expected_headers) + @session.delete_with_basic(path,params,headers,'username','password') + end + + def test_head_with_basic + path = "/index"; params = "blah"; headers = {:location => 'blah'} + expected_headers = headers.merge(:authorization => "Basic dXNlcm5hbWU6cGFzc3dvcmQ=\n") + @session.expects(:process).with(:head,path,params,expected_headers) + @session.head_with_basic(path,params,headers,'username','password') + end + + def test_get_with_digest + path = "/index"; params = "blah"; headers = {:location => 'blah'} + expected_headers = headers.merge(:authorization => encoded_credentials(:get)) + @session.expects(:process).with(:get,path,params,expected_headers) + @session.get_with_digest(path,params,headers,'username','password') + end + + def test_post_with_digest + path = "/index"; params = "blah"; headers = {:location => 'blah'} + expected_headers = headers.merge(:authorization => encoded_credentials(:post)) + @session.expects(:process).with(:post,path,params,expected_headers) + @session.post_with_digest(path,params,headers,'username','password') + end + + def test_put_with_digest + path = "/index"; params = "blah"; headers = {:location => 'blah'} + expected_headers = headers.merge(:authorization => encoded_credentials(:put)) + @session.expects(:process).with(:put,path,params,expected_headers) + @session.put_with_digest(path,params,headers,'username','password') + end + + def test_delete_with_digest + path = "/index"; params = "blah"; headers = {:location => 'blah'} + expected_headers = headers.merge(:authorization => encoded_credentials(:delete)) + @session.expects(:process).with(:delete,path,params,expected_headers) + @session.delete_with_digest(path,params,headers,'username','password') + end + + def test_head_with_digest + path = "/index"; params = "blah"; headers = {:location => 'blah'} + expected_headers = headers.merge(:authorization => encoded_credentials(:head)) + @session.expects(:process).with(:head,path,params,expected_headers) + @session.head_with_digest(path,params,headers,'username','password') + end + def test_xml_http_request_get path = "/index"; params = "blah"; headers = {:location => 'blah'} headers_after_xhr = headers.merge( -- cgit v1.2.3 From 5d89605c11cc54acadfdd76ccd226d38989ec600 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 28 Dec 2008 15:31:03 -0600 Subject: Make router and controller classes better rack citizens --- actionpack/test/controller/dispatcher_test.rb | 4 +- actionpack/test/controller/rescue_test.rb | 6 +- actionpack/test/controller/routing_test.rb | 133 ++++++++++++-------------- 3 files changed, 66 insertions(+), 77 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb index fd06b4ea99..da87d26146 100644 --- a/actionpack/test/controller/dispatcher_test.rb +++ b/actionpack/test/controller/dispatcher_test.rb @@ -96,9 +96,7 @@ class DispatcherTest < Test::Unit::TestCase private def dispatch(cache_classes = true) - controller = mock() - controller.stubs(:process).returns([200, {}, 'response']) - ActionController::Routing::Routes.stubs(:recognize).returns(controller) + ActionController::Routing::RouteSet.any_instance.stubs(:call).returns([200, {}, 'response']) Dispatcher.define_dispatcher_callbacks(cache_classes) @dispatcher.call({}) end diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index 63f9827f4a..49aca3a6ee 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -367,7 +367,11 @@ class RescueControllerTest < ActionController::TestCase end def test_rescue_dispatcher_exceptions - RescueController.process_with_exception(@request, @response, ActionController::RoutingError.new("Route not found")) + env = @request.env + env["actioncontroller.rescue.request"] = @request + env["actioncontroller.rescue.response"] = @response + + RescueController.call_with_exception(env, ActionController::RoutingError.new("Route not found")) assert_equal "no way", @response.body end diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index d5b6bd6b2a..b981119e1e 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -706,7 +706,7 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do port_string = port == 80 ? '' : ":#{port}" protocol = options.delete(:protocol) || "http" - host = options.delete(:host) || "named.route.test" + host = options.delete(:host) || "test.host" anchor = "##{options.delete(:anchor)}" if options.key?(:anchor) path = routes.generate(options) @@ -715,27 +715,7 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do end def request - @request ||= MockRequest.new(:host => "named.route.test", :method => :get) - end - end - - class MockRequest - attr_accessor :path, :path_parameters, :host, :subdomains, :domain, :method - - def initialize(values={}) - values.each { |key, value| send("#{key}=", value) } - if values[:host] - subdomain, self.domain = values[:host].split(/\./, 2) - self.subdomains = [subdomain] - end - end - - def protocol - "http://" - end - - def host_with_port - (subdomains * '.') + '.' + domain + @request ||= ActionController::TestRequest.new end end @@ -900,7 +880,7 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do def test_basic_named_route rs.add_named_route :home, '', :controller => 'content', :action => 'list' x = setup_for_named_route - assert_equal("http://named.route.test/", + assert_equal("http://test.host/", x.send(:home_url)) end @@ -908,7 +888,7 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do rs.add_named_route :home, '', :controller => 'content', :action => 'list' x = setup_for_named_route ActionController::Base.relative_url_root = "/foo" - assert_equal("http://named.route.test/foo/", + assert_equal("http://test.host/foo/", x.send(:home_url)) assert_equal "/foo/", x.send(:home_path) ActionController::Base.relative_url_root = nil @@ -917,14 +897,14 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do def test_named_route_with_option rs.add_named_route :page, 'page/:title', :controller => 'content', :action => 'show_page' x = setup_for_named_route - assert_equal("http://named.route.test/page/new%20stuff", + assert_equal("http://test.host/page/new%20stuff", x.send(:page_url, :title => 'new stuff')) end def test_named_route_with_default rs.add_named_route :page, 'page/:title', :controller => 'content', :action => 'show_page', :title => 'AboutPage' x = setup_for_named_route - assert_equal("http://named.route.test/page/AboutRails", + assert_equal("http://test.host/page/AboutRails", x.send(:page_url, :title => "AboutRails")) end @@ -932,21 +912,21 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do def test_named_route_with_name_prefix rs.add_named_route :page, 'page', :controller => 'content', :action => 'show_page', :name_prefix => 'my_' x = setup_for_named_route - assert_equal("http://named.route.test/page", + assert_equal("http://test.host/page", x.send(:my_page_url)) end def test_named_route_with_path_prefix rs.add_named_route :page, 'page', :controller => 'content', :action => 'show_page', :path_prefix => 'my' x = setup_for_named_route - assert_equal("http://named.route.test/my/page", + assert_equal("http://test.host/my/page", x.send(:page_url)) end def test_named_route_with_nested_controller rs.add_named_route :users, 'admin/user', :controller => 'admin/user', :action => 'index' x = setup_for_named_route - assert_equal("http://named.route.test/admin/user", + assert_equal("http://test.host/admin/user", x.send(:users_url)) end @@ -985,7 +965,7 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do map.root :controller => "hello" end x = setup_for_named_route - assert_equal("http://named.route.test/", x.send(:root_url)) + assert_equal("http://test.host/", x.send(:root_url)) assert_equal("/", x.send(:root_path)) end @@ -1001,7 +981,7 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do # x.send(:article_url, :title => 'hi') # ) assert_equal( - "http://named.route.test/page/2005/6/10/hi", + "http://test.host/page/2005/6/10/hi", x.send(:article_url, :title => 'hi', :day => 10, :year => 2005, :month => 6) ) end @@ -1202,7 +1182,7 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do assert_equal '/test', rs.generate(:controller => 'post', :action => 'show', :year => nil) x = setup_for_named_route - assert_equal("http://named.route.test/test", + assert_equal("http://test.host/test", x.send(:blog_url)) end @@ -1249,7 +1229,7 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do assert_equal '/', rs.generate(:controller => 'content') x = setup_for_named_route - assert_equal("http://named.route.test/", + assert_equal("http://test.host/", x.send(:home_url)) end @@ -1591,7 +1571,7 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do end def request - @request ||= MockRequest.new(:host => "named.routes.test", :method => :get) + @request ||= ActionController::TestRequest.new end def test_generate_extras @@ -1692,13 +1672,13 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do def test_named_route_url_method controller = setup_named_route_test - assert_equal "http://named.route.test/people/5", controller.send(:show_url, :id => 5) + assert_equal "http://test.host/people/5", controller.send(:show_url, :id => 5) assert_equal "/people/5", controller.send(:show_path, :id => 5) - assert_equal "http://named.route.test/people", controller.send(:index_url) + assert_equal "http://test.host/people", controller.send(:index_url) assert_equal "/people", controller.send(:index_path) - assert_equal "http://named.route.test/admin/users", controller.send(:users_url) + assert_equal "http://test.host/admin/users", controller.send(:users_url) assert_equal '/admin/users', controller.send(:users_path) assert_equal '/admin/users', set.generate(controller.send(:hash_for_users_url), {:controller => 'users', :action => 'index'}) end @@ -1706,28 +1686,28 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do def test_named_route_url_method_with_anchor controller = setup_named_route_test - assert_equal "http://named.route.test/people/5#location", controller.send(:show_url, :id => 5, :anchor => 'location') + assert_equal "http://test.host/people/5#location", controller.send(:show_url, :id => 5, :anchor => 'location') assert_equal "/people/5#location", controller.send(:show_path, :id => 5, :anchor => 'location') - assert_equal "http://named.route.test/people#location", controller.send(:index_url, :anchor => 'location') + assert_equal "http://test.host/people#location", controller.send(:index_url, :anchor => 'location') assert_equal "/people#location", controller.send(:index_path, :anchor => 'location') - assert_equal "http://named.route.test/admin/users#location", controller.send(:users_url, :anchor => 'location') + assert_equal "http://test.host/admin/users#location", controller.send(:users_url, :anchor => 'location') assert_equal '/admin/users#location', controller.send(:users_path, :anchor => 'location') - assert_equal "http://named.route.test/people/go/7/hello/joe/5#location", + assert_equal "http://test.host/people/go/7/hello/joe/5#location", controller.send(:multi_url, 7, "hello", 5, :anchor => 'location') - assert_equal "http://named.route.test/people/go/7/hello/joe/5?baz=bar#location", + assert_equal "http://test.host/people/go/7/hello/joe/5?baz=bar#location", controller.send(:multi_url, 7, "hello", 5, :baz => "bar", :anchor => 'location') - assert_equal "http://named.route.test/people?baz=bar#location", + assert_equal "http://test.host/people?baz=bar#location", controller.send(:index_url, :baz => "bar", :anchor => 'location') end def test_named_route_url_method_with_port controller = setup_named_route_test - assert_equal "http://named.route.test:8080/people/5", controller.send(:show_url, 5, :port=>8080) + assert_equal "http://test.host:8080/people/5", controller.send(:show_url, 5, :port=>8080) end def test_named_route_url_method_with_host @@ -1737,30 +1717,30 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do def test_named_route_url_method_with_protocol controller = setup_named_route_test - assert_equal "https://named.route.test/people/5", controller.send(:show_url, 5, :protocol => "https") + assert_equal "https://test.host/people/5", controller.send(:show_url, 5, :protocol => "https") end def test_named_route_url_method_with_ordered_parameters controller = setup_named_route_test - assert_equal "http://named.route.test/people/go/7/hello/joe/5", + assert_equal "http://test.host/people/go/7/hello/joe/5", controller.send(:multi_url, 7, "hello", 5) end def test_named_route_url_method_with_ordered_parameters_and_hash controller = setup_named_route_test - assert_equal "http://named.route.test/people/go/7/hello/joe/5?baz=bar", + assert_equal "http://test.host/people/go/7/hello/joe/5?baz=bar", controller.send(:multi_url, 7, "hello", 5, :baz => "bar") end def test_named_route_url_method_with_ordered_parameters_and_empty_hash controller = setup_named_route_test - assert_equal "http://named.route.test/people/go/7/hello/joe/5", + assert_equal "http://test.host/people/go/7/hello/joe/5", controller.send(:multi_url, 7, "hello", 5, {}) end def test_named_route_url_method_with_no_positional_arguments controller = setup_named_route_test - assert_equal "http://named.route.test/people?baz=bar", + assert_equal "http://test.host/people?baz=bar", controller.send(:index_url, :baz => "bar") end @@ -1896,49 +1876,54 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do end request.path = "/people" - request.method = :get + request.env["REQUEST_METHOD"] = "GET" assert_nothing_raised { set.recognize(request) } assert_equal("index", request.path_parameters[:action]) + request.recycle! - request.method = :post + request.env["REQUEST_METHOD"] = "POST" assert_nothing_raised { set.recognize(request) } assert_equal("create", request.path_parameters[:action]) + request.recycle! - request.method = :put + request.env["REQUEST_METHOD"] = "PUT" assert_nothing_raised { set.recognize(request) } assert_equal("update", request.path_parameters[:action]) + request.recycle! - begin - request.method = :bacon + assert_raises(ActionController::UnknownHttpMethod) { + request.env["REQUEST_METHOD"] = "BACON" set.recognize(request) - flunk 'Should have raised NotImplemented' - rescue ActionController::NotImplemented => e - assert_equal [:get, :post, :put, :delete], e.allowed_methods - end + } + request.recycle! request.path = "/people/5" - request.method = :get + request.env["REQUEST_METHOD"] = "GET" assert_nothing_raised { set.recognize(request) } assert_equal("show", request.path_parameters[:action]) assert_equal("5", request.path_parameters[:id]) + request.recycle! - request.method = :put + request.env["REQUEST_METHOD"] = "PUT" assert_nothing_raised { set.recognize(request) } assert_equal("update", request.path_parameters[:action]) assert_equal("5", request.path_parameters[:id]) + request.recycle! - request.method = :delete + request.env["REQUEST_METHOD"] = "DELETE" assert_nothing_raised { set.recognize(request) } assert_equal("destroy", request.path_parameters[:action]) assert_equal("5", request.path_parameters[:id]) + request.recycle! begin - request.method = :post + request.env["REQUEST_METHOD"] = "POST" set.recognize(request) flunk 'Should have raised MethodNotAllowed' rescue ActionController::MethodNotAllowed => e assert_equal [:get, :put, :delete], e.allowed_methods end + request.recycle! ensure Object.send(:remove_const, :PeopleController) @@ -1954,13 +1939,13 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do end request.path = "/people" - request.method = :get + request.env["REQUEST_METHOD"] = "GET" assert_nothing_raised { set.recognize(request) } assert_equal("people", request.path_parameters[:controller]) assert_equal("index", request.path_parameters[:action]) request.path = "/" - request.method = :get + request.env["REQUEST_METHOD"] = "GET" assert_nothing_raised { set.recognize(request) } assert_equal("people", request.path_parameters[:controller]) assert_equal("index", request.path_parameters[:action]) @@ -1978,7 +1963,7 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do end request.path = "/articles/2005/11/05/a-very-interesting-article" - request.method = :get + request.env["REQUEST_METHOD"] = "GET" assert_nothing_raised { set.recognize(request) } assert_equal("permalink", request.path_parameters[:action]) assert_equal("2005", request.path_parameters[:year]) @@ -2015,17 +2000,19 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do end request.path = "/people/5" - request.method = :get + request.env["REQUEST_METHOD"] = "GET" assert_nothing_raised { set.recognize(request) } assert_equal("show", request.path_parameters[:action]) assert_equal("5", request.path_parameters[:id]) + request.recycle! - request.method = :put + request.env["REQUEST_METHOD"] = "PUT" assert_nothing_raised { set.recognize(request) } assert_equal("update", request.path_parameters[:action]) + request.recycle! request.path = "/people/5.png" - request.method = :get + request.env["REQUEST_METHOD"] = "GET" assert_nothing_raised { set.recognize(request) } assert_equal("show", request.path_parameters[:action]) assert_equal("5", request.path_parameters[:id]) @@ -2050,7 +2037,7 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do set.draw { |map| map.root :controller => "people" } request.path = "" - request.method = :get + request.env["REQUEST_METHOD"] = "GET" assert_nothing_raised { set.recognize(request) } assert_equal("people", request.path_parameters[:controller]) assert_equal("index", request.path_parameters[:action]) @@ -2070,7 +2057,7 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do end request.path = "/api/inventory" - request.method = :get + request.env["REQUEST_METHOD"] = "GET" assert_nothing_raised { set.recognize(request) } assert_equal("api/products", request.path_parameters[:controller]) assert_equal("inventory", request.path_parameters[:action]) @@ -2090,7 +2077,7 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do end request.path = "/api" - request.method = :get + request.env["REQUEST_METHOD"] = "GET" assert_nothing_raised { set.recognize(request) } assert_equal("api/products", request.path_parameters[:controller]) assert_equal("index", request.path_parameters[:action]) @@ -2110,7 +2097,7 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do end request.path = "/prefix/inventory" - request.method = :get + request.env["REQUEST_METHOD"] = "GET" assert_nothing_raised { set.recognize(request) } assert_equal("api/products", request.path_parameters[:controller]) assert_equal("inventory", request.path_parameters[:action]) @@ -2246,7 +2233,7 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do end request.path = "/projects/1/milestones" - request.method = :get + request.env["REQUEST_METHOD"] = "GET" assert_nothing_raised { set.recognize(request) } assert_equal("milestones", request.path_parameters[:controller]) assert_equal("index", request.path_parameters[:action]) -- cgit v1.2.3 From 2e1132fad8fa2ab58476b9ecc30523ed02a43181 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 30 Dec 2008 18:06:56 -0800 Subject: Test that exceptions raised in filters are properly rescued --- actionpack/test/controller/rescue_test.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index 49aca3a6ee..d45ba3c3a1 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -67,6 +67,11 @@ class RescueController < ActionController::Base render :text => 'no way' end + before_filter(:only => :before_filter_raises) { raise 'umm nice' } + + def before_filter_raises + end + def raises render :text => 'already rendered' raise "don't panic!" @@ -154,6 +159,16 @@ class RescueControllerTest < ActionController::TestCase end end + def test_rescue_exceptions_raised_by_filters + with_rails_root FIXTURE_PUBLIC do + with_all_requests_local false do + get :before_filter_raises + end + end + + assert_response :internal_server_error + end + def test_rescue_action_locally_if_all_requests_local @controller.expects(:local_request?).never @controller.expects(:rescue_action_locally).with(@exception) -- cgit v1.2.3 From 606176a55b90c27687ae17f40fd1af0a86b62246 Mon Sep 17 00:00:00 2001 From: Laszlo Bacsi Date: Fri, 2 Jan 2009 10:46:48 -0600 Subject: Fixed call_with_exception for Routing Errors [#1684 state:resolved] Signed-off-by: Joshua Peek --- actionpack/test/controller/rescue_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index d45ba3c3a1..8728c9fca3 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -390,6 +390,13 @@ class RescueControllerTest < ActionController::TestCase assert_equal "no way", @response.body end + def test_rescue_dispatcher_exceptions_without_request_set + @request.env['REQUEST_URI'] = '/no_way' + response = RescueController.call_with_exception(@request.env, ActionController::RoutingError.new("Route not found")) + assert_kind_of ActionController::Response, response + assert_equal "no way", response.body + end + protected def with_all_requests_local(local = true) old_local, ActionController::Base.consider_all_requests_local = -- cgit v1.2.3 From 104898fcb7958bcb69ba0239d6de8aa37f2da9ba Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 2 Jan 2009 13:40:23 -0600 Subject: Revert to the good old days when AssetTag didn't cause anyone problems --- actionpack/test/controller/dispatcher_test.rb | 5 ----- 1 file changed, 5 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb index da87d26146..7cd4e71aa1 100644 --- a/actionpack/test/controller/dispatcher_test.rb +++ b/actionpack/test/controller/dispatcher_test.rb @@ -32,11 +32,6 @@ class DispatcherTest < Test::Unit::TestCase dispatch(false) end - def test_clears_asset_tag_cache_before_dispatch_if_in_loading_mode - ActionView::Helpers::AssetTagHelper::AssetTag::Cache.expects(:clear).once - dispatch(false) - end - def test_leaves_dependencies_after_dispatch_if_not_in_loading_mode ActionController::Routing::Routes.expects(:reload).never ActiveSupport::Dependencies.expects(:clear).never -- cgit v1.2.3 From f7ee082bb3cde977a199b81207e5d12e1d7101b3 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 2 Jan 2009 18:46:01 -0600 Subject: Add failing test for file uploads with unrewindable input --- .../test/controller/integration_upload_test.rb | 46 +++++++++++++++++----- 1 file changed, 36 insertions(+), 10 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/integration_upload_test.rb b/actionpack/test/controller/integration_upload_test.rb index 39d2e164e4..d579980c19 100644 --- a/actionpack/test/controller/integration_upload_test.rb +++ b/actionpack/test/controller/integration_upload_test.rb @@ -10,6 +10,10 @@ class UploadTestController < ActionController::Base SessionUploadTest.last_request_type = ActionController::Base.param_parsers[request.content_type] render :text => "got here" end + + def read + render :text => "File: #{params[:uploaded_data].read}" + end end class SessionUploadTest < ActionController::IntegrationTest @@ -19,21 +23,43 @@ class SessionUploadTest < ActionController::IntegrationTest attr_accessor :last_request_type end - # def setup - # @session = ActionController::Integration::Session.new - # end - def test_post_with_upload - uses_mocha "test_post_with_upload" do - ActiveSupport::Dependencies.stubs(:load?).returns(false) + def test_upload_and_read_file + with_test_routing do + post '/read', :uploaded_data => fixture_file_upload(FILES_DIR + "/hello.txt", "text/plain") + assert_equal "File: Hello", response.body + end + end + + # The lint wrapper is used in integration tests + # instead of a normal StringIO class + InputWrapper = Rack::Lint::InputWrapper + + def test_post_with_upload_with_unrewindable_input + InputWrapper.any_instance.expects(:rewind).raises(Errno::ESPIPE) + + with_test_routing do + post '/read', :uploaded_data => fixture_file_upload(FILES_DIR + "/hello.txt", "text/plain") + assert_equal "File: Hello", response.body + end + end + + def test_post_with_upload_with_params_parsing + with_test_routing do + params = { :uploaded_data => fixture_file_upload(FILES_DIR + "/mona_lisa.jpg", "image/jpg") } + post '/update', params, :location => 'blah' + assert_equal(:multipart_form, SessionUploadTest.last_request_type) + end + end + + private + def with_test_routing with_routing do |set| set.draw do |map| map.update 'update', :controller => "upload_test", :action => "update", :method => :post + map.read 'read', :controller => "upload_test", :action => "read", :method => :post end - params = { :uploaded_data => fixture_file_upload(FILES_DIR + "/mona_lisa.jpg", "image/jpg") } - post '/update', params, :location => 'blah' - assert_equal(:multipart_form, SessionUploadTest.last_request_type) + yield end end - end end -- cgit v1.2.3 From ed2e776bdec3f0764433a6dc4f592f9bebfea859 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 3 Jan 2009 23:02:29 -0600 Subject: Move metal above method piggybacking middleware and add some test coverage --- .../test/controller/middleware_stack_test.rb | 70 ++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 actionpack/test/controller/middleware_stack_test.rb (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/middleware_stack_test.rb b/actionpack/test/controller/middleware_stack_test.rb new file mode 100644 index 0000000000..5029f5f609 --- /dev/null +++ b/actionpack/test/controller/middleware_stack_test.rb @@ -0,0 +1,70 @@ +require 'abstract_unit' + +class MiddlewareStackTest < ActiveSupport::TestCase + class FooMiddleware; end + class BarMiddleware; end + class BazMiddleware; end + + def setup + @stack = ActionController::MiddlewareStack.new + @stack.use FooMiddleware + @stack.use BarMiddleware + end + + test "use should push middleware as class onto the stack" do + assert_difference "@stack.size" do + @stack.use BazMiddleware + end + assert_equal BazMiddleware, @stack.last.klass + end + + test "use should push middleware as a string onto the stack" do + assert_difference "@stack.size" do + @stack.use "MiddlewareStackTest::BazMiddleware" + end + assert_equal BazMiddleware, @stack.last.klass + end + + test "use should push middleware as a symbol onto the stack" do + assert_difference "@stack.size" do + @stack.use :"MiddlewareStackTest::BazMiddleware" + end + assert_equal BazMiddleware, @stack.last.klass + end + + test "use should push middleware class with arguments onto the stack" do + assert_difference "@stack.size" do + @stack.use BazMiddleware, true, :foo => "bar" + end + assert_equal BazMiddleware, @stack.last.klass + assert_equal([true, {:foo => "bar"}], @stack.last.args) + end + + test "insert inserts middleware at the integer index" do + @stack.insert(1, BazMiddleware) + assert_equal BazMiddleware, @stack[1].klass + end + + test "insert_after inserts middleware after the integer index" do + @stack.insert_after(1, BazMiddleware) + assert_equal BazMiddleware, @stack[2].klass + end + + test "insert_before inserts middleware before another middleware class" do + @stack.insert_before(BarMiddleware, BazMiddleware) + assert_equal BazMiddleware, @stack[1].klass + end + + test "insert_after inserts middleware after another middleware class" do + @stack.insert_after(BarMiddleware, BazMiddleware) + assert_equal BazMiddleware, @stack[2].klass + end + + test "active returns all only enabled middleware" do + assert_no_difference "@stack.active.size" do + assert_difference "@stack.size" do + @stack.use BazMiddleware, :if => lambda { false } + end + end + end +end -- cgit v1.2.3 From f00e86d7e9c7a4689a49fc085bcb757c5a2c0b03 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 4 Jan 2009 12:15:15 -0600 Subject: Memoize request accessors on the Rack env so other request objects have access to the same cache [#1668 state:resolved] --- actionpack/test/controller/request_test.rb | 4 ++-- actionpack/test/controller/rescue_test.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb index c93d3152b8..02bb2ee890 100644 --- a/actionpack/test/controller/request_test.rb +++ b/actionpack/test/controller/request_test.rb @@ -391,8 +391,8 @@ class RequestTest < ActiveSupport::TestCase end def test_parameters - @request.instance_eval { @request_parameters = { "foo" => 1 } } - @request.instance_eval { @query_parameters = { "bar" => 2 } } + @request.stubs(:request_parameters).returns({ "foo" => 1 }) + @request.stubs(:query_parameters).returns({ "bar" => 2 }) assert_equal({"foo" => 1, "bar" => 2}, @request.parameters) assert_equal({"foo" => 1}, @request.request_parameters) diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index 8728c9fca3..9f6b45f065 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -383,8 +383,8 @@ class RescueControllerTest < ActionController::TestCase def test_rescue_dispatcher_exceptions env = @request.env - env["actioncontroller.rescue.request"] = @request - env["actioncontroller.rescue.response"] = @response + env["action_controller.rescue.request"] = @request + env["action_controller.rescue.response"] = @response RescueController.call_with_exception(env, ActionController::RoutingError.new("Route not found")) assert_equal "no way", @response.body -- cgit v1.2.3 From b7ea4add86231ef628d479516c8a09ca55e610bc Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 6 Jan 2009 15:20:57 -0600 Subject: Bump Rack version to 0.9 --- actionpack/test/controller/integration_test.rb | 6 +++--- actionpack/test/controller/rack_test.rb | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 53cebf768e..7ac9d97096 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -4,7 +4,7 @@ uses_mocha 'integration' do class SessionTest < Test::Unit::TestCase StubApp = lambda { |env| - [200, {"Content-Type" => "text/html"}, "Hello, World!"] + [200, {"Content-Type" => "text/html", "Content-Length" => "13"}, "Hello, World!"] } def setup @@ -465,9 +465,9 @@ class MetalTest < ActionController::IntegrationTest class Poller def self.call(env) if env["PATH_INFO"] =~ /^\/success/ - [200, {"Content-Type" => "text/plain"}, "Hello World!"] + [200, {"Content-Type" => "text/plain", "Content-Length" => "12"}, "Hello World!"] else - [404, {"Content-Type" => "text/plain"}, ''] + [404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, ''] end end end diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb index 31bff4ae6d..8fd004a9e9 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/controller/rack_test.rb @@ -236,7 +236,12 @@ class RackResponseTest < BaseRackTest status, headers, body = @response.to_a assert_equal 200, status - assert_equal({"Content-Type" => "text/html; charset=utf-8", "Cache-Control" => "no-cache", "Set-Cookie" => []}, headers) + assert_equal({ + "Content-Type" => "text/html; charset=utf-8", + "Content-Length" => "", + "Cache-Control" => "no-cache", + "Set-Cookie" => [] + }, headers) parts = [] body.each { |part| parts << part } -- cgit v1.2.3 From 35fa00731329120fa1d0c2a9d66af6813203195a Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 7 Jan 2009 13:23:10 -0800 Subject: Include process methods in ActionController::TestCase only. No need to alias_method_chain :process either. --- .../test/controller/addresses_render_test.rb | 9 +++------ actionpack/test/controller/base_test.rb | 22 ++++++++++------------ actionpack/test/controller/benchmark_test.rb | 6 +++--- actionpack/test/controller/capture_test.rb | 9 +++------ actionpack/test/controller/content_type_test.rb | 9 +++------ actionpack/test/controller/cookie_test.rb | 8 +++----- actionpack/test/controller/filters_test.rb | 8 ++++++-- actionpack/test/controller/flash_test.rb | 8 ++------ actionpack/test/controller/send_file_test.rb | 3 ++- 9 files changed, 35 insertions(+), 47 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/addresses_render_test.rb b/actionpack/test/controller/addresses_render_test.rb index b26cae24fb..556b0593ea 100644 --- a/actionpack/test/controller/addresses_render_test.rb +++ b/actionpack/test/controller/addresses_render_test.rb @@ -19,17 +19,14 @@ class AddressesTestController < ActionController::Base def self.controller_path; "addresses"; end end -class AddressesTest < Test::Unit::TestCase - def setup - @controller = AddressesTestController.new +class AddressesTest < ActionController::TestCase + tests AddressesTestController + def setup # enable a logger so that (e.g.) the benchmarking stuff runs, so we can get # a more accurate simulation of what happens in "real life". @controller.logger = Logger.new(nil) - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - @request.host = "www.nextangle.com" end diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb index 18d185b264..9523189f41 100644 --- a/actionpack/test/controller/base_test.rb +++ b/actionpack/test/controller/base_test.rb @@ -129,6 +129,8 @@ class PerformActionTest < ActionController::TestCase @response = ActionController::TestResponse.new @request.host = "www.nextangle.com" + + rescue_action_in_public! end def test_get_on_priv_should_show_selector @@ -164,14 +166,12 @@ class PerformActionTest < ActionController::TestCase end end -class DefaultUrlOptionsTest < Test::Unit::TestCase - def setup - @controller = DefaultUrlOptionsController.new - - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new +class DefaultUrlOptionsTest < ActionController::TestCase + tests DefaultUrlOptionsController + def setup @request.host = 'www.example.com' + rescue_action_in_public! end def test_default_url_options_are_used_if_set @@ -189,14 +189,12 @@ class DefaultUrlOptionsTest < Test::Unit::TestCase end end -class EmptyUrlOptionsTest < Test::Unit::TestCase - def setup - @controller = NonEmptyController.new - - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new +class EmptyUrlOptionsTest < ActionController::TestCase + tests NonEmptyController + def setup @request.host = 'www.example.com' + rescue_action_in_public! end def test_ensure_url_for_works_as_expected_when_called_with_no_options_if_default_url_options_is_not_set diff --git a/actionpack/test/controller/benchmark_test.rb b/actionpack/test/controller/benchmark_test.rb index 608ea5f5a9..f9100a2313 100644 --- a/actionpack/test/controller/benchmark_test.rb +++ b/actionpack/test/controller/benchmark_test.rb @@ -11,17 +11,17 @@ class BenchmarkedController < ActionController::Base end end -class BenchmarkTest < Test::Unit::TestCase +class BenchmarkTest < ActionController::TestCase + tests BenchmarkedController + class MockLogger def method_missing(*args) end end def setup - @controller = BenchmarkedController.new # benchmark doesn't do anything unless a logger is set @controller.logger = MockLogger.new - @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new @request.host = "test.actioncontroller.i" end diff --git a/actionpack/test/controller/capture_test.rb b/actionpack/test/controller/capture_test.rb index 5ded6a5d26..6dfa0995eb 100644 --- a/actionpack/test/controller/capture_test.rb +++ b/actionpack/test/controller/capture_test.rb @@ -23,17 +23,14 @@ class CaptureController < ActionController::Base def rescue_action(e) raise end end -class CaptureTest < Test::Unit::TestCase - def setup - @controller = CaptureController.new +class CaptureTest < ActionController::TestCase + tests CaptureController + def setup # enable a logger so that (e.g.) the benchmarking stuff runs, so we can get # a more accurate simulation of what happens in "real life". @controller.logger = Logger.new(nil) - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - @request.host = "www.nextangle.com" end diff --git a/actionpack/test/controller/content_type_test.rb b/actionpack/test/controller/content_type_test.rb index ae71d62e11..32c1757ef9 100644 --- a/actionpack/test/controller/content_type_test.rb +++ b/actionpack/test/controller/content_type_test.rb @@ -50,16 +50,13 @@ class ContentTypeController < ActionController::Base def rescue_action(e) raise end end -class ContentTypeTest < Test::Unit::TestCase - def setup - @controller = ContentTypeController.new +class ContentTypeTest < ActionController::TestCase + tests ContentTypeController + def setup # enable a logger so that (e.g.) the benchmarking stuff runs, so we can get # a more accurate simulation of what happens in "real life". @controller.logger = Logger.new(nil) - - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new end def test_render_defaults diff --git a/actionpack/test/controller/cookie_test.rb b/actionpack/test/controller/cookie_test.rb index 3ddc5768a9..9508348ca1 100644 --- a/actionpack/test/controller/cookie_test.rb +++ b/actionpack/test/controller/cookie_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' -class CookieTest < Test::Unit::TestCase +class CookieTest < ActionController::TestCase class TestController < ActionController::Base def authenticate cookies["user_name"] = "david" @@ -41,11 +41,9 @@ class CookieTest < Test::Unit::TestCase end end - def setup - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new + tests TestController - @controller = TestController.new + def setup @request.host = "www.nextangle.com" end diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index dafa344473..e83fde2349 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -634,9 +634,11 @@ class FilterTest < Test::Unit::TestCase private def test_process(controller, action = "show") + ActionController::Base.class_eval { include ActionController::ProcessWithTest } unless ActionController::Base < ActionController::ProcessWithTest request = ActionController::TestRequest.new request.action = action - controller.process(request, ActionController::TestResponse.new) + controller = controller.new if controller.is_a?(Class) + controller.process_with_test(request, ActionController::TestResponse.new) end end @@ -874,8 +876,10 @@ class YieldingAroundFiltersTest < Test::Unit::TestCase protected def test_process(controller, action = "show") + ActionController::Base.class_eval { include ActionController::ProcessWithTest } unless ActionController::Base < ActionController::ProcessWithTest request = ActionController::TestRequest.new request.action = action - controller.process(request, ActionController::TestResponse.new) + controller = controller.new if controller.is_a?(Class) + controller.process_with_test(request, ActionController::TestResponse.new) end end diff --git a/actionpack/test/controller/flash_test.rb b/actionpack/test/controller/flash_test.rb index e562531bf3..d8a892811e 100644 --- a/actionpack/test/controller/flash_test.rb +++ b/actionpack/test/controller/flash_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' -class FlashTest < Test::Unit::TestCase +class FlashTest < ActionController::TestCase class TestController < ActionController::Base def set_flash flash["that"] = "hello" @@ -73,11 +73,7 @@ class FlashTest < Test::Unit::TestCase end end - def setup - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - @controller = TestController.new - end + tests TestController def test_flash get :set_flash diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb index 1b7486ad34..5fc79baa44 100644 --- a/actionpack/test/controller/send_file_test.rb +++ b/actionpack/test/controller/send_file_test.rb @@ -19,7 +19,8 @@ class SendFileController < ActionController::Base def rescue_action(e) raise end end -class SendFileTest < Test::Unit::TestCase +class SendFileTest < ActionController::TestCase + tests SendFileController include TestFileUtils Mime::Type.register "image/png", :png unless defined? Mime::PNG -- cgit v1.2.3 From c90572e3ab65e02933d204747645d0de83b00481 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 7 Jan 2009 14:39:23 -0800 Subject: Use instance_eval instead of adding an accessor to the class --- actionpack/test/controller/layout_test.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb index c2efe9d00b..2f5e830fba 100644 --- a/actionpack/test/controller/layout_test.rb +++ b/actionpack/test/controller/layout_test.rb @@ -146,8 +146,7 @@ class LayoutExceptionRaised < ActionController::TestCase def test_exception_raised_when_layout_file_not_found @controller = SetsNonExistentLayoutFile.new get :hello - @response.template.class.module_eval { attr_accessor :exception } - assert_equal ActionView::MissingTemplate, @response.template.exception.class + assert_kind_of ActionView::MissingTemplate, @response.template.instance_eval { @exception } end end -- cgit v1.2.3 From 074414883cd39c24a6197f7450723c6fc60132d0 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 7 Jan 2009 15:55:28 -0800 Subject: Remove Content-Length header from :no_content responses --- actionpack/test/controller/render_test.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 5fd41d8eec..8809aa7c34 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -1218,6 +1218,11 @@ class RenderTest < ActionController::TestCase assert_equal "404 Not Found", @response.status assert_response :not_found + get :head_with_symbolic_status, :status => "no_content" + assert_equal "204 No Content", @response.status + assert !@response.headers.include?('Content-Length') + assert_response :no_content + ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE.each do |status, code| get :head_with_symbolic_status, :status => status.to_s assert_equal code, @response.response_code @@ -1470,7 +1475,7 @@ class EtagRenderTest < ActionController::TestCase def test_render_against_etag_request_should_have_no_content_length_when_match @request.if_none_match = etag_for("hello david") get :render_hello_world_from_variable - assert !@response.headers.has_key?("Content-Length") + assert !@response.headers.has_key?("Content-Length"), @response.headers['Content-Length'] end def test_render_against_etag_request_should_200_when_no_match -- cgit v1.2.3 From 282c1d6159a06dce4dd52c1849daad9e73480808 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 9 Jan 2009 12:52:59 -0600 Subject: Refactor request query string parsing tests --- .../test/controller/query_string_parsing_test.rb | 118 +++++++++++++++++++++ actionpack/test/controller/request_test.rb | 106 +----------------- 2 files changed, 119 insertions(+), 105 deletions(-) create mode 100644 actionpack/test/controller/query_string_parsing_test.rb (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/query_string_parsing_test.rb b/actionpack/test/controller/query_string_parsing_test.rb new file mode 100644 index 0000000000..91f5b2b27a --- /dev/null +++ b/actionpack/test/controller/query_string_parsing_test.rb @@ -0,0 +1,118 @@ +class QueryStringParsingTest "create_customer", "full_name" => "David Heinemeier Hansson", "customerId" => "1"}, + "action=create_customer&full_name=David%20Heinemeier%20Hansson&customerId=1" + ) + end + + test "deep query string" do + assert_parses( + {'x' => {'y' => {'z' => '10'}}}, + "x[y][z]=10" + ) + end + + test "deep query string with array" do + assert_parses({'x' => {'y' => {'z' => ['10']}}}, 'x[y][z][]=10') + assert_parses({'x' => {'y' => {'z' => ['10', '5']}}}, 'x[y][z][]=10&x[y][z][]=5') + end + + test "deep query string with array of hash" do + assert_parses({'x' => {'y' => [{'z' => '10'}]}}, 'x[y][][z]=10') + assert_parses({'x' => {'y' => [{'z' => '10', 'w' => '10'}]}}, 'x[y][][z]=10&x[y][][w]=10') + assert_parses({'x' => {'y' => [{'z' => '10', 'v' => {'w' => '10'}}]}}, 'x[y][][z]=10&x[y][][v][w]=10') + end + + test "deep query string with array of hashes with one pair" do + assert_parses({'x' => {'y' => [{'z' => '10'}, {'z' => '20'}]}}, 'x[y][][z]=10&x[y][][z]=20') + end + + test "deep query string with array of hashes with multiple pairs" do + assert_parses( + {'x' => {'y' => [{'z' => '10', 'w' => 'a'}, {'z' => '20', 'w' => 'b'}]}}, + 'x[y][][z]=10&x[y][][w]=a&x[y][][z]=20&x[y][][w]=b' + ) + end + + test "query string with nil" do + assert_parses( + { "action" => "create_customer", "full_name" => ''}, + "action=create_customer&full_name=" + ) + end + + test "query string with array" do + assert_parses( + { "action" => "create_customer", "selected" => ["1", "2", "3"]}, + "action=create_customer&selected[]=1&selected[]=2&selected[]=3" + ) + end + + test "query string with amps" do + assert_parses( + { "action" => "create_customer", "name" => "Don't & Does"}, + "action=create_customer&name=Don%27t+%26+Does" + ) + end + + test "query string with many equal" do + assert_parses( + { "action" => "create_customer", "full_name" => "abc=def=ghi"}, + "action=create_customer&full_name=abc=def=ghi" + ) + end + + test "query string without equal" do + assert_parses({ "action" => nil }, "action") + end + + test "query string with empty key" do + assert_parses( + { "action" => "create_customer", "full_name" => "David Heinemeier Hansson" }, + "action=create_customer&full_name=David%20Heinemeier%20Hansson&=Save" + ) + end + + test "query string with many ampersands" do + assert_parses( + { "action" => "create_customer", "full_name" => "David Heinemeier Hansson"}, + "&action=create_customer&&&full_name=David%20Heinemeier%20Hansson" + ) + end + + test "unbalanced query string with array" do + assert_parses( + {'location' => ["1", "2"], 'age_group' => ["2"]}, + "location[]=1&location[]=2&age_group[]=2" + ) + end + + private + def assert_parses(expected, actual) + with_routing do |set| + set.draw do |map| + map.connect ':action', :controller => "query_string_parsing_test/test" + end + + get "/parse", actual + assert_response :ok + assert_equal(expected, TestController.last_query_parameters) + end + end +end diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb index 02bb2ee890..64cc3f5291 100644 --- a/actionpack/test/controller/request_test.rb +++ b/actionpack/test/controller/request_test.rb @@ -407,114 +407,10 @@ class RequestTest < ActiveSupport::TestCase end class UrlEncodedRequestParameterParsingTest < ActiveSupport::TestCase - def setup - @query_string = "action=create_customer&full_name=David%20Heinemeier%20Hansson&customerId=1" - @query_string_with_empty = "action=create_customer&full_name=" - @query_string_with_array = "action=create_customer&selected[]=1&selected[]=2&selected[]=3" - @query_string_with_amps = "action=create_customer&name=Don%27t+%26+Does" - @query_string_with_multiple_of_same_name = - "action=update_order&full_name=Lau%20Taarnskov&products=4&products=2&products=3" - @query_string_with_many_equal = "action=create_customer&full_name=abc=def=ghi" - @query_string_without_equal = "action" - @query_string_with_many_ampersands = - "&action=create_customer&&&full_name=David%20Heinemeier%20Hansson" - @query_string_with_empty_key = "action=create_customer&full_name=David%20Heinemeier%20Hansson&=Save" - end - - def test_query_string - assert_equal( - { "action" => "create_customer", "full_name" => "David Heinemeier Hansson", "customerId" => "1"}, - ActionController::RequestParser.parse_query_parameters(@query_string) - ) - end - - def test_deep_query_string - expected = {'x' => {'y' => {'z' => '10'}}} - assert_equal(expected, ActionController::RequestParser.parse_query_parameters('x[y][z]=10')) - end - - def test_deep_query_string_with_array - assert_equal({'x' => {'y' => {'z' => ['10']}}}, ActionController::RequestParser.parse_query_parameters('x[y][z][]=10')) - assert_equal({'x' => {'y' => {'z' => ['10', '5']}}}, ActionController::RequestParser.parse_query_parameters('x[y][z][]=10&x[y][z][]=5')) - end - - def test_deep_query_string_with_array_of_hash - assert_equal({'x' => {'y' => [{'z' => '10'}]}}, ActionController::RequestParser.parse_query_parameters('x[y][][z]=10')) - assert_equal({'x' => {'y' => [{'z' => '10', 'w' => '10'}]}}, ActionController::RequestParser.parse_query_parameters('x[y][][z]=10&x[y][][w]=10')) - assert_equal({'x' => {'y' => [{'z' => '10', 'v' => {'w' => '10'}}]}}, ActionController::RequestParser.parse_query_parameters('x[y][][z]=10&x[y][][v][w]=10')) - end - - def test_deep_query_string_with_array_of_hashes_with_one_pair - assert_equal({'x' => {'y' => [{'z' => '10'}, {'z' => '20'}]}}, ActionController::RequestParser.parse_query_parameters('x[y][][z]=10&x[y][][z]=20')) - assert_equal("10", ActionController::RequestParser.parse_query_parameters('x[y][][z]=10&x[y][][z]=20')["x"]["y"].first["z"]) - assert_equal("10", ActionController::RequestParser.parse_query_parameters('x[y][][z]=10&x[y][][z]=20').with_indifferent_access[:x][:y].first[:z]) - end - - def test_deep_query_string_with_array_of_hashes_with_multiple_pairs - assert_equal( - {'x' => {'y' => [{'z' => '10', 'w' => 'a'}, {'z' => '20', 'w' => 'b'}]}}, - ActionController::RequestParser.parse_query_parameters('x[y][][z]=10&x[y][][w]=a&x[y][][z]=20&x[y][][w]=b') - ) - end - - def test_query_string_with_nil - assert_equal( - { "action" => "create_customer", "full_name" => ''}, - ActionController::RequestParser.parse_query_parameters(@query_string_with_empty) - ) - end - - def test_query_string_with_array - assert_equal( - { "action" => "create_customer", "selected" => ["1", "2", "3"]}, - ActionController::RequestParser.parse_query_parameters(@query_string_with_array) - ) - end - - def test_query_string_with_amps - assert_equal( - { "action" => "create_customer", "name" => "Don't & Does"}, - ActionController::RequestParser.parse_query_parameters(@query_string_with_amps) - ) - end - - def test_query_string_with_many_equal - assert_equal( - { "action" => "create_customer", "full_name" => "abc=def=ghi"}, - ActionController::RequestParser.parse_query_parameters(@query_string_with_many_equal) - ) - end - - def test_query_string_without_equal - assert_equal( - { "action" => nil }, - ActionController::RequestParser.parse_query_parameters(@query_string_without_equal) - ) - end - - def test_query_string_with_empty_key - assert_equal( - { "action" => "create_customer", "full_name" => "David Heinemeier Hansson" }, - ActionController::RequestParser.parse_query_parameters(@query_string_with_empty_key) - ) - end - - def test_query_string_with_many_ampersands - assert_equal( - { "action" => "create_customer", "full_name" => "David Heinemeier Hansson"}, - ActionController::RequestParser.parse_query_parameters(@query_string_with_many_ampersands) - ) - end - def test_unbalanced_query_string_with_array assert_equal( {'location' => ["1", "2"], 'age_group' => ["2"]}, - ActionController::RequestParser.parse_query_parameters("location[]=1&location[]=2&age_group[]=2") - ) - assert_equal( - {'location' => ["1", "2"], 'age_group' => ["2"]}, - ActionController::RequestParser.parse_request_parameters({'location[]' => ["1", "2"], - 'age_group[]' => ["2"]}) + ActionController::RequestParser.parse_request_parameters({'location[]' => ["1", "2"], 'age_group[]' => ["2"]}) ) end -- cgit v1.2.3 From ac4bf1180aa0f82616038522bddaf3ff3d5020c8 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 9 Jan 2009 13:12:39 -0600 Subject: Ensure we override Rack::Request's POST method too --- actionpack/test/controller/query_string_parsing_test.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/query_string_parsing_test.rb b/actionpack/test/controller/query_string_parsing_test.rb index 91f5b2b27a..a31e326ddf 100644 --- a/actionpack/test/controller/query_string_parsing_test.rb +++ b/actionpack/test/controller/query_string_parsing_test.rb @@ -1,4 +1,6 @@ -class QueryStringParsingTest Date: Fri, 9 Jan 2009 15:43:32 -0600 Subject: Refactor request json params parsing tests --- .../controller/request/json_params_parsing_test.rb | 45 ++++++++++++++++++++++ actionpack/test/controller/request_test.rb | 22 ----------- 2 files changed, 45 insertions(+), 22 deletions(-) create mode 100644 actionpack/test/controller/request/json_params_parsing_test.rb (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/request/json_params_parsing_test.rb b/actionpack/test/controller/request/json_params_parsing_test.rb new file mode 100644 index 0000000000..a3dde72c4e --- /dev/null +++ b/actionpack/test/controller/request/json_params_parsing_test.rb @@ -0,0 +1,45 @@ +require 'abstract_unit' + +class JsonParamsParsingTest < ActionController::IntegrationTest + class TestController < ActionController::Base + class << self + attr_accessor :last_request_parameters + end + + def parse + self.class.last_request_parameters = request.request_parameters + head :ok + end + end + + def teardown + TestController.last_request_parameters = nil + end + + test "parses json params for application json" do + assert_parses( + {"person" => {"name" => "David"}}, + "{\"person\": {\"name\": \"David\"}}", { 'CONTENT_TYPE' => 'application/json' } + ) + end + + test "parses json params for application jsonrequest" do + assert_parses( + {"person" => {"name" => "David"}}, + "{\"person\": {\"name\": \"David\"}}", { 'CONTENT_TYPE' => 'application/jsonrequest' } + ) + end + + private + def assert_parses(expected, actual, headers = {}) + with_routing do |set| + set.draw do |map| + map.connect ':action', :controller => "json_params_parsing_test/test" + end + + post "/parse", actual, headers + assert_response :ok + assert_equal(expected, TestController.last_request_parameters) + end + end +end diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb index 64cc3f5291..2eb2693644 100644 --- a/actionpack/test/controller/request_test.rb +++ b/actionpack/test/controller/request_test.rb @@ -764,25 +764,3 @@ class LegacyXmlParamsParsingTest < XmlParamsParsingTest ActionController::Request.new(env).request_parameters end end - -class JsonParamsParsingTest < ActiveSupport::TestCase - def test_hash_params_for_application_json - person = parse_body({:person => {:name => "David"}}.to_json,'application/json')[:person] - assert_kind_of Hash, person - assert_equal 'David', person['name'] - end - - def test_hash_params_for_application_jsonrequest - person = parse_body({:person => {:name => "David"}}.to_json,'application/jsonrequest')[:person] - assert_kind_of Hash, person - assert_equal 'David', person['name'] - end - - private - def parse_body(body,content_type) - env = { 'rack.input' => StringIO.new(body), - 'CONTENT_TYPE' => content_type, - 'CONTENT_LENGTH' => body.size.to_s } - ActionController::Request.new(env).request_parameters - end -end -- cgit v1.2.3 From 40a75a509187b6759099a3644b7ae8db9fc14045 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 9 Jan 2009 16:05:27 -0600 Subject: Refactor request xml params parsing tests --- .../controller/request/xml_params_parsing_test.rb | 88 ++++++++++++++++++++++ actionpack/test/controller/request_test.rb | 54 ------------- 2 files changed, 88 insertions(+), 54 deletions(-) create mode 100644 actionpack/test/controller/request/xml_params_parsing_test.rb (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/request/xml_params_parsing_test.rb b/actionpack/test/controller/request/xml_params_parsing_test.rb new file mode 100644 index 0000000000..ee764e726e --- /dev/null +++ b/actionpack/test/controller/request/xml_params_parsing_test.rb @@ -0,0 +1,88 @@ +require 'abstract_unit' + +class XmlParamsParsingTest < ActionController::IntegrationTest + class TestController < ActionController::Base + class << self + attr_accessor :last_request_parameters + end + + def parse + self.class.last_request_parameters = request.request_parameters + head :ok + end + end + + def teardown + TestController.last_request_parameters = nil + end + + test "parses hash params" do + with_test_routing do + xml = "David" + post "/parse", xml, default_headers + assert_response :ok + assert_equal({"person" => {"name" => "David"}}, TestController.last_request_parameters) + end + end + + test "parses single file" do + with_test_routing do + xml = "David#{ActiveSupport::Base64.encode64('ABC')}" + post "/parse", xml, default_headers + assert_response :ok + + person = TestController.last_request_parameters + assert_equal "image/jpg", person['person']['avatar'].content_type + assert_equal "me.jpg", person['person']['avatar'].original_filename + assert_equal "ABC", person['person']['avatar'].read + end + end + + test "parses multiple files" do + xml = <<-end_body + + David + + #{ActiveSupport::Base64.encode64('ABC')} + #{ActiveSupport::Base64.encode64('DEF')} + + + end_body + + with_test_routing do + post "/parse", xml, default_headers + assert_response :ok + end + + person = TestController.last_request_parameters + + assert_equal "image/jpg", person['person']['avatars']['avatar'].first.content_type + assert_equal "me.jpg", person['person']['avatars']['avatar'].first.original_filename + assert_equal "ABC", person['person']['avatars']['avatar'].first.read + + assert_equal "image/gif", person['person']['avatars']['avatar'].last.content_type + assert_equal "you.gif", person['person']['avatars']['avatar'].last.original_filename + assert_equal "DEF", person['person']['avatars']['avatar'].last.read + end + + private + def with_test_routing + with_routing do |set| + set.draw do |map| + map.connect ':action', :controller => "xml_params_parsing_test/test" + end + yield + end + end + + def default_headers + {'CONTENT_TYPE' => 'application/xml'} + end +end + +class LegacyXmlParamsParsingTest < XmlParamsParsingTest + private + def default_headers + {'HTTP_X_POST_DATA_FORMAT' => 'xml'} + end +end diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb index 2eb2693644..c53f1bc2d9 100644 --- a/actionpack/test/controller/request_test.rb +++ b/actionpack/test/controller/request_test.rb @@ -710,57 +710,3 @@ class MultipartRequestParameterParsingTest < ActiveSupport::TestCase end end end - -class XmlParamsParsingTest < ActiveSupport::TestCase - def test_hash_params - person = parse_body("David")[:person] - assert_kind_of Hash, person - assert_equal 'David', person['name'] - end - - def test_single_file - person = parse_body("David#{ActiveSupport::Base64.encode64('ABC')}") - - assert_equal "image/jpg", person['person']['avatar'].content_type - assert_equal "me.jpg", person['person']['avatar'].original_filename - assert_equal "ABC", person['person']['avatar'].read - end - - def test_multiple_files - person = parse_body(<<-end_body) - - David - - #{ActiveSupport::Base64.encode64('ABC')} - #{ActiveSupport::Base64.encode64('DEF')} - - - end_body - - assert_equal "image/jpg", person['person']['avatars']['avatar'].first.content_type - assert_equal "me.jpg", person['person']['avatars']['avatar'].first.original_filename - assert_equal "ABC", person['person']['avatars']['avatar'].first.read - - assert_equal "image/gif", person['person']['avatars']['avatar'].last.content_type - assert_equal "you.gif", person['person']['avatars']['avatar'].last.original_filename - assert_equal "DEF", person['person']['avatars']['avatar'].last.read - end - - private - def parse_body(body) - env = { 'rack.input' => StringIO.new(body), - 'CONTENT_TYPE' => 'application/xml', - 'CONTENT_LENGTH' => body.size.to_s } - ActionController::Request.new(env).request_parameters - end -end - -class LegacyXmlParamsParsingTest < XmlParamsParsingTest - private - def parse_body(body) - env = { 'rack.input' => StringIO.new(body), - 'HTTP_X_POST_DATA_FORMAT' => 'xml', - 'CONTENT_LENGTH' => body.size.to_s } - ActionController::Request.new(env).request_parameters - end -end -- cgit v1.2.3 From 92dbf5ba832c2c4d8f6fda8b151090069cd701f3 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 10 Jan 2009 11:32:38 -0600 Subject: Refactor request multipart params parsing tests --- .../test/controller/integration_upload_test.rb | 65 -------- .../request/multipart_params_parsing_test.rb | 167 +++++++++++++++++++++ actionpack/test/controller/request_test.rb | 104 ------------- 3 files changed, 167 insertions(+), 169 deletions(-) delete mode 100644 actionpack/test/controller/integration_upload_test.rb create mode 100644 actionpack/test/controller/request/multipart_params_parsing_test.rb (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/integration_upload_test.rb b/actionpack/test/controller/integration_upload_test.rb deleted file mode 100644 index d579980c19..0000000000 --- a/actionpack/test/controller/integration_upload_test.rb +++ /dev/null @@ -1,65 +0,0 @@ -require 'abstract_unit' - -unless defined? ApplicationController - class ApplicationController < ActionController::Base - end -end - -class UploadTestController < ActionController::Base - def update - SessionUploadTest.last_request_type = ActionController::Base.param_parsers[request.content_type] - render :text => "got here" - end - - def read - render :text => "File: #{params[:uploaded_data].read}" - end -end - -class SessionUploadTest < ActionController::IntegrationTest - FILES_DIR = File.dirname(__FILE__) + '/../fixtures/multipart' - - class << self - attr_accessor :last_request_type - end - - def test_upload_and_read_file - with_test_routing do - post '/read', :uploaded_data => fixture_file_upload(FILES_DIR + "/hello.txt", "text/plain") - assert_equal "File: Hello", response.body - end - end - - # The lint wrapper is used in integration tests - # instead of a normal StringIO class - InputWrapper = Rack::Lint::InputWrapper - - def test_post_with_upload_with_unrewindable_input - InputWrapper.any_instance.expects(:rewind).raises(Errno::ESPIPE) - - with_test_routing do - post '/read', :uploaded_data => fixture_file_upload(FILES_DIR + "/hello.txt", "text/plain") - assert_equal "File: Hello", response.body - end - end - - def test_post_with_upload_with_params_parsing - with_test_routing do - params = { :uploaded_data => fixture_file_upload(FILES_DIR + "/mona_lisa.jpg", "image/jpg") } - post '/update', params, :location => 'blah' - assert_equal(:multipart_form, SessionUploadTest.last_request_type) - end - end - - private - def with_test_routing - with_routing do |set| - set.draw do |map| - map.update 'update', :controller => "upload_test", :action => "update", :method => :post - map.read 'read', :controller => "upload_test", :action => "read", :method => :post - end - - yield - end - end -end diff --git a/actionpack/test/controller/request/multipart_params_parsing_test.rb b/actionpack/test/controller/request/multipart_params_parsing_test.rb new file mode 100644 index 0000000000..03ab164972 --- /dev/null +++ b/actionpack/test/controller/request/multipart_params_parsing_test.rb @@ -0,0 +1,167 @@ +require 'abstract_unit' + +class MultipartParamsParsingTest < ActionController::IntegrationTest + class TestController < ActionController::Base + class << self + attr_accessor :last_request_parameters, :last_request_type + end + + def parse + self.class.last_request_type = ActionController::Base.param_parsers[request.content_type] + self.class.last_request_parameters = request.request_parameters + head :ok + end + + def read + render :text => "File: #{params[:uploaded_data].read}" + end + end + + FIXTURE_PATH = File.dirname(__FILE__) + '/../../fixtures/multipart' + + def teardown + TestController.last_request_parameters = nil + TestController.last_request_type = nil + end + + test "parses single parameter" do + assert_equal({ 'foo' => 'bar' }, parse_multipart('single_parameter')) + end + + test "parses bracketed parameters" do + assert_equal({ 'foo' => { 'baz' => 'bar'}}, parse_multipart('bracketed_param')) + end + + test "parses text file" do + params = parse_multipart('text_file') + assert_equal %w(file foo), params.keys.sort + assert_equal 'bar', params['foo'] + + file = params['file'] + assert_kind_of StringIO, file + assert_equal 'file.txt', file.original_filename + assert_equal "text/plain", file.content_type + assert_equal 'contents', file.read + end + + test "parses boundary problem file" do + params = parse_multipart('boundary_problem_file') + assert_equal %w(file foo), params.keys.sort + + file = params['file'] + foo = params['foo'] + + assert_kind_of Tempfile, file + + assert_equal 'file.txt', file.original_filename + assert_equal "text/plain", file.content_type + + assert_equal 'bar', foo + end + + test "parses large text file" do + params = parse_multipart('large_text_file') + assert_equal %w(file foo), params.keys.sort + assert_equal 'bar', params['foo'] + + file = params['file'] + + assert_kind_of Tempfile, file + + assert_equal 'file.txt', file.original_filename + assert_equal "text/plain", file.content_type + assert ('a' * 20480) == file.read + end + + test "parses binary file" do + params = parse_multipart('binary_file') + assert_equal %w(file flowers foo), params.keys.sort + assert_equal 'bar', params['foo'] + + file = params['file'] + assert_kind_of StringIO, file + assert_equal 'file.csv', file.original_filename + assert_nil file.content_type + assert_equal 'contents', file.read + + file = params['flowers'] + assert_kind_of StringIO, file + assert_equal 'flowers.jpg', file.original_filename + assert_equal "image/jpeg", file.content_type + assert_equal 19512, file.size + end + + test "parses mixed files" do + params = parse_multipart('mixed_files') + assert_equal %w(files foo), params.keys.sort + assert_equal 'bar', params['foo'] + + # Ruby CGI doesn't handle multipart/mixed for us. + files = params['files'] + assert_kind_of String, files + files.force_encoding('ASCII-8BIT') if files.respond_to?(:force_encoding) + assert_equal 19756, files.size + end + + test "uploads and parses parameters" do + with_test_routing do + params = { :uploaded_data => fixture_file_upload(FIXTURE_PATH + "/mona_lisa.jpg", "image/jpg") } + post '/parse', params, :location => 'blah' + assert_equal(:multipart_form, TestController.last_request_type) + end + end + + test "uploads and reads file" do + with_test_routing do + post '/read', :uploaded_data => fixture_file_upload(FIXTURE_PATH + "/hello.txt", "text/plain") + assert_equal "File: Hello", response.body + end + end + + # The lint wrapper is used in integration tests + # instead of a normal StringIO class + InputWrapper = Rack::Lint::InputWrapper + + test "parses unwindable stream" do + InputWrapper.any_instance.expects(:rewind).raises(Errno::ESPIPE) + params = parse_multipart('large_text_file') + assert_equal %w(file foo), params.keys.sort + assert_equal 'bar', params['foo'] + end + + test "uploads and reads file with unwindable input" do + InputWrapper.any_instance.expects(:rewind).raises(Errno::ESPIPE) + + with_test_routing do + post '/read', :uploaded_data => fixture_file_upload(FIXTURE_PATH + "/hello.txt", "text/plain") + assert_equal "File: Hello", response.body + end + end + + private + def fixture(name) + File.open(File.join(FIXTURE_PATH, name), 'rb') do |file| + { "rack.input" => file.read, + "CONTENT_TYPE" => "multipart/form-data; boundary=AaB03x", + "CONTENT_LENGTH" => file.stat.size.to_s } + end + end + + def parse_multipart(name) + with_test_routing do + headers = fixture(name) + post "/parse", headers.delete("rack.input"), headers + assert_response :ok + TestController.last_request_parameters + end + end + + def with_test_routing + with_routing do |set| + set.draw do |map| + map.connect ':action', :controller => "multipart_params_parsing_test/test" + end + yield + end + end +end diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb index c53f1bc2d9..3256774b6d 100644 --- a/actionpack/test/controller/request_test.rb +++ b/actionpack/test/controller/request_test.rb @@ -606,107 +606,3 @@ class UrlEncodedRequestParameterParsingTest < ActiveSupport::TestCase assert_equal expected, ActionController::RequestParser.parse_request_parameters(input) end end - -class MultipartRequestParameterParsingTest < ActiveSupport::TestCase - FIXTURE_PATH = File.dirname(__FILE__) + '/../fixtures/multipart' - - def test_single_parameter - params = parse_multipart('single_parameter') - assert_equal({ 'foo' => 'bar' }, params) - end - - def test_bracketed_param - assert_equal({ 'foo' => { 'baz' => 'bar'}}, parse_multipart('bracketed_param')) - end - - def test_text_file - params = parse_multipart('text_file') - assert_equal %w(file foo), params.keys.sort - assert_equal 'bar', params['foo'] - - file = params['file'] - assert_kind_of StringIO, file - assert_equal 'file.txt', file.original_filename - assert_equal "text/plain", file.content_type - assert_equal 'contents', file.read - end - - def test_boundary_problem_file - params = parse_multipart('boundary_problem_file') - assert_equal %w(file foo), params.keys.sort - - file = params['file'] - foo = params['foo'] - - assert_kind_of Tempfile, file - - assert_equal 'file.txt', file.original_filename - assert_equal "text/plain", file.content_type - - assert_equal 'bar', foo - end - - def test_large_text_file - params = parse_multipart('large_text_file') - assert_equal %w(file foo), params.keys.sort - assert_equal 'bar', params['foo'] - - file = params['file'] - - assert_kind_of Tempfile, file - - assert_equal 'file.txt', file.original_filename - assert_equal "text/plain", file.content_type - assert ('a' * 20480) == file.read - end - - uses_mocha "test_no_rewind_stream" do - def test_no_rewind_stream - # Ensures that parse_multipart_form_parameters works with streams that cannot be rewound - file = File.open(File.join(FIXTURE_PATH, 'large_text_file'), 'rb') - file.expects(:rewind).raises(Errno::ESPIPE) - params = ActionController::RequestParser.parse_multipart_form_parameters(file, 'AaB03x', file.stat.size, {}) - assert_not_equal 0, file.pos # file was not rewound after reading - end - end - - def test_binary_file - params = parse_multipart('binary_file') - assert_equal %w(file flowers foo), params.keys.sort - assert_equal 'bar', params['foo'] - - file = params['file'] - assert_kind_of StringIO, file - assert_equal 'file.csv', file.original_filename - assert_nil file.content_type - assert_equal 'contents', file.read - - file = params['flowers'] - assert_kind_of StringIO, file - assert_equal 'flowers.jpg', file.original_filename - assert_equal "image/jpeg", file.content_type - assert_equal 19512, file.size - #assert_equal File.read(File.dirname(__FILE__) + '/../../../activerecord/test/fixtures/flowers.jpg'), file.read - end - - def test_mixed_files - params = parse_multipart('mixed_files') - assert_equal %w(files foo), params.keys.sort - assert_equal 'bar', params['foo'] - - # Ruby CGI doesn't handle multipart/mixed for us. - files = params['files'] - assert_kind_of String, files - files.force_encoding('ASCII-8BIT') if files.respond_to?(:force_encoding) - assert_equal 19756, files.size - end - - private - def parse_multipart(name) - File.open(File.join(FIXTURE_PATH, name), 'rb') do |file| - params = ActionController::RequestParser.parse_multipart_form_parameters(file, 'AaB03x', file.stat.size, {}) - assert_equal 0, file.pos # file was rewound after reading - params - end - end -end -- cgit v1.2.3 From 9fe69b225cfbf12c02ee1433adf3a5aa17bcdf59 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 10 Jan 2009 11:39:57 -0600 Subject: Moved query string parsing tests into the request tests folder --- .../test/controller/query_string_parsing_test.rb | 120 --------------------- .../request/query_string_parsing_test.rb | 120 +++++++++++++++++++++ 2 files changed, 120 insertions(+), 120 deletions(-) delete mode 100644 actionpack/test/controller/query_string_parsing_test.rb create mode 100644 actionpack/test/controller/request/query_string_parsing_test.rb (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/query_string_parsing_test.rb b/actionpack/test/controller/query_string_parsing_test.rb deleted file mode 100644 index a31e326ddf..0000000000 --- a/actionpack/test/controller/query_string_parsing_test.rb +++ /dev/null @@ -1,120 +0,0 @@ -require 'abstract_unit' - -class QueryStringParsingTest < ActionController::IntegrationTest - class TestController < ActionController::Base - class << self - attr_accessor :last_query_parameters - end - - def parse - self.class.last_query_parameters = request.query_parameters - head :ok - end - end - - def teardown - TestController.last_query_parameters = nil - end - - test "query string" do - assert_parses( - {"action" => "create_customer", "full_name" => "David Heinemeier Hansson", "customerId" => "1"}, - "action=create_customer&full_name=David%20Heinemeier%20Hansson&customerId=1" - ) - end - - test "deep query string" do - assert_parses( - {'x' => {'y' => {'z' => '10'}}}, - "x[y][z]=10" - ) - end - - test "deep query string with array" do - assert_parses({'x' => {'y' => {'z' => ['10']}}}, 'x[y][z][]=10') - assert_parses({'x' => {'y' => {'z' => ['10', '5']}}}, 'x[y][z][]=10&x[y][z][]=5') - end - - test "deep query string with array of hash" do - assert_parses({'x' => {'y' => [{'z' => '10'}]}}, 'x[y][][z]=10') - assert_parses({'x' => {'y' => [{'z' => '10', 'w' => '10'}]}}, 'x[y][][z]=10&x[y][][w]=10') - assert_parses({'x' => {'y' => [{'z' => '10', 'v' => {'w' => '10'}}]}}, 'x[y][][z]=10&x[y][][v][w]=10') - end - - test "deep query string with array of hashes with one pair" do - assert_parses({'x' => {'y' => [{'z' => '10'}, {'z' => '20'}]}}, 'x[y][][z]=10&x[y][][z]=20') - end - - test "deep query string with array of hashes with multiple pairs" do - assert_parses( - {'x' => {'y' => [{'z' => '10', 'w' => 'a'}, {'z' => '20', 'w' => 'b'}]}}, - 'x[y][][z]=10&x[y][][w]=a&x[y][][z]=20&x[y][][w]=b' - ) - end - - test "query string with nil" do - assert_parses( - { "action" => "create_customer", "full_name" => ''}, - "action=create_customer&full_name=" - ) - end - - test "query string with array" do - assert_parses( - { "action" => "create_customer", "selected" => ["1", "2", "3"]}, - "action=create_customer&selected[]=1&selected[]=2&selected[]=3" - ) - end - - test "query string with amps" do - assert_parses( - { "action" => "create_customer", "name" => "Don't & Does"}, - "action=create_customer&name=Don%27t+%26+Does" - ) - end - - test "query string with many equal" do - assert_parses( - { "action" => "create_customer", "full_name" => "abc=def=ghi"}, - "action=create_customer&full_name=abc=def=ghi" - ) - end - - test "query string without equal" do - assert_parses({ "action" => nil }, "action") - end - - test "query string with empty key" do - assert_parses( - { "action" => "create_customer", "full_name" => "David Heinemeier Hansson" }, - "action=create_customer&full_name=David%20Heinemeier%20Hansson&=Save" - ) - end - - test "query string with many ampersands" do - assert_parses( - { "action" => "create_customer", "full_name" => "David Heinemeier Hansson"}, - "&action=create_customer&&&full_name=David%20Heinemeier%20Hansson" - ) - end - - test "unbalanced query string with array" do - assert_parses( - {'location' => ["1", "2"], 'age_group' => ["2"]}, - "location[]=1&location[]=2&age_group[]=2" - ) - end - - private - def assert_parses(expected, actual) - with_routing do |set| - set.draw do |map| - map.connect ':action', :controller => "query_string_parsing_test/test" - end - - get "/parse", actual - assert_response :ok - assert_equal(expected, TestController.last_query_parameters) - end - end -end diff --git a/actionpack/test/controller/request/query_string_parsing_test.rb b/actionpack/test/controller/request/query_string_parsing_test.rb new file mode 100644 index 0000000000..a31e326ddf --- /dev/null +++ b/actionpack/test/controller/request/query_string_parsing_test.rb @@ -0,0 +1,120 @@ +require 'abstract_unit' + +class QueryStringParsingTest < ActionController::IntegrationTest + class TestController < ActionController::Base + class << self + attr_accessor :last_query_parameters + end + + def parse + self.class.last_query_parameters = request.query_parameters + head :ok + end + end + + def teardown + TestController.last_query_parameters = nil + end + + test "query string" do + assert_parses( + {"action" => "create_customer", "full_name" => "David Heinemeier Hansson", "customerId" => "1"}, + "action=create_customer&full_name=David%20Heinemeier%20Hansson&customerId=1" + ) + end + + test "deep query string" do + assert_parses( + {'x' => {'y' => {'z' => '10'}}}, + "x[y][z]=10" + ) + end + + test "deep query string with array" do + assert_parses({'x' => {'y' => {'z' => ['10']}}}, 'x[y][z][]=10') + assert_parses({'x' => {'y' => {'z' => ['10', '5']}}}, 'x[y][z][]=10&x[y][z][]=5') + end + + test "deep query string with array of hash" do + assert_parses({'x' => {'y' => [{'z' => '10'}]}}, 'x[y][][z]=10') + assert_parses({'x' => {'y' => [{'z' => '10', 'w' => '10'}]}}, 'x[y][][z]=10&x[y][][w]=10') + assert_parses({'x' => {'y' => [{'z' => '10', 'v' => {'w' => '10'}}]}}, 'x[y][][z]=10&x[y][][v][w]=10') + end + + test "deep query string with array of hashes with one pair" do + assert_parses({'x' => {'y' => [{'z' => '10'}, {'z' => '20'}]}}, 'x[y][][z]=10&x[y][][z]=20') + end + + test "deep query string with array of hashes with multiple pairs" do + assert_parses( + {'x' => {'y' => [{'z' => '10', 'w' => 'a'}, {'z' => '20', 'w' => 'b'}]}}, + 'x[y][][z]=10&x[y][][w]=a&x[y][][z]=20&x[y][][w]=b' + ) + end + + test "query string with nil" do + assert_parses( + { "action" => "create_customer", "full_name" => ''}, + "action=create_customer&full_name=" + ) + end + + test "query string with array" do + assert_parses( + { "action" => "create_customer", "selected" => ["1", "2", "3"]}, + "action=create_customer&selected[]=1&selected[]=2&selected[]=3" + ) + end + + test "query string with amps" do + assert_parses( + { "action" => "create_customer", "name" => "Don't & Does"}, + "action=create_customer&name=Don%27t+%26+Does" + ) + end + + test "query string with many equal" do + assert_parses( + { "action" => "create_customer", "full_name" => "abc=def=ghi"}, + "action=create_customer&full_name=abc=def=ghi" + ) + end + + test "query string without equal" do + assert_parses({ "action" => nil }, "action") + end + + test "query string with empty key" do + assert_parses( + { "action" => "create_customer", "full_name" => "David Heinemeier Hansson" }, + "action=create_customer&full_name=David%20Heinemeier%20Hansson&=Save" + ) + end + + test "query string with many ampersands" do + assert_parses( + { "action" => "create_customer", "full_name" => "David Heinemeier Hansson"}, + "&action=create_customer&&&full_name=David%20Heinemeier%20Hansson" + ) + end + + test "unbalanced query string with array" do + assert_parses( + {'location' => ["1", "2"], 'age_group' => ["2"]}, + "location[]=1&location[]=2&age_group[]=2" + ) + end + + private + def assert_parses(expected, actual) + with_routing do |set| + set.draw do |map| + map.connect ':action', :controller => "query_string_parsing_test/test" + end + + get "/parse", actual + assert_response :ok + assert_equal(expected, TestController.last_query_parameters) + end + end +end -- cgit v1.2.3