Permalink
Browse files

Merge remote branch 'rails/master'

  • Loading branch information...
2 parents 56669ec + b456877 commit 919eb200a9a0969c444b938d08eb4661d41ba986 @fxn fxn committed Jul 21, 2010
Showing with 1,275 additions and 1,234 deletions.
  1. +58 −0 README.rdoc
  2. +8 −8 Rakefile
  3. +3 −19 actionmailer/{README → README.rdoc}
  4. +1 −1 actionmailer/Rakefile
  5. +1 −1 actionmailer/actionmailer.gemspec
  6. +0 −30 actionmailer/install.rb
  7. +2 −0 actionpack/CHANGELOG
  8. +4 −22 actionpack/{README → README.rdoc}
  9. +1 −1 actionpack/Rakefile
  10. +1 −1 actionpack/actionpack.gemspec
  11. +0 −30 actionpack/install.rb
  12. +1 −0 actionpack/lib/abstract_controller.rb
  13. +0 −1 actionpack/lib/action_controller.rb
  14. +1 −2 actionpack/lib/action_controller/base.rb
  15. +1 −0 actionpack/lib/action_controller/metal/instrumentation.rb
  16. +9 −0 actionpack/lib/action_controller/metal/rescue.rb
  17. +2 −0 actionpack/lib/action_controller/metal/streaming.rb
  18. +0 −183 actionpack/lib/action_controller/polymorphic_routes.rb
  19. +3 −30 actionpack/lib/action_controller/record_identifier.rb
  20. +6 −0 actionpack/lib/action_dispatch.rb
  21. +10 −66 actionpack/lib/action_dispatch/http/filter_parameters.rb
  22. +72 −0 actionpack/lib/action_dispatch/http/parameter_filter.rb
  23. +7 −4 actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
  24. +0 −1 actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb
  25. +11 −4 actionpack/lib/action_dispatch/middleware/stack.rb
  26. +2 −2 actionpack/lib/action_dispatch/routing.rb
  27. +186 −0 actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
  28. +2 −1 actionpack/lib/action_dispatch/routing/route_set.rb
  29. +1 −0 actionpack/lib/action_dispatch/routing/url_for.rb
  30. +0 −2 actionpack/lib/action_dispatch/testing/assertions.rb
  31. +0 −19 actionpack/lib/action_dispatch/testing/assertions/model.rb
  32. +1 −0 actionpack/lib/action_view.rb
  33. +0 −2 actionpack/lib/action_view/helpers.rb
  34. +2 −1 actionpack/lib/action_view/helpers/date_helper.rb
  35. +5 −5 actionpack/lib/action_view/helpers/form_helper.rb
  36. +3 −3 actionpack/lib/action_view/helpers/form_options_helper.rb
  37. +1 −1 actionpack/lib/action_view/helpers/prototype_helper.rb
  38. +0 −23 actionpack/lib/action_view/helpers/record_identification_helper.rb
  39. +4 −0 actionpack/lib/action_view/helpers/record_tag_helper.rb
  40. +1 −1 actionpack/lib/action_view/helpers/url_helper.rb
  41. +1 −1 actionpack/lib/action_view/test_case.rb
  42. +0 −15 actionpack/test/controller/action_pack_assertions_test.rb
  43. +0 −40 actionpack/test/controller/record_identifier_test.rb
  44. +27 −0 actionpack/test/controller/rescue_test.rb
  45. +7 −0 actionpack/test/controller/test_test.rb
  46. +10 −0 actionpack/test/dispatch/middleware_stack_test.rb
  47. +4 −4 actionpack/test/dispatch/request_test.rb
  48. +19 −1 actionpack/test/dispatch/session/cookie_store_test.rb
  49. +23 −0 actionpack/test/template/form_options_helper_test.rb
  50. +6 −0 actionpack/test/template/prototype_helper_test.rb
  51. +5 −0 activemodel/CHANGELOG
  52. 0 activemodel/{README → README.rdoc}
  53. +1 −1 activemodel/Rakefile
  54. +1 −1 activemodel/activemodel.gemspec
  55. +29 −0 activemodel/lib/active_model/naming.rb
  56. +39 −0 activemodel/test/cases/naming_test.rb
  57. +1 −0 activemodel/test/models/contact.rb
  58. +4 −0 activemodel/test/models/sheep.rb
  59. +2 −0 activerecord/CHANGELOG
  60. +3 −18 activerecord/{README → README.rdoc}
  61. +1 −1 activerecord/Rakefile
  62. +3 −3 activerecord/activerecord.gemspec
  63. +0 −30 activerecord/install.rb
  64. +3 −3 activerecord/lib/active_record/association_preload.rb
  65. +16 −15 activerecord/lib/active_record/associations.rb
  66. +16 −8 activerecord/lib/active_record/associations/association_collection.rb
  67. +21 −7 activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
  68. +7 −4 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
  69. +1 −1 activerecord/lib/active_record/fixtures.rb
  70. +5 −3 activerecord/lib/active_record/log_subscriber.rb
  71. +2 −2 activerecord/lib/active_record/named_scope.rb
  72. +2 −0 activerecord/lib/active_record/persistence.rb
  73. +6 −0 activerecord/lib/active_record/railtie.rb
  74. +1 −1 activerecord/lib/active_record/railties/databases.rake
  75. +3 −6 activerecord/lib/active_record/relation.rb
  76. +0 −1 activerecord/lib/active_record/session_store.rb
  77. +16 −3 activerecord/lib/active_record/timestamp.rb
  78. +1 −0 activerecord/test/cases/adapters/mysql/active_schema_test.rb
  79. +1 −1 activerecord/test/cases/aggregations_test.rb
  80. +1 −1 activerecord/test/cases/ar_schema_test.rb
  81. +0 −2 activerecord/test/cases/associations/belongs_to_associations_test.rb
  82. +0 −2 activerecord/test/cases/associations/callbacks_test.rb
  83. +0 −1 activerecord/test/cases/associations/cascaded_eager_loading_test.rb
  84. +51 −6 activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
  85. +2 −2 activerecord/test/cases/associations/inverse_associations_test.rb
  86. +20 −12 activerecord/test/cases/associations_test.rb
  87. +10 −2 activerecord/test/cases/base_test.rb
  88. +0 −1 activerecord/test/cases/finder_test.rb
  89. +3 −3 activerecord/test/cases/fixtures_test.rb
  90. +18 −0 activerecord/test/cases/log_subscriber_test.rb
  91. +1 −2 activerecord/test/cases/method_scoping_test.rb
  92. +5 −5 activerecord/test/cases/named_scope_test.rb
  93. +66 −3 activerecord/test/cases/nested_attributes_test.rb
  94. +7 −8 activerecord/test/cases/persistence_test.rb
  95. +2 −2 activerecord/test/cases/{pk_test.rb → primary_keys_test.rb}
  96. +0 −2 activerecord/test/cases/query_cache_test.rb
  97. +21 −2 activerecord/test/cases/relation_scoping_test.rb
  98. +0 −1 activerecord/test/cases/relations_test.rb
  99. +0 −1 activerecord/test/cases/transaction_callbacks_test.rb
  100. +0 −1 activerecord/test/cases/validations/i18n_generate_message_validation_test.rb
  101. +0 −5 activerecord/test/cases/validations_test.rb
  102. +0 −1 activerecord/test/cases/xml_serialization_test.rb
  103. +1 −0 activerecord/test/fixtures/minivans.yml
  104. +7 −0 activerecord/test/models/country.rb
  105. +4 −1 activerecord/test/models/minivan.rb
  106. +2 −0 activerecord/test/models/person.rb
  107. +5 −0 activerecord/test/models/reference.rb
  108. +7 −0 activerecord/test/models/treaty.rb
  109. +16 −0 activerecord/test/schema/schema.rb
  110. 0 activeresource/{README → README.rdoc}
  111. +1 −1 activeresource/Rakefile
  112. +3 −3 activeresource/activeresource.gemspec
  113. +3 −12 activesupport/{README → README.rdoc}
  114. +1 −1 activesupport/Rakefile
  115. +1 −1 activesupport/activesupport.gemspec
  116. +0 −30 activesupport/install.rb
  117. +5 −1 activesupport/lib/active_support/buffered_logger.rb
  118. +1 −7 activesupport/lib/active_support/core_ext/module/attribute_accessors.rb
  119. +5 −0 activesupport/lib/active_support/core_ext/module/remove_method.rb
  120. +1 −1 activesupport/lib/active_support/core_ext/object/to_param.rb
  121. +14 −9 activesupport/lib/active_support/log_subscriber.rb
  122. +16 −7 activesupport/lib/active_support/log_subscriber/test_helper.rb
  123. +1 −23 activesupport/lib/active_support/notifications.rb
  124. +16 −53 activesupport/lib/active_support/notifications/fanout.rb
  125. +12 −8 activesupport/lib/active_support/notifications/instrumenter.rb
  126. +15 −0 activesupport/test/buffered_logger_test.rb
  127. +29 −0 activesupport/test/core_ext/hash_ext_test.rb
  128. +4 −1 activesupport/test/multibyte_test_helpers.rb
  129. +14 −18 activesupport/test/notifications_test.rb
  130. +8 −6 railties/CHANGELOG
  131. +0 −281 railties/README
  132. +25 −0 railties/README.rdoc
  133. +1 −8 railties/Rakefile
  134. +22 −0 railties/guides/source/active_support_core_extensions.textile
  135. +42 −15 railties/guides/source/contributing_to_rails.textile
  136. +13 −0 railties/lib/rails/application.rb
  137. +1 −4 railties/lib/rails/commands/console.rb
  138. +2 −3 railties/lib/rails/configuration.rb
  139. +0 −7 railties/lib/rails/generators/rails/app/templates/config/application.rb
  140. +10 −8 railties/lib/rails/railtie.rb
  141. +8 −8 railties/lib/rails/tasks/documentation.rake
  142. +1 −1 railties/railties.gemspec
  143. +18 −3 railties/test/application/console_test.rb
  144. +15 −0 railties/test/application/generators_test.rb
  145. +5 −14 railties/test/application/initializers/notifications_test.rb
  146. +16 −0 railties/test/railties/railtie_test.rb
View
58 README.rdoc
@@ -0,0 +1,58 @@
+== Welcome to Rails
+
+Rails is a web-application framework that includes everything needed to create
+database-backed web applications according to the Model-View-Control pattern.
+
+This pattern splits the view (also called the presentation) into "dumb"
+templates that are primarily responsible for inserting pre-built data in between
+HTML tags. The model contains the "smart" domain objects (such as Account,
+Product, Person, Post) that holds all the business logic and knows how to
+persist themselves to a database. The controller handles the incoming requests
+(such as Save New Account, Update Product, Show Post) by manipulating the model
+and directing data to the view.
+
+In Rails, the model is handled by what's called an object-relational mapping
+layer entitled Active Record. This layer allows you to present the data from
+database rows as objects and embellish these data objects with business logic
+methods. You can read more about Active Record in
+link:files/vendor/rails/activerecord/README.html.
+
+The controller and view are handled by the Action Pack, which handles both
+layers by its two parts: Action View and Action Controller. These two layers
+are bundled in a single package due to their heavy interdependence. This is
+unlike the relationship between the Active Record and Action Pack that is much
+more separate. Each of these packages can be used independently outside of
+Rails. You can read more about Action Pack in
+link:files/vendor/rails/actionpack/README.html.
+
+
+== Getting Started
+
+1. Install Rails at the command prompt if you haven't yet:
+ <tt>gem install rails</tt>
+
+2. At the command prompt, create a new Rails application:
+ <tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
+
+3. Change directory to <tt>myapp</tt> and start the web server:
+ <tt>cd myapp; rails server</tt> (run with --help for options)
+
+4. Go to http://localhost:3000/ and you'll see:
+ "Welcome aboard: You're riding Ruby on Rails!"
+
+5. Follow the guidelines to start developing your application. You can find
+the following resources handy:
+
+* The README file created within your application
+* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
+* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
+
+
+== Contributing
+
+Check out the contributing guide at http://edgeguides.rubyonrails.org/contributing_to_rails.html
+
+
+== License
+
+Ruby on Rails is released under the MIT license.
View
16 Rakefile
@@ -69,7 +69,7 @@ Rake::RDocTask.new do |rdoc|
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.options << '-A cattr_accessor=object'
rdoc.options << '--charset' << 'utf-8'
- rdoc.options << '--main' << 'railties/README'
+ rdoc.options << '--main' << 'README.rdoc'
# Workaround: RDoc assumes that rdoc.template can be required, and that
# rdoc.template.upcase is a constant living in RDoc::Generator::HTML
@@ -83,38 +83,38 @@ Rake::RDocTask.new do |rdoc|
rdoc.rdoc_files.include('railties/CHANGELOG')
rdoc.rdoc_files.include('railties/MIT-LICENSE')
- rdoc.rdoc_files.include('railties/README')
+ rdoc.rdoc_files.include('railties/README.rdoc')
rdoc.rdoc_files.include('railties/lib/**/*.rb')
rdoc.rdoc_files.exclude('railties/lib/rails/generators/**/templates/*')
- rdoc.rdoc_files.include('activerecord/README')
+ rdoc.rdoc_files.include('activerecord/README.rdoc')
rdoc.rdoc_files.include('activerecord/CHANGELOG')
rdoc.rdoc_files.include('activerecord/lib/active_record/**/*.rb')
rdoc.rdoc_files.exclude('activerecord/lib/active_record/vendor/*')
- rdoc.rdoc_files.include('activeresource/README')
+ rdoc.rdoc_files.include('activeresource/README.rdoc')
rdoc.rdoc_files.include('activeresource/CHANGELOG')
rdoc.rdoc_files.include('activeresource/lib/active_resource.rb')
rdoc.rdoc_files.include('activeresource/lib/active_resource/*')
- rdoc.rdoc_files.include('actionpack/README')
+ rdoc.rdoc_files.include('actionpack/README.rdoc')
rdoc.rdoc_files.include('actionpack/CHANGELOG')
rdoc.rdoc_files.include('actionpack/lib/action_controller/**/*.rb')
rdoc.rdoc_files.include('actionpack/lib/action_dispatch/**/*.rb')
rdoc.rdoc_files.include('actionpack/lib/action_view/**/*.rb')
rdoc.rdoc_files.exclude('actionpack/lib/action_controller/vendor/*')
- rdoc.rdoc_files.include('actionmailer/README')
+ rdoc.rdoc_files.include('actionmailer/README.rdoc')
rdoc.rdoc_files.include('actionmailer/CHANGELOG')
rdoc.rdoc_files.include('actionmailer/lib/action_mailer/base.rb')
rdoc.rdoc_files.exclude('actionmailer/lib/action_mailer/vendor/*')
- rdoc.rdoc_files.include('activesupport/README')
+ rdoc.rdoc_files.include('activesupport/README.rdoc')
rdoc.rdoc_files.include('activesupport/CHANGELOG')
rdoc.rdoc_files.include('activesupport/lib/active_support/**/*.rb')
rdoc.rdoc_files.exclude('activesupport/lib/active_support/vendor/*')
- rdoc.rdoc_files.include('activemodel/README')
+ rdoc.rdoc_files.include('activemodel/README.rdoc')
rdoc.rdoc_files.include('activemodel/CHANGELOG')
rdoc.rdoc_files.include('activemodel/lib/active_model/**/*.rb')
end
View
22 actionmailer/README → actionmailer/README.rdoc
@@ -126,36 +126,20 @@ or is accessible as a GEM.
Additionally, Action Mailer requires the Mail gem, http://github.com/mikel/mail
-== Bundled software
-
-* Text::Format 0.63 by Austin Ziegler released under OpenSource
- Read more on http://www.halostatue.ca/ruby/Text__Format.html
-
== Download
-The latest version of Action Mailer can be found at
+The latest version of Action Mailer can be installed with Rubygems:
-* http://rubyforge.org/project/showfiles.php?group_id=361
+* gem install actionmailer
Documentation can be found at
-* http://actionmailer.rubyonrails.org
-
-
-== Installation
-
-You can install Action Mailer with the following command.
-
- % [sudo] ruby install.rb
-
-from its distribution directory.
-
+* http://api.rubyonrails.org
== License
Action Mailer is released under the MIT license.
-
== Support
The Action Mailer homepage is http://www.rubyonrails.org. You can find
View
2 actionmailer/Rakefile
@@ -32,7 +32,7 @@ Rake::RDocTask.new { |rdoc|
rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
rdoc.options << '--charset' << 'utf-8'
rdoc.template = ENV['template'] ? "#{ENV['template']}.rb" : '../doc/template/horo'
- rdoc.rdoc_files.include('README', 'CHANGELOG')
+ rdoc.rdoc_files.include('README.rdoc', 'CHANGELOG')
rdoc.rdoc_files.include('lib/action_mailer.rb')
rdoc.rdoc_files.include('lib/action_mailer/*.rb')
rdoc.rdoc_files.include('lib/action_mailer/delivery_method/*.rb')
View
2 actionmailer/actionmailer.gemspec
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
s.homepage = 'http://www.rubyonrails.org'
s.rubyforge_project = 'actionmailer'
- s.files = Dir['CHANGELOG', 'README', 'MIT-LICENSE', 'lib/**/*']
+ s.files = Dir['CHANGELOG', 'README.rdoc', 'MIT-LICENSE', 'lib/**/*']
s.require_path = 'lib'
s.requirements << 'none'
View
30 actionmailer/install.rb
@@ -1,30 +0,0 @@
-require 'rbconfig'
-require 'find'
-require 'ftools'
-
-include Config
-
-# this was adapted from rdoc's install.rb by way of Log4r
-
-$sitedir = CONFIG["sitelibdir"]
-unless $sitedir
- version = CONFIG["MAJOR"] + "." + CONFIG["MINOR"]
- $libdir = File.join(CONFIG["libdir"], "ruby", version)
- $sitedir = $:.find {|x| x =~ /site_ruby/ }
- if !$sitedir
- $sitedir = File.join($libdir, "site_ruby")
- elsif $sitedir !~ Regexp.quote(version)
- $sitedir = File.join($sitedir, version)
- end
-end
-
-# the actual gruntwork
-Dir.chdir("lib")
-
-Find.find("action_mailer", "action_mailer.rb") { |f|
- if f[-3..-1] == ".rb"
- File::install(f, File.join($sitedir, *f.split(/\//)), 0644, true)
- else
- File::makedirs(File.join($sitedir, *f.split(/\//)))
- end
-}
View
2 actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*Rails 3.0.0 [Release Candidate] (unreleased)*
+* Allow stylesheet/javascript extensions to be changed through railties. [Josh Kalderimis]
+
* link_to, button_to, and tag/tag_options now rely on html_escape instead of escape_once. [fxn]
* url_for returns always unescaped strings, and the :escape option is gone. [fxn]
View
26 actionpack/README → actionpack/README.rdoc
@@ -19,15 +19,6 @@ the HTML. To avoid cluttering the templates with code, a bunch of helper
classes provide common behavior for forms, dates, and strings. And it's easy
to add specific helpers to keep the separation as the application evolves.
-Note: Some of the features, such as scaffolding and form building, are tied to
-ActiveRecord[http://activerecord.rubyonrails.org] (an object-relational
-mapping package), but that doesn't mean that Action Pack depends on Active
-Record. Action Pack is an independent package that can be used with any sort
-of backend (Instiki[http://www.instiki.org], which is based on an older version
-of Action Pack, used Madeleine for example). Read more about the role Action
-Pack can play when used together with Active Record on
-http://www.rubyonrails.org.
-
A short rundown of the major features:
* Actions grouped in controller as methods instead of separate command objects
@@ -366,22 +357,13 @@ an URL such as /weblog/5 (where 5 is the id of the post).
== Download
-The latest version of Action Pack can be found at
-
-* http://rubyforge.org/project/showfiles.php?group_id=249
-
-Documentation can be found at
-
-* http://api.rubyonrails.com
-
-
-== Installation
+The latest version of Action Pack can be installed with Rubygems:
-You can install Action Pack with the following command.
+* gem install actionpack
- % [sudo] ruby install.rb
+Documentation can be found at
-from its distribution directory.
+* http://api.rubyonrails.org
== License
View
2 actionpack/Rakefile
@@ -47,7 +47,7 @@ Rake::RDocTask.new { |rdoc|
if ENV['DOC_FILES']
rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
else
- rdoc.rdoc_files.include('README', 'RUNNING_UNIT_TESTS', 'CHANGELOG')
+ rdoc.rdoc_files.include('README.rdoc', 'RUNNING_UNIT_TESTS', 'CHANGELOG')
rdoc.rdoc_files.include(Dir['lib/**/*.rb'] -
Dir['lib/*/vendor/**/*.rb'])
rdoc.rdoc_files.exclude('lib/actionpack.rb')
View
2 actionpack/actionpack.gemspec
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
s.homepage = 'http://www.rubyonrails.org'
s.rubyforge_project = 'actionpack'
- s.files = Dir['CHANGELOG', 'README', 'MIT-LICENSE', 'lib/**/*']
+ s.files = Dir['CHANGELOG', 'README.rdoc', 'MIT-LICENSE', 'lib/**/*']
s.require_path = 'lib'
s.requirements << 'none'
View
30 actionpack/install.rb
@@ -1,30 +0,0 @@
-require 'rbconfig'
-require 'find'
-require 'ftools'
-
-include Config
-
-# this was adapted from rdoc's install.rb by way of Log4r
-
-$sitedir = CONFIG["sitelibdir"]
-unless $sitedir
- version = CONFIG["MAJOR"] + "." + CONFIG["MINOR"]
- $libdir = File.join(CONFIG["libdir"], "ruby", version)
- $sitedir = $:.find {|x| x =~ /site_ruby/ }
- if !$sitedir
- $sitedir = File.join($libdir, "site_ruby")
- elsif $sitedir !~ Regexp.quote(version)
- $sitedir = File.join($sitedir, version)
- end
-end
-
-# the actual gruntwork
-Dir.chdir("lib")
-
-Find.find("action_controller", "action_controller.rb", "action_view", "action_view.rb") { |f|
- if f[-3..-1] == ".rb"
- File::install(f, File.join($sitedir, *f.split(/\//)), 0644, true)
- else
- File::makedirs(File.join($sitedir, *f.split(/\//)))
- end
-}
View
1 actionpack/lib/abstract_controller.rb
@@ -1,6 +1,7 @@
activesupport_path = File.expand_path('../../../activesupport/lib', __FILE__)
$:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)
+require 'action_pack'
require 'active_support/ruby/shim'
require 'active_support/dependencies/autoload'
require 'active_support/core_ext/class/attribute'
View
1 actionpack/lib/action_controller.rb
@@ -6,7 +6,6 @@ module ActionController
autoload :Base
autoload :Caching
- autoload :PolymorphicRoutes
autoload :Metal
autoload :Middleware
View
3 actionpack/lib/action_controller/base.rb
@@ -28,7 +28,6 @@ def self.without_modules(*modules)
SessionManagement,
Caching,
MimeResponds,
- PolymorphicRoutes,
ImplicitRender,
Cookies,
@@ -69,4 +68,4 @@ def self.inherited(klass)
end
end
-require "action_controller/deprecated/base"
+require "action_controller/deprecated/base"
View
1 actionpack/lib/action_controller/metal/instrumentation.rb
@@ -1,3 +1,4 @@
+require 'benchmark'
require 'abstract_controller/logger'
module ActionController
View
9 actionpack/lib/action_controller/metal/rescue.rb
@@ -3,6 +3,15 @@ module Rescue
extend ActiveSupport::Concern
include ActiveSupport::Rescuable
+ def rescue_with_handler(exception)
+ if (exception.respond_to?(:original_exception) &&
+ (orig_exception = exception.original_exception) &&
+ handler_for_rescue(orig_exception))
+ exception = orig_exception
+ end
+ super(exception)
+ end
+
private
def process_action(*args)
super
View
2 actionpack/lib/action_controller/metal/streaming.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/file/path'
+
module ActionController #:nodoc:
# Methods for sending arbitrary data and for streaming files to the browser,
# instead of rendering.
View
183 actionpack/lib/action_controller/polymorphic_routes.rb
@@ -1,183 +0,0 @@
-module ActionController
- # Polymorphic URL helpers are methods for smart resolution to a named route call when
- # given an Active Record model instance. They are to be used in combination with
- # ActionController::Resources.
- #
- # These methods are useful when you want to generate correct URL or path to a RESTful
- # resource without having to know the exact type of the record in question.
- #
- # Nested resources and/or namespaces are also supported, as illustrated in the example:
- #
- # polymorphic_url([:admin, @article, @comment])
- #
- # results in:
- #
- # admin_article_comment_url(@article, @comment)
- #
- # == Usage within the framework
- #
- # Polymorphic URL helpers are used in a number of places throughout the Rails framework:
- #
- # * <tt>url_for</tt>, so you can use it with a record as the argument, e.g.
- # <tt>url_for(@article)</tt>;
- # * ActionView::Helpers::FormHelper uses <tt>polymorphic_path</tt>, so you can write
- # <tt>form_for(@article)</tt> without having to specify <tt>:url</tt> parameter for the form
- # action;
- # * <tt>redirect_to</tt> (which, in fact, uses <tt>url_for</tt>) so you can write
- # <tt>redirect_to(post)</tt> in your controllers;
- # * ActionView::Helpers::AtomFeedHelper, so you don't have to explicitly specify URLs
- # for feed entries.
- #
- # == Prefixed polymorphic helpers
- #
- # In addition to <tt>polymorphic_url</tt> and <tt>polymorphic_path</tt> methods, a
- # number of prefixed helpers are available as a shorthand to <tt>:action => "..."</tt>
- # in options. Those are:
- #
- # * <tt>edit_polymorphic_url</tt>, <tt>edit_polymorphic_path</tt>
- # * <tt>new_polymorphic_url</tt>, <tt>new_polymorphic_path</tt>
- #
- # Example usage:
- #
- # edit_polymorphic_path(@post) # => "/posts/1/edit"
- # polymorphic_path(@post, :format => :pdf) # => "/posts/1.pdf"
- module PolymorphicRoutes
- # Constructs a call to a named RESTful route for the given record and returns the
- # resulting URL string. For example:
- #
- # # calls post_url(post)
- # polymorphic_url(post) # => "http://example.com/posts/1"
- # polymorphic_url([blog, post]) # => "http://example.com/blogs/1/posts/1"
- # polymorphic_url([:admin, blog, post]) # => "http://example.com/admin/blogs/1/posts/1"
- # polymorphic_url([user, :blog, post]) # => "http://example.com/users/1/blog/posts/1"
- # polymorphic_url(Comment) # => "http://example.com/comments"
- #
- # ==== Options
- #
- # * <tt>:action</tt> - Specifies the action prefix for the named route:
- # <tt>:new</tt> or <tt>:edit</tt>. Default is no prefix.
- # * <tt>:routing_type</tt> - Allowed values are <tt>:path</tt> or <tt>:url</tt>.
- # Default is <tt>:url</tt>.
- #
- # ==== Examples
- #
- # # an Article record
- # polymorphic_url(record) # same as article_url(record)
- #
- # # a Comment record
- # polymorphic_url(record) # same as comment_url(record)
- #
- # # it recognizes new records and maps to the collection
- # record = Comment.new
- # polymorphic_url(record) # same as comments_url()
- #
- # # the class of a record will also map to the collection
- # polymorphic_url(Comment) # same as comments_url()
- #
- def polymorphic_url(record_or_hash_or_array, options = {})
- if record_or_hash_or_array.kind_of?(Array)
- record_or_hash_or_array = record_or_hash_or_array.compact
- record_or_hash_or_array = record_or_hash_or_array[0] if record_or_hash_or_array.size == 1
- end
-
- record = extract_record(record_or_hash_or_array)
- record = record.to_model if record.respond_to?(:to_model)
-
- args = case record_or_hash_or_array
- when Hash; [ record_or_hash_or_array ]
- when Array; record_or_hash_or_array.dup
- else [ record_or_hash_or_array ]
- end
-
- inflection = if options[:action].to_s == "new"
- args.pop
- :singular
- elsif (record.respond_to?(:persisted?) && !record.persisted?)
- args.pop
- :plural
- elsif record.is_a?(Class)
- args.pop
- :plural
- else
- :singular
- end
-
- args.delete_if {|arg| arg.is_a?(Symbol) || arg.is_a?(String)}
- named_route = build_named_route_call(record_or_hash_or_array, inflection, options)
-
- url_options = options.except(:action, :routing_type)
- unless url_options.empty?
- args.last.kind_of?(Hash) ? args.last.merge!(url_options) : args << url_options
- end
-
- __send__(named_route, *args)
- end
-
- # Returns the path component of a URL for the given record. It uses
- # <tt>polymorphic_url</tt> with <tt>:routing_type => :path</tt>.
- def polymorphic_path(record_or_hash_or_array, options = {})
- polymorphic_url(record_or_hash_or_array, options.merge(:routing_type => :path))
- end
-
- %w(edit new).each do |action|
- module_eval <<-EOT, __FILE__, __LINE__ + 1
- def #{action}_polymorphic_url(record_or_hash, options = {}) # def edit_polymorphic_url(record_or_hash, options = {})
- polymorphic_url( # polymorphic_url(
- record_or_hash, # record_or_hash,
- options.merge(:action => "#{action}")) # options.merge(:action => "edit"))
- end # end
- #
- def #{action}_polymorphic_path(record_or_hash, options = {}) # def edit_polymorphic_path(record_or_hash, options = {})
- polymorphic_url( # polymorphic_url(
- record_or_hash, # record_or_hash,
- options.merge(:action => "#{action}", :routing_type => :path)) # options.merge(:action => "edit", :routing_type => :path))
- end # end
- EOT
- end
-
- private
- def action_prefix(options)
- options[:action] ? "#{options[:action]}_" : ''
- end
-
- def routing_type(options)
- options[:routing_type] || :url
- end
-
- def build_named_route_call(records, inflection, options = {})
- unless records.is_a?(Array)
- record = extract_record(records)
- route = ''
- else
- record = records.pop
- route = records.inject("") do |string, parent|
- if parent.is_a?(Symbol) || parent.is_a?(String)
- string << "#{parent}_"
- else
- string << RecordIdentifier.__send__("plural_class_name", parent).singularize
- string << "_"
- end
- end
- end
-
- if record.is_a?(Symbol) || record.is_a?(String)
- route << "#{record}_"
- else
- route << RecordIdentifier.__send__("plural_class_name", record)
- route = route.singularize if inflection == :singular
- route << "_"
- route << "index_" if RecordIdentifier.uncountable?(record) && inflection == :plural
- end
-
- action_prefix(options) + route + routing_type(options).to_s
- end
-
- def extract_record(record_or_hash_or_array)
- case record_or_hash_or_array
- when Array; record_or_hash_or_array.last
- when Hash; record_or_hash_or_array[:id]
- else record_or_hash_or_array
- end
- end
- end
-end
View
33 actionpack/lib/action_controller/record_identifier.rb
@@ -46,7 +46,7 @@ module RecordIdentifier
# dom_class(post, :edit) # => "edit_post"
# dom_class(Person, :edit) # => "edit_person"
def dom_class(record_or_class, prefix = nil)
- singular = singular_class_name(record_or_class)
+ singular = ActiveModel::Naming.singular(record_or_class)
prefix ? "#{prefix}#{JOIN}#{singular}" : singular
end
@@ -67,6 +67,8 @@ def dom_id(record, prefix = nil)
end
end
+ protected
+
# Returns a string representation of the key attribute(s) that is suitable for use in an HTML DOM id.
# This can be overwritten to customize the default generated string representation if desired.
# If you need to read back a key from a dom_id in order to query for the underlying database record,
@@ -85,34 +87,5 @@ def record_key_for_dom_id(record)
def sanitize_dom_id(candidate_id)
candidate_id # TODO implement conversion to valid DOM id values
end
-
- # Returns the plural class name of a record or class. Examples:
- #
- # plural_class_name(post) # => "posts"
- # plural_class_name(Highrise::Person) # => "highrise_people"
- def plural_class_name(record_or_class)
- model_name_from_record_or_class(record_or_class).plural
- end
-
- # Returns the singular class name of a record or class. Examples:
- #
- # singular_class_name(post) # => "post"
- # singular_class_name(Highrise::Person) # => "highrise_person"
- def singular_class_name(record_or_class)
- model_name_from_record_or_class(record_or_class).singular
- end
-
- # Identifies whether the class name of a record or class is uncountable. Examples:
- #
- # uncountable?(Sheep) # => true
- # uncountable?(Post) => false
- def uncountable?(record_or_class)
- plural_class_name(record_or_class) == singular_class_name(record_or_class)
- end
-
- private
- def model_name_from_record_or_class(record_or_class)
- (record_or_class.is_a?(Class) ? record_or_class : record_or_class.class).model_name
- end
end
end
View
6 actionpack/lib/action_dispatch.rb
@@ -24,9 +24,14 @@
activesupport_path = File.expand_path('../../../activesupport/lib', __FILE__)
$:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)
+activemodel_path = File.expand_path('../../../activemodel/lib', __FILE__)
+$:.unshift(activemodel_path) if File.directory?(activemodel_path) && !$:.include?(activemodel_path)
+
require 'active_support'
require 'active_support/dependencies/autoload'
+require 'action_pack'
+require 'active_model'
require 'rack'
module Rack
@@ -63,6 +68,7 @@ module Http
autoload :Headers
autoload :MimeNegotiation
autoload :Parameters
+ autoload :ParameterFilter
autoload :FilterParameters
autoload :Upload
autoload :UploadedFile, 'action_dispatch/http/upload'
View
76 actionpack/lib/action_dispatch/http/filter_parameters.rb
@@ -26,88 +26,32 @@ module Http
module FilterParameters
extend ActiveSupport::Concern
- @@compiled_parameter_filter_for = {}
+ @@parameter_filter_for = {}
# Return a hash of parameters with all sensitive data replaced.
def filtered_parameters
- @filtered_parameters ||= if filtering_parameters?
- process_parameter_filter(parameters)
- else
- parameters.dup
- end
+ @filtered_parameters ||= parameter_filter.filter(parameters)
end
- alias :fitered_params :filtered_parameters
# Return a hash of request.env with all sensitive data replaced.
def filtered_env
- filtered_env = @env.dup
- filtered_env.each do |key, value|
- if (key =~ /RAW_POST_DATA/i)
- filtered_env[key] = '[FILTERED]'
- elsif value.is_a?(Hash)
- filtered_env[key] = process_parameter_filter(value)
- end
- end
- filtered_env
+ @filtered_env ||= env_filter.filter(@env)
end
protected
- def filtering_parameters? #:nodoc:
- @env["action_dispatch.parameter_filter"].present?
+ def parameter_filter
+ parameter_filter_for(@env["action_dispatch.parameter_filter"])
end
- def process_parameter_filter(params) #:nodoc:
- compiled_parameter_filter_for(@env["action_dispatch.parameter_filter"]).call(params)
+ def env_filter
+ parameter_filter_for(Array.wrap(@env["action_dispatch.parameter_filter"]) << /RAW_POST_DATA/)
end
- def compile_parameter_filter(filters) #:nodoc:
- strings, regexps, blocks = [], [], []
-
- filters.each do |item|
- case item
- when NilClass
- when Proc
- blocks << item
- when Regexp
- regexps << item
- else
- strings << item.to_s
- end
- end
-
- regexps << Regexp.new(strings.join('|'), true) unless strings.empty?
- [regexps, blocks]
- end
-
- def compiled_parameter_filter_for(filters) #:nodoc:
- @@compiled_parameter_filter_for[filters] ||= begin
- regexps, blocks = compile_parameter_filter(filters)
-
- lambda do |original_params|
- filtered_params = {}
-
- original_params.each do |key, value|
- if regexps.find { |r| key =~ r }
- value = '[FILTERED]'
- elsif value.is_a?(Hash)
- value = process_parameter_filter(value)
- elsif value.is_a?(Array)
- value = value.map { |v| v.is_a?(Hash) ? process_parameter_filter(v) : v }
- elsif blocks.present?
- key = key.dup
- value = value.dup if value.duplicable?
- blocks.each { |b| b.call(key, value) }
- end
-
- filtered_params[key] = value
- end
-
- filtered_params
- end
- end
+ def parameter_filter_for(filters)
+ @@parameter_filter_for[filters] ||= ParameterFilter.new(filters)
end
end
end
-end
+end
View
72 actionpack/lib/action_dispatch/http/parameter_filter.rb
@@ -0,0 +1,72 @@
+module ActionDispatch
+ module Http
+ class ParameterFilter
+
+ def initialize(filters)
+ @filters = filters
+ end
+
+ def filter(params)
+ if enabled?
+ compiled_filter.call(params)
+ else
+ params.dup
+ end
+ end
+
+ private
+
+ def enabled?
+ @filters.present?
+ end
+
+ def compiled_filter
+ @compiled_filter ||= begin
+ regexps, blocks = compile_filter
+
+ lambda do |original_params|
+ filtered_params = {}
+
+ original_params.each do |key, value|
+ if regexps.find { |r| key =~ r }
+ value = '[FILTERED]'
+ elsif value.is_a?(Hash)
+ value = filter(value)
+ elsif value.is_a?(Array)
+ value = value.map { |v| v.is_a?(Hash) ? filter(v) : v }
+ elsif blocks.present?
+ key = key.dup
+ value = value.dup if value.duplicable?
+ blocks.each { |b| b.call(key, value) }
+ end
+
+ filtered_params[key] = value
+ end
+
+ filtered_params
+ end
+ end
+ end
+
+ def compile_filter
+ strings, regexps, blocks = [], [], []
+
+ @filters.each do |item|
+ case item
+ when NilClass
+ when Proc
+ blocks << item
+ when Regexp
+ regexps << item
+ else
+ strings << item.to_s
+ end
+ end
+
+ regexps << Regexp.new(strings.join('|'), true) unless strings.empty?
+ [regexps, blocks]
+ end
+
+ end
+ end
+end
View
11 actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
@@ -24,9 +24,9 @@ def initialize(by, env, default_options)
def [](key)
if key == :id
- load_session_id! unless super(:id) || has_session_id?
+ load_session_id! unless key?(:id) || has_session_id?
end
- super(key)
+ super
end
private
@@ -191,8 +191,11 @@ def set_cookie(request, options)
def load_session(env)
stale_session_check! do
- sid = current_session_id(env)
- sid, session = get_session(env, sid)
+ if sid = current_session_id(env)
+ sid, session = get_session(env, sid)
+ else
+ sid, session = generate_sid, {}
+ end
[sid, session]
end
end
View
1 actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb
@@ -25,7 +25,6 @@ def initialize(app, options = {})
private
def get_session(env, sid)
- sid ||= generate_sid
begin
session = @pool.get(sid) || {}
rescue MemCache::MemCacheError, Errno::ECONNREFUSED
View
15 actionpack/lib/action_dispatch/middleware/stack.rb
@@ -46,17 +46,16 @@ def initialize(*args, &block)
end
def insert(index, *args, &block)
- index = self.index(index) unless index.is_a?(Integer)
+ index = assert_index(index, :before)
middleware = self.class::Middleware.new(*args, &block)
super(index, middleware)
end
alias_method :insert_before, :insert
def insert_after(index, *args, &block)
- i = index.is_a?(Integer) ? index : self.index(index)
- raise "No such middleware to insert after: #{index.inspect}" unless i
- insert(i + 1, *args, &block)
+ index = assert_index(index, :after)
+ insert(index + 1, *args, &block)
end
def swap(target, *args, &block)
@@ -79,5 +78,13 @@ def build(app = nil, &block)
raise "MiddlewareStack#build requires an app" unless app
reverse.inject(app) { |a, e| e.build(a) }
end
+
+ protected
+
+ def assert_index(index, where)
+ i = index.is_a?(Integer) ? index : self.index(index)
+ raise "No such middleware to insert #{where}: #{index.inspect}" unless i
+ i
+ end
end
end
View
4 actionpack/lib/action_dispatch/routing.rb
@@ -1,6 +1,5 @@
require 'active_support/core_ext/object/to_param'
require 'active_support/core_ext/regexp'
-require 'action_controller/polymorphic_routes'
module ActionDispatch
# = Routing
@@ -217,13 +216,14 @@ module Routing
autoload :Route, 'action_dispatch/routing/route'
autoload :RouteSet, 'action_dispatch/routing/route_set'
autoload :UrlFor, 'action_dispatch/routing/url_for'
+ autoload :PolymorphicRoutes, 'action_dispatch/routing/polymorphic_routes'
SEPARATORS = %w( / . ? ) #:nodoc:
HTTP_METHODS = [:get, :head, :post, :put, :delete, :options] #:nodoc:
# A helper module to hold URL related helpers.
module Helpers #:nodoc:
- include ActionController::PolymorphicRoutes
+ include PolymorphicRoutes
end
end
end
View
186 actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
@@ -0,0 +1,186 @@
+module ActionDispatch
+ module Routing
+ # Polymorphic URL helpers are methods for smart resolution to a named route call when
+ # given an Active Record model instance. They are to be used in combination with
+ # ActionController::Resources.
+ #
+ # These methods are useful when you want to generate correct URL or path to a RESTful
+ # resource without having to know the exact type of the record in question.
+ #
+ # Nested resources and/or namespaces are also supported, as illustrated in the example:
+ #
+ # polymorphic_url([:admin, @article, @comment])
+ #
+ # results in:
+ #
+ # admin_article_comment_url(@article, @comment)
+ #
+ # == Usage within the framework
+ #
+ # Polymorphic URL helpers are used in a number of places throughout the Rails framework:
+ #
+ # * <tt>url_for</tt>, so you can use it with a record as the argument, e.g.
+ # <tt>url_for(@article)</tt>;
+ # * ActionView::Helpers::FormHelper uses <tt>polymorphic_path</tt>, so you can write
+ # <tt>form_for(@article)</tt> without having to specify <tt>:url</tt> parameter for the form
+ # action;
+ # * <tt>redirect_to</tt> (which, in fact, uses <tt>url_for</tt>) so you can write
+ # <tt>redirect_to(post)</tt> in your controllers;
+ # * ActionView::Helpers::AtomFeedHelper, so you don't have to explicitly specify URLs
+ # for feed entries.
+ #
+ # == Prefixed polymorphic helpers
+ #
+ # In addition to <tt>polymorphic_url</tt> and <tt>polymorphic_path</tt> methods, a
+ # number of prefixed helpers are available as a shorthand to <tt>:action => "..."</tt>
+ # in options. Those are:
+ #
+ # * <tt>edit_polymorphic_url</tt>, <tt>edit_polymorphic_path</tt>
+ # * <tt>new_polymorphic_url</tt>, <tt>new_polymorphic_path</tt>
+ #
+ # Example usage:
+ #
+ # edit_polymorphic_path(@post) # => "/posts/1/edit"
+ # polymorphic_path(@post, :format => :pdf) # => "/posts/1.pdf"
+ module PolymorphicRoutes
+ # Constructs a call to a named RESTful route for the given record and returns the
+ # resulting URL string. For example:
+ #
+ # # calls post_url(post)
+ # polymorphic_url(post) # => "http://example.com/posts/1"
+ # polymorphic_url([blog, post]) # => "http://example.com/blogs/1/posts/1"
+ # polymorphic_url([:admin, blog, post]) # => "http://example.com/admin/blogs/1/posts/1"
+ # polymorphic_url([user, :blog, post]) # => "http://example.com/users/1/blog/posts/1"
+ # polymorphic_url(Comment) # => "http://example.com/comments"
+ #
+ # ==== Options
+ #
+ # * <tt>:action</tt> - Specifies the action prefix for the named route:
+ # <tt>:new</tt> or <tt>:edit</tt>. Default is no prefix.
+ # * <tt>:routing_type</tt> - Allowed values are <tt>:path</tt> or <tt>:url</tt>.
+ # Default is <tt>:url</tt>.
+ #
+ # ==== Examples
+ #
+ # # an Article record
+ # polymorphic_url(record) # same as article_url(record)
+ #
+ # # a Comment record
+ # polymorphic_url(record) # same as comment_url(record)
+ #
+ # # it recognizes new records and maps to the collection
+ # record = Comment.new
+ # polymorphic_url(record) # same as comments_url()
+ #
+ # # the class of a record will also map to the collection
+ # polymorphic_url(Comment) # same as comments_url()
+ #
+ def polymorphic_url(record_or_hash_or_array, options = {})
+ if record_or_hash_or_array.kind_of?(Array)
+ record_or_hash_or_array = record_or_hash_or_array.compact
+ record_or_hash_or_array = record_or_hash_or_array[0] if record_or_hash_or_array.size == 1
+ end
+
+ record = extract_record(record_or_hash_or_array)
+ record = record.to_model if record.respond_to?(:to_model)
+
+ args = case record_or_hash_or_array
+ when Hash; [ record_or_hash_or_array ]
+ when Array; record_or_hash_or_array.dup
+ else [ record_or_hash_or_array ]
+ end
+
+ inflection = if options[:action].to_s == "new"
+ args.pop
+ :singular
+ elsif (record.respond_to?(:persisted?) && !record.persisted?)
+ args.pop
+ :plural
+ elsif record.is_a?(Class)
+ args.pop
+ :plural
+ else
+ :singular
+ end
+
+ args.delete_if {|arg| arg.is_a?(Symbol) || arg.is_a?(String)}
+ named_route = build_named_route_call(record_or_hash_or_array, inflection, options)
+
+ url_options = options.except(:action, :routing_type)
+ unless url_options.empty?
+ args.last.kind_of?(Hash) ? args.last.merge!(url_options) : args << url_options
+ end
+
+ send(named_route, *args)
+ end
+
+ # Returns the path component of a URL for the given record. It uses
+ # <tt>polymorphic_url</tt> with <tt>:routing_type => :path</tt>.
+ def polymorphic_path(record_or_hash_or_array, options = {})
+ polymorphic_url(record_or_hash_or_array, options.merge(:routing_type => :path))
+ end
+
+ %w(edit new).each do |action|
+ module_eval <<-EOT, __FILE__, __LINE__ + 1
+ def #{action}_polymorphic_url(record_or_hash, options = {}) # def edit_polymorphic_url(record_or_hash, options = {})
+ polymorphic_url( # polymorphic_url(
+ record_or_hash, # record_or_hash,
+ options.merge(:action => "#{action}")) # options.merge(:action => "edit"))
+ end # end
+ #
+ def #{action}_polymorphic_path(record_or_hash, options = {}) # def edit_polymorphic_path(record_or_hash, options = {})
+ polymorphic_url( # polymorphic_url(
+ record_or_hash, # record_or_hash,
+ options.merge(:action => "#{action}", :routing_type => :path)) # options.merge(:action => "edit", :routing_type => :path))
+ end # end
+ EOT
+ end
+
+ private
+ def action_prefix(options)
+ options[:action] ? "#{options[:action]}_" : ''
+ end
+
+ def routing_type(options)
+ options[:routing_type] || :url
+ end
+
+ def build_named_route_call(records, inflection, options = {})
+ unless records.is_a?(Array)
+ record = extract_record(records)
+ route = ''
+ else
+ record = records.pop
+ route = records.inject("") do |string, parent|
+ if parent.is_a?(Symbol) || parent.is_a?(String)
+ string << "#{parent}_"
+ else
+ string << ActiveModel::Naming.plural(parent).singularize
+ string << "_"
+ end
+ end
+ end
+
+ if record.is_a?(Symbol) || record.is_a?(String)
+ route << "#{record}_"
+ else
+ route << ActiveModel::Naming.plural(record)
+ route = route.singularize if inflection == :singular
+ route << "_"
+ route << "index_" if ActiveModel::Naming.uncountable?(record) && inflection == :plural
+ end
+
+ action_prefix(options) + route + routing_type(options).to_s
+ end
+
+ def extract_record(record_or_hash_or_array)
+ case record_or_hash_or_array
+ when Array; record_or_hash_or_array.last
+ when Hash; record_or_hash_or_array[:id]
+ else record_or_hash_or_array
+ end
+ end
+ end
+ end
+end
+
View
3 actionpack/lib/action_dispatch/routing/route_set.rb
@@ -414,7 +414,8 @@ def opts
elsif value.is_a?(Array)
value.map { |v| Rack::Mount::Utils.escape_uri(v.to_param) }.join('/')
else
- Rack::Mount::Utils.escape_uri(value.to_param)
+ return nil unless param = value.to_param
+ param.split('/').map { |v| Rack::Mount::Utils.escape_uri(v) }.join("/")
end
end
{:parameterize => parameterize}
View
1 actionpack/lib/action_dispatch/routing/url_for.rb
@@ -82,6 +82,7 @@ module Routing
#
module UrlFor
extend ActiveSupport::Concern
+ include PolymorphicRoutes
included do
# TODO: with_routing extends @controller with url_helpers, trickling down to including this module which overrides its default_url_options
View
2 actionpack/lib/action_dispatch/testing/assertions.rb
@@ -1,7 +1,6 @@
module ActionDispatch
module Assertions
autoload :DomAssertions, 'action_dispatch/testing/assertions/dom'
- autoload :ModelAssertions, 'action_dispatch/testing/assertions/model'
autoload :ResponseAssertions, 'action_dispatch/testing/assertions/response'
autoload :RoutingAssertions, 'action_dispatch/testing/assertions/routing'
autoload :SelectorAssertions, 'action_dispatch/testing/assertions/selector'
@@ -11,7 +10,6 @@ module Assertions
included do
include DomAssertions
- include ModelAssertions
include ResponseAssertions
include RoutingAssertions
include SelectorAssertions
View
19 actionpack/lib/action_dispatch/testing/assertions/model.rb
@@ -1,19 +0,0 @@
-module ActionDispatch
- module Assertions
- module ModelAssertions
- # Ensures that the passed record is valid by Active Record standards and
- # returns any error messages if it is not.
- #
- # ==== Examples
- #
- # # assert that a newly created record is valid
- # model = Model.new
- # assert_valid(model)
- #
- def assert_valid(record)
- ::ActiveSupport::Deprecation.warn("assert_valid is deprecated. Use assert record.valid? instead", caller)
- assert record.valid?, record.errors.full_messages.join("\n")
- end
- end
- end
-end
View
1 actionpack/lib/action_view.rb
@@ -23,6 +23,7 @@
activesupport_path = File.expand_path('../../../activesupport/lib', __FILE__)
$:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)
+
require 'active_support/ruby/shim'
require 'active_support/core_ext/class/attribute_accessors'
View
2 actionpack/lib/action_view/helpers.rb
@@ -20,7 +20,6 @@ module Helpers #:nodoc:
autoload :NumberHelper
autoload :PrototypeHelper
autoload :RawOutputHelper
- autoload :RecordIdentificationHelper
autoload :RecordTagHelper
autoload :SanitizeHelper
autoload :ScriptaculousHelper
@@ -51,7 +50,6 @@ module Helpers #:nodoc:
include NumberHelper
include PrototypeHelper
include RawOutputHelper
- include RecordIdentificationHelper
include RecordTagHelper
include SanitizeHelper
include ScriptaculousHelper
View
3 actionpack/lib/action_view/helpers/date_helper.rb
@@ -800,7 +800,8 @@ def build_options(selected, options = {})
start = options.delete(:start) || 0
stop = options.delete(:end) || 59
step = options.delete(:step) || 1
- leading_zeros = options.delete(:leading_zeros).nil? ? true : false
+ options.reverse_merge!({:leading_zeros => true})
+ leading_zeros = options.delete(:leading_zeros)
select_options = []
start.step(stop, step) do |i|
View
10 actionpack/lib/action_view/helpers/form_helper.rb
@@ -298,12 +298,12 @@ def form_for(record_or_name_or_array, *args, &proc)
object_name = record_or_name_or_array
when Array
object = record_or_name_or_array.last
- object_name = options[:as] || ActionController::RecordIdentifier.singular_class_name(object)
+ object_name = options[:as] || ActiveModel::Naming.singular(object)
apply_form_for_options!(record_or_name_or_array, options)
args.unshift object
else
object = record_or_name_or_array
- object_name = options[:as] || ActionController::RecordIdentifier.singular_class_name(object)
+ object_name = options[:as] || ActiveModel::Naming.singular(object)
apply_form_for_options!([object], options)
args.unshift object
end
@@ -529,7 +529,7 @@ def fields_for(record_or_name_or_array, *args, &block)
object = args.first
else
object = record_or_name_or_array
- object_name = ActionController::RecordIdentifier.singular_class_name(object)
+ object_name = ActiveModel::Naming.singular(object)
end
builder = options[:builder] || ActionView::Base.default_form_builder
@@ -1152,11 +1152,11 @@ def fields_for(record_or_name_or_array, *args, &block)
end
when Array
object = record_or_name_or_array.last
- name = "#{object_name}#{index}[#{ActionController::RecordIdentifier.singular_class_name(object)}]"
+ name = "#{object_name}#{index}[#{ActiveModel::Naming.singular(object)}]"
args.unshift(object)
else
object = record_or_name_or_array
- name = "#{object_name}#{index}[#{ActionController::RecordIdentifier.singular_class_name(object)}]"
+ name = "#{object_name}#{index}[#{ActiveModel::Naming.singular(object)}]"
args.unshift(object)
end
View
6 actionpack/lib/action_view/helpers/form_options_helper.rb
@@ -447,7 +447,7 @@ def option_groups_from_collection_for_select(collection, group_method, group_lab
# wrap the output in an appropriate <tt><select></tt> tag.
def grouped_options_for_select(grouped_options, selected_key = nil, prompt = nil)
body = ''
- body << content_tag(:option, prompt, :value => "") if prompt
+ body << content_tag(:option, prompt, { :value => "" }, true) if prompt
grouped_options = grouped_options.sort if grouped_options.is_a?(Hash)
@@ -593,11 +593,11 @@ def to_time_zone_select_tag(priority_zones, options, html_options)
private
def add_options(option_tags, options, value = nil)
if options[:include_blank]
- option_tags = "<option value=\"\">#{options[:include_blank] if options[:include_blank].kind_of?(String)}</option>\n" + option_tags
+ option_tags = "<option value=\"\">#{html_escape(options[:include_blank]) if options[:include_blank].kind_of?(String)}</option>\n" + option_tags
end
if value.blank? && options[:prompt]
prompt = options[:prompt].kind_of?(String) ? options[:prompt] : I18n.translate('helpers.select.prompt', :default => 'Please select')
- option_tags = "<option value=\"\">#{prompt}</option>\n" + option_tags
+ option_tags = "<option value=\"\">#{html_escape(prompt)}</option>\n" + option_tags
end
option_tags.html_safe
end
View
2 actionpack/lib/action_view/helpers/prototype_helper.rb
@@ -139,7 +139,7 @@ def remote_function(options)
function = "if (#{options[:condition]}) { #{function}; }" if options[:condition]
function = "if (confirm('#{escape_javascript(options[:confirm])}')) { #{function}; }" if options[:confirm]
- return function
+ return function.html_safe
end
# All the methods were moved to GeneratorMethods so that
View
23 actionpack/lib/action_view/helpers/record_identification_helper.rb
@@ -1,23 +0,0 @@
-module ActionView
- # = Action View Record Identification Helpers
- #
- # See ActionController::RecordIdentifier for documentation on these methods.
- module Helpers
- module RecordIdentificationHelper
- # See ActionController::RecordIdentifier.partial_path -- this is just a delegate to that for convenient access in the view.
- def partial_path(*args, &block)
- ActionController::RecordIdentifier.partial_path(*args, &block)
- end
-
- # See ActionController::RecordIdentifier.dom_class -- this is just a delegate to that for convenient access in the view.
- def dom_class(*args, &block)
- ActionController::RecordIdentifier.dom_class(*args, &block)
- end
-
- # See ActionController::RecordIdentifier.dom_id -- this is just a delegate to that for convenient access in the view.
- def dom_id(*args, &block)
- ActionController::RecordIdentifier.dom_id(*args, &block)
- end
- end
- end
-end
View
4 actionpack/lib/action_view/helpers/record_tag_helper.rb
@@ -1,7 +1,11 @@
+require 'action_controller/record_identifier'
+
module ActionView
# = Action View Record Tag Helpers
module Helpers
module RecordTagHelper
+ include ActionController::RecordIdentifier
+
# Produces a wrapper DIV element with id and class parameters that
# relate to the specified Active Record object. Usage example:
#
View
2 actionpack/lib/action_view/helpers/url_helper.rb
@@ -398,7 +398,7 @@ def link_to_unless_current(name, options = {}, html_options = {}, &block)
def link_to_unless(condition, name, options = {}, html_options = {}, &block)
if condition
if block_given?
- block.arity <= 1 ? yield(name) : yield(name, options, html_options)
+ block.arity <= 1 ? capture(name, &block) : capture(name, options, html_options, &block)
else
name
end
View
2 actionpack/lib/action_view/test_case.rb
@@ -37,7 +37,7 @@ module Behavior
include ActionController::TemplateAssertions
include ActionView::Context
- include ActionController::PolymorphicRoutes
+ include ActionDispatch::Routing::PolymorphicRoutes
include ActionController::RecordIdentifier
include AbstractController::Helpers
View
15 actionpack/test/controller/action_pack_assertions_test.rb
@@ -482,21 +482,6 @@ def test_redirected_to_with_nested_controller
assert_redirected_to :controller => 'admin/user'
end
- def test_assert_valid
- get :get_valid_record
- assert_deprecated { assert_valid assigns('record') }
- end
-
- def test_assert_valid_failing
- get :get_invalid_record
-
- begin
- assert_deprecated { assert_valid assigns('record') }
- assert false
- rescue ActiveSupport::TestCase::Assertion => e
- end
- end
-
def test_assert_response_uses_exception_message
@controller = AssertResponseWithUnexpectedErrorController.new
get :index
View
40 actionpack/test/controller/record_identifier_test.rb
@@ -26,20 +26,6 @@ def name
end
end
-class Comment::Nested < Comment; end
-
-class Test::Unit::TestCase
- protected
- def comments_url
- 'http://www.example.com/comments'
- end
-
- def comment_url(comment)
- "http://www.example.com/comments/#{comment.id}"
- end
-end
-
-
class RecordIdentifierTest < Test::Unit::TestCase
include ActionController::RecordIdentifier
@@ -76,30 +62,4 @@ def test_dom_class
def test_dom_class_with_prefix
assert_equal "custom_prefix_#{@singular}", dom_class(@record, :custom_prefix)
end
-
- def test_singular_class_name
- assert_equal @singular, singular_class_name(@record)
- end
-
- def test_singular_class_name_for_class
- assert_equal @singular, singular_class_name(@klass)
- end
-
- def test_plural_class_name
- assert_equal @plural, plural_class_name(@record)
- end
-
- def test_plural_class_name_for_class
- assert_equal @plural, plural_class_name(@klass)
- end
-
- def test_uncountable
- assert_equal true, uncountable?(@uncountable)
- assert_equal false, uncountable?(@klass)
- end
-
- private
- def method_missing(method, *args)
- RecordIdentifier.send(method, *args)
- end
end
View
27 actionpack/test/controller/rescue_test.rb
@@ -79,6 +79,14 @@ class ResourceUnavailableToRescueAsString < StandardError
render :text => 'no way'
end
+ rescue_from ActionView::TemplateError do
+ render :text => 'action_view templater error'
+ end
+
+ rescue_from IOError do
+ render :text => 'io error'
+ end
+
before_filter(:only => :before_filter_raises) { raise 'umm nice' }
def before_filter_raises
@@ -141,6 +149,14 @@ def resource_unavailable_raise_as_string
def missing_template
end
+
+ def io_error_in_view
+ raise ActionView::TemplateError.new(nil, {}, IOError.new('this is io error'))
+ end
+
+ def zero_division_error_in_view
+ raise ActionView::TemplateError.new(nil, {}, ZeroDivisionError.new('this is zero division error'))
+ end
protected
def deny_access
@@ -228,6 +244,17 @@ def test_exception_in_parent_controller
end
class RescueControllerTest < ActionController::TestCase
+
+ def test_io_error_in_view
+ get :io_error_in_view
+ assert_equal 'io error', @response.body
+ end
+
+ def test_zero_division_error_in_view
+ get :zero_division_error_in_view
+ assert_equal 'action_view templater error', @response.body
+ end
+
def test_rescue_handler
get :not_authorized
assert_response :forbidden
View
7 actionpack/test/controller/test_test.rb
@@ -461,6 +461,13 @@ def test_assert_routing_with_method
def test_assert_routing_in_module
assert_routing 'admin/user', :controller => 'admin/user', :action => 'index'
end
+
+ def test_assert_routing_with_glob
+ with_routing do |set|
+ set.draw { |map| match('*path' => "pages#show") }
+ assert_routing('/company/about', { :controller => 'pages', :action => 'show', :path => 'company/about' })
+ end
+ end
def test_params_passing
get :test_params, :page => {:name => "Page name", :month => '4', :year => '2004', :day => '6'}
View
10 actionpack/test/dispatch/middleware_stack_test.rb
@@ -66,6 +66,16 @@ def setup
assert_equal BazMiddleware, @stack[0].klass
end
+ test "raise an error on invalid index" do
+ assert_raise RuntimeError do
+ @stack.insert("HiyaMiddleware", BazMiddleware)
+ end
+
+ assert_raise RuntimeError do
+ @stack.insert_after("HiyaMiddleware", BazMiddleware)
+ end
+ end
+
test "lazy evaluates middleware class" do
assert_difference "@stack.size" do
@stack.use "MiddlewareStackTest::BazMiddleware"
View
8 actionpack/test/dispatch/request_test.rb
@@ -392,19 +392,19 @@ class RequestTest < ActiveSupport::TestCase
[{'baz'=>[{'foo'=>'baz'}, "1"]}, {'baz'=>[{'foo'=>'[FILTERED]'}, "1"]}, [/foo/]]]
test_hashes.each do |before_filter, after_filter, filter_words|
- request = stub_request('action_dispatch.parameter_filter' => filter_words)
- assert_equal after_filter, request.send(:process_parameter_filter, before_filter)
+ parameter_filter = ActionDispatch::Http::ParameterFilter.new(filter_words)
+ assert_equal after_filter, parameter_filter.filter(before_filter)
filter_words << 'blah'
filter_words << lambda { |key, value|
value.reverse! if key =~ /bargain/
}
- request = stub_request('action_dispatch.parameter_filter' => filter_words)
+ parameter_filter = ActionDispatch::Http::ParameterFilter.new(filter_words)
before_filter['barg'] = {'bargain'=>'gain', 'blah'=>'bar', 'bar'=>{'bargain'=>{'blah'=>'foo'}}}
after_filter['barg'] = {'bargain'=>'niag', 'blah'=>'[FILTERED]', 'bar'=>{'bargain'=>{'blah'=>'[FILTERED]'}}}
- assert_equal after_filter, request.send(:process_parameter_filter, before_filter)
+ assert_equal after_filter, parameter_filter.filter(before_filter)
end
end
View
20 actionpack/test/dispatch/session/cookie_store_test.rb
@@ -44,7 +44,12 @@ def raise_data_overflow
session[:foo] = 'bye!' * 1024
head :ok
end
-
+
+ def change_session_id
+ request.session_options[:id] = nil
+ get_session_id
+ end
+
def rescue_action(e) raise end
end
@@ -212,6 +217,19 @@ def test_persistent_session_id
end
end
+ def test_setting_session_id_to_nil_is_respected
+ with_test_route_set do
+ cookies[SessionKey] = SignedBar
+
+ get "/get_session_id"
+ sid = response.body
+ assert_equal sid.size, 36
+
+ get "/change_session_id"
+ assert_not_equal sid, response.body
+ end
+ end
+
def test_session_store_with_expire_after
with_test_route_set(:expire_after => 5.hours) do
# First request accesses the session
View
23 actionpack/test/template/form_options_helper_test.rb
@@ -210,6 +210,12 @@ def test_grouped_options_for_select_returns_html_safe_string
assert grouped_options_for_select([["Hats", ["Baseball Cap","Cowboy Hat"]]]).html_safe?
end
+ def test_grouped_options_for_select_with_prompt_returns_html_escaped_string
+ assert_dom_equal(
+ "<option value=\"\">&lt;Choose One&gt;</option><optgroup label=\"Hats\"><option value=\"Baseball Cap\">Baseball Cap</option>\n<option value=\"Cowboy Hat\">Cowboy Hat</option></optgroup>",
+ grouped_options_for_select([["Hats", ["Baseball Cap","Cowboy Hat"]]], nil, '<Choose One>'))
+ end
+
def test_optgroups_with_with_options_with_hash
assert_dom_equal(
"<optgroup label=\"Europe\"><option value=\"Denmark\">Denmark</option>\n<option value=\"Germany\">Germany</option></optgroup><optgroup label=\"North America\"><option value=\"United States\">United States</option>\n<option value=\"Canada\">Canada</option></optgroup>",
@@ -367,6 +373,15 @@ def test_select_with_blank_as_string
)
end
+ def test_select_with_blank_as_string_escaped
+ @post = Post.new
+ @post.category = "<mus>"
+ assert_dom_equal(
+ "<select id=\"post_category\" name=\"post[category]\"><option value=\"\">&lt;None&gt;</option>\n<option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\" selected=\"selected\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
+ select("post", "category", %w( abe <mus> hest), :include_blank => '<None>')
+ )
+ end
+
def test_select_with_default_prompt
@post = Post.new
@post.category = ""
@@ -394,6 +409,14 @@ def test_select_with_given_prompt
)
end
+ def test_select_with_given_prompt_escaped
+ @post = Post.new
+ assert_dom_equal(
+ "<select id=\"post_category\" name=\"post[category]\"><option value=\"\">&lt;The prompt&gt;</option>\n<option value=\"abe\">abe</option>\n<option value=\"&lt;mus&gt;\">&lt;mus&gt;</option>\n<option value=\"hest\">hest</option></select>",
+ select("post", "category", %w( abe <mus> hest), :prompt => '<The prompt>')
+ )
+ end
+
def test_select_with_prompt_and_blank
@post = Post.new
@post.category = ""
View
6 actionpack/test/template/prototype_helper_test.rb
@@ -104,6 +104,12 @@ def test_update_page_tag_with_html_options
assert_equal javascript_tag(create_generator(&block).to_s, {:defer => 'true'}), update_page_tag({:defer => 'true'}, &block)
end
+ def test_remote_function
+ res = remote_function(:url => authors_path, :with => "'author[name]='+$F('author_name')+'&author[dob]='+$F('author_dob')")
+ assert_equal "new Ajax.Request('/authors', {asynchronous:true, evalScripts:true, parameters:'author[name]='+$F('author_name')+'&author[dob]='+$F('author_dob')})", res
+ assert res.html_safe?
+ end
+
protected
def author_path(record)
"/authors/#{record.id}"
View
5 activemodel/CHANGELOG
@@ -1,3 +1,8 @@
+*Rails 3.0.0 [Release Candidate] (unreleased)*
+
+* Added ActiveModel::MassAssignmentSecurity [Eric Chapweske, Josh Kalderimis]
+
+
*Rails 3.0.0 [beta 4] (June 8th, 2010)*
* JSON supports a custom root option: to_json(:root => 'custom') #4515 [Jatinder Singh]
View
0 activemodel/README → activemodel/README.rdoc
File renamed without changes.
View
2 activemodel/Rakefile
@@ -32,7 +32,7 @@ Rake::RDocTask.new do |rdoc|
rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
rdoc.options << '--charset' << 'utf-8'
rdoc.template = ENV['template'] ? "#{ENV['template']}.rb" : '../doc/template/horo'
- rdoc.rdoc_files.include("README", "CHANGELOG")
+ rdoc.rdoc_files.include("README.rdoc", "CHANGELOG")
rdoc.rdoc_files.include("lib/**/*.rb")
end
View
2 activemodel/activemodel.gemspec
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
s.homepage = 'http://www.rubyonrails.org'
s.rubyforge_project = 'activemodel'
- s.files = Dir['CHANGELOG', 'MIT-LICENSE', 'README', 'lib/**/*']
+ s.files = Dir['CHANGELOG', 'MIT-LICENSE', 'README.rdoc', 'lib/**/*']
s.require_path = 'lib'
s.has_rdoc = true
View
29 activemodel/lib/active_model/naming.rb
@@ -57,6 +57,35 @@ module Naming
def model_name
@_model_name ||= ActiveModel::Name.new(self)
end
+
+ # Returns the plural class name of a record or class. Examples:
+ #
+ # ActiveModel::Naming.plural(post) # => "posts"
+ # ActiveModel::Naming.plural(Highrise::Person) # => "highrise_people"
+ def self.plural(record_or_class)
+ model_name_from_record_or_class(record_or_class).plural
+ end
+
+ # Returns the singular class name of a record or class. Examples:
+ #
+ # ActiveModel::Naming.singular(post) # => "post"
+ # ActiveModel::Naming.singular(Highrise::Person) # => "highrise_person"
+ def self.singular(record_or_class)
+ model_name_from_record_or_class(record_or_class).singular