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/CHANGELOG | 738 +++++++++++++++++++++
actionpack/MIT-LICENSE | 21 +
actionpack/README | 418 ++++++++++++
actionpack/RUNNING_UNIT_TESTS | 25 +
actionpack/Rakefile | 105 +++
actionpack/examples/.htaccess | 24 +
actionpack/examples/address_book/index.rhtml | 33 +
actionpack/examples/address_book/layout.rhtml | 8 +
actionpack/examples/address_book_controller.cgi | 9 +
actionpack/examples/address_book_controller.fcgi | 6 +
actionpack/examples/address_book_controller.rb | 52 ++
actionpack/examples/address_book_controller.rbx | 4 +
actionpack/examples/benchmark.rb | 52 ++
actionpack/examples/benchmark_with_ar.fcgi | 89 +++
actionpack/examples/blog_controller.cgi | 53 ++
actionpack/examples/debate/index.rhtml | 14 +
actionpack/examples/debate/new_topic.rhtml | 22 +
actionpack/examples/debate/topic.rhtml | 32 +
actionpack/examples/debate_controller.cgi | 57 ++
actionpack/install.rb | 97 +++
actionpack/lib/action_controller.rb | 51 ++
.../assertions/action_pack_assertions.rb | 199 ++++++
.../assertions/active_record_assertions.rb | 65 ++
actionpack/lib/action_controller/base.rb | 689 +++++++++++++++++++
actionpack/lib/action_controller/benchmarking.rb | 49 ++
.../lib/action_controller/cgi_ext/cgi_ext.rb | 43 ++
.../lib/action_controller/cgi_ext/cgi_methods.rb | 91 +++
actionpack/lib/action_controller/cgi_process.rb | 124 ++++
actionpack/lib/action_controller/dependencies.rb | 49 ++
actionpack/lib/action_controller/filters.rb | 279 ++++++++
actionpack/lib/action_controller/flash.rb | 65 ++
actionpack/lib/action_controller/helpers.rb | 100 +++
actionpack/lib/action_controller/layout.rb | 149 +++++
actionpack/lib/action_controller/request.rb | 99 +++
actionpack/lib/action_controller/rescue.rb | 94 +++
actionpack/lib/action_controller/response.rb | 15 +
actionpack/lib/action_controller/scaffolding.rb | 183 +++++
.../session/active_record_store.rb | 72 ++
.../lib/action_controller/session/drb_server.rb | 9 +
.../lib/action_controller/session/drb_store.rb | 31 +
.../support/class_attribute_accessors.rb | 57 ++
.../support/class_inheritable_attributes.rb | 37 ++
.../lib/action_controller/support/clean_logger.rb | 10 +
.../support/cookie_performance_fix.rb | 121 ++++
.../lib/action_controller/support/inflector.rb | 78 +++
.../templates/rescues/_request_and_response.rhtml | 28 +
.../templates/rescues/diagnostics.rhtml | 22 +
.../templates/rescues/layout.rhtml | 29 +
.../templates/rescues/missing_template.rhtml | 2 +
.../templates/rescues/template_error.rhtml | 26 +
.../templates/rescues/unknown_action.rhtml | 2 +
.../templates/scaffolds/edit.rhtml | 6 +
.../templates/scaffolds/layout.rhtml | 29 +
.../templates/scaffolds/list.rhtml | 24 +
.../templates/scaffolds/new.rhtml | 5 +
.../templates/scaffolds/show.rhtml | 9 +
actionpack/lib/action_controller/test_process.rb | 195 ++++++
actionpack/lib/action_controller/url_rewriter.rb | 170 +++++
actionpack/lib/action_view.rb | 49 ++
actionpack/lib/action_view/base.rb | 264 ++++++++
.../action_view/helpers/active_record_helper.rb | 171 +++++
actionpack/lib/action_view/helpers/date_helper.rb | 230 +++++++
actionpack/lib/action_view/helpers/debug_helper.rb | 17 +
actionpack/lib/action_view/helpers/form_helper.rb | 182 +++++
.../lib/action_view/helpers/form_options_helper.rb | 212 ++++++
actionpack/lib/action_view/helpers/tag_helper.rb | 59 ++
actionpack/lib/action_view/helpers/text_helper.rb | 111 ++++
actionpack/lib/action_view/helpers/url_helper.rb | 78 +++
actionpack/lib/action_view/partials.rb | 64 ++
actionpack/lib/action_view/template_error.rb | 84 +++
actionpack/lib/action_view/vendor/builder.rb | 13 +
.../lib/action_view/vendor/builder/blankslate.rb | 51 ++
.../lib/action_view/vendor/builder/xmlbase.rb | 143 ++++
.../lib/action_view/vendor/builder/xmlevents.rb | 63 ++
.../lib/action_view/vendor/builder/xmlmarkup.rb | 288 ++++++++
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 ++
105 files changed, 9547 insertions(+)
create mode 100644 actionpack/CHANGELOG
create mode 100644 actionpack/MIT-LICENSE
create mode 100755 actionpack/README
create mode 100644 actionpack/RUNNING_UNIT_TESTS
create mode 100755 actionpack/Rakefile
create mode 100644 actionpack/examples/.htaccess
create mode 100644 actionpack/examples/address_book/index.rhtml
create mode 100644 actionpack/examples/address_book/layout.rhtml
create mode 100755 actionpack/examples/address_book_controller.cgi
create mode 100755 actionpack/examples/address_book_controller.fcgi
create mode 100644 actionpack/examples/address_book_controller.rb
create mode 100644 actionpack/examples/address_book_controller.rbx
create mode 100644 actionpack/examples/benchmark.rb
create mode 100755 actionpack/examples/benchmark_with_ar.fcgi
create mode 100755 actionpack/examples/blog_controller.cgi
create mode 100644 actionpack/examples/debate/index.rhtml
create mode 100644 actionpack/examples/debate/new_topic.rhtml
create mode 100644 actionpack/examples/debate/topic.rhtml
create mode 100755 actionpack/examples/debate_controller.cgi
create mode 100644 actionpack/install.rb
create mode 100755 actionpack/lib/action_controller.rb
create mode 100644 actionpack/lib/action_controller/assertions/action_pack_assertions.rb
create mode 100644 actionpack/lib/action_controller/assertions/active_record_assertions.rb
create mode 100755 actionpack/lib/action_controller/base.rb
create mode 100644 actionpack/lib/action_controller/benchmarking.rb
create mode 100755 actionpack/lib/action_controller/cgi_ext/cgi_ext.rb
create mode 100755 actionpack/lib/action_controller/cgi_ext/cgi_methods.rb
create mode 100644 actionpack/lib/action_controller/cgi_process.rb
create mode 100644 actionpack/lib/action_controller/dependencies.rb
create mode 100644 actionpack/lib/action_controller/filters.rb
create mode 100644 actionpack/lib/action_controller/flash.rb
create mode 100644 actionpack/lib/action_controller/helpers.rb
create mode 100644 actionpack/lib/action_controller/layout.rb
create mode 100755 actionpack/lib/action_controller/request.rb
create mode 100644 actionpack/lib/action_controller/rescue.rb
create mode 100755 actionpack/lib/action_controller/response.rb
create mode 100644 actionpack/lib/action_controller/scaffolding.rb
create mode 100644 actionpack/lib/action_controller/session/active_record_store.rb
create mode 100644 actionpack/lib/action_controller/session/drb_server.rb
create mode 100644 actionpack/lib/action_controller/session/drb_store.rb
create mode 100644 actionpack/lib/action_controller/support/class_attribute_accessors.rb
create mode 100644 actionpack/lib/action_controller/support/class_inheritable_attributes.rb
create mode 100644 actionpack/lib/action_controller/support/clean_logger.rb
create mode 100644 actionpack/lib/action_controller/support/cookie_performance_fix.rb
create mode 100644 actionpack/lib/action_controller/support/inflector.rb
create mode 100644 actionpack/lib/action_controller/templates/rescues/_request_and_response.rhtml
create mode 100644 actionpack/lib/action_controller/templates/rescues/diagnostics.rhtml
create mode 100644 actionpack/lib/action_controller/templates/rescues/layout.rhtml
create mode 100644 actionpack/lib/action_controller/templates/rescues/missing_template.rhtml
create mode 100644 actionpack/lib/action_controller/templates/rescues/template_error.rhtml
create mode 100644 actionpack/lib/action_controller/templates/rescues/unknown_action.rhtml
create mode 100644 actionpack/lib/action_controller/templates/scaffolds/edit.rhtml
create mode 100644 actionpack/lib/action_controller/templates/scaffolds/layout.rhtml
create mode 100644 actionpack/lib/action_controller/templates/scaffolds/list.rhtml
create mode 100644 actionpack/lib/action_controller/templates/scaffolds/new.rhtml
create mode 100644 actionpack/lib/action_controller/templates/scaffolds/show.rhtml
create mode 100644 actionpack/lib/action_controller/test_process.rb
create mode 100644 actionpack/lib/action_controller/url_rewriter.rb
create mode 100644 actionpack/lib/action_view.rb
create mode 100644 actionpack/lib/action_view/base.rb
create mode 100644 actionpack/lib/action_view/helpers/active_record_helper.rb
create mode 100755 actionpack/lib/action_view/helpers/date_helper.rb
create mode 100644 actionpack/lib/action_view/helpers/debug_helper.rb
create mode 100644 actionpack/lib/action_view/helpers/form_helper.rb
create mode 100644 actionpack/lib/action_view/helpers/form_options_helper.rb
create mode 100644 actionpack/lib/action_view/helpers/tag_helper.rb
create mode 100644 actionpack/lib/action_view/helpers/text_helper.rb
create mode 100644 actionpack/lib/action_view/helpers/url_helper.rb
create mode 100644 actionpack/lib/action_view/partials.rb
create mode 100644 actionpack/lib/action_view/template_error.rb
create mode 100644 actionpack/lib/action_view/vendor/builder.rb
create mode 100644 actionpack/lib/action_view/vendor/builder/blankslate.rb
create mode 100644 actionpack/lib/action_view/vendor/builder/xmlbase.rb
create mode 100644 actionpack/lib/action_view/vendor/builder/xmlevents.rb
create mode 100644 actionpack/lib/action_view/vendor/builder/xmlmarkup.rb
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')
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
new file mode 100644
index 0000000000..a422af3f0e
--- /dev/null
+++ b/actionpack/CHANGELOG
@@ -0,0 +1,738 @@
+*CVS*
+
+* Upgraded to Builder 1.2.1
+
+* Added :module as an alias for :controller_prefix to url_for and friends, so you can do redirect_to(:module => "shop", :controller => "purchases")
+ and go to /shop/purchases/
+
+* Added support for controllers in modules through @params["module"].
+
+* Added reloading for dependencies under cached environments like FastCGI and mod_ruby. This makes it possible to use those environments for development.
+ This is turned on by default, but can be turned off with ActionController::Base.reload_dependencies = false in production environments.
+
+ NOTE: This will only have an effect if you use the new model, service, and observer class methods to mark dependencies. All libraries loaded through
+ require will be "forever" cached. You can, however, use ActionController::Base.load_or_require("library") to get this behavior outside of the new
+ dependency style.
+
+* Added that controllers will automatically require their own helper if possible. So instead of doing:
+
+ class MsgController < AbstractApplicationController
+ helper :msg
+ end
+
+ ...you can just do:
+
+ class MsgController < AbstractApplicationController
+ end
+
+* Added dependencies_on(layer) to query the dependencies of a controller. Examples:
+
+ MsgController.dependencies_on(:model) # => [ :post, :comment, :attachment ]
+ MsgController.dependencies_on(:service) # => [ :notification_service ]
+ MsgController.dependencies_on(:observer) # => [ :comment_observer ]
+
+* Added a new dependency model with the class methods model, service, and observer. Example:
+
+ class MsgController < AbstractApplicationController
+ model :post, :comment, :attachment
+ service :notification_service
+ observer :comment_observer
+ end
+
+ These new "keywords" remove the need for explicitly calling 'require' in most cases. The observer method even instantiates the
+ observer as well as requiring it.
+
+* Fixed that link_to would escape & in the url again after url_for already had done so
+
+*0.9.5* (28)
+
+* Added helper_method to designate that a given private or protected method you should available as a helper in the view. [bitsweat]
+
+* Fixed assert_rendered_file so it actually verifies if that was the rendered file [htonl]
+
+* Added the option for sharing partial spacer templates just like partials themselves [radsaq]
+
+* Fixed that Russia was named twice in country_select [alexey]
+
+* Fixed request_origin to use remote_ip instead of remote_addr [bitsweat]
+
+* Fixed link_to breakage when nil was passed for html_options [alexey]
+
+* Fixed redirect_to on a virtual server setup with apache with a port other than the default where it would forget the port number [seanohalpin]
+
+* Fixed that auto-loading webrick on Windows would cause file uploads to fail [bitsweat]
+
+* Fixed issues with sending files on WEBrick by setting the proper binmode [bitsweat]
+
+* Added send_data as an alternative to send_file when the stream is not read off the filesystem but from a database or generated live [bitsweat]
+
+* Added a new way to include helpers that doesn't require the include hack and can go without the explicit require. [bitsweat]
+
+ Before:
+
+ module WeblogHelper
+ def self.append_features(controller) #:nodoc:
+ controller.ancestors.include?(ActionController::Base) ? controller.add_template_helper(self) : super
+ end
+ end
+
+ require 'weblog_helper'
+ class WeblogController < ActionController::Base
+ include WeblogHelper
+ end
+
+ After:
+
+ module WeblogHelper
+ end
+
+ class WeblogController < ActionController::Base
+ helper :weblog
+ end
+
+* Added a default content-type of "text/xml" to .rxml renders [Ryan Platte]
+
+* Fixed that when /controller/index was requested by the browser, url_for would generates wrong URLs [Ryan Platte]
+
+* Fixed a bug that would share cookies between users when using FastCGI and mod_ruby [The Robot Co-op]
+
+* Added an optional third hash parameter to the process method in functional tests that takes the session data to be used [alexey]
+
+* Added UrlHelper#mail_to to make it easier to create mailto: style ahrefs
+
+* Added better error messages for layouts declared with the .rhtml extension (which they shouldn't) [geech]
+
+* Added another case to DateHelper#distance_in_minutes to return "less than a minute" instead of "0 minutes" and "1 minute" instead of "1 minutes"
+
+* Added a hidden field to checkboxes generated with FormHelper#check_box that will make sure that the unchecked value (usually 0)
+ is sent even if the checkbox is not checked. This relieves the controller from doing custom checking if the the checkbox wasn't
+ checked. BEWARE: This might conflict with your run-on-the-mill work-around code. [Tobias Luetke]
+
+* Fixed error_message_on to just use the first if more than one error had been added [marcel]
+
+* Fixed that URL rewriting with /controller/ was working but /controller was not and that you couldn't use :id on index [geech]
+
+* Fixed a bug with link_to where the :confirm option wouldn't be picked up if the link was a straight url instead of an option hash
+
+* Changed scaffolding of forms to use
",
+ form("post")
+ )
+ end
+
+ def test_form_with_date
+ def Post.content_columns() [ Column.new(:date, "written_on", "Written on") ] end
+
+ assert_equal(
+ "",
+ 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(
+ "",
+ 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"
+
+ 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"
+
+ 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"
+
+ 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"
+
+ 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"
+
+ 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"
+
+ 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"
+
+ 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 << "\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(
+ '',
+ text_area("post", "body")
+ )
+ end
+
+ def test_text_area_with_escapes
+ @post.body = "Back to the hill and over it again!"
+ assert_equal(
+ '',
+ text_area("post", "body")
+ )
+ end
+
+ def test_date_selects
+ assert_equal(
+ '',
+ text_area("post", "body")
+ )
+ end
+
+
+ def test_explicit_name
+ assert_equal(
+ '', text_field("post", "title", "name" => "dont guess")
+ )
+ assert_equal(
+ '',
+ 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(
+ '',
+ 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(
+ "\n\n",
+ 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(
+ "\n\n",
+ 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(
+ "\n\n",
+ options_from_collection_for_select(@posts, "author_name", "title", [ "Babe", "Cabe" ])
+ )
+ end
+
+ def test_array_options_for_select
+ assert_equal(
+ "\n\n",
+ options_for_select([ "", "USA", "Sweden" ])
+ )
+ end
+
+ def test_array_options_for_select_with_selection
+ assert_equal(
+ "\n\n",
+ options_for_select([ "Denmark", "", "Sweden" ], "")
+ )
+ end
+
+ def test_array_options_for_select_with_selection_array
+ assert_equal(
+ "\n\n",
+ options_for_select([ "Denmark", "", "Sweden" ], [ "", "Sweden" ])
+ )
+ end
+
+ def test_hash_options_for_select
+ assert_equal(
+ "\n",
+ options_for_select({ "$" => "Dollar", "" => "" })
+ )
+ end
+
+ def test_hash_options_for_select_with_selection
+ assert_equal(
+ "\n",
+ options_for_select({ "$" => "Dollar", "" => "" }, "Dollar")
+ )
+ end
+
+ def test_hash_options_for_select_with_selection
+ assert_equal(
+ "\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(
+ "",
+ 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(
+ "",
+ select("post", "category", %w( abe hest))
+ )
+ end
+
+ def test_select_with_blank
+ @post = Post.new
+ @post.category = ""
+ assert_equal(
+ "",
+ 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(
+ "",
+ 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(
+ "",
+ 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(
+ "",
+ 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