Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Resolved conflict

  • Loading branch information...
commit 73ade4fe100ae7f48c5f95dcdf7067f6a0cd51fa 2 parents 8fe01de + 90c930f
@dhh dhh authored
Showing with 5,080 additions and 1,990 deletions.
  1. +1 −1  actionmailer/lib/action_mailer/base.rb
  2. +2 −2 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/address.rb
  3. +1 −1  actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/header.rb
  4. +1 −1  actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/interface.rb
  5. +2 −2 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/mail.rb
  6. +1 −2  actionmailer/test/abstract_unit.rb
  7. +47 −0 actionpack/CHANGELOG
  8. +6 −12 actionpack/README
  9. +29 −78 actionpack/lib/action_controller/assertions/response_assertions.rb
  10. +2 −4 actionpack/lib/action_controller/assertions/selector_assertions.rb
  11. +45 −32 actionpack/lib/action_controller/base.rb
  12. +12 −11 actionpack/lib/action_controller/caching/actions.rb
  13. +2 −4 actionpack/lib/action_controller/caching/fragments.rb
  14. +10 −0 actionpack/lib/action_controller/cookies.rb
  15. +219 −195 actionpack/lib/action_controller/filters.rb
  16. +1 −1  actionpack/lib/action_controller/integration.rb
  17. +1 −1  actionpack/lib/action_controller/layout.rb
  18. +5 −1 actionpack/lib/action_controller/mime_responds.rb
  19. +43 −39 actionpack/lib/action_controller/mime_type.rb
  20. +3 −7 actionpack/lib/action_controller/rack_process.rb
  21. +44 −11 actionpack/lib/action_controller/request.rb
  22. +1 −1  actionpack/lib/action_controller/request_forgery_protection.rb
  23. +16 −12 actionpack/lib/action_controller/rescue.rb
  24. +4 −0 actionpack/lib/action_controller/resources.rb
  25. +4 −0 actionpack/lib/action_controller/routing.rb
  26. +1 −2  actionpack/lib/action_controller/routing/builder.rb
  27. +15 −8 actionpack/lib/action_controller/streaming.rb
  28. +23 −0 actionpack/lib/action_controller/test_case.rb
  29. +5 −25 actionpack/lib/action_controller/test_process.rb
  30. +2 −2 actionpack/lib/action_controller/vendor/html-scanner/html/selector.rb
  31. +5 −3 actionpack/lib/action_view.rb
  32. +88 −79 actionpack/lib/action_view/base.rb
  33. +1 −1  actionpack/lib/action_view/helpers/active_record_helper.rb
  34. +44 −18 actionpack/lib/action_view/helpers/asset_tag_helper.rb
  35. +1 −2  actionpack/lib/action_view/helpers/cache_helper.rb
  36. +10 −10 actionpack/lib/action_view/helpers/capture_helper.rb
  37. +30 −18 actionpack/lib/action_view/helpers/date_helper.rb
  38. +20 −13 actionpack/lib/action_view/helpers/debug_helper.rb
  39. +47 −14 actionpack/lib/action_view/helpers/form_helper.rb
  40. +13 −11 actionpack/lib/action_view/helpers/form_options_helper.rb
  41. +19 −30 actionpack/lib/action_view/helpers/javascript_helper.rb
  42. +197 −192 actionpack/lib/action_view/helpers/prototype_helper.rb
  43. +1 −1  actionpack/lib/action_view/helpers/sanitize_helper.rb
  44. +1 −1  actionpack/lib/action_view/helpers/scriptaculous_helper.rb
  45. +13 −7 actionpack/lib/action_view/helpers/tag_helper.rb
  46. +1 −1  actionpack/lib/action_view/helpers/text_helper.rb
  47. +4 −6 actionpack/lib/action_view/helpers/url_helper.rb
  48. +11 −9 actionpack/lib/action_view/inline_template.rb
  49. +0 −74 actionpack/lib/action_view/partial_template.rb
  50. +21 −22 actionpack/lib/action_view/partials.rb
  51. +104 −0 actionpack/lib/action_view/paths.rb
  52. +87 −0 actionpack/lib/action_view/renderable.rb
  53. +36 −0 actionpack/lib/action_view/renderable_partial.rb
  54. +65 −63 actionpack/lib/action_view/template.rb
  55. +2 −2 actionpack/lib/action_view/template_error.rb
  56. +0 −88 actionpack/lib/action_view/template_file.rb
  57. +1 −13 actionpack/lib/action_view/template_handler.rb
  58. +5 −15 actionpack/lib/action_view/template_handlers/builder.rb
  59. +2 −116 actionpack/lib/action_view/template_handlers/compilable.rb
  60. +0 −6 actionpack/lib/action_view/template_handlers/erb.rb
  61. +2 −17 actionpack/lib/action_view/template_handlers/rjs.rb
  62. +0 −99 actionpack/lib/action_view/view_load_paths.rb
  63. +3 −1 actionpack/test/abstract_unit.rb
  64. +9 −8 actionpack/test/activerecord/render_partial_with_record_identification_test.rb
  65. +7 −33 actionpack/test/controller/action_pack_assertions_test.rb
  66. +0 −2  actionpack/test/controller/addresses_render_test.rb
  67. +73 −66 actionpack/test/controller/caching_test.rb
  68. +0 −2  actionpack/test/controller/capture_test.rb
  69. +46 −4 actionpack/test/controller/cgi_test.rb
  70. +1 −1  actionpack/test/controller/components_test.rb
  71. +14 −2 actionpack/test/controller/content_type_test.rb
  72. +0 −2  actionpack/test/controller/deprecation/deprecated_base_methods_test.rb
  73. +3 −2 actionpack/test/controller/layout_test.rb
  74. +5 −2 actionpack/test/controller/mime_responds_test.rb
  75. +10 −9 actionpack/test/controller/new_render_test.rb
  76. +77 −4 actionpack/test/controller/rack_test.rb
  77. +8 −16 actionpack/test/controller/redirect_test.rb
  78. +10 −13 actionpack/test/controller/render_test.rb
  79. +1 −1  actionpack/test/controller/request_test.rb
  80. +9 −0 actionpack/test/controller/rescue_test.rb
  81. +15 −17 actionpack/test/controller/resources_test.rb
  82. +20 −0 actionpack/test/controller/routing_test.rb
  83. +0 −2  actionpack/test/controller/send_file_test.rb
  84. +0 −18 actionpack/test/controller/test_test.rb
  85. +0 −16 actionpack/test/controller/view_paths_test.rb
  86. +1 −0  actionpack/test/fixtures/developers/_developer.erb
  87. +1 −0  actionpack/test/fixtures/fun/games/_game.erb
  88. +1 −0  actionpack/test/fixtures/fun/serious/games/_game.erb
  89. +3 −0  actionpack/test/fixtures/functional_caching/formatted_fragment_cached.html.erb
  90. +6 −0 actionpack/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs
  91. +5 −0 actionpack/test/fixtures/functional_caching/formatted_fragment_cached.xml.builder
  92. +2 −0  actionpack/test/fixtures/functional_caching/inline_fragment_cached.html.erb
  93. +1 −0  actionpack/test/fixtures/projects/_project.erb
  94. +1 −0  actionpack/test/fixtures/public/javascripts/subdir/subdir.js
  95. +1 −0  actionpack/test/fixtures/public/stylesheets/subdir/subdir.css
  96. +1 −0  actionpack/test/fixtures/replies/_reply.erb
  97. +1 −0  actionpack/test/fixtures/test/hyphen-ated.erb
  98. +45 −1 actionpack/test/template/asset_tag_helper_test.rb
  99. +41 −0 actionpack/test/template/compiled_templates_test.rb
  100. +15 −0 actionpack/test/template/date_helper_test.rb
  101. +907 −22 actionpack/test/template/form_options_helper_test.rb
  102. +3 −5 actionpack/test/template/javascript_helper_test.rb
  103. +8 −4 actionpack/test/template/prototype_helper_test.rb
  104. +7 −8 actionpack/test/template/render_test.rb
  105. +11 −9 actionpack/test/template/url_helper_test.rb
  106. +27 −0 activerecord/CHANGELOG
  107. +13 −4 activerecord/lib/active_record/association_preload.rb
  108. +28 −14 activerecord/lib/active_record/associations.rb
  109. +13 −4 activerecord/lib/active_record/associations/association_collection.rb
  110. +10 −2 activerecord/lib/active_record/associations/has_many_association.rb
  111. +10 −1 activerecord/lib/active_record/associations/has_one_association.rb
  112. +5 −6 activerecord/lib/active_record/base.rb
  113. +3 −3 activerecord/lib/active_record/callbacks.rb
  114. +8 −6 activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
  115. +1 −1  activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
  116. +13 −0 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
  117. +31 −9 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
  118. +14 −2 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
  119. +12 −0 activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
  120. +6 −6 activerecord/lib/active_record/dirty.rb
  121. +8 −7 activerecord/lib/active_record/fixtures.rb
  122. +2 −1  activerecord/lib/active_record/named_scope.rb
  123. +4 −5 activerecord/lib/active_record/observer.rb
  124. +13 −2 activerecord/lib/active_record/test_case.rb
  125. +3 −14 activerecord/lib/active_record/transactions.rb
  126. +35 −31 activerecord/lib/active_record/validations.rb
  127. +6 −0 activerecord/test/cases/adapter_test.rb
  128. +35 −0 activerecord/test/cases/associations/has_many_associations_test.rb
  129. +7 −0 activerecord/test/cases/associations/has_one_associations_test.rb
  130. +108 −0 activerecord/test/cases/associations_test.rb
  131. +19 −2 activerecord/test/cases/base_test.rb
  132. +36 −0 activerecord/test/cases/column_definition_test.rb
  133. +32 −3 activerecord/test/cases/fixtures_test.rb
  134. +5 −5 activerecord/test/cases/helper.rb
  135. +7 −0 activerecord/test/cases/inheritance_test.rb
  136. +10 −2 activerecord/test/cases/lifecycle_test.rb
  137. +56 −1 activerecord/test/cases/migration_test.rb
  138. +25 −0 activerecord/test/cases/multiple_db_test.rb
  139. +26 −0 activerecord/test/cases/named_scope_test.rb
  140. +3 −3 activerecord/test/cases/reflection_test.rb
  141. +18 −5 activerecord/test/cases/validations_test.rb
  142. +1 −0  activerecord/test/fixtures/companies.yml
  143. +1 −1  activerecord/test/models/author.rb
  144. +3 −0  activerecord/test/models/company.rb
  145. +6 −0 activerecord/test/models/post.rb
  146. +2 −0  activerecord/test/models/topic.rb
  147. +2 −0  activerecord/test/schema/schema.rb
  148. +1 −1  activeresource/README
  149. +11 −11 activeresource/lib/active_resource/base.rb
  150. +2 −2 activeresource/lib/active_resource/custom_methods.rb
  151. +1 −1  activeresource/lib/active_resource/http_mock.rb
  152. +14 −0 activesupport/CHANGELOG
  153. +1 −0  activesupport/lib/active_support.rb
  154. +9 −1 activesupport/lib/active_support/callbacks.rb
  155. +45 −2 activesupport/lib/active_support/core_ext/array/grouping.rb
  156. +1 −1  activesupport/lib/active_support/core_ext/bigdecimal/conversions.rb
  157. +1 −1  activesupport/lib/active_support/core_ext/hash/except.rb
  158. +12 −5 activesupport/lib/active_support/core_ext/hash/reverse_merge.rb
  159. +18 −7 activesupport/lib/active_support/core_ext/module/introspection.rb
  160. +1 −0  activesupport/lib/active_support/core_ext/object.rb
  161. +1 −1  activesupport/lib/active_support/core_ext/object/instance_variables.rb
  162. +8 −0 activesupport/lib/active_support/core_ext/object/metaclass.rb
  163. +2 −2 activesupport/lib/active_support/core_ext/string/inflections.rb
  164. +0 −1  activesupport/lib/active_support/core_ext/test.rb
  165. +1 −1  activesupport/lib/active_support/core_ext/time/calculations.rb
  166. +2 −2 activesupport/lib/active_support/dependencies.rb
  167. +1 −1  activesupport/lib/active_support/json.rb
  168. +9 −2 activesupport/lib/active_support/json/encoders/date.rb
  169. +10 −3 activesupport/lib/active_support/json/encoders/date_time.rb
  170. +10 −3 activesupport/lib/active_support/json/encoders/time.rb
  171. +35 −0 activesupport/lib/active_support/memoizable.rb
  172. +1 −5 activesupport/lib/active_support/test_case.rb
  173. +6 −0 activesupport/lib/active_support/testing/core_ext/test.rb
  174. +4 −3 activesupport/lib/active_support/{ → testing}/core_ext/test/unit/assertions.rb
  175. +14 −2 activesupport/lib/active_support/time_with_zone.rb
  176. +1 −1  activesupport/lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb
  177. +2 −2 activesupport/lib/active_support/vendor/memcache-client-1.5.0/memcache.rb
  178. +1 −1  activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/data_timezone.rb
  179. +1 −1  activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/data_timezone_info.rb
  180. +1 −1  activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/linked_timezone.rb
  181. +1 −1  activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/timezone.rb
  182. +1 −1  activesupport/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/timezone_transition_info.rb
  183. +3 −3 activesupport/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb
  184. +24 −0 activesupport/test/callbacks_test.rb
  185. +46 −4 activesupport/test/core_ext/array_ext_test.rb
  186. +8 −0 activesupport/test/core_ext/object_and_class_ext_test.rb
  187. +6 −0 activesupport/test/core_ext/time_with_zone_test.rb
  188. +49 −0 activesupport/test/memoizable_test.rb
  189. +0 −1  cleanlogs.sh
  190. +7 −0 railties/CHANGELOG
  191. +17 −0 railties/config.ru
  192. +2 −0  railties/configs/routes.rb
  193. +91 −0 railties/doc/guides/actionview/helpers.markdown
  194. +90 −0 railties/doc/guides/actionview/partials.markdown
  195. +56 −0 railties/doc/guides/activerecord/basics.markdown
  196. +861 −0 railties/doc/guides/creating_plugins/basics.markdown
  197. +4 −4 railties/environments/boot.rb
  198. +0 −1  railties/environments/production.rb
  199. +1 −5 railties/helpers/performance_test_helper.rb
  200. +32 −15 railties/lib/commands/plugin.rb
  201. +2 −2 railties/lib/commands/process/spawner.rb
  202. +1 −1  railties/lib/console_with_helpers.rb
  203. +50 −33 railties/lib/initializer.rb
  204. +5 −0 railties/lib/performance_test_help.rb
  205. +1 −1  railties/lib/rails/plugin/locator.rb
  206. +9 −16 railties/lib/rails_generator/commands.rb
  207. +1 −0  railties/lib/rails_generator/generators/applications/app/app_generator.rb
  208. +9 −5 railties/lib/rails_generator/generators/components/scaffold/USAGE
  209. +1 −1  railties/lib/rails_generator/lookup.rb
  210. +1 −1  railties/lib/rails_generator/scripts.rb
  211. +6 −7 railties/lib/rails_generator/scripts/destroy.rb
  212. +1 −1  railties/lib/rails_generator/secret_key_generator.rb
  213. +8 −11 railties/lib/tasks/annotations.rake
  214. +20 −14 railties/lib/tasks/databases.rake
  215. +1 −1  railties/lib/tasks/misc.rake
  216. +1 −1  railties/test/generators/generator_test_helper.rb
  217. +19 −0 railties/test/generators/rails_controller_generator_test.rb
View
2  actionmailer/lib/action_mailer/base.rb
@@ -426,7 +426,7 @@ def register_template_extension(extension)
end
def template_root=(root)
- write_inheritable_attribute(:template_root, ActionView::ViewLoadPaths.new(Array(root)))
+ write_inheritable_attribute(:template_root, ActionView::PathSet.new(Array(root)))
end
end
View
4 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/address.rb
@@ -38,7 +38,7 @@ module TMail
# = Class Address
#
# Provides a complete handling library for email addresses. Can parse a string of an
- # address directly or take in preformatted addresses themseleves. Allows you to add
+ # address directly or take in preformatted addresses themselves. Allows you to add
# and remove phrases from the front of the address and provides a compare function for
# email addresses.
#
@@ -143,7 +143,7 @@ def initialize( local, domain )
# This is to catch an unquoted "@" symbol in the local part of the
# address. Handles addresses like <"@"@me.com> and makes sure they
- # stay like <"@"@me.com> (previously were becomming <@@me.com>)
+ # stay like <"@"@me.com> (previously were becoming <@@me.com>)
if local && (local.join == '@' || local.join =~ /\A[^"].*?@.*?[^"]\Z/)
@local = "\"#{local.join}\""
else
View
2  actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/header.rb
@@ -59,7 +59,7 @@ def new( name, body, conf = DEFAULT_CONFIG )
#
# This is because a mailbox doesn't have the : after the From that designates the
# beginning of the envelope sender (which can be different to the from address of
- # the emial)
+ # the email)
#
# Other fields can be passed as normal, "Reply-To", "Received" etc.
#
View
2  actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/interface.rb
@@ -42,7 +42,7 @@ class Mail
# Allows you to query the mail object with a string to get the contents
# of the field you want.
#
- # Returns a string of the exact contnts of the field
+ # Returns a string of the exact contents of the field
#
# mail.from = "mikel <mikel@lindsaar.net>"
# mail.header_string("From") #=> "mikel <mikel@lindsaar.net>"
View
4 actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/mail.rb
@@ -255,7 +255,7 @@ def sub_header(key, param)
alias fetch []
# Allows you to set or delete TMail header objects at will.
- # Eamples:
+ # Examples:
# @mail = TMail::Mail.new
# @mail['to'].to_s # => 'mikel@test.com.au'
# @mail['to'] = 'mikel@elsewhere.org'
@@ -265,7 +265,7 @@ def sub_header(key, param)
# @mail['to'].to_s # => nil
# @mail.encoded # => "\r\n"
#
- # Note: setting mail[] = nil actualy deletes the header field in question from the object,
+ # Note: setting mail[] = nil actually deletes the header field in question from the object,
# it does not just set the value of the hash to nil
def []=( key, val )
dkey = key.downcase
View
3  actionmailer/test/abstract_unit.rb
@@ -32,8 +32,7 @@ def self.start(*args)
# Wrap tests that use Mocha and skip if unavailable.
def uses_mocha(test_name)
- gem 'mocha', ">=0.5"
- require 'stubba'
+ gem 'mocha', ">=0.9.0"
yield
rescue Gem::LoadError
$stderr.puts "Skipping #{test_name} tests (Mocha >= 0.5 is required). `gem install mocha` and try again."
View
47 actionpack/CHANGELOG
@@ -2,6 +2,43 @@
* Fixed that AssetTagHelper#compute_public_path shouldn't cache the asset_host along with the source or per-request proc's won't run [DHH]
+* Removed config.action_view.cache_template_loading, use config.cache_classes instead [Josh Peek]
+
+* Get buffer for fragment cache from template's @output_buffer [Josh Peek]
+
+* Set config.action_view.warn_cache_misses = true to receive a warning if you perform an action that results in an expensive disk operation that could be cached [Josh Peek]
+
+* Refactor template preloading. New abstractions include Renderable mixins and a refactored Template class [Josh Peek]
+
+* Changed ActionView::TemplateHandler#render API method signature to render(template, local_assigns = {}) [Josh Peek]
+
+* Changed PrototypeHelper#submit_to_remote to PrototypeHelper#button_to_remote to stay consistent with link_to_remote (submit_to_remote still works as an alias) #8994 [clemens]
+
+* Add :recursive option to javascript_include_tag and stylesheet_link_tag to be used along with :all. #480 [Damian Janowski]
+
+* Allow users to disable the use of the Accept header [Michael Koziarski]
+
+ The accept header is poorly implemented by browsers and causes strange
+ errors when used on public sites where crawlers make requests too. You
+ can use formatted urls (e.g. /people/1.xml) to support API clients in a
+ much simpler way.
+
+ To disable the header you need to set:
+
+ config.action_controller.use_accept_header = false
+
+* Do not stat template files in production mode before rendering. You will no longer be able to modify templates in production mode without restarting the server [Josh Peek]
+
+* Deprecated TemplateHandler line offset [Josh Peek]
+
+* Allow caches_action to accept cache store options. #416. [José Valim]. Example:
+
+ caches_action :index, :redirected, :if => Proc.new { |c| !c.request.format.json? }, :expires_in => 1.hour
+
+* Remove define_javascript_functions, javascript_include_tag and friends are far superior. [Michael Koziarski]
+
+* Deprecate :use_full_path render option. The supplying the option no longer has an effect [Josh Peek]
+
* Add :as option to render a collection of partials with a custom local variable name. #509 [Simon Jefford, Pratik Naik]
render :partial => 'other_people', :collection => @people, :as => :person
@@ -12,6 +49,16 @@
* Made ActionView::Base#render_file private [Josh Peek]
+* Refactor and simplify the implementation of assert_redirected_to. Arguments are now normalised relative to the controller being tested, not the root of the application. [Michael Koziarski]
+
+ This could cause some erroneous test failures if you were redirecting between controllers
+ in different namespaces and wrote your assertions relative to the root of the application.
+
+* Remove follow_redirect from controller functional tests.
+
+ If you want to follow redirects you can use integration tests. The functional test
+ version was only useful if you were using redirect_to :id=>...
+
* Fix polymorphic_url with singleton resources. #461 [Tammer Saleh]
* Replaced TemplateFinder abstraction with ViewLoadPaths [Josh Peek]
View
18 actionpack/README
@@ -31,7 +31,7 @@ http://www.rubyonrails.org.
A short rundown of the major features:
* Actions grouped in controller as methods instead of separate command objects
- and can therefore share helper methods.
+ and can therefore share helper methods
BlogController < ActionController::Base
def show
@@ -168,7 +168,7 @@ A short rundown of the major features:
{Learn more}[link:classes/ActionController/Base.html]
-* Javascript and Ajax integration.
+* Javascript and Ajax integration
link_to_function "Greeting", "alert('Hello world!')"
link_to_remote "Delete this post", :update => "posts",
@@ -177,7 +177,7 @@ A short rundown of the major features:
{Learn more}[link:classes/ActionView/Helpers/JavaScriptHelper.html]
-* Pagination for navigating lists of results.
+* Pagination for navigating lists of results
# controller
def list
@@ -192,15 +192,9 @@ A short rundown of the major features:
{Learn more}[link:classes/ActionController/Pagination.html]
-* Easy testing of both controller and template result through TestRequest/Response
-
- class LoginControllerTest < Test::Unit::TestCase
- def setup
- @controller = LoginController.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
- end
+* Easy testing of both controller and rendered template through ActionController::TestCase
+ class LoginControllerTest < ActionController::TestCase
def test_failing_authenticate
process :authenticate, :user_name => "nop", :password => ""
assert flash.has_key?(:alert)
@@ -208,7 +202,7 @@ A short rundown of the major features:
end
end
- {Learn more}[link:classes/ActionController/TestRequest.html]
+ {Learn more}[link:classes/ActionController/TestCase.html]
* Automated benchmarking and integrated logging
View
107 actionpack/lib/action_controller/assertions/response_assertions.rb
@@ -56,74 +56,24 @@ def assert_response(type, message = nil)
# # assert that the redirection was to the named route login_url
# assert_redirected_to login_url
#
+ # # assert that the redirection was to the url for @customer
+ # assert_redirected_to @customer
+ #
def assert_redirected_to(options = {}, message=nil)
clean_backtrace do
assert_response(:redirect, message)
return true if options == @response.redirected_to
- ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty?
-
- begin
- url = {}
- original = { :expected => options, :actual => @response.redirected_to.is_a?(Symbol) ? @response.redirected_to : @response.redirected_to.dup }
- original.each do |key, value|
- if value.is_a?(Symbol)
- value = @controller.respond_to?(value, true) ? @controller.send(value) : @controller.send("hash_for_#{value}_url")
- end
-
- unless value.is_a?(Hash)
- request = case value
- when NilClass then nil
- when /^\w+:\/\// then recognized_request_for(%r{^(\w+://.*?(/|$|\?))(.*)$} =~ value ? $3 : nil)
- else recognized_request_for(value)
- end
- value = request.path_parameters if request
- end
-
- if value.is_a?(Hash) # stringify 2 levels of hash keys
- if name = value.delete(:use_route)
- route = ActionController::Routing::Routes.named_routes[name]
- value.update(route.parameter_shell)
- end
-
- value.stringify_keys!
- value.values.select { |v| v.is_a?(Hash) }.collect { |v| v.stringify_keys! }
- if key == :expected && value['controller'] == @controller.controller_name && original[:actual].is_a?(Hash)
- original[:actual].stringify_keys!
- value.delete('controller') if original[:actual]['controller'].nil? || original[:actual]['controller'] == value['controller']
- end
- end
-
- if value.respond_to?(:[]) && value['controller']
- value['controller'] = value['controller'].to_s
- if key == :actual && value['controller'].first != '/' && !value['controller'].include?('/')
- new_controller_path = ActionController::Routing.controller_relative_to(value['controller'], @controller.class.controller_path)
- value['controller'] = new_controller_path if value['controller'] != new_controller_path && ActionController::Routing.possible_controllers.include?(new_controller_path) && @response.redirected_to.is_a?(Hash)
- end
- value['controller'] = value['controller'][1..-1] if value['controller'].first == '/' # strip leading hash
- end
- url[key] = value
- end
-
- @response_diff = url[:actual].diff(url[:expected]) if url[:actual]
- msg = build_message(message, "expected a redirect to <?>, found one to <?>, a difference of <?> ", url[:expected], url[:actual], @response_diff)
-
- assert_block(msg) do
- url[:expected].keys.all? do |k|
- if k == :controller then url[:expected][k] == ActionController::Routing.controller_relative_to(url[:actual][k], @controller.class.controller_path)
- else parameterize(url[:expected][k]) == parameterize(url[:actual][k])
- end
- end
- end
- rescue ActionController::RoutingError # routing failed us, so match the strings only.
- msg = build_message(message, "expected a redirect to <?>, found one to <?>", options, @response.redirect_url)
- url_regexp = %r{^(\w+://.*?(/|$|\?))(.*)$}
- eurl, epath, url, path = [options, @response.redirect_url].collect do |url|
- u, p = (url_regexp =~ url) ? [$1, $3] : [nil, url]
- [u, (p.first == '/') ? p : '/' + p]
- end.flatten
+
+ # Support partial arguments for hash redirections
+ if options.is_a?(Hash) && @response.redirected_to.is_a?(Hash)
+ return true if options.all? {|(key, value)| @response.redirected_to[key] == value}
+ end
+
+ redirected_to_after_normalisation = normalize_argument_to_redirection(@response.redirected_to)
+ options_after_normalisation = normalize_argument_to_redirection(options)
- assert_equal(eurl, url, msg) if eurl && url
- assert_equal(epath, path, msg) if epath && path
+ if redirected_to_after_normalisation != options_after_normalisation
+ flunk "Expected response to be a redirect to <#{options_after_normalisation}> but was a redirect to <#{redirected_to_after_normalisation}>"
end
end
end
@@ -137,36 +87,37 @@ def assert_redirected_to(options = {}, message=nil)
#
def assert_template(expected = nil, message=nil)
clean_backtrace do
- rendered = expected ? @response.rendered_file(!expected.include?('/')) : @response.rendered_file
+ rendered = @response.rendered_template
msg = build_message(message, "expecting <?> but rendering with <?>", expected, rendered)
assert_block(msg) do
if expected.nil?
- !@response.rendered_with_file?
+ @response.rendered_template.nil?
else
- expected == rendered
+ rendered.to_s.match(expected)
end
end
end
end
private
- # Recognizes the route for a given path.
- def recognized_request_for(path, request_method = nil)
- path = "/#{path}" unless path.first == '/'
-
- # Assume given controller
- request = ActionController::TestRequest.new({}, {}, nil)
- request.env["REQUEST_METHOD"] = request_method.to_s.upcase if request_method
- request.path = path
-
- ActionController::Routing::Routes.recognize(request)
- request
- end
# Proxy to to_param if the object will respond to it.
def parameterize(value)
value.respond_to?(:to_param) ? value.to_param : value
end
+
+ def normalize_argument_to_redirection(fragment)
+ after_routing = @controller.url_for(fragment)
+ if after_routing =~ %r{^\w+://.*}
+ after_routing
+ else
+ # FIXME - this should probably get removed.
+ if after_routing.first != '/'
+ after_routing = '/' + after_routing
+ end
+ @request.protocol + @request.host_with_port + after_routing
+ end
+ end
end
end
end
View
6 actionpack/lib/action_controller/assertions/selector_assertions.rb
@@ -21,10 +21,8 @@ module Assertions
# from the response HTML or elements selected by the enclosing assertion.
#
# In addition to HTML responses, you can make the following assertions:
- # * +assert_select_rjs+ - Assertions on HTML content of RJS update and
- # insertion operations.
- # * +assert_select_encoded+ - Assertions on HTML encoded inside XML,
- # for example for dealing with feed item descriptions.
+ # * +assert_select_rjs+ - Assertions on HTML content of RJS update and insertion operations.
+ # * +assert_select_encoded+ - Assertions on HTML encoded inside XML, for example for dealing with feed item descriptions.
# * +assert_select_email+ - Assertions on the HTML body of an e-mail.
#
# Also see HTML::Selector to learn how to use selectors.
View
77 actionpack/lib/action_controller/base.rb
@@ -340,6 +340,16 @@ class Base
cattr_accessor :optimise_named_routes
self.optimise_named_routes = true
+ # Indicates whether the response format should be determined by examining the Accept HTTP header,
+ # or by using the simpler params + ajax rules.
+ #
+ # If this is set to +true+ (the default) then +respond_to+ and +Request#format+ will take the Accept
+ # header into account. If it is set to false then the request format will be determined solely
+ # by examining params[:format]. If params format is missing, the format will be either HTML or
+ # Javascript depending on whether the request is an AJAX request.
+ cattr_accessor :use_accept_header
+ self.use_accept_header = true
+
# Controls whether request forgergy protection is turned on or not. Turned off by default only in test mode.
class_inheritable_accessor :allow_forgery_protection
self.allow_forgery_protection = true
@@ -402,7 +412,7 @@ def controller_path
# More methods can be hidden using <tt>hide_actions</tt>.
def hidden_actions
unless read_inheritable_attribute(:hidden_actions)
- write_inheritable_attribute(:hidden_actions, ActionController::Base.public_instance_methods.map(&:to_s))
+ write_inheritable_attribute(:hidden_actions, ActionController::Base.public_instance_methods.map { |m| m.to_s })
end
read_inheritable_attribute(:hidden_actions)
@@ -410,18 +420,18 @@ def hidden_actions
# Hide each of the given methods from being callable as actions.
def hide_action(*names)
- write_inheritable_attribute(:hidden_actions, hidden_actions | names.map(&:to_s))
+ write_inheritable_attribute(:hidden_actions, hidden_actions | names.map { |name| name.to_s })
end
- ## View load paths determine the bases from which template references can be made. So a call to
- ## render("test/template") will be looked up in the view load paths array and the closest match will be
- ## returned.
+ # View load paths determine the bases from which template references can be made. So a call to
+ # 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
end
def view_paths=(value)
- @view_paths = ActionView::ViewLoadPaths.new(Array(value)) if value
+ @view_paths = ActionView::Base.process_view_paths(value) if value
end
# Adds a view_path to the front of the view_paths array.
@@ -603,7 +613,8 @@ def process(request, response, method = :perform_action, *arguments) #:nodoc:
#
# This takes the current URL as is and only exchanges the action. In contrast, <tt>url_for :action => 'print'</tt>
# would have slashed-off the path components after the changed action.
- def url_for(options = {}) #:doc:
+ def url_for(options = {})
+ options ||= {}
case options
when String
options
@@ -641,7 +652,7 @@ def view_paths
end
def view_paths=(value)
- @template.view_paths = ViewLoadPaths.new(value)
+ @template.view_paths = ActionView::Base.process_view_paths(value)
end
# Adds a view_path to the front of the view_paths array.
@@ -858,7 +869,7 @@ def render(options = nil, extra_options = {}, &block) #:doc:
else
if file = options[:file]
- render_for_file(file, options[:status], options[:use_full_path], options[:locals] || {})
+ render_for_file(file, options[:status], nil, options[:locals] || {})
elsif template = options[:template]
render_for_file(template, options[:status], true, options[:locals] || {})
@@ -870,9 +881,9 @@ def render(options = nil, extra_options = {}, &block) #:doc:
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], :use_full_path => true, :layout => true)
+ render_with_a_layout(:file => template, :status => options[:status], :layout => true)
else
- render_with_no_layout(:file => template, :status => options[:status], :use_full_path => true)
+ render_with_no_layout(:file => template, :status => options[:status])
end
elsif xml = options[:xml]
@@ -897,7 +908,7 @@ def render(options = nil, extra_options = {}, &block) #:doc:
else
render_for_text(
@template.send!(:render_partial, partial,
- ActionView::Base::ObjectWrapper.new(options[:object]), options[:locals]), options[:status]
+ options[:object], options[:locals]), options[:status]
)
end
@@ -1042,29 +1053,31 @@ def redirect_to(options = {}, response_status = {}) #:doc:
status = 302
end
+ response.redirected_to= options
+ logger.info("Redirected to #{options}") if logger && logger.info?
+
case options
when %r{^\w+://.*}
- raise DoubleRenderError if performed?
- logger.info("Redirected to #{options}") if logger && logger.info?
- response.redirect(options, interpret_status(status))
- response.redirected_to = options
- @performed_redirect = true
-
+ redirect_to_full_url(options, status)
when String
- redirect_to(request.protocol + request.host_with_port + options, :status=>status)
-
+ redirect_to_full_url(request.protocol + request.host_with_port + options, status)
when :back
- request.env["HTTP_REFERER"] ? redirect_to(request.env["HTTP_REFERER"], :status=>status) : raise(RedirectBackError)
-
- when Hash
- redirect_to(url_for(options), :status=>status)
- response.redirected_to = options
-
+ if referer = request.headers["Referer"]
+ redirect_to(referer, :status=>status)
+ else
+ raise RedirectBackError
+ end
else
- redirect_to(url_for(options), :status=>status)
+ redirect_to_full_url(url_for(options), status)
end
end
+ def redirect_to_full_url(url, status)
+ raise DoubleRenderError if performed?
+ response.redirect(url, interpret_status(status))
+ @performed_redirect = true
+ end
+
# Sets a HTTP 1.1 Cache-Control header. Defaults to issuing a "private" instruction, so that
# intermediate caches shouldn't cache the response.
#
@@ -1097,10 +1110,10 @@ def reset_session #:doc:
private
- def render_for_file(template_path, status = nil, use_full_path = false, locals = {}) #:nodoc:
+ def render_for_file(template_path, status = nil, use_full_path = nil, locals = {}) #:nodoc:
add_variables_to_assigns
logger.info("Rendering #{template_path}" + (status ? " (#{status})" : '')) if logger
- render_for_text(@template.render(:file => template_path, :use_full_path => use_full_path, :locals => locals), status)
+ render_for_text(@template.render(:file => template_path, :locals => locals), status)
end
def render_for_text(text = nil, status = nil, append_response = false) #:nodoc:
@@ -1188,7 +1201,7 @@ def action_methods
end
def self.action_methods
- @action_methods ||= Set.new(public_instance_methods.map(&:to_s)) - hidden_actions
+ @action_methods ||= Set.new(public_instance_methods.map { |m| m.to_s }) - hidden_actions
end
def add_variables_to_assigns
@@ -1235,8 +1248,8 @@ def template_public?(template_name = default_template_name)
end
def template_exempt_from_layout?(template_name = default_template_name)
- template_name = @template.send(:template_file_from_name, template_name) if @template
- @@exempt_from_layout.any? { |ext| template_name.to_s =~ ext }
+ template_name = @template.pick_template(template_name).to_s if @template
+ @@exempt_from_layout.any? { |ext| template_name =~ ext }
end
def default_template_name(action_name = self.action_name)
View
23 actionpack/lib/action_controller/caching/actions.rb
@@ -27,13 +27,15 @@ module Caching
# You can set modify the default action cache path by passing a :cache_path option. This will be passed directly to ActionCachePath.path_for. This is handy
# for actions with multiple possible routes that should be cached differently. If a block is given, it is called with the current controller instance.
#
- # And you can also use :if to pass a Proc that specifies when the action should be cached.
+ # And you can also use :if (or :unless) to pass a Proc that specifies when the action should be cached.
+ #
+ # Finally, if you are using memcached, you can also pass :expires_in.
#
# class ListsController < ApplicationController
# before_filter :authenticate, :except => :public
# caches_page :public
# caches_action :index, :if => Proc.new { |c| !c.request.format.json? } # cache if is not a JSON request
- # caches_action :show, :cache_path => { :project => 1 }
+ # 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]) :
@@ -56,8 +58,10 @@ module ClassMethods
def caches_action(*actions)
return unless cache_configured?
options = actions.extract_options!
- cache_filter = ActionCacheFilter.new(:layout => options.delete(:layout), :cache_path => options.delete(:cache_path))
- around_filter(cache_filter, {:only => actions}.merge(options))
+ filter_options = { :only => actions, :if => options.delete(:if), :unless => options.delete(:unless) }
+
+ cache_filter = ActionCacheFilter.new(:layout => options.delete(:layout), :cache_path => options.delete(:cache_path), :store_options => options)
+ around_filter(cache_filter, filter_options)
end
end
@@ -80,8 +84,8 @@ def initialize(options, &block)
end
def before(controller)
- cache_path = ActionCachePath.new(controller, path_options_for(controller, @options))
- if cache = controller.read_fragment(cache_path.path)
+ cache_path = ActionCachePath.new(controller, path_options_for(controller, @options.slice(:cache_path)))
+ if cache = controller.read_fragment(cache_path.path, @options[:store_options])
controller.rendered_action_cache = true
set_content_type!(controller, cache_path.extension)
options = { :text => cache }
@@ -96,7 +100,7 @@ def before(controller)
def after(controller)
return if controller.rendered_action_cache || !caching_allowed(controller)
action_content = cache_layout? ? content_for_layout(controller) : controller.response.body
- controller.write_fragment(controller.action_cache_path.path, action_content)
+ controller.write_fragment(controller.action_cache_path.path, action_content, @options[:store_options])
end
private
@@ -162,10 +166,7 @@ def extract_extension(request)
# If there's no extension in the path, check request.format
if extension.nil?
- extension = request.format.to_sym.to_s
- if extension=='all'
- extension = nil
- end
+ extension = request.cache_format
end
extension
end
View
6 actionpack/lib/action_controller/caching/fragments.rb
@@ -2,7 +2,7 @@ module ActionController #:nodoc:
module Caching
# Fragment caching is used for caching various blocks within templates without caching the entire action as a whole. This is useful when
# certain elements of an action change frequently or depend on complicated state while other parts rarely change or can be shared amongst multiple
- # parties. The caching is doing using the cache helper available in the Action View. A template with caching might look something like:
+ # parties. The caching is done using the cache helper available in the Action View. A template with caching might look something like:
#
# <b>Hello <%= @name %></b>
# <% cache do %>
@@ -60,10 +60,8 @@ def fragment_cache_key(key)
ActiveSupport::Cache.expand_cache_key(key.is_a?(Hash) ? url_for(key).split("://").last : key, :views)
end
- def fragment_for(block, name = {}, options = nil) #:nodoc:
+ def fragment_for(buffer, name = {}, options = nil, &block) #:nodoc:
if perform_caching
- buffer = yield
-
if cache = read_fragment(name, options)
buffer.concat(cache)
else
View
10 actionpack/lib/action_controller/cookies.rb
@@ -22,6 +22,16 @@ module ActionController #:nodoc:
#
# cookies.delete :user_name
#
+ # Please note that if you specify a :domain when setting a cookie, you must also specify the domain when deleting the cookie:
+ #
+ # cookies[:key] = {
+ # :value => 'a yummy cookie',
+ # :expires => 1.year.from_now,
+ # :domain => 'domain.com'
+ # }
+ #
+ # cookies.delete(:key, :domain => 'domain.com')
+ #
# The option symbols for setting cookies are:
#
# * <tt>:value</tt> - The cookie's value or list of values (as an array).
View
414 actionpack/lib/action_controller/filters.rb
@@ -7,6 +7,225 @@ def self.included(base)
end
end
+ class FilterChain < ActiveSupport::Callbacks::CallbackChain #:nodoc:
+ def append_filter_to_chain(filters, filter_type, &block)
+ pos = find_filter_append_position(filters, filter_type)
+ update_filter_chain(filters, filter_type, pos, &block)
+ end
+
+ def prepend_filter_to_chain(filters, filter_type, &block)
+ pos = find_filter_prepend_position(filters, filter_type)
+ update_filter_chain(filters, filter_type, pos, &block)
+ end
+
+ def create_filters(filters, filter_type, &block)
+ filters, conditions = extract_options(filters, &block)
+ filters.map! { |filter| find_or_create_filter(filter, filter_type, conditions) }
+ filters
+ end
+
+ def skip_filter_in_chain(*filters, &test)
+ filters, conditions = extract_options(filters)
+ filters.each do |filter|
+ if callback = find(filter) then delete(callback) end
+ end if conditions.empty?
+ update_filter_in_chain(filters, :skip => conditions, &test)
+ end
+
+ private
+ def update_filter_chain(filters, filter_type, pos, &block)
+ new_filters = create_filters(filters, filter_type, &block)
+ insert(pos, new_filters).flatten!
+ end
+
+ def find_filter_append_position(filters, filter_type)
+ # appending an after filter puts it at the end of the call chain
+ # before and around filters go before the first after filter in the chain
+ unless filter_type == :after
+ each_with_index do |f,i|
+ return i if f.after?
+ end
+ end
+ return -1
+ end
+
+ def find_filter_prepend_position(filters, filter_type)
+ # prepending a before or around filter puts it at the front of the call chain
+ # after filters go before the first after filter in the chain
+ if filter_type == :after
+ each_with_index do |f,i|
+ return i if f.after?
+ end
+ return -1
+ end
+ return 0
+ end
+
+ def find_or_create_filter(filter, filter_type, options = {})
+ update_filter_in_chain([filter], options)
+
+ if found_filter = find(filter) { |f| f.type == filter_type }
+ found_filter
+ else
+ filter_kind = case
+ when filter.respond_to?(:before) && filter_type == :before
+ :before
+ when filter.respond_to?(:after) && filter_type == :after
+ :after
+ else
+ :filter
+ end
+
+ case filter_type
+ when :before
+ BeforeFilter.new(filter_kind, filter, options)
+ when :after
+ AfterFilter.new(filter_kind, filter, options)
+ else
+ AroundFilter.new(filter_kind, filter, options)
+ end
+ end
+ end
+
+ def update_filter_in_chain(filters, options, &test)
+ filters.map! { |f| block_given? ? find(f, &test) : find(f) }
+ filters.compact!
+
+ map! do |filter|
+ if filters.include?(filter)
+ new_filter = filter.dup
+ new_filter.update_options!(options)
+ new_filter
+ else
+ filter
+ end
+ end
+ end
+ end
+
+ class Filter < ActiveSupport::Callbacks::Callback #:nodoc:
+ def initialize(kind, method, options = {})
+ super
+ update_options! options
+ end
+
+ def before?
+ self.class == BeforeFilter
+ end
+
+ def after?
+ self.class == AfterFilter
+ end
+
+ def around?
+ self.class == AroundFilter
+ end
+
+ # Make sets of strings from :only/:except options
+ def update_options!(other)
+ if other
+ convert_only_and_except_options_to_sets_of_strings(other)
+ if other[:skip]
+ convert_only_and_except_options_to_sets_of_strings(other[:skip])
+ end
+ end
+
+ options.update(other)
+ end
+
+ private
+ def should_not_skip?(controller)
+ if options[:skip]
+ !included_in_action?(controller, options[:skip])
+ else
+ true
+ end
+ end
+
+ def included_in_action?(controller, options)
+ if options[:only]
+ options[:only].include?(controller.action_name)
+ elsif options[:except]
+ !options[:except].include?(controller.action_name)
+ else
+ true
+ end
+ end
+
+ def should_run_callback?(controller)
+ should_not_skip?(controller) && included_in_action?(controller, options) && super
+ end
+
+ def convert_only_and_except_options_to_sets_of_strings(opts)
+ [:only, :except].each do |key|
+ if values = opts[key]
+ opts[key] = Array(values).map(&:to_s).to_set
+ end
+ end
+ end
+ end
+
+ class AroundFilter < Filter #:nodoc:
+ def type
+ :around
+ end
+
+ def call(controller, &block)
+ if should_run_callback?(controller)
+ method = filter_responds_to_before_and_after? ? around_proc : self.method
+
+ # For around_filter do |controller, action|
+ if method.is_a?(Proc) && method.arity == 2
+ evaluate_method(method, controller, block)
+ else
+ evaluate_method(method, controller, &block)
+ end
+ else
+ block.call
+ end
+ end
+
+ private
+ def filter_responds_to_before_and_after?
+ method.respond_to?(:before) && method.respond_to?(:after)
+ end
+
+ def around_proc
+ Proc.new do |controller, action|
+ method.before(controller)
+
+ if controller.send!(:performed?)
+ controller.send!(:halt_filter_chain, method, :rendered_or_redirected)
+ else
+ begin
+ action.call
+ ensure
+ method.after(controller)
+ end
+ end
+ end
+ end
+ end
+
+ class BeforeFilter < Filter #:nodoc:
+ def type
+ :before
+ end
+
+ def call(controller, &block)
+ super
+ if controller.send!(:performed?)
+ controller.send!(:halt_filter_chain, method, :rendered_or_redirected)
+ end
+ end
+ end
+
+ class AfterFilter < Filter #:nodoc:
+ def type
+ :after
+ end
+ end
+
# Filters enable controllers to run shared pre- and post-processing code for its actions. These filters can be used to do
# authentication, caching, or auditing before the intended action is performed. Or to do localization or output
# compression after the action has been performed. Filters have access to the request, response, and all the instance
@@ -245,201 +464,6 @@ def self.included(base)
# filter and controller action will not be run. If +before+ renders or redirects,
# the second half of +around+ and will still run but +after+ and the
# action will not. If +around+ fails to yield, +after+ will not be run.
-
- class FilterChain < ActiveSupport::Callbacks::CallbackChain #:nodoc:
- def append_filter_to_chain(filters, filter_type, &block)
- pos = find_filter_append_position(filters, filter_type)
- update_filter_chain(filters, filter_type, pos, &block)
- end
-
- def prepend_filter_to_chain(filters, filter_type, &block)
- pos = find_filter_prepend_position(filters, filter_type)
- update_filter_chain(filters, filter_type, pos, &block)
- end
-
- def create_filters(filters, filter_type, &block)
- filters, conditions = extract_options(filters, &block)
- filters.map! { |filter| find_or_create_filter(filter, filter_type, conditions) }
- filters
- end
-
- def skip_filter_in_chain(*filters, &test)
- filters, conditions = extract_options(filters)
- filters.each do |filter|
- if callback = find(filter) then delete(callback) end
- end if conditions.empty?
- update_filter_in_chain(filters, :skip => conditions, &test)
- end
-
- private
- def update_filter_chain(filters, filter_type, pos, &block)
- new_filters = create_filters(filters, filter_type, &block)
- insert(pos, new_filters).flatten!
- end
-
- def find_filter_append_position(filters, filter_type)
- # appending an after filter puts it at the end of the call chain
- # before and around filters go before the first after filter in the chain
- unless filter_type == :after
- each_with_index do |f,i|
- return i if f.after?
- end
- end
- return -1
- end
-
- def find_filter_prepend_position(filters, filter_type)
- # prepending a before or around filter puts it at the front of the call chain
- # after filters go before the first after filter in the chain
- if filter_type == :after
- each_with_index do |f,i|
- return i if f.after?
- end
- return -1
- end
- return 0
- end
-
- def find_or_create_filter(filter, filter_type, options = {})
- update_filter_in_chain([filter], options)
-
- if found_filter = find(filter) { |f| f.type == filter_type }
- found_filter
- else
- filter_kind = case
- when filter.respond_to?(:before) && filter_type == :before
- :before
- when filter.respond_to?(:after) && filter_type == :after
- :after
- else
- :filter
- end
-
- case filter_type
- when :before
- BeforeFilter.new(filter_kind, filter, options)
- when :after
- AfterFilter.new(filter_kind, filter, options)
- else
- AroundFilter.new(filter_kind, filter, options)
- end
- end
- end
-
- def update_filter_in_chain(filters, options, &test)
- filters.map! { |f| block_given? ? find(f, &test) : find(f) }
- filters.compact!
-
- map! do |filter|
- if filters.include?(filter)
- new_filter = filter.dup
- new_filter.options.merge!(options)
- new_filter
- else
- filter
- end
- end
- end
- end
-
- class Filter < ActiveSupport::Callbacks::Callback #:nodoc:
- def before?
- self.class == BeforeFilter
- end
-
- def after?
- self.class == AfterFilter
- end
-
- def around?
- self.class == AroundFilter
- end
-
- private
- def should_not_skip?(controller)
- if options[:skip]
- !included_in_action?(controller, options[:skip])
- else
- true
- end
- end
-
- def included_in_action?(controller, options)
- if options[:only]
- Array(options[:only]).map(&:to_s).include?(controller.action_name)
- elsif options[:except]
- !Array(options[:except]).map(&:to_s).include?(controller.action_name)
- else
- true
- end
- end
-
- def should_run_callback?(controller)
- should_not_skip?(controller) && included_in_action?(controller, options) && super
- end
- end
-
- class AroundFilter < Filter #:nodoc:
- def type
- :around
- end
-
- def call(controller, &block)
- if should_run_callback?(controller)
- method = filter_responds_to_before_and_after? ? around_proc : self.method
-
- # For around_filter do |controller, action|
- if method.is_a?(Proc) && method.arity == 2
- evaluate_method(method, controller, block)
- else
- evaluate_method(method, controller, &block)
- end
- else
- block.call
- end
- end
-
- private
- def filter_responds_to_before_and_after?
- method.respond_to?(:before) && method.respond_to?(:after)
- end
-
- def around_proc
- Proc.new do |controller, action|
- method.before(controller)
-
- if controller.send!(:performed?)
- controller.send!(:halt_filter_chain, method, :rendered_or_redirected)
- else
- begin
- action.call
- ensure
- method.after(controller)
- end
- end
- end
- end
- end
-
- class BeforeFilter < Filter #:nodoc:
- def type
- :before
- end
-
- def call(controller, &block)
- super
- if controller.send!(:performed?)
- controller.send!(:halt_filter_chain, method, :rendered_or_redirected)
- end
- end
- end
-
- class AfterFilter < Filter #:nodoc:
- def type
- :after
- end
- end
-
module ClassMethods
# The passed <tt>filters</tt> will be appended to the filter_chain and
# will execute before the action on this controller is performed.
View
2  actionpack/lib/action_controller/integration.rb
@@ -101,7 +101,7 @@ def https!(flag=true)
@https = flag
end
- # Return +true+ if the session is mimicing a secure HTTPS request.
+ # Return +true+ if the session is mimicking a secure HTTPS request.
#
# if session.https?
# ...
View
2  actionpack/lib/action_controller/layout.rb
@@ -304,7 +304,7 @@ def action_has_layout?
end
def layout_directory?(layout_name)
- @template.view_paths.find_template_file_for_path("#{File.join('layouts', layout_name)}.#{@template.template_format}.erb") ? true : false
+ @template.file_exists?("#{File.join('layouts', layout_name)}.#{@template.template_format}")
end
end
end
View
6 actionpack/lib/action_controller/mime_responds.rb
@@ -114,7 +114,11 @@ def initialize(controller)
@request = controller.request
@response = controller.response
- @mime_type_priority = Array(Mime::Type.lookup_by_extension(@request.parameters[:format]) || @request.accepts)
+ if ActionController::Base.use_accept_header
+ @mime_type_priority = Array(Mime::Type.lookup_by_extension(@request.parameters[:format]) || @request.accepts)
+ else
+ @mime_type_priority = [@request.format]
+ end
@order = []
@responses = {}
View
82 actionpack/lib/action_controller/mime_type.rb
@@ -72,57 +72,61 @@ def register(string, symbol, mime_type_synonyms = [], extension_synonyms = [], s
end
def parse(accept_header)
- # keep track of creation order to keep the subsequent sort stable
- list = []
- accept_header.split(/,/).each_with_index do |header, index|
- params, q = header.split(/;\s*q=/)
- if params
- params.strip!
- list << AcceptItem.new(index, params, q) unless params.empty?
+ if accept_header !~ /,/
+ [Mime::Type.lookup(accept_header)]
+ else
+ # keep track of creation order to keep the subsequent sort stable
+ list = []
+ accept_header.split(/,/).each_with_index do |header, index|
+ params, q = header.split(/;\s*q=/)
+ if params
+ params.strip!
+ list << AcceptItem.new(index, params, q) unless params.empty?
+ end
end
- end
- list.sort!
+ list.sort!
- # Take care of the broken text/xml entry by renaming or deleting it
- text_xml = list.index("text/xml")
- app_xml = list.index(Mime::XML.to_s)
+ # Take care of the broken text/xml entry by renaming or deleting it
+ text_xml = list.index("text/xml")
+ app_xml = list.index(Mime::XML.to_s)
- if text_xml && app_xml
- # set the q value to the max of the two
- list[app_xml].q = [list[text_xml].q, list[app_xml].q].max
+ if text_xml && app_xml
+ # set the q value to the max of the two
+ list[app_xml].q = [list[text_xml].q, list[app_xml].q].max
- # make sure app_xml is ahead of text_xml in the list
- if app_xml > text_xml
- list[app_xml], list[text_xml] = list[text_xml], list[app_xml]
- app_xml, text_xml = text_xml, app_xml
- end
+ # make sure app_xml is ahead of text_xml in the list
+ if app_xml > text_xml
+ list[app_xml], list[text_xml] = list[text_xml], list[app_xml]
+ app_xml, text_xml = text_xml, app_xml
+ end
- # delete text_xml from the list
- list.delete_at(text_xml)
+ # delete text_xml from the list
+ list.delete_at(text_xml)
- elsif text_xml
- list[text_xml].name = Mime::XML.to_s
- end
+ elsif text_xml
+ list[text_xml].name = Mime::XML.to_s
+ end
- # Look for more specific XML-based types and sort them ahead of app/xml
+ # Look for more specific XML-based types and sort them ahead of app/xml
- if app_xml
- idx = app_xml
- app_xml_type = list[app_xml]
+ if app_xml
+ idx = app_xml
+ app_xml_type = list[app_xml]
- while(idx < list.length)
- type = list[idx]
- break if type.q < app_xml_type.q
- if type.name =~ /\+xml$/
- list[app_xml], list[idx] = list[idx], list[app_xml]
- app_xml = idx
+ while(idx < list.length)
+ type = list[idx]
+ break if type.q < app_xml_type.q
+ if type.name =~ /\+xml$/
+ list[app_xml], list[idx] = list[idx], list[app_xml]
+ app_xml = idx
+ end
+ idx += 1
end
- idx += 1
end
- end
- list.map! { |i| Mime::Type.lookup(i.name) }.uniq!
- list
+ list.map! { |i| Mime::Type.lookup(i.name) }.uniq!
+ list
+ end
end
end
View
10 actionpack/lib/action_controller/rack_process.rb
@@ -24,7 +24,7 @@ def initialize(env, session_options = DEFAULT_SESSION_OPTIONS)
super()
end
- %w[ AUTH_TYPE CONTENT_TYPE GATEWAY_INTERFACE PATH_INFO
+ %w[ AUTH_TYPE GATEWAY_INTERFACE PATH_INFO
PATH_TRANSLATED QUERY_STRING REMOTE_HOST
REMOTE_IDENT REMOTE_USER SCRIPT_NAME
SERVER_NAME SERVER_PROTOCOL
@@ -98,10 +98,6 @@ def remote_addr
@env['REMOTE_ADDR']
end
- def request_method
- @env['REQUEST_METHOD'].downcase.to_sym
- end
-
def server_port
@env['SERVER_PORT'].to_i
end
@@ -250,11 +246,11 @@ def normalize_headers(options = "text/html")
headers['Content-Language'] = options.delete('language') if options['language']
headers['Expires'] = options.delete('expires') if options['expires']
- @status = options['Status'] || "200 OK"
+ @status = options.delete('Status') || "200 OK"
# Convert 'cookie' header to 'Set-Cookie' headers.
# Because Set-Cookie header can appear more the once in the response body,
- # we store it in a line break seperated string that will be translated to
+ # we store it in a line break separated string that will be translated to
# multiple Set-Cookie header by the handler.
if cookie = options.delete('cookie')
cookies = []
View
55 actionpack/lib/action_controller/request.rb
@@ -61,7 +61,7 @@ def head?
request_method == :head
end
- # Provides acccess to the request's HTTP headers, for example:
+ # Provides access to the request's HTTP headers, for example:
# request.headers["Content-Type"] # => "text/plain"
def headers
@headers ||= ActionController::Http::Headers.new(@env)
@@ -82,21 +82,34 @@ def content_type
# Returns the accepted MIME type for the request
def accepts
@accepts ||=
- if @env['HTTP_ACCEPT'].to_s.strip.empty?
- [ content_type, Mime::ALL ].compact # make sure content_type being nil is not included
- else
- Mime::Type.parse(@env['HTTP_ACCEPT'])
+ begin
+ header = @env['HTTP_ACCEPT'].to_s.strip
+
+ if header.empty?
+ [content_type, Mime::ALL].compact
+ else
+ Mime::Type.parse(header)
+ end
end
end
- # Returns the Mime type for the format used in the request. If there is no format available, the first of the
- # accept types will be used. Examples:
+ # 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
- # GET /posts/5 | request.format => request.accepts.first (usually Mime::HTML for browsers)
+ # GET /posts/5 | request.format => Mime::HTML or MIME::JS, or request.accepts.first depending on the value of <tt>ActionController::Base.use_accept_header</tt>
def format
- @format ||= parameters[:format] ? Mime::Type.lookup_by_extension(parameters[:format]) : accepts.first
+ @format ||= begin
+ if parameters[:format]
+ Mime::Type.lookup_by_extension(parameters[:format])
+ elsif ActionController::Base.use_accept_header
+ accepts.first
+ elsif xhr?
+ Mime::Type.lookup_by_extension("js")
+ else
+ Mime::Type.lookup_by_extension("html")
+ end
+ end
end
@@ -116,6 +129,26 @@ def format=(extension)
@format = Mime::Type.lookup_by_extension(parameters[:format])
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>
+ # otherwise.
+ def template_format
+ parameter_format = parameters[:format]
+
+ if parameter_format
+ parameter_format.to_sym
+ elsif xhr?
+ :js
+ else
+ :html
+ end
+ end
+
+ def cache_format
+ parameter_format = parameters[:format]
+ parameter_format && parameter_format.to_sym
+ end
+
# Returns true if the request's "X-Requested-With" header contains
# "XMLHttpRequest". (The Prototype Javascript library sends this header with
# every Ajax request.)
@@ -232,7 +265,7 @@ def subdomains(tld_length = 1)
parts[0..-(tld_length+2)]
end
- # Return the query string, accounting for server idiosyncracies.
+ # Return the query string, accounting for server idiosyncrasies.
def query_string
if uri = @env['REQUEST_URI']
uri.split('?', 2)[1] || ''
@@ -241,7 +274,7 @@ def query_string
end
end
- # Return the request URI, accounting for server idiosyncracies.
+ # Return the request URI, accounting for server idiosyncrasies.
# WEBrick includes the full URL. IIS leaves REQUEST_URI blank.
def request_uri
if uri = @env['REQUEST_URI']
View
2  actionpack/lib/action_controller/request_forgery_protection.rb
@@ -17,7 +17,7 @@ def self.included(base)
# forged link from another site, is done by embedding a token based on the session (which an attacker wouldn't know) in all
# forms and Ajax requests generated by Rails and then verifying the authenticity of that token in the controller. Only
# HTML/JavaScript requests are checked, so this will not protect your XML API (presumably you'll have a different authentication
- # scheme there anyway). Also, GET requests are not protected as these should be indempotent anyway.
+ # scheme there anyway). Also, GET requests are not protected as these should be idempotent anyway.
#
# This is turned on with the <tt>protect_from_forgery</tt> method, which will check the token and raise an
# ActionController::InvalidAuthenticityToken if it doesn't match what was expected. You can customize the error message in
View
28 actionpack/lib/action_controller/rescue.rb
@@ -112,19 +112,23 @@ def rescue_from(*klasses, &block)
protected
# Exception handler called when the performance of an action raises an exception.
def rescue_action(exception)
- log_error(exception) if logger
- erase_results if performed?
+ if handler_for_rescue(exception)
+ rescue_action_with_handler(exception)
+ else
+ log_error(exception) if logger
+ erase_results if performed?
- # Let the exception alter the response if it wants.
- # For example, MethodNotAllowed sets the Allow header.
- if exception.respond_to?(:handle_response!)
- exception.handle_response!(response)
- end
+ # Let the exception alter the response if it wants.
+ # For example, MethodNotAllowed sets the Allow header.
+ if exception.respond_to?(:handle_response!)
+ exception.handle_response!(response)
+ end
- if consider_all_requests_local || local_request?
- rescue_action_locally(exception)
- else
- rescue_action_in_public(exception)
+ if consider_all_requests_local || local_request?
+ rescue_action_locally(exception)
+ else
+ rescue_action_in_public(exception)
+ end
end
end
@@ -200,7 +204,7 @@ def rescue_action_with_handler(exception)
def perform_action_with_rescue #:nodoc:
perform_action_without_rescue
rescue Exception => exception
- rescue_action_with_handler(exception) || rescue_action(exception)
+ rescue_action(exception)
end
def rescues_path(template_name)
View
4 actionpack/lib/action_controller/resources.rb
@@ -296,6 +296,10 @@ def initialize(entity, options)
# article_comments_url(:article_id => @article)
# article_comment_url(:article_id => @article, :id => @comment)
#
+ # If you don't want to load all objects from the database you might want to use the <tt>article_id</tt> directly:
+ #
+ # articles_comments_url(@comment.article_id, @comment)
+ #
# * <tt>:name_prefix</tt> - Define a prefix for all generated routes, usually ending in an underscore.
# Use this if you have named routes that may clash.
#
View
4 actionpack/lib/action_controller/routing.rb
@@ -88,6 +88,10 @@ module ActionController
#
# map.connect ':controller/:action/:id', :action => 'show', :defaults => { :page => 'Dashboard' }
#
+ # Note: The default routes, as provided by the Rails generator, make all actions in every
+ # controller accessible via GET requests. You should consider removing them or commenting
+ # them out if you're using named routes and resources.
+ #
# == Named routes
#
# Routes can be named with the syntax <tt>map.name_of_route options</tt>,
View
3  actionpack/lib/action_controller/routing/builder.rb
@@ -67,10 +67,9 @@ def divide_route_options(segments, options)
options = options.dup
if options[:namespace]
- options[:controller] = "#{options[:path_prefix]}/#{options[:controller]}"
+ options[:controller] = "#{options.delete(:namespace).sub(/\/$/, '')}/#{options[:controller]}"
options.delete(:path_prefix)
options.delete(:name_prefix)
- options.delete(:namespace)
end
requirements = (options.delete(:requirements) || {}).dup
View
23 actionpack/lib/action_controller/streaming.rb
@@ -12,19 +12,21 @@ module Streaming
X_SENDFILE_HEADER = 'X-Sendfile'.freeze
protected
- # Sends the file by streaming it 4096 bytes at a time. This way the
- # whole file doesn't need to be read into memory at once. This makes
- # it feasible to send even large files.
+ # Sends the file, by default streaming it 4096 bytes at a time. This way the
+ # whole file doesn't need to be read into memory at once. This makes it
+ # feasible to send even large files. You can optionally turn off streaming
+ # and send the whole file at once.
#
- # Be careful to sanitize the path parameter if it coming from a web
+ # Be careful to sanitize the path parameter if it is coming from a web
# page. <tt>send_file(params[:path])</tt> allows a malicious user to
# download any file on your server.
#
# Options:
# * <tt>:filename</tt> - suggests a filename for the browser to use.
# Defaults to <tt>File.basename(path)</tt>.
- # * <tt>:type</tt> - specifies an HTTP content type.
- # Defaults to 'application/octet-stream'.
+ # * <tt>:type</tt> - specifies an HTTP content type. Defaults to 'application/octet-stream'.
+ # * <tt>:length</tt> - used to manually override the length (in bytes) of the content that
+ # is going to be sent to the client. Defaults to <tt>File.size(path)</tt>.
# * <tt>:disposition</tt> - specifies whether the file will be shown inline or downloaded.
# Valid values are 'inline' and 'attachment' (default).
# * <tt>:stream</tt> - whether to send the file to the user agent as it is read (+true+)
@@ -35,6 +37,12 @@ module Streaming
# * <tt>:url_based_filename</tt> - set to +true+ if you want the browser guess the filename from
# the URL, which is necessary for i18n filenames on certain browsers
# (setting <tt>:filename</tt> overrides this option).
+ # * <tt>:x_sendfile</tt> - uses X-Sendfile to send the file when set to +true+. This is currently
+ # only available with Lighttpd/Apache2 and specific modules installed and activated. Since this
+ # uses the web server to send the file, this may lower memory consumption on your server and
+ # it will not block your application for further requests.
+ # See http://blog.lighttpd.net/articles/2006/07/02/x-sendfile and
+ # http://tn123.ath.cx/mod_xsendfile/ for details. Defaults to +false+.
#
# The default Content-Type and Content-Disposition headers are
# set to download arbitrary binary files in as many browsers as
@@ -99,8 +107,7 @@ def send_file(path, options = {}) #:doc:
#
# Options:
# * <tt>:filename</tt> - suggests a filename for the browser to use.
- # * <tt>:type</tt> - specifies an HTTP content type.
- # Defaults to 'application/octet-stream'.
+ # * <tt>:type</tt> - specifies an HTTP content type. Defaults to 'application/octet-stream'.
# * <tt>:disposition</tt> - specifies whether the file will be shown inline or downloaded.
# Valid values are 'inline' and 'attachment' (default).
# * <tt>:status</tt> - specifies the status code to send with the response. Defaults to '200 OK'.
View
23 actionpack/lib/action_controller/test_case.rb
@@ -15,6 +15,27 @@ def inferred_controller_name
end
end
+ # Superclass for Action Controller functional tests. Infers the controller under test from the test class name,
+ # and creates @controller, @request, @response instance variables.
+ #
+ # class WidgetsControllerTest < ActionController::TestCase
+ # def test_index
+ # get :index
+ # end
+ # end
+ #
+ # * @controller - WidgetController.new
+ # * @request - ActionController::TestRequest.new
+ # * @response - ActionController::TestResponse.new
+ #
+ # (Earlier versions of Rails required each functional test to subclass Test::Unit::TestCase and define
+ # @controller, @request, @response in +setup+.)
+ #
+ # If the controller cannot be inferred from the test class name, you can explicity set it with +tests+.
+ #
+ # class SpecialEdgeCaseWidgetsControllerTest < ActionController::TestCase
+ # tests WidgetController
+ # end
class TestCase < ActiveSupport::TestCase
# When the request.remote_addr remains the default for testing, which is 0.0.0.0, the exception is simply raised inline
# (bystepping the regular exception handling from rescue_action). If the request.remote_addr is anything else, the regular
@@ -41,6 +62,8 @@ def rescue_action(e)
@@controller_class = nil
class << self
+ # Sets the controller class name. Useful if the name can't be inferred from test class.
+ # Expects +controller_class+ as a constant. Example: <tt>tests WidgetController</tt>.
def tests(controller_class)
self.controller_class = controller_class
end
View
30 actionpack/lib/action_controller/test_process.rb
@@ -205,24 +205,13 @@ def redirect_url_match?( pattern )
p.match(redirect_url) != nil
end
- # Returns the template path of the file which was used to
- # render this response (or nil)
- def rendered_file(with_controller=false)
- unless template.first_render.nil?
- unless with_controller
- template.first_render
- else
- template.first_render.split('/').last || template.first_render
- end
- end
- end
-
- # Was this template rendered by a file?
- def rendered_with_file?
- !rendered_file.nil?
+ # Returns the template of the file which was used to
+ # render this response (or nil)
+ def rendered_template
+ template._first_render
end
- # A shortcut to the flash. Returns an empyt hash if no session flash exists.
+ # A shortcut to the flash. Returns an empty hash if no session flash exists.
def flash
session['flash'] || {}
end
@@ -404,15 +393,6 @@ def xml_http_request(request_method, action, parameters = nil, session = nil, fl
end
alias xhr :xml_http_request
- def follow_redirect
- redirected_controller = @response.redirected_to[:controller]
- if redirected_controller && redirected_controller != @controller.controller_name
- raise "Can't follow redirects outside of current controller (from #{@controller.controller_name} to #{redirected_controller})"
- end
-
- get(@response.redirected_to.delete(:action), @response.redirected_to.stringify_keys)
- end
-
def assigns(key = nil)
if key.nil?
@response.template.assigns
View
4 actionpack/lib/action_controller/vendor/html-scanner/html/selector.rb
@@ -64,7 +64,7 @@ module HTML
#
# When using a combination of the above, the element name comes first
# followed by identifier, class names, attributes, pseudo classes and
- # negation in any order. Do not seprate these parts with spaces!
+ # negation in any order. Do not separate these parts with spaces!
# Space separation is used for descendant selectors.
#
# For example:
@@ -158,7 +158,7 @@ module HTML
# * <tt>:not(selector)</tt> -- Match the element only if the element does not
# match the simple selector.
#
- # As you can see, <tt>:nth-child<tt> pseudo class and its varient can get quite
+ # As you can see, <tt>:nth-child<tt> pseudo class and its variant can get quite
# tricky and the CSS specification doesn't do a much better job explaining it.
# But after reading the examples and trying a few combinations, it's easy to
# figure out.
View
8 actionpack/lib/action_view.rb
@@ -21,12 +21,14 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
+
require 'action_view/template_handlers'
-require 'action_view/template_file'
-require 'action_view/view_load_paths'
+require 'action_view/renderable'
+require 'action_view/renderable_partial'
+
require 'action_view/template'
-require 'action_view/partial_template'
require 'action_view/inline_template'
+require 'action_view/paths'
require 'action_view/base'
require 'action_view/partials'
View
167 actionpack/lib/action_view/base.rb
@@ -3,6 +3,12 @@ class ActionViewError < StandardError #:nodoc:
end
class MissingTemplate < ActionViewError #:nodoc:
+ def initialize(paths, path, template_format = nil)
+ full_template_path = path.include?('.') ? path : "#{path}.erb"
+ display_paths = paths.join(':')
+ template_type = (path =~ /layouts/i) ? 'layout' : 'template'
+ super("Missing #{template_type} #{full_template_path} in view path #{display_paths}")
+ end
end
# Action View templates can be written in three ways. If the template file has a <tt>.erb</tt> (or <tt>.rhtml</tt>) extension then it uses a mixture of ERb
@@ -153,11 +159,11 @@ class MissingTemplate < ActionViewError #:nodoc:
class Base
include ERB::Util
- attr_accessor :base_path, :assigns, :template_extension, :first_render
+ attr_accessor :base_path, :assigns, :template_extension
attr_accessor :controller
+ attr_accessor :_first_render, :_last_render
attr_writer :template_format
- attr_accessor :current_render_extension
attr_accessor :output_buffer
@@ -165,12 +171,13 @@ class << self
delegate :erb_trim_mode=, :to => 'ActionView::TemplateHandlers::ERB'
end
- # Specify whether file modification times should be checked to see if a template needs recompilation
- @@cache_template_loading = false
- cattr_accessor :cache_template_loading
+ def self.cache_template_loading=(*args)
+ ActiveSupport::Deprecation.warn("config.action_view.cache_template_loading option has been deprecated and has no affect. " <<
+ "Please remove it from your config files.", caller)
+ end
def self.cache_template_extensions=(*args)
- ActiveSupport::Deprecation.warn("config.action_view.cache_template_extensions option has been deprecated and has no affect. " <<
+ ActiveSupport::Deprecation.warn("config.action_view.cache_template_extensions option has been deprecated and has no effect. " <<
"Please remove it from your config files.", caller)
end
@@ -179,6 +186,10 @@ def self.cache_template_extensions=(*args)
@@debug_rjs = false
cattr_accessor :debug_rjs
+ # A warning will be displayed whenever an action results in a cache miss on your view paths.
+ @@warn_cache_misses = false
+ cattr_accessor :warn_cache_misses
+
attr_internal :request
delegate :request_forgery_protection_token, :template, :params, :session, :cookies, :response, :headers,
@@ -189,19 +200,10 @@ module CompiledTemplates #:nodoc:
end
include CompiledTemplates
- # Maps inline templates to their method names
- cattr_accessor :method_names
- @@method_names = {}
- # Map method names to the names passed in local assigns so far
- @@template_args = {}
-
# Cache public asset paths
cattr_reader :computed_public_paths
@@computed_public_paths = {}
- class ObjectWrapper < Struct.new(:value) #:nodoc:
- end
-
def self.helper_modules #:nodoc:
helpers = []
Dir.entries(File.expand_path("#{File.dirname(__FILE__)}/helpers")).sort.each do |file|
@@ -215,6 +217,10 @@ def self.helper_modules #:nodoc:
return helpers
end
+ def self.process_view_paths(value)
+ ActionView::PathSet.new(Array(value))
+ end
+
def initialize(view_paths = [], assigns_for_first_render = {}, controller = nil)#:nodoc:
@assigns = assigns_for_first_render
@assigns_added = nil
@@ -225,19 +231,20 @@ def initialize(view_paths = [], assigns_for_first_render = {}, controller = nil)
attr_reader :view_paths
def view_paths=(paths)
- @view_paths = ViewLoadPaths.new(Array(paths))
+ @view_paths = self.class.process_view_paths(paths)
end
# Renders the template present at <tt>template_path</tt> (relative to the view_paths array).
# The hash in <tt>local_assigns</tt> is made available as local variables.
def render(options = {}, local_assigns = {}, &block) #:nodoc:
+ local_assigns ||= {}
+
if options.is_a?(String)
- render_file(options, true, local_assigns)
+ render_file(options, nil, local_assigns)
elsif options == :update
update_page(&block)
elsif options.is_a?(Hash)
- use_full_path = options[:use_full_path]
- options = options.reverse_merge(:locals => {}, :use_full_path => true)
+ options = options.reverse_merge(:locals => {})