mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-24 03:00:12 +01:00
Vendoring Rails 2.3.5
This commit is contained in:
parent
3e83d19299
commit
f8779795ce
943 changed files with 56503 additions and 61351 deletions
|
|
@ -1,22 +1,12 @@
|
|||
require 'abstract_unit'
|
||||
require 'action_controller/integration'
|
||||
require 'action_controller/routing'
|
||||
|
||||
uses_mocha 'integration' do
|
||||
|
||||
module IntegrationSessionStubbing
|
||||
def stub_integration_session(session)
|
||||
session.stubs(:process)
|
||||
session.stubs(:generic_url_rewriter)
|
||||
end
|
||||
end
|
||||
|
||||
class SessionTest < Test::Unit::TestCase
|
||||
include IntegrationSessionStubbing
|
||||
StubApp = lambda { |env|
|
||||
[200, {"Content-Type" => "text/html", "Content-Length" => "13"}, ["Hello, World!"]]
|
||||
}
|
||||
|
||||
def setup
|
||||
@session = ActionController::Integration::Session.new
|
||||
stub_integration_session(@session)
|
||||
@session = ActionController::Integration::Session.new(StubApp)
|
||||
end
|
||||
|
||||
def test_https_bang_works_and_sets_truth_by_default
|
||||
|
|
@ -38,14 +28,6 @@ class SessionTest < Test::Unit::TestCase
|
|||
assert_raise(RuntimeError) { @session.follow_redirect! }
|
||||
end
|
||||
|
||||
def test_follow_redirect_calls_get_and_returns_status
|
||||
@session.stubs(:redirect?).returns(true)
|
||||
@session.stubs(:headers).returns({"location" => ["www.google.com"]})
|
||||
@session.stubs(:status).returns(200)
|
||||
@session.expects(:get)
|
||||
assert_equal 200, @session.follow_redirect!
|
||||
end
|
||||
|
||||
def test_request_via_redirect_uses_given_method
|
||||
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue"}
|
||||
@session.expects(:put).with(path, args, headers)
|
||||
|
|
@ -209,13 +191,10 @@ class SessionTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
class IntegrationTestTest < Test::Unit::TestCase
|
||||
include IntegrationSessionStubbing
|
||||
|
||||
def setup
|
||||
@test = ::ActionController::IntegrationTest.new(:default_test)
|
||||
@test.class.stubs(:fixture_table_names).returns([])
|
||||
@session = @test.open_session
|
||||
stub_integration_session(@session)
|
||||
end
|
||||
|
||||
def test_opens_new_session
|
||||
|
|
@ -228,20 +207,38 @@ 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.
|
||||
# Integration tests have their own setup and teardown.
|
||||
class IntegrationTestUsesCorrectClass < ActionController::IntegrationTest
|
||||
include IntegrationSessionStubbing
|
||||
|
||||
def self.fixture_table_names
|
||||
[]
|
||||
end
|
||||
|
||||
def test_integration_methods_called
|
||||
reset!
|
||||
stub_integration_session(@integration_session)
|
||||
@integration_session.stubs(:generic_url_rewriter)
|
||||
@integration_session.stubs(:process)
|
||||
|
||||
%w( get post head put delete ).each do |verb|
|
||||
assert_nothing_raised("'#{verb}' should use integration test methods") { __send__(verb, '/') }
|
||||
end
|
||||
|
|
@ -250,8 +247,6 @@ end
|
|||
|
||||
class IntegrationProcessTest < ActionController::IntegrationTest
|
||||
class IntegrationController < ActionController::Base
|
||||
session :off
|
||||
|
||||
def get
|
||||
respond_to do |format|
|
||||
format.html { render :text => "OK", :status => 200 }
|
||||
|
|
@ -263,6 +258,14 @@ class IntegrationProcessTest < ActionController::IntegrationTest
|
|||
render :text => "foo: #{params[:foo]}", :status => 200
|
||||
end
|
||||
|
||||
def post_with_multiparameter_params
|
||||
render :text => "foo(1i): #{params[:"foo(1i)"]}, foo(2i): #{params[:"foo(2i)"]}", :status => 200
|
||||
end
|
||||
|
||||
def multipart_post_with_multiparameter_params
|
||||
render :text => "foo(1i): #{params[:"foo(1i)"]}, foo(2i): #{params[:"foo(2i)"]}, filesize: #{params[:file].size}", :status => 200
|
||||
end
|
||||
|
||||
def post
|
||||
render :text => "Created", :status => 201
|
||||
end
|
||||
|
|
@ -278,19 +281,18 @@ class IntegrationProcessTest < ActionController::IntegrationTest
|
|||
end
|
||||
end
|
||||
|
||||
FILES_DIR = File.dirname(__FILE__) + '/../fixtures/multipart'
|
||||
|
||||
def test_get
|
||||
with_test_route_set do
|
||||
get '/get'
|
||||
assert_equal 200, status
|
||||
assert_equal "OK", status_message
|
||||
assert_equal "200 OK", response.headers["Status"]
|
||||
assert_equal ["200 OK"], headers["status"]
|
||||
assert_response 200
|
||||
assert_response :success
|
||||
assert_response :ok
|
||||
assert_equal [], response.headers["cookie"]
|
||||
assert_equal [], headers["cookie"]
|
||||
assert_equal({}, cookies)
|
||||
assert_equal "OK", body
|
||||
assert_equal "OK", response.body
|
||||
assert_kind_of HTML::Document, html_document
|
||||
assert_equal 1, request_count
|
||||
|
|
@ -302,14 +304,11 @@ class IntegrationProcessTest < ActionController::IntegrationTest
|
|||
post '/post'
|
||||
assert_equal 201, status
|
||||
assert_equal "Created", status_message
|
||||
assert_equal "201 Created", response.headers["Status"]
|
||||
assert_equal ["201 Created"], headers["status"]
|
||||
assert_response 201
|
||||
assert_response :success
|
||||
assert_response :created
|
||||
assert_equal [], response.headers["cookie"]
|
||||
assert_equal [], headers["cookie"]
|
||||
assert_equal({}, cookies)
|
||||
assert_equal "Created", body
|
||||
assert_equal "Created", response.body
|
||||
assert_kind_of HTML::Document, html_document
|
||||
assert_equal 1, request_count
|
||||
|
|
@ -323,17 +322,9 @@ class IntegrationProcessTest < ActionController::IntegrationTest
|
|||
get '/cookie_monster'
|
||||
assert_equal 410, status
|
||||
assert_equal "Gone", status_message
|
||||
assert_equal "410 Gone", response.headers["Status"]
|
||||
assert_equal ["410 Gone"], headers["status"]
|
||||
assert_response 410
|
||||
assert_response :gone
|
||||
assert_equal ["cookie_1=; path=/", "cookie_3=chocolate; path=/"], response.headers["Set-Cookie"]
|
||||
assert_equal ["cookie_1=; path=/", "cookie_3=chocolate; path=/"], headers['set-cookie']
|
||||
assert_equal [
|
||||
CGI::Cookie::new("name" => "cookie_1", "value" => ""),
|
||||
CGI::Cookie::new("name" => "cookie_3", "value" => "chocolate")
|
||||
], response.headers["cookie"]
|
||||
assert_equal [], headers["cookie"]
|
||||
assert_equal "cookie_1=; path=/\ncookie_3=chocolate; path=/", headers["Set-Cookie"]
|
||||
assert_equal({"cookie_1"=>"", "cookie_2"=>"oatmeal", "cookie_3"=>"chocolate"}, cookies)
|
||||
assert_equal "Gone", response.body
|
||||
end
|
||||
|
|
@ -344,14 +335,16 @@ class IntegrationProcessTest < ActionController::IntegrationTest
|
|||
get '/redirect'
|
||||
assert_equal 302, status
|
||||
assert_equal "Found", status_message
|
||||
assert_equal "302 Found", response.headers["Status"]
|
||||
assert_equal ["302 Found"], headers["status"]
|
||||
assert_response 302
|
||||
assert_response :redirect
|
||||
assert_response :found
|
||||
assert_equal "<html><body>You are being <a href=\"http://www.example.com/get\">redirected</a>.</body></html>", response.body
|
||||
assert_kind_of HTML::Document, html_document
|
||||
assert_equal 1, request_count
|
||||
|
||||
follow_redirect!
|
||||
assert_response :success
|
||||
assert_equal "/get", path
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -360,8 +353,6 @@ class IntegrationProcessTest < ActionController::IntegrationTest
|
|||
xhr :get, '/get'
|
||||
assert_equal 200, status
|
||||
assert_equal "OK", status_message
|
||||
assert_equal "200 OK", response.headers["Status"]
|
||||
assert_equal ["200 OK"], headers["status"]
|
||||
assert_response 200
|
||||
assert_response :success
|
||||
assert_response :ok
|
||||
|
|
@ -374,7 +365,7 @@ class IntegrationProcessTest < ActionController::IntegrationTest
|
|||
get '/get_with_params?foo=bar'
|
||||
assert_equal '/get_with_params?foo=bar', request.env["REQUEST_URI"]
|
||||
assert_equal '/get_with_params?foo=bar', request.request_uri
|
||||
assert_equal nil, request.env["QUERY_STRING"]
|
||||
assert_equal "", request.env["QUERY_STRING"]
|
||||
assert_equal 'foo=bar', request.query_string
|
||||
assert_equal 'bar', request.parameters['foo']
|
||||
|
||||
|
|
@ -397,6 +388,36 @@ class IntegrationProcessTest < ActionController::IntegrationTest
|
|||
end
|
||||
end
|
||||
|
||||
def test_post_with_multiparameter_attribute_parameters
|
||||
with_test_route_set do
|
||||
post '/post_with_multiparameter_params', :"foo(1i)" => "bar", :"foo(2i)" => "baz"
|
||||
|
||||
assert_equal 200, status
|
||||
assert_equal "foo(1i): bar, foo(2i): baz", response.body
|
||||
end
|
||||
end
|
||||
|
||||
def test_multipart_post_with_multiparameter_attribute_parameters
|
||||
with_test_route_set do
|
||||
post '/multipart_post_with_multiparameter_params', :"foo(1i)" => "bar", :"foo(2i)" => "baz", :file => fixture_file_upload(FILES_DIR + "/mona_lisa.jpg", "image/jpg")
|
||||
|
||||
assert_equal 200, status
|
||||
assert_equal "foo(1i): bar, foo(2i): baz, filesize: 159528", response.body
|
||||
end
|
||||
end
|
||||
|
||||
def test_head
|
||||
with_test_route_set do
|
||||
head '/get'
|
||||
assert_equal 200, status
|
||||
assert_equal "", body
|
||||
|
||||
head '/post'
|
||||
assert_equal 201, status
|
||||
assert_equal "", body
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def with_test_route_set
|
||||
with_routing do |set|
|
||||
|
|
@ -410,4 +431,53 @@ class IntegrationProcessTest < ActionController::IntegrationTest
|
|||
end
|
||||
end
|
||||
|
||||
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!"]]
|
||||
else
|
||||
[404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def setup
|
||||
@integration_session = ActionController::Integration::Session.new(Poller)
|
||||
end
|
||||
|
||||
def test_successful_get
|
||||
get "/success"
|
||||
assert_response 200
|
||||
assert_response :success
|
||||
assert_response :ok
|
||||
assert_equal "Hello World!", response.body
|
||||
end
|
||||
|
||||
def test_failed_get
|
||||
get "/failure"
|
||||
assert_response 404
|
||||
assert_response :not_found
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue