Instiki 0.16.5

Update to Rails 2.3.2 (the stable Rails 2.3 release).
Add audio/speex support
Update CHANGELOG
Bump version number
This commit is contained in:
Jacques Distler 2009-03-16 09:55:30 -05:00
parent 801d307405
commit e2ccdfd812
264 changed files with 4850 additions and 1906 deletions

View file

@ -76,7 +76,7 @@ class AssertSelectTest < ActionController::TestCase
end
def assert_failure(message, &block)
e = assert_raises(Assertion, &block)
e = assert_raise(Assertion, &block)
assert_match(message, e.message) if Regexp === message
assert_equal(message, e.message) if String === message
end
@ -95,24 +95,24 @@ class AssertSelectTest < ActionController::TestCase
def test_equality_true_false
render_html %Q{<div id="1"></div><div id="2"></div>}
assert_nothing_raised { assert_select "div" }
assert_raises(Assertion) { assert_select "p" }
assert_raise(Assertion) { assert_select "p" }
assert_nothing_raised { assert_select "div", true }
assert_raises(Assertion) { assert_select "p", true }
assert_raises(Assertion) { assert_select "div", false }
assert_raise(Assertion) { assert_select "p", true }
assert_raise(Assertion) { assert_select "div", false }
assert_nothing_raised { assert_select "p", false }
end
def test_equality_string_and_regexp
render_html %Q{<div id="1">foo</div><div id="2">foo</div>}
assert_nothing_raised { assert_select "div", "foo" }
assert_raises(Assertion) { assert_select "div", "bar" }
assert_raise(Assertion) { assert_select "div", "bar" }
assert_nothing_raised { assert_select "div", :text=>"foo" }
assert_raises(Assertion) { assert_select "div", :text=>"bar" }
assert_raise(Assertion) { assert_select "div", :text=>"bar" }
assert_nothing_raised { assert_select "div", /(foo|bar)/ }
assert_raises(Assertion) { assert_select "div", /foobar/ }
assert_raise(Assertion) { assert_select "div", /foobar/ }
assert_nothing_raised { assert_select "div", :text=>/(foo|bar)/ }
assert_raises(Assertion) { assert_select "div", :text=>/foobar/ }
assert_raises(Assertion) { assert_select "p", :text=>/foobar/ }
assert_raise(Assertion) { assert_select "div", :text=>/foobar/ }
assert_raise(Assertion) { assert_select "p", :text=>/foobar/ }
end
def test_equality_of_html
@ -120,17 +120,17 @@ class AssertSelectTest < ActionController::TestCase
text = "\"This is not a big problem,\" he said."
html = "<em>\"This is <strong>not</strong> a big problem,\"</em> he said."
assert_nothing_raised { assert_select "p", text }
assert_raises(Assertion) { assert_select "p", html }
assert_raise(Assertion) { assert_select "p", html }
assert_nothing_raised { assert_select "p", :html=>html }
assert_raises(Assertion) { assert_select "p", :html=>text }
assert_raise(Assertion) { assert_select "p", :html=>text }
# No stripping for pre.
render_html %Q{<pre>\n<em>"This is <strong>not</strong> a big problem,"</em> he said.\n</pre>}
text = "\n\"This is not a big problem,\" he said.\n"
html = "\n<em>\"This is <strong>not</strong> a big problem,\"</em> he said.\n"
assert_nothing_raised { assert_select "pre", text }
assert_raises(Assertion) { assert_select "pre", html }
assert_raise(Assertion) { assert_select "pre", html }
assert_nothing_raised { assert_select "pre", :html=>html }
assert_raises(Assertion) { assert_select "pre", :html=>text }
assert_raise(Assertion) { assert_select "pre", :html=>text }
end
def test_counts
@ -210,12 +210,12 @@ class AssertSelectTest < ActionController::TestCase
assert_nothing_raised { assert_select "div", "bar" }
assert_nothing_raised { assert_select "div", /\w*/ }
assert_nothing_raised { assert_select "div", /\w*/, :count=>2 }
assert_raises(Assertion) { assert_select "div", :text=>"foo", :count=>2 }
assert_raise(Assertion) { assert_select "div", :text=>"foo", :count=>2 }
assert_nothing_raised { assert_select "div", :html=>"<span>bar</span>" }
assert_nothing_raised { assert_select "div", :html=>"<span>bar</span>" }
assert_nothing_raised { assert_select "div", :html=>/\w*/ }
assert_nothing_raised { assert_select "div", :html=>/\w*/, :count=>2 }
assert_raises(Assertion) { assert_select "div", :html=>"<span>foo</span>", :count=>2 }
assert_raise(Assertion) { assert_select "div", :html=>"<span>foo</span>", :count=>2 }
end
end
@ -253,7 +253,12 @@ class AssertSelectTest < ActionController::TestCase
page.insert_html :top, "test1", "<div id=\"1\">foo</div>"
page.insert_html :bottom, "test2", "<div id=\"2\">foo</div>"
end
assert_raises(Assertion) {assert_select_rjs :insert, :top, "test2"}
assert_raise(Assertion) {assert_select_rjs :insert, :top, "test2"}
end
def test_elect_with_xml_namespace_attributes
render_html %Q{<link xlink:href="http://nowhere.com"></link>}
assert_nothing_raised { assert_select "link[xlink:href=http://nowhere.com]" }
end
#
@ -331,7 +336,7 @@ class AssertSelectTest < ActionController::TestCase
# Test that we fail if there is nothing to pick.
def test_assert_select_rjs_fails_if_nothing_to_pick
render_rjs { }
assert_raises(Assertion) { assert_select_rjs }
assert_raise(Assertion) { assert_select_rjs }
end
def test_assert_select_rjs_with_unicode
@ -346,10 +351,10 @@ class AssertSelectTest < ActionController::TestCase
if str.respond_to?(:force_encoding)
str.force_encoding(Encoding::UTF_8)
assert_select str, /\343\203\201..\343\203\210/u
assert_raises(Assertion) { assert_select str, /\343\203\201.\343\203\210/u }
assert_raise(Assertion) { assert_select str, /\343\203\201.\343\203\210/u }
else
assert_select str, Regexp.new("\343\203\201..\343\203\210",0,'U')
assert_raises(Assertion) { assert_select str, Regexp.new("\343\203\201.\343\203\210",0,'U') }
assert_raise(Assertion) { assert_select str, Regexp.new("\343\203\201.\343\203\210",0,'U') }
end
end
end
@ -373,7 +378,7 @@ class AssertSelectTest < ActionController::TestCase
assert_select "div", 1
assert_select "#3"
end
assert_raises(Assertion) { assert_select_rjs "test4" }
assert_raise(Assertion) { assert_select_rjs "test4" }
end
def test_assert_select_rjs_for_replace
@ -391,7 +396,7 @@ class AssertSelectTest < ActionController::TestCase
assert_select "div", 1
assert_select "#1"
end
assert_raises(Assertion) { assert_select_rjs :replace, "test2" }
assert_raise(Assertion) { assert_select_rjs :replace, "test2" }
# Replace HTML.
assert_select_rjs :replace_html do
assert_select "div", 1
@ -401,7 +406,7 @@ class AssertSelectTest < ActionController::TestCase
assert_select "div", 1
assert_select "#2"
end
assert_raises(Assertion) { assert_select_rjs :replace_html, "test1" }
assert_raise(Assertion) { assert_select_rjs :replace_html, "test1" }
end
def test_assert_select_rjs_for_chained_replace
@ -419,7 +424,7 @@ class AssertSelectTest < ActionController::TestCase
assert_select "div", 1
assert_select "#1"
end
assert_raises(Assertion) { assert_select_rjs :chained_replace, "test2" }
assert_raise(Assertion) { assert_select_rjs :chained_replace, "test2" }
# Replace HTML.
assert_select_rjs :chained_replace_html do
assert_select "div", 1
@ -429,7 +434,7 @@ class AssertSelectTest < ActionController::TestCase
assert_select "div", 1
assert_select "#2"
end
assert_raises(Assertion) { assert_select_rjs :replace_html, "test1" }
assert_raise(Assertion) { assert_select_rjs :replace_html, "test1" }
end
# Simple remove
@ -575,7 +580,7 @@ class AssertSelectTest < ActionController::TestCase
assert_select "div", 1
assert_select "#3"
end
assert_raises(Assertion) { assert_select_rjs :insert_html, "test1" }
assert_raise(Assertion) { assert_select_rjs :insert_html, "test1" }
end
# Positioned insert.
@ -608,8 +613,8 @@ class AssertSelectTest < ActionController::TestCase
end
def test_assert_select_rjs_raise_errors
assert_raises(ArgumentError) { assert_select_rjs(:destroy) }
assert_raises(ArgumentError) { assert_select_rjs(:insert, :left) }
assert_raise(ArgumentError) { assert_select_rjs(:destroy) }
assert_raise(ArgumentError) { assert_select_rjs(:insert, :left) }
end
# Simple selection from a single result.
@ -701,7 +706,7 @@ EOF
#
def test_assert_select_email
assert_raises(Assertion) { assert_select_email {} }
assert_raise(Assertion) { assert_select_email {} }
AssertSelectMailer.deliver_test "<div><p>foo</p><p>bar</p></div>"
assert_select_email do
assert_select "div:root" do

View file

@ -428,6 +428,20 @@ class ActionCacheTest < ActionController::TestCase
assert_equal 'application/xml', @response.content_type
end
def test_correct_content_type_is_returned_for_cache_hit_on_action_with_string_key
# run it twice to cache it the first time
get :show, :format => 'xml'
get :show, :format => 'xml'
assert_equal 'application/xml', @response.content_type
end
def test_correct_content_type_is_returned_for_cache_hit_on_action_with_string_key_from_proc
# run it twice to cache it the first time
get :edit, :id => 1, :format => 'xml'
get :edit, :id => 1, :format => 'xml'
assert_equal 'application/xml', @response.content_type
end
def test_empty_path_is_normalized
@mock_controller.mock_url_for = 'http://example.org/'
@mock_controller.mock_path = '/'

View file

@ -9,3 +9,11 @@ end
class GoodCustomer < Customer
end
module Quiz
class Question < Struct.new(:name, :id)
def to_param
id.to_s
end
end
end

View file

@ -134,7 +134,7 @@ HTML
end
def test_invalid_document_raises_exception_when_strict
assert_raises RuntimeError do
assert_raise RuntimeError do
doc = HTML::Document.new("<html>
<table>
<tr>

View file

@ -5,7 +5,8 @@ class HttpDigestAuthenticationTest < ActionController::TestCase
before_filter :authenticate, :only => :index
before_filter :authenticate_with_request, :only => :display
USERS = { 'lifo' => 'world', 'pretty' => 'please' }
USERS = { 'lifo' => 'world', 'pretty' => 'please',
'dhh' => ::Digest::MD5::hexdigest(["dhh","SuperSecret","secret"].join(":"))}
def index
render :text => "Hello Secret"
@ -107,8 +108,42 @@ class HttpDigestAuthenticationTest < ActionController::TestCase
assert_equal 'Definitely Maybe', @response.body
end
test "authentication request with relative URI" do
@request.env['HTTP_AUTHORIZATION'] = encode_credentials(:uri => "/", :username => 'pretty', :password => 'please')
test "authentication request with valid credential and nil session" do
@request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'please')
# session_id = "" in functional test, but is +nil+ in real life
@request.session.session_id = nil
get :display
assert_response :success
assert assigns(:logged_in)
assert_equal 'Definitely Maybe', @response.body
end
test "authentication request with request-uri that doesn't match credentials digest-uri" do
@request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'please')
@request.env['REQUEST_URI'] = "/http_digest_authentication_test/dummy_digest/altered/uri"
get :display
assert_response :unauthorized
assert_equal "Authentication Failed", @response.body
end
test "authentication request with absolute uri" do
@request.env['HTTP_AUTHORIZATION'] = encode_credentials(:uri => "http://test.host/http_digest_authentication_test/dummy_digest/display",
:username => 'pretty', :password => 'please')
@request.env['REQUEST_URI'] = "http://test.host/http_digest_authentication_test/dummy_digest/display"
get :display
assert_response :success
assert assigns(:logged_in)
assert_equal 'Definitely Maybe', @response.body
end
test "authentication request with password stored as ha1 digest hash" do
@request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'dhh',
:password => ::Digest::MD5::hexdigest(["dhh","SuperSecret","secret"].join(":")),
:password_is_ha1 => true)
get :display
assert_response :success
@ -119,18 +154,22 @@ class HttpDigestAuthenticationTest < ActionController::TestCase
private
def encode_credentials(options)
options.reverse_merge!(:nc => "00000001", :cnonce => "0a4f113b")
options.reverse_merge!(:nc => "00000001", :cnonce => "0a4f113b", :password_is_ha1 => false)
password = options.delete(:password)
# Perform unautheticated get to retrieve digest parameters to use on subsequent request
# Set in /initializers/session_store.rb. Used as secret in generating nonce
# to prevent tampering of timestamp
ActionController::Base.session_options[:secret] = "session_options_secret"
# Perform unauthenticated GET to retrieve digest parameters to use on subsequent request
get :index
assert_response :unauthorized
credentials = decode_credentials(@response.headers['WWW-Authenticate'])
credentials.merge!(options)
credentials.reverse_merge!(:uri => "http://#{@request.host}#{@request.env['REQUEST_URI']}")
ActionController::HttpAuthentication::Digest.encode_credentials("GET", credentials, password)
credentials.reverse_merge!(:uri => "#{@request.env['REQUEST_URI']}")
ActionController::HttpAuthentication::Digest.encode_credentials("GET", credentials, password, options[:password_is_ha1])
end
def decode_credentials(header)

View file

@ -2,7 +2,7 @@ require 'abstract_unit'
class SessionTest < Test::Unit::TestCase
StubApp = lambda { |env|
[200, {"Content-Type" => "text/html", "Content-Length" => "13"}, "Hello, World!"]
[200, {"Content-Type" => "text/html", "Content-Length" => "13"}, ["Hello, World!"]]
}
def setup
@ -389,9 +389,9 @@ class MetalTest < ActionController::IntegrationTest
class Poller
def self.call(env)
if env["PATH_INFO"] =~ /^\/success/
[200, {"Content-Type" => "text/plain", "Content-Length" => "12"}, "Hello World!"]
[200, {"Content-Type" => "text/plain", "Content-Length" => "12"}, ["Hello World!"]]
else
[404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, '']
[404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []]
end
end
end

View file

@ -79,6 +79,10 @@ end
class DefaultLayoutController < LayoutTest
end
class AbsolutePathLayoutController < LayoutTest
layout File.expand_path(File.expand_path(__FILE__) + '/../../fixtures/layout_tests/layouts/layout_test.rhtml')
end
class HasOwnLayoutController < LayoutTest
layout 'item'
end
@ -137,12 +141,18 @@ class LayoutSetInResponseTest < ActionController::TestCase
ensure
ActionController::Base.exempt_from_layout.delete(/\.rhtml$/)
end
def test_layout_is_picked_from_the_controller_instances_view_path
@controller = PrependsViewPathController.new
get :hello
assert_equal 'layouts/alt', @response.layout
end
def test_absolute_pathed_layout
@controller = AbsolutePathLayoutController.new
get :hello
assert_equal "layout_test.rhtml hello.rhtml", @response.body.strip
end
end
class RenderWithTemplateOptionController < LayoutTest

View file

@ -469,7 +469,7 @@ class MimeControllerTest < ActionController::TestCase
assert_equal '<html><div id="html_missing">Hello future from Firefox!</div></html>', @response.body
@request.accept = "text/iphone"
assert_raises(ActionView::MissingTemplate) { get :iphone_with_html_response_type_without_layout }
assert_raise(ActionView::MissingTemplate) { get :iphone_with_html_response_type_without_layout }
end
end

View file

@ -18,6 +18,20 @@ class Tag < Article
def response_id; 1 end
end
class Tax
attr_reader :id
def save; @id = 1 end
def new_record?; @id.nil? end
def name
model = self.class.name.downcase
@id.nil? ? "new #{model}" : "#{model} ##{@id}"
end
end
class Fax < Tax
def store_id; 1 end
end
# TODO: test nested models
class Response::Nested < Response; end
@ -27,6 +41,8 @@ class PolymorphicRoutesTest < ActiveSupport::TestCase
def setup
@article = Article.new
@response = Response.new
@tax = Tax.new
@fax = Fax.new
end
def test_with_record
@ -205,4 +221,73 @@ class PolymorphicRoutesTest < ActiveSupport::TestCase
polymorphic_url(path)
end
end
# Tests for names where .plural.singular doesn't round-trip
def test_with_irregular_plural_record
@tax.save
expects(:taxis_url).with(@tax)
polymorphic_url(@tax)
end
def test_with_irregular_plural_new_record
expects(:taxes_url).with()
@tax.expects(:new_record?).returns(true)
polymorphic_url(@tax)
end
def test_with_irregular_plural_record_and_action
expects(:new_taxis_url).with()
@tax.expects(:new_record?).never
polymorphic_url(@tax, :action => 'new')
end
def test_irregular_plural_url_helper_prefixed_with_new
expects(:new_taxis_url).with()
new_polymorphic_url(@tax)
end
def test_irregular_plural_url_helper_prefixed_with_edit
@tax.save
expects(:edit_taxis_url).with(@tax)
edit_polymorphic_url(@tax)
end
def test_with_nested_irregular_plurals
@fax.save
expects(:taxis_faxis_url).with(@tax, @fax)
polymorphic_url([@tax, @fax])
end
def test_with_nested_unsaved_irregular_plurals
expects(:taxis_faxes_url).with(@tax)
polymorphic_url([@tax, @fax])
end
def test_new_with_irregular_plural_array_and_namespace
expects(:new_admin_taxis_url).with()
polymorphic_url([:admin, @tax], :action => 'new')
end
def test_unsaved_with_irregular_plural_array_and_namespace
expects(:admin_taxes_url).with()
polymorphic_url([:admin, @tax])
end
def test_nesting_with_irregular_plurals_and_array_ending_in_singleton_resource
expects(:taxis_faxis_url).with(@tax)
polymorphic_url([@tax, :faxis])
end
def test_with_array_containing_single_irregular_plural_object
@tax.save
expects(:taxis_url).with(@tax)
polymorphic_url([nil, @tax])
end
def test_with_array_containing_single_name_irregular_plural
@tax.save
expects(:taxes_url)
polymorphic_url([:taxes])
end
end

View file

@ -212,7 +212,7 @@ class RedirectTest < ActionController::TestCase
end
def test_redirect_to_back_with_no_referer
assert_raises(ActionController::RedirectBackError) {
assert_raise(ActionController::RedirectBackError) {
@request.env["HTTP_REFERER"] = nil
get :redirect_to_back
}
@ -239,7 +239,7 @@ class RedirectTest < ActionController::TestCase
end
def test_redirect_to_nil
assert_raises(ActionController::ActionControllerError) do
assert_raise(ActionController::ActionControllerError) do
get :redirect_to_nil
end
end

View file

@ -157,6 +157,11 @@ class TestController < ActionController::Base
render :file => 'test/dot.directory/render_file_with_ivar'
end
def render_file_using_pathname
@secret = 'in the sauce'
render :file => Pathname.new(File.dirname(__FILE__)).join('..', 'fixtures', 'test', 'dot.directory', 'render_file_with_ivar.erb')
end
def render_file_from_template
@secret = 'in the sauce'
@path = File.expand_path(File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb'))
@ -313,6 +318,10 @@ class TestController < ActionController::Base
def render_implicit_js_template_without_layout
end
def render_html_explicit_template_and_layout
render :template => 'test/render_implicit_html_template_from_xhr_request', :layout => 'layouts/default_html'
end
def formatted_html_erb
end
@ -678,6 +687,14 @@ class TestController < ActionController::Base
render :partial => "hash_object", :object => {:first_name => "Sam"}
end
def partial_with_nested_object
render :partial => "quiz/questions/question", :object => Quiz::Question.new("first")
end
def partial_with_nested_object_shorthand
render Quiz::Question.new("first")
end
def partial_hash_collection
render :partial => "hash_object", :collection => [ {:first_name => "Pratik"}, {:first_name => "Amy"} ]
end
@ -720,6 +737,8 @@ class TestController < ActionController::Base
"delete_with_js", "update_page", "update_page_with_instance_variables"
"layouts/standard"
when "render_implicit_js_template_without_layout"
"layouts/default_html"
when "action_talk_to_layout", "layout_overriding_layout"
"layouts/talk_from_action"
when "render_implicit_html_template_from_xhr_request"
@ -817,6 +836,11 @@ class RenderTest < ActionController::TestCase
assert_equal "<html>hello world, I'm here!</html>", @response.body
end
def test_xhr_with_render_text_and_layout
xhr :get, :render_text_hello_world_with_layout
assert_equal "<html>hello world, I'm here!</html>", @response.body
end
def test_do_with_render_action_and_layout_false
get :hello_world_with_layout_false
assert_equal 'Hello world!', @response.body
@ -842,6 +866,11 @@ class RenderTest < ActionController::TestCase
assert_equal "The secret is in the sauce\n", @response.body
end
def test_render_file_using_pathname
get :render_file_using_pathname
assert_equal "The secret is in the sauce\n", @response.body
end
def test_render_file_with_locals
get :render_file_with_locals
assert_equal "The secret is in the sauce\n", @response.body
@ -918,11 +947,11 @@ class RenderTest < ActionController::TestCase
end
def test_attempt_to_access_object_method
assert_raises(ActionController::UnknownAction, "No action responded to [clone]") { get :clone }
assert_raise(ActionController::UnknownAction, "No action responded to [clone]") { get :clone }
end
def test_private_methods
assert_raises(ActionController::UnknownAction, "No action responded to [determine_layout]") { get :determine_layout }
assert_raise(ActionController::UnknownAction, "No action responded to [determine_layout]") { get :determine_layout }
end
def test_access_to_request_in_view
@ -1056,6 +1085,11 @@ class RenderTest < ActionController::TestCase
assert_equal "XHR!\nHello HTML!", @response.body
end
def test_should_render_explicit_html_template_with_html_layout
xhr :get, :render_html_explicit_template_and_layout
assert_equal "<html>Hello HTML!</html>\n", @response.body
end
def test_should_implicitly_render_js_template_without_layout
get :render_implicit_js_template_without_layout, :format => :js
assert_no_match /<html>/, @response.body
@ -1149,7 +1183,7 @@ class RenderTest < ActionController::TestCase
end
def test_bad_render_to_string_still_throws_exception
assert_raises(ActionView::MissingTemplate) { get :render_to_string_with_exception }
assert_raise(ActionView::MissingTemplate) { get :render_to_string_with_exception }
end
def test_render_to_string_that_throws_caught_exception_doesnt_break_assigns
@ -1174,15 +1208,15 @@ class RenderTest < ActionController::TestCase
end
def test_double_render
assert_raises(ActionController::DoubleRenderError) { get :double_render }
assert_raise(ActionController::DoubleRenderError) { get :double_render }
end
def test_double_redirect
assert_raises(ActionController::DoubleRenderError) { get :double_redirect }
assert_raise(ActionController::DoubleRenderError) { get :double_redirect }
end
def test_render_and_redirect
assert_raises(ActionController::DoubleRenderError) { get :render_and_redirect }
assert_raise(ActionController::DoubleRenderError) { get :render_and_redirect }
end
# specify the one exception to double render rule - render_to_string followed by render
@ -1463,6 +1497,16 @@ class RenderTest < ActionController::TestCase
assert_equal "Sam\nmaS\n", @response.body
end
def test_partial_with_nested_object
get :partial_with_nested_object
assert_equal "first", @response.body
end
def test_partial_with_nested_object_shorthand
get :partial_with_nested_object_shorthand
assert_equal "first", @response.body
end
def test_hash_partial_collection
get :partial_hash_collection
assert_equal "Pratik\nkitarP\nAmy\nymA\n", @response.body
@ -1481,7 +1525,7 @@ class RenderTest < ActionController::TestCase
end
def test_render_missing_partial_template
assert_raises(ActionView::MissingTemplate) do
assert_raise(ActionView::MissingTemplate) do
get :missing_partial
end
end
@ -1509,7 +1553,7 @@ class ExpiresInRenderTest < ActionController::TestCase
assert_equal "max-age=60, private", @response.headers["Cache-Control"]
end
def test_expires_in_header
def test_expires_in_header_with_public
get :conditional_hello_with_expires_in_with_public
assert_equal "max-age=60, public", @response.headers["Cache-Control"]
end

View file

@ -103,7 +103,7 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest
test "does not create tempfile if no file has been selected" do
params = parse_multipart('none')
assert_equal %w(files submit-name), params.keys.sort
assert_equal %w(submit-name), params.keys.sort
assert_equal 'Larry', params['submit-name']
assert_equal nil, params['files']
end

View file

@ -79,17 +79,17 @@ module RequestForgeryProtectionTests
def test_should_not_allow_html_post_without_token
@request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s
assert_raises(ActionController::InvalidAuthenticityToken) { post :index, :format => :html }
assert_raise(ActionController::InvalidAuthenticityToken) { post :index, :format => :html }
end
def test_should_not_allow_html_put_without_token
@request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s
assert_raises(ActionController::InvalidAuthenticityToken) { put :index, :format => :html }
assert_raise(ActionController::InvalidAuthenticityToken) { put :index, :format => :html }
end
def test_should_not_allow_html_delete_without_token
@request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s
assert_raises(ActionController::InvalidAuthenticityToken) { delete :index, :format => :html }
assert_raise(ActionController::InvalidAuthenticityToken) { delete :index, :format => :html }
end
def test_should_allow_api_formatted_post_without_token
@ -111,42 +111,42 @@ module RequestForgeryProtectionTests
end
def test_should_not_allow_api_formatted_post_sent_as_url_encoded_form_without_token
assert_raises(ActionController::InvalidAuthenticityToken) do
assert_raise(ActionController::InvalidAuthenticityToken) do
@request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s
post :index, :format => 'xml'
end
end
def test_should_not_allow_api_formatted_put_sent_as_url_encoded_form_without_token
assert_raises(ActionController::InvalidAuthenticityToken) do
assert_raise(ActionController::InvalidAuthenticityToken) do
@request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s
put :index, :format => 'xml'
end
end
def test_should_not_allow_api_formatted_delete_sent_as_url_encoded_form_without_token
assert_raises(ActionController::InvalidAuthenticityToken) do
assert_raise(ActionController::InvalidAuthenticityToken) do
@request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s
delete :index, :format => 'xml'
end
end
def test_should_not_allow_api_formatted_post_sent_as_multipart_form_without_token
assert_raises(ActionController::InvalidAuthenticityToken) do
assert_raise(ActionController::InvalidAuthenticityToken) do
@request.env['CONTENT_TYPE'] = Mime::MULTIPART_FORM.to_s
post :index, :format => 'xml'
end
end
def test_should_not_allow_api_formatted_put_sent_as_multipart_form_without_token
assert_raises(ActionController::InvalidAuthenticityToken) do
assert_raise(ActionController::InvalidAuthenticityToken) do
@request.env['CONTENT_TYPE'] = Mime::MULTIPART_FORM.to_s
put :index, :format => 'xml'
end
end
def test_should_not_allow_api_formatted_delete_sent_as_multipart_form_without_token
assert_raises(ActionController::InvalidAuthenticityToken) do
assert_raise(ActionController::InvalidAuthenticityToken) do
@request.env['CONTENT_TYPE'] = Mime::MULTIPART_FORM.to_s
delete :index, :format => 'xml'
end

View file

@ -59,7 +59,7 @@ class RequestTest < ActiveSupport::TestCase
assert_equal '3.4.5.6', @request.remote_ip
@request.env['HTTP_CLIENT_IP'] = '8.8.8.8'
e = assert_raises(ActionController::ActionControllerError) {
e = assert_raise(ActionController::ActionControllerError) {
@request.remote_ip
}
assert_match /IP spoofing attack/, e.message
@ -297,7 +297,7 @@ class RequestTest < ActiveSupport::TestCase
end
def test_invalid_http_method_raises_exception
assert_raises(ActionController::UnknownHttpMethod) do
assert_raise(ActionController::UnknownHttpMethod) do
self.request_method = :random_method
@request.request_method
end
@ -311,7 +311,7 @@ class RequestTest < ActiveSupport::TestCase
end
def test_invalid_method_hacking_on_post_raises_exception
assert_raises(ActionController::UnknownHttpMethod) do
assert_raise(ActionController::UnknownHttpMethod) do
self.request_method = :_random_method
@request.request_method
end

View file

@ -99,7 +99,7 @@ class ResourcesTest < ActionController::TestCase
expected_options = {:controller => 'messages', :action => 'show', :id => '1.1.1'}
with_restful_routing :messages do
assert_raises(ActionController::RoutingError) do
assert_raise(ActionController::RoutingError) do
assert_recognizes(expected_options, :path => 'messages/1.1.1', :method => :get)
end
end
@ -175,6 +175,24 @@ class ResourcesTest < ActionController::TestCase
end
end
def test_with_collection_actions_and_name_prefix_and_member_action_with_same_name
actions = { 'a' => :get }
with_restful_routing :messages, :path_prefix => '/threads/:thread_id', :name_prefix => "thread_", :collection => actions, :member => actions do
assert_restful_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options|
actions.each do |action, method|
assert_recognizes(options.merge(:action => action), :path => "/threads/1/messages/#{action}", :method => method)
end
end
assert_restful_named_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options|
actions.keys.each do |action|
assert_named_route "/threads/1/messages/#{action}", "#{action}_thread_messages_path", :action => action
end
end
end
end
def test_with_collection_action_and_name_prefix_and_formatted
actions = { 'a' => :get, 'b' => :put, 'c' => :post, 'd' => :delete }
@ -209,6 +227,14 @@ class ResourcesTest < ActionController::TestCase
end
end
def test_with_member_action_and_requirement
expected_options = {:controller => 'messages', :action => 'mark', :id => '1.1.1'}
with_restful_routing(:messages, :requirements => {:id => /[0-9]\.[0-9]\.[0-9]/}, :member => { :mark => :get }) do
assert_recognizes(expected_options, :path => 'messages/1.1.1/mark', :method => :get)
end
end
def test_member_when_override_paths_for_default_restful_actions_with
[:put, :post].each do |method|
with_restful_routing :messages, :member => { :mark => method }, :path_names => {:new => 'nuevo'} do
@ -325,7 +351,7 @@ class ResourcesTest < ActionController::TestCase
with_restful_routing :messages do
assert_restful_routes_for :messages do |options|
assert_recognizes(options.merge(:action => "new"), :path => "/messages/new", :method => :get)
assert_raises(ActionController::MethodNotAllowed) do
assert_raise(ActionController::MethodNotAllowed) do
ActionController::Routing::Routes.recognize_path("/messages/new", :method => :post)
end
end
@ -406,6 +432,34 @@ class ResourcesTest < ActionController::TestCase
end
end
def test_shallow_nested_restful_routes_with_namespaces
with_routing do |set|
set.draw do |map|
map.namespace :backoffice do |map|
map.namespace :admin do |map|
map.resources :products, :shallow => true do |map|
map.resources :images
end
end
end
end
assert_simply_restful_for :products,
:controller => 'backoffice/admin/products',
:namespace => 'backoffice/admin/',
:name_prefix => 'backoffice_admin_',
:path_prefix => 'backoffice/admin/',
:shallow => true
assert_simply_restful_for :images,
:controller => 'backoffice/admin/images',
:namespace => 'backoffice/admin/',
:name_prefix => 'backoffice_admin_product_',
:path_prefix => 'backoffice/admin/products/1/',
:shallow => true,
:options => { :product_id => '1' }
end
end
def test_restful_routes_dont_generate_duplicates
with_restful_routing :messages do
routes = ActionController::Routing::Routes.routes
@ -583,11 +637,11 @@ class ResourcesTest < ActionController::TestCase
options = { :controller => controller_name.to_s }
collection_path = "/#{controller_name}"
assert_raises(ActionController::MethodNotAllowed) do
assert_raise(ActionController::MethodNotAllowed) do
assert_recognizes(options.merge(:action => 'update'), :path => collection_path, :method => :put)
end
assert_raises(ActionController::MethodNotAllowed) do
assert_raise(ActionController::MethodNotAllowed) do
assert_recognizes(options.merge(:action => 'destroy'), :path => collection_path, :method => :delete)
end
end
@ -596,7 +650,7 @@ class ResourcesTest < ActionController::TestCase
def test_should_not_allow_invalid_head_method_for_member_routes
with_routing do |set|
set.draw do |map|
assert_raises(ArgumentError) do
assert_raise(ArgumentError) do
map.resources :messages, :member => {:something => :head}
end
end
@ -606,7 +660,7 @@ class ResourcesTest < ActionController::TestCase
def test_should_not_allow_invalid_http_methods_for_member_routes
with_routing do |set|
set.draw do |map|
assert_raises(ArgumentError) do
assert_raise(ArgumentError) do
map.resources :messages, :member => {:something => :invalid}
end
end
@ -1074,7 +1128,7 @@ class ResourcesTest < ActionController::TestCase
path = "#{options[:as] || controller_name}"
collection_path = "/#{options[:path_prefix]}#{path}"
shallow_path = "/#{options[:path_prefix] unless options[:shallow]}#{path}"
shallow_path = "/#{options[:shallow] ? options[:namespace] : options[:path_prefix]}#{path}"
member_path = "#{shallow_path}/1"
new_path = "#{collection_path}/#{new_action}"
edit_member_path = "#{member_path}/#{edit_action}"
@ -1138,10 +1192,10 @@ class ResourcesTest < ActionController::TestCase
options[:options].delete :action
path = "#{options[:as] || controller_name}"
shallow_path = "/#{options[:path_prefix] unless options[:shallow]}#{path}"
shallow_path = "/#{options[:shallow] ? options[:namespace] : options[:path_prefix]}#{path}"
full_path = "/#{options[:path_prefix]}#{path}"
name_prefix = options[:name_prefix]
shallow_prefix = "#{options[:name_prefix] unless options[:shallow]}"
shallow_prefix = options[:shallow] ? options[:namespace].try(:gsub, /\//, '_') : options[:name_prefix]
new_action = "new"
edit_action = "edit"

View file

@ -219,7 +219,7 @@ class DynamicSegmentTest < Test::Unit::TestCase
a_value = nil
# Local jump because of return inside eval.
assert_raises(LocalJumpError) { eval(segment.extraction_code) }
assert_raise(LocalJumpError) { eval(segment.extraction_code) }
end
def test_extraction_code_should_return_on_mismatch
@ -229,7 +229,7 @@ class DynamicSegmentTest < Test::Unit::TestCase
a_value = nil
# Local jump because of return inside eval.
assert_raises(LocalJumpError) { eval(segment.extraction_code) }
assert_raise(LocalJumpError) { eval(segment.extraction_code) }
end
def test_extraction_code_should_accept_value_and_set_local
@ -494,7 +494,7 @@ class RouteBuilderTest < Test::Unit::TestCase
defaults = {:action => 'buy', :person => nil, :car => nil}
requirements = {:person => /\w+/, :car => /^\w+$/}
assert_raises ArgumentError do
assert_raise ArgumentError do
route_requirements = builder.assign_route_options(segments, defaults, requirements)
end
@ -882,7 +882,7 @@ class LegacyRouteSetTests < Test::Unit::TestCase
end
assert_equal({:controller => "admin/accounts", :action => "index"}, rs.recognize_path("/admin/accounts"))
assert_equal({:controller => "admin/users", :action => "index"}, rs.recognize_path("/admin/users"))
assert_raises(ActionController::RoutingError) { rs.recognize_path("/admin/products") }
assert_raise(ActionController::RoutingError) { rs.recognize_path("/admin/products") }
end
def test_route_with_regexp_and_dot
@ -955,6 +955,13 @@ class LegacyRouteSetTests < Test::Unit::TestCase
x.send(:page_url))
end
def test_named_route_with_blank_path_prefix
rs.add_named_route :page, 'page', :controller => 'content', :action => 'show_page', :path_prefix => ''
x = setup_for_named_route
assert_equal("http://test.host/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
@ -1060,11 +1067,11 @@ class LegacyRouteSetTests < Test::Unit::TestCase
rs.draw do |map|
map.connect ':controller/:action/:id'
end
assert_raises(ActionController::RoutingError) { rs.recognize_path("/not_a/show/10") }
assert_raise(ActionController::RoutingError) { rs.recognize_path("/not_a/show/10") }
end
def test_paths_do_not_accept_defaults
assert_raises(ActionController::RoutingError) do
assert_raise(ActionController::RoutingError) do
rs.draw do |map|
map.path 'file/*path', :controller => 'content', :action => 'show_file', :path => %w(fake default)
map.connect ':controller/:action/:id'
@ -1197,7 +1204,7 @@ class LegacyRouteSetTests < Test::Unit::TestCase
assert_equal '/post/10', rs.generate(:controller => 'post', :action => 'show', :id => 10)
assert_raises ActionController::RoutingError do
assert_raise ActionController::RoutingError do
rs.generate(:controller => 'post', :action => 'show')
end
end
@ -1407,7 +1414,7 @@ class LegacyRouteSetTests < Test::Unit::TestCase
end
x = setup_for_named_route
assert_raises(ActionController::RoutingError) do
assert_raise(ActionController::RoutingError) do
x.send(:foo_with_requirement_url, "I am Against the requirements")
end
end
@ -1539,7 +1546,7 @@ class RouteTest < Test::Unit::TestCase
end
def test_builder_complains_without_controller
assert_raises(ArgumentError) do
assert_raise(ArgumentError) do
ROUTING::RouteBuilder.new.build '/contact', :contoller => "contact", :action => "index"
end
end
@ -1822,27 +1829,27 @@ class RouteSetTest < Test::Unit::TestCase
end
def test_route_requirements_with_anchor_chars_are_invalid
assert_raises ArgumentError do
assert_raise ArgumentError do
set.draw do |map|
map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /^\d+/
end
end
assert_raises ArgumentError do
assert_raise ArgumentError do
set.draw do |map|
map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /\A\d+/
end
end
assert_raises ArgumentError do
assert_raise ArgumentError do
set.draw do |map|
map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /\d+$/
end
end
assert_raises ArgumentError do
assert_raise ArgumentError do
set.draw do |map|
map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /\d+\Z/
end
end
assert_raises ArgumentError do
assert_raise ArgumentError do
set.draw do |map|
map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /\d+\z/
end
@ -1851,22 +1858,30 @@ class RouteSetTest < Test::Unit::TestCase
set.draw do |map|
map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /\d+/, :name => /^(david|jamis)/
end
assert_raises ActionController::RoutingError do
assert_raise ActionController::RoutingError do
set.generate :controller => 'pages', :action => 'show', :id => 10
end
end
end
def test_route_requirements_with_invalid_http_method_is_invalid
assert_raises ArgumentError do
assert_raise ArgumentError do
set.draw do |map|
map.connect 'valid/route', :controller => 'pages', :action => 'show', :conditions => {:method => :invalid}
end
end
end
def test_route_requirements_with_options_method_condition_is_valid
assert_nothing_raised do
set.draw do |map|
map.connect 'valid/route', :controller => 'pages', :action => 'show', :conditions => {:method => :options}
end
end
end
def test_route_requirements_with_head_method_condition_is_invalid
assert_raises ArgumentError do
assert_raise ArgumentError do
set.draw do |map|
map.connect 'valid/route', :controller => 'pages', :action => 'show', :conditions => {:method => :head}
end
@ -1878,10 +1893,10 @@ class RouteSetTest < Test::Unit::TestCase
map.connect 'page/37s', :controller => 'pages', :action => 'show', :name => /(jamis|david)/
end
assert_equal '/page/37s', set.generate(:controller => 'pages', :action => 'show', :name => 'jamis')
assert_raises ActionController::RoutingError do
assert_raise ActionController::RoutingError do
set.generate(:controller => 'pages', :action => 'show', :name => 'not_jamis')
end
assert_raises ActionController::RoutingError do
assert_raise ActionController::RoutingError do
set.generate(:controller => 'pages', :action => 'show', :name => 'nor_jamis_and_david')
end
end
@ -1924,7 +1939,7 @@ class RouteSetTest < Test::Unit::TestCase
assert_equal("update", request.path_parameters[:action])
request.recycle!
assert_raises(ActionController::UnknownHttpMethod) {
assert_raise(ActionController::UnknownHttpMethod) {
request.env["REQUEST_METHOD"] = "BACON"
set.recognize(request)
}
@ -2122,11 +2137,9 @@ class RouteSetTest < Test::Unit::TestCase
Object.const_set(:Api, Module.new { |m| m.const_set(:ProductsController, Class.new) })
set.draw do |map|
map.namespace 'api', :path_prefix => 'prefix' do |api|
api.route 'inventory', :controller => "products", :action => 'inventory'
end
end
request.path = "/prefix/inventory"
@ -2138,6 +2151,24 @@ class RouteSetTest < Test::Unit::TestCase
Object.send(:remove_const, :Api)
end
def test_namespace_with_blank_path_prefix
Object.const_set(:Api, Module.new { |m| m.const_set(:ProductsController, Class.new) })
set.draw do |map|
map.namespace 'api', :path_prefix => '' do |api|
api.route 'inventory', :controller => "products", :action => 'inventory'
end
end
request.path = "/inventory"
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])
ensure
Object.send(:remove_const, :Api)
end
def test_generate_finds_best_fit
set.draw do |map|
map.connect "/people", :controller => "people", :action => "index"
@ -2202,6 +2233,13 @@ class RouteSetTest < Test::Unit::TestCase
assert_equal "/my/foo/bar/7?x=y", set.generate(args)
end
def test_generate_with_blank_path_prefix
set.draw { |map| map.connect ':controller/:action/:id', :path_prefix => '' }
args = { :controller => "foo", :action => "bar", :id => "7", :x => "y" }
assert_equal "/foo/bar/7?x=y", set.generate(args)
end
def test_named_routes_are_never_relative_to_modules
set.draw do |map|
map.connect "/connection/manage/:action", :controller => 'connection/manage'
@ -2309,7 +2347,7 @@ class RouteSetTest < Test::Unit::TestCase
end
def test_route_requirements_with_unsupported_regexp_options_must_error
assert_raises ArgumentError do
assert_raise ArgumentError do
set.draw do |map|
map.connect 'page/:name', :controller => 'pages',
:action => 'show',
@ -2347,7 +2385,7 @@ class RouteSetTest < Test::Unit::TestCase
:requirements => {:name => /(david|jamis)/i}
end
assert_equal({:controller => 'pages', :action => 'show', :name => 'jamis'}, set.recognize_path('/page/jamis'))
assert_raises ActionController::RoutingError do
assert_raise ActionController::RoutingError do
set.recognize_path('/page/davidjamis')
end
assert_equal({:controller => 'pages', :action => 'show', :name => 'DAVID'}, set.recognize_path('/page/DAVID'))
@ -2361,7 +2399,7 @@ class RouteSetTest < Test::Unit::TestCase
end
url = set.generate({:controller => 'pages', :action => 'show', :name => 'david'})
assert_equal "/page/david", url
assert_raises ActionController::RoutingError do
assert_raise ActionController::RoutingError do
url = set.generate({:controller => 'pages', :action => 'show', :name => 'davidjamis'})
end
url = set.generate({:controller => 'pages', :action => 'show', :name => 'JAMIS'})
@ -2381,10 +2419,10 @@ class RouteSetTest < Test::Unit::TestCase
end
assert_equal({:controller => 'pages', :action => 'show', :name => 'jamis'}, set.recognize_path('/page/jamis'))
assert_equal({:controller => 'pages', :action => 'show', :name => 'david'}, set.recognize_path('/page/david'))
assert_raises ActionController::RoutingError do
assert_raise ActionController::RoutingError do
set.recognize_path('/page/david #The Creator')
end
assert_raises ActionController::RoutingError do
assert_raise ActionController::RoutingError do
set.recognize_path('/page/David')
end
end
@ -2402,10 +2440,10 @@ class RouteSetTest < Test::Unit::TestCase
end
url = set.generate({:controller => 'pages', :action => 'show', :name => 'david'})
assert_equal "/page/david", url
assert_raises ActionController::RoutingError do
assert_raise ActionController::RoutingError do
url = set.generate({:controller => 'pages', :action => 'show', :name => 'davidjamis'})
end
assert_raises ActionController::RoutingError do
assert_raise ActionController::RoutingError do
url = set.generate({:controller => 'pages', :action => 'show', :name => 'JAMIS'})
end
end

View file

@ -303,7 +303,7 @@ class SelectorTest < Test::Unit::TestCase
assert_equal 1, @matches.size
assert_equal "2", @matches[0].attributes["id"]
# Before first and past last returns nothing.:
assert_raises(ArgumentError) { select("tr:nth-child(-1)") }
assert_raise(ArgumentError) { select("tr:nth-child(-1)") }
select("tr:nth-child(0)")
assert_equal 0, @matches.size
select("tr:nth-child(5)")
@ -597,8 +597,8 @@ class SelectorTest < Test::Unit::TestCase
def test_negation_details
parse(%Q{<p id="1"></p><p id="2"></p><p id="3"></p>})
assert_raises(ArgumentError) { select(":not(") }
assert_raises(ArgumentError) { select(":not(:not())") }
assert_raise(ArgumentError) { select(":not(") }
assert_raise(ArgumentError) { select(":not(:not())") }
select("p:not(#1):not(#3)")
assert_equal 1, @matches.size
assert_equal "2", @matches[0].attributes["id"]

View file

@ -142,7 +142,7 @@ class SendFileTest < ActionController::TestCase
}
@controller.headers = {}
assert_raises(ArgumentError){ @controller.send(:send_file_headers!, options) }
assert_raise(ArgumentError){ @controller.send(:send_file_headers!, options) }
end
%w(file data).each do |method|

View file

@ -199,29 +199,18 @@ class CookieStoreTest < ActionController::IntegrationTest
with_test_route_set do
# First request accesses the session
time = Time.local(2008, 4, 24)
Time.stubs(:now).returns(time)
expected_expiry = (time + 5.hours).gmtime.strftime("%a, %d-%b-%Y %H:%M:%S GMT")
cookies[SessionKey] = SignedBar
get '/set_session_value'
assert_response :success
cookie = headers['Set-Cookie']
cookie_body = response.body
assert_equal "_myapp_session=#{cookie_body}; path=/; expires=#{expected_expiry}; HttpOnly",
headers['Set-Cookie']
# Second request does not access the session
time = Time.local(2008, 4, 25)
Time.stubs(:now).returns(time)
expected_expiry = (time + 5.hours).gmtime.strftime("%a, %d-%b-%Y %H:%M:%S GMT")
# Second request does not access the session so the
# expires header should not be changed
get '/no_session_access'
assert_response :success
assert_equal "_myapp_session=#{cookie_body}; path=/; expires=#{expected_expiry}; HttpOnly",
headers['Set-Cookie']
assert_equal cookie, headers['Set-Cookie'],
"#{unmarshal_session(cookie).inspect} expected but was #{unmarshal_session(headers['Set-Cookie']).inspect}"
end
end
@ -236,4 +225,13 @@ class CookieStoreTest < ActionController::IntegrationTest
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

View file

@ -17,11 +17,14 @@ class MemCacheStoreTest < ActionController::IntegrationTest
end
def get_session_id
render :text => "foo: #{session[:foo].inspect}; id: #{request.session_options[:id]}"
session[:foo]
render :text => "#{request.session_options[:id]}"
end
def call_reset_session
session[:bar]
reset_session
session[:bar] = "baz"
head :ok
end
@ -58,6 +61,27 @@ class MemCacheStoreTest < ActionController::IntegrationTest
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']
session_id = 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
get '/get_session_id'
assert_response :success
assert_not_equal session_id, response.body
end
end
def test_getting_session_id
with_test_route_set do
get '/set_session_value'
@ -67,7 +91,7 @@ class MemCacheStoreTest < ActionController::IntegrationTest
get '/get_session_id'
assert_response :success
assert_equal "foo: \"bar\"; id: #{session_id}", response.body
assert_equal session_id, response.body
end
end
@ -85,22 +109,6 @@ 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

View file

@ -99,7 +99,7 @@ class UrlWriterTests < ActionController::TestCase
end
def test_exception_is_thrown_without_host
assert_raises RuntimeError do
assert_raise RuntimeError do
W.new.url_for :controller => 'c', :action => 'a', :id => 'i'
end
end