From ef58194129a1dc0a96286c271b71455d37712b42 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 26 Sep 2009 11:37:42 -0500 Subject: Move Rails::Static into ActionDispatch --- actionpack/test/dispatch/static_test.rb | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 actionpack/test/dispatch/static_test.rb (limited to 'actionpack/test/dispatch') diff --git a/actionpack/test/dispatch/static_test.rb b/actionpack/test/dispatch/static_test.rb new file mode 100644 index 0000000000..e6957bb0ea --- /dev/null +++ b/actionpack/test/dispatch/static_test.rb @@ -0,0 +1,35 @@ +require 'abstract_unit' + +class StaticTest < ActiveSupport::TestCase + DummyApp = lambda { |env| + [200, {"Content-Type" => "text/plain"}, ["Hello, World!"]] + } + App = ActionDispatch::Static.new(DummyApp, "#{FIXTURE_LOAD_PATH}/public") + + test "serves dynamic content" do + assert_equal "Hello, World!", get("/nofile") + end + + test "serves static index at root" do + assert_equal "/index.html", get("/index.html") + assert_equal "/index.html", get("/index") + assert_equal "/index.html", get("/") + end + + test "serves static file in directory" do + assert_equal "/foo/bar.html", get("/foo/bar.html") + assert_equal "/foo/bar.html", get("/foo/bar/") + assert_equal "/foo/bar.html", get("/foo/bar") + end + + test "serves static index file in directory" do + assert_equal "/foo/index.html", get("/foo/index.html") + assert_equal "/foo/index.html", get("/foo/") + assert_equal "/foo/index.html", get("/foo") + end + + private + def get(path) + Rack::MockRequest.new(App).request("GET", path).body + end +end -- cgit v1.2.3 From 0c638b340685b0bd1020bef2cd8a6d221058aa78 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 26 Sep 2009 12:56:53 -0500 Subject: Clean up session integration tests so they don't reference AC::Dispatcher --- .../test/dispatch/session/cookie_store_test.rb | 25 ++++++---------------- .../test/dispatch/session/mem_cache_store_test.rb | 15 +++---------- 2 files changed, 9 insertions(+), 31 deletions(-) (limited to 'actionpack/test/dispatch') diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb index d695be0be4..366a14168b 100644 --- a/actionpack/test/dispatch/session/cookie_store_test.rb +++ b/actionpack/test/dispatch/session/cookie_store_test.rb @@ -46,10 +46,6 @@ class CookieStoreTest < ActionController::IntegrationTest def rescue_action(e) raise end end - def setup - reset_app! - end - def test_raises_argument_error_if_missing_session_key assert_raise(ArgumentError, nil.inspect) { ActionDispatch::Session::CookieStore.new(nil, @@ -193,10 +189,7 @@ class CookieStoreTest < ActionController::IntegrationTest end def test_session_store_with_expire_after - with_test_route_set do - app = ActionDispatch::Session::CookieStore.new(ActionController::Dispatcher.new, :key => SessionKey, :secret => SessionSecret, :expire_after => 5.hours) - @integration_session = open_session(app) - + with_test_route_set(:expire_after => 5.hours) do # First request accesses the session time = Time.local(2008, 4, 24) Time.stubs(:now).returns(time) @@ -226,20 +219,14 @@ class CookieStoreTest < ActionController::IntegrationTest end private - def reset_app! - app = ActionDispatch::Session::CookieStore.new(ActionController::Dispatcher.new, - :key => SessionKey, :secret => SessionSecret) - @integration_session = open_session(app) - end - - def with_test_route_set + def with_test_route_set(options = {}) with_routing do |set| set.draw do |map| - map.with_options :controller => "cookie_store_test/test" do |c| - c.connect "/:action" - end + map.connect "/:action", :controller => "cookie_store_test/test" end - reset_app! + options = {:key => SessionKey, :secret => SessionSecret}.merge(options) + app = ActionDispatch::Session::CookieStore.new(set, options) + @integration_session = open_session(app) yield end end diff --git a/actionpack/test/dispatch/session/mem_cache_store_test.rb b/actionpack/test/dispatch/session/mem_cache_store_test.rb index 1588918be7..d7129da187 100644 --- a/actionpack/test/dispatch/session/mem_cache_store_test.rb +++ b/actionpack/test/dispatch/session/mem_cache_store_test.rb @@ -32,8 +32,6 @@ class MemCacheStoreTest < ActionController::IntegrationTest end begin - App = ActionDispatch::Session::MemCacheStore.new(ActionController::Dispatcher.new, :key => '_session_id') - def test_setting_and_getting_session_value with_test_route_set do get '/set_session_value' @@ -107,20 +105,13 @@ class MemCacheStoreTest < ActionController::IntegrationTest end private - def reset_app! - app = ActionDispatch::Session::MemCacheStore.new( - ActionController::Dispatcher.new, :key => '_session_id') - @integration_session = open_session(app) - end - 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 + map.connect "/:action", :controller => "mem_cache_store_test/test" end - reset_app! + app = ActionDispatch::Session::MemCacheStore.new(set, :key => '_session_id') + @integration_session = open_session(app) yield end end -- cgit v1.2.3 From 1f7270057596592946a877cd029d95760ba3e5ee Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 26 Sep 2009 13:41:32 -0500 Subject: Move default middleware stack into initializer --- actionpack/test/dispatch/session/cookie_store_test.rb | 3 --- 1 file changed, 3 deletions(-) (limited to 'actionpack/test/dispatch') diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb index 366a14168b..bc0b4b22a5 100644 --- a/actionpack/test/dispatch/session/cookie_store_test.rb +++ b/actionpack/test/dispatch/session/cookie_store_test.rb @@ -5,9 +5,6 @@ class CookieStoreTest < ActionController::IntegrationTest SessionKey = '_myapp_session' SessionSecret = 'b3c631c314c0bbca50c1b2843150fe33' - # Make sure Session middleware doesnt get included in the middleware stack - ActionController::Base.session_store = nil - Verifier = ActiveSupport::MessageVerifier.new(SessionSecret, 'SHA1') SignedBar = Verifier.generate(:foo => "bar", :session_id => ActiveSupport::SecureRandom.hex(16)) -- cgit v1.2.3 From 02413baabbc2d7458377822974ee3405a91fe627 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 26 Sep 2009 20:02:47 -0500 Subject: Fix skipping memcache tests if a memcache server isn't running --- actionpack/test/dispatch/session/mem_cache_store_test.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'actionpack/test/dispatch') diff --git a/actionpack/test/dispatch/session/mem_cache_store_test.rb b/actionpack/test/dispatch/session/mem_cache_store_test.rb index d7129da187..4c6a80fdb8 100644 --- a/actionpack/test/dispatch/session/mem_cache_store_test.rb +++ b/actionpack/test/dispatch/session/mem_cache_store_test.rb @@ -32,6 +32,10 @@ class MemCacheStoreTest < ActionController::IntegrationTest end begin + require 'memcache' + memcache = MemCache.new('localhost:11211') + memcache.set('ping', '') + def test_setting_and_getting_session_value with_test_route_set do get '/set_session_value' -- cgit v1.2.3 From acfeec515111d427b3a27aef3af034922e0d9248 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 26 Sep 2009 20:51:05 -0500 Subject: Allow integration test rack app to be set with "@app" ivar instead of using open_session --- actionpack/test/dispatch/session/cookie_store_test.rb | 4 ++-- actionpack/test/dispatch/session/mem_cache_store_test.rb | 6 +++--- actionpack/test/dispatch/show_exceptions_test.rb | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'actionpack/test/dispatch') diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb index bc0b4b22a5..6241c79829 100644 --- a/actionpack/test/dispatch/session/cookie_store_test.rb +++ b/actionpack/test/dispatch/session/cookie_store_test.rb @@ -222,8 +222,8 @@ class CookieStoreTest < ActionController::IntegrationTest map.connect "/:action", :controller => "cookie_store_test/test" end options = {:key => SessionKey, :secret => SessionSecret}.merge(options) - app = ActionDispatch::Session::CookieStore.new(set, options) - @integration_session = open_session(app) + @app = ActionDispatch::Session::CookieStore.new(set, options) + reset! yield end end diff --git a/actionpack/test/dispatch/session/mem_cache_store_test.rb b/actionpack/test/dispatch/session/mem_cache_store_test.rb index 4c6a80fdb8..c2d40ae24a 100644 --- a/actionpack/test/dispatch/session/mem_cache_store_test.rb +++ b/actionpack/test/dispatch/session/mem_cache_store_test.rb @@ -101,7 +101,7 @@ class MemCacheStoreTest < ActionController::IntegrationTest get '/set_session_value', :_session_id => session_id assert_response :success - assert_equal nil, cookies['_session_id'] + assert_not_equal session_id, cookies['_session_id'] end end rescue LoadError, RuntimeError @@ -114,8 +114,8 @@ class MemCacheStoreTest < ActionController::IntegrationTest set.draw do |map| map.connect "/:action", :controller => "mem_cache_store_test/test" end - app = ActionDispatch::Session::MemCacheStore.new(set, :key => '_session_id') - @integration_session = open_session(app) + @app = ActionDispatch::Session::MemCacheStore.new(set, :key => '_session_id') + reset! yield end end diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb index d4800e4edb..9f6a93756c 100644 --- a/actionpack/test/dispatch/show_exceptions_test.rb +++ b/actionpack/test/dispatch/show_exceptions_test.rb @@ -35,7 +35,7 @@ class ShowExceptionsTest < ActionController::IntegrationTest DevelopmentApp = ActionDispatch::ShowExceptions.new(Boomer, true) test "rescue in public from a remote ip" do - @integration_session = open_session(ProductionApp) + @app = ProductionApp self.remote_addr = '208.77.188.166' get "/" @@ -52,7 +52,7 @@ class ShowExceptionsTest < ActionController::IntegrationTest end test "rescue locally from a local request" do - @integration_session = open_session(ProductionApp) + @app = ProductionApp self.remote_addr = '127.0.0.1' get "/" @@ -73,7 +73,7 @@ class ShowExceptionsTest < ActionController::IntegrationTest old_locale, I18n.locale = I18n.locale, :da begin - @integration_session = open_session(ProductionApp) + @app = ProductionApp self.remote_addr = '208.77.188.166' get "/" @@ -89,7 +89,7 @@ class ShowExceptionsTest < ActionController::IntegrationTest end test "always rescue locally in development mode" do - @integration_session = open_session(DevelopmentApp) + @app = DevelopmentApp self.remote_addr = '208.77.188.166' get "/" -- cgit v1.2.3