aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/dispatch')
-rw-r--r--actionpack/test/dispatch/response_test.rb4
-rw-r--r--actionpack/test/dispatch/routing_test.rb12
-rw-r--r--actionpack/test/dispatch/session/cookie_store_test.rb66
-rw-r--r--actionpack/test/dispatch/session/mem_cache_store_test.rb7
-rw-r--r--actionpack/test/dispatch/session/test_session_test.rb12
5 files changed, 41 insertions, 60 deletions
diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb
index c7f7f3102d..c20fa10f63 100644
--- a/actionpack/test/dispatch/response_test.rb
+++ b/actionpack/test/dispatch/response_test.rb
@@ -113,6 +113,10 @@ class ResponseTest < ActiveSupport::TestCase
status, headers, body = @response.to_a
assert_equal "user_name=david; path=/\nlogin=foo%26bar; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT", headers["Set-Cookie"]
assert_equal({"login" => "foo&bar", "user_name" => "david"}, @response.cookies)
+
+ @response.delete_cookie("login")
+ status, headers, body = @response.to_a
+ assert_equal({"user_name" => "david", "login" => nil}, @response.cookies)
end
test "read cache control" do
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 651a7a6be0..180889ddf2 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -186,6 +186,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
resources :products, :constraints => { :id => /\d{4}/ } do
+ root :to => "products#root"
+ get :favorite, :on => :collection
resources :images
end
@@ -963,7 +965,9 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
get '/products/1'
assert_equal 'pass', @response.headers['X-Cascade']
get '/products'
- assert_equal 'products#index', @response.body
+ assert_equal 'products#root', @response.body
+ get '/products/favorite'
+ assert_equal 'products#favorite', @response.body
get '/products/0001'
assert_equal 'products#show', @response.body
@@ -981,6 +985,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
+ def test_root_works_in_the_resources_scope
+ get '/products'
+ assert_equal 'products#root', @response.body
+ assert_equal '/products', products_root_path
+ end
+
def test_module_scope
with_test_routes do
get '/token'
diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb
index d2c1758af1..21d11ff31c 100644
--- a/actionpack/test/dispatch/session/cookie_store_test.rb
+++ b/actionpack/test/dispatch/session/cookie_store_test.rb
@@ -55,42 +55,13 @@ class CookieStoreTest < ActionController::IntegrationTest
}
end
- def test_raises_argument_error_if_missing_secret
- assert_raise(ArgumentError, nil.inspect) {
- ActionDispatch::Session::CookieStore.new(nil,
- :key => SessionKey, :secret => nil)
- }
-
- assert_raise(ArgumentError, ''.inspect) {
- ActionDispatch::Session::CookieStore.new(nil,
- :key => SessionKey, :secret => '')
- }
- end
-
- def test_raises_argument_error_if_secret_is_probably_insecure
- assert_raise(ArgumentError, "password".inspect) {
- ActionDispatch::Session::CookieStore.new(nil,
- :key => SessionKey, :secret => "password")
- }
-
- assert_raise(ArgumentError, "secret".inspect) {
- ActionDispatch::Session::CookieStore.new(nil,
- :key => SessionKey, :secret => "secret")
- }
-
- assert_raise(ArgumentError, "12345678901234567890123456789".inspect) {
- ActionDispatch::Session::CookieStore.new(nil,
- :key => SessionKey, :secret => "12345678901234567890123456789")
- }
- end
-
def test_setting_session_value
with_test_route_set do
get '/set_session_value'
assert_response :success
assert_equal "_myapp_session=#{response.body}; path=/; HttpOnly",
headers['Set-Cookie']
- end
+ end
end
def test_getting_session_value
@@ -99,7 +70,7 @@ class CookieStoreTest < ActionController::IntegrationTest
get '/get_session_value'
assert_response :success
assert_equal 'foo: "bar"', response.body
- end
+ end
end
def test_getting_session_id
@@ -127,7 +98,7 @@ class CookieStoreTest < ActionController::IntegrationTest
def test_close_raises_when_data_overflows
with_test_route_set do
- assert_raise(ActionDispatch::Session::CookieStore::CookieOverflow) {
+ assert_raise(ActionDispatch::Cookies::CookieOverflow) {
get '/raise_data_overflow'
}
end
@@ -209,30 +180,33 @@ class CookieStoreTest < ActionController::IntegrationTest
get '/no_session_access'
assert_response :success
- # Mystery bug that came up in 2.3 as well. What is this trying to test?!
- # assert_equal "_myapp_session=#{cookie_body}; path=/; expires=#{expected_expiry}; HttpOnly",
- # headers['Set-Cookie']
+ assert_equal "_myapp_session=#{cookie_body}; path=/; expires=#{expected_expiry}; HttpOnly",
+ headers['Set-Cookie']
end
end
private
+
+ # Overwrite get to send SessionSecret in env hash
+ def get(path, parameters = nil, env = {})
+ env["action_dispatch.secret_token"] ||= SessionSecret
+ super
+ end
+
def with_test_route_set(options = {})
with_routing do |set|
set.draw do |map|
match ':action', :to => ::CookieStoreTest::TestController
end
- options = {:key => SessionKey, :secret => SessionSecret}.merge(options)
- @app = ActionDispatch::Session::CookieStore.new(set, options)
+
+ options = { :key => SessionKey }.merge!(options)
+
+ @app = self.class.build_app(set) do |middleware|
+ middleware.use ActionDispatch::Session::CookieStore, options
+ middleware.delete "ActionDispatch::ShowExceptions"
+ end
+
yield
end
end
-
- def unmarshal_session(cookie_string)
- session = Rack::Utils.parse_query(cookie_string, ';,').inject({}) {|h,(k,v)|
- h[k] = Array === v ? v.first : v
- h
- }[SessionKey]
- verifier = ActiveSupport::MessageVerifier.new(SessionSecret, 'SHA1')
- verifier.verify(session)
- 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 5a1dcb4dab..8858a398e0 100644
--- a/actionpack/test/dispatch/session/mem_cache_store_test.rb
+++ b/actionpack/test/dispatch/session/mem_cache_store_test.rb
@@ -114,7 +114,12 @@ class MemCacheStoreTest < ActionController::IntegrationTest
set.draw do |map|
match ':action', :to => ::MemCacheStoreTest::TestController
end
- @app = ActionDispatch::Session::MemCacheStore.new(set, :key => '_session_id')
+
+ @app = self.class.build_app(set) do |middleware|
+ middleware.use ActionDispatch::Session::MemCacheStore, :key => '_session_id'
+ middleware.delete "ActionDispatch::ShowExceptions"
+ end
+
yield
end
end
diff --git a/actionpack/test/dispatch/session/test_session_test.rb b/actionpack/test/dispatch/session/test_session_test.rb
index c8dc4ab461..31ce97a25b 100644
--- a/actionpack/test/dispatch/session/test_session_test.rb
+++ b/actionpack/test/dispatch/session/test_session_test.rb
@@ -2,18 +2,6 @@ require 'abstract_unit'
require 'stringio'
class ActionController::TestSessionTest < ActiveSupport::TestCase
- def test_calling_delete_without_parameters_raises_deprecation_warning_and_calls_to_clear_test_session
- assert_deprecated(/use clear instead/){ ActionController::TestSession.new.delete }
- end
-
- def test_calling_update_without_parameters_raises_deprecation_warning_and_calls_to_clear_test_session
- assert_deprecated(/use replace instead/){ ActionController::TestSession.new.update }
- end
-
- def test_calling_close_raises_deprecation_warning
- assert_deprecated(/sessions should no longer be closed/){ ActionController::TestSession.new.close }
- end
-
def test_ctor_allows_setting
session = ActionController::TestSession.new({:one => 'one', :two => 'two'})
assert_equal('one', session[:one])