diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2008-07-04 00:33:56 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-07-04 00:33:56 +0100 |
commit | 0a7923ea7a76c1136bddfe638a600c62457df751 (patch) | |
tree | 2709c19133af9342958fc51b36ad53ca56c2927a /actionpack/test/controller | |
parent | 5dba6c024289e42c31894b7d13c1695049fcf30d (diff) | |
parent | 1a478923dc909bf7b6aea4f2ad49cbeee6dea259 (diff) | |
download | rails-0a7923ea7a76c1136bddfe638a600c62457df751.tar.gz rails-0a7923ea7a76c1136bddfe638a600c62457df751.tar.bz2 rails-0a7923ea7a76c1136bddfe638a600c62457df751.zip |
Merge commit 'mainstream/master'
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r-- | actionpack/test/controller/action_pack_assertions_test.rb | 5 | ||||
-rw-r--r-- | actionpack/test/controller/addresses_render_test.rb | 3 | ||||
-rw-r--r-- | actionpack/test/controller/caching_test.rb | 5 | ||||
-rw-r--r-- | actionpack/test/controller/capture_test.rb | 2 | ||||
-rwxr-xr-x | actionpack/test/controller/cgi_test.rb | 87 | ||||
-rw-r--r-- | actionpack/test/controller/content_type_test.rb | 24 | ||||
-rw-r--r-- | actionpack/test/controller/custom_handler_test.rb | 45 | ||||
-rw-r--r-- | actionpack/test/controller/deprecation/deprecated_base_methods_test.rb | 3 | ||||
-rw-r--r-- | actionpack/test/controller/layout_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/mime_responds_test.rb | 53 | ||||
-rw-r--r-- | actionpack/test/controller/new_render_test.rb | 138 | ||||
-rw-r--r-- | actionpack/test/controller/rack_test.rb | 54 | ||||
-rw-r--r-- | actionpack/test/controller/render_test.rb | 29 | ||||
-rw-r--r-- | actionpack/test/controller/request_test.rb | 14 | ||||
-rw-r--r-- | actionpack/test/controller/routing_test.rb | 20 | ||||
-rw-r--r-- | actionpack/test/controller/send_file_test.rb | 4 | ||||
-rw-r--r-- | actionpack/test/controller/view_paths_test.rb | 48 |
17 files changed, 316 insertions, 220 deletions
diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index c25e9e1df6..7a90a9408e 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -157,7 +157,7 @@ module Admin def redirect_to_fellow_controller redirect_to :controller => 'user' end - + def redirect_to_top_level_named_route redirect_to top_level_url(:id => "foo") end @@ -170,7 +170,7 @@ end # tell the controller where to find its templates but start from parent # directory of test_request_response to simulate the behaviour of a # production environment -ActionPackAssertionsController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ] +ActionPackAssertionsController.view_paths = [FIXTURE_LOAD_PATH] # a test case to exercise the new capabilities TestRequest & TestResponse class ActionPackAssertionsControllerTest < Test::Unit::TestCase @@ -533,7 +533,6 @@ class ActionPackHeaderTest < Test::Unit::TestCase assert_equal('application/pdf; charset=utf-8', @response.headers['type']) end - def test_render_text_with_custom_content_type get :render_text_with_custom_content_type assert_equal 'application/rss+xml; charset=utf-8', @response.headers['type'] diff --git a/actionpack/test/controller/addresses_render_test.rb b/actionpack/test/controller/addresses_render_test.rb index a31734203d..df87182082 100644 --- a/actionpack/test/controller/addresses_render_test.rb +++ b/actionpack/test/controller/addresses_render_test.rb @@ -1,7 +1,6 @@ require 'abstract_unit' class Address - def Address.count(conditions = nil, join = nil) nil end @@ -20,7 +19,7 @@ class AddressesTestController < ActionController::Base def self.controller_path; "addresses"; end end -AddressesTestController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ] +AddressesTestController.view_paths = [FIXTURE_LOAD_PATH] class AddressesTest < Test::Unit::TestCase def setup diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index 14cf0a86a1..0140654155 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -6,7 +6,7 @@ CACHE_DIR = 'test_cache' FILE_STORE_PATH = File.join(File.dirname(__FILE__), '/../temp/', CACHE_DIR) ActionController::Base.page_cache_directory = FILE_STORE_PATH ActionController::Base.cache_store = :file_store, FILE_STORE_PATH -ActionController::Base.view_paths = [ File.dirname(__FILE__) + '/../fixtures/' ] +ActionController::Base.view_paths = [FIXTURE_LOAD_PATH] class PageCachingTestController < ActionController::Base caches_page :ok, :no_content, :if => Proc.new { |c| !c.request.format.json? } @@ -631,7 +631,7 @@ class FunctionalCachingController < ActionController::Base end end -FunctionalCachingController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ] +FunctionalCachingController.view_paths = [FIXTURE_LOAD_PATH] class FunctionalFragmentCachingTest < Test::Unit::TestCase def setup @@ -642,6 +642,7 @@ class FunctionalFragmentCachingTest < Test::Unit::TestCase @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new end + def test_fragment_caching get :fragment_cached assert_response :success diff --git a/actionpack/test/controller/capture_test.rb b/actionpack/test/controller/capture_test.rb index 2604844b84..87f9ce8ab3 100644 --- a/actionpack/test/controller/capture_test.rb +++ b/actionpack/test/controller/capture_test.rb @@ -23,7 +23,7 @@ class CaptureController < ActionController::Base def rescue_action(e) raise end end -CaptureController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ] +CaptureController.view_paths = [FIXTURE_LOAD_PATH] class CaptureTest < Test::Unit::TestCase def setup diff --git a/actionpack/test/controller/cgi_test.rb b/actionpack/test/controller/cgi_test.rb index 1b1ded4615..bf3b8b788e 100755 --- a/actionpack/test/controller/cgi_test.rb +++ b/actionpack/test/controller/cgi_test.rb @@ -3,18 +3,58 @@ require 'action_controller/cgi_process' class BaseCgiTest < Test::Unit::TestCase def setup - @request_hash = {"HTTP_MAX_FORWARDS"=>"10", "SERVER_NAME"=>"glu.ttono.us:8007", "FCGI_ROLE"=>"RESPONDER", "HTTP_X_FORWARDED_HOST"=>"glu.ttono.us", "HTTP_ACCEPT_ENCODING"=>"gzip, deflate", "HTTP_USER_AGENT"=>"Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/312.5.1 (KHTML, like Gecko) Safari/312.3.1", "PATH_INFO"=>"", "HTTP_ACCEPT_LANGUAGE"=>"en", "HTTP_HOST"=>"glu.ttono.us:8007", "SERVER_PROTOCOL"=>"HTTP/1.1", "REDIRECT_URI"=>"/dispatch.fcgi", "SCRIPT_NAME"=>"/dispatch.fcgi", "SERVER_ADDR"=>"207.7.108.53", "REMOTE_ADDR"=>"207.7.108.53", "SERVER_SOFTWARE"=>"lighttpd/1.4.5", "HTTP_COOKIE"=>"_session_id=c84ace84796670c052c6ceb2451fb0f2; is_admin=yes", "HTTP_X_FORWARDED_SERVER"=>"glu.ttono.us", "REQUEST_URI"=>"/admin", "DOCUMENT_ROOT"=>"/home/kevinc/sites/typo/public", "SERVER_PORT"=>"8007", "QUERY_STRING"=>"", "REMOTE_PORT"=>"63137", "GATEWAY_INTERFACE"=>"CGI/1.1", "HTTP_X_FORWARDED_FOR"=>"65.88.180.234", "HTTP_ACCEPT"=>"*/*", "SCRIPT_FILENAME"=>"/home/kevinc/sites/typo/public/dispatch.fcgi", "REDIRECT_STATUS"=>"200", "REQUEST_METHOD"=>"GET"} + @request_hash = { + "HTTP_MAX_FORWARDS" => "10", + "SERVER_NAME" => "glu.ttono.us:8007", + "FCGI_ROLE" => "RESPONDER", + "AUTH_TYPE" => "Basic", + "HTTP_X_FORWARDED_HOST" => "glu.ttono.us", + "HTTP_ACCEPT_CHARSET" => "UTF-8", + "HTTP_ACCEPT_ENCODING" => "gzip, deflate", + "HTTP_CACHE_CONTROL" => "no-cache, max-age=0", + "HTTP_PRAGMA" => "no-cache", + "HTTP_USER_AGENT" => "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en)", + "PATH_INFO" => "/homepage/", + "HTTP_ACCEPT_LANGUAGE" => "en", + "HTTP_NEGOTIATE" => "trans", + "HTTP_HOST" => "glu.ttono.us:8007", + "HTTP_REFERER" => "http://www.google.com/search?q=glu.ttono.us", + "HTTP_FROM" => "googlebot", + "SERVER_PROTOCOL" => "HTTP/1.1", + "REDIRECT_URI" => "/dispatch.fcgi", + "SCRIPT_NAME" => "/dispatch.fcgi", + "SERVER_ADDR" => "207.7.108.53", + "REMOTE_ADDR" => "207.7.108.53", + "REMOTE_HOST" => "google.com", + "REMOTE_IDENT" => "kevin", + "REMOTE_USER" => "kevin", + "SERVER_SOFTWARE" => "lighttpd/1.4.5", + "HTTP_COOKIE" => "_session_id=c84ace84796670c052c6ceb2451fb0f2; is_admin=yes", + "HTTP_X_FORWARDED_SERVER" => "glu.ttono.us", + "REQUEST_URI" => "/admin", + "DOCUMENT_ROOT" => "/home/kevinc/sites/typo/public", + "PATH_TRANSLATED" => "/home/kevinc/sites/typo/public/homepage/", + "SERVER_PORT" => "8007", + "QUERY_STRING" => "", + "REMOTE_PORT" => "63137", + "GATEWAY_INTERFACE" => "CGI/1.1", + "HTTP_X_FORWARDED_FOR" => "65.88.180.234", + "HTTP_ACCEPT" => "*/*", + "SCRIPT_FILENAME" => "/home/kevinc/sites/typo/public/dispatch.fcgi", + "REDIRECT_STATUS" => "200", + "REQUEST_METHOD" => "GET" + } # some Nokia phone browsers omit the space after the semicolon separator. # some developers have grown accustomed to using comma in cookie values. @alt_cookie_fmt_request_hash = {"HTTP_COOKIE"=>"_session_id=c84ace847,96670c052c6ceb2451fb0f2;is_admin=yes"} - @fake_cgi = Struct.new(:env_table).new(@request_hash) - @request = ActionController::CgiRequest.new(@fake_cgi) + @cgi = CGI.new + @cgi.stubs(:env_table).returns(@request_hash) + @request = ActionController::CgiRequest.new(@cgi) end def default_test; end end - class CgiRequestTest < BaseCgiTest def test_proxy_request assert_equal 'glu.ttono.us', @request.host_with_port @@ -71,6 +111,37 @@ class CgiRequestTest < BaseCgiTest assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", @request.host end + def test_cgi_environment_variables + assert_equal "Basic", @request.auth_type + assert_equal 0, @request.content_length + assert_equal nil, @request.content_type + assert_equal "CGI/1.1", @request.gateway_interface + assert_equal "*/*", @request.accept + assert_equal "UTF-8", @request.accept_charset + assert_equal "gzip, deflate", @request.accept_encoding + assert_equal "en", @request.accept_language + assert_equal "no-cache, max-age=0", @request.cache_control + assert_equal "googlebot", @request.from + assert_equal "glu.ttono.us", @request.host + assert_equal "trans", @request.negotiate + assert_equal "no-cache", @request.pragma + assert_equal "http://www.google.com/search?q=glu.ttono.us", @request.referer + assert_equal "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en)", @request.user_agent + assert_equal "/homepage/", @request.path_info + assert_equal "/home/kevinc/sites/typo/public/homepage/", @request.path_translated + assert_equal "", @request.query_string + assert_equal "207.7.108.53", @request.remote_addr + assert_equal "google.com", @request.remote_host + assert_equal "kevin", @request.remote_ident + assert_equal "kevin", @request.remote_user + assert_equal :get, @request.request_method + assert_equal "/dispatch.fcgi", @request.script_name + assert_equal "glu.ttono.us:8007", @request.server_name + assert_equal 8007, @request.server_port + assert_equal "HTTP/1.1", @request.server_protocol + assert_equal "lighttpd", @request.server_software + end + def test_cookie_syntax_resilience cookies = CGI::Cookie::parse(@request_hash["HTTP_COOKIE"]); assert_equal ["c84ace84796670c052c6ceb2451fb0f2"], cookies["_session_id"], cookies.inspect @@ -82,7 +153,6 @@ class CgiRequestTest < BaseCgiTest end end - class CgiRequestParamsParsingTest < BaseCgiTest def test_doesnt_break_when_content_type_has_charset data = 'flamenco=love' @@ -98,7 +168,6 @@ class CgiRequestParamsParsingTest < BaseCgiTest end end - class CgiRequestNeedsRewoundTest < BaseCgiTest def test_body_should_be_rewound data = 'foo' @@ -119,8 +188,8 @@ uses_mocha 'CGI Response' do class CgiResponseTest < BaseCgiTest def setup super - @fake_cgi.expects(:header).returns("HTTP/1.0 200 OK\nContent-Type: text/html\n") - @response = ActionController::CgiResponse.new(@fake_cgi) + @cgi.expects(:header).returns("HTTP/1.0 200 OK\nContent-Type: text/html\n") + @response = ActionController::CgiResponse.new(@cgi) @output = StringIO.new('') end @@ -132,7 +201,7 @@ uses_mocha 'CGI Response' do end def test_head_request - @fake_cgi.env_table['REQUEST_METHOD'] = 'HEAD' + @cgi.env_table['REQUEST_METHOD'] = 'HEAD' @response.body = "Hello, World!" @response.out(@output) diff --git a/actionpack/test/controller/content_type_test.rb b/actionpack/test/controller/content_type_test.rb index d262ce8103..2019b4a2d0 100644 --- a/actionpack/test/controller/content_type_test.rb +++ b/actionpack/test/controller/content_type_test.rb @@ -13,12 +13,12 @@ class ContentTypeController < ActionController::Base def render_content_type_from_render render :text => "hello world!", :content_type => Mime::RSS end - + def render_charset_from_body response.charset = "utf-16" render :text => "hello world!" end - + def render_default_for_rhtml end @@ -45,7 +45,7 @@ class ContentTypeController < ActionController::Base def rescue_action(e) raise end end -ContentTypeController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ] +ContentTypeController.view_paths = [FIXTURE_LOAD_PATH] class ContentTypeTest < Test::Unit::TestCase def setup @@ -68,7 +68,7 @@ class ContentTypeTest < Test::Unit::TestCase def test_render_changed_charset_default ContentTypeController.default_charset = "utf-16" get :render_defaults - assert_equal "utf-16", @response.charset + assert_equal "utf-16", @response.charset assert_equal Mime::HTML, @response.content_type ContentTypeController.default_charset = "utf-8" end @@ -76,13 +76,13 @@ class ContentTypeTest < Test::Unit::TestCase def test_content_type_from_body get :render_content_type_from_body assert_equal "application/rss+xml", @response.content_type - assert_equal "utf-8", @response.charset + assert_equal "utf-8", @response.charset end def test_content_type_from_render get :render_content_type_from_render assert_equal "application/rss+xml", @response.content_type - assert_equal "utf-8", @response.charset + assert_equal "utf-8", @response.charset end def test_charset_from_body @@ -94,27 +94,27 @@ class ContentTypeTest < Test::Unit::TestCase def test_default_for_rhtml get :render_default_for_rhtml assert_equal Mime::HTML, @response.content_type - assert_equal "utf-8", @response.charset + assert_equal "utf-8", @response.charset end def test_default_for_rxml get :render_default_for_rxml assert_equal Mime::XML, @response.content_type - assert_equal "utf-8", @response.charset + assert_equal "utf-8", @response.charset end def test_default_for_rjs xhr :post, :render_default_for_rjs assert_equal Mime::JS, @response.content_type - assert_equal "utf-8", @response.charset + assert_equal "utf-8", @response.charset end def test_change_for_rxml get :render_change_for_rxml assert_equal Mime::HTML, @response.content_type - assert_equal "utf-8", @response.charset + assert_equal "utf-8", @response.charset end - + def test_render_default_content_types_for_respond_to @request.env["HTTP_ACCEPT"] = Mime::HTML.to_s get :render_default_content_types_for_respond_to @@ -130,7 +130,7 @@ class ContentTypeTest < Test::Unit::TestCase get :render_default_content_types_for_respond_to assert_equal Mime::XML, @response.content_type end - + def test_render_default_content_types_for_respond_to_with_overwrite @request.env["HTTP_ACCEPT"] = Mime::RSS.to_s get :render_default_content_types_for_respond_to diff --git a/actionpack/test/controller/custom_handler_test.rb b/actionpack/test/controller/custom_handler_test.rb deleted file mode 100644 index ac484ae17e..0000000000 --- a/actionpack/test/controller/custom_handler_test.rb +++ /dev/null @@ -1,45 +0,0 @@ -require 'abstract_unit' - -class CustomHandler < ActionView::TemplateHandler - def initialize( view ) - @view = view - end - - def render( template ) - [ template.source, - template.locals, - @view ] - end -end - -class CustomHandlerTest < Test::Unit::TestCase - def setup - ActionView::Template.register_template_handler "foo", CustomHandler - ActionView::Template.register_template_handler :foo2, CustomHandler - @view = ActionView::Base.new - end - - def test_custom_render - template = ActionView::InlineTemplate.new(@view, "hello <%= one %>", { :one => "two" }, "foo") - - result = @view.render_template(template) - assert_equal( - [ "hello <%= one %>", { :one => "two" }, @view ], - result ) - end - - def test_custom_render2 - template = ActionView::InlineTemplate.new(@view, "hello <%= one %>", { :one => "two" }, "foo2") - result = @view.render_template(template) - assert_equal( - [ "hello <%= one %>", { :one => "two" }, @view ], - result ) - end - - def test_unhandled_extension - # uses the ERb handler by default if the extension isn't recognized - template = ActionView::InlineTemplate.new(@view, "hello <%= one %>", { :one => "two" }, "bar") - result = @view.render_template(template) - assert_equal "hello two", result - end -end diff --git a/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb b/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb index 8c1a8954a5..f485500b7f 100644 --- a/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb +++ b/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb @@ -2,7 +2,6 @@ require 'abstract_unit' class DeprecatedBaseMethodsTest < Test::Unit::TestCase class Target < ActionController::Base - def home_url(greeting) "http://example.com/#{greeting}" end @@ -14,7 +13,7 @@ class DeprecatedBaseMethodsTest < Test::Unit::TestCase def rescue_action(e) raise e end end - Target.view_paths = [ File.dirname(__FILE__) + "/../../fixtures" ] + Target.view_paths = [FIXTURE_LOAD_PATH] def setup @request = ActionController::TestRequest.new diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb index 3dc311b78a..52ab72bb99 100644 --- a/actionpack/test/controller/layout_test.rb +++ b/actionpack/test/controller/layout_test.rb @@ -40,7 +40,7 @@ class MabView < ActionView::TemplateHandler end end -ActionView::Template::register_template_handler :mab, MabView +ActionView::Base.register_template_handler :mab, MabView class LayoutAutoDiscoveryTest < Test::Unit::TestCase def setup diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index c617cb2e84..fb2519563d 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -107,7 +107,7 @@ class RespondToController < ActionController::Base type.any(:js, :xml) { render :text => "Either JS or XML" } end end - + def handle_any_any respond_to do |type| type.html { render :text => 'HTML' } @@ -120,12 +120,12 @@ class RespondToController < ActionController::Base type.html type.js end - end - - def iphone_with_html_response_type + end + + def iphone_with_html_response_type Mime::Type.register_alias("text/html", :iphone) request.format = :iphone if request.env["HTTP_ACCEPT"] == "text/iphone" - + respond_to do |type| type.html { @type = "Firefox" } type.iphone { @type = "iPhone" } @@ -138,7 +138,7 @@ class RespondToController < ActionController::Base def iphone_with_html_response_type_without_layout Mime::Type.register_alias("text/html", :iphone) request.format = "iphone" if request.env["HTTP_ACCEPT"] == "text/iphone" - + respond_to do |type| type.html { @type = "Firefox"; render :action => "iphone_with_html_response_type" } type.iphone { @type = "iPhone" ; render :action => "iphone_with_html_response_type" } @@ -162,7 +162,7 @@ class RespondToController < ActionController::Base end end -RespondToController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ] +RespondToController.view_paths = [FIXTURE_LOAD_PATH] class MimeControllerTest < Test::Unit::TestCase def setup @@ -247,7 +247,7 @@ class MimeControllerTest < Test::Unit::TestCase get :just_xml assert_equal 'XML', @response.body end - + def test_using_defaults @request.env["HTTP_ACCEPT"] = "*/*" get :using_defaults @@ -347,12 +347,12 @@ class MimeControllerTest < Test::Unit::TestCase get :handle_any_any assert_equal 'HTML', @response.body end - + def test_handle_any_any_parameter_format get :handle_any_any, {:format=>'html'} assert_equal 'HTML', @response.body end - + def test_handle_any_any_explicit_html @request.env["HTTP_ACCEPT"] = "text/html" get :handle_any_any @@ -364,7 +364,7 @@ class MimeControllerTest < Test::Unit::TestCase get :handle_any_any assert_equal 'Whatever you ask for, I got it', @response.body end - + def test_handle_any_any_xml @request.env["HTTP_ACCEPT"] = "text/xml" get :handle_any_any @@ -445,31 +445,31 @@ class MimeControllerTest < Test::Unit::TestCase get :using_defaults, :format => "xml" assert_equal "using_defaults - xml", @response.body - end - + end + def test_format_with_custom_response_type get :iphone_with_html_response_type - assert_equal '<html><div id="html">Hello future from Firefox!</div></html>', @response.body - + assert_equal '<html><div id="html">Hello future from Firefox!</div></html>', @response.body + get :iphone_with_html_response_type, :format => "iphone" assert_equal "text/html", @response.content_type assert_equal '<html><div id="iphone">Hello iPhone future from iPhone!</div></html>', @response.body - end - + end + def test_format_with_custom_response_type_and_request_headers @request.env["HTTP_ACCEPT"] = "text/iphone" get :iphone_with_html_response_type assert_equal '<html><div id="iphone">Hello iPhone future from iPhone!</div></html>', @response.body assert_equal "text/html", @response.content_type - end + end def test_format_with_custom_response_type_and_request_headers_with_only_one_layout_present get :iphone_with_html_response_type_without_layout - assert_equal '<html><div id="html_missing">Hello future from Firefox!</div></html>', @response.body + assert_equal '<html><div id="html_missing">Hello future from Firefox!</div></html>', @response.body @request.env["HTTP_ACCEPT"] = "text/iphone" assert_raises(ActionView::MissingTemplate) { get :iphone_with_html_response_type_without_layout } - end + end end class AbstractPostController < ActionController::Base @@ -497,7 +497,7 @@ class PostController < AbstractPostController end end -class SuperPostController < PostController +class SuperPostController < PostController def index respond_to do |type| type.html @@ -514,25 +514,24 @@ class MimeControllerLayoutsTest < Test::Unit::TestCase @controller = PostController.new @request.host = "www.example.com" end - + def test_missing_layout_renders_properly get :index - assert_equal '<html><div id="html">Hello Firefox</div></html>', @response.body + assert_equal '<html><div id="html">Hello Firefox</div></html>', @response.body @request.env["HTTP_ACCEPT"] = "text/iphone" get :index assert_equal 'Hello iPhone', @response.body end - + def test_format_with_inherited_layouts @controller = SuperPostController.new - + get :index assert_equal 'Super Firefox', @response.body - + @request.env["HTTP_ACCEPT"] = "text/iphone" get :index assert_equal '<html><div id="super_iphone">Super iPhone</div></html>', @response.body end end - diff --git a/actionpack/test/controller/new_render_test.rb b/actionpack/test/controller/new_render_test.rb index b77b3ceffa..b2691d981b 100644 --- a/actionpack/test/controller/new_render_test.rb +++ b/actionpack/test/controller/new_render_test.rb @@ -45,11 +45,11 @@ class NewRenderTestController < ActionController::Base def render_action_hello_world_as_symbol render :action => :hello_world end - + def render_text_hello_world render :text => "hello world" end - + def render_text_hello_world_with_layout @variable_for_layout = ", I'm here!" render :text => "hello world", :layout => true @@ -68,7 +68,7 @@ class NewRenderTestController < ActionController::Base path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb') render :file => path 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')) @@ -76,17 +76,17 @@ class NewRenderTestController < ActionController::Base def render_file_with_locals path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_locals.erb') - render :file => path, :locals => {:secret => 'in the sauce'} + render :file => path, :locals => {:secret => 'in the sauce'} end def render_file_not_using_full_path @secret = 'in the sauce' - render :file => 'test/render_file_with_ivar', :use_full_path => true + render :file => 'test/render_file_with_ivar' end - + def render_file_not_using_full_path_with_dot_in_path @secret = 'in the sauce' - render :file => 'test/dot.directory/render_file_with_ivar', :use_full_path => true + render :file => 'test/dot.directory/render_file_with_ivar' end def render_xml_hello @@ -105,7 +105,7 @@ class NewRenderTestController < ActionController::Base def layout_test_with_different_layout render :action => "hello_world", :layout => "standard" end - + def rendering_without_layout render :action => "hello_world", :layout => false end @@ -113,11 +113,11 @@ class NewRenderTestController < ActionController::Base def layout_overriding_layout render :action => "hello_world", :layout => "standard" end - + def rendering_nothing_on_layout render :nothing => true end - + def builder_layout_test render :action => "hello" end @@ -135,9 +135,9 @@ class NewRenderTestController < ActionController::Base def partial_only_with_layout render :partial => "partial_only", :layout => true end - + def partial_with_locals - render :partial => "customer", :locals => { :customer => Customer.new("david") } + render :partial => "customer", :locals => { :customer => Customer.new("david") } end def partial_with_form_builder @@ -151,11 +151,15 @@ class NewRenderTestController < ActionController::Base def partial_collection render :partial => "customer", :collection => [ Customer.new("david"), Customer.new("mary") ] end - + + def partial_collection_with_as + render :partial => "customer_with_var", :collection => [ Customer.new("david"), Customer.new("mary") ], :as => :customer + end + def partial_collection_with_spacer render :partial => "customer", :spacer_template => "partial_only", :collection => [ Customer.new("david"), Customer.new("mary") ] end - + def partial_collection_with_counter render :partial => "customer_counter", :collection => [ Customer.new("david"), Customer.new("mary") ] end @@ -186,33 +190,33 @@ class NewRenderTestController < ActionController::Base def empty_partial_collection render :partial => "customer", :collection => [] end - + def partial_with_hash_object render :partial => "hash_object", :object => {:first_name => "Sam"} end - + def partial_hash_collection render :partial => "hash_object", :collection => [ {:first_name => "Pratik"}, {:first_name => "Amy"} ] end - + def partial_hash_collection_with_locals render :partial => "hash_greeting", :collection => [ {:first_name => "Pratik"}, {:first_name => "Amy"} ], :locals => { :greeting => "Hola" } end - + def partial_with_implicit_local_assignment @customer = Customer.new("Marcel") render :partial => "customer" end - + def missing_partial render :partial => 'thisFileIsntHere' end - + def hello_in_a_string @customers = [ Customer.new("david"), Customer.new("mary") ] render :text => "How's there? " << render_to_string(:template => "test/list") end - + def render_to_string_with_assigns @before = "i'm before the render" render_to_string :text => "foo" @@ -222,18 +226,18 @@ class NewRenderTestController < ActionController::Base def render_to_string_with_partial @partial_only = render_to_string :partial => "partial_only" - @partial_with_locals = render_to_string :partial => "customer", :locals => { :customer => Customer.new("david") } - render :action => "test/hello_world" - end - + @partial_with_locals = render_to_string :partial => "customer", :locals => { :customer => Customer.new("david") } + render :action => "test/hello_world" + end + def render_to_string_with_exception - render_to_string :file => "exception that will not be caught - this will certainly not work", :use_full_path => true + render_to_string :file => "exception that will not be caught - this will certainly not work" end - + def render_to_string_with_caught_exception @before = "i'm before the render" begin - render_to_string :file => "exception that will be caught- hope my future instance vars still work!", :use_full_path => true + render_to_string :file => "exception that will be caught- hope my future instance vars still work!" rescue end @after = "i'm after the render" @@ -268,6 +272,10 @@ class NewRenderTestController < ActionController::Base render :template => "test/hello_world" end + def render_with_explicit_template_with_locals + render :template => "test/render_file_with_locals", :locals => { :secret => 'area51' } + end + def double_render render :text => "hello" render :text => "world" @@ -282,7 +290,7 @@ class NewRenderTestController < ActionController::Base render :text => "hello" redirect_to :action => "double_render" end - + def render_to_string_and_render @stuff = render_to_string :text => "here is some cached stuff" render :text => "Hi web users! #{@stuff}" @@ -329,7 +337,7 @@ class NewRenderTestController < ActionController::Base def render_with_location render :xml => "<hello/>", :location => "http://example.com", :status => 201 end - + def render_with_object_location customer = Customer.new("Some guy", 1) render :xml => "<customer/>", :location => customer_url(customer), :status => :created @@ -341,12 +349,12 @@ class NewRenderTestController < ActionController::Base "<i-am-xml/>" end end.new - + render :xml => to_xmlable end helper NewRenderTestHelper - helper do + helper do def rjs_helper_method(value) page.visual_effect :highlight, value end @@ -383,7 +391,7 @@ class NewRenderTestController < ActionController::Base page.visual_effect :highlight, 'balance' end end - + def update_page_with_instance_variables @money = '$37,000,000.00' @div_id = 'balance' @@ -426,12 +434,12 @@ class NewRenderTestController < ActionController::Base def render_using_layout_around_block_in_main_layout_and_within_content_for_layout render :action => "using_layout_around_block" end - + def rescue_action(e) raise end - + private def determine_layout - case action_name + case action_name when "hello_world", "layout_test", "rendering_without_layout", "rendering_nothing_on_layout", "render_text_hello_world", "render_text_hello_world_with_layout", @@ -443,7 +451,7 @@ class NewRenderTestController < ActionController::Base "render_js_with_explicit_template", "render_js_with_explicit_action_template", "delete_with_js", "update_page", "update_page_with_instance_variables" - + "layouts/standard" when "builder_layout_test" "layouts/builder" @@ -457,8 +465,8 @@ class NewRenderTestController < ActionController::Base end end -NewRenderTestController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ] -Fun::GamesController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ] +NewRenderTestController.view_paths = [FIXTURE_LOAD_PATH] +Fun::GamesController.view_paths = [FIXTURE_LOAD_PATH] class NewRenderTest < Test::Unit::TestCase def setup @@ -527,7 +535,7 @@ class NewRenderTest < Test::Unit::TestCase end def test_render_file_not_using_full_path - get :render_file_not_using_full_path + get :render_file_not_using_full_path assert_equal "The secret is in the sauce\n", @response.body end @@ -540,7 +548,7 @@ class NewRenderTest < Test::Unit::TestCase get :render_file_with_locals assert_equal "The secret is in the sauce\n", @response.body end - + def test_render_file_from_template get :render_file_from_template assert_equal "The secret is in the sauce\n", @response.body @@ -597,8 +605,7 @@ EOS end def test_render_with_default_from_accept_header - @request.env["HTTP_ACCEPT"] = "text/javascript" - get :greeting + xhr :get, :greeting assert_equal "$(\"body\").visualEffect(\"highlight\");", @response.body end @@ -661,7 +668,7 @@ EOS assert_not_deprecated { get :hello_in_a_string } assert_equal "How's there? goodbyeHello: davidHello: marygoodbye\n", @response.body end - + def test_render_to_string_doesnt_break_assigns get :render_to_string_with_assigns assert_equal "i'm before the render", assigns(:before) @@ -672,12 +679,12 @@ EOS get :render_to_string_with_partial assert_equal "only partial", assigns(:partial_only) assert_equal "Hello: david", assigns(:partial_with_locals) - end + end def test_bad_render_to_string_still_throws_exception assert_raises(ActionView::MissingTemplate) { get :render_to_string_with_exception } end - + def test_render_to_string_that_throws_caught_exception_doesnt_break_assigns assert_nothing_raised { get :render_to_string_with_caught_exception } assert_equal "i'm before the render", assigns(:before) @@ -715,7 +722,7 @@ EOS def test_render_and_redirect assert_raises(ActionController::DoubleRenderError) { get :render_and_redirect } end - + # specify the one exception to double render rule - render_to_string followed by render def test_render_to_string_and_render get :render_to_string_and_render @@ -736,7 +743,7 @@ EOS get :partials_list assert_equal "goodbyeHello: davidHello: marygoodbye\n", @response.body end - + def test_partial_with_locals get :partial_with_locals assert_equal "Hello: david", @response.body @@ -758,17 +765,22 @@ EOS get :partial_collection assert_equal "Hello: davidHello: mary", @response.body end - + + def test_partial_collection_with_as + get :partial_collection_with_as + assert_equal "david david davidmary mary mary", @response.body + end + def test_partial_collection_with_counter get :partial_collection_with_counter assert_equal "david0mary1", @response.body end - + def test_partial_collection_with_locals get :partial_collection_with_locals assert_equal "Bonjour: davidBonjour: mary", @response.body end - + def test_partial_collection_with_spacer get :partial_collection_with_spacer assert_equal "Hello: davidonly partialHello: mary", @response.body @@ -793,12 +805,12 @@ EOS get :partial_with_hash_object assert_equal "Sam\nmaS\n", @response.body end - + def test_hash_partial_collection get :partial_hash_collection assert_equal "Pratik\nkitarP\nAmy\nymA\n", @response.body end - + def test_partial_hash_collection_with_locals get :partial_hash_collection_with_locals assert_equal "Hola: PratikHola: Amy", @response.body @@ -808,25 +820,30 @@ EOS get :partial_with_implicit_local_assignment assert_equal "Hello: Marcel", @response.body end - + def test_render_missing_partial_template assert_raises(ActionView::MissingTemplate) do get :missing_partial end end - + def test_render_text_with_assigns get :render_text_with_assigns assert_equal "world", assigns["hello"] end - + + def test_template_with_locals + get :render_with_explicit_template_with_locals + assert_equal "The secret is area51\n", @response.body + end + def test_update_page get :update_page assert_template nil assert_equal 'text/javascript; charset=utf-8', @response.headers['type'] assert_equal 2, @response.body.split($/).length end - + def test_update_page_with_instance_variables get :update_page_with_instance_variables assert_template nil @@ -834,7 +851,7 @@ EOS assert_match /balance/, @response.body assert_match /\$37/, @response.body end - + def test_yield_content_for assert_not_deprecated { get :yield_content_for } assert_equal "<title>Putting stuff in the title!</title>\n\nGreat stuff!\n", @response.body @@ -906,12 +923,12 @@ EOS get :render_with_location assert_equal "http://example.com", @response.headers["Location"] end - + def test_rendering_xml_should_call_to_xml_if_possible get :render_with_to_xml assert_equal "<i-am-xml/>", @response.body end - + def test_rendering_with_object_location_should_set_header_with_url_for ActionController::Routing::Routes.draw do |map| map.resources :customers @@ -941,5 +958,4 @@ EOS get :render_using_layout_around_block_in_main_layout_and_within_content_for_layout assert_equal "Before (Anthony)\nInside from first block in layout\nAfter\nBefore (David)\nInside from block\nAfter\nBefore (Ramm)\nInside from second block in layout\nAfter\n", @response.body end - end diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb index 856f24bbdb..486fe49737 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/controller/rack_test.rb @@ -7,22 +7,33 @@ class BaseRackTest < Test::Unit::TestCase "HTTP_MAX_FORWARDS" => "10", "SERVER_NAME" => "glu.ttono.us:8007", "FCGI_ROLE" => "RESPONDER", + "AUTH_TYPE" => "Basic", "HTTP_X_FORWARDED_HOST" => "glu.ttono.us", + "HTTP_ACCEPT_CHARSET" => "UTF-8", "HTTP_ACCEPT_ENCODING" => "gzip, deflate", + "HTTP_CACHE_CONTROL" => "no-cache, max-age=0", + "HTTP_PRAGMA" => "no-cache", "HTTP_USER_AGENT" => "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en)", - "PATH_INFO" => "", + "PATH_INFO" => "/homepage/", "HTTP_ACCEPT_LANGUAGE" => "en", + "HTTP_NEGOTIATE" => "trans", "HTTP_HOST" => "glu.ttono.us:8007", + "HTTP_REFERER" => "http://www.google.com/search?q=glu.ttono.us", + "HTTP_FROM" => "googlebot", "SERVER_PROTOCOL" => "HTTP/1.1", "REDIRECT_URI" => "/dispatch.fcgi", "SCRIPT_NAME" => "/dispatch.fcgi", "SERVER_ADDR" => "207.7.108.53", "REMOTE_ADDR" => "207.7.108.53", + "REMOTE_HOST" => "google.com", + "REMOTE_IDENT" => "kevin", + "REMOTE_USER" => "kevin", "SERVER_SOFTWARE" => "lighttpd/1.4.5", "HTTP_COOKIE" => "_session_id=c84ace84796670c052c6ceb2451fb0f2; is_admin=yes", "HTTP_X_FORWARDED_SERVER" => "glu.ttono.us", "REQUEST_URI" => "/admin", "DOCUMENT_ROOT" => "/home/kevinc/sites/typo/public", + "PATH_TRANSLATED" => "/home/kevinc/sites/typo/public/homepage/", "SERVER_PORT" => "8007", "QUERY_STRING" => "", "REMOTE_PORT" => "63137", @@ -42,7 +53,6 @@ class BaseRackTest < Test::Unit::TestCase def default_test; end end - class RackRequestTest < BaseRackTest def test_proxy_request assert_equal 'glu.ttono.us', @request.host_with_port @@ -99,6 +109,37 @@ class RackRequestTest < BaseRackTest assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", @request.host end + def test_cgi_environment_variables + assert_equal "Basic", @request.auth_type + assert_equal 0, @request.content_length + assert_equal nil, @request.content_type + assert_equal "CGI/1.1", @request.gateway_interface + assert_equal "*/*", @request.accept + assert_equal "UTF-8", @request.accept_charset + assert_equal "gzip, deflate", @request.accept_encoding + assert_equal "en", @request.accept_language + assert_equal "no-cache, max-age=0", @request.cache_control + assert_equal "googlebot", @request.from + assert_equal "glu.ttono.us", @request.host + assert_equal "trans", @request.negotiate + assert_equal "no-cache", @request.pragma + assert_equal "http://www.google.com/search?q=glu.ttono.us", @request.referer + assert_equal "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en)", @request.user_agent + assert_equal "/homepage/", @request.path_info + assert_equal "/home/kevinc/sites/typo/public/homepage/", @request.path_translated + assert_equal "", @request.query_string + assert_equal "207.7.108.53", @request.remote_addr + assert_equal "google.com", @request.remote_host + assert_equal "kevin", @request.remote_ident + assert_equal "kevin", @request.remote_user + assert_equal :get, @request.request_method + assert_equal "/dispatch.fcgi", @request.script_name + assert_equal "glu.ttono.us:8007", @request.server_name + assert_equal 8007, @request.server_port + assert_equal "HTTP/1.1", @request.server_protocol + assert_equal "lighttpd", @request.server_software + end + def test_cookie_syntax_resilience cookies = @request.cookies assert_equal ["c84ace84796670c052c6ceb2451fb0f2"], cookies["_session_id"], cookies.inspect @@ -110,7 +151,6 @@ class RackRequestTest < BaseRackTest end end - class RackRequestParamsParsingTest < BaseRackTest def test_doesnt_break_when_content_type_has_charset data = 'flamenco=love' @@ -126,7 +166,6 @@ class RackRequestParamsParsingTest < BaseRackTest end end - class RackRequestNeedsRewoundTest < BaseRackTest def test_body_should_be_rewound data = 'foo' @@ -143,7 +182,6 @@ class RackRequestNeedsRewoundTest < BaseRackTest end end - class RackResponseTest < BaseRackTest def setup super @@ -155,7 +193,7 @@ class RackResponseTest < BaseRackTest @response.body = "Hello, World!" status, headers, body = @response.out(@output) - assert_equal 200, status + assert_equal "200 OK", status assert_equal({"Content-Type" => "text/html", "Cache-Control" => "no-cache", "Set-Cookie" => []}, headers) parts = [] @@ -169,7 +207,7 @@ class RackResponseTest < BaseRackTest end status, headers, body = @response.out(@output) - assert_equal 200, status + assert_equal "200 OK", status assert_equal({"Content-Type" => "text/html", "Cache-Control" => "no-cache", "Set-Cookie" => []}, headers) parts = [] @@ -184,7 +222,7 @@ class RackResponseTest < BaseRackTest @response.body = "Hello, World!" status, headers, body = @response.out(@output) - assert_equal 200, status + assert_equal "200 OK", status assert_equal({ "Content-Type" => "text/html", "Cache-Control" => "no-cache", diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 066fa6acd4..10264dadaa 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -23,11 +23,11 @@ class TestController < ActionController::Base def render_hello_world_with_forward_slash render :template => "/test/hello_world" end - + def render_template_in_top_directory render :template => 'shared' end - + def render_template_in_top_directory_with_slash render :template => '/shared' end @@ -86,7 +86,7 @@ class TestController < ActionController::Base def render_nothing_with_appendix render :text => "appended" end - + def render_invalid_args render("test/hello") end @@ -103,7 +103,7 @@ class TestController < ActionController::Base def render_line_offset begin render :inline => '<% raise %>', :locals => {:foo => 'bar'} - rescue => exc + rescue RuntimeError => exc end line = exc.backtrace.first render :text => line @@ -171,7 +171,7 @@ class TestController < ActionController::Base def partial_dot_html render :partial => 'partial.html.erb' end - + def partial_as_rjs render :update do |page| page.replace :foo, :partial => 'partial' @@ -217,8 +217,8 @@ class TestController < ActionController::Base end end -TestController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ] -Fun::GamesController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ] +TestController.view_paths = [FIXTURE_LOAD_PATH] +Fun::GamesController.view_paths = [FIXTURE_LOAD_PATH] class RenderTest < Test::Unit::TestCase def setup @@ -251,13 +251,13 @@ class RenderTest < Test::Unit::TestCase get :render_hello_world_with_forward_slash assert_template "test/hello_world" end - + def test_render_in_top_directory get :render_template_in_top_directory assert_template "shared" assert_equal "Elastica", @response.body end - + def test_render_in_top_directory_with_slash get :render_template_in_top_directory_with_slash assert_template "shared" @@ -336,11 +336,11 @@ class RenderTest < Test::Unit::TestCase assert_response 200 assert_equal 'appended', @response.body end - + def test_attempt_to_render_with_invalid_arguments assert_raises(ActionController::RenderError) { get :render_invalid_args } end - + def test_attempt_to_access_object_method assert_raises(ActionController::UnknownAction, "No action responded to [clone]") { get :clone } end @@ -467,17 +467,17 @@ class RenderTest < Test::Unit::TestCase get :formatted_html_erb assert_equal 'formatted html erb', @response.body end - + def test_should_render_formatted_xml_erb_template get :formatted_xml_erb, :format => :xml assert_equal '<test>passed formatted xml erb</test>', @response.body end - + def test_should_render_formatted_html_erb_template get :formatted_xml_erb assert_equal '<test>passed formatted html erb</test>', @response.body end - + def test_should_render_formatted_html_erb_template_with_faulty_accepts_header @request.env["HTTP_ACCEPT"] = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, appliction/x-shockwave-flash, */*" get :formatted_xml_erb @@ -520,7 +520,6 @@ class RenderTest < Test::Unit::TestCase end protected - def etag_for(text) %("#{Digest::MD5.hexdigest(text)}") end diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb index 2bd489b2c7..20f3fd4d7b 100644 --- a/actionpack/test/controller/request_test.rb +++ b/actionpack/test/controller/request_test.rb @@ -909,15 +909,21 @@ class LegacyXmlParamsParsingTest < XmlParamsParsingTest end class JsonParamsParsingTest < Test::Unit::TestCase - def test_hash_params - person = parse_body({:person => {:name => "David"}}.to_json)[:person] + def test_hash_params_for_application_json + person = parse_body({:person => {:name => "David"}}.to_json,'application/json')[:person] + assert_kind_of Hash, person + assert_equal 'David', person['name'] + end + + def test_hash_params_for_application_jsonrequest + person = parse_body({:person => {:name => "David"}}.to_json,'application/jsonrequest')[:person] assert_kind_of Hash, person assert_equal 'David', person['name'] end private - def parse_body(body) - env = { 'CONTENT_TYPE' => 'application/json', + def parse_body(body,content_type) + env = { 'CONTENT_TYPE' => content_type, 'CONTENT_LENGTH' => body.size.to_s } cgi = ActionController::Integration::Session::StubCGI.new(env, body) ActionController::CgiRequest.new(cgi).request_parameters diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 07c13ebbf7..c5ccb71582 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -2039,6 +2039,26 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do Object.send(:remove_const, :Api) end + def test_namespace_with_path_prefix + 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" + 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" diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb index 406825fe59..ddec51d173 100644 --- a/actionpack/test/controller/send_file_test.rb +++ b/actionpack/test/controller/send_file_test.rb @@ -1,13 +1,11 @@ require 'abstract_unit' - module TestFileUtils def file_name() File.basename(__FILE__) end def file_path() File.expand_path(__FILE__) end def file_data() File.open(file_path, 'rb') { |f| f.read } end end - class SendFileController < ActionController::Base include TestFileUtils layout "layouts/standard" # to make sure layouts don't interfere @@ -21,7 +19,7 @@ class SendFileController < ActionController::Base def rescue_action(e) raise end end -SendFileController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ] +SendFileController.view_paths = [FIXTURE_LOAD_PATH] class SendFileTest < Test::Unit::TestCase include TestFileUtils diff --git a/actionpack/test/controller/view_paths_test.rb b/actionpack/test/controller/view_paths_test.rb index 1b4c1fae2f..9401c87d10 100644 --- a/actionpack/test/controller/view_paths_test.rb +++ b/actionpack/test/controller/view_paths_test.rb @@ -1,9 +1,7 @@ require 'abstract_unit' class ViewLoadPathsTest < Test::Unit::TestCase - LOAD_PATH_ROOT = File.join(File.dirname(__FILE__), '..', 'fixtures') - - ActionController::Base.view_paths = [LOAD_PATH_ROOT] + ActionController::Base.view_paths = [FIXTURE_LOAD_PATH] class TestController < ActionController::Base def self.controller_path() "test" end @@ -16,7 +14,7 @@ class ViewLoadPathsTest < Test::Unit::TestCase private def add_view_path - prepend_view_path "#{LOAD_PATH_ROOT}/override" + prepend_view_path "#{FIXTURE_LOAD_PATH}/override" end end @@ -47,35 +45,35 @@ class ViewLoadPathsTest < Test::Unit::TestCase end def test_template_load_path_was_set_correctly - assert_equal [ LOAD_PATH_ROOT ], @controller.view_paths.map(&:to_s) + assert_equal [FIXTURE_LOAD_PATH], @controller.view_paths end def test_controller_appends_view_path_correctly @controller.append_view_path 'foo' - assert_equal [LOAD_PATH_ROOT, 'foo'], @controller.view_paths.map(&:to_s) + assert_equal [FIXTURE_LOAD_PATH, 'foo'], @controller.view_paths @controller.append_view_path(%w(bar baz)) - assert_equal [LOAD_PATH_ROOT, 'foo', 'bar', 'baz'], @controller.view_paths.map(&:to_s) + assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths - @controller.append_view_path(LOAD_PATH_ROOT) - assert_equal ['foo', 'bar', 'baz', LOAD_PATH_ROOT], @controller.view_paths.map(&:to_s) + @controller.append_view_path(FIXTURE_LOAD_PATH) + assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths - @controller.append_view_path([LOAD_PATH_ROOT]) - assert_equal ['foo', 'bar', 'baz', LOAD_PATH_ROOT], @controller.view_paths.map(&:to_s) + @controller.append_view_path([FIXTURE_LOAD_PATH]) + assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths end def test_controller_prepends_view_path_correctly @controller.prepend_view_path 'baz' - assert_equal ['baz', LOAD_PATH_ROOT], @controller.view_paths.map(&:to_s) + assert_equal ['baz', FIXTURE_LOAD_PATH], @controller.view_paths @controller.prepend_view_path(%w(foo bar)) - assert_equal ['foo', 'bar', 'baz', LOAD_PATH_ROOT], @controller.view_paths.map(&:to_s) + assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths - @controller.prepend_view_path(LOAD_PATH_ROOT) - assert_equal [LOAD_PATH_ROOT, 'foo', 'bar', 'baz'], @controller.view_paths.map(&:to_s) + @controller.prepend_view_path(FIXTURE_LOAD_PATH) + assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths - @controller.prepend_view_path([LOAD_PATH_ROOT]) - assert_equal [LOAD_PATH_ROOT, 'foo', 'bar', 'baz'], @controller.view_paths.map(&:to_s) + @controller.prepend_view_path([FIXTURE_LOAD_PATH]) + assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths end def test_template_appends_view_path_correctly @@ -83,10 +81,10 @@ class ViewLoadPathsTest < Test::Unit::TestCase class_view_paths = TestController.view_paths @controller.append_view_path 'foo' - assert_equal [LOAD_PATH_ROOT, 'foo'], @controller.view_paths.map(&:to_s) + assert_equal [FIXTURE_LOAD_PATH, 'foo'], @controller.view_paths @controller.append_view_path(%w(bar baz)) - assert_equal [LOAD_PATH_ROOT, 'foo', 'bar', 'baz'], @controller.view_paths.map(&:to_s) + assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths assert_equal class_view_paths, TestController.view_paths end @@ -95,10 +93,10 @@ class ViewLoadPathsTest < Test::Unit::TestCase class_view_paths = TestController.view_paths @controller.prepend_view_path 'baz' - assert_equal ['baz', LOAD_PATH_ROOT], @controller.view_paths.map(&:to_s) + assert_equal ['baz', FIXTURE_LOAD_PATH], @controller.view_paths @controller.prepend_view_path(%w(foo bar)) - assert_equal ['foo', 'bar', 'baz', LOAD_PATH_ROOT], @controller.view_paths.map(&:to_s) + assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths assert_equal class_view_paths, TestController.view_paths end @@ -109,7 +107,7 @@ class ViewLoadPathsTest < Test::Unit::TestCase end def test_view_paths_override - TestController.prepend_view_path "#{LOAD_PATH_ROOT}/override" + TestController.prepend_view_path "#{FIXTURE_LOAD_PATH}/override" get :hello_world assert_response :success assert_equal "Hello overridden world!", @response.body @@ -117,7 +115,7 @@ class ViewLoadPathsTest < Test::Unit::TestCase def test_view_paths_override_for_layouts_in_controllers_with_a_module @controller = Test::SubController.new - Test::SubController.view_paths = [ "#{LOAD_PATH_ROOT}/override", LOAD_PATH_ROOT, "#{LOAD_PATH_ROOT}/override2" ] + Test::SubController.view_paths = [ "#{FIXTURE_LOAD_PATH}/override", FIXTURE_LOAD_PATH, "#{FIXTURE_LOAD_PATH}/override2" ] get :hello_world assert_response :success assert_equal "layout: Hello overridden world!", @response.body @@ -140,13 +138,13 @@ class ViewLoadPathsTest < Test::Unit::TestCase A.view_paths = ['a/path'] - assert_equal ['a/path'], A.view_paths.map(&:to_s) + assert_equal ['a/path'], A.view_paths assert_equal A.view_paths, B.view_paths assert_equal original_load_paths, C.view_paths C.view_paths = [] assert_nothing_raised { C.view_paths << 'c/path' } - assert_equal ['c/path'], C.view_paths.map(&:to_s) + assert_equal ['c/path'], C.view_paths end def test_find_template_file_for_path |