aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-09-30 22:27:02 +0100
committerPratik Naik <pratiknaik@gmail.com>2009-09-30 22:27:02 +0100
commitdd2779e1b83b4d867d47dd286ec0c919f5df12a9 (patch)
tree6e52ea0a329c24429f4d1d41b065e082f0ed6baa /actionpack/test/dispatch
parent329b14aa8fdd291a00d17ba12c2e0ab4c3a157cc (diff)
parent420004e030e96f2ace6e27fd622c90ee9e986677 (diff)
downloadrails-dd2779e1b83b4d867d47dd286ec0c919f5df12a9.tar.gz
rails-dd2779e1b83b4d867d47dd286ec0c919f5df12a9.tar.bz2
rails-dd2779e1b83b4d867d47dd286ec0c919f5df12a9.zip
Merge commit 'mainstream/master'
Diffstat (limited to 'actionpack/test/dispatch')
-rw-r--r--actionpack/test/dispatch/session/cookie_store_test.rb28
-rw-r--r--actionpack/test/dispatch/session/mem_cache_store_test.rb19
-rw-r--r--actionpack/test/dispatch/show_exceptions_test.rb8
-rw-r--r--actionpack/test/dispatch/static_test.rb35
4 files changed, 52 insertions, 38 deletions
diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb
index d695be0be4..6241c79829 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))
@@ -46,10 +43,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 +186,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 +216,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)
+ 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 1588918be7..c2d40ae24a 100644
--- a/actionpack/test/dispatch/session/mem_cache_store_test.rb
+++ b/actionpack/test/dispatch/session/mem_cache_store_test.rb
@@ -32,7 +32,9 @@ class MemCacheStoreTest < ActionController::IntegrationTest
end
begin
- App = ActionDispatch::Session::MemCacheStore.new(ActionController::Dispatcher.new, :key => '_session_id')
+ require 'memcache'
+ memcache = MemCache.new('localhost:11211')
+ memcache.set('ping', '')
def test_setting_and_getting_session_value
with_test_route_set do
@@ -99,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
@@ -107,20 +109,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')
+ 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 "/"
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