Permalink
Browse files

Merge commit 'rails/master'

  • Loading branch information...
2 parents 1ed1652 + db28d40 commit 824fa10f4d1306cc1e310a7d5de7e95cfb07d6f8 @fxn fxn committed Mar 31, 2010
Showing with 1,042 additions and 436 deletions.
  1. +1 −2 .gitignore
  2. +2 −0 Gemfile
  3. +3 −2 Rakefile
  4. +1 −1 actionmailer/actionmailer.gemspec
  5. +2 −1 actionmailer/lib/action_mailer/base.rb
  6. +1 −0 actionmailer/lib/action_mailer/old_api.rb
  7. +3 −3 actionmailer/lib/action_mailer/railtie.rb
  8. +25 −9 actionmailer/test/base_test.rb
  9. +3 −3 actionmailer/test/old_base/mail_service_test.rb
  10. +1 −2 actionpack/lib/action_controller/base.rb
  11. +12 −0 actionpack/lib/action_controller/deprecated/base.rb
  12. +0 −1 actionpack/lib/action_controller/metal/cookies.rb
  13. +1 −0 actionpack/lib/action_controller/metal/http_authentication.rb
  14. +1 −0 actionpack/lib/action_controller/metal/renderers.rb
  15. +5 −5 actionpack/lib/action_controller/railtie.rb
  16. +2 −0 actionpack/lib/action_controller/railties/log_subscriber.rb
  17. +3 −3 actionpack/lib/action_controller/railties/url_helpers.rb
  18. +2 −2 actionpack/lib/action_controller/record_identifier.rb
  19. +6 −5 actionpack/lib/action_controller/test_case.rb
  20. +2 −0 actionpack/lib/action_dispatch/http/cache.rb
  21. +1 −0 actionpack/lib/action_dispatch/http/filter_parameters.rb
  22. +6 −2 actionpack/lib/action_dispatch/http/mime_negotiation.rb
  23. +1 −0 actionpack/lib/action_dispatch/http/mime_type.rb
  24. +3 −3 actionpack/lib/action_dispatch/http/request.rb
  25. +1 −0 actionpack/lib/action_dispatch/http/response.rb
  26. +2 −0 actionpack/lib/action_dispatch/http/upload.rb
  27. +3 −3 actionpack/lib/action_dispatch/middleware/cookies.rb
  28. +4 −2 actionpack/lib/action_dispatch/middleware/params_parser.rb
  29. +1 −0 actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
  30. +1 −0 actionpack/lib/action_dispatch/middleware/session/cookie_store.rb
  31. +2 −0 actionpack/lib/action_dispatch/routing/deprecated_mapper.rb
  32. +54 −15 actionpack/lib/action_dispatch/routing/mapper.rb
  33. +10 −10 actionpack/lib/action_dispatch/testing/assertions/routing.rb
  34. +3 −1 actionpack/lib/action_dispatch/testing/performance_test.rb
  35. +2 −0 actionpack/lib/action_dispatch/testing/test_request.rb
  36. +1 −1 actionpack/lib/action_view/base.rb
  37. +13 −10 actionpack/lib/action_view/helpers/active_model_helper.rb
  38. +68 −3 actionpack/lib/action_view/helpers/asset_tag_helper.rb
  39. +2 −0 actionpack/lib/action_view/helpers/capture_helper.rb
  40. +2 −1 actionpack/lib/action_view/helpers/form_helper.rb
  41. +1 −0 actionpack/lib/action_view/helpers/form_options_helper.rb
  42. +1 −0 actionpack/lib/action_view/helpers/form_tag_helper.rb
  43. +1 −0 actionpack/lib/action_view/helpers/number_helper.rb
  44. +1 −0 actionpack/lib/action_view/helpers/prototype_helper.rb
  45. +1 −0 actionpack/lib/action_view/helpers/tag_helper.rb
  46. +1 −0 actionpack/lib/action_view/helpers/text_helper.rb
  47. +2 −2 actionpack/lib/action_view/railtie.rb
  48. +2 −0 actionpack/lib/action_view/render/partials.rb
  49. +1 −6 actionpack/lib/action_view/template/resolver.rb
  50. +1 −0 actionpack/lib/action_view/test_case.rb
  51. +7 −8 actionpack/test/abstract_unit.rb
  52. +82 −82 actionpack/test/activerecord/polymorphic_routes_test.rb
  53. +3 −3 actionpack/test/controller/caching_test.rb
  54. +1 −1 actionpack/test/controller/cookie_test.rb
  55. +47 −0 actionpack/test/controller/integration_test.rb
  56. +7 −7 actionpack/test/controller/resources_test.rb
  57. +4 −4 actionpack/test/controller/test_test.rb
  58. +14 −14 actionpack/test/controller/url_rewriter_test.rb
  59. +1 −1 actionpack/test/controller/webservice_test.rb
  60. +3 −3 actionpack/test/dispatch/rack_test.rb
  61. +4 −4 actionpack/test/dispatch/request_test.rb
  62. +45 −0 actionpack/test/dispatch/routing_test.rb
  63. +4 −0 actionpack/test/template/active_model_helper_test.rb
  64. +16 −0 actionpack/test/template/asset_tag_helper_test.rb
  65. +1 −1 actionpack/test/template/test_case_test.rb
  66. +3 −0 activemodel/lib/active_model/dirty.rb
  67. +1 −0 activemodel/lib/active_model/errors.rb
  68. +1 −1 activemodel/lib/active_model/validations/inclusion.rb
  69. +1 −0 activemodel/lib/active_model/validator.rb
  70. +4 −2 activerecord/CHANGELOG
  71. +3 −3 activerecord/lib/active_record.rb
  72. +6 −1 activerecord/lib/active_record/association_preload.rb
  73. +39 −3 activerecord/lib/active_record/associations.rb
  74. +1 −0 activerecord/lib/active_record/associations/has_many_through_association.rb
  75. +2 −0 activerecord/lib/active_record/attribute_methods/dirty.rb
  76. +6 −16 activerecord/lib/active_record/attribute_methods/primary_key.rb
  77. +2 −0 activerecord/lib/active_record/attribute_methods/query.rb
  78. +13 −5 activerecord/lib/active_record/base.rb
  79. +2 −0 activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
  80. +1 −0 activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
  81. +1 −0 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
  82. +7 −6 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
  83. +1 −0 activerecord/lib/active_record/fixtures.rb
  84. +11 −2 activerecord/lib/active_record/named_scope.rb
  85. +1 −0 activerecord/lib/active_record/nested_attributes.rb
  86. +2 −0 activerecord/lib/active_record/query_cache.rb
  87. +8 −8 activerecord/lib/active_record/railtie.rb
  88. +2 −0 activerecord/lib/active_record/relation.rb
  89. +7 −1 activerecord/lib/active_record/relation/batches.rb
  90. +2 −0 activerecord/lib/active_record/relation/calculations.rb
  91. +2 −0 activerecord/lib/active_record/relation/finder_methods.rb
  92. +1 −6 activerecord/lib/active_record/relation/predicate_builder.rb
  93. +2 −0 activerecord/lib/active_record/relation/query_methods.rb
  94. +2 −0 activerecord/lib/active_record/relation/spawn_methods.rb
  95. +2 −0 activerecord/lib/active_record/schema.rb
  96. +2 −4 activerecord/lib/active_record/validations/uniqueness.rb
  97. +25 −1 activerecord/test/cases/associations/belongs_to_associations_test.rb
  98. +6 −0 activerecord/test/cases/associations/eager_test.rb
  99. +8 −0 activerecord/test/cases/associations/has_many_associations_test.rb
  100. +9 −1 activerecord/test/cases/associations/has_one_associations_test.rb
  101. +13 −3 activerecord/test/cases/batches_test.rb
  102. +28 −0 activerecord/test/cases/modules_test.rb
  103. +21 −2 activerecord/test/cases/named_scope_test.rb
  104. +6 −0 activerecord/test/cases/pk_test.rb
  105. +5 −0 activerecord/test/models/company.rb
  106. +17 −0 activerecord/test/models/company_in_module.rb
  107. +1 −0 activeresource/lib/active_resource/base.rb
  108. +2 −0 activeresource/lib/active_resource/custom_methods.rb
  109. +1 −0 activeresource/lib/active_resource/validations.rb
  110. +2 −0 activesupport/CHANGELOG
  111. +1 −1 activesupport/lib/active_support/cache/mem_cache_store.rb
  112. +1 −1 activesupport/lib/active_support/core_ext/hash/keys.rb
  113. +56 −0 activesupport/lib/active_support/core_ext/time/marshal.rb
  114. +0 −26 activesupport/lib/active_support/core_ext/time/marshal_with_utc_flag.rb
  115. +0 −4 activesupport/lib/active_support/dependencies/autoload.rb
  116. +1 −1 activesupport/lib/active_support/i18n.rb
  117. +11 −19 activesupport/lib/active_support/lazy_load_hooks.rb
  118. +1 −1 activesupport/lib/active_support/railtie.rb
  119. +15 −0 activesupport/lib/active_support/testing/assertions.rb
  120. +1 −1 activesupport/lib/active_support/time.rb
  121. +5 −2 activesupport/lib/active_support/values/time_zone.rb
  122. +1 −0 activesupport/lib/active_support/xml_mini/libxmlsax.rb
  123. +1 −0 activesupport/lib/active_support/xml_mini/nokogirisax.rb
  124. +7 −1 activesupport/lib/active_support/xml_mini/rexml.rb
  125. +1 −0 activesupport/test/abstract_unit.rb
  126. +6 −0 activesupport/test/caching_test.rb
  127. +0 −8 activesupport/test/core_ext/blank_test.rb
  128. +8 −12 activesupport/test/core_ext/time_ext_test.rb
  129. +7 −0 activesupport/test/empty_bool.rb
  130. +1 −1 activesupport/test/message_encryptor_test.rb
  131. +1 −1 activesupport/test/message_verifier_test.rb
  132. +40 −0 activesupport/test/test_test.rb
  133. +1 −1 ci/ci_build.rb
  134. +2 −6 railties/Rakefile
  135. +9 −9 railties/guides/source/configuring.textile
  136. +1 −1 railties/lib/rails/application/routes_reloader.rb
  137. +5 −0 railties/lib/rails/commands/server.rb
  138. +7 −2 railties/lib/rails/engine.rb
  139. +1 −1 railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb
  140. +0 −12 railties/lib/rails/generators/rails/model_subclass/model_subclass_generator.rb
  141. +13 −0 railties/lib/rails/generators/rails/plugin/templates/Rakefile.tt
  142. +1 −0 railties/lib/rails/generators/rails/resource/resource_generator.rb
  143. +38 −31 railties/lib/rails/tasks/documentation.rake
  144. +1 −1 railties/lib/rails/test_help.rb
  145. +2 −2 railties/test/rails_info_controller_test.rb
  146. +7 −0 tools/console
View
3 .gitignore
@@ -15,7 +15,6 @@ activesupport/test/fixtures/isolation_test
railties/test/500.html
railties/test/fixtures/tmp
railties/test/initializer/root/log
-railties/doc/guides/html/images
-railties/doc/guides/html/stylesheets
+railties/doc
railties/guides/output
railties/tmp
View
2 Gemfile
@@ -11,6 +11,8 @@ group :mri do
if RUBY_VERSION < '1.9'
gem "system_timer"
gem "ruby-debug", ">= 0.10.3"
+ elsif RUBY_VERSION < '1.9.2'
+ gem "ruby-debug19"
end
end
View
5 Rakefile
@@ -72,8 +72,8 @@ 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/lib/{*.rb,commands/*.rb,rails/*.rb,generators/*.rb}')
- rdoc.rdoc_files.exclude('railties/lib/vendor/*')
+ 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/CHANGELOG')
@@ -88,6 +88,7 @@ Rake::RDocTask.new do |rdoc|
rdoc.rdoc_files.include('actionpack/README')
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/*')
View
2 actionmailer/actionmailer.gemspec
@@ -20,6 +20,6 @@ Gem::Specification.new do |s|
s.has_rdoc = true
s.add_dependency('actionpack', version)
- s.add_dependency('mail', '~> 2.1.3')
+ s.add_dependency('mail', '~> 2.1.5.3')
s.add_dependency('text-format', '~> 1.0.0')
end
View
3 actionmailer/lib/action_mailer/base.rb
@@ -2,6 +2,7 @@
require 'action_mailer/tmail_compat'
require 'action_mailer/collector'
require 'active_support/core_ext/array/wrap'
+require 'active_support/core_ext/object/blank'
module ActionMailer #:nodoc:
# Action Mailer allows you to send email from your application using a mailer model and views.
@@ -290,7 +291,7 @@ class Base < AbstractController::Base
:parts_order => [ "text/plain", "text/enriched", "text/html" ]
}.freeze
- ActionMailer.run_base_hooks(self)
+ ActiveSupport.run_load_hooks(:action_mailer, self)
class << self
View
1 actionmailer/lib/action_mailer/old_api.rb
@@ -1,4 +1,5 @@
require 'active_support/core_ext/object/try'
+require 'active_support/core_ext/object/blank'
module ActionMailer
module OldApi #:nodoc:
View
6 actionmailer/lib/action_mailer/railtie.rb
@@ -6,18 +6,18 @@ class Railtie < Rails::Railtie
config.action_mailer = ActiveSupport::OrderedOptions.new
initializer "action_mailer.url_for", :before => :load_environment_config do |app|
- ActionMailer.base_hook { include app.routes.url_helpers }
+ ActiveSupport.on_load(:action_mailer) { include app.routes.url_helpers }
end
require "action_mailer/railties/log_subscriber"
log_subscriber :action_mailer, ActionMailer::Railties::LogSubscriber.new
initializer "action_mailer.logger" do
- ActionMailer.base_hook { self.logger ||= Rails.logger }
+ ActiveSupport.on_load(:action_mailer) { self.logger ||= Rails.logger }
end
initializer "action_mailer.set_configs" do |app|
- ActionMailer.base_hook do
+ ActiveSupport.on_load(:action_mailer) do
app.config.action_mailer.each do |k,v|
send "#{k}=", v
end
View
34 actionmailer/test/base_test.rb
@@ -39,8 +39,15 @@ def attachment_with_content(hash = {})
end
def attachment_with_hash
- attachments['invoice.jpg'] = { :data => "you smiling", :mime_type => "image/x-jpg",
- :transfer_encoding => "base64" }
+ attachments['invoice.jpg'] = { :data => "\312\213\254\232)b",
+ :mime_type => "image/x-jpg",
+ :transfer_encoding => "base64" }
+ mail
+ end
+
+ def attachment_with_hash_default_encoding
+ attachments['invoice.jpg'] = { :data => "\312\213\254\232)b",
+ :mime_type => "image/x-jpg" }
mail
end
@@ -135,13 +142,13 @@ def different_layout(layout_name='')
:mime_version => '2.0',
:reply_to => 'reply-to@test.lindsaar.net',
:date => @time)
- assert_equal(['bcc@test.lindsaar.net'], email.bcc)
- assert_equal(['cc@test.lindsaar.net'], email.cc)
- assert_equal('multipart/mixed', email.content_type)
- assert_equal('iso-8559-1', email.charset)
- assert_equal('2.0', email.mime_version)
- assert_equal(['reply-to@test.lindsaar.net'], email.reply_to)
- assert_equal(@time, email.date)
+ assert_equal(['bcc@test.lindsaar.net'], email.bcc)
+ assert_equal(['cc@test.lindsaar.net'], email.cc)
+ assert_equal('multipart/mixed; charset=iso-8559-1', email.content_type)
+ assert_equal('iso-8559-1', email.charset)
+ assert_equal('2.0', email.mime_version)
+ assert_equal(['reply-to@test.lindsaar.net'], email.reply_to)
+ assert_equal(@time, email.date)
end
test "mail() renders the template using the method being processed" do
@@ -206,6 +213,15 @@ def different_layout(layout_name='')
assert_equal expected, email.attachments['invoice.jpg'].decoded
end
+ test "attachment with hash using default mail encoding" do
+ email = BaseMailer.attachment_with_hash_default_encoding
+ assert_equal(1, email.attachments.length)
+ assert_equal('invoice.jpg', email.attachments[0].filename)
+ expected = "\312\213\254\232)b"
+ expected.force_encoding(Encoding::BINARY) if '1.9'.respond_to?(:force_encoding)
+ assert_equal expected, email.attachments['invoice.jpg'].decoded
+ end
+
test "sets mime type to multipart/mixed when attachment is included" do
email = BaseMailer.attachment_with_content
assert_equal(1, email.attachments.length)
View
6 actionmailer/test/old_base/mail_service_test.rb
@@ -784,7 +784,7 @@ def test_utf8_body_is_not_quoted
expected.date = Time.local 2004, 12, 12
created = TestMailer.utf8_body @recipient
- assert_match(/åœö blah/, created.encoded)
+ assert_match(/åœö blah/, created.decoded)
end
def test_multiple_utf8_recipients
@@ -1019,8 +1019,8 @@ def test_decode_message_with_unknown_charset
def test_empty_header_values_omitted
result = TestMailer.unnamed_attachment(@recipient).encoded
- assert_match %r{Content-Type: application/octet-stream;}, result
- assert_match %r{Content-Disposition: attachment;}, result
+ assert_match %r{Content-Type: application/octet-stream}, result
+ assert_match %r{Content-Disposition: attachment}, result
end
def test_headers_with_nonalpha_chars
View
3 actionpack/lib/action_controller/base.rb
@@ -64,8 +64,7 @@ def self.filter_parameter_logging(*args, &block)
filter
end
- ActionController.run_base_hooks(self)
-
+ ActiveSupport.run_load_hooks(:action_controller, self)
end
end
View
12 actionpack/lib/action_controller/deprecated/base.rb
@@ -66,6 +66,18 @@ def ip_spoofing_check
Rails.application.config.action_dispatch.ip_spoofing_check
end
+ def cookie_verifier_secret=(value)
+ ActiveSupport::Deprecation.warn "ActionController::Base.cookie_verifier_secret= is deprecated. " <<
+ "Please configure it on your application with config.cookie_secret=", caller
+ ActionController::Base.config.secret = value
+ end
+
+ def cookie_verifier_secret
+ ActiveSupport::Deprecation.warn "ActionController::Base.cookie_verifier_secret is deprecated. " <<
+ "Please use ActionController::Base.config.secret instead.", caller
+ ActionController::Base.config.secret
+ end
+
def trusted_proxies=(value)
ActiveSupport::Deprecation.warn "ActionController::Base.trusted_proxies= is deprecated. " <<
"Please configure it on your application with config.action_dispatch.trusted_proxies=", caller
View
1 actionpack/lib/action_controller/metal/cookies.rb
@@ -6,7 +6,6 @@ module Cookies
included do
helper_method :cookies
- cattr_accessor :cookie_verifier_secret
end
private
View
1 actionpack/lib/action_controller/metal/http_authentication.rb
@@ -1,4 +1,5 @@
require 'active_support/base64'
+require 'active_support/core_ext/object/blank'
module ActionController
module HttpAuthentication
View
1 actionpack/lib/action_controller/metal/renderers.rb
@@ -1,4 +1,5 @@
require 'active_support/core_ext/class/attribute'
+require 'active_support/core_ext/object/blank'
module ActionController
def self.add_renderer(key, &block)
View
10 actionpack/lib/action_controller/railtie.rb
@@ -41,7 +41,7 @@ class Railtie < Rails::Railtie
log_subscriber :action_controller, ActionController::Railties::LogSubscriber.new
initializer "action_controller.logger" do
- ActionController.base_hook { self.logger ||= Rails.logger }
+ ActiveSupport.on_load(:action_controller) { self.logger ||= Rails.logger }
end
initializer "action_controller.set_configs" do |app|
@@ -53,23 +53,23 @@ class Railtie < Rails::Railtie
ac.stylesheets_dir = paths.public.stylesheets.to_a.first
ac.secret = app.config.cookie_secret
- ActionController.base_hook do
+ ActiveSupport.on_load(:action_controller) do
self.config.merge!(ac)
end
end
initializer "action_controller.initialize_framework_caches" do
- ActionController.base_hook { self.cache_store ||= RAILS_CACHE }
+ ActiveSupport.on_load(:action_controller) { self.cache_store ||= RAILS_CACHE }
end
initializer "action_controller.set_helpers_path" do |app|
- ActionController.base_hook do
+ ActiveSupport.on_load(:action_controller) do
self.helpers_path = app.config.paths.app.helpers.to_a
end
end
initializer "action_controller.url_helpers" do |app|
- ActionController.base_hook do
+ ActiveSupport.on_load(:action_controller) do
extend ::ActionController::Railties::UrlHelpers.with(app.routes)
end
View
2 actionpack/lib/action_controller/railties/log_subscriber.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/blank'
+
module ActionController
module Railties
class LogSubscriber < Rails::LogSubscriber
View
6 actionpack/lib/action_controller/railties/url_helpers.rb
@@ -1,14 +1,14 @@
module ActionController
module Railties
module UrlHelpers
- def self.with(router)
+ def self.with(routes)
Module.new do
define_method(:inherited) do |klass|
super(klass)
- klass.send(:include, router.url_helpers)
+ klass.send(:include, routes.url_helpers)
end
end
end
end
end
-end
+end
View
4 actionpack/lib/action_controller/record_identifier.rb
@@ -76,8 +76,8 @@ def dom_id(record, prefix = nil)
# method that replaces all characters that are invalid inside DOM ids, with valid ones. You need to
# make sure yourself that your dom ids are valid, in case you overwrite this method.
def record_key_for_dom_id(record)
- return record.id unless record.respond_to?(:to_model)
- key = record.to_model.to_key
+ record = record.to_model if record.respond_to?(:to_model)
+ key = record.to_key
key ? sanitize_dom_id(key.join('_')) : key
end
View
11 actionpack/lib/action_controller/test_case.rb
@@ -1,4 +1,5 @@
require 'rack/session/abstract/id'
+require 'active_support/core_ext/object/blank'
module ActionController
module TemplateAssertions
@@ -117,9 +118,9 @@ def self.new_escaped(strings)
end
end
- def assign_parameters(router, controller_path, action, parameters = {})
+ def assign_parameters(routes, controller_path, action, parameters = {})
parameters = parameters.symbolize_keys.merge(:controller => controller_path, :action => action)
- extra_keys = router.extra_keys(parameters)
+ extra_keys = routes.extra_keys(parameters)
non_path_parameters = get? ? query_parameters : request_parameters
parameters.each do |key, value|
if value.is_a? Fixnum
@@ -321,7 +322,7 @@ def xml_http_request(request_method, action, parameters = nil, session = nil, fl
def process(action, parameters = nil, session = nil, flash = nil, http_method = 'GET')
# Sanity check for required instance variables so we can give an
# understandable error message.
- %w(@router @controller @request @response).each do |iv_name|
+ %w(@routes @controller @request @response).each do |iv_name|
if !(instance_variable_names.include?(iv_name) || instance_variable_names.include?(iv_name.to_sym)) || instance_variable_get(iv_name).nil?
raise "#{iv_name} is nil: make sure you set it in your test's setup method."
end
@@ -337,7 +338,7 @@ def process(action, parameters = nil, session = nil, flash = nil, http_method =
@request.env['REQUEST_METHOD'] = http_method
parameters ||= {}
- @request.assign_parameters(@router, @controller.class.name.underscore.sub(/_controller$/, ''), action.to_s, parameters)
+ @request.assign_parameters(@routes, @controller.class.name.underscore.sub(/_controller$/, ''), action.to_s, parameters)
@request.session = ActionController::TestSession.new(session) unless session.nil?
@request.session["flash"] = @request.flash.update(flash || {})
@@ -446,7 +447,7 @@ def build_request_uri(action, parameters)
:relative_url_root => nil,
:_path_segments => @request.symbolized_path_parameters)
- url, query_string = @router.url_for(options).split("?", 2)
+ url, query_string = @routes.url_for(options).split("?", 2)
@request.env["SCRIPT_NAME"] = @controller.config.relative_url_root
@request.env["PATH_INFO"] = url
View
2 actionpack/lib/action_dispatch/http/cache.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/blank'
+
module ActionDispatch
module Http
module Cache
View
1 actionpack/lib/action_dispatch/http/filter_parameters.rb
@@ -1,5 +1,6 @@
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/hash/keys'
+require 'active_support/core_ext/object/duplicable'
module ActionDispatch
module Http
View
8 actionpack/lib/action_dispatch/http/mime_negotiation.rb
@@ -5,7 +5,7 @@ module MimeNegotiation
#
# For backward compatibility, the post \format is extracted from the
# X-Post-Data-Format HTTP header if present.
- def content_type
+ def content_mime_type
@env["action_dispatch.request.content_type"] ||= begin
if @env['CONTENT_TYPE'] =~ /^([^,\;]*)/
Mime::Type.lookup($1.strip.downcase)
@@ -15,13 +15,17 @@ def content_type
end
end
+ def content_type
+ content_mime_type && content_mime_type.to_s
+ end
+
# Returns the accepted MIME type for the request.
def accepts
@env["action_dispatch.request.accepts"] ||= begin
header = @env['HTTP_ACCEPT'].to_s.strip
if header.empty?
- [content_type]
+ [content_mime_type]
else
Mime::Type.parse(header)
end
View
1 actionpack/lib/action_dispatch/http/mime_type.rb
@@ -1,5 +1,6 @@
require 'set'
require 'active_support/core_ext/class/attribute_accessors'
+require 'active_support/core_ext/object/blank'
module Mime
class Mimes < Array
View
6 actionpack/lib/action_dispatch/http/request.rb
@@ -96,11 +96,11 @@ def headers
end
def forgery_whitelisted?
- method == :get || xhr? || content_type.nil? || !content_type.verify_request?
+ method == :get || xhr? || content_mime_type.nil? || !content_mime_type.verify_request?
end
def media_type
- content_type.to_s
+ content_mime_type.to_s
end
# Returns the content length of the request as an integer.
@@ -157,7 +157,7 @@ def body
end
def form_data?
- FORM_DATA_MEDIA_TYPES.include?(content_type.to_s)
+ FORM_DATA_MEDIA_TYPES.include?(content_mime_type.to_s)
end
def body_stream #:nodoc:
View
1 actionpack/lib/action_dispatch/http/response.rb
@@ -1,5 +1,6 @@
require 'digest/md5'
require 'active_support/core_ext/module/delegation'
+require 'active_support/core_ext/object/blank'
module ActionDispatch # :nodoc:
# Represents an HTTP response generated by a controller action. One can use
View
2 actionpack/lib/action_dispatch/http/upload.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/blank'
+
module ActionDispatch
module Http
module UploadedFile
View
6 actionpack/lib/action_dispatch/middleware/cookies.rb
@@ -168,12 +168,12 @@ def method_missing(method, *arguments, &block)
class SignedCookieJar < CookieJar #:nodoc:
def initialize(parent_jar)
- unless ActionController::Base.cookie_verifier_secret
- raise "You must set ActionController::Base.cookie_verifier_secret to use signed cookies"
+ unless ActionController::Base.config.secret
+ raise "You must set ActionController::Base.config.secret"
end
@parent_jar = parent_jar
- @verifier = ActiveSupport::MessageVerifier.new(ActionController::Base.cookie_verifier_secret)
+ @verifier = ActiveSupport::MessageVerifier.new(ActionController::Base.config.secret)
end
def [](name)
View
6 actionpack/lib/action_dispatch/middleware/params_parser.rb
@@ -25,7 +25,9 @@ def parse_formatted_parameters(env)
return false if request.content_length.zero?
- mime_type = content_type_from_legacy_post_data_format_header(env) || request.content_type
+ mime_type = content_type_from_legacy_post_data_format_header(env) ||
+ request.content_mime_type
+
strategy = @parsers[mime_type]
return false unless strategy
@@ -53,7 +55,7 @@ def parse_formatted_parameters(env)
raise
{ "body" => request.raw_post,
- "content_type" => request.content_type,
+ "content_type" => request.content_mime_type,
"content_length" => request.content_length,
"exception" => "#{e.message} (#{e.class})",
"backtrace" => e.backtrace }
View
1 actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
@@ -1,5 +1,6 @@
require 'rack/utils'
require 'rack/request'
+require 'active_support/core_ext/object/blank'
module ActionDispatch
module Session
View
1 actionpack/lib/action_dispatch/middleware/session/cookie_store.rb
@@ -1,4 +1,5 @@
require 'active_support/core_ext/hash/keys'
+require 'active_support/core_ext/object/blank'
module ActionDispatch
module Session
View
2 actionpack/lib/action_dispatch/routing/deprecated_mapper.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/blank'
+
module ActionDispatch
module Routing
class RouteSet
View
69 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -1,4 +1,5 @@
require 'active_support/core_ext/hash/except'
+require 'active_support/core_ext/object/blank'
module ActionDispatch
module Routing
@@ -258,6 +259,7 @@ def initialize(*args) #:nodoc:
def scope(*args)
options = args.extract_options!
+ options = options.dup
case args.first
when String
@@ -423,8 +425,13 @@ def member_name
singular
end
+ # Checks for uncountable plurals, and appends "_index" if they're.
def collection_name
- plural
+ uncountable? ? "#{plural}_index" : plural
+ end
+
+ def uncountable?
+ singular == plural
end
def name_for_action(action)
@@ -439,6 +446,32 @@ def name_for_action(action)
def id_segment
":#{singular}_id"
end
+
+ def constraints
+ options[:constraints] || {}
+ end
+
+ def id_constraint?
+ options[:id] && options[:id].is_a?(Regexp) || constraints[:id] && constraints[:id].is_a?(Regexp)
+ end
+
+ def id_constraint
+ options[:id] || constraints[:id]
+ end
+
+ def collection_options
+ (options || {}).dup.tap do |options|
+ options.delete(:id)
+ options[:constraints] = options[:constraints].dup if options[:constraints]
+ options[:constraints].delete(:id) if options[:constraints].is_a?(Hash)
+ end
+ end
+
+ def nested_options
+ options = { :name_prefix => member_name }
+ options["#{singular}_id".to_sym] = id_constraint if id_constraint?
+ options
+ end
end
class SingletonResource < Resource #:nodoc:
@@ -483,12 +516,14 @@ def resource(*resources, &block)
yield if block_given?
end
- get :show if resource.actions.include?(:show)
- post :create if resource.actions.include?(:create)
- put :update if resource.actions.include?(:update)
- delete :destroy if resource.actions.include?(:destroy)
- get :new, :as => resource.name if resource.actions.include?(:new)
- get :edit, :as => resource.name if resource.actions.include?(:edit)
+ scope(resource.options) do
+ get :show if resource.actions.include?(:show)
+ post :create if resource.actions.include?(:create)
+ put :update if resource.actions.include?(:update)
+ delete :destroy if resource.actions.include?(:destroy)
+ get :new, :as => resource.name if resource.actions.include?(:new)
+ get :edit, :as => resource.name if resource.actions.include?(:edit)
+ end
end
end
@@ -509,17 +544,21 @@ def resources(*resources, &block)
yield if block_given?
with_scope_level(:collection) do
- get :index if resource.actions.include?(:index)
- post :create if resource.actions.include?(:create)
- get :new, :as => resource.singular if resource.actions.include?(:new)
+ scope(resource.collection_options) do
+ get :index if resource.actions.include?(:index)
+ post :create if resource.actions.include?(:create)
+ get :new, :as => resource.singular if resource.actions.include?(:new)
+ end
end
with_scope_level(:member) do
scope(':id') do
- get :show if resource.actions.include?(:show)
- put :update if resource.actions.include?(:update)
- delete :destroy if resource.actions.include?(:destroy)
- get :edit, :as => resource.singular if resource.actions.include?(:edit)
+ scope(resource.options) do
+ get :show if resource.actions.include?(:show)
+ put :update if resource.actions.include?(:update)
+ delete :destroy if resource.actions.include?(:destroy)
+ get :edit, :as => resource.singular if resource.actions.include?(:edit)
+ end
end
end
end
@@ -558,7 +597,7 @@ def nested
end
with_scope_level(:nested) do
- scope(parent_resource.id_segment, :name_prefix => parent_resource.member_name) do
+ scope(parent_resource.id_segment, parent_resource.nested_options) do
yield
end
end
View
20 actionpack/lib/action_dispatch/testing/assertions/routing.rb
@@ -80,7 +80,7 @@ def assert_generates(expected_path, options, defaults={}, extras = {}, message=n
expected_path = "/#{expected_path}" unless expected_path[0] == ?/
# Load routes.rb if it hasn't been loaded.
- generated_path, extra_keys = @router.generate_extras(options, defaults)
+ generated_path, extra_keys = @routes.generate_extras(options, defaults)
found_extras = options.reject {|k, v| ! extra_keys.include? k}
msg = build_message(message, "found extras <?>, not <?>", found_extras, extras)
@@ -125,7 +125,7 @@ def assert_routing(path, options, defaults={}, extras={}, message=nil)
end
# A helper to make it easier to test different route configurations.
- # This method temporarily replaces @router
+ # This method temporarily replaces @routes
# with a new RouteSet instance.
#
# The new instance is yielded to the passed block. Typically the block
@@ -142,9 +142,9 @@ def assert_routing(path, options, defaults={}, extras={}, message=nil)
# end
#
def with_routing
- old_routes, @router = @router, ActionDispatch::Routing::RouteSet.new
+ old_routes, @routes = @routes, ActionDispatch::Routing::RouteSet.new
old_controller, @controller = @controller, @controller.clone if @controller
- _router = @router
+ _routes = @routes
# Unfortunately, there is currently an abstraction leak between AC::Base
# and AV::Base which requires having the URL helpers in both AC and AV.
@@ -153,22 +153,22 @@ def with_routing
#
# TODO: Make this unnecessary
if @controller
- @controller.singleton_class.send(:include, _router.url_helpers)
+ @controller.singleton_class.send(:include, _routes.url_helpers)
@controller.view_context_class = Class.new(@controller.view_context_class) do
- include _router.url_helpers
+ include _routes.url_helpers
end
end
- yield @router
+ yield @routes
ensure
- @router = old_routes
+ @routes = old_routes
if @controller
@controller = old_controller
end
end
# ROUTES TODO: These assertions should really work in an integration context
def method_missing(selector, *args, &block)
- if @controller && @router.named_routes.helpers.include?(selector)
+ if @controller && @routes && @routes.named_routes.helpers.include?(selector)
@controller.send(selector, *args, &block)
else
super
@@ -185,7 +185,7 @@ def recognized_request_for(path, request_method = nil)
request.env["REQUEST_METHOD"] = request_method.to_s.upcase if request_method
request.path = path
- params = @router.recognize_path(path, { :method => request.method })
+ params = @routes.recognize_path(path, { :method => request.method })
request.path_parameters = params.with_indifferent_access
request
View
4 actionpack/lib/action_dispatch/testing/performance_test.rb
@@ -1,7 +1,7 @@
require 'active_support/testing/performance'
require 'active_support/testing/default'
-if defined?(ActiveSupport::Testing::Performance)
+begin
module ActionDispatch
# An integration test that runs a code profiler on your test methods.
# Profiling output for combinations of each test method, measurement, and
@@ -14,4 +14,6 @@ class PerformanceTest < ActionDispatch::IntegrationTest
include ActiveSupport::Testing::Default
end
end
+rescue NameError
+ $stderr.puts "Specify ruby-prof as application's dependency in Gemfile to run benchmarks."
end
View
2 actionpack/lib/action_dispatch/testing/test_request.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/blank'
+
module ActionDispatch
class TestRequest < Request
DEFAULT_ENV = Rack::MockRequest.env_for('/')
View
2 actionpack/lib/action_view/base.rb
@@ -173,7 +173,7 @@ class << self
delegate :logger, :to => 'ActionController::Base', :allow_nil => true
end
- ActionView.run_base_hooks(self)
+ ActiveSupport.run_load_hooks(:action_view, self)
attr_accessor :base_path, :assigns, :template_extension, :lookup_context
attr_internal :captures, :request, :controller, :template, :config
View
23 actionpack/lib/action_view/helpers/active_model_helper.rb
@@ -6,7 +6,7 @@
require 'active_support/core_ext/object/blank'
module ActionView
- ActionView.base_hook do
+ ActiveSupport.on_load(:action_view) do
class ActionView::Base
@@field_error_proc = Proc.new{ |html_tag, instance| "<div class=\"fieldWithErrors\">#{html_tag}</div>".html_safe }
cattr_accessor :field_error_proc
@@ -97,10 +97,10 @@ def form(record_name, options = {})
end
# Returns a string containing the error message attached to the +method+ on the +object+ if one exists.
- # This error message is wrapped in a <tt>DIV</tt> tag, which can be extended to include a <tt>:prepend_text</tt>
- # and/or <tt>:append_text</tt> (to properly explain the error), and a <tt>:css_class</tt> to style it
- # accordingly. +object+ should either be the name of an instance variable or the actual object. The method can be
- # passed in either as a string or a symbol.
+ # This error message is wrapped in a <tt>DIV</tt> tag by default or with <tt>:html_tag</tt> if specified,
+ # which can be extended to include a <tt>:prepend_text</tt> and/or <tt>:append_text</tt> (to properly explain
+ # the error), and a <tt>:css_class</tt> to style it accordingly. +object+ should either be the name of an
+ # instance variable or the actual object. The method can be passed in either as a string or a symbol.
# As an example, let's say you have a model <tt>@post</tt> that has an error message on the +title+ attribute:
#
# <%= error_message_on "post", "title" %>
@@ -112,25 +112,28 @@ def form(record_name, options = {})
# <%= error_message_on "post", "title",
# :prepend_text => "Title simply ",
# :append_text => " (or it won't work).",
+ # :html_tag => "span",
# :css_class => "inputError" %>
+ # # => <span class="inputError">Title simply can't be empty (or it won't work).</span>
def error_message_on(object, method, *args)
options = args.extract_options!
unless args.empty?
ActiveSupport::Deprecation.warn('error_message_on takes an option hash instead of separate ' +
- 'prepend_text, append_text, and css_class arguments', caller)
+ 'prepend_text, append_text, html_tag, and css_class arguments', caller)
options[:prepend_text] = args[0] || ''
options[:append_text] = args[1] || ''
- options[:css_class] = args[2] || 'formError'
+ options[:html_tag] = args[2] || 'div'
+ options[:css_class] = args[3] || 'formError'
end
- options.reverse_merge!(:prepend_text => '', :append_text => '', :css_class => 'formError')
+ options.reverse_merge!(:prepend_text => '', :append_text => '', :html_tag => 'div', :css_class => 'formError')
object = convert_to_model(object)
if (obj = (object.respond_to?(:errors) ? object : instance_variable_get("@#{object}"))) &&
(errors = obj.errors[method]).presence
- content_tag("div",
- "#{options[:prepend_text]}#{ERB::Util.h(errors.first)}#{options[:append_text]}".html_safe,
+ content_tag(options[:html_tag],
+ (options[:prepend_text].html_safe << errors.first).safe_concat(options[:append_text]),
:class => options[:css_class]
)
else
View
71 actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -108,7 +108,7 @@ module Helpers #:nodoc:
# "http://asset%d.example.com", "https://asset1.example.com"
# )
#
- # === Using asset timestamps
+ # === Customizing the asset path
#
# By default, Rails appends asset's timestamps to all asset paths. This allows
# you to set a cache-expiration date for the asset far into the future, but
@@ -133,6 +133,65 @@ module Helpers #:nodoc:
# will request the same assets over and over again even thought they didn't
# change. You can use something like Live HTTP Headers for Firefox to verify
# that the cache is indeed working.
+ #
+ # This strategy works well enough for most server setups and requires the
+ # least configuration, but if you deploy several application servers at
+ # different times - say to handle a temporary spike in load - then the
+ # asset time stamps will be out of sync. In a setup like this you may want
+ # to set the way that asset paths are generated yourself.
+ #
+ # Altering the asset paths that Rails generates can be done in two ways.
+ # The easiest is to define the RAILS_ASSET_ID environment variable. The
+ # contents of this variable will always be used in preference to
+ # calculated timestamps. A more complex but flexible way is to set
+ # <tt>ActionController::Base.config.asset_path</tt> to a proc
+ # that takes the unmodified asset path and returns the path needed for
+ # your asset caching to work. Typically you'd do something like this in
+ # <tt>config/environments/production.rb</tt>:
+ #
+ # # Normally you'd calculate RELEASE_NUMBER at startup.
+ # RELEASE_NUMBER = 12345
+ # config.action_controller.asset_path_template = proc { |asset_path|
+ # "/release-#{RELEASE_NUMBER}#{asset_path}"
+ # }
+ #
+ # This example would cause the following behaviour on all servers no
+ # matter when they were deployed:
+ #
+ # image_tag("rails.png")
+ # # => <img alt="Rails" src="/release-12345/images/rails.png" />
+ # stylesheet_link_tag("application")
+ # # => <link href="/release-12345/stylesheets/application.css?1232285206" media="screen" rel="stylesheet" type="text/css" />
+ #
+ # Changing the asset_path does require that your web servers have
+ # knowledge of the asset template paths that you rewrite to so it's not
+ # suitable for out-of-the-box use. To use the example given above you
+ # could use something like this in your Apache VirtualHost configuration:
+ #
+ # <LocationMatch "^/release-\d+/(images|javascripts|stylesheets)/.*$">
+ # # Some browsers still send conditional-GET requests if there's a
+ # # Last-Modified header or an ETag header even if they haven't
+ # # reached the expiry date sent in the Expires header.
+ # Header unset Last-Modified
+ # Header unset ETag
+ # FileETag None
+ #
+ # # Assets requested using a cache-busting filename should be served
+ # # only once and then cached for a really long time. The HTTP/1.1
+ # # spec frowns on hugely-long expiration times though and suggests
+ # # that assets which never expire be served with an expiration date
+ # # 1 year from access.
+ # ExpiresActive On
+ # ExpiresDefault "access plus 1 year"
+ # </LocationMatch>
+ #
+ # # We use cached-busting location names with the far-future expires
+ # # headers to ensure that if a file does change it can force a new
+ # # request. The actual asset filenames are still the same though so we
+ # # need to rewrite the location from the cache-busting location to the
+ # # real asset location so that we can serve it.
+ # RewriteEngine On
+ # RewriteRule ^/release-\d+/(images|javascripts|stylesheets)/(.*)$ /$1/$2 [L]
module AssetTagHelper
JAVASCRIPT_DEFAULT_SOURCES = ['prototype', 'effects', 'dragdrop', 'controls', 'rails'].freeze unless const_defined?(:JAVASCRIPT_DEFAULT_SOURCES)
@@ -646,7 +705,7 @@ def compute_public_path(source, dir, ext = nil, include_host = true)
source += ".#{ext}" if rewrite_extension?(source, dir, ext)
source = "/#{dir}/#{source}" unless source[0] == ?/
- source = rewrite_asset_path(source)
+ source = rewrite_asset_path(source, config.asset_path)
has_request = controller.respond_to?(:request)
if has_request && include_host && source !~ %r{^#{controller.config.relative_url_root}/}
@@ -710,7 +769,13 @@ def rails_asset_id(source)
# Break out the asset path rewrite in case plugins wish to put the asset id
# someplace other than the query string.
- def rewrite_asset_path(source)
+ def rewrite_asset_path(source, path = nil)
+ if path && path.respond_to?(:call)
+ return path.call(source)
+ elsif path && path.is_a?(String)
+ return path % [source]
+ end
+
asset_id = rails_asset_id(source)
if asset_id.blank?
source
View
2 actionpack/lib/action_view/helpers/capture_helper.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/blank'
+
module ActionView
module Helpers
# CaptureHelper exposes methods to let you extract generated markup which
View
3 actionpack/lib/action_view/helpers/form_helper.rb
@@ -4,6 +4,7 @@
require 'action_view/helpers/form_tag_helper'
require 'active_support/core_ext/class/inheritable_attributes'
require 'active_support/core_ext/hash/slice'
+require 'active_support/core_ext/object/blank'
module ActionView
module Helpers
@@ -1220,7 +1221,7 @@ def nested_child_index(name)
end
end
- ActionView.base_hook do
+ ActiveSupport.on_load(:action_view) do
class ActionView::Base
cattr_accessor :default_form_builder
@@default_form_builder = ::ActionView::Helpers::FormBuilder
View
1 actionpack/lib/action_view/helpers/form_options_helper.rb
@@ -1,6 +1,7 @@
require 'cgi'
require 'erb'
require 'action_view/helpers/form_helper'
+require 'active_support/core_ext/object/blank'
module ActionView
module Helpers
View
1 actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -1,6 +1,7 @@
require 'cgi'
require 'action_view/helpers/tag_helper'
require 'active_support/core_ext/object/returning'
+require 'active_support/core_ext/object/blank'
module ActionView
module Helpers
View
1 actionpack/lib/action_view/helpers/number_helper.rb
@@ -1,5 +1,6 @@
require 'active_support/core_ext/big_decimal/conversions'
require 'active_support/core_ext/float/rounding'
+require 'active_support/core_ext/object/blank'
module ActionView
module Helpers #:nodoc:
View
1 actionpack/lib/action_view/helpers/prototype_helper.rb
@@ -1,6 +1,7 @@
require 'set'
require 'active_support/json'
require 'active_support/core_ext/object/returning'
+require 'active_support/core_ext/object/blank'
module ActionView
module Helpers
View
1 actionpack/lib/action_view/helpers/tag_helper.rb
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/object/blank'
require 'set'
module ActionView
View
1 actionpack/lib/action_view/helpers/text_helper.rb
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/object/blank'
require 'action_view/helpers/tag_helper'
module ActionView
View
4 actionpack/lib/action_view/railtie.rb
@@ -10,14 +10,14 @@ class Railtie < Rails::Railtie
initializer "action_view.cache_asset_timestamps" do |app|
unless app.config.cache_classes
- ActionView.base_hook do
+ ActiveSupport.on_load(:action_view) do
ActionView::Helpers::AssetTagHelper.cache_asset_timestamps = false
end
end
end
initializer "action_view.set_configs" do |app|
- ActionView.base_hook do
+ ActiveSupport.on_load(:action_view) do
app.config.action_view.each do |k,v|
send "#{k}=", v
end
View
2 actionpack/lib/action_view/render/partials.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/blank'
+
module ActionView
# There's also a convenience method for rendering sub templates within the current controller that depends on a
# single object (we call this kind of sub templates for partials). It relies on the fact that partials should
View
7 actionpack/lib/action_view/template/resolver.rb
@@ -35,12 +35,7 @@ def find_templates(name, prefix, partial, details)
def cached(key, prefix, name, partial)
return yield unless key && caching?
- scope = @cached[key][prefix][name]
- if scope.key?(partial)
- scope[partial]
- else
- scope[partial] = yield
- end
+ @cached[key][prefix][name][partial] ||= yield
end
end
View
1 actionpack/lib/action_view/test_case.rb
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/object/blank'
require 'action_controller/test_case'
require 'action_view'
View
15 actionpack/test/abstract_unit.rb
@@ -95,7 +95,7 @@ class TestCase
map.connect ':controller/:action/:id'
end
- ActionController::IntegrationTest.app.router.draw do |map|
+ ActionController::IntegrationTest.app.routes.draw do |map|
# FIXME: match ':controller(/:action(/:id))'
map.connect ':controller/:action/:id'
end
@@ -104,12 +104,11 @@ class TestCase
end
class RoutedRackApp
- attr_reader :router
- alias routes router
+ attr_reader :routes
- def initialize(router, &blk)
- @router = router
- @stack = ActionDispatch::MiddlewareStack.new(&blk).build(@router)
+ def initialize(routes, &blk)
+ @routes = routes
+ @stack = ActionDispatch::MiddlewareStack.new(&blk).build(@routes)
end
def call(env)
@@ -234,7 +233,7 @@ class TestCase
# Must repeat the setup because AV::TestCase is a duplication
# of AC::TestCase
setup do
- @router = SharedTestRoutes
+ @routes = SharedTestRoutes
end
end
end
@@ -250,7 +249,7 @@ class TestCase
include ActionDispatch::TestProcess
setup do
- @router = SharedTestRoutes
+ @routes = SharedTestRoutes
end
end
end
View
164 actionpack/test/activerecord/polymorphic_routes_test.rb
@@ -40,80 +40,80 @@ def setup
end
def test_with_record
- with_test_routes do
+ with_test_routes do
@project.save
assert_equal "http://example.com/projects/#{@project.id}", polymorphic_url(@project)
end
end
-
+
def test_with_class
with_test_routes do
assert_equal "http://example.com/projects", polymorphic_url(@project.class)
end
end
def test_with_new_record
- with_test_routes do
+ with_test_routes do
assert_equal "http://example.com/projects", polymorphic_url(@project)
end
end
def test_with_destroyed_record
- with_test_routes do
+ with_test_routes do
@project.destroy
assert_equal "http://example.com/projects", polymorphic_url(@project)
end
end
def test_with_record_and_action
- with_test_routes do
+ with_test_routes do
assert_equal "http://example.com/projects/new", polymorphic_url(@project, :action => 'new')
end
end
def test_url_helper_prefixed_with_new
- with_test_routes do
+ with_test_routes do
assert_equal "http://example.com/projects/new", new_polymorphic_url(@project)
end
end
def test_url_helper_prefixed_with_edit
- with_test_routes do
+ with_test_routes do
@project.save
assert_equal "http://example.com/projects/#{@project.id}/edit", edit_polymorphic_url(@project)
end
end
-
+
def test_url_helper_prefixed_with_edit_with_url_options
- with_test_routes do
+ with_test_routes do
@project.save
assert_equal "http://example.com/projects/#{@project.id}/edit?param1=10", edit_polymorphic_url(@project, :param1 => '10')
end
end
-
+
def test_url_helper_with_url_options
- with_test_routes do
+ with_test_routes do
@project.save
assert_equal "http://example.com/projects/#{@project.id}?param1=10", polymorphic_url(@project, :param1 => '10')
end
end
def test_format_option
- with_test_routes do
+ with_test_routes do
@project.save
assert_equal "http://example.com/projects/#{@project.id}.pdf", polymorphic_url(@project, :format => :pdf)
end
end
-
+
def test_format_option_with_url_options
- with_test_routes do
+ with_test_routes do
@project.save
assert_equal "http://example.com/projects/#{@project.id}.pdf?param1=10", polymorphic_url(@project, :format => :pdf, :param1 => '10')
end
end
-
+
def test_id_and_format_option
- with_test_routes do
+ with_test_routes do
@project.save
assert_equal "http://example.com/projects/#{@project.id}.pdf", polymorphic_url(:id => @project, :format => :pdf)
end
@@ -126,142 +126,142 @@ def test_with_nested
assert_equal "http://example.com/projects/#{@project.id}/tasks/#{@task.id}", polymorphic_url([@project, @task])
end
end
-
+
def test_with_nested_unsaved
with_test_routes do
@project.save
assert_equal "http://example.com/projects/#{@project.id}/tasks", polymorphic_url([@project, @task])
end
end
-
+
def test_with_nested_destroyed
with_test_routes do
@project.save
@task.destroy
assert_equal "http://example.com/projects/#{@project.id}/tasks", polymorphic_url([@project, @task])
end
end
-
+
def test_with_nested_class
with_test_routes do
@project.save
assert_equal "http://example.com/projects/#{@project.id}/tasks", polymorphic_url([@project, @task.class])
end
end
-
+
def test_class_with_array_and_namespace
- with_admin_test_routes do
+ with_admin_test_routes do
assert_equal "http://example.com/admin/projects", polymorphic_url([:admin, @project.class])
end
end
-
+
def test_new_with_array_and_namespace
- with_admin_test_routes do
+ with_admin_test_routes do
assert_equal "http://example.com/admin/projects/new", polymorphic_url([:admin, @project], :action => 'new')
end
end
-
+
def test_unsaved_with_array_and_namespace
- with_admin_test_routes do
+ with_admin_test_routes do
assert_equal "http://example.com/admin/projects", polymorphic_url([:admin, @project])
end
end
-
+
def test_nested_unsaved_with_array_and_namespace
- with_admin_test_routes do
+ with_admin_test_routes do
@project.save
assert_equal "http://example.com/admin/projects/#{@project.id}/tasks", polymorphic_url([:admin, @project, @task])
end
end
-
+
def test_nested_with_array_and_namespace
- with_admin_test_routes do
+ with_admin_test_routes do
@project.save
@task.save
assert_equal "http://example.com/admin/projects/#{@project.id}/tasks/#{@task.id}", polymorphic_url([:admin, @project, @task])
end
end
-
+
def test_ordering_of_nesting_and_namespace
- with_admin_and_site_test_routes do
+ with_admin_and_site_test_routes do
@project.save
@task.save
@step.save
assert_equal "http://example.com/admin/projects/#{@project.id}/site/tasks/#{@task.id}/steps/#{@step.id}", polymorphic_url([:admin, @project, :site, @task, @step])
end
end
-
+
def test_nesting_with_array_ending_in_singleton_resource
with_test_routes do
@project.save
assert_equal "http://example.com/projects/#{@project.id}/bid", polymorphic_url([@project, :bid])
end
end
-
+
def test_nesting_with_array_containing_singleton_resource
with_test_routes do
@project.save
@task.save
assert_equal "http://example.com/projects/#{@project.id}/bid/tasks/#{@task.id}", polymorphic_url([@project, :bid, @task])
end
end
-
+
def test_nesting_with_array_containing_singleton_resource_and_format
with_test_routes do
@project.save
@task.save
assert_equal "http://example.com/projects/#{@project.id}/bid/tasks/#{@task.id}.pdf", polymorphic_url([@project, :bid, @task], :format => :pdf)
end
end
-
+
def test_nesting_with_array_containing_namespace_and_singleton_resource
with_admin_test_routes do
@project.save
@task.save
assert_equal "http://example.com/admin/projects/#{@project.id}/bid/tasks/#{@task.id}", polymorphic_url([:admin, @project, :bid, @task])
end
end
-
+
def test_nesting_with_array_containing_nil
with_test_routes do
@project.save
assert_equal "http://example.com/projects/#{@project.id}/bid", polymorphic_url([@project, nil, :bid])
end
end
-
+
def test_with_array_containing_single_object
- with_test_routes do
+ with_test_routes do
@project.save
assert_equal "http://example.com/projects/#{@project.id}", polymorphic_url([nil, @project])
end
end
-
+
def test_with_array_containing_single_name
- with_test_routes do
+ with_test_routes do
@project.save
assert_equal "http://example.com/projects", polymorphic_url([:projects])
end
end
-
+
def test_with_array_containing_symbols
with_test_routes do
assert_equal "http://example.com/series/new", polymorphic_url([:new, :series])
end
end
-
+
def test_with_hash
- with_test_routes do
+ with_test_routes do
@project.save
assert_equal "http://example.com/projects/#{@project.id}", polymorphic_url(:id => @project)
end
end
-
+
def test_polymorphic_path_accepts_options
- with_test_routes do
+ with_test_routes do
assert_equal "/projects/new", polymorphic_path(@project, :action => 'new')
end
end
-
+
def test_polymorphic_path_does_not_modify_arguments
with_admin_test_routes do
@project.save
@@ -275,108 +275,108 @@ def test_polymorphic_path_does_not_modify_arguments
assert_equal original_args, [object_array, options]
end
end
-
+
# Tests for names where .plural.singular doesn't round-trip
def test_with_irregular_plural_record
- with_test_routes do
+ with_test_routes do
@tax.save
assert_equal "http://example.com/taxes/#{@tax.id}", polymorphic_url(@tax)
end
end
-
+
def test_with_irregular_plural_class
- with_test_routes do
+ with_test_routes do
assert_equal "http://example.com/taxes", polymorphic_url(@tax.class)
end
end
-
+
def test_with_irregular_plural_new_record
- with_test_routes do
+ with_test_routes do
assert_equal "http://example.com/taxes", polymorphic_url(@tax)
end
end
def test_with_irregular_plural_destroyed_record
with_test_routes do
- @tax.destroy
+ @tax.destroy
assert_equal "http://example.com/taxes", polymorphic_url(@tax)
end
end
-
+
def test_with_irregular_plural_record_and_action
- with_test_routes do
+ with_test_routes do
assert_equal "http://example.com/taxes/new", polymorphic_url(@tax, :action => 'new')
end
end
-
+
def test_irregular_plural_url_helper_prefixed_with_new
- with_test_routes do
+ with_test_routes do
assert_equal "http://example.com/taxes/new", new_polymorphic_url(@tax)
end
end
-
+
def test_irregular_plural_url_helper_prefixed_with_edit
- with_test_routes do
+ with_test_routes do
@tax.save
assert_equal "http://example.com/taxes/#{@tax.id}/edit", edit_polymorphic_url(@tax)
end
end
-
+
def test_with_nested_irregular_plurals
- with_test_routes do
+ with_test_routes do
@tax.save
@fax.save
assert_equal "http://example.com/taxes/#{@tax.id}/faxes/#{@fax.id}", polymorphic_url([@tax, @fax])
end
end
-
+
def test_with_nested_unsaved_irregular_plurals
- with_test_routes do
+ with_test_routes do
@tax.save
assert_equal "http://example.com/taxes/#{@tax.id}/faxes", polymorphic_url([@tax, @fax])
end
end
-
+
def test_new_with_irregular_plural_array_and_namespace
- with_admin_test_routes do
+ with_admin_test_routes do
assert_equal "http://example.com/admin/taxes/new", polymorphic_url([:admin, @tax], :action => 'new')
end
end
-
+
def test_class_with_irregular_plural_array_and_namespace
- with_admin_test_routes do
+ with_admin_test_routes do
assert_equal "http://example.com/admin/taxes", polymorphic_url([:admin, @tax.class])
end
end
-
+
def test_unsaved_with_irregular_plural_array_and_namespace
- with_admin_test_routes do
+ with_admin_test_routes do
assert_equal "http://example.com/admin/taxes", polymorphic_url([:admin, @tax])
end
end
-
+
def test_nesting_with_irregular_plurals_and_array_ending_in_singleton_resource
- with_test_routes do
+ with_test_routes do
@tax.save
assert_equal "http://example.com/taxes/#{@tax.id}/bid", polymorphic_url([@tax, :bid])
end
end
-
+
def test_with_array_containing_single_irregular_plural_object
- with_test_routes do
+ with_test_routes do
@tax.save
assert_equal "http://example.com/taxes/#{@tax.id}", polymorphic_url([nil, @tax])
end
end
-
+
def test_with_array_containing_single_name_irregular_plural
- with_test_routes do
+ with_test_routes do
@tax.save
assert_equal "http://example.com/taxes", polymorphic_url([:taxes])
end
end
-
- # Tests for uncountable names
+
+ # Tests for uncountable names
def test_uncountable_resource
with_test_routes do
@series.save
@@ -400,11 +400,11 @@ def with_test_routes(options = {})
map.resources :series
end
- self.class.send(:include, @router.url_helpers)
+ self.class.send(:include, @routes.url_helpers)
yield
end
end
-
+
def with_admin_test_routes(options = {})
with_routing do |set|
set.draw do |map|
@@ -422,11 +422,11 @@ def with_admin_test_routes(options = {})
end
end
- self.class.send(:include, @router.url_helpers)
+ self.class.send(:include, @routes.url_helpers)
yield
end
end
-
+
def with_admin_and_site_test_routes(options = {})
with_routing do |set|
set.draw do |map|
@@ -441,7 +441,7 @@ def with_admin_and_site_test_routes(options = {})
end
end
- self.class.send(:include, @router.url_helpers)
+ self.class.send(:include, @routes.url_helpers)
yield
end
end
View
6 actionpack/test/controller/caching_test.rb
@@ -81,9 +81,9 @@ def test_page_caching_resources_saves_to_correct_path_with_extension_even_if_def
match '/', :to => 'posts#index', :as => :main
end
@params[:format] = 'rss'
- assert_equal '/posts.rss', @router.url_for(@params)
+ assert_equal '/posts.rss', @routes.url_for(@params)
@params[:format] = nil
- assert_equal '/', @router.url_for(@params)
+ assert_equal '/', @routes.url_for(@params)
end
end
@@ -518,7 +518,7 @@ def reset!
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@controller = ActionCachingTestController.new
- @controller.singleton_class.send(:include, @router.url_helpers)
+ @controller.singleton_class.send(:include, @routes.url_helpers)
@request.host = 'hostname.com'
end
View
2 actionpack/test/controller/cookie_test.rb
@@ -1,6 +1,6 @@
require 'abstract_unit'
-ActionController::Base.cookie_verifier_secret = "thisISverySECRET123"
+ActionController::Base.config.secret = "thisISverySECRET123"
class CookieTest < ActionController::TestCase
class TestController < ActionController::Base
View
47 actionpack/test/controller/integration_test.rb
@@ -430,3 +430,50 @@ def test_generate_url_without_controller
assert_equal 'http://www.example.com/foo', url_for(:controller => "foo")
end
end
+
+class ApplicationIntegrationTest < ActionController::IntegrationTest
+ class TestController < ActionController::Base
+ def index
+ render :text => "index"
+ end
+ end
+
+ def self.call(env)
+ routes.call(env)
+ end
+
+ def self.routes
+ @routes ||= ActionDispatch::Routing::RouteSet.new
+ end
+
+ routes.draw do
+ match 'foo', :to => 'application_integration_test/test#index', :as => :foo
+ match 'bar', :to => 'application_integration_test/test#index', :as => :bar
+ end
+
+ def app
+ self.class
+ end
+
+ test "includes route helpers" do
+ assert_equal '/foo', foo_path
+ assert_equal '/bar', bar_path
+ end
+
+ test "route helpers after controller access" do
+ get '/foo'
+ assert_equal '/foo', foo_path
+
+ get '/bar'
+ assert_equal '/bar', bar_path
+ end
+
+ test "missing route helper before controller access" do
+ assert_raise(NameError) { missing_path }
+ end
+
+ test "missing route helper after controller access" do
+ get '/foo'
+ assert_raise(NameError) { missing_path }
+ end
+end
View
14 actionpack/test/controller/resources_test.rb
@@ -126,7 +126,7 @@ def test_multiple_default_restful_routes
def test_with_custom_conditions
with_restful_routing :messages, :conditions => { :subdomain => 'app' } do
- assert @router.recognize_path("/messages", :method => :get, :subdomain => 'app')
+ assert @routes.recognize_path("/messages", :method => :get, :subdomain => 'app')
end
end
@@ -395,7 +395,7 @@ def test_override_new_method
assert_restful_routes_for :messages do |options|
assert_recognizes(options.merge(:action => "new"), :path => "/messages/new", :method => :get)
assert_raise(ActionController::RoutingError) do
- @router.recognize_path("/messages/new", :method => :post)
+ @routes.recognize_path("/messages/new", :method => :post)
end