From db045dbbf60b53dbe013ef25554fd013baf88134 Mon Sep 17 00:00:00 2001
From: David Heinemeier Hansson
Date: Wed, 24 Nov 2004 01:04:44 +0000
Subject: Initial
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
---
actionpack/test/abstract_unit.rb | 9 +
.../test/controller/action_pack_assertions_test.rb | 323 ++++++++++++++++++
.../controller/active_record_assertions_test.rb | 119 +++++++
actionpack/test/controller/cgi_test.rb | 142 ++++++++
actionpack/test/controller/cookie_test.rb | 38 +++
actionpack/test/controller/filters_test.rb | 159 +++++++++
actionpack/test/controller/flash_test.rb | 69 ++++
actionpack/test/controller/helper_test.rb | 110 ++++++
actionpack/test/controller/layout_test.rb | 49 +++
actionpack/test/controller/redirect_test.rb | 44 +++
actionpack/test/controller/render_test.rb | 178 ++++++++++
actionpack/test/controller/send_file_test.rb | 68 ++++
actionpack/test/controller/url_test.rb | 368 +++++++++++++++++++++
actionpack/test/fixtures/helpers/abc_helper.rb | 5 +
actionpack/test/fixtures/layouts/builder.rxml | 3 +
actionpack/test/fixtures/layouts/standard.rhtml | 1 +
actionpack/test/fixtures/scope/test/modgreet.rhtml | 1 +
actionpack/test/fixtures/test/_customer.rhtml | 1 +
actionpack/test/fixtures/test/greeting.rhtml | 1 +
actionpack/test/fixtures/test/hello.rxml | 4 +
actionpack/test/fixtures/test/hello_world.rhtml | 1 +
actionpack/test/fixtures/test/hello_xml_world.rxml | 11 +
actionpack/test/fixtures/test/list.rhtml | 1 +
.../test/template/active_record_helper_test.rb | 76 +++++
actionpack/test/template/date_helper_test.rb | 104 ++++++
actionpack/test/template/form_helper_test.rb | 124 +++++++
.../test/template/form_options_helper_test.rb | 165 +++++++++
actionpack/test/template/tag_helper_test.rb | 18 +
actionpack/test/template/text_helper_test.rb | 62 ++++
actionpack/test/template/url_helper_test.rb | 49 +++
30 files changed, 2303 insertions(+)
create mode 100644 actionpack/test/abstract_unit.rb
create mode 100644 actionpack/test/controller/action_pack_assertions_test.rb
create mode 100644 actionpack/test/controller/active_record_assertions_test.rb
create mode 100755 actionpack/test/controller/cgi_test.rb
create mode 100644 actionpack/test/controller/cookie_test.rb
create mode 100644 actionpack/test/controller/filters_test.rb
create mode 100644 actionpack/test/controller/flash_test.rb
create mode 100644 actionpack/test/controller/helper_test.rb
create mode 100644 actionpack/test/controller/layout_test.rb
create mode 100755 actionpack/test/controller/redirect_test.rb
create mode 100644 actionpack/test/controller/render_test.rb
create mode 100644 actionpack/test/controller/send_file_test.rb
create mode 100644 actionpack/test/controller/url_test.rb
create mode 100644 actionpack/test/fixtures/helpers/abc_helper.rb
create mode 100644 actionpack/test/fixtures/layouts/builder.rxml
create mode 100644 actionpack/test/fixtures/layouts/standard.rhtml
create mode 100644 actionpack/test/fixtures/scope/test/modgreet.rhtml
create mode 100644 actionpack/test/fixtures/test/_customer.rhtml
create mode 100644 actionpack/test/fixtures/test/greeting.rhtml
create mode 100644 actionpack/test/fixtures/test/hello.rxml
create mode 100644 actionpack/test/fixtures/test/hello_world.rhtml
create mode 100644 actionpack/test/fixtures/test/hello_xml_world.rxml
create mode 100644 actionpack/test/fixtures/test/list.rhtml
create mode 100644 actionpack/test/template/active_record_helper_test.rb
create mode 100755 actionpack/test/template/date_helper_test.rb
create mode 100644 actionpack/test/template/form_helper_test.rb
create mode 100644 actionpack/test/template/form_options_helper_test.rb
create mode 100644 actionpack/test/template/tag_helper_test.rb
create mode 100644 actionpack/test/template/text_helper_test.rb
create mode 100644 actionpack/test/template/url_helper_test.rb
(limited to 'actionpack/test')
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
new file mode 100644
index 0000000000..0fcb5e852d
--- /dev/null
+++ b/actionpack/test/abstract_unit.rb
@@ -0,0 +1,9 @@
+$:.unshift(File.dirname(__FILE__) + '/../lib')
+
+require 'test/unit'
+require 'action_controller'
+
+require 'action_controller/test_process'
+
+ActionController::Base.logger = nil
+ActionController::Base.ignore_missing_templates = true
\ No newline at end of file
diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb
new file mode 100644
index 0000000000..6d727be5a2
--- /dev/null
+++ b/actionpack/test/controller/action_pack_assertions_test.rb
@@ -0,0 +1,323 @@
+require File.dirname(__FILE__) + '/../abstract_unit'
+
+# a controller class to facilitate the tests
+class ActionPackAssertionsController < ActionController::Base
+
+ # this does absolutely nothing
+ def nothing() render_text ""; end
+
+ # a standard template
+ def hello_world() render "test/hello_world"; end
+
+ # a standard template
+ def hello_xml_world() render "test/hello_xml_world"; end
+
+ # a redirect to an internal location
+ def redirect_internal() redirect_to "nothing"; end
+
+ # a redirect to an external location
+ def redirect_external() redirect_to_url "http://www.rubyonrails.org"; end
+
+ # a 404
+ def response404() render_text "", "404 AWOL"; end
+
+ # a 500
+ def response500() render_text "", "500 Sorry"; end
+
+ # a fictional 599
+ def response599() render_text "", "599 Whoah!"; end
+
+ # putting stuff in the flash
+ def flash_me
+ flash['hello'] = 'my name is inigo montoya...'
+ render_text "Inconceivable!"
+ end
+
+ # we have a flash, but nothing is in it
+ def flash_me_naked
+ flash.clear
+ render_text "wow!"
+ end
+
+ # assign some template instance variables
+ def assign_this
+ @howdy = "ho"
+ render_text "Mr. Henke"
+ end
+
+ def render_based_on_parameters
+ render_text "Mr. #{@params["name"]}"
+ end
+
+ # puts something in the session
+ def session_stuffing
+ session['xmas'] = 'turkey'
+ render_text "ho ho ho"
+ end
+
+ # 911
+ def rescue_action(e) raise; end
+
+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.template_root = File.dirname(__FILE__) + "/../fixtures/"
+
+
+# a test case to exercise the new capabilities TestRequest & TestResponse
+class ActionPackAssertionsControllerTest < Test::Unit::TestCase
+ # let's get this party started
+ def setup
+ @controller = ActionPackAssertionsController.new
+ @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
+ end
+
+ # -- assertion-based testing ------------------------------------------------
+
+ # test the session assertion to make sure something is there.
+ def test_assert_session_has
+ process :session_stuffing
+ assert_session_has 'xmas'
+ assert_session_has_no 'halloween'
+ end
+
+ # test the assertion of goodies in the template
+ def test_assert_template_has
+ process :assign_this
+ assert_template_has 'howdy'
+ end
+
+ # test the assertion for goodies that shouldn't exist in the template
+ def test_assert_template_has_no
+ process :nothing
+ assert_template_has_no 'maple syrup'
+ assert_template_has_no 'howdy'
+ end
+
+ # test the redirection assertions
+ def test_assert_redirect
+ process :redirect_internal
+ assert_redirect
+ end
+
+ # test the redirect url string
+ def test_assert_redirect_url
+ process :redirect_external
+ assert_redirect_url 'http://www.rubyonrails.org'
+ end
+
+ # test the redirection pattern matching on a string
+ def test_assert_redirect_url_match_string
+ process :redirect_external
+ assert_redirect_url_match 'rails.org'
+ end
+
+ # test the redirection pattern matching on a pattern
+ def test_assert_redirect_url_match_pattern
+ process :redirect_external
+ assert_redirect_url_match /ruby/
+ end
+
+ # test the flash-based assertions with something is in the flash
+ def test_flash_assertions_full
+ process :flash_me
+ assert @response.has_flash_with_contents?
+ assert_flash_exists
+ assert ActionController::TestResponse.assertion_target.has_flash_with_contents?
+ assert_flash_not_empty
+ assert_flash_has 'hello'
+ assert_flash_has_no 'stds'
+ end
+
+ # test the flash-based assertions with no flash at all
+ def test_flash_assertions_negative
+ process :nothing
+ assert_flash_not_exists
+ assert_flash_empty
+ assert_flash_has_no 'hello'
+ assert_flash_has_no 'qwerty'
+ end
+
+ # test the assert_rendered_file
+ def test_assert_rendered_file
+ process :hello_world
+ assert_rendered_file 'test/hello_world'
+ assert_rendered_file 'hello_world'
+ assert_rendered_file
+ end
+
+ # test the assert_success assertion
+ def test_assert_success
+ process :nothing
+ assert_success
+ end
+
+ # -- standard request/reponse object testing --------------------------------
+
+ # ensure our session is working properly
+ def test_session_objects
+ process :session_stuffing
+ assert @response.has_session_object?('xmas')
+ assert_session_equal 'turkey', 'xmas'
+ assert !@response.has_session_object?('easter')
+ end
+
+ # make sure that the template objects exist
+ def test_template_objects_alive
+ process :assign_this
+ assert !@response.has_template_object?('hi')
+ assert @response.has_template_object?('howdy')
+ end
+
+ # make sure we don't have template objects when we shouldn't
+ def test_template_object_missing
+ process :nothing
+ assert_nil @response.template_objects['howdy']
+ end
+
+ def test_assigned_equal
+ process :assign_this
+ assert_assigned_equal "ho", :howdy
+ end
+
+ # check the empty flashing
+ def test_flash_me_naked
+ process :flash_me_naked
+ assert @response.has_flash?
+ assert !@response.has_flash_with_contents?
+ end
+
+ # check if we have flash objects
+ def test_flash_haves
+ process :flash_me
+ assert @response.has_flash?
+ assert @response.has_flash_with_contents?
+ assert @response.has_flash_object?('hello')
+ end
+
+ # ensure we don't have flash objects
+ def test_flash_have_nots
+ process :nothing
+ assert !@response.has_flash?
+ assert !@response.has_flash_with_contents?
+ assert_nil @response.flash['hello']
+ end
+
+ # examine that the flash objects are what we expect
+ def test_flash_equals
+ process :flash_me
+ assert_flash_equal 'my name is inigo montoya...', 'hello'
+ end
+
+
+ # check if we were rendered by a file-based template?
+ def test_rendered_action
+ process :nothing
+ assert !@response.rendered_with_file?
+
+ process :hello_world
+ assert @response.rendered_with_file?
+ assert 'hello_world', @response.rendered_file
+ end
+
+ # check the redirection location
+ def test_redirection_location
+ process :redirect_internal
+ assert_equal 'nothing', @response.redirect_url
+
+ process :redirect_external
+ assert_equal 'http://www.rubyonrails.org', @response.redirect_url
+
+ process :nothing
+ assert_nil @response.redirect_url
+ end
+
+
+ # check server errors
+ def test_server_error_response_code
+ process :response500
+ assert @response.server_error?
+
+ process :response599
+ assert @response.server_error?
+
+ process :response404
+ assert !@response.server_error?
+ end
+
+ # check a 404 response code
+ def test_missing_response_code
+ process :response404
+ assert @response.missing?
+ end
+
+ # check to see if our redirection matches a pattern
+ def test_redirect_url_match
+ process :redirect_external
+ assert @response.redirect?
+ assert @response.redirect_url_match?("rubyonrails")
+ assert @response.redirect_url_match?(/rubyonrails/)
+ assert !@response.redirect_url_match?("phpoffrails")
+ assert !@response.redirect_url_match?(/perloffrails/)
+ end
+
+ # check for a redirection
+ def test_redirection
+ process :redirect_internal
+ assert @response.redirect?
+
+ process :redirect_external
+ assert @response.redirect?
+
+ process :nothing
+ assert !@response.redirect?
+ end
+
+ # check a successful response code
+ def test_successful_response_code
+ process :nothing
+ assert @response.success?
+ end
+
+ # a basic check to make sure we have a TestResponse object
+ def test_has_response
+ process :nothing
+ assert_kind_of ActionController::TestResponse, @response
+ end
+
+ def test_render_based_on_parameters
+ process :render_based_on_parameters, "name" => "David"
+ assert_equal "Mr. David", @response.body
+ end
+
+ def test_simple_one_element_xpath_match
+ process :hello_xml_world
+ assert_template_xpath_match('//title', "Hello World")
+ end
+
+ def test_array_of_elements_in_xpath_match
+ process :hello_xml_world
+ assert_template_xpath_match('//p', %w( abes monks wiseguys ))
+ end
+end
+
+class ActionPackHeaderTest < Test::Unit::TestCase
+ def setup
+ @controller = ActionPackAssertionsController.new
+ @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
+ end
+ def test_rendering_xml_sets_content_type
+ process :hello_xml_world
+ assert_equal('text/xml', @controller.headers['Content-Type'])
+ end
+ def test_rendering_xml_respects_content_type
+ @response.headers['Content-Type'] = 'application/pdf'
+ process :hello_xml_world
+ assert_equal('application/pdf', @controller.headers['Content-Type'])
+ end
+end
diff --git a/actionpack/test/controller/active_record_assertions_test.rb b/actionpack/test/controller/active_record_assertions_test.rb
new file mode 100644
index 0000000000..53106aaee7
--- /dev/null
+++ b/actionpack/test/controller/active_record_assertions_test.rb
@@ -0,0 +1,119 @@
+path_to_ar = File.dirname(__FILE__) + '/../../../activerecord'
+
+if Object.const_defined?("ActiveRecord") || File.exist?(path_to_ar)
+# This test is very different than the others. It requires ActiveRecord to
+# run. There's a bunch of stuff we are assuming here:
+#
+# 1. activerecord exists as a sibling directory to actionpack
+# (i.e., actionpack/../activerecord)
+# 2. you've created the appropriate database to run the active_record unit tests
+# 3. you set the appropriate database connection below
+
+driver_to_use = 'native_sqlite'
+
+$: << path_to_ar + '/lib/'
+$: << path_to_ar + '/test/'
+require 'active_record' unless Object.const_defined?("ActiveRecord")
+require "connections/#{driver_to_use}/connection"
+require 'fixtures/company'
+
+# -----------------------------------------------------------------------------
+
+# add some validation rules to trip up the assertions
+class Company
+ def validate
+ errors.add_on_empty('name')
+ errors.add('rating', 'rating should not be 2') if rating == 2
+ errors.add_to_base('oh oh') if rating == 3
+ end
+end
+
+# -----------------------------------------------------------------------------
+
+require File.dirname(__FILE__) + '/../abstract_unit'
+
+# a controller class to handle the AR assertions
+class ActiveRecordAssertionsController < ActionController::Base
+ # fail with 1 bad column
+ def nasty_columns_1
+ @company = Company.new
+ @company.name = "B"
+ @company.rating = 2
+ render_text "snicker...."
+ end
+
+ # fail with 2 bad column
+ def nasty_columns_2
+ @company = Company.new
+ @company.name = ""
+ @company.rating = 2
+ render_text "double snicker...."
+ end
+
+ # this will pass validation
+ def good_company
+ @company = Company.new
+ @company.name = "A"
+ @company.rating = 69
+ render_text "Goodness Gracious!"
+ end
+
+ # this will fail validation
+ def bad_company
+ @company = Company.new
+ render_text "Who's Bad?"
+ end
+
+ # the safety dance......
+ def rescue_action(e) raise; end
+end
+
+# -----------------------------------------------------------------------------
+
+ActiveRecordAssertionsController.template_root = File.dirname(__FILE__) + "/../fixtures/"
+
+# The test case to try the AR assertions
+class ActiveRecordAssertionsControllerTest < Test::Unit::TestCase
+ # set it up
+ def setup
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ @controller = ActiveRecordAssertionsController.new
+ end
+
+ # test for 1 bad apple column
+ def test_some_invalid_columns
+ process :nasty_columns_1
+ assert_success
+ assert_invalid_record 'company'
+ assert_invalid_column_on_record 'company', 'rating'
+ assert_valid_column_on_record 'company', 'name'
+ assert_valid_column_on_record 'company', ['name','id']
+ end
+
+ # test for 2 bad apples columns
+ def test_all_invalid_columns
+ process :nasty_columns_2
+ assert_success
+ assert_invalid_record 'company'
+ assert_invalid_column_on_record 'company', 'rating'
+ assert_invalid_column_on_record 'company', 'name'
+ assert_invalid_column_on_record 'company', ['name','rating']
+ end
+
+ # ensure we have no problems with an ActiveRecord
+ def test_valid_record
+ process :good_company
+ assert_success
+ assert_valid_record 'company'
+ end
+
+ # ensure we have problems with an ActiveRecord
+ def test_invalid_record
+ process :bad_company
+ assert_success
+ assert_invalid_record 'company'
+ end
+end
+
+end
\ No newline at end of file
diff --git a/actionpack/test/controller/cgi_test.rb b/actionpack/test/controller/cgi_test.rb
new file mode 100755
index 0000000000..46e24ab403
--- /dev/null
+++ b/actionpack/test/controller/cgi_test.rb
@@ -0,0 +1,142 @@
+$:.unshift(File.dirname(__FILE__) + '/../../lib')
+
+require 'test/unit'
+require 'action_controller/cgi_ext/cgi_methods'
+require 'stringio'
+
+class MockUploadedFile < StringIO
+ def content_type
+ "img/jpeg"
+ end
+
+ def original_filename
+ "my_file.doc"
+ end
+end
+
+class CGITest < Test::Unit::TestCase
+ def setup
+ @query_string = "action=create_customer&full_name=David%20Heinemeier%20Hansson&customerId=1"
+ @query_string_with_nil = "action=create_customer&full_name="
+ @query_string_with_array = "action=create_customer&selected[]=1&selected[]=2&selected[]=3"
+ @query_string_with_amps = "action=create_customer&name=Don%27t+%26+Does"
+ @query_string_with_multiple_of_same_name =
+ "action=update_order&full_name=Lau%20Taarnskov&products=4&products=2&products=3"
+ end
+
+ def test_query_string
+ assert_equal(
+ { "action" => "create_customer", "full_name" => "David Heinemeier Hansson", "customerId" => "1"},
+ CGIMethods.parse_query_parameters(@query_string)
+ )
+ end
+
+ def test_query_string_with_nil
+ assert_equal(
+ { "action" => "create_customer", "full_name" => nil},
+ CGIMethods.parse_query_parameters(@query_string_with_nil)
+ )
+ end
+
+ def test_query_string_with_array
+ assert_equal(
+ { "action" => "create_customer", "selected" => ["1", "2", "3"]},
+ CGIMethods.parse_query_parameters(@query_string_with_array)
+ )
+ end
+
+ def test_query_string_with_amps
+ assert_equal(
+ { "action" => "create_customer", "name" => "Don't & Does"},
+ CGIMethods.parse_query_parameters(@query_string_with_amps)
+ )
+ end
+
+ def test_parse_params
+ input = {
+ "customers[boston][first][name]" => [ "David" ],
+ "customers[boston][first][url]" => [ "http://David" ],
+ "customers[boston][second][name]" => [ "Allan" ],
+ "customers[boston][second][url]" => [ "http://Allan" ],
+ "something_else" => [ "blah" ],
+ "something_nil" => [ nil ],
+ "something_empty" => [ "" ],
+ "products[first]" => [ "Apple Computer" ],
+ "products[second]" => [ "Pc" ]
+ }
+
+ expected_output = {
+ "customers" => {
+ "boston" => {
+ "first" => {
+ "name" => "David",
+ "url" => "http://David"
+ },
+ "second" => {
+ "name" => "Allan",
+ "url" => "http://Allan"
+ }
+ }
+ },
+ "something_else" => "blah",
+ "something_empty" => "",
+ "something_nil" => "",
+ "products" => {
+ "first" => "Apple Computer",
+ "second" => "Pc"
+ }
+ }
+
+ assert_equal expected_output, CGIMethods.parse_request_parameters(input)
+ end
+
+ def test_parse_params_from_multipart_upload
+ mock_file = MockUploadedFile.new
+
+ input = {
+ "something" => [ StringIO.new("") ],
+ "products[string]" => [ StringIO.new("Apple Computer") ],
+ "products[file]" => [ mock_file ]
+ }
+
+ expected_output = {
+ "something" => "",
+ "products" => {
+ "string" => "Apple Computer",
+ "file" => mock_file
+ }
+ }
+
+ assert_equal expected_output, CGIMethods.parse_request_parameters(input)
+ end
+
+ def test_parse_params_with_file
+ input = {
+ "customers[boston][first][name]" => [ "David" ],
+ "something_else" => [ "blah" ],
+ "logo" => [ File.new(File.dirname(__FILE__) + "/cgi_test.rb").path ]
+ }
+
+ expected_output = {
+ "customers" => {
+ "boston" => {
+ "first" => {
+ "name" => "David"
+ }
+ }
+ },
+ "something_else" => "blah",
+ "logo" => File.new(File.dirname(__FILE__) + "/cgi_test.rb").path,
+ }
+
+ assert_equal expected_output, CGIMethods.parse_request_parameters(input)
+ end
+
+ def test_parse_params_with_array
+ input = { "selected[]" => [ "1", "2", "3" ] }
+
+ expected_output = { "selected" => [ "1", "2", "3" ] }
+
+ assert_equal expected_output, CGIMethods.parse_request_parameters(input)
+ end
+end
diff --git a/actionpack/test/controller/cookie_test.rb b/actionpack/test/controller/cookie_test.rb
new file mode 100644
index 0000000000..d3099bcd99
--- /dev/null
+++ b/actionpack/test/controller/cookie_test.rb
@@ -0,0 +1,38 @@
+require File.dirname(__FILE__) + '/../abstract_unit'
+
+class CookieTest < Test::Unit::TestCase
+ class TestController < ActionController::Base
+ def authenticate
+ cookie "name" => "user_name", "value" => "david"
+ render_text "hello world"
+ end
+
+ def access_frozen_cookies
+ @cookies["wont"] = "work"
+ end
+
+ def rescue_action(e) raise end
+ end
+
+ def setup
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+
+ @request.host = "www.nextangle.com"
+ end
+
+ def test_setting_cookie
+ @request.action = "authenticate"
+ assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david") ], process_request.headers["cookie"]
+ end
+
+ def test_setting_cookie
+ @request.action = "access_frozen_cookies"
+ assert_raises(TypeError) { process_request }
+ end
+
+ private
+ def process_request
+ TestController.process(@request, @response)
+ end
+end
\ No newline at end of file
diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb
new file mode 100644
index 0000000000..f4d7a689b5
--- /dev/null
+++ b/actionpack/test/controller/filters_test.rb
@@ -0,0 +1,159 @@
+require File.dirname(__FILE__) + '/../abstract_unit'
+
+class FilterTest < Test::Unit::TestCase
+ class TestController < ActionController::Base
+ before_filter :ensure_login
+
+ def show
+ render_text "ran action"
+ end
+
+ private
+ def ensure_login
+ @ran_filter ||= []
+ @ran_filter << "ensure_login"
+ end
+ end
+
+ class PrependingController < TestController
+ prepend_before_filter :wonderful_life
+
+ private
+ def wonderful_life
+ @ran_filter ||= []
+ @ran_filter << "wonderful_life"
+ end
+ end
+
+ class ProcController < PrependingController
+ before_filter(proc { |c| c.assigns["ran_proc_filter"] = true })
+ end
+
+ class ImplicitProcController < PrependingController
+ before_filter { |c| c.assigns["ran_proc_filter"] = true }
+ end
+
+ class AuditFilter
+ def self.filter(controller)
+ controller.assigns["was_audited"] = true
+ end
+ end
+
+ class AroundFilter
+ def before(controller)
+ @execution_log = "before"
+ controller.class.execution_log << " before aroundfilter " if controller.respond_to? :execution_log
+ controller.assigns["before_ran"] = true
+ end
+
+ def after(controller)
+ controller.assigns["execution_log"] = @execution_log + " and after"
+ controller.assigns["after_ran"] = true
+ controller.class.execution_log << " after aroundfilter " if controller.respond_to? :execution_log
+ end
+ end
+
+ class AppendedAroundFilter
+ def before(controller)
+ controller.class.execution_log << " before appended aroundfilter "
+ end
+
+ def after(controller)
+ controller.class.execution_log << " after appended aroundfilter "
+ end
+ end
+
+ class AuditController < ActionController::Base
+ before_filter(AuditFilter)
+
+ def show
+ render_text "hello"
+ end
+ end
+
+ class BadFilterController < ActionController::Base
+ before_filter 2
+
+ def show() "show" end
+
+ protected
+ def rescue_action(e) raise(e) end
+ end
+
+ class AroundFilterController < PrependingController
+ around_filter AroundFilter.new
+ end
+
+ class MixedFilterController < PrependingController
+ cattr_accessor :execution_log
+ def initialize
+ @@execution_log = ""
+ end
+
+ before_filter { |c| c.class.execution_log << " before procfilter " }
+ prepend_around_filter AroundFilter.new
+
+ after_filter { |c| c.class.execution_log << " after procfilter " }
+ append_around_filter AppendedAroundFilter.new
+ end
+
+
+ def test_added_filter_to_inheritance_graph
+ assert_equal [ :fire_flash, :ensure_login ], TestController.before_filters
+ end
+
+ def test_base_class_in_isolation
+ assert_equal [ :fire_flash ], ActionController::Base.before_filters
+ end
+
+ def test_prepending_filter
+ assert_equal [ :wonderful_life, :fire_flash, :ensure_login ], PrependingController.before_filters
+ end
+
+ def test_running_filters
+ assert_equal %w( wonderful_life ensure_login ), test_process(PrependingController).template.assigns["ran_filter"]
+ end
+
+ def test_running_filters_with_proc
+ assert test_process(ProcController).template.assigns["ran_proc_filter"]
+ end
+
+ def test_running_filters_with_implicit_proc
+ assert test_process(ImplicitProcController).template.assigns["ran_proc_filter"]
+ end
+
+ def test_running_filters_with_class
+ assert test_process(AuditController).template.assigns["was_audited"]
+ end
+
+ def test_bad_filter
+ assert_raises(ActionController::ActionControllerError) {
+ test_process(BadFilterController)
+ }
+ end
+
+ def test_around_filter
+ controller = test_process(AroundFilterController)
+ assert controller.template.assigns["before_ran"]
+ assert controller.template.assigns["after_ran"]
+ end
+
+ def test_having_properties_in_around_filter
+ controller = test_process(AroundFilterController)
+ assert_equal "before and after", controller.template.assigns["execution_log"]
+ end
+
+ def test_prepending_and_appending_around_filter
+ controller = test_process(MixedFilterController)
+ assert_equal " before aroundfilter before procfilter before appended aroundfilter " +
+ " after appended aroundfilter after aroundfilter after procfilter ",
+ MixedFilterController.execution_log
+ end
+
+ private
+ def test_process(controller)
+ request = ActionController::TestRequest.new
+ request.action = "show"
+ controller.process(request, ActionController::TestResponse.new)
+ end
+end
\ No newline at end of file
diff --git a/actionpack/test/controller/flash_test.rb b/actionpack/test/controller/flash_test.rb
new file mode 100644
index 0000000000..033477fe39
--- /dev/null
+++ b/actionpack/test/controller/flash_test.rb
@@ -0,0 +1,69 @@
+require File.dirname(__FILE__) + '/../abstract_unit'
+
+class FlashTest < Test::Unit::TestCase
+ class TestController < ActionController::Base
+ def set_flash
+ flash["that"] = "hello"
+ render_text "hello"
+ end
+
+ def use_flash
+ @flashy = flash["that"]
+ render_text "hello"
+ end
+
+ def use_flash_and_keep_it
+ @flashy = flash["that"]
+ keep_flash
+ render_text "hello"
+ end
+
+ def rescue_action(e)
+ raise unless ActionController::MissingTemplate === e
+ end
+ end
+
+ def setup
+ initialize_request_and_response
+ end
+
+ def test_flash
+ @request.action = "set_flash"
+ response = process_request
+
+ @request.action = "use_flash"
+ first_response = process_request
+ assert_equal "hello", first_response.template.assigns["flash"]["that"]
+ assert_equal "hello", first_response.template.assigns["flashy"]
+
+ second_response = process_request
+ assert_nil second_response.template.assigns["flash"]["that"], "On second flash"
+ end
+
+ def test_keep_flash
+ @request.action = "set_flash"
+ response = process_request
+
+ @request.action = "use_flash_and_keep_it"
+ first_response = process_request
+ assert_equal "hello", first_response.template.assigns["flash"]["that"]
+ assert_equal "hello", first_response.template.assigns["flashy"]
+
+ @request.action = "use_flash"
+ second_response = process_request
+ assert_equal "hello", second_response.template.assigns["flash"]["that"], "On second flash"
+
+ third_response = process_request
+ assert_nil third_response.template.assigns["flash"]["that"], "On third flash"
+ end
+
+ private
+ def initialize_request_and_response
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ end
+
+ def process_request
+ TestController.process(@request, @response)
+ end
+end
\ No newline at end of file
diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb
new file mode 100644
index 0000000000..9d1da53241
--- /dev/null
+++ b/actionpack/test/controller/helper_test.rb
@@ -0,0 +1,110 @@
+require File.dirname(__FILE__) + '/../abstract_unit'
+
+class HelperTest < Test::Unit::TestCase
+ HELPER_PATHS = %w(/../fixtures/helpers)
+
+ class TestController < ActionController::Base
+ attr_accessor :delegate_attr
+ def delegate_method() end
+ def rescue_action(e) raise end
+ end
+
+ module LocalAbcHelper
+ def a() end
+ def b() end
+ def c() end
+ end
+
+
+ def setup
+ # Increment symbol counter.
+ @symbol = (@@counter ||= 'A0').succ!.dup
+
+ # Generate new controller class.
+ controller_class_name = "Helper#{@symbol}Controller"
+ eval("class #{controller_class_name} < TestController; end")
+ @controller_class = self.class.const_get(controller_class_name)
+
+ # Generate new template class and assign to controller.
+ template_class_name = "Test#{@symbol}View"
+ eval("class #{template_class_name} < ActionView::Base; end")
+ @template_class = self.class.const_get(template_class_name)
+ @controller_class.template_class = @template_class
+
+ # Add helper paths to LOAD_PATH.
+ HELPER_PATHS.each { |path|
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + path)
+ }
+
+ # Set default test helper.
+ self.test_helper = LocalAbcHelper
+ end
+
+ def teardown
+ # Reset template class.
+ #ActionController::Base.template_class = ActionView::Base
+
+ # Remove helper paths from LOAD_PATH.
+ HELPER_PATHS.each { |path|
+ $LOAD_PATH.delete(File.dirname(__FILE__) + path)
+ }
+ end
+
+
+ def test_deprecated_helper
+ assert_equal helper_methods, missing_methods
+ assert_nothing_raised { @controller_class.helper TestHelper }
+ assert_equal [], missing_methods
+ end
+
+ def test_declare_helper
+ require 'abc_helper'
+ self.test_helper = AbcHelper
+ assert_equal helper_methods, missing_methods
+ assert_nothing_raised { @controller_class.helper :abc }
+ assert_equal [], missing_methods
+ end
+
+ def test_declare_missing_helper
+ assert_equal helper_methods, missing_methods
+ assert_raise(LoadError) { @controller_class.helper :missing }
+ end
+
+ def test_helper_block
+ assert_nothing_raised {
+ @controller_class.helper { def block_helper_method; end }
+ }
+ assert template_methods.include?('block_helper_method')
+ end
+
+ def test_helper_block_include
+ assert_equal helper_methods, missing_methods
+ assert_nothing_raised {
+ @controller_class.helper { include TestHelper }
+ }
+ assert [], missing_methods
+ end
+
+ def test_helper_method
+ assert_nothing_raised { @controller_class.helper_method :delegate_method }
+ assert template_methods.include?('delegate_method')
+ end
+
+ def test_helper_attr
+ assert_nothing_raised { @controller_class.helper_attr :delegate_attr }
+ assert template_methods.include?('delegate_attr')
+ assert template_methods.include?('delegate_attr=')
+ end
+
+
+ private
+ def helper_methods; TestHelper.instance_methods end
+ def template_methods; @template_class.instance_methods end
+ def missing_methods; helper_methods - template_methods end
+
+ def test_helper=(helper_module)
+ old_verbose, $VERBOSE = $VERBOSE, nil
+ self.class.const_set('TestHelper', helper_module)
+ $VERBOSE = old_verbose
+ end
+end
\ No newline at end of file
diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb
new file mode 100644
index 0000000000..f652453ebd
--- /dev/null
+++ b/actionpack/test/controller/layout_test.rb
@@ -0,0 +1,49 @@
+require File.dirname(__FILE__) + '/../abstract_unit'
+
+class TestLayoutController < ActionController::Base
+ layout "layouts/standard"
+
+ def hello_world
+ end
+
+ def hello_world_outside_layout
+ end
+
+ def rescue_action(e) raise end
+end
+
+class ChildWithoutTestLayoutController < TestLayoutController
+ layout nil
+
+ def hello_world
+ end
+end
+
+class ChildWithOtherTestLayoutController < TestLayoutController
+ layout nil
+
+ def hello_world
+ end
+end
+
+class RenderTest < Test::Unit::TestCase
+ def setup
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+
+ @request.host = "www.nextangle.com"
+ end
+
+ def test_layout_rendering
+ @request.action = "hello_world"
+ response = process_request
+ assert_equal "200 OK", response.headers["Status"]
+ assert_equal "layouts/standard", response.template.template_name
+ end
+
+
+ private
+ def process_request
+ TestLayoutController.process(@request, @response)
+ end
+end
\ No newline at end of file
diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb
new file mode 100755
index 0000000000..6302016a53
--- /dev/null
+++ b/actionpack/test/controller/redirect_test.rb
@@ -0,0 +1,44 @@
+require File.dirname(__FILE__) + '/../abstract_unit'
+
+class RedirectTest < Test::Unit::TestCase
+ class RedirectController < ActionController::Base
+ def simple_redirect
+ redirect_to :action => "hello_world"
+ end
+
+ def method_redirect
+ redirect_to :dashbord_url, 1, "hello"
+ end
+
+ def rescue_errors(e) raise e end
+
+ protected
+ def dashbord_url(id, message)
+ url_for :action => "dashboard", :params => { "id" => id, "message" => message }
+ end
+ end
+
+ def setup
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ end
+
+ def test_simple_redirect
+ @request.path = "/redirect/simple_redirect"
+ @request.action = "simple_redirect"
+ response = process_request
+ assert_equal "http://test.host/redirect/hello_world", response.headers["location"]
+ end
+
+ def test_redirect_with_method_reference_and_parameters
+ @request.path = "/redirect/method_redirect"
+ @request.action = "method_redirect"
+ response = process_request
+ assert_equal "http://test.host/redirect/dashboard?message=hello&id=1", response.headers["location"]
+ end
+
+ private
+ def process_request
+ RedirectController.process(@request, @response)
+ end
+end
\ No newline at end of file
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
new file mode 100644
index 0000000000..ce778e1d7d
--- /dev/null
+++ b/actionpack/test/controller/render_test.rb
@@ -0,0 +1,178 @@
+require File.dirname(__FILE__) + '/../abstract_unit'
+
+Customer = Struct.new("Customer", :name)
+
+class RenderTest < Test::Unit::TestCase
+ class TestController < ActionController::Base
+ layout :determine_layout
+
+ def hello_world
+ end
+
+ def render_hello_world
+ render "test/hello_world"
+ end
+
+ def render_hello_world_from_variable
+ @person = "david"
+ render_text "hello #{@person}"
+ end
+
+ def render_action_hello_world
+ render_action "hello_world"
+ end
+
+ def render_text_hello_world
+ render_text "hello world"
+ end
+
+ def render_custom_code
+ render_text "hello world", "404 Moved"
+ end
+
+ def render_xml_hello
+ @name = "David"
+ render "test/hello"
+ end
+
+ def greeting
+ # let's just rely on the template
+ end
+
+ def layout_test
+ render_action "hello_world"
+ end
+
+ def builder_layout_test
+ render_action "hello"
+ end
+
+ def partials_list
+ @customers = [ Customer.new("david"), Customer.new("mary") ]
+ render_action "list"
+ end
+
+ def modgreet
+ end
+
+ def rescue_action(e) raise end
+
+ private
+ def determine_layout
+ case action_name
+ when "layout_test": "layouts/standard"
+ when "builder_layout_test": "layouts/builder"
+ end
+ end
+ end
+
+ TestController.template_root = File.dirname(__FILE__) + "/../fixtures/"
+
+ class TestLayoutController < ActionController::Base
+ layout "layouts/standard"
+
+ def hello_world
+ end
+
+ def hello_world_outside_layout
+ end
+
+ def rescue_action(e)
+ raise unless ActionController::MissingTemplate === e
+ end
+ end
+
+ def setup
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+
+ @request.host = "www.nextangle.com"
+ end
+
+ def test_simple_show
+ @request.action = "hello_world"
+ response = process_request
+ assert_equal "200 OK", response.headers["Status"]
+ assert_equal "test/hello_world", response.template.first_render
+ end
+
+ def test_do_with_render
+ @request.action = "render_hello_world"
+ assert_equal "test/hello_world", process_request.template.first_render
+ end
+
+ def test_do_with_render_from_variable
+ @request.action = "render_hello_world_from_variable"
+ assert_equal "hello david", process_request.body
+ end
+
+ def test_do_with_render_action
+ @request.action = "render_action_hello_world"
+ assert_equal "test/hello_world", process_request.template.first_render
+ end
+
+ def test_do_with_render_text
+ @request.action = "render_text_hello_world"
+ assert_equal "hello world", process_request.body
+ end
+
+ def test_do_with_render_custom_code
+ @request.action = "render_custom_code"
+ assert_equal "404 Moved", process_request.headers["Status"]
+ end
+
+ def test_attempt_to_access_object_method
+ @request.action = "clone"
+ assert_raises(ActionController::UnknownAction, "No action responded to [clone]") { process_request }
+ end
+
+ def test_access_to_request_in_view
+ ActionController::Base.view_controller_internals = false
+
+ @request.action = "hello_world"
+ response = process_request
+ assert_nil response.template.assigns["request"]
+
+ ActionController::Base.view_controller_internals = true
+
+ @request.action = "hello_world"
+ response = process_request
+ assert_kind_of ActionController::AbstractRequest, response.template.assigns["request"]
+ end
+
+ def test_render_xml
+ @request.action = "render_xml_hello"
+ assert_equal "\n Hello David
\nThis is grand!
\n\n", process_request.body
+ end
+
+ def test_render_xml_with_default
+ @request.action = "greeting"
+ assert_equal "This is grand!
\n", process_request.body
+ end
+
+ def test_layout_rendering
+ @request.action = "layout_test"
+ assert_equal "Hello world!", process_request.body
+ end
+
+ def test_render_xml_with_layouts
+ @request.action = "builder_layout_test"
+ assert_equal "\n\n Hello
\nThis is grand!
\n\n \n", process_request.body
+ end
+
+ def test_partials_list
+ @request.action = "partials_list"
+ assert_equal "Hello: davidHello: mary", process_request.body
+ end
+
+ def test_module_rendering
+ @request.action = "modgreet"
+ @request.parameters["module"] = "scope"
+ assert_equal "Beautiful modules!
", process_request.body
+ end
+
+ private
+ def process_request
+ TestController.process(@request, @response)
+ end
+end
\ No newline at end of file
diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb
new file mode 100644
index 0000000000..57205a01c5
--- /dev/null
+++ b/actionpack/test/controller/send_file_test.rb
@@ -0,0 +1,68 @@
+require File.join(File.dirname(__FILE__), '..', '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
+
+ attr_writer :options
+ def options() @options ||= {} end
+
+ def file() send_file(file_path, options) end
+ def data() send_data(file_data, options) end
+
+ def rescue_action(e) raise end
+end
+
+
+class SendFileTest < Test::Unit::TestCase
+ include TestFileUtils
+
+ def setup
+ @controller = SendFileController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ end
+
+ def test_file_nostream
+ @controller.options = { :stream => false }
+ response = nil
+ assert_nothing_raised { response = process('file') }
+ assert_not_nil response
+ assert_kind_of String, response.body
+ assert_equal file_data, response.body
+ end
+
+ def test_file_stream
+ response = nil
+ assert_nothing_raised { response = process('file') }
+ assert_not_nil response
+ assert_kind_of Proc, response.body
+
+ old_stdout = $stdout
+ begin
+ require 'stringio'
+ $stdout = StringIO.new
+ $stdout.binmode
+ assert_nothing_raised { response.body.call }
+ assert_equal file_data, $stdout.string
+ ensure
+ $stdout = old_stdout
+ end
+ end
+
+ def test_data
+ response = nil
+ assert_nothing_raised { response = process('data') }
+ assert_not_nil response
+
+ assert_kind_of String, response.body
+ assert_equal file_data, response.body
+ end
+end
diff --git a/actionpack/test/controller/url_test.rb b/actionpack/test/controller/url_test.rb
new file mode 100644
index 0000000000..bf6a7aab75
--- /dev/null
+++ b/actionpack/test/controller/url_test.rb
@@ -0,0 +1,368 @@
+require File.dirname(__FILE__) + '/../abstract_unit'
+require 'action_controller/url_rewriter'
+
+MockRequest = Struct.new("MockRequest", :protocol, :host, :port, :path, :parameters)
+class MockRequest
+ def host_with_port
+ if (protocol == "http://" && port == 80) || (protocol == "https://" && port == 443)
+ host
+ else
+ host + ":#{port}"
+ end
+ end
+end
+
+class UrlTest < Test::Unit::TestCase
+ def setup
+ @library_url = ActionController::UrlRewriter.new(MockRequest.new(
+ "http://",
+ "www.singlefile.com",
+ 80,
+ "/library/books/ISBN/0743536703/show",
+ { "type" => "ISBN", "code" => "0743536703" }
+ ), "books", "show")
+
+ @library_url_on_index = ActionController::UrlRewriter.new(MockRequest.new(
+ "http://",
+ "www.singlefile.com",
+ 80,
+ "/library/books/ISBN/0743536703/",
+ { "type" => "ISBN", "code" => "0743536703" }
+ ), "books", "index")
+
+ @clean_urls = [
+ ActionController::UrlRewriter.new(MockRequest.new(
+ "http://", "www.singlefile.com", 80, "/identity/", {}
+ ), "identity", "index"),
+ ActionController::UrlRewriter.new(MockRequest.new(
+ "http://", "www.singlefile.com", 80, "/identity", {}
+ ), "identity", "index")
+ ]
+
+ @clean_url_with_id = ActionController::UrlRewriter.new(MockRequest.new(
+ "http://", "www.singlefile.com", 80, "/identity/show/5", { "id" => "5" }
+ ), "identity", "show")
+
+ @clean_url_with_id_as_char = ActionController::UrlRewriter.new(MockRequest.new(
+ "http://", "www.singlefile.com", 80, "/teachers/show/t", { "id" => "t" }
+ ), "teachers", "show")
+ end
+
+ def test_clean_action
+ assert_equal "http://www.singlefile.com/library/books/ISBN/0743536703/edit", @library_url.rewrite(:action => "edit")
+ end
+
+ def test_clean_action_with_only_path
+ assert_equal "/library/books/ISBN/0743536703/edit", @library_url.rewrite(:action => "edit", :only_path => true)
+ end
+
+ def test_action_from_index
+ assert_equal "http://www.singlefile.com/library/books/ISBN/0743536703/edit", @library_url_on_index.rewrite(:action => "edit")
+ end
+
+ def test_action_from_index_on_clean
+ @clean_urls.each do |url|
+ assert_equal "http://www.singlefile.com/identity/edit", url.rewrite(:action => "edit")
+ end
+ end
+
+ def test_action_without_prefix
+ assert_equal "http://www.singlefile.com/library/books/", @library_url.rewrite(:action => "index", :action_prefix => "")
+ end
+
+ def test_action_with_prefix
+ assert_equal(
+ "http://www.singlefile.com/library/books/XTC/123/show",
+ @library_url.rewrite(:action => "show", :action_prefix => "XTC/123")
+ )
+ end
+
+ def test_action_prefix_alone
+ assert_equal(
+ "http://www.singlefile.com/library/books/XTC/123/",
+ @library_url.rewrite(:action_prefix => "XTC/123")
+ )
+ end
+
+ def test_action_with_suffix
+ assert_equal(
+ "http://www.singlefile.com/library/books/show/XTC/123",
+ @library_url.rewrite(:action => "show", :action_prefix => "", :action_suffix => "XTC/123")
+ )
+ end
+
+ def test_clean_controller
+ assert_equal "http://www.singlefile.com/library/settings/", @library_url.rewrite(:controller => "settings")
+ end
+
+ def test_clean_controller_prefix
+ assert_equal "http://www.singlefile.com/shop/", @library_url.rewrite(:controller_prefix => "shop")
+ end
+
+ def test_clean_controller_with_module
+ assert_equal "http://www.singlefile.com/shop/purchases/", @library_url.rewrite(:module => "shop", :controller => "purchases")
+ end
+
+ def test_controller_and_action
+ assert_equal "http://www.singlefile.com/library/settings/show", @library_url.rewrite(:controller => "settings", :action => "show")
+ end
+
+ def test_controller_and_action_and_anchor
+ assert_equal(
+ "http://www.singlefile.com/library/settings/show#5",
+ @library_url.rewrite(:controller => "settings", :action => "show", :anchor => "5")
+ )
+ end
+
+ def test_controller_and_action_and_empty_overwrite_params_and_anchor
+ assert_equal(
+ "http://www.singlefile.com/library/settings/show?code=0743536703&type=ISBN#5",
+ @library_url.rewrite(:controller => "settings", :action => "show", :overwrite_params => {}, :anchor => "5")
+ )
+ end
+
+ def test_controller_and_action_and_overwrite_params_and_anchor
+ assert_equal(
+ "http://www.singlefile.com/library/settings/show?code=0000001&type=ISBN#5",
+ @library_url.rewrite(:controller => "settings", :action => "show", :overwrite_params => {"code"=>"0000001"}, :anchor => "5")
+ )
+ end
+
+ def test_controller_and_action_and_overwrite_params_with_nil_value_and_anchor
+ assert_equal(
+ "http://www.singlefile.com/library/settings/show?type=ISBN#5",
+ @library_url.rewrite(:controller => "settings", :action => "show", :overwrite_params => {"code" => nil}, :anchor => "5")
+ )
+ end
+
+ def test_controller_and_action_params_and_overwrite_params_and_anchor
+ assert_equal(
+ "http://www.singlefile.com/library/settings/show?code=0000001&version=5.0#5",
+ @library_url.rewrite(:controller => "settings", :action => "show", :params=>{"version" => "5.0"}, :overwrite_params => {"code"=>"0000001"}, :anchor => "5")
+ )
+ end
+
+ def test_controller_and_action_and_params_anchor
+ assert_equal(
+ "http://www.singlefile.com/library/settings/show?update=1#5",
+ @library_url.rewrite(:controller => "settings", :action => "show", :params => { "update" => "1"}, :anchor => "5")
+ )
+ end
+
+ def test_controller_and_index_action
+ assert_equal "http://www.singlefile.com/library/settings/", @library_url.rewrite(:controller => "settings", :action => "index")
+ end
+
+ def test_controller_and_action_with_same_name_as_controller
+ @clean_urls.each do |url|
+ assert_equal "http://www.singlefile.com/anything/identity", url.rewrite(:controller => "anything", :action => "identity")
+ end
+ end
+
+ def test_controller_and_index_action_without_controller_prefix
+ assert_equal(
+ "http://www.singlefile.com/settings/",
+ @library_url.rewrite(:controller => "settings", :action => "index", :controller_prefix => "")
+ )
+ end
+
+ def test_controller_and_index_action_with_controller_prefix
+ assert_equal(
+ "http://www.singlefile.com/fantastic/settings/show",
+ @library_url.rewrite(:controller => "settings", :action => "show", :controller_prefix => "fantastic")
+ )
+ end
+
+ def test_path_parameters
+ assert_equal "http://www.singlefile.com/library/books/EXBC/0743536703/show", @library_url.rewrite(:path_params => {"type" => "EXBC"})
+ end
+
+ def test_parameters
+ assert_equal(
+ "http://www.singlefile.com/library/books/ISBN/0743536703/show?delete=1&name=David",
+ @library_url.rewrite(:params => {"delete" => "1", "name" => "David"})
+ )
+ end
+
+ def test_parameters_with_id
+ @clean_urls.each do |url|
+ assert_equal(
+ "http://www.singlefile.com/identity/show?name=David&id=5",
+ url.rewrite(
+ :action => "show",
+ :params => { "id" => "5", "name" => "David" }
+ )
+ )
+ end
+ end
+
+ def test_action_with_id
+ assert_equal(
+ "http://www.singlefile.com/identity/show/7",
+ @clean_url_with_id.rewrite(
+ :action => "show",
+ :id => 7
+ )
+ )
+ @clean_urls.each do |url|
+ assert_equal(
+ "http://www.singlefile.com/identity/index/7",
+ url.rewrite(:id => 7)
+ )
+ end
+ end
+
+ def test_parameters_with_id_and_away
+ assert_equal(
+ "http://www.singlefile.com/identity/show/25?name=David",
+ @clean_url_with_id.rewrite(
+ :path_params => { "id" => "25" },
+ :params => { "name" => "David" }
+ )
+ )
+ end
+
+ def test_parameters_with_index_and_id
+ @clean_urls.each do |url|
+ assert_equal(
+ "http://www.singlefile.com/identity/index/25?name=David",
+ url.rewrite(
+ :path_params => { "id" => "25" },
+ :params => { "name" => "David" }
+ )
+ )
+ end
+ end
+
+ def test_action_going_away_from_id
+ assert_equal(
+ "http://www.singlefile.com/identity/list",
+ @clean_url_with_id.rewrite(
+ :action => "list"
+ )
+ )
+ end
+
+ def test_parameters_with_direct_id_and_away
+ assert_equal(
+ "http://www.singlefile.com/identity/show/25?name=David",
+ @clean_url_with_id.rewrite(
+ :id => "25",
+ :params => { "name" => "David" }
+ )
+ )
+ end
+
+ def test_parameters_with_direct_id_and_away
+ assert_equal(
+ "http://www.singlefile.com/store/open/25?name=David",
+ @clean_url_with_id.rewrite(
+ :controller => "store",
+ :action => "open",
+ :id => "25",
+ :params => { "name" => "David" }
+ )
+ )
+ end
+
+ def test_parameters_to_id
+ @clean_urls.each do |url|
+ %w(show index).each do |action|
+ assert_equal(
+ "http://www.singlefile.com/identity/#{action}/25?name=David",
+ url.rewrite(
+ :action => action,
+ :path_params => { "id" => "25" },
+ :params => { "name" => "David" }
+ )
+ )
+ end
+ end
+ end
+
+ def test_parameters_from_id
+ assert_equal(
+ "http://www.singlefile.com/identity/",
+ @clean_url_with_id.rewrite(
+ :action => "index"
+ )
+ )
+ end
+
+ def test_id_as_char_and_part_of_controller
+ assert_equal(
+ "http://www.singlefile.com/teachers/skill/5",
+ @clean_url_with_id_as_char.rewrite(
+ :action => "skill",
+ :id => 5
+ )
+ )
+ end
+
+ def test_from_clean_to_library
+ @clean_urls.each do |url|
+ assert_equal(
+ "http://www.singlefile.com/library/books/ISBN/0743536703/show?delete=1&name=David",
+ url.rewrite(
+ :controller_prefix => "library",
+ :controller => "books",
+ :action_prefix => "ISBN/0743536703",
+ :action => "show",
+ :params => { "delete" => "1", "name" => "David" }
+ )
+ )
+ end
+ end
+
+ def test_from_library_to_clean
+ assert_equal(
+ "http://www.singlefile.com/identity/",
+ @library_url.rewrite(
+ :controller => "identity", :controller_prefix => ""
+ )
+ )
+ end
+
+ def test_from_another_port
+ @library_url = ActionController::UrlRewriter.new(MockRequest.new(
+ "http://",
+ "www.singlefile.com",
+ 8080,
+ "/library/books/ISBN/0743536703/show",
+ { "type" => "ISBN", "code" => "0743536703" }
+ ), "books", "show")
+
+ assert_equal(
+ "http://www.singlefile.com:8080/identity/",
+ @library_url.rewrite(
+ :controller => "identity", :controller_prefix => ""
+ )
+ )
+ end
+
+ def test_basecamp
+ basecamp_url = ActionController::UrlRewriter.new(MockRequest.new(
+ "http://",
+ "projects.basecamp",
+ 80,
+ "/clients/disarray/1/msg/transcripts/",
+ {"category_name"=>"transcripts", "client_name"=>"disarray", "action"=>"index", "controller"=>"msg", "project_name"=>"1"}
+ ), "msg", "index")
+
+ assert_equal(
+ "http://projects.basecamp/clients/disarray/1/msg/transcripts/1/comments",
+ basecamp_url.rewrite(:action_prefix => "transcripts/1", :action => "comments")
+ )
+ end
+
+ def test_on_explicit_index_page # My index page is very modest, thank you...
+ url = ActionController::UrlRewriter.new(
+ MockRequest.new(
+ "http://", "example.com", 80, "/controller/index",
+ {"controller"=>"controller", "action"=>"index"}
+ ), "controller", "index"
+ )
+ assert_equal("http://example.com/controller/foo", url.rewrite(:action => 'foo'))
+ end
+
+end
diff --git a/actionpack/test/fixtures/helpers/abc_helper.rb b/actionpack/test/fixtures/helpers/abc_helper.rb
new file mode 100644
index 0000000000..7104ff3730
--- /dev/null
+++ b/actionpack/test/fixtures/helpers/abc_helper.rb
@@ -0,0 +1,5 @@
+module AbcHelper
+ def bare_a() end
+ def bare_b() end
+ def bare_c() end
+end
diff --git a/actionpack/test/fixtures/layouts/builder.rxml b/actionpack/test/fixtures/layouts/builder.rxml
new file mode 100644
index 0000000000..729af4b8bc
--- /dev/null
+++ b/actionpack/test/fixtures/layouts/builder.rxml
@@ -0,0 +1,3 @@
+xml.wrapper do
+ xml << @content_for_layout
+end
\ No newline at end of file
diff --git a/actionpack/test/fixtures/layouts/standard.rhtml b/actionpack/test/fixtures/layouts/standard.rhtml
new file mode 100644
index 0000000000..fcb28ec755
--- /dev/null
+++ b/actionpack/test/fixtures/layouts/standard.rhtml
@@ -0,0 +1 @@
+<%= @content_for_layout %>
\ No newline at end of file
diff --git a/actionpack/test/fixtures/scope/test/modgreet.rhtml b/actionpack/test/fixtures/scope/test/modgreet.rhtml
new file mode 100644
index 0000000000..8947726e89
--- /dev/null
+++ b/actionpack/test/fixtures/scope/test/modgreet.rhtml
@@ -0,0 +1 @@
+Beautiful modules!
\ No newline at end of file
diff --git a/actionpack/test/fixtures/test/_customer.rhtml b/actionpack/test/fixtures/test/_customer.rhtml
new file mode 100644
index 0000000000..872d8c44e6
--- /dev/null
+++ b/actionpack/test/fixtures/test/_customer.rhtml
@@ -0,0 +1 @@
+Hello: <%= customer.name %>
\ No newline at end of file
diff --git a/actionpack/test/fixtures/test/greeting.rhtml b/actionpack/test/fixtures/test/greeting.rhtml
new file mode 100644
index 0000000000..62fb0293f0
--- /dev/null
+++ b/actionpack/test/fixtures/test/greeting.rhtml
@@ -0,0 +1 @@
+This is grand!
diff --git a/actionpack/test/fixtures/test/hello.rxml b/actionpack/test/fixtures/test/hello.rxml
new file mode 100644
index 0000000000..82a4a310d3
--- /dev/null
+++ b/actionpack/test/fixtures/test/hello.rxml
@@ -0,0 +1,4 @@
+xml.html do
+ xml.p "Hello #{@name}"
+ xml << render_file("test/greeting")
+end
\ No newline at end of file
diff --git a/actionpack/test/fixtures/test/hello_world.rhtml b/actionpack/test/fixtures/test/hello_world.rhtml
new file mode 100644
index 0000000000..6769dd60bd
--- /dev/null
+++ b/actionpack/test/fixtures/test/hello_world.rhtml
@@ -0,0 +1 @@
+Hello world!
\ No newline at end of file
diff --git a/actionpack/test/fixtures/test/hello_xml_world.rxml b/actionpack/test/fixtures/test/hello_xml_world.rxml
new file mode 100644
index 0000000000..02b14fe87c
--- /dev/null
+++ b/actionpack/test/fixtures/test/hello_xml_world.rxml
@@ -0,0 +1,11 @@
+xml.html do
+ xml.head do
+ xml.title "Hello World"
+ end
+
+ xml.body do
+ xml.p "abes"
+ xml.p "monks"
+ xml.p "wiseguys"
+ end
+end
\ No newline at end of file
diff --git a/actionpack/test/fixtures/test/list.rhtml b/actionpack/test/fixtures/test/list.rhtml
new file mode 100644
index 0000000000..39e2cad966
--- /dev/null
+++ b/actionpack/test/fixtures/test/list.rhtml
@@ -0,0 +1 @@
+<%= render_collection_of_partials "customer", @customers %>
\ No newline at end of file
diff --git a/actionpack/test/template/active_record_helper_test.rb b/actionpack/test/template/active_record_helper_test.rb
new file mode 100644
index 0000000000..4b32f4dd48
--- /dev/null
+++ b/actionpack/test/template/active_record_helper_test.rb
@@ -0,0 +1,76 @@
+require 'test/unit'
+require File.dirname(__FILE__) + '/../../lib/action_view/helpers/date_helper'
+require File.dirname(__FILE__) + '/../../lib/action_view/helpers/form_helper'
+# require File.dirname(__FILE__) + '/../../lib/action_view/helpers/active_record_helper'
+
+class ActiveRecordHelperTest < Test::Unit::TestCase
+ include ActionView::Helpers::FormHelper
+ include ActionView::Helpers::ActiveRecordHelper
+
+ Post = Struct.new("Post", :title, :author_name, :body, :secret, :written_on)
+ Column = Struct.new("Column", :type, :name, :human_name)
+
+ def setup
+ @post = Post.new
+ def @post.errors() Class.new{ def on(field) field == "author_name" || field == "body" end }.new end
+ def @post.new_record?() true end
+
+ def @post.column_for_attribute(attr_name)
+ Post.content_columns.select { |column| column.name == attr_name }.first
+ end
+
+ def Post.content_columns() [ Column.new(:string, "title", "Title"), Column.new(:text, "body", "Body") ] end
+
+ @post.title = "Hello World"
+ @post.author_name = ""
+ @post.body = "Back to the hill and over it again!"
+ @post.secret = 1
+ @post.written_on = Date.new(2004, 6, 15)
+ end
+
+ def test_generic_input_tag
+ assert_equal(
+ ' ', input("post", "title")
+ )
+ end
+
+ def test_text_area_with_errors
+ assert_equal(
+ "
",
+ text_area("post", "body")
+ )
+ end
+
+ def test_text_field_with_errors
+ assert_equal(
+ '
',
+ text_field("post", "author_name")
+ )
+ end
+
+ def test_form_with_string
+ assert_equal(
+ "
",
+ form("post")
+ )
+ end
+
+ def test_form_with_date
+ def Post.content_columns() [ Column.new(:date, "written_on", "Written on") ] end
+
+ assert_equal(
+ "Written on \n1999 \n2000 \n2001 \n2002 \n2003 \n2004 \n2005 \n2006 \n2007 \n2008 \n2009 \n \n\nJanuary \nFebruary \nMarch \nApril \nMay \nJune \nJuly \nAugust \nSeptember \nOctober \nNovember \nDecember \n \n\n1 \n2 \n3 \n4 \n5 \n6 \n7 \n8 \n9 \n10 \n11 \n12 \n13 \n14 \n15 \n16 \n17 \n18 \n19 \n20 \n21 \n22 \n23 \n24 \n25 \n26 \n27 \n28 \n29 \n30 \n31 \n \n
",
+ form("post")
+ )
+ end
+
+ def test_form_with_datetime
+ def Post.content_columns() [ Column.new(:datetime, "written_on", "Written on") ] end
+ @post.written_on = Time.gm(2004, 6, 15, 16, 30)
+
+ assert_equal(
+ "Written on \n1999 \n2000 \n2001 \n2002 \n2003 \n2004 \n2005 \n2006 \n2007 \n2008 \n2009 \n \n\nJanuary \nFebruary \nMarch \nApril \nMay \nJune \nJuly \nAugust \nSeptember \nOctober \nNovember \nDecember \n \n\n1 \n2 \n3 \n4 \n5 \n6 \n7 \n8 \n9 \n10 \n11 \n12 \n13 \n14 \n15 \n16 \n17 \n18 \n19 \n20 \n21 \n22 \n23 \n24 \n25 \n26 \n27 \n28 \n29 \n30 \n31 \n \n — \n00 \n01 \n02 \n03 \n04 \n05 \n06 \n07 \n08 \n09 \n10 \n11 \n12 \n13 \n14 \n15 \n16 \n17 \n18 \n19 \n20 \n21 \n22 \n23 \n \n : \n00 \n01 \n02 \n03 \n04 \n05 \n06 \n07 \n08 \n09 \n10 \n11 \n12 \n13 \n14 \n15 \n16 \n17 \n18 \n19 \n20 \n21 \n22 \n23 \n24 \n25 \n26 \n27 \n28 \n29 \n30 \n31 \n32 \n33 \n34 \n35 \n36 \n37 \n38 \n39 \n40 \n41 \n42 \n43 \n44 \n45 \n46 \n47 \n48 \n49 \n50 \n51 \n52 \n53 \n54 \n55 \n56 \n57 \n58 \n59 \n \n
",
+ form("post")
+ )
+ end
+end
\ No newline at end of file
diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb
new file mode 100755
index 0000000000..a8ad37918d
--- /dev/null
+++ b/actionpack/test/template/date_helper_test.rb
@@ -0,0 +1,104 @@
+require 'test/unit'
+require File.dirname(__FILE__) + '/../../lib/action_view/helpers/date_helper'
+
+class DateHelperTest < Test::Unit::TestCase
+ include ActionView::Helpers::DateHelper
+
+ def test_distance_in_words
+ from = Time.mktime(2004, 3, 6, 21, 41, 18)
+
+ assert_equal "less than a minute", distance_of_time_in_words(from, Time.mktime(2004, 3, 6, 21, 41, 25))
+ assert_equal "5 minutes", distance_of_time_in_words(from, Time.mktime(2004, 3, 6, 21, 46, 25))
+ assert_equal "about 1 hour", distance_of_time_in_words(from, Time.mktime(2004, 3, 6, 22, 47, 25))
+ assert_equal "about 3 hours", distance_of_time_in_words(from, Time.mktime(2004, 3, 7, 0, 41))
+ assert_equal "about 4 hours", distance_of_time_in_words(from, Time.mktime(2004, 3, 7, 1, 20))
+ assert_equal "2 days", distance_of_time_in_words(from, Time.mktime(2004, 3, 9, 15, 40))
+ end
+
+ def test_select_day
+ expected = "\n"
+ expected <<
+"1 \n2 \n3 \n4 \n5 \n6 \n7 \n8 \n9 \n10 \n11 \n12 \n13 \n14 \n15 \n16 \n17 \n18 \n19 \n20 \n21 \n22 \n23 \n24 \n25 \n26 \n27 \n28 \n29 \n30 \n31 \n"
+ expected << " \n"
+
+ assert_equal expected, select_day(Time.mktime(2003, 8, 16))
+ assert_equal expected, select_day(16)
+ end
+
+ def test_select_day_with_blank
+ expected = "\n"
+ expected <<
+" \n1 \n2 \n3 \n4 \n5 \n6 \n7 \n8 \n9 \n10 \n11 \n12 \n13 \n14 \n15 \n16 \n17 \n18 \n19 \n20 \n21 \n22 \n23 \n24 \n25 \n26 \n27 \n28 \n29 \n30 \n31 \n"
+ expected << " \n"
+
+ assert_equal expected, select_day(Time.mktime(2003, 8, 16), :include_blank => true)
+ assert_equal expected, select_day(16, :include_blank => true)
+ end
+
+ def test_select_month
+ expected = "\n"
+ expected << "January \nFebruary \nMarch \nApril \nMay \nJune \nJuly \nAugust \nSeptember \nOctober \nNovember \nDecember \n"
+ expected << " \n"
+
+ assert_equal expected, select_month(Time.mktime(2003, 8, 16))
+ assert_equal expected, select_month(8)
+ end
+
+ def test_select_month_with_numbers
+ expected = "\n"
+ expected << "1 \n2 \n3 \n4 \n5 \n6 \n7 \n8 \n9 \n10 \n11 \n12 \n"
+ expected << " \n"
+
+ assert_equal expected, select_month(Time.mktime(2003, 8, 16), :use_month_numbers => true)
+ assert_equal expected, select_month(8, :use_month_numbers => true)
+ end
+
+ def test_select_month_with_numbers_and_names
+ expected = "\n"
+ expected << "1 - January \n2 - February \n3 - March \n4 - April \n5 - May \n6 - June \n7 - July \n8 - August \n9 - September \n10 - October \n11 - November \n12 - December \n"
+ expected << " \n"
+
+ assert_equal expected, select_month(Time.mktime(2003, 8, 16), :add_month_numbers => true)
+ assert_equal expected, select_month(8, :add_month_numbers => true)
+ end
+
+ def test_select_year
+ expected = "\n"
+ expected << "2003 \n2004 \n2005 \n"
+ expected << " \n"
+
+ assert_equal expected, select_year(Time.mktime(2003, 8, 16), :start_year => 2003, :end_year => 2005)
+ assert_equal expected, select_year(2003, :start_year => 2003, :end_year => 2005)
+ end
+
+ def test_select_year_with_type_discarding
+ expected = "\n"
+ expected << "2003 \n2004 \n2005 \n"
+ expected << " \n"
+
+ assert_equal expected, select_year(
+ Time.mktime(2003, 8, 16), :prefix => "date_year", :discard_type => true, :start_year => 2003, :end_year => 2005)
+ assert_equal expected, select_year(
+ 2003, :prefix => "date_year", :discard_type => true, :start_year => 2003, :end_year => 2005)
+ end
+
+
+ def test_select_date
+ expected = "\n"
+ expected << "2003 \n2004 \n2005 \n"
+ expected << " \n"
+
+ expected << "\n"
+ expected << "January \nFebruary \nMarch \nApril \nMay \nJune \nJuly \nAugust \nSeptember \nOctober \nNovember \nDecember \n"
+ expected << " \n"
+
+ expected << "\n"
+ expected <<
+"1 \n2 \n3 \n4 \n5 \n6 \n7 \n8 \n9 \n10 \n11 \n12 \n13 \n14 \n15 \n16 \n17 \n18 \n19 \n20 \n21 \n22 \n23 \n24 \n25 \n26 \n27 \n28 \n29 \n30 \n31 \n"
+ expected << " \n"
+
+ assert_equal expected, select_date(
+ Time.mktime(2003, 8, 16), :start_year => 2003, :end_year => 2005, :prefix => "date[first]"
+ )
+ end
+end
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
new file mode 100644
index 0000000000..8f3d5ebb94
--- /dev/null
+++ b/actionpack/test/template/form_helper_test.rb
@@ -0,0 +1,124 @@
+require 'test/unit'
+require File.dirname(__FILE__) + '/../../lib/action_view/helpers/form_helper'
+
+class FormHelperTest < Test::Unit::TestCase
+ include ActionView::Helpers::FormHelper
+
+ old_verbose, $VERBOSE = $VERBOSE, nil
+ Post = Struct.new("Post", :title, :author_name, :body, :secret, :written_on)
+ $VERBOSE = old_verbose
+
+ def setup
+ @post = Post.new
+ def @post.errors() Class.new{ def on(field) field == "author_name" end }.new end
+
+ @post.title = "Hello World"
+ @post.author_name = ""
+ @post.body = "Back to the hill and over it again!"
+ @post.secret = 1
+ @post.written_on = Date.new(2004, 6, 15)
+ end
+
+ def test_text_field
+ assert_equal(
+ ' ', text_field("post", "title")
+ )
+ assert_equal(
+ ' ', password_field("post", "title")
+ )
+ assert_equal(
+ ' ', password_field("person", "name")
+ )
+ end
+
+ def test_text_field_with_escapes
+ @post.title = "Hello World "
+ assert_equal(
+ ' ', text_field("post", "title")
+ )
+ end
+
+ def test_text_field_with_options
+ assert_equal(
+ ' ',
+ text_field("post", "title", "size" => "35")
+ )
+ end
+
+ def test_text_field_assuming_size
+ assert_equal(
+ ' ',
+ text_field("post", "title", "maxlength" => 35)
+ )
+ end
+
+ def test_check_box
+ assert_equal(
+ ' ',
+ check_box("post", "secret")
+ )
+
+ @post.secret = 0
+ assert_equal(
+ ' ',
+ check_box("post", "secret")
+ )
+
+ @post.secret = true
+ assert_equal(
+ ' ',
+ check_box("post", "secret")
+ )
+ end
+
+ def test_text_area
+ assert_equal(
+ 'Back to the hill and over it again! ',
+ text_area("post", "body")
+ )
+ end
+
+ def test_text_area_with_escapes
+ @post.body = "Back to the hill and over it again!"
+ assert_equal(
+ 'Back to <i>the</i> hill and over it again! ',
+ text_area("post", "body")
+ )
+ end
+
+ def test_date_selects
+ assert_equal(
+ 'Back to the hill and over it again! ',
+ text_area("post", "body")
+ )
+ end
+
+
+ def test_explicit_name
+ assert_equal(
+ ' ', text_field("post", "title", "name" => "dont guess")
+ )
+ assert_equal(
+ 'Back to the hill and over it again! ',
+ text_area("post", "body", "name" => "really!")
+ )
+ assert_equal(
+ ' ',
+ check_box("post", "secret", "name" => "i mean it")
+ )
+ end
+
+ def test_explicit_id
+ assert_equal(
+ ' ', text_field("post", "title", "id" => "dont guess")
+ )
+ assert_equal(
+ 'Back to the hill and over it again! ',
+ text_area("post", "body", "id" => "really!")
+ )
+ assert_equal(
+ ' ',
+ check_box("post", "secret", "id" => "i mean it")
+ )
+ end
+end
diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb
new file mode 100644
index 0000000000..fa0a37aa36
--- /dev/null
+++ b/actionpack/test/template/form_options_helper_test.rb
@@ -0,0 +1,165 @@
+require 'test/unit'
+require File.dirname(__FILE__) + '/../../lib/action_view/helpers/form_options_helper'
+
+class FormOptionsHelperTest < Test::Unit::TestCase
+ include ActionView::Helpers::FormOptionsHelper
+
+ old_verbose, $VERBOSE = $VERBOSE, nil
+ Post = Struct.new('Post', :title, :author_name, :body, :secret, :written_on, :category, :origin)
+ Continent = Struct.new('Continent', :continent_name, :countries)
+ Country = Struct.new('Country', :country_id, :country_name)
+ $VERBOSE = old_verbose
+
+ def test_collection_options
+ @posts = [
+ Post.new(" went home", "", "To a little house", "shh!"),
+ Post.new("Babe went home", "Babe", "To a little house", "shh!"),
+ Post.new("Cabe went home", "Cabe", "To a little house", "shh!")
+ ]
+
+ assert_equal(
+ "<Abe> went home \nBabe went home \nCabe went home ",
+ options_from_collection_for_select(@posts, "author_name", "title")
+ )
+ end
+
+
+ def test_collection_options_with_preselected_value
+ @posts = [
+ Post.new(" went home", "", "To a little house", "shh!"),
+ Post.new("Babe went home", "Babe", "To a little house", "shh!"),
+ Post.new("Cabe went home", "Cabe", "To a little house", "shh!")
+ ]
+
+ assert_equal(
+ "<Abe> went home \nBabe went home \nCabe went home ",
+ options_from_collection_for_select(@posts, "author_name", "title", "Babe")
+ )
+ end
+
+ def test_collection_options_with_preselected_value_array
+ @posts = [
+ Post.new(" went home", "", "To a little house", "shh!"),
+ Post.new("Babe went home", "Babe", "To a little house", "shh!"),
+ Post.new("Cabe went home", "Cabe", "To a little house", "shh!")
+ ]
+
+ assert_equal(
+ "<Abe> went home \nBabe went home \nCabe went home ",
+ options_from_collection_for_select(@posts, "author_name", "title", [ "Babe", "Cabe" ])
+ )
+ end
+
+ def test_array_options_for_select
+ assert_equal(
+ "<Denmark> \nUSA \nSweden ",
+ options_for_select([ "", "USA", "Sweden" ])
+ )
+ end
+
+ def test_array_options_for_select_with_selection
+ assert_equal(
+ "Denmark \n<USA> \nSweden ",
+ options_for_select([ "Denmark", "", "Sweden" ], "")
+ )
+ end
+
+ def test_array_options_for_select_with_selection_array
+ assert_equal(
+ "Denmark \n<USA> \nSweden ",
+ options_for_select([ "Denmark", "", "Sweden" ], [ "", "Sweden" ])
+ )
+ end
+
+ def test_hash_options_for_select
+ assert_equal(
+ "<DKR> \n$ ",
+ options_for_select({ "$" => "Dollar", "" => "" })
+ )
+ end
+
+ def test_hash_options_for_select_with_selection
+ assert_equal(
+ "<DKR> \n$ ",
+ options_for_select({ "$" => "Dollar", "" => "" }, "Dollar")
+ )
+ end
+
+ def test_hash_options_for_select_with_selection
+ assert_equal(
+ "<DKR> \n$ ",
+ options_for_select({ "$" => "Dollar", "" => "" }, [ "Dollar", "" ])
+ )
+ end
+
+ def test_html_option_groups_from_collection
+ @continents = [
+ Continent.new("", [Country.new("", ""), Country.new("so", "Somalia")] ),
+ Continent.new("Europe", [Country.new("dk", "Denmark"), Country.new("ie", "Ireland")] )
+ ]
+
+ assert_equal(
+ "<South Africa> \nSomalia Denmark \nIreland ",
+ option_groups_from_collection_for_select(@continents, "countries", "continent_name", "country_id", "country_name", "dk")
+ )
+ end
+
+ def test_select
+ @post = Post.new
+ @post.category = ""
+ assert_equal(
+ "abe \n<mus> \nhest ",
+ select("post", "category", %w( abe hest))
+ )
+ end
+
+ def test_select_with_blank
+ @post = Post.new
+ @post.category = ""
+ assert_equal(
+ " \nabe \n<mus> \nhest ",
+ select("post", "category", %w( abe hest), :include_blank => true)
+ )
+ end
+
+ def test_collection_select
+ @posts = [
+ Post.new(" went home", "", "To a little house", "shh!"),
+ Post.new("Babe went home", "Babe", "To a little house", "shh!"),
+ Post.new("Cabe went home", "Cabe", "To a little house", "shh!")
+ ]
+
+ @post = Post.new
+ @post.author_name = "Babe"
+
+ assert_equal(
+ "<Abe> \nBabe \nCabe ",
+ collection_select("post", "author_name", @posts, "author_name", "author_name")
+ )
+ end
+
+ def test_collection_select_with_blank_and_style
+ @posts = [
+ Post.new(" went home", "", "To a little house", "shh!"),
+ Post.new("Babe went home", "Babe", "To a little house", "shh!"),
+ Post.new("Cabe went home", "Cabe", "To a little house", "shh!")
+ ]
+
+ @post = Post.new
+ @post.author_name = "Babe"
+
+ assert_equal(
+ " \n<Abe> \nBabe \nCabe ",
+ collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => true }, "style" => "width: 200px")
+ )
+ end
+
+ def test_country_select
+ @post = Post.new
+ @post.origin = "Denmark"
+ assert_equal(
+ "Albania \nAlgeria \nAmerican Samoa \nAndorra \nAngola \nAnguilla \nAntarctica \nAntigua And Barbuda \nArgentina \nArmenia \nAruba \nAustralia \nAustria \nAzerbaijan \nBahamas \nBahrain \nBangladesh \nBarbados \nBelarus \nBelgium \nBelize \nBenin \nBermuda \nBhutan \nBolivia \nBosnia and Herzegowina \nBotswana \nBouvet Island \nBrazil \nBritish Indian Ocean Territory \nBrunei Darussalam \nBulgaria \nBurkina Faso \nBurma \nBurundi \nCambodia \nCameroon \nCanada \nCape Verde \nCayman Islands \nCentral African Republic \nChad \nChile \nChina \nChristmas Island \nCocos (Keeling) Islands \nColombia \nComoros \nCongo \nCongo, the Democratic Republic of the \nCook Islands \nCosta Rica \nCote d'Ivoire \nCroatia \nCyprus \nCzech Republic \nDenmark \nDjibouti \nDominica \nDominican Republic \nEast Timor \nEcuador \nEgypt \nEl Salvador \nEngland \nEquatorial Guinea \nEritrea \nEspana \nEstonia \nEthiopia \nFalkland Islands \nFaroe Islands \nFiji \nFinland \nFrance \nFrench Guiana \nFrench Polynesia \nFrench Southern Territories \nGabon \nGambia \nGeorgia \nGermany \nGhana \nGibraltar \nGreat Britain \nGreece \nGreenland \nGrenada \nGuadeloupe \nGuam \nGuatemala \nGuinea \nGuinea-Bissau \nGuyana \nHaiti \nHeard and Mc Donald Islands \nHonduras \nHong Kong \nHungary \nIceland \nIndia \nIndonesia \nIreland \nIsrael \nItaly \nJamaica \nJapan \nJordan \nKazakhstan \nKenya \nKiribati \nKorea, Republic of \nKorea (South) \nKuwait \nKyrgyzstan \nLao People's Democratic Republic \nLatvia \nLebanon \nLesotho \nLiberia \nLiechtenstein \nLithuania \nLuxembourg \nMacau \nMacedonia \nMadagascar \nMalawi \nMalaysia \nMaldives \nMali \nMalta \nMarshall Islands \nMartinique \nMauritania \nMauritius \nMayotte \nMexico \nMicronesia, Federated States of \nMoldova, Republic of \nMonaco \nMongolia \nMontserrat \nMorocco \nMozambique \nMyanmar \nNamibia \nNauru \nNepal \nNetherlands \nNetherlands Antilles \nNew Caledonia \nNew Zealand \nNicaragua \nNiger \nNigeria \nNiue \nNorfolk Island \nNorthern Ireland \nNorthern Mariana Islands \nNorway \nOman \nPakistan \nPalau \nPanama \nPapua New Guinea \nParaguay \nPeru \nPhilippines \nPitcairn \nPoland \nPortugal \nPuerto Rico \nQatar \nReunion \nRomania \nRussia \nRwanda \nSaint Kitts and Nevis \nSaint Lucia \nSaint Vincent and the Grenadines \nSamoa (Independent) \nSan Marino \nSao Tome and Principe \nSaudi Arabia \nScotland \nSenegal \nSeychelles \nSierra Leone \nSingapore \nSlovakia \nSlovenia \nSolomon Islands \nSomalia \nSouth Africa \nSouth Georgia and the South Sandwich Islands \nSouth Korea \nSpain \nSri Lanka \nSt. Helena \nSt. Pierre and Miquelon \nSuriname \nSvalbard and Jan Mayen Islands \nSwaziland \nSweden \nSwitzerland \nTaiwan \nTajikistan \nTanzania \nThailand \nTogo \nTokelau \nTonga \nTrinidad \nTrinidad and Tobago \nTunisia \nTurkey \nTurkmenistan \nTurks and Caicos Islands \nTuvalu \nUganda \nUkraine \nUnited Arab Emirates \nUnited Kingdom \nUnited States \nUnited States Minor Outlying Islands \nUruguay \nUzbekistan \nVanuatu \nVatican City State (Holy See) \nVenezuela \nViet Nam \nVirgin Islands (British) \nVirgin Islands (U.S.) \nWales \nWallis and Futuna Islands \nWestern Sahara \nYemen \nZambia \nZimbabwe ",
+ country_select("post", "origin")
+ )
+ end
+end
diff --git a/actionpack/test/template/tag_helper_test.rb b/actionpack/test/template/tag_helper_test.rb
new file mode 100644
index 0000000000..c3289af50c
--- /dev/null
+++ b/actionpack/test/template/tag_helper_test.rb
@@ -0,0 +1,18 @@
+require 'test/unit'
+require File.dirname(__FILE__) + '/../../lib/action_view/helpers/tag_helper'
+require File.dirname(__FILE__) + '/../../lib/action_view/helpers/url_helper'
+
+class TagHelperTest < Test::Unit::TestCase
+ include ActionView::Helpers::TagHelper
+ include ActionView::Helpers::UrlHelper
+
+ def test_tag
+ assert_equal "
", tag("p", "class" => "show")
+ end
+
+ def test_content_tag
+ assert_equal "Create ", content_tag("a", "Create", "href" => "create")
+ end
+
+ # FIXME: Test form tag
+end
\ No newline at end of file
diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb
new file mode 100644
index 0000000000..347420a72b
--- /dev/null
+++ b/actionpack/test/template/text_helper_test.rb
@@ -0,0 +1,62 @@
+require 'test/unit'
+require File.dirname(__FILE__) + '/../../lib/action_view/helpers/text_helper'
+
+class TextHelperTest < Test::Unit::TestCase
+ include ActionView::Helpers::TextHelper
+
+ def test_truncate
+ assert_equal "Hello World!", truncate("Hello World!", 12)
+ assert_equal "Hello Worl...", truncate("Hello World!!", 12)
+ end
+
+ def test_strip_links
+ assert_equal "on my mind", strip_links("on my mind ")
+ end
+
+ def test_highlighter
+ assert_equal(
+ "This is a beautiful morning",
+ highlight("This is a beautiful morning", "beautiful")
+ )
+
+ assert_equal(
+ "This is a beautiful morning, but also a beautiful day",
+ highlight("This is a beautiful morning, but also a beautiful day", "beautiful")
+ )
+
+ assert_equal(
+ "This is a beautiful morning, but also a beautiful day",
+ highlight("This is a beautiful morning, but also a beautiful day", "beautiful", '\1 ')
+ )
+ end
+
+ def test_highlighter_with_regexp
+ assert_equal(
+ "This is a beautiful! morning",
+ highlight("This is a beautiful! morning", "beautiful!")
+ )
+
+ assert_equal(
+ "This is a beautiful! morning ",
+ highlight("This is a beautiful! morning", "beautiful! morning")
+ )
+
+ assert_equal(
+ "This is a beautiful? morning ",
+ highlight("This is a beautiful? morning", "beautiful? morning")
+ )
+ end
+
+ def test_excerpt
+ assert_equal("...is a beautiful morni...", excerpt("This is a beautiful morning", "beautiful", 5))
+ assert_equal("This is a...", excerpt("This is a beautiful morning", "this", 5))
+ assert_equal("...iful morning", excerpt("This is a beautiful morning", "morning", 5))
+ assert_equal("...iful morning", excerpt("This is a beautiful morning", "morning", 5))
+ assert_nil excerpt("This is a beautiful morning", "day")
+ end
+
+ def test_pluralization
+ assert_equal("1 count", pluralize(1, "count"))
+ assert_equal("2 counts", pluralize(2, "count"))
+ end
+end
\ No newline at end of file
diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb
new file mode 100644
index 0000000000..198b26b113
--- /dev/null
+++ b/actionpack/test/template/url_helper_test.rb
@@ -0,0 +1,49 @@
+require 'test/unit'
+require File.dirname(__FILE__) + '/../../lib/action_view/helpers/url_helper'
+require File.dirname(__FILE__) + '/../../lib/action_view/helpers/tag_helper'
+
+class UrlHelperTest < Test::Unit::TestCase
+ include ActionView::Helpers::UrlHelper
+ include ActionView::Helpers::TagHelper
+
+ def setup
+ @controller = Class.new do
+ def url_for(options, *parameters_for_method_reference)
+ "http://www.world.com"
+ end
+ end
+ @controller = @controller.new
+ end
+
+ # todo: missing test cases
+ def test_link_tag_with_straight_url
+ assert_equal "Hello ", link_to("Hello", "http://www.world.com")
+ end
+
+ def test_link_tag_with_javascript_confirm
+ assert_equal(
+ "Hello ",
+ link_to("Hello", "http://www.world.com", :confirm => "Are you sure?")
+ )
+ end
+
+ def test_link_unless_current
+ @params = { "controller" => "weblog", "action" => "show"}
+ assert_equal "Showing", link_to_unless_current("Showing", :action => "show", :controller => "weblog")
+ assert "Listing ", link_to_unless_current("Listing", :action => "list", :controller => "weblog")
+ end
+
+ def test_mail_to
+ assert_equal "david@loudthinking.com ", mail_to("david@loudthinking.com")
+ assert_equal "David Heinemeier Hansson ", mail_to("david@loudthinking.com", "David Heinemeier Hansson")
+ assert_equal(
+ "David Heinemeier Hansson ",
+ mail_to("david@loudthinking.com", "David Heinemeier Hansson", "class" => "admin")
+ )
+ end
+
+ def test_link_with_nil_html_options
+ assert "Hello ",
+ link_to("Hello", {:action => 'myaction'}, nil)
+ end
+end
\ No newline at end of file
--
cgit v1.2.3