Rails 2.3.5

Upgrade to Rails 2.3.5.
Also work around this bug:
 https://rails.lighthouseapp.com/projects/8994/tickets/3524
created by the aforementioned
Rails release.
This commit is contained in:
Jacques Distler 2009-11-30 19:38:34 -06:00
parent a6429f8c22
commit e3832c6f79
187 changed files with 2316 additions and 891 deletions

View file

@ -114,6 +114,13 @@ class CookieTest < ActionController::TestCase
assert_equal %w{1 2 3}, jar["pages"]
end
def test_cookiejar_delete_removes_item_and_returns_its_value
@request.cookies["user_name"] = "david"
@controller.response = @response
jar = ActionController::CookieJar.new(@controller)
assert_equal "david", jar.delete("user_name")
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"]

View file

@ -0,0 +1,53 @@
require 'abstract_unit'
class DomAssertionsTest < ActionView::TestCase
def setup
super
@html_only = '<ul><li>foo</li><li>bar</li></ul>'
@html_with_meaningless_whitespace = %{
<ul>
<li>\tfoo </li>
<li>
bar
</li>
</ul>
}
@more_html_with_meaningless_whitespace = %{<ul>
<li>foo</li>
<li>bar</li></ul>}
end
test "assert_dom_equal strips meaningless whitespace from expected string" do
assert_dom_equal @html_with_meaningless_whitespace, @html_only
end
test "assert_dom_equal strips meaningless whitespace from actual string" do
assert_dom_equal @html_only, @html_with_meaningless_whitespace
end
test "assert_dom_equal strips meaningless whitespace from both expected and actual strings" do
assert_dom_equal @more_html_with_meaningless_whitespace, @html_with_meaningless_whitespace
end
test "assert_dom_not_equal strips meaningless whitespace from expected string" do
assert_assertion_fails { assert_dom_not_equal @html_with_meaningless_whitespace, @html_only }
end
test "assert_dom_not_equal strips meaningless whitespace from actual string" do
assert_assertion_fails { assert_dom_not_equal @html_only, @html_with_meaningless_whitespace }
end
test "assert_dom_not_equal strips meaningless whitespace from both expected and actual strings" do
assert_assertion_fails do
assert_dom_not_equal @more_html_with_meaningless_whitespace, @html_with_meaningless_whitespace
end
end
private
def assert_assertion_fails
assert_raise(ActiveSupport::TestCase::Assertion) { yield }
end
end

View file

@ -18,6 +18,7 @@ class FilterParamTest < Test::Unit::TestCase
test_hashes = [[{},{},[]],
[{'foo'=>nil},{'foo'=>nil},[]],
[{'foo'=>'bar'},{'foo'=>'bar'},[]],
[{'foo'=>1},{'foo'=>1},[]],
[{'foo'=>'bar'},{'foo'=>'bar'},%w'food'],
[{'foo'=>'bar'},{'foo'=>'[FILTERED]'},%w'foo'],
[{'foo'=>'bar', 'bar'=>'foo'},{'foo'=>'[FILTERED]', 'bar'=>'foo'},%w'foo baz'],

View file

@ -19,6 +19,7 @@ class SanitizerTest < ActionController::TestCase
assert_equal "This has a here.", sanitizer.sanitize("This has a <!-- comment --> here.")
assert_equal "This has a here.", sanitizer.sanitize("This has a <![CDATA[<section>]]> here.")
assert_equal "This has an unclosed ", sanitizer.sanitize("This has an unclosed <![CDATA[<section>]] here...")
assert_equal "non printable char is a tag", sanitizer.sanitize("<\x07a href='/hello'>non printable char is a tag</a>")
[nil, '', ' '].each { |blank| assert_equal blank, sanitizer.sanitize(blank) }
end

View file

@ -92,6 +92,23 @@ class HttpDigestAuthenticationTest < ActionController::TestCase
assert_equal "Authentication Failed", @response.body
end
test "authentication request with missing nonce should return 401" do
@request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'please', :remove_nonce => true)
get :display
assert_response :unauthorized
assert_equal "Authentication Failed", @response.body
end
test "authentication request with Basic auth credentials should return 401" do
ActionController::Base.session_options[:secret] = "session_options_secret"
@request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials('pretty', 'please')
get :display
assert_response :unauthorized
assert_equal "Authentication Failed", @response.body
end
test "authentication request with invalid opaque" do
@request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'foo', :opaque => "xxyyzz")
get :display
@ -220,9 +237,14 @@ class HttpDigestAuthenticationTest < ActionController::TestCase
assert_response :unauthorized
remove_nonce = options.delete(:remove_nonce)
credentials = decode_credentials(@response.headers['WWW-Authenticate'])
credentials.merge!(options)
credentials.merge!(:uri => @request.env['REQUEST_URI'].to_s)
credentials.delete(:nonce) if remove_nonce
ActionController::HttpAuthentication::Digest.encode_credentials(method, credentials, password, options[:password_is_ha1])
end

View file

@ -207,6 +207,24 @@ class IntegrationTestTest < Test::Unit::TestCase
assert_equal ::ActionController::Integration::Session, session2.class
assert_not_equal session1, session2
end
# RSpec mixes Matchers (which has a #method_missing) into
# IntegrationTest's superclass. Make sure IntegrationTest does not
# try to delegate these methods to the session object.
def test_does_not_prevent_method_missing_passing_up_to_ancestors
mixin = Module.new do
def method_missing(name, *args)
name.to_s == 'foo' ? 'pass' : super
end
end
@test.class.superclass.__send__(:include, mixin)
begin
assert_equal 'pass', @test.foo
ensure
# leave other tests as unaffected as possible
mixin.__send__(:remove_method, :method_missing)
end
end
end
# Tests that integration tests don't call Controller test methods for processing.
@ -443,3 +461,23 @@ class MetalTest < ActionController::IntegrationTest
assert_equal '', response.body
end
end
class StringSubclassBodyTest < ActionController::IntegrationTest
class SafeString < String
end
class SafeStringMiddleware
def self.call(env)
[200, {"Content-Type" => "text/plain", "Content-Length" => "12"}, [SafeString.new("Hello World!")]]
end
end
def setup
@integration_session = ActionController::Integration::Session.new(SafeStringMiddleware)
end
def test_string_subclass_body
get '/'
assert_equal 'Hello World!', response.body
end
end

View file

@ -83,6 +83,11 @@ class AbsolutePathLayoutController < LayoutTest
layout File.expand_path(File.expand_path(__FILE__) + '/../../fixtures/layout_tests/layouts/layout_test.rhtml')
end
class AbsolutePathWithoutLayoutsController < LayoutTest
# Absolute layout path without 'layouts' in it.
layout File.expand_path(File.expand_path(__FILE__) + '/../../fixtures/layout_tests/abs_path_layout.rhtml')
end
class HasOwnLayoutController < LayoutTest
layout 'item'
end
@ -153,6 +158,12 @@ class LayoutSetInResponseTest < ActionController::TestCase
get :hello
assert_equal "layout_test.rhtml hello.rhtml", @response.body.strip
end
def test_absolute_pathed_layout_without_layouts_in_path
@controller = AbsolutePathWithoutLayoutsController.new
get :hello
assert_equal "abs_path_layout.rhtml hello.rhtml", @response.body.strip
end
end
class RenderWithTemplateOptionController < LayoutTest

View file

@ -290,4 +290,8 @@ class PolymorphicRoutesTest < ActiveSupport::TestCase
polymorphic_url([:taxes])
end
def test_with_array_containing_symbols
expects(:new_article_url).with()
polymorphic_url([:new, :article])
end
end

View file

@ -22,7 +22,7 @@ module RequestForgeryProtectionActions
def unsafe
render :text => 'pwn'
end
def rescue_action(e) raise e end
end
@ -44,6 +44,13 @@ class FreeCookieController < RequestForgeryProtectionController
end
end
class CustomAuthenticityParamController < RequestForgeryProtectionController
def form_authenticity_param
'foobar'
end
end
# common test methods
module RequestForgeryProtectionTests
@ -245,3 +252,14 @@ class FreeCookieControllerTest < ActionController::TestCase
end
end
end
class CustomAuthenticityParamControllerTest < ActionController::TestCase
def setup
ActionController::Base.request_forgery_protection_token = :authenticity_token
end
def test_should_allow_custom_token
post :index, :authenticity_token => 'foobar'
assert_response :ok
end
end

View file

@ -107,7 +107,11 @@ class StaticSegmentTest < Test::Unit::TestCase
end
end
class DynamicSegmentTest < Test::Unit::TestCase
class DynamicSegmentTest < ActiveSupport::TestCase
def setup
@segment = nil
end
def segment(options = {})
unless @segment
@segment = ROUTING::DynamicSegment.new(:a, options)
@ -341,7 +345,11 @@ class ControllerSegmentTest < Test::Unit::TestCase
end
end
class PathSegmentTest < Test::Unit::TestCase
class PathSegmentTest < ActiveSupport::TestCase
def setup
@segment = nil
end
def segment(options = {})
unless @segment
@segment = ROUTING::PathSegment.new(:path, options)
@ -754,7 +762,7 @@ class LegacyRouteSetTests < ActiveSupport::TestCase
ActionController::Routing.use_controllers! %w(content admin/user admin/news_feed)
end
def teardown
@rs.clear!
end
@ -1094,21 +1102,21 @@ class LegacyRouteSetTests < ActiveSupport::TestCase
map.post 'post/:id', :controller=> 'post', :action=> 'show', :requirements => {:id => /\d+/}
end
exception = assert_raise(ActionController::RoutingError) { rs.generate(:controller => 'post', :action => 'show', :bad_param => "foo", :use_route => "post") }
assert_match /^post_url failed to generate/, exception.message
assert_match(/^post_url failed to generate/, exception.message)
from_match = exception.message.match(/from \{[^\}]+\}/).to_s
assert_match /:bad_param=>"foo"/, from_match
assert_match /:action=>"show"/, from_match
assert_match /:controller=>"post"/, from_match
assert_match(/:bad_param=>"foo"/, from_match)
assert_match(/:action=>"show"/, from_match)
assert_match(/:controller=>"post"/, from_match)
expected_match = exception.message.match(/expected: \{[^\}]+\}/).to_s
assert_no_match /:bad_param=>"foo"/, expected_match
assert_match /:action=>"show"/, expected_match
assert_match /:controller=>"post"/, expected_match
assert_no_match(/:bad_param=>"foo"/, expected_match)
assert_match( /:action=>"show"/, expected_match)
assert_match( /:controller=>"post"/, expected_match)
diff_match = exception.message.match(/diff: \{[^\}]+\}/).to_s
assert_match /:bad_param=>"foo"/, diff_match
assert_no_match /:action=>"show"/, diff_match
assert_no_match /:controller=>"post"/, diff_match
assert_match( /:bad_param=>"foo"/, diff_match)
assert_no_match(/:action=>"show"/, diff_match)
assert_no_match(/:controller=>"post"/, diff_match)
end
# this specifies the case where your formerly would get a very confusing error message with an empty diff
@ -2564,10 +2572,10 @@ class RouteLoadingTest < Test::Unit::TestCase
routes.reload
end
def test_load_multiple_configurations
routes.add_configuration_file("engines.rb")
File.expects(:stat).at_least_once.returns(@stat)
routes.expects(:load).with('./config/routes.rb')

View file

@ -33,11 +33,11 @@ class ActionController::TestSessionTest < ActiveSupport::TestCase
assert_equal('value', session[:key])
end
def test_calling_delete_removes_item
def test_calling_delete_removes_item_and_returns_its_value
session = ActionController::TestSession.new
session[:key] = 'value'
assert_equal('value', session[:key])
session.delete(:key)
assert_equal('value', session.delete(:key))
assert_nil(session[:key])
end