Permalink
Browse files

Merge commit 'origin/master' into mail

  • Loading branch information...
2 parents 3cb46b4 + e1935e3 commit e68bc3f14ea93eabdd4274e66071b65debb5a0a8 @jeremy jeremy committed Nov 22, 2009
Showing with 1,622 additions and 2,360 deletions.
  1. +1 −0 .gitignore
  2. +6 −0 .gitmodules
  3. +29 −16 Gemfile
  4. +2 −2 Rakefile
  5. +8 −6 actionmailer/Rakefile
  6. +4 −2 actionmailer/lib/action_mailer/base.rb
  7. +3 −1 actionmailer/test/abstract_unit.rb
  8. +1 −1 actionmailer/test/mail_service_test.rb
  9. +4 −2 actionpack/actionpack.gemspec
  10. +1 −1 actionpack/lib/abstract_controller/layouts.rb
  11. +6 −0 actionpack/lib/abstract_controller/rendering_controller.rb
  12. +1 −0 actionpack/lib/action_controller/caching.rb
  13. +5 −0 actionpack/lib/action_controller/metal/request_forgery_protection.rb
  14. +27 −17 actionpack/lib/action_controller/metal/responder.rb
  15. +0 −2 actionpack/lib/action_controller/metal/streaming.rb
  16. +2 −2 actionpack/lib/action_controller/translation.rb
  17. +3 −3 actionpack/lib/action_dispatch/http/request.rb
  18. +4 −2 actionpack/lib/action_dispatch/middleware/stack.rb
  19. +20 −10 actionpack/lib/action_dispatch/routing/mapper.rb
  20. +12 −55 actionpack/lib/action_dispatch/routing/route_set.rb
  21. +16 −3 actionpack/lib/action_dispatch/testing/assertions.rb
  22. +1 −0 actionpack/lib/action_view/erb/util.rb
  23. +11 −2 actionpack/lib/action_view/helpers/form_helper.rb
  24. +1 −1 actionpack/lib/action_view/helpers/translation_helper.rb
  25. +1 −0 actionpack/lib/action_view/test_case.rb
  26. +1 −1 actionpack/test/abstract/layouts_test.rb
  27. +3 −7 actionpack/test/abstract_unit.rb
  28. +0 −1 actionpack/test/controller/filters_test.rb
  29. +21 −1 actionpack/test/controller/mime_responds_test.rb
  30. +1 −1 actionpack/test/controller/new_base/render_action_test.rb
  31. +19 −1 actionpack/test/controller/request_forgery_protection_test.rb
  32. +76 −15 actionpack/test/controller/routing_test.rb
  33. +4 −0 actionpack/test/dispatch/request_test.rb
  34. +52 −0 actionpack/test/dispatch/routing_test.rb
  35. +1 −1 actionpack/test/dispatch/test_request_test.rb
  36. +55 −11 actionpack/test/template/form_helper_test.rb
  37. +9 −4 actionpack/test/template/test_case_test.rb
  38. +15 −12 activemodel/Rakefile
  39. +2 −0 activemodel/lib/active_model/translation.rb
  40. +3 −1 activemodel/test/cases/helper.rb
  41. +7 −5 activerecord/Rakefile
  42. +1 −1 activerecord/activerecord.gemspec
  43. +12 −8 activerecord/lib/active_record/association_preload.rb
  44. +14 −9 activerecord/lib/active_record/associations.rb
  45. +10 −4 activerecord/lib/active_record/associations/association_proxy.rb
  46. +3 −4 activerecord/lib/active_record/attribute_methods.rb
  47. +0 −2 activerecord/lib/active_record/attribute_methods/dirty.rb
  48. +0 −1 activerecord/lib/active_record/base.rb
  49. +0 −34 activerecord/lib/active_record/locking/optimistic.rb
  50. +2 −0 activerecord/lib/active_record/nested_attributes.rb
  51. +2 −2 activerecord/lib/active_record/notifications.rb
  52. +4 −6 activerecord/lib/active_record/relation.rb
  53. +0 −2 activerecord/lib/active_record/validations.rb
  54. +12 −0 activerecord/test/cases/associations/has_many_associations_test.rb
  55. +22 −0 activerecord/test/cases/associations/has_many_through_associations_test.rb
  56. +2 −2 activerecord/test/cases/copy_table_test_sqlite.rb
  57. +3 −1 activerecord/test/cases/helper.rb
  58. +8 −23 activerecord/test/cases/locking_test.rb
  59. +1 −1 activerecord/test/cases/pooled_connections_test.rb
  60. +2 −2 activerecord/test/cases/reflection_test.rb
  61. +1 −1 activerecord/test/cases/relations_test.rb
  62. +2 −0 activerecord/test/models/company.rb
  63. +1 −1 activerecord/test/models/pirate.rb
  64. +1 −1 activerecord/test/models/ship.rb
  65. +8 −7 activeresource/Rakefile
  66. +23 −16 activeresource/lib/active_resource/base.rb
  67. +5 −4 activeresource/lib/active_resource/connection.rb
  68. +3 −1 activeresource/test/abstract_unit.rb
  69. +0 −1 activeresource/test/cases/base/load_test.rb
  70. +2 −1 activesupport/lib/active_support/cache.rb
  71. +5 −0 activesupport/lib/active_support/cache/mem_cache_store.rb
  72. +3 −4 activesupport/lib/active_support/core_ext/array/wrap.rb
  73. +0 −7 activesupport/lib/active_support/core_ext/date.rb
  74. +0 −3 activesupport/lib/active_support/core_ext/date/conversions.rb
  75. +0 −5 activesupport/lib/active_support/core_ext/date_time.rb
  76. +0 −9 activesupport/lib/active_support/core_ext/enumerable.rb
  77. +2 −1 activesupport/lib/active_support/core_ext/hash/conversions.rb
  78. +1 −1 activesupport/lib/active_support/core_ext/integer.rb
  79. +0 −16 activesupport/lib/active_support/core_ext/integer/even_odd.rb
  80. +6 −0 activesupport/lib/active_support/core_ext/integer/multiple.rb
  81. +1 −0 activesupport/lib/active_support/core_ext/kernel/debugger.rb
  82. +3 −1 activesupport/lib/active_support/core_ext/name_error.rb
  83. +0 −27 activesupport/lib/active_support/core_ext/object/extending.rb
  84. +0 −7 activesupport/lib/active_support/core_ext/object/instance_variables.rb
  85. +0 −1 activesupport/lib/active_support/core_ext/object/misc.rb
  86. +0 −16 activesupport/lib/active_support/core_ext/object/tap.rb
  87. +0 −1 activesupport/lib/active_support/core_ext/string.rb
  88. +2 −0 activesupport/lib/active_support/core_ext/string/access.rb
  89. +0 −5 activesupport/lib/active_support/core_ext/string/bytesize.rb
  90. +1 −2 activesupport/lib/active_support/core_ext/string/interpolation.rb
  91. +0 −13 activesupport/lib/active_support/core_ext/string/iterators.rb
  92. +0 −14 activesupport/lib/active_support/core_ext/string/starts_ends_with.rb
  93. +0 −1 activesupport/lib/active_support/core_ext/symbol.rb
  94. +0 −14 activesupport/lib/active_support/core_ext/symbol/to_proc.rb
  95. +0 −10 activesupport/lib/active_support/core_ext/time.rb
  96. +1 −1 activesupport/lib/active_support/dependencies.rb
  97. +3 −2 activesupport/lib/active_support/deprecated_callbacks.rb
  98. +4 −407 activesupport/lib/active_support/inflector.rb
  99. +211 −0 activesupport/lib/active_support/inflector/inflections.rb
  100. +139 −0 activesupport/lib/active_support/inflector/methods.rb
  101. +61 −0 activesupport/lib/active_support/inflector/transliterate.rb
  102. +12 −9 activesupport/lib/active_support/json/backends/jsongem.rb
  103. +1 −1 activesupport/lib/active_support/json/encoding.rb
  104. +0 −2 activesupport/lib/active_support/message_verifier.rb
  105. +3 −2 activesupport/lib/active_support/multibyte/chars.rb
  106. +8 −10 activesupport/lib/active_support/notifications.rb
  107. +1 −1 activesupport/lib/active_support/rescuable.rb
  108. +0 −6 activesupport/lib/active_support/ruby/shim.rb
  109. +2 −2 activesupport/lib/active_support/testing/setup_and_teardown.rb
  110. +23 −3 activesupport/lib/active_support/time.rb
  111. +1 −7 activesupport/lib/active_support/time_with_zone.rb
  112. +1 −3 activesupport/lib/active_support/values/time_zone.rb
  113. +1 −1 activesupport/lib/active_support/vendor.rb
  114. +8 −2 activesupport/lib/active_support/whiny_nil.rb
  115. +5 −12 activesupport/test/abstract_unit.rb
  116. +3 −1 activesupport/test/caching_test.rb
  117. +20 −0 activesupport/test/core_ext/array_ext_test.rb
  118. +1 −1 activesupport/test/core_ext/date_ext_test.rb
  119. +1 −1 activesupport/test/core_ext/date_time_ext_test.rb
  120. +0 −12 activesupport/test/core_ext/enumerable_test.rb
  121. +0 −16 activesupport/test/core_ext/integer_ext_test.rb
  122. +11 −15 activesupport/test/core_ext/name_error_test.rb
  123. +0 −7 activesupport/test/core_ext/object_and_class_ext_test.rb
  124. +0 −9 activesupport/test/core_ext/object_ext_test.rb
  125. +1 −1 activesupport/test/core_ext/range_ext_test.rb
  126. +2 −27 activesupport/test/core_ext/string_ext_test.rb
  127. +0 −9 activesupport/test/core_ext/symbol_test.rb
  128. +0 −1 activesupport/test/dependencies_test.rb
  129. +2 −2 activesupport/test/i18n_test.rb
  130. +1 −0 activesupport/test/json/decoding_test.rb
  131. +1 −0 activesupport/test/message_encryptor_test.rb
  132. +2 −0 activesupport/test/message_verifier_test.rb
  133. +5 −5 activesupport/test/multibyte_chars_test.rb
  134. +1 −0 activesupport/test/multibyte_utils_test.rb
  135. +15 −10 activesupport/test/notifications_test.rb
  136. +13 −1 activesupport/test/whiny_nil_test.rb
  137. +1 −0 arel
  138. +36 −28 ci/ci_build.rb
  139. +1 −24 ci/geminstaller.yml
  140. +1 −0 rack-mount
  141. +15 −17 railties/Rakefile
  142. +12 −0 railties/lib/rails.rb
  143. +18 −37 railties/lib/rails/application.rb
  144. +3 −0 railties/lib/rails/commands/destroy.rb
  145. +3 −0 railties/lib/rails/commands/generate.rb
  146. +2 −2 railties/lib/rails/commands/server.rb
  147. +3 −30 railties/lib/rails/configuration.rb
  148. +1 −1 railties/lib/rails/generators.rb
  149. +29 −27 railties/lib/rails/generators/base.rb
  150. +4 −2 railties/lib/rails/generators/rails/app/app_generator.rb
  151. +0 −1 railties/lib/rails/generators/rails/app/templates/script/{about.tt → about}
  152. +0 −1 railties/lib/rails/generators/rails/app/templates/script/{console.tt → console}
  153. +0 −1 railties/lib/rails/generators/rails/app/templates/script/{dbconsole.tt → dbconsole}
  154. +0 −3 railties/lib/rails/generators/rails/app/templates/script/{destroy.tt → destroy}
  155. +0 −3 railties/lib/rails/generators/rails/app/templates/script/{generate.tt → generate}
  156. +0 −1 railties/lib/rails/generators/rails/app/templates/script/performance/{benchmarker.tt → benchmarker}
  157. +0 −1 railties/lib/rails/generators/rails/app/templates/script/performance/{profiler.tt → profiler}
  158. +0 −1 railties/lib/rails/generators/rails/app/templates/script/{plugin.tt → plugin}
  159. +0 −1 railties/lib/rails/generators/rails/app/templates/script/{runner.tt → runner}
  160. +0 −1 railties/lib/rails/generators/rails/app/templates/script/{server.tt → server}
  161. +1 −1 railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb
  162. +1 −1 railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb
  163. +2 −1 railties/lib/rails/initializable.rb
  164. +2 −12 railties/lib/rails/initializer.rb
  165. +5 −1 railties/lib/rails/paths.rb
  166. +45 −164 railties/lib/rails/plugin.rb
  167. +0 −200 railties/lib/rails/plugin/loader.rb
  168. +0 −100 railties/lib/rails/plugin/locator.rb
  169. +1 −1 railties/lib/rails/rack/static.rb
  170. +6 −1 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/CHANGELOG.rdoc
  171. 0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/LICENSE
  172. 0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/README.rdoc
  173. 0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/Thorfile
  174. 0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor.rb
  175. 0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/actions.rb
  176. +1 −0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/actions/create_file.rb
  177. +9 −5 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/actions/directory.rb
  178. +1 −0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/actions/empty_directory.rb
  179. 0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/actions/file_manipulation.rb
  180. 0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/actions/inject_into_file.rb
  181. 0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/base.rb
  182. 0 ...es/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/core_ext/hash_with_indifferent_access.rb
  183. 0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/core_ext/ordered_hash.rb
  184. 0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/error.rb
  185. +1 −1 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/group.rb
  186. 0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/invocation.rb
  187. 0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/parser.rb
  188. 0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/parser/argument.rb
  189. 0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/parser/arguments.rb
  190. 0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/parser/option.rb
  191. 0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/parser/options.rb
  192. 0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/rake_compat.rb
  193. 0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/runner.rb
  194. 0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/shell.rb
  195. 0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/shell/basic.rb
  196. 0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/shell/color.rb
  197. 0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/task.rb
  198. 0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/util.rb
  199. 0 railties/lib/rails/vendor/{thor-0.11.8 → thor-0.12.0}/lib/thor/version.rb
  200. +0 −117 railties/test/application/plugins_test.rb
  201. +2 −2 railties/test/backtrace_cleaner_test.rb
  202. +1 −4 railties/test/generators_test.rb
  203. +6 −2 railties/test/initializable_test.rb
  204. +21 −21 railties/test/initializer/initialize_i18n_test.rb
  205. +34 −2 railties/test/isolation/abstract_unit.rb
  206. +0 −176 railties/test/plugin_loader_test.rb
  207. +0 −73 railties/test/plugin_locator_test.rb
  208. +0 −174 railties/test/plugin_test.rb
  209. +0 −29 railties/test/plugin_test_helper.rb
  210. +183 −7 railties/test/plugins/vendored_test.rb
  211. +1 −12 railties/test/rails_info_test.rb
View
@@ -27,6 +27,7 @@ railties/guides/output
*.rbc
*.swp
*.swo
+*.tmproj
bin
vendor/gems/
railties/tmp
View
@@ -0,0 +1,6 @@
+[submodule "arel"]
+ path = arel
+ url = git://github.com/rails/arel.git
+[submodule "rack-mount"]
+ path = rack-mount
+ url = git://github.com/rails/rack-mount.git
View
45 Gemfile
@@ -1,22 +1,35 @@
clear_sources
source 'http://gemcutter.org'
+gem "rake", ">= 0.8.7"
+gem "mocha", ">= 0.9.8"
+
gem "rails", "3.0.pre", :vendored_at => "railties"
-%w(
- activesupport
- activemodel
- actionpack
- actionmailer
- activerecord
- activeresource
-).each do |lib|
+%w(activesupport activemodel actionpack actionmailer activerecord activeresource).each do |lib|
gem lib, '3.0.pre', :vendored_at => lib
end
-gem "rack", "1.0.1"
-gem "rack-mount", :git => "git://github.com/rails/rack-mount.git"
-gem "rack-test", "~> 0.5.0"
-gem "erubis", "~> 2.6.0"
-gem "arel", "0.1.3", :git => "git://github.com/rails/arel.git"
-gem "mocha"
-gem "sqlite3-ruby"
-gem "RedCloth"
+
+# AR
+gem "arel", "0.2.pre", :git => "git://github.com/rails/arel.git"
+gem "sqlite3-ruby", ">= 1.2.5"
+gem "pg", ">= 0.8.0"
+gem "mysql", ">= 2.8.1"
+
+# AP
+gem "rack", "1.0.1", :git => "git://github.com/rails/rack.git"
+gem "RedCloth", ">= 4.2.2"
+
+if ENV['CI']
+ disable_system_gems
+
+ gem "nokogiri", ">= 1.4.0"
+ gem "memcache-client", ">= 1.7.6"
+
+ # fcgi gem doesn't compile on 1.9
+ # avoid minitest strangeness on 1.9
+ if RUBY_VERSION < '1.9.0'
+ gem "fcgi", ">= 0.8.7"
+ else
+ gem "test-unit", ">= 2.0.5"
+ end
+end
View
@@ -10,9 +10,9 @@ Dir["#{File.dirname(__FILE__)}/*/lib/*/version.rb"].each do |version_path|
end
desc 'Run all tests by default'
-task :default => :test
+task :default => %w(test test:isolated)
-%w(test isolated_test rdoc pgem package release gem gemspec).each do |task_name|
+%w(test test:isolated rdoc pgem package release gem gemspec).each do |task_name|
desc "Run #{task_name} task for all projects"
task task_name do
errors = []
View
@@ -24,14 +24,16 @@ Rake::TestTask.new { |t|
t.libs << "test"
t.pattern = 'test/*_test.rb'
t.verbose = true
- t.warning = false
+ t.warning = true
}
-task :isolated_test do
- ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
- Dir.glob("test/*_test.rb").all? do |file|
- system(ruby, '-Ilib:test', file)
- end or raise "Failures"
+namespace :test do
+ task :isolated do
+ ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
+ Dir.glob("test/*_test.rb").all? do |file|
+ system(ruby, '-Ilib:test', file)
+ end or raise "Failures"
+ end
end
# Generate the RDoc documentation
@@ -475,6 +475,8 @@ def matches_dynamic_method?(method_name) #:nodoc:
# remain uninitialized (useful when you only need to invoke the "receive"
# method, for instance).
def initialize(method_name=nil, *parameters) #:nodoc:
+ @_response_body = nil
+ super()
create!(method_name, *parameters) if method_name
end
@@ -488,8 +490,8 @@ def create!(method_name, *parameters) #:nodoc:
create_parts
# Set the subject if not set yet
- @subject ||= I18n.t(method_name, :scope => [:actionmailer, :subjects, mailer_name],
- :default => method_name.humanize)
+ @subject ||= I18n.t(:subject, :scope => [:actionmailer, mailer_name, method_name],
+ :default => method_name.humanize)
# build the mail object itself
@mail = create_mail
@@ -4,9 +4,11 @@
rescue LoadError
$:.unshift("#{root}/activesupport/lib")
$:.unshift("#{root}/actionpack/lib")
- $:.unshift("#{root}/actionmailer/lib")
end
+lib = File.expand_path("#{File.dirname(__FILE__)}/../lib")
+$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib)
+
require 'rubygems'
require 'test/unit'
@@ -415,7 +415,7 @@ def test_subject_with_i18n
assert_nothing_raised { TestMailer.deliver_subject_with_i18n(@recipient) }
assert_equal "Subject with i18n", ActionMailer::Base.deliveries.first.subject.decoded
- I18n.backend.store_translations('en', :actionmailer => {:subjects => {:test_mailer => {:subject_with_i18n => "New Subject!"}}})
+ I18n.backend.store_translations('en', :actionmailer => {:test_mailer => {:subject_with_i18n => {:subject => "New Subject!"}}})
assert_nothing_raised { TestMailer.deliver_subject_with_i18n(@recipient) }
assert_equal "New Subject!", ActionMailer::Base.deliveries.last.subject.decoded
end
@@ -16,8 +16,10 @@ Gem::Specification.new do |s|
s.add_dependency('activesupport', '= 3.0.pre')
s.add_dependency('activemodel', '= 3.0.pre')
- s.add_dependency('rack', '~> 1.0.0')
- s.add_dependency('rack-test', '~> 0.5.0')
+ s.add_dependency('rack', '~> 1.0.1')
+ s.add_dependency('rack-test', '~> 0.5.0')
+ s.add_dependency('rack-mount', '~> 0.2')
+ s.add_dependency('erubis', '~> 2.6.5')
s.require_path = 'lib'
s.autorequire = 'action_controller'
@@ -100,7 +100,7 @@ def _implied_layout_name
# name, return that string. Otherwise, use the superclass'
# layout (which might also be implied)
def _write_layout_method
- case @_layout
+ case defined?(@_layout) ? @_layout : nil
when String
self.class_eval %{def _layout(details) #{@_layout.inspect} end}
when Symbol
@@ -12,6 +12,12 @@ module RenderingController
self._view_paths ||= ActionView::PathSet.new
end
+ # Initialize controller with nil formats.
+ def initialize(*) #:nodoc:
+ @_formats = nil
+ super
+ end
+
# An instance of a view class. The default view class is ActionView::Base
#
# The view class must have the following methods:
@@ -26,6 +26,7 @@ module ActionController #:nodoc:
# config.action_controller.cache_store = :file_store, "/path/to/cache/directory"
# config.action_controller.cache_store = :drb_store, "druby://localhost:9192"
# config.action_controller.cache_store = :mem_cache_store, "localhost"
+ # config.action_controller.cache_store = :mem_cache_store, Memcached::Rails.new("localhost:11211")
# config.action_controller.cache_store = MyOwnStore.new("parameter")
module Caching
extend ActiveSupport::Concern
@@ -101,6 +101,11 @@ def form_authenticity_token
session[:_csrf_token] ||= ActiveSupport::SecureRandom.base64(32)
end
+ # The form's authenticity parameter. Override to provide your own.
+ def form_authenticity_param
+ params[request_forgery_protection_token]
+ end
+
def protect_against_forgery?
allow_forgery_protection
end
@@ -14,12 +14,11 @@ module ActionController #:nodoc:
#
# When a request comes, for example with format :xml, three steps happen:
#
- # 1) respond_with searches for a template at people/index.xml;
+ # 1) responder searches for a template at people/index.xml;
#
- # 2) if the template is not available, it will create a responder, passing
- # the controller and the resource and invoke :to_xml on it;
+ # 2) if the template is not available, it will invoke :to_xml in the given resource;
#
- # 3) if the responder does not respond_to :to_xml, call to_format on it.
+ # 3) if the responder does not respond_to :to_xml, call :to_format on it.
#
# === Builtin HTTP verb semantics
#
@@ -88,14 +87,16 @@ def initialize(controller, resources, options={})
@resource = resources.is_a?(Array) ? resources.last : resources
@resources = resources
@options = options
+ @action = options.delete(:action)
@default_response = options.delete(:default_response)
end
delegate :head, :render, :redirect_to, :to => :controller
delegate :get?, :post?, :put?, :delete?, :to => :request
- # Undefine :to_json since it's defined on Object
+ # Undefine :to_json and :to_yaml since it's defined on Object
undef_method(:to_json) if method_defined?(:to_json)
+ undef_method(:to_yaml) if method_defined?(:to_yaml)
# Initializes a new responder an invoke the proper format. If the format is
# not defined, call to_format.
@@ -111,14 +112,8 @@ def self.call(*args)
#
def to_html
default_render
- rescue ActionView::MissingTemplate
- if get?
- raise
- elsif has_errors?
- render :action => default_action
- else
- redirect_to resource_location
- end
+ rescue ActionView::MissingTemplate => e
+ navigation_behavior(e)
end
# All others formats follow the procedure below. First we try to render a
@@ -127,9 +122,26 @@ def to_html
#
def to_format
default_render
- rescue ActionView::MissingTemplate
+ rescue ActionView::MissingTemplate => e
raise unless resourceful?
+ api_behavior(e)
+ end
+ protected
+
+ # This is the common behavior for "navigation" requests, like :html, :iphone and so forth.
+ def navigation_behavior(error)
+ if get?
+ raise error
+ elsif has_errors?
+ render :action => default_action
+ else
+ redirect_to resource_location
+ end
+ end
+
+ # This is the common behavior for "API" requests, like :xml and :json.
+ def api_behavior(error)
if get?
display resource
elsif has_errors?
@@ -141,8 +153,6 @@ def to_format
end
end
- protected
-
# Checks whether the resource responds to the current format or not.
#
def resourceful?
@@ -194,7 +204,7 @@ def has_errors?
# the verb is post.
#
def default_action
- request.post? ? :new : :edit
+ @action || (request.post? ? :new : :edit)
end
end
end
@@ -1,5 +1,3 @@
-require 'active_support/core_ext/string/bytesize'
-
module ActionController #:nodoc:
# Methods for sending arbitrary data and for streaming files to the browser,
# instead of rendering.
@@ -1,12 +1,12 @@
module ActionController
module Translation
def translate(*args)
- I18n.translate *args
+ I18n.translate(*args)
end
alias :t :translate
def localize(*args)
- I18n.localize *args
+ I18n.localize(*args)
end
alias :l :localize
end
@@ -5,7 +5,7 @@
require 'active_support/memoizable'
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/hash/indifferent_access'
-require 'active_support/core_ext/object/tap'
+require 'active_support/core_ext/string/access'
module ActionDispatch
class Request < Rack::Request
@@ -166,7 +166,7 @@ def formats
@env["action_dispatch.request.formats"] ||=
if parameters[:format]
- [Mime[parameters[:format]]]
+ Array.wrap(Mime[parameters[:format]])
elsif xhr? || (accept && !accept.include?(?,))
accepts
else
@@ -489,7 +489,7 @@ module UploadedFile
def self.extended(object)
object.class_eval do
attr_accessor :original_path, :content_type
- alias_method :local_path, :path
+ alias_method :local_path, :path if method_defined?(:path)
end
end
@@ -1,3 +1,5 @@
+require "active_support/inflector/methods"
+
module ActionDispatch
class MiddlewareStack < Array
class Middleware
@@ -32,7 +34,7 @@ def klass
elsif @klass.respond_to?(:call)
@klass.call
else
- @klass.to_s.constantize
+ ActiveSupport::Inflector.constantize(@klass.to_s)
end
end
@@ -53,7 +55,7 @@ def ==(middleware)
when Class
klass == middleware
else
- klass == middleware.to_s.constantize
+ klass == ActiveSupport::Inflector.constantize(middleware.to_s)
end
end
Oops, something went wrong.

0 comments on commit e68bc3f

Please sign in to comment.