Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of git@github.com:rails/rails

  • Loading branch information...
commit 22e830f883af0b56de81186c184751b6398d0141 2 parents 0aef9d1 + a3b7fa7
@technoweenie technoweenie authored
Showing with 10,347 additions and 5,055 deletions.
  1. +5 −0 actionmailer/CHANGELOG
  2. +39 −8 actionmailer/lib/action_mailer/base.rb
  3. +2 −2 actionmailer/lib/action_mailer/helpers.rb
  4. +1 −0  actionmailer/test/fixtures/auto_layout_mailer/hello.html.erb
  5. +1 −0  actionmailer/test/fixtures/explicit_layout_mailer/logout.html.erb
  6. +1 −0  actionmailer/test/fixtures/explicit_layout_mailer/signup.html.erb
  7. +1 −0  actionmailer/test/fixtures/layouts/auto_layout_mailer.html.erb
  8. +1 −0  actionmailer/test/fixtures/layouts/spam.html.erb
  9. +10 −0 actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.text.html.erb~
  10. +78 −0 actionmailer/test/mail_layout_test.rb
  11. +52 −0 actionmailer/test/mail_service_test.rb
  12. +46 −0 actionpack/CHANGELOG
  13. +8 −6 actionpack/Rakefile
  14. +2 −0  actionpack/lib/action_controller.rb
  15. +14 −14 actionpack/lib/action_controller/assertions/routing_assertions.rb
  16. +33 −53 actionpack/lib/action_controller/assertions/selector_assertions.rb
  17. +38 −68 actionpack/lib/action_controller/base.rb
  18. +37 −24 actionpack/lib/action_controller/benchmarking.rb
  19. +4 −4 actionpack/lib/action_controller/caching/actions.rb
  20. +3 −3 actionpack/lib/action_controller/caching/sweeping.rb
  21. +5 −4 actionpack/lib/action_controller/cgi_process.rb
  22. +4 −1 actionpack/lib/action_controller/components.rb
  23. +4 −4 actionpack/lib/action_controller/filters.rb
  24. +2 −2 actionpack/lib/action_controller/helpers.rb
  25. +1 −1  actionpack/lib/action_controller/http_authentication.rb
  26. +4 −4 actionpack/lib/action_controller/integration.rb
  27. +27 −53 actionpack/lib/action_controller/layout.rb
  28. +2 −0  actionpack/lib/action_controller/mime_type.rb
  29. +3 −3 actionpack/lib/action_controller/polymorphic_routes.rb
  30. +2 −1  actionpack/lib/action_controller/rack_process.rb
  31. +42 −35 actionpack/lib/action_controller/request.rb
  32. +1 −4 actionpack/lib/action_controller/rescue.rb
  33. +102 −48 actionpack/lib/action_controller/resources.rb
  34. +1 −1  actionpack/lib/action_controller/response.rb
  35. +7 −5 actionpack/lib/action_controller/routing/builder.rb
  36. +3 −2 actionpack/lib/action_controller/routing/optimisations.rb
  37. +22 −0 actionpack/lib/action_controller/routing/recognition_optimisation.rb
  38. +1 −1  actionpack/lib/action_controller/routing/route.rb
  39. +5 −5 actionpack/lib/action_controller/routing/route_set.rb
  40. +3 −3 actionpack/lib/action_controller/routing/segments.rb
  41. +2 −1  actionpack/lib/action_controller/session/cookie_store.rb
  42. +6 −2 actionpack/lib/action_controller/session_management.rb
  43. +13 −6 actionpack/lib/action_controller/test_process.rb
  44. +13 −0 actionpack/lib/action_controller/translation.rb
  45. +2 −2 actionpack/lib/action_controller/verification.rb
  46. +1 −3 actionpack/lib/action_view.rb
  47. +113 −79 actionpack/lib/action_view/base.rb
  48. +0 −1  actionpack/lib/action_view/helpers.rb
  49. +6 −6 actionpack/lib/action_view/helpers/active_record_helper.rb
  50. +18 −16 actionpack/lib/action_view/helpers/asset_tag_helper.rb
  51. +3 −3 actionpack/lib/action_view/helpers/benchmark_helper.rb
  52. +0 −92 actionpack/lib/action_view/helpers/form_country_helper.rb
  53. +0 −3  actionpack/lib/action_view/helpers/form_options_helper.rb
  54. +19 −12 actionpack/lib/action_view/helpers/form_tag_helper.rb
  55. +12 −22 actionpack/lib/action_view/helpers/prototype_helper.rb
  56. +3 −3 actionpack/lib/action_view/helpers/record_tag_helper.rb
  57. +10 −1 actionpack/lib/action_view/helpers/sanitize_helper.rb
  58. +1 −1  actionpack/lib/action_view/helpers/scriptaculous_helper.rb
  59. +51 −5 actionpack/lib/action_view/helpers/text_helper.rb
  60. +1 −1  actionpack/lib/action_view/partials.rb
  61. +12 −15 actionpack/lib/action_view/renderable.rb
  62. +19 −7 actionpack/lib/action_view/renderable_partial.rb
  63. +2 −0  actionpack/lib/action_view/template.rb
  64. +1 −1  actionpack/lib/action_view/template_handlers/builder.rb
  65. +1 −1  actionpack/lib/action_view/test_case.rb
  66. +49 −0 actionpack/test/controller/assert_select_test.rb
  67. +4 −4 actionpack/test/controller/base_test.rb
  68. +41 −25 actionpack/test/controller/components_test.rb
  69. +2 −2 actionpack/test/controller/filter_params_test.rb
  70. +13 −13 actionpack/test/controller/filters_test.rb
  71. +1 −1  actionpack/test/controller/integration_test.rb
  72. +0 −49 actionpack/test/controller/layout_test.rb
  73. +0 −981 actionpack/test/controller/new_render_test.rb
  74. +871 −27 actionpack/test/controller/render_test.rb
  75. +3 −0  actionpack/test/controller/request_test.rb
  76. +122 −25 actionpack/test/controller/resources_test.rb
  77. +59 −0 actionpack/test/controller/routing_test.rb
  78. +52 −1 actionpack/test/controller/session/cookie_store_test.rb
  79. +5 −0 actionpack/test/controller/test_test.rb
  80. +26 −0 actionpack/test/controller/translation_test.rb
  81. +0 −1,549 actionpack/test/template/form_country_helper_test.rb
  82. +9 −2 actionpack/test/template/form_tag_helper_test.rb
  83. +15 −0 actionpack/test/template/prototype_helper_test.rb
  84. +8 −0 actionpack/test/template/record_tag_helper_test.rb
  85. +34 −0 actionpack/test/template/text_helper_test.rb
  86. +3 −3 activemodel/lib/active_model/state_machine/event.rb
  87. +1 −1  activemodel/lib/active_model/validations.rb
  88. +1 −1  activemodel/lib/active_model/validations/exclusion.rb
  89. +1 −1  activemodel/lib/active_model/validations/inclusion.rb
  90. +4 −4 activemodel/lib/active_model/validations/uniqueness.rb
  91. +16 −18 activerecord/CHANGELOG
  92. +2 −4 activerecord/lib/active_record.rb
  93. +108 −36 activerecord/lib/active_record/aggregations.rb
  94. +8 −5 activerecord/lib/active_record/association_preload.rb
  95. +93 −79 activerecord/lib/active_record/associations.rb
  96. +66 −13 activerecord/lib/active_record/associations/association_collection.rb
  97. +49 −12 activerecord/lib/active_record/associations/association_proxy.rb
  98. +2 −2 activerecord/lib/active_record/associations/belongs_to_association.rb
  99. +10 −0 activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
  100. +17 −17 activerecord/lib/active_record/associations/has_many_association.rb
  101. +5 −14 activerecord/lib/active_record/associations/has_many_through_association.rb
  102. +12 −4 activerecord/lib/active_record/associations/has_one_association.rb
  103. +4 −0 activerecord/lib/active_record/associations/has_one_through_association.rb
  104. +4 −4 activerecord/lib/active_record/attribute_methods.rb
  105. +99 −62 activerecord/lib/active_record/base.rb
  106. +19 −6 activerecord/lib/active_record/calculations.rb
  107. +8 −2 activerecord/lib/active_record/callbacks.rb
  108. +278 −0 activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
  109. +42 −215 activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
  110. +4 −0 activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
  111. +29 −14 activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
  112. +40 −2 activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
  113. +20 −11 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
  114. +22 −1 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
  115. +40 −1 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
  116. +23 −2 activerecord/lib/active_record/dirty.rb
  117. +2 −1  activerecord/lib/active_record/dynamic_finder_match.rb
  118. +1 −1  activerecord/lib/active_record/fixtures.rb
  119. +26 −0 activerecord/lib/active_record/i18n_interpolation_deprecation.rb
  120. +25 −4 activerecord/lib/active_record/locale/en-US.yml
  121. +19 −15 activerecord/lib/active_record/named_scope.rb
  122. +35 −0 activerecord/lib/active_record/reflection.rb
  123. +1 −1  activerecord/lib/active_record/schema_dumper.rb
  124. +15 −0 activerecord/lib/active_record/test_case.rb
  125. +1 −1  activerecord/lib/active_record/transactions.rb
  126. +62 −48 activerecord/lib/active_record/validations.rb
  127. +39 −0 activerecord/test/cases/aggregations_test.rb
  128. +13 −0 activerecord/test/cases/associations/belongs_to_associations_test.rb
  129. +44 −9 activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
  130. +36 −7 activerecord/test/cases/associations/has_many_associations_test.rb
  131. +24 −0 activerecord/test/cases/associations/has_many_through_associations_test.rb
  132. +9 −0 activerecord/test/cases/associations/has_one_through_associations_test.rb
  133. +18 −106 activerecord/test/cases/associations_test.rb
  134. +9 −0 activerecord/test/cases/attribute_methods_test.rb
  135. +34 −5 activerecord/test/cases/base_test.rb
  136. +1 −1  activerecord/test/cases/connection_test_mysql.rb
  137. +31 −0 activerecord/test/cases/defaults_test.rb
  138. +49 −0 activerecord/test/cases/dirty_test.rb
  139. +52 −6 activerecord/test/cases/finder_test.rb
  140. +14 −0 activerecord/test/cases/helper.rb
  141. +7 −12 activerecord/test/cases/i18n_test.rb
  142. +1 −1  activerecord/test/cases/inheritance_test.rb
  143. +2 −7 activerecord/test/cases/locking_test.rb
  144. +79 −2 activerecord/test/cases/method_scoping_test.rb
  145. +5 −1 activerecord/test/cases/migration_test.rb
  146. +19 −0 activerecord/test/cases/named_scope_test.rb
  147. +87 −0 activerecord/test/cases/pooled_connections_test.rb
  148. +2 −2 activerecord/test/cases/reflection_test.rb
  149. +25 −0 activerecord/test/cases/sanitize_test.rb
  150. +2 −2 activerecord/test/cases/schema_authorization_test_postgresql.rb
  151. +0 −48 activerecord/test/cases/threaded_connections_test.rb
  152. +2 −10 activerecord/test/cases/transactions_test.rb
  153. +64 −1 activerecord/test/cases/validations_i18n_test.rb
  154. +48 −29 activerecord/test/cases/validations_test.rb
  155. +10 −1 activerecord/test/fixtures/customers.yml
  156. +2 −1  activerecord/test/models/author.rb
  157. +3 −0  activerecord/test/models/category.rb
  158. +2 −0  activerecord/test/models/company.rb
  159. +19 −1 activerecord/test/models/customer.rb
  160. +1 −0  activerecord/test/models/parrot.rb
  161. +0 −6 activerecord/test/models/post.rb
  162. +57 −46 activeresource/lib/active_resource/base.rb
  163. +18 −7 activeresource/lib/active_resource/connection.rb
  164. +12 −11 activeresource/lib/active_resource/custom_methods.rb
  165. +6 −6 activeresource/lib/active_resource/formats/json_format.rb
  166. +9 −9 activeresource/lib/active_resource/formats/xml_format.rb
  167. +1 −1  activeresource/lib/active_resource/http_mock.rb
  168. +15 −29 activeresource/lib/active_resource/validations.rb
  169. +8 −8 activeresource/test/authorization_test.rb
  170. +1 −2  activeresource/test/base/custom_methods_test.rb
  171. +2 −2 activeresource/test/base/load_test.rb
  172. +5 −5 activeresource/test/base_test.rb
  173. +11 −3 activeresource/test/connection_test.rb
  174. +23 −11 activeresource/test/format_test.rb
  175. +12 −0 activesupport/CHANGELOG
  176. +3 −4 activesupport/lib/active_support.rb
  177. +1 −1  activesupport/lib/active_support/buffered_logger.rb
  178. +1 −1  activesupport/lib/active_support/cache.rb
  179. +1 −1  activesupport/lib/active_support/cache/file_store.rb
  180. +11 −39 activesupport/lib/active_support/cache/memory_store.rb
  181. +46 −0 activesupport/lib/active_support/cache/synchronized_memory_store.rb
  182. +1 −1  activesupport/lib/active_support/callbacks.rb
  183. +0 −127 activesupport/lib/active_support/clean_logger.rb
  184. +6 −6 activesupport/lib/active_support/core_ext/array/grouping.rb
  185. +18 −22 activesupport/lib/active_support/core_ext/bigdecimal/conversions.rb
  186. +5 −5 activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
  187. +21 −8 activesupport/lib/active_support/core_ext/date/behavior.rb
  188. +24 −9 activesupport/lib/active_support/core_ext/date/calculations.rb
  189. +19 −5 activesupport/lib/active_support/core_ext/date_time/calculations.rb
  190. +21 −1 activesupport/lib/active_support/core_ext/enumerable.rb
  191. +1 −1  activesupport/lib/active_support/core_ext/file/atomic.rb
  192. +1 −1  activesupport/lib/active_support/core_ext/hash/conversions.rb
  193. +1 −1  activesupport/lib/active_support/core_ext/hash/except.rb
  194. +128 −1 activesupport/lib/active_support/core_ext/logger.rb
  195. +11 −1 activesupport/lib/active_support/core_ext/module.rb
  196. +71 −67 activesupport/lib/active_support/core_ext/module/aliasing.rb
  197. +79 −75 activesupport/lib/active_support/core_ext/module/introspection.rb
  198. +5 −5 activesupport/lib/active_support/core_ext/module/model_naming.rb
  199. +39 −0 activesupport/lib/active_support/core_ext/module/synchronization.rb
  200. +0 −5 activesupport/lib/active_support/core_ext/object/misc.rb
  201. +2 −2 activesupport/lib/active_support/core_ext/range/blockless_step.rb
  202. +36 −0 activesupport/lib/active_support/core_ext/rexml.rb
  203. +2 −0  activesupport/lib/active_support/core_ext/string.rb
  204. +13 −0 activesupport/lib/active_support/core_ext/string/behavior.rb
  205. +19 −0 activesupport/lib/active_support/core_ext/string/inflections.rb
  206. +22 −1 activesupport/lib/active_support/core_ext/time.rb
  207. +26 −11 activesupport/lib/active_support/core_ext/time/calculations.rb
  208. +1 −1  activesupport/lib/active_support/core_ext/time/zones.rb
  209. +17 −1 activesupport/lib/active_support/deprecation.rb
  210. +19 −0 activesupport/lib/active_support/inflector.rb
  211. +1 −1  activesupport/lib/active_support/memoizable.rb
  212. +5 −0 activesupport/lib/active_support/multibyte/chars.rb
  213. +1 −1  activesupport/lib/active_support/option_merger.rb
  214. +197 −0 activesupport/lib/active_support/secure_random.rb
  215. +10 −0 activesupport/lib/active_support/string_inquirer.rb
  216. +7 −1 activesupport/lib/active_support/test_case.rb
  217. +5 −1 activesupport/lib/active_support/testing/core_ext/test/unit/assertions.rb
  218. +54 −42 activesupport/lib/active_support/time_with_zone.rb
  219. +1 −1  activesupport/lib/active_support/values/time_zone.rb
  220. +16 −21 activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb
  221. +36 −29 activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb
  222. +30 −0 activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/definitions/Asia/Colombo.rb
  223. +2 −1  activesupport/test/buffered_logger_test.rb
  224. +23 −0 activesupport/test/core_ext/date_ext_test.rb
  225. +75 −0 activesupport/test/core_ext/date_time_ext_test.rb
  226. +5 −0 activesupport/test/core_ext/enumerable_test.rb
  227. +39 −4 activesupport/test/core_ext/hash_ext_test.rb
  228. +85 −0 activesupport/test/core_ext/module/synchronization_test.rb
  229. +0 −5 activesupport/test/core_ext/object_and_class_ext_test.rb
  230. +6 −0 activesupport/test/core_ext/string_ext_test.rb
  231. +113 −4 activesupport/test/core_ext/time_ext_test.rb
  232. +64 −10 activesupport/test/core_ext/time_with_zone_test.rb
  233. +9 −9 activesupport/test/dependencies_test.rb
  234. +6 −0 activesupport/test/inflector_test.rb
  235. +8 −0 activesupport/test/inflector_test_cases.rb
  236. +4 −0 activesupport/test/multibyte_chars_test.rb
  237. +15 −0 activesupport/test/secure_random_test.rb
  238. +2 −0  railties/CHANGELOG
  239. +37 −8 railties/Rakefile
  240. +1,657 −0 railties/doc/guides/activerecord/association_basics.txt
  241. +604 −0 railties/doc/guides/debugging/debugging_rails_applications.txt
  242. +270 −0 railties/doc/guides/forms/form_helpers.txt
  243. +348 −0 railties/doc/guides/getting_started_with_rails/getting_started_with_rails.txt
  244. +53 −0 railties/doc/guides/index.txt
  245. +85 −0 railties/doc/guides/migrations/anatomy_of_a_migration.txt
  246. +109 −0 railties/doc/guides/migrations/creating_a_migration.txt
  247. +7 −0 railties/doc/guides/migrations/foreign_keys.txt
  248. +21 −0 railties/doc/guides/migrations/migrations.txt
  249. +111 −0 railties/doc/guides/migrations/rakeing_around.txt
  250. +47 −0 railties/doc/guides/migrations/scheming.txt
  251. +46 −0 railties/doc/guides/migrations/using_models_in_migrations.txt
  252. +159 −0 railties/doc/guides/migrations/writing_a_migration.txt
  253. +838 −0 railties/doc/guides/routing/routing_outside_in.txt
  254. +3 −2 railties/environments/environment.rb
  255. +13 −0 railties/lib/commands/console.rb
  256. +1 −1  railties/lib/commands/dbconsole.rb
  257. +9 −9 railties/lib/commands/plugin.rb
  258. +2 −2 railties/lib/commands/process/spawner.rb
  259. +1 −2  railties/lib/initializer.rb
  260. +1 −2  railties/lib/rails_generator/generators/applications/app/app_generator.rb
  261. +0 −1  railties/lib/rails_generator/generators/components/mailer/templates/unit_test.rb
  262. +5 −147 railties/lib/rails_generator/secret_key_generator.rb
  263. +28 −8 railties/lib/tasks/databases.rake
  264. +2 −2 railties/lib/tasks/documentation.rake
  265. +3 −4 railties/lib/tasks/misc.rake
  266. +2 −8 railties/test/secret_key_generation_test.rb
  267. +5 −2 release.rb
View
5 actionmailer/CHANGELOG
@@ -1,3 +1,8 @@
+* Add layout functionality to mailers [Pratik]
+
+ Mailer layouts behaves just like controller layouts, except layout names need to
+ have '_mailer' postfix for them to be automatically picked up.
+
*2.1.0 (May 31st, 2008)*
* Fixed that a return-path header would be ignored #7572 [joost]
View
47 actionmailer/lib/action_mailer/base.rb
@@ -246,7 +246,10 @@ module ActionMailer #:nodoc:
# +implicit_parts_order+.
class Base
include AdvAttrAccessor, PartContainer
- include ActionController::UrlWriter if Object.const_defined?(:ActionController)
+ if Object.const_defined?(:ActionController)
+ include ActionController::UrlWriter
+ include ActionController::Layout
+ end
private_class_method :new #:nodoc:
@@ -362,6 +365,7 @@ def mailer_name=(value)
# The mail object instance referenced by this mailer.
attr_reader :mail
+ attr_reader :template_name, :default_template_name, :action_name
class << self
attr_writer :mailer_name
@@ -374,11 +378,16 @@ def mailer_name
alias_method :controller_name, :mailer_name
alias_method :controller_path, :mailer_name
- def method_missing(method_symbol, *parameters)#:nodoc:
- case method_symbol.id2name
- when /^create_([_a-z]\w*)/ then new($1, *parameters).mail
- when /^deliver_([_a-z]\w*)/ then new($1, *parameters).deliver!
- when "new" then nil
+ def respond_to?(method_symbol, include_private = false) #:nodoc:
+ matches_dynamic_method?(method_symbol) || super
+ end
+
+ def method_missing(method_symbol, *parameters) #:nodoc:
+ match = matches_dynamic_method?(method_symbol)
+ case match[1]
+ when 'create' then new(match[2], *parameters).mail
+ when 'deliver' then new(match[2], *parameters).deliver!
+ when 'new' then nil
else super
end
end
@@ -424,6 +433,12 @@ def template_root
def template_root=(root)
self.view_paths = ActionView::Base.process_view_paths(root)
end
+
+ private
+ def matches_dynamic_method?(method_name) #:nodoc:
+ method_name = method_name.to_s
+ /(create|deliver)_([_a-z]\w*)/.match(method_name) || /^(new)$/.match(method_name)
+ end
end
# Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
@@ -451,7 +466,7 @@ def create!(method_name, *parameters) #:nodoc:
template = template_root["#{mailer_name}/#{File.basename(path)}"]
# Skip unless template has a multipart format
- next unless template.multipart?
+ next unless template && template.multipart?
@parts << Part.new(
:content_type => template.content_type,
@@ -519,6 +534,7 @@ def initialize_defaults(method_name)
@content_type ||= @@default_content_type.dup
@implicit_parts_order ||= @@default_implicit_parts_order.dup
@template ||= method_name
+ @default_template_name = @action_name = @template
@mailer_name ||= self.class.name.underscore
@parts ||= []
@headers ||= {}
@@ -535,7 +551,22 @@ def render(opts)
if opts[:file] && (opts[:file] !~ /\// && !opts[:file].respond_to?(:render))
opts[:file] = "#{mailer_name}/#{opts[:file]}"
end
- initialize_template_class(body).render(opts)
+
+ begin
+ old_template, @template = @template, initialize_template_class(body)
+ layout = respond_to?(:pick_layout, true) ? pick_layout(opts) : false
+ @template.render(opts.merge(:layout => layout))
+ ensure
+ @template = old_template
+ end
+ end
+
+ def default_template_format
+ :html
+ end
+
+ def candidate_for_layout?(options)
+ !@template.send(:_exempt_from_layout?, default_template_name)
end
def template_root
View
4 actionmailer/lib/action_mailer/helpers.rb
@@ -72,7 +72,7 @@ def helper_method(*methods)
methods.flatten.each do |method|
master_helper_module.module_eval <<-end_eval
def #{method}(*args, &block)
- controller.send!(%(#{method}), *args, &block)
+ controller.__send__(%(#{method}), *args, &block)
end
end_eval
end
@@ -92,7 +92,7 @@ def inherited_with_helper(child)
inherited_without_helper(child)
begin
child.master_helper_module = Module.new
- child.master_helper_module.send! :include, master_helper_module
+ child.master_helper_module.__send__(:include, master_helper_module)
child.helper child.name.to_s.underscore
rescue MissingSourceFile => e
raise unless e.is_missing?("helpers/#{child.name.to_s.underscore}_helper")
View
1  actionmailer/test/fixtures/auto_layout_mailer/hello.html.erb
@@ -0,0 +1 @@
+Inside
View
1  actionmailer/test/fixtures/explicit_layout_mailer/logout.html.erb
@@ -0,0 +1 @@
+You logged out
View
1  actionmailer/test/fixtures/explicit_layout_mailer/signup.html.erb
@@ -0,0 +1 @@
+We do not spam
View
1  actionmailer/test/fixtures/layouts/auto_layout_mailer.html.erb
@@ -0,0 +1 @@
+Hello from layout <%= yield %>
View
1  actionmailer/test/fixtures/layouts/spam.html.erb
@@ -0,0 +1 @@
+Spammer layout <%= yield %>
View
10 actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.text.html.erb~
@@ -0,0 +1,10 @@
+<html>
+ <body>
+ HTML formatted message to <strong><%= @recipient %></strong>.
+ </body>
+</html>
+<html>
+ <body>
+ HTML formatted message to <strong><%= @recipient %></strong>.
+ </body>
+</html>
View
78 actionmailer/test/mail_layout_test.rb
@@ -0,0 +1,78 @@
+require 'abstract_unit'
+
+class AutoLayoutMailer < ActionMailer::Base
+ def hello(recipient)
+ recipients recipient
+ subject "You have a mail"
+ from "tester@example.com"
+ end
+
+ def spam(recipient)
+ recipients recipient
+ subject "You have a mail"
+ from "tester@example.com"
+ body render(:inline => "Hello, <%= @world %>", :layout => 'spam', :body => { :world => "Earth" })
+ end
+
+ def nolayout(recipient)
+ recipients recipient
+ subject "You have a mail"
+ from "tester@example.com"
+ body render(:inline => "Hello, <%= @world %>", :layout => false, :body => { :world => "Earth" })
+ end
+end
+
+class ExplicitLayoutMailer < ActionMailer::Base
+ layout 'spam', :except => [:logout]
+
+ def signup(recipient)
+ recipients recipient
+ subject "You have a mail"
+ from "tester@example.com"
+ end
+
+ def logout(recipient)
+ recipients recipient
+ subject "You have a mail"
+ from "tester@example.com"
+ end
+end
+
+class LayoutMailerTest < Test::Unit::TestCase
+ def setup
+ set_delivery_method :test
+ ActionMailer::Base.perform_deliveries = true
+ ActionMailer::Base.deliveries = []
+
+ @recipient = 'test@localhost'
+ end
+
+ def teardown
+ restore_delivery_method
+ end
+
+ def test_should_pickup_default_layout
+ mail = AutoLayoutMailer.create_hello(@recipient)
+ assert_equal "Hello from layout Inside", mail.body.strip
+ end
+
+ def test_should_pickup_layout_given_to_render
+ mail = AutoLayoutMailer.create_spam(@recipient)
+ assert_equal "Spammer layout Hello, Earth", mail.body.strip
+ end
+
+ def test_should_respect_layout_false
+ mail = AutoLayoutMailer.create_nolayout(@recipient)
+ assert_equal "Hello, Earth", mail.body.strip
+ end
+
+ def test_explicit_class_layout
+ mail = ExplicitLayoutMailer.create_signup(@recipient)
+ assert_equal "Spammer layout We do not spam", mail.body.strip
+ end
+
+ def test_explicit_layout_exceptions
+ mail = ExplicitLayoutMailer.create_logout(@recipient)
+ assert_equal "You logged out", mail.body.strip
+ end
+end
View
52 actionmailer/test/mail_service_test.rb
@@ -968,3 +968,55 @@ def test_send_method
end
end
end
+
+class RespondToTest < Test::Unit::TestCase
+ class RespondToMailer < ActionMailer::Base; end
+
+ def setup
+ set_delivery_method :test
+ end
+
+ def teardown
+ restore_delivery_method
+ end
+
+ def test_should_respond_to_new
+ assert RespondToMailer.respond_to?(:new)
+ end
+
+ def test_should_respond_to_create_with_template_suffix
+ assert RespondToMailer.respond_to?(:create_any_old_template)
+ end
+
+ def test_should_respond_to_deliver_with_template_suffix
+ assert RespondToMailer.respond_to?(:deliver_any_old_template)
+ end
+
+ def test_should_not_respond_to_new_with_template_suffix
+ assert !RespondToMailer.respond_to?(:new_any_old_template)
+ end
+
+ def test_should_not_respond_to_create_with_template_suffix_unless_it_is_separated_by_an_underscore
+ assert !RespondToMailer.respond_to?(:createany_old_template)
+ end
+
+ def test_should_not_respond_to_deliver_with_template_suffix_unless_it_is_separated_by_an_underscore
+ assert !RespondToMailer.respond_to?(:deliverany_old_template)
+ end
+
+ def test_should_not_respond_to_create_with_template_suffix_if_it_begins_with_a_uppercase_letter
+ assert !RespondToMailer.respond_to?(:create_Any_old_template)
+ end
+
+ def test_should_not_respond_to_deliver_with_template_suffix_if_it_begins_with_a_uppercase_letter
+ assert !RespondToMailer.respond_to?(:deliver_Any_old_template)
+ end
+
+ def test_should_not_respond_to_create_with_template_suffix_if_it_begins_with_a_digit
+ assert !RespondToMailer.respond_to?(:create_1_template)
+ end
+
+ def test_should_not_respond_to_deliver_with_template_suffix_if_it_begins_with_a_digit
+ assert !RespondToMailer.respond_to?(:deliver_1_template)
+ end
+end
View
46 actionpack/CHANGELOG
@@ -1,5 +1,51 @@
*Edge*
+* Set HttpOnly for the cookie session store's cookie. #1046
+
+* Added FormTagHelper#image_submit_tag confirm option #784 [Alastair Brunton]
+
+* Fixed FormTagHelper#submit_tag with :disable_with option wouldn't submit the button's value when was clicked #633 [Jose Fernandez]
+
+* Stopped logging template compiles as it only clogs up the log [DHH]
+
+* Changed the X-Runtime header to report in milliseconds [DHH]
+
+* Changed BenchmarkHelper#benchmark to report in milliseconds [DHH]
+
+* Changed logging format to be millisecond based and skip misleading stats [DHH]. Went from:
+
+ Completed in 0.10000 (4 reqs/sec) | Rendering: 0.04000 (40%) | DB: 0.00400 (4%) | 200 OK [http://example.com]
+
+ ...to:
+
+ Completed in 100ms (View: 40, DB: 4) | 200 OK [http://example.com]
+
+* Add support for shallow nesting of routes. #838 [S. Brent Faulkner]
+
+ Example :
+
+ map.resources :users, :shallow => true do |user|
+ user.resources :posts
+ end
+
+ - GET /users/1/posts (maps to PostsController#index action as usual)
+ named route "user_posts" is added as usual.
+
+ - GET /posts/2 (maps to PostsController#show action as if it were not nested)
+ Additionally, named route "post" is added too.
+
+* Added button_to_remote helper. #3641 [Donald Piret, Tarmo Tänav]
+
+* Deprecate render_component. Please use render_component plugin from http://github.com/rails/render_component/tree/master [Pratik]
+
+* Routes may be restricted to lists of HTTP methods instead of a single method or :any. #407 [Brennan Dunn, Gaius Centus Novus]
+ map.resource :posts, :collection => { :search => [:get, :post] }
+ map.session 'session', :requirements => { :method => [:get, :post, :delete] }
+
+* Deprecated implicit local assignments when rendering partials [Josh Peek]
+
+* Introduce current_cycle helper method to return the current value without bumping the cycle. #417 [Ken Collins]
+
* Allow polymorphic_url helper to take url options. #880 [Tarmo Tänav]
* Switched integration test runner to use Rack processor instead of CGI [Josh Peek]
View
14 actionpack/Rakefile
@@ -25,14 +25,16 @@ task :default => [ :test ]
desc "Run all unit tests"
task :test => [:test_action_pack, :test_active_record_integration]
-Rake::TestTask.new(:test_action_pack) { |t|
+Rake::TestTask.new(:test_action_pack) do |t|
t.libs << "test"
-# make sure we include the tests in alphabetical order as on some systems
-# this will not happen automatically and the tests (as a whole) will error
- t.test_files=Dir.glob( "test/[cft]*/**/*_test.rb" ).sort
-# t.pattern = 'test/*/*_test.rb'
+
+ # make sure we include the tests in alphabetical order as on some systems
+ # this will not happen automatically and the tests (as a whole) will error
+ t.test_files = Dir.glob( "test/[cft]*/**/*_test.rb" ).sort
+
t.verbose = true
-}
+ #t.warning = true
+end
desc 'ActiveRecord Integration Tests'
Rake::TestTask.new(:test_active_record_integration) do |t|
View
2  actionpack/lib/action_controller.rb
@@ -54,6 +54,7 @@
require 'action_controller/record_identifier'
require 'action_controller/request_forgery_protection'
require 'action_controller/headers'
+require 'action_controller/translation'
require 'action_view'
@@ -74,4 +75,5 @@
include ActionController::Components
include ActionController::RecordIdentifier
include ActionController::RequestForgeryProtection
+ include ActionController::Translation
end
View
28 actionpack/lib/action_controller/assertions/routing_assertions.rb
@@ -10,32 +10,32 @@ module RoutingAssertions
# and a :method containing the required HTTP verb.
#
# # assert that POSTing to /items will call the create action on ItemsController
- # assert_recognizes({:controller => 'items', :action => 'create'}, {:path => 'items', :method => :post})
+ # assert_recognizes {:controller => 'items', :action => 'create'}, {:path => 'items', :method => :post}
#
# You can also pass in +extras+ with a hash containing URL parameters that would normally be in the query string. This can be used
# to assert that values in the query string string will end up in the params hash correctly. To test query strings you must use the
# extras argument, appending the query string on the path directly will not work. For example:
#
# # assert that a path of '/items/list/1?view=print' returns the correct options
- # assert_recognizes({:controller => 'items', :action => 'list', :id => '1', :view => 'print'}, 'items/list/1', { :view => "print" })
+ # assert_recognizes {:controller => 'items', :action => 'list', :id => '1', :view => 'print'}, 'items/list/1', { :view => "print" }
#
# The +message+ parameter allows you to pass in an error message that is displayed upon failure.
#
# ==== Examples
# # Check the default route (i.e., the index action)
- # assert_recognizes({:controller => 'items', :action => 'index'}, 'items')
+ # assert_recognizes {:controller => 'items', :action => 'index'}, 'items'
#
# # Test a specific action
- # assert_recognizes({:controller => 'items', :action => 'list'}, 'items/list')
+ # assert_recognizes {:controller => 'items', :action => 'list'}, 'items/list'
#
# # Test an action with a parameter
- # assert_recognizes({:controller => 'items', :action => 'destroy', :id => '1'}, 'items/destroy/1')
+ # assert_recognizes {:controller => 'items', :action => 'destroy', :id => '1'}, 'items/destroy/1'
#
# # Test a custom route
- # assert_recognizes({:controller => 'items', :action => 'show', :id => '1'}, 'view/item1')
+ # assert_recognizes {:controller => 'items', :action => 'show', :id => '1'}, 'view/item1'
#
# # Check a Simply RESTful generated route
- # assert_recognizes(list_items_url, 'items/list')
+ # assert_recognizes list_items_url, 'items/list'
def assert_recognizes(expected_options, path, extras={}, message=nil)
if path.is_a? Hash
request_method = path[:method]
@@ -67,13 +67,13 @@ def assert_recognizes(expected_options, path, extras={}, message=nil)
#
# ==== Examples
# # Asserts that the default action is generated for a route with no action
- # assert_generates("/items", :controller => "items", :action => "index")
+ # assert_generates "/items", :controller => "items", :action => "index"
#
# # Tests that the list action is properly routed
- # assert_generates("/items/list", :controller => "items", :action => "list")
+ # assert_generates "/items/list", :controller => "items", :action => "list"
#
# # Tests the generation of a route with a parameter
- # assert_generates("/items/list/1", { :controller => "items", :action => "list", :id => "1" })
+ # assert_generates "/items/list/1", { :controller => "items", :action => "list", :id => "1" }
#
# # Asserts that the generated route gives us our custom route
# assert_generates "changesets/12", { :controller => 'scm', :action => 'show_diff', :revision => "12" }
@@ -104,19 +104,19 @@ def assert_generates(expected_path, options, defaults={}, extras = {}, message=n
#
# ==== Examples
# # Assert a basic route: a controller with the default action (index)
- # assert_routing('/home', :controller => 'home', :action => 'index')
+ # assert_routing '/home', :controller => 'home', :action => 'index'
#
# # Test a route generated with a specific controller, action, and parameter (id)
- # assert_routing('/entries/show/23', :controller => 'entries', :action => 'show', id => 23)
+ # assert_routing '/entries/show/23', :controller => 'entries', :action => 'show', id => 23
#
# # Assert a basic route (controller + default action), with an error message if it fails
- # assert_routing('/store', { :controller => 'store', :action => 'index' }, {}, {}, 'Route for store index not generated properly')
+ # assert_routing '/store', { :controller => 'store', :action => 'index' }, {}, {}, 'Route for store index not generated properly'
#
# # Tests a route, providing a defaults hash
# assert_routing 'controller/action/9', {:id => "9", :item => "square"}, {:controller => "controller", :action => "action"}, {}, {:item => "square"}
#
# # Tests a route with a HTTP method
- # assert_routing({ :method => 'put', :path => '/product/321' }, { :controller => "product", :action => "update", :id => "321" })
+ # assert_routing { :method => 'put', :path => '/product/321' }, { :controller => "product", :action => "update", :id => "321" }
def assert_routing(path, options, defaults={}, extras={}, message=nil)
assert_recognizes(options, path, extras, message)
View
86 actionpack/lib/action_controller/assertions/selector_assertions.rb
@@ -396,54 +396,31 @@ def count_description(min, max) #:nodoc:
# # The same, but shorter.
# assert_select "ol>li", 4
def assert_select_rjs(*args, &block)
- rjs_type = nil
- arg = args.shift
+ rjs_type = args.first.is_a?(Symbol) ? args.shift : nil
+ id = args.first.is_a?(String) ? args.shift : nil
# If the first argument is a symbol, it's the type of RJS statement we're looking
# for (update, replace, insertion, etc). Otherwise, we're looking for just about
# any RJS statement.
- if arg.is_a?(Symbol)
- rjs_type = arg
-
+ if rjs_type
if rjs_type == :insert
- arg = args.shift
- position = arg
- insertion = "insert_#{arg}".to_sym
- raise ArgumentError, "Unknown RJS insertion type #{arg}" unless RJS_STATEMENTS[insertion]
+ position = args.shift
+ insertion = "insert_#{position}".to_sym
+ raise ArgumentError, "Unknown RJS insertion type #{position}" unless RJS_STATEMENTS[insertion]
statement = "(#{RJS_STATEMENTS[insertion]})"
else
raise ArgumentError, "Unknown RJS statement type #{rjs_type}" unless RJS_STATEMENTS[rjs_type]
statement = "(#{RJS_STATEMENTS[rjs_type]})"
end
- arg = args.shift
else
statement = "#{RJS_STATEMENTS[:any]}"
end
- position ||= Regexp.new(RJS_INSERTIONS.join('|'))
# Next argument we're looking for is the element identifier. If missing, we pick
- # any element.
- if arg.is_a?(String)
- id = Regexp.quote(arg)
- arg = args.shift
- else
- id = "[^\"]*"
- end
-
- pattern =
- case rjs_type
- when :chained_replace, :chained_replace_html
- Regexp.new("\\$\\(\"#{id}\"\\)#{statement}\\(#{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE)
- when :remove, :show, :hide, :toggle
- Regexp.new("#{statement}\\(\"#{id}\"\\)")
- when :replace, :replace_html
- Regexp.new("#{statement}\\(\"#{id}\", #{RJS_PATTERN_HTML}\\)")
- when :insert, :insert_html
- Regexp.new("Element.insert\\(\\\"#{id}\\\", \\{ #{position}: #{RJS_PATTERN_HTML} \\}\\);")
- else
- Regexp.union(Regexp.new("#{statement}\\(\"#{id}\", #{RJS_PATTERN_HTML}\\)"),
- Regexp.new("Element.insert\\(\\\"#{id}\\\", \\{ #{position}: #{RJS_PATTERN_HTML} \\}\\);"))
- end
+ # any element, otherwise we replace it in the statement.
+ pattern = Regexp.new(
+ id ? statement.gsub(RJS_ANY_ID, "\"#{id}\"") : statement
+ )
# Duplicate the body since the next step involves destroying it.
matches = nil
@@ -472,7 +449,13 @@ def assert_select_rjs(*args, &block)
matches
else
# RJS statement not found.
- flunk args.shift || "No RJS statement that replaces or inserts HTML content."
+ case rjs_type
+ when :remove, :show, :hide, :toggle
+ flunk_message = "No RJS statement that #{rjs_type.to_s}s '#{id}' was rendered."
+ else
+ flunk_message = "No RJS statement that replaces or inserts HTML content."
+ end
+ flunk args.shift || flunk_message
end
end
@@ -582,26 +565,23 @@ def assert_select_email(&block)
protected
unless const_defined?(:RJS_STATEMENTS)
- RJS_STATEMENTS = {
- :replace => /Element\.replace/,
- :replace_html => /Element\.update/,
- :chained_replace => /\.replace/,
- :chained_replace_html => /\.update/,
- :remove => /Element\.remove/,
- :show => /Element\.show/,
- :hide => /Element\.hide/,
- :toggle => /Element\.toggle/
+ RJS_PATTERN_HTML = "\"((\\\\\"|[^\"])*)\""
+ RJS_ANY_ID = "\"([^\"])*\""
+ RJS_STATEMENTS = {
+ :chained_replace => "\\$\\(#{RJS_ANY_ID}\\)\\.replace\\(#{RJS_PATTERN_HTML}\\)",
+ :chained_replace_html => "\\$\\(#{RJS_ANY_ID}\\)\\.update\\(#{RJS_PATTERN_HTML}\\)",
+ :replace_html => "Element\\.update\\(#{RJS_ANY_ID}, #{RJS_PATTERN_HTML}\\)",
+ :replace => "Element\\.replace\\(#{RJS_ANY_ID}, #{RJS_PATTERN_HTML}\\)"
}
- RJS_STATEMENTS[:any] = Regexp.new("(#{RJS_STATEMENTS.values.join('|')})")
- RJS_PATTERN_HTML = /"((\\"|[^"])*)"/
- RJS_INSERTIONS = [:top, :bottom, :before, :after]
+ [:remove, :show, :hide, :toggle].each do |action|
+ RJS_STATEMENTS[action] = "Element\\.#{action}\\(#{RJS_ANY_ID}\\)"
+ end
+ RJS_INSERTIONS = ["top", "bottom", "before", "after"]
RJS_INSERTIONS.each do |insertion|
- RJS_STATEMENTS["insert_#{insertion}".to_sym] = /Element.insert\(\"([^\"]*)\", \{ #{insertion.to_s.downcase}: #{RJS_PATTERN_HTML} \}\);/
+ RJS_STATEMENTS["insert_#{insertion}".to_sym] = "Element.insert\\(#{RJS_ANY_ID}, \\{ #{insertion}: #{RJS_PATTERN_HTML} \\}\\)"
end
- RJS_STATEMENTS[:insert_html] = Regexp.new(RJS_INSERTIONS.collect do |insertion|
- /Element.insert\(\"([^\"]*)\", \{ #{insertion.to_s.downcase}: #{RJS_PATTERN_HTML} \}\);/
- end.join('|'))
- RJS_PATTERN_EVERYTHING = Regexp.new("#{RJS_STATEMENTS[:any]}\\(\"([^\"]*)\", #{RJS_PATTERN_HTML}\\)", Regexp::MULTILINE)
+ RJS_STATEMENTS[:insert_html] = "Element.insert\\(#{RJS_ANY_ID}, \\{ (#{RJS_INSERTIONS.join('|')}): #{RJS_PATTERN_HTML} \\}\\)"
+ RJS_STATEMENTS[:any] = Regexp.new("(#{RJS_STATEMENTS.values.join('|')})")
RJS_PATTERN_UNICODE_ESCAPED_CHAR = /\\u([0-9a-zA-Z]{4})/
end
@@ -615,8 +595,8 @@ def response_from_page_or_rjs()
root = HTML::Node.new(nil)
while true
- next if body.sub!(RJS_PATTERN_EVERYTHING) do |match|
- html = unescape_rjs($3)
+ next if body.sub!(RJS_STATEMENTS[:any]) do |match|
+ html = unescape_rjs(match)
matches = HTML::Document.new(html).root.children.select { |n| n.tag? }
root.children.concat matches
""
View
106 actionpack/lib/action_controller/base.rb
@@ -260,10 +260,11 @@ class Base
include StatusCodes
+ cattr_reader :protected_instance_variables
# Controller specific instance variables which will not be accessible inside views.
- @@protected_view_variables = %w(@assigns @performed_redirect @performed_render @variables_added @request_origin @url @parent_controller
- @action_name @before_filter_chain_aborted @action_cache_path @_session @_cookies @_headers @_params
- @_flash @_response)
+ @@protected_instance_variables = %w(@assigns @performed_redirect @performed_render @variables_added @request_origin @url @parent_controller
+ @action_name @before_filter_chain_aborted @action_cache_path @_session @_cookies @_headers @_params
+ @_flash @_response)
# Prepends all the URL-generating helpers from AssetHelper. This makes it possible to easily move javascripts, stylesheets,
# and images to a dedicated asset server away from the main web server. Example:
@@ -393,16 +394,9 @@ def self.relative_url_root
# directive. Values should always be specified as strings.
attr_internal :headers
- # Holds the hash of variables that are passed on to the template class to be made available to the view. This hash
- # is generated by taking a snapshot of all the instance variables in the current scope just before a template is rendered.
- attr_accessor :assigns
-
# Returns the name of the action this controller is processing.
attr_accessor :action_name
- # Templates that are exempt from layouts
- @@exempt_from_layout = Set.new([/\.rjs$/])
-
class << self
# Factory for the standard create, process loop where the controller is discarded after processing.
def process(request, response) #:nodoc:
@@ -440,7 +434,11 @@ def hide_action(*names)
# render("test/template") will be looked up in the view load paths array and the closest match will be
# returned.
def view_paths
- @view_paths || superclass.view_paths
+ if defined? @view_paths
+ @view_paths
+ else
+ superclass.view_paths
+ end
end
def view_paths=(value)
@@ -455,7 +453,7 @@ def view_paths=(value)
# ArticleController.prepend_view_path(["views/default", "views/custom"])
#
def prepend_view_path(path)
- @view_paths = superclass.view_paths.dup if @view_paths.nil?
+ @view_paths = superclass.view_paths.dup if !defined?(@view_paths) || @view_paths.nil?
@view_paths.unshift(*path)
end
@@ -520,13 +518,7 @@ def filter_parameter_logging(*filter_words, &block)
protected :filter_parameters
end
- # Don't render layouts for templates with the given extensions.
- def exempt_from_layout(*extensions)
- regexps = extensions.collect do |extension|
- extension.is_a?(Regexp) ? extension : /\.#{Regexp.escape(extension.to_s)}$/
- end
- @@exempt_from_layout.merge regexps
- end
+ delegate :exempt_from_layout, :to => 'ActionView::Base'
end
public
@@ -538,7 +530,6 @@ def process(request, response, method = :perform_action, *arguments) #:nodoc:
assign_shortcuts(request, response)
initialize_current_url
assign_names
- forget_variables_added_to_assigns
log_processing
@@ -548,12 +539,16 @@ def process(request, response, method = :perform_action, *arguments) #:nodoc:
@@guard.synchronize { send(method, *arguments) }
end
- response.prepare! unless component_request?
- response
+ send_response
ensure
process_cleanup
end
+ def send_response
+ response.prepare! unless component_request?
+ response
+ end
+
# Returns a URL that has been rewritten according to the options hash and the defined Routes.
# (For doing a complete redirect, use redirect_to).
#
@@ -859,7 +854,7 @@ def render(options = nil, extra_options = {}, &block) #:doc:
raise DoubleRenderError, "Can only render or redirect once per action" if performed?
if options.nil?
- return render_for_file(default_template_name, nil, true)
+ return render(:file => default_template_name, :layout => true)
elsif !extra_options.is_a?(Hash)
raise RenderError, "You called render with invalid options : #{options.inspect}, #{extra_options.inspect}"
else
@@ -870,6 +865,9 @@ def render(options = nil, extra_options = {}, &block) #:doc:
end
end
+ response.layout = layout = pick_layout(options)
+ logger.info("Rendering template within #{layout}") if logger && layout
+
if content_type = options[:content_type]
response.content_type = content_type.to_s
end
@@ -879,26 +877,21 @@ def render(options = nil, extra_options = {}, &block) #:doc:
end
if options.has_key?(:text)
- render_for_text(options[:text], options[:status])
+ text = layout ? @template.render(options.merge(:text => options[:text], :layout => layout)) : options[:text]
+ render_for_text(text, options[:status])
else
if file = options[:file]
- render_for_file(file, options[:status], nil, options[:locals] || {})
+ render_for_file(file, options[:status], layout, options[:locals] || {})
elsif template = options[:template]
- render_for_file(template, options[:status], true, options[:locals] || {})
+ render_for_file(template, options[:status], layout, options[:locals] || {})
elsif inline = options[:inline]
- add_variables_to_assigns
- render_for_text(@template.render(options), options[:status])
+ render_for_text(@template.render(options.merge(:layout => layout)), options[:status])
elsif action_name = options[:action]
- template = default_template_name(action_name.to_s)
- if options[:layout] && !template_exempt_from_layout?(template)
- render_with_a_layout(:file => template, :status => options[:status], :layout => true)
- else
- render_with_no_layout(:file => template, :status => options[:status])
- end
+ render_for_file(default_template_name(action_name.to_s), options[:status], layout)
elsif xml = options[:xml]
response.content_type ||= Mime::XML
@@ -912,12 +905,14 @@ def render(options = nil, extra_options = {}, &block) #:doc:
elsif options[:partial]
options[:partial] = default_template_name if options[:partial] == true
- add_variables_to_assigns
- render_for_text(@template.render(options), options[:status])
+ if layout
+ render_for_text(@template.render(:text => @template.render(options), :layout => layout), options[:status])
+ else
+ render_for_text(@template.render(options), options[:status])
+ end
elsif options[:update]
- add_variables_to_assigns
- @template.send! :evaluate_assigns
+ @template.send(:_evaluate_assigns_and_ivars)
generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(@template, &block)
response.content_type = Mime::JS
@@ -927,7 +922,7 @@ def render(options = nil, extra_options = {}, &block) #:doc:
render_for_text(nil, options[:status])
else
- render_for_file(default_template_name, options[:status], true)
+ render_for_file(default_template_name, options[:status], layout)
end
end
end
@@ -938,7 +933,6 @@ def render_to_string(options = nil, &block) #:doc:
render(options, &block)
ensure
erase_render_results
- forget_variables_added_to_assigns
reset_variables_added_to_assigns
end
@@ -1123,10 +1117,9 @@ def reset_session #:doc:
private
- def render_for_file(template_path, status = nil, use_full_path = nil, locals = {}) #:nodoc:
- add_variables_to_assigns
+ def render_for_file(template_path, status = nil, layout = nil, locals = {}) #:nodoc:
logger.info("Rendering #{template_path}" + (status ? " (#{status})" : '')) if logger
- render_for_text(@template.render(:file => template_path, :locals => locals), status)
+ render_for_text @template.render(:file => template_path, :locals => locals, :layout => layout), status
end
def render_for_text(text = nil, status = nil, append_response = false) #:nodoc:
@@ -1148,7 +1141,7 @@ def render_for_text(text = nil, status = nil, append_response = false) #:nodoc:
def initialize_template_class(response)
response.template = ActionView::Base.new(self.class.view_paths, {}, self)
- response.template.extend self.class.master_helper_module
+ response.template.helpers.send :include, self.class.master_helper_module
response.redirected_to = nil
@performed_render = @performed_redirect = false
end
@@ -1161,7 +1154,6 @@ def assign_shortcuts(request, response)
@_session = @_response.session
@template = @_response.template
- @assigns = @_response.template.assigns
@_headers = @_response.headers
end
@@ -1225,27 +1217,10 @@ def self.action_methods
hidden_actions
end
- def add_variables_to_assigns
- unless @variables_added
- add_instance_variables_to_assigns
- @variables_added = true
- end
- end
-
- def forget_variables_added_to_assigns
- @variables_added = nil
- end
-
def reset_variables_added_to_assigns
@template.instance_variable_set("@assigns_added", nil)
end
- def add_instance_variables_to_assigns
- (instance_variable_names - @@protected_view_variables).each do |var|
- @assigns[var[1..-1]] = instance_variable_get(var)
- end
- end
-
def request_origin
# this *needs* to be cached!
# otherwise you'd get different results if calling it more than once
@@ -1261,12 +1236,7 @@ def close_session
end
def template_exists?(template_name = default_template_name)
- @template.file_exists?(template_name)
- end
-
- def template_exempt_from_layout?(template_name = default_template_name)
- template_name = @template.pick_template(template_name).to_s if @template
- @@exempt_from_layout.any? { |ext| template_name =~ ext }
+ @template.send(:_pick_template, template_name) ? true : false
rescue ActionView::MissingTemplate
false
end
View
61 actionpack/lib/action_controller/benchmarking.rb
@@ -24,7 +24,7 @@ def benchmark(title, log_level = Logger::DEBUG, use_silence = true)
if logger && logger.level == log_level
result = nil
seconds = Benchmark.realtime { result = use_silence ? silence { yield } : yield }
- logger.add(log_level, "#{title} (#{'%.5f' % seconds})")
+ logger.add(log_level, "#{title} (#{('%.1f' % (seconds * 1000))}ms)")
result
else
yield
@@ -42,53 +42,66 @@ def silence
protected
def render_with_benchmark(options = nil, extra_options = {}, &block)
- unless logger
- render_without_benchmark(options, extra_options, &block)
- else
- db_runtime = ActiveRecord::Base.connection.reset_runtime if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected?
+ if logger
+ if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected?
+ db_runtime = ActiveRecord::Base.connection.reset_runtime
+ end
render_output = nil
- @rendering_runtime = Benchmark::realtime{ render_output = render_without_benchmark(options, extra_options, &block) }
+ @view_runtime = Benchmark::realtime { render_output = render_without_benchmark(options, extra_options, &block) }
if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected?
@db_rt_before_render = db_runtime
@db_rt_after_render = ActiveRecord::Base.connection.reset_runtime
- @rendering_runtime -= @db_rt_after_render
+ @view_runtime -= @db_rt_after_render
end
render_output
+ else
+ render_without_benchmark(options, extra_options, &block)
end
end
private
def perform_action_with_benchmark
- unless logger
- perform_action_without_benchmark
- else
- runtime = [ Benchmark::measure{ perform_action_without_benchmark }.real, 0.0001 ].max
+ if logger
+ seconds = [ Benchmark::measure{ perform_action_without_benchmark }.real, 0.0001 ].max
+ logging_view = defined?(@view_runtime)
+ logging_active_record = Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected?
+
+ log_message = "Completed in #{sprintf("%.0f", seconds * 1000)}ms"
+
+ if logging_view || logging_active_record
+ log_message << " ("
+ log_message << view_runtime if logging_view
+
+ if logging_active_record
+ log_message << ", " if logging_view
+ log_message << active_record_runtime + ")"
+ else
+ ")"
+ end
+ end
- log_message = "Completed in #{sprintf("%.5f", runtime)} (#{(1 / runtime).floor} reqs/sec)"
- log_message << rendering_runtime(runtime) if defined?(@rendering_runtime)
- log_message << active_record_runtime(runtime) if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected?
log_message << " | #{headers["Status"]}"
log_message << " [#{complete_request_uri rescue "unknown"}]"
logger.info(log_message)
- response.headers["X-Runtime"] = sprintf("%.5f", runtime)
+ response.headers["X-Runtime"] = "#{sprintf("%.0f", seconds * 1000)}ms"
+ else
+ perform_action_without_benchmark
end
end
- def rendering_runtime(runtime)
- percentage = @rendering_runtime * 100 / runtime
- " | Rendering: %.5f (%d%%)" % [@rendering_runtime, percentage.to_i]
+ def view_runtime
+ "View: %.0f" % (@view_runtime * 1000)
end
- def active_record_runtime(runtime)
- db_runtime = ActiveRecord::Base.connection.reset_runtime
- db_runtime += @db_rt_before_render if @db_rt_before_render
- db_runtime += @db_rt_after_render if @db_rt_after_render
- db_percentage = db_runtime * 100 / runtime
- " | DB: %.5f (%d%%)" % [db_runtime, db_percentage.to_i]
+ def active_record_runtime
+ db_runtime = ActiveRecord::Base.connection.reset_runtime
+ db_runtime += @db_rt_before_render if @db_rt_before_render
+ db_runtime += @db_rt_after_render if @db_rt_after_render
+ "DB: %.0f" % (db_runtime * 1000)
end
end
end
View
8 actionpack/lib/action_controller/caching/actions.rb
@@ -38,8 +38,8 @@ module Caching
# caches_action :show, :cache_path => { :project => 1 }, :expires_in => 1.hour
# caches_action :feed, :cache_path => Proc.new { |controller|
# controller.params[:user_id] ?
- # controller.send(:user_list_url, c.params[:user_id], c.params[:id]) :
- # controller.send(:list_url, c.params[:id]) }
+ # controller.send(:user_list_url, controller.params[:user_id], controller.params[:id]) :
+ # controller.send(:list_url, controller.params[:id]) }
# end
#
# If you pass :layout => false, it will only cache your action content. It is useful when your layout has dynamic information.
@@ -90,7 +90,7 @@ def before(controller)
set_content_type!(controller, cache_path.extension)
options = { :text => cache }
options.merge!(:layout => true) if cache_layout?
- controller.send!(:render, options)
+ controller.__send__(:render, options)
false
else
controller.action_cache_path = cache_path
@@ -121,7 +121,7 @@ def cache_layout?
end
def content_for_layout(controller)
- controller.response.layout && controller.response.template.instance_variable_get('@content_for_layout')
+ controller.response.layout && controller.response.template.instance_variable_get('@cached_content_for_layout')
end
end
View
6 actionpack/lib/action_controller/caching/sweeping.rb
@@ -83,13 +83,13 @@ def callback(timing)
controller_callback_method_name = "#{timing}_#{controller.controller_name.underscore}"
action_callback_method_name = "#{controller_callback_method_name}_#{controller.action_name}"
- send!(controller_callback_method_name) if respond_to?(controller_callback_method_name, true)
- send!(action_callback_method_name) if respond_to?(action_callback_method_name, true)
+ __send__(controller_callback_method_name) if respond_to?(controller_callback_method_name, true)
+ __send__(action_callback_method_name) if respond_to?(action_callback_method_name, true)
end
def method_missing(method, *arguments)
return if @controller.nil?
- @controller.send!(method, *arguments)
+ @controller.__send__(method, *arguments)
end
end
end
View
9 actionpack/lib/action_controller/cgi_process.rb
@@ -42,13 +42,14 @@ class SessionFixationAttempt < StandardError #:nodoc:
:prefix => "ruby_sess.", # prefix session file names
:session_path => "/", # available to all paths in app
:session_key => "_session_id",
- :cookie_only => true
+ :cookie_only => true,
+ :session_http_only=> true
}
def initialize(cgi, session_options = {})
@cgi = cgi
@session_options = session_options
- @env = @cgi.send!(:env_table)
+ @env = @cgi.__send__(:env_table)
super()
end
@@ -107,7 +108,7 @@ def reset_session
end
def method_missing(method_id, *arguments)
- @cgi.send!(method_id, *arguments) rescue super
+ @cgi.__send__(method_id, *arguments) rescue super
end
private
@@ -164,7 +165,7 @@ def out(output = $stdout)
begin
output.write(@cgi.header(@headers))
- if @cgi.send!(:env_table)['REQUEST_METHOD'] == 'HEAD'
+ if @cgi.__send__(:env_table)['REQUEST_METHOD'] == 'HEAD'
return
elsif @body.respond_to?(:call)
# Flush the output now in case the @body Proc uses
View
5 actionpack/lib/action_controller/components.rb
@@ -38,6 +38,7 @@ module Components
def self.included(base) #:nodoc:
base.class_eval do
include InstanceMethods
+ include ActiveSupport::Deprecation
extend ClassMethods
helper HelperMethods
@@ -64,7 +65,7 @@ def process_with_components(request, response, parent_controller = nil) #:nodoc:
module HelperMethods
def render_component(options)
- @controller.send!(:render_component_as_string, options)
+ @controller.__send__(:render_component_as_string, options)
end
end
@@ -82,6 +83,7 @@ def render_component(options) #:doc:
render_for_text(component_response(options, true).body, response.headers["Status"])
end
end
+ deprecate :render_component => "Please install render_component plugin from http://github.com/rails/render_component/tree/master"
# Returns the component response as a string
def render_component_as_string(options) #:doc:
@@ -95,6 +97,7 @@ def render_component_as_string(options) #:doc:
end
end
end
+ deprecate :render_component_as_string => "Please install render_component plugin from http://github.com/rails/render_component/tree/master"
def flash_with_components(refresh = false) #:nodoc:
if !defined?(@_flash) || refresh
View
8 actionpack/lib/action_controller/filters.rb
@@ -199,8 +199,8 @@ def around_proc
Proc.new do |controller, action|
method.before(controller)
- if controller.send!(:performed?)
- controller.send!(:halt_filter_chain, method, :rendered_or_redirected)
+ if controller.__send__(:performed?)
+ controller.__send__(:halt_filter_chain, method, :rendered_or_redirected)
else
begin
action.call
@@ -223,8 +223,8 @@ def before?
def call(controller, &block)
super
- if controller.send!(:performed?)
- controller.send!(:halt_filter_chain, method, :rendered_or_redirected)
+ if controller.__send__(:performed?)
+ controller.__send__(:halt_filter_chain, method, :rendered_or_redirected)
end
end
end
View
4 actionpack/lib/action_controller/helpers.rb
@@ -204,8 +204,8 @@ def inherited_with_helper(child)
begin
child.master_helper_module = Module.new
- child.master_helper_module.send! :include, master_helper_module
- child.send! :default_helper_module!
+ child.master_helper_module.__send__ :include, master_helper_module
+ child.__send__ :default_helper_module!
rescue MissingSourceFile => e
raise unless e.is_missing?("helpers/#{child.controller_path}_helper")
end
View
2  actionpack/lib/action_controller/http_authentication.rb
@@ -117,7 +117,7 @@ def encode_credentials(user_name, password)
def authentication_request(controller, realm)
controller.headers["WWW-Authenticate"] = %(Basic realm="#{realm.gsub(/"/, "")}")
- controller.send! :render, :text => "HTTP Basic: Access denied.\n", :status => :unauthorized
+ controller.__send__ :render, :text => "HTTP Basic: Access denied.\n", :status => :unauthorized
end
end
end
View
8 actionpack/lib/action_controller/integration.rb
@@ -444,7 +444,7 @@ def reset!
reset! unless @integration_session
# reset the html_document variable, but only for new get/post calls
@html_document = nil unless %w(cookies assigns).include?(method)
- returning @integration_session.send!(method, *args) do
+ returning @integration_session.__send__(method, *args) do
copy_session_variables!
end
end
@@ -469,12 +469,12 @@ def open_session
self.class.fixture_table_names.each do |table_name|
name = table_name.tr(".", "_")
next unless respond_to?(name)
- extras.send!(:define_method, name) { |*args| delegate.send(name, *args) }
+ extras.__send__(:define_method, name) { |*args| delegate.send(name, *args) }
end
end
# delegate add_assertion to the test case
- extras.send!(:define_method, :add_assertion) { test_result.add_assertion }
+ extras.__send__(:define_method, :add_assertion) { test_result.add_assertion }
session.extend(extras)
session.delegate = self
session.test_result = @_result
@@ -488,7 +488,7 @@ def open_session
def copy_session_variables! #:nodoc:
return unless @integration_session
%w(controller response request).each do |var|
- instance_variable_set("@#{var}", @integration_session.send!(var))
+ instance_variable_set("@#{var}", @integration_session.__send__(var))
end
end
View
80 actionpack/lib/action_controller/layout.rb
@@ -3,11 +3,6 @@ module Layout #:nodoc:
def self.included(base)
base.extend(ClassMethods)
base.class_eval do
- # NOTE: Can't use alias_method_chain here because +render_without_layout+ is already
- # defined as a publicly exposed method
- alias_method :render_with_no_layout, :render
- alias_method :render, :render_with_a_layout
-
class << self
alias_method_chain :inherited, :layout
end
@@ -169,17 +164,17 @@ module ClassMethods
# performance and have access to them as any normal template would.
def layout(template_name, conditions = {}, auto = false)
add_layout_conditions(conditions)
- write_inheritable_attribute "layout", template_name
- write_inheritable_attribute "auto_layout", auto
+ write_inheritable_attribute(:layout, template_name)
+ write_inheritable_attribute(:auto_layout, auto)
end
def layout_conditions #:nodoc:
- @layout_conditions ||= read_inheritable_attribute("layout_conditions")
+ @layout_conditions ||= read_inheritable_attribute(:layout_conditions)
end
def default_layout(format) #:nodoc:
- layout = read_inheritable_attribute("layout")
- return layout unless read_inheritable_attribute("auto_layout")
+ layout = read_inheritable_attribute(:layout)
+ return layout unless read_inheritable_attribute(:auto_layout)
@default_layout ||= {}
@default_layout[format] ||= default_layout_with_format(format, layout)
@default_layout[format]
@@ -199,7 +194,7 @@ def inherited_with_layout(child)
end
def add_layout_conditions(conditions)
- write_inheritable_hash "layout_conditions", normalize_conditions(conditions)
+ write_inheritable_hash(:layout_conditions, normalize_conditions(conditions))
end
def normalize_conditions(conditions)
@@ -221,10 +216,10 @@ def default_layout_with_format(format, layout)
# object). If the layout was defined without a directory, layouts is assumed. So <tt>layout "weblog/standard"</tt> will return
# weblog/standard, but <tt>layout "standard"</tt> will return layouts/standard.
def active_layout(passed_layout = nil)
- layout = passed_layout || self.class.default_layout(response.template.template_format)
+ layout = passed_layout || self.class.default_layout(default_template_format)
active_layout = case layout
when String then layout
- when Symbol then send!(layout)
+ when Symbol then __send__(layout)
when Proc then layout.call(self)
end
@@ -240,51 +235,24 @@ def active_layout(passed_layout = nil)
end
end
- protected
- def render_with_a_layout(options = nil, extra_options = {}, &block) #:nodoc:
- template_with_options = options.is_a?(Hash)
-
- if (layout = pick_layout(template_with_options, options)) && apply_layout?(template_with_options, options)
- options = options.merge :layout => false if template_with_options
- logger.info("Rendering template within #{layout}") if logger
-
- content_for_layout = render_with_no_layout(options, extra_options, &block)
- erase_render_results
- add_variables_to_assigns
- @template.instance_variable_set("@content_for_layout", content_for_layout)
- response.layout = layout
- status = template_with_options ? options[:status] : nil
- render_for_text(@template.render(layout), status)
- else
- render_with_no_layout(options, extra_options, &block)
- end
- end
-
-
private
- def apply_layout?(template_with_options, options)
- return false if options == :update
- template_with_options ? candidate_for_layout?(options) : !template_exempt_from_layout?
- end
-
def candidate_for_layout?(options)
- (options.has_key?(:layout) && options[:layout] != false) ||
- options.values_at(:text, :xml, :json, :file, :inline, :partial, :nothing).compact.empty? &&
- !template_exempt_from_layout?(options[:template] || default_template_name(options[:action]))
+ options.values_at(:text, :xml, :json, :file, :inline, :partial, :nothing, :update).compact.empty? &&
+ !@template.__send__(:_exempt_from_layout?, options[:template] || default_template_name(options[:action]))
end
- def pick_layout(template_with_options, options)
- if template_with_options
- case layout = options[:layout]
- when FalseClass
- nil
- when NilClass, TrueClass
- active_layout if action_has_layout?
- else
- active_layout(layout)
+ def pick_layout(options)
+ if options.has_key?(:layout)
+ case layout = options.delete(:layout)
+ when FalseClass
+ nil
+ when NilClass, TrueClass
+ active_layout if action_has_layout? && !@template.__send__(:_exempt_from_layout?, default_template_name)
+ else
+ active_layout(layout)
end
else
- active_layout if action_has_layout?
+ active_layout if action_has_layout? && candidate_for_layout?(options)
end
end
@@ -304,7 +272,13 @@ def action_has_layout?
end
def layout_directory?(layout_name)
- @template.file_exists?("#{File.join('layouts', layout_name)}.#{@template.template_format}")
+ @template.__send__(:_pick_template, "#{File.join('layouts', layout_name)}.#{@template.template_format}") ? true : false
+ rescue ActionView::MissingTemplate
+ false
+ end
+
+ def default_template_format
+ response.template.template_format
end
end
end
View
2  actionpack/lib/action_controller/mime_type.rb
@@ -1,3 +1,5 @@
+require 'set'
+
module Mime
SET = []
EXTENSION_LOOKUP = Hash.new { |h, k| h[k] = Type.new(k) unless k.blank? }
View
6 actionpack/lib/action_controller/polymorphic_routes.rb
@@ -108,7 +108,7 @@ def polymorphic_url(record_or_hash_or_array, options = {})
args.last.kind_of?(Hash) ? args.last.merge!(url_options) : args << url_options
end
- send!(named_route, *args)
+ __send__(named_route, *args)
end
# Returns the path component of a URL for the given record. It uses
@@ -149,7 +149,7 @@ def build_named_route_call(records, namespace, inflection, options = {})
if parent.is_a?(Symbol) || parent.is_a?(String)
string << "#{parent}_"
else
- string << "#{RecordIdentifier.send!("singular_class_name", parent)}_"
+ string << "#{RecordIdentifier.__send__("singular_class_name", parent)}_"
end
end
end
@@ -157,7 +157,7 @@ def build_named_route_call(records, namespace, inflection, options = {})
if record.is_a?(Symbol) || record.is_a?(String)
route << "#{record}_"
else
- route << "#{RecordIdentifier.send!("#{inflection}_class_name", record)}_"
+ route << "#{RecordIdentifier.__send__("#{inflection}_class_name", record)}_"
end
action_prefix(options) + namespace + route + routing_type(options).to_s
View
3  actionpack/lib/action_controller/rack_process.rb
@@ -14,7 +14,8 @@ class SessionFixationAttempt < StandardError #:nodoc:
:prefix => "ruby_sess.", # prefix session file names
:session_path => "/", # available to all paths in app
:session_key => "_session_id",
- :cookie_only => true
+ :cookie_only => true,
+ :session_http_only=> true
}
def initialize(env, session_options = DEFAULT_SESSION_OPTIONS)
View
77 actionpack/lib/action_controller/request.rb 100644 → 100755
@@ -22,7 +22,7 @@ def self.relative_url_root=(*args)
# such as { 'RAILS_ENV' => 'production' }.
attr_reader :env
- # The true HTTP request method as a lowercase symbol, such as <tt>:get</tt>.
+ # The true HTTP request \method as a lowercase symbol, such as <tt>:get</tt>.
# UnknownHttpMethod is raised for invalid methods not listed in ACCEPTED_HTTP_METHODS.
def request_method
method = @env['REQUEST_METHOD']
@@ -32,7 +32,7 @@ def request_method
end
memoize :request_method
- # The HTTP request method as a lowercase symbol, such as <tt>:get</tt>.
+ # The HTTP request \method as a lowercase symbol, such as <tt>:get</tt>.
# Note, HEAD is returned as <tt>:get</tt> since the two are functionally
# equivalent from the application's perspective.
def method
@@ -59,19 +59,21 @@ def delete?
request_method == :delete
end
- # Is this a HEAD request? <tt>request.method</tt> sees HEAD as <tt>:get</tt>,
- # so check the HTTP method directly.
+ # Is this a HEAD request? Since <tt>request.method</tt> sees HEAD as <tt>:get</tt>,
+ # this \method checks the actual HTTP \method directly.
def head?
request_method == :head
end
# Provides access to the request's HTTP headers, for example:
- # request.headers["Content-Type"] # => "text/plain"
+ #
+ # request.headers["Content-Type"] # => "text/plain"
def headers
ActionController::Http::Headers.new(@env)
end
memoize :headers
+ # Returns the content length of the request as an integer.
def content_length
@env['CONTENT_LENGTH'].to_i
end
@@ -79,14 +81,14 @@ def content_length
# The MIME type of the HTTP request, such as Mime::XML.
#
- # For backward compatibility, the post format is extracted from the
+ # For backward compatibility, the post \format is extracted from the
# X-Post-Data-Format HTTP header if present.
def content_type
Mime::Type.lookup(content_type_without_parameters)
end
memoize :content_type
- # Returns the accepted MIME type for the request
+ # Returns the accepted MIME type for the request.
def accepts
header = @env['HTTP_ACCEPT'].to_s.strip
@@ -123,7 +125,7 @@ def fresh?(response)
not_modified?(response.last_modified) || etag_matches?(response.etag)
end
- # Returns the Mime type for the format used in the request.
+ # Returns the Mime type for the \format used in the request.
#
# GET /posts/5.xml | request.format => Mime::XML
# GET /posts/5.xhtml | request.format => Mime::HTML
@@ -142,8 +144,8 @@ def format
end
- # Sets the format by string extension, which can be used to force custom formats that are not controlled by the extension.
- # Example:
+ # Sets the \format by string extension, which can be used to force custom formats
+ # that are not controlled by the extension.
#
# class ApplicationController < ActionController::Base
# before_filter :adjust_format_for_iphone
@@ -159,7 +161,7 @@ def format=(extension)
end
# Returns a symbolized version of the <tt>:format</tt> parameter of the request.
- # If no format is given it returns <tt>:js</tt>for AJAX requests and <tt>:html</tt>
+ # If no \format is given it returns <tt>:js</tt>for Ajax requests and <tt>:html</tt>
# otherwise.
def template_format
parameter_format = parameters[:format]
@@ -190,17 +192,19 @@ def xml_http_request?
# the right-hand-side of X-Forwarded-For
TRUSTED_PROXIES = /^127\.0\.0\.1$|^(10|172\.(1[6-9]|2[0-9]|30|31)|192\.168)\./i
- # Determine originating IP address. REMOTE_ADDR is the standard
+ # Determines originating IP address. REMOTE_ADDR is the standard
# but will fail if the user is behind a proxy. HTTP_CLIENT_IP and/or
# HTTP_X_FORWARDED_FOR are set by proxies so check for these if
# REMOTE_ADDR is a proxy. HTTP_X_FORWARDED_FOR may be a comma-
# delimited list in the case of multiple chained proxies; the last
# address which is not trusted is the originating IP.
def remote_ip
- if TRUSTED_PROXIES !~ @env['REMOTE_ADDR']
- return @env['REMOTE_ADDR']
- end
+ remote_addr_list = @env['REMOTE_ADDR'] && @env['REMOTE_ADDR'].split(',').collect(&:strip)
+ unless remote_addr_list.blank?
+ not_trusted_addrs = remote_addr_list.reject {|addr| addr =~ TRUSTED_PROXIES}
+ return not_trusted_addrs.first unless not_trusted_addrs.empty?
+ end
remote_ips = @env['HTTP_X_FORWARDED_FOR'] && @env['HTTP_X_FORWARDED_FOR'].split(',')
if @env.include? 'HTTP_CLIENT_IP'
@@ -235,13 +239,13 @@ def server_software
memoize :server_software
- # Returns the complete URL used for this request
+ # Returns the complete URL used for this request.
def url
protocol + host_with_port + request_uri
end
memoize :url
- # Return 'https://' if this is an SSL request and 'http://' otherwise.
+ # Returns 'https://' if this is an SSL request and 'http://' otherwise.
def protocol
ssl? ? 'https://' : 'http://'
end
@@ -252,6 +256,7 @@ def ssl?
@env['HTTPS'] == 'on' || @env['HTTP_X_FORWARDED_PROTO'] == 'https'
end
+ # Returns the \host for this request, such as "example.com".
def raw_host_with_port
if forwarded = env["HTTP_X_FORWARDED_HOST"]
forwarded.split(/,\s?/).last
@@ -266,8 +271,8 @@ def host
end
memoize :host
- # Returns a host:port string for this request, such as example.com or
- # example.com:8080.
+ # Returns a \host:\port string for this request, such as "example.com" or
+ # "example.com:8080".
def host_with_port
"#{host}#{port_string}"
end
@@ -283,7 +288,7 @@ def port
end
memoize :port
- # Returns the standard port number for this request's protocol
+ # Returns the standard \port number for this request's protocol.
def standard_port
case protocol
when 'https://' then 443
@@ -291,13 +296,13 @@ def standard_port
end
end
- # Returns a port suffix like ":8080" if the port number of this request
- # is not the default HTTP port 80 or HTTPS port 443.
+ # Returns a \port suffix like ":8080" if the \port number of this request
+ # is not the default HTTP \port 80 or HTTPS \port 443.
def port_string
port == standard_port ? '' : ":#{port}"
end
- # Returns the domain part of a host, such as rubyonrails.org in "www.rubyonrails.org". You can specify
+ # Returns the \domain part of a \host, such as "rubyonrails.org" in "www.rubyonrails.org". You can specify
# a different <tt>tld_length</tt>, such as 2 to catch rubyonrails.co.uk in "www.rubyonrails.co.uk".
def domain(tld_length = 1)
return nil unless named_host?(host)
@@ -305,8 +310,9 @@ def domain(tld_length = 1)
host.split('.').last(1 + tld_length).join('.')
end
- # Returns all the subdomains as an array, so ["dev", "www"] would be returned for "dev.www.rubyonrails.org".
- # You can specify a different <tt>tld_length</tt>, such as 2 to catch ["www"] instead of ["www", "rubyonrails"]
+ # Returns all the \subdomains as an array, so <tt>["dev", "www"]</tt> would be
+ # returned for "dev.www.rubyonrails.org". You can specify a different <tt>tld_length</tt>,
+ # such as 2 to catch <tt>["www"]</tt> instead of <tt>["www", "rubyonrails"]</tt>
# in "www.rubyonrails.co.uk".
def subdomains(tld_length = 1)
return [] unless named_host?(host)
@@ -314,7 +320,7 @@ def subdomains(tld_length = 1)
parts[0..-(tld_length+2)]
end
- # Return the query string, accounting for server idiosyncrasies.
+ # Returns the query string, accounting for server idiosyncrasies.