Permalink
Browse files

Merge commit 'mainstream/master'

  • Loading branch information...
2 parents dd2779e + b9ce821 commit 66ee2654ff243f03595a402fa15e1eea1b5b45be @lifo lifo committed Oct 10, 2009
Showing with 2,509 additions and 3,821 deletions.
  1. +0 −1 .gitignore
  2. +1 −1 actionmailer/test/fixtures/helpers/example_helper.rb
  3. +1 −0 actionpack/Gemfile
  4. +5 −6 actionpack/Rakefile
  5. +1 −1 actionpack/lib/action_controller/dispatch/dispatcher.rb
  6. +1 −1 actionpack/lib/action_controller/metal/session_management.rb
  7. +1 −0 actionpack/lib/action_dispatch.rb
  8. +6 −1 actionpack/lib/action_dispatch/http/mime_type.rb
  9. +29 −0 actionpack/lib/action_dispatch/middleware/string_coercion.rb
  10. +3 −3 actionpack/lib/action_view.rb
  11. +11 −2 actionpack/lib/action_view/base.rb
  12. +11 −1 actionpack/lib/action_view/erb/util.rb
  13. +2 −0 actionpack/lib/action_view/helpers.rb
  14. +2 −1 actionpack/lib/action_view/helpers/active_model_helper.rb
  15. +3 −3 actionpack/lib/action_view/helpers/asset_tag_helper.rb
  16. +1 −1 actionpack/lib/action_view/helpers/capture_helper.rb
  17. +3 −3 actionpack/lib/action_view/helpers/date_helper.rb
  18. +2 −2 actionpack/lib/action_view/helpers/form_helper.rb
  19. +1 −1 actionpack/lib/action_view/helpers/form_options_helper.rb
  20. +3 −3 actionpack/lib/action_view/helpers/form_tag_helper.rb
  21. +1 −0 actionpack/lib/action_view/helpers/number_helper.rb
  22. +1 −1 actionpack/lib/action_view/helpers/prototype_helper.rb
  23. +9 −0 actionpack/lib/action_view/helpers/raw_output_helper.rb
  24. +3 −3 actionpack/lib/action_view/helpers/record_tag_helper.rb
  25. +10 −2 actionpack/lib/action_view/helpers/sanitize_helper.rb
  26. +4 −4 actionpack/lib/action_view/helpers/tag_helper.rb
  27. +5 −5 actionpack/lib/action_view/helpers/url_helper.rb
  28. +5 −2 actionpack/lib/action_view/paths.rb
  29. +5 −2 actionpack/lib/action_view/render/partials.rb
  30. +13 −9 actionpack/lib/action_view/render/rendering.rb
  31. +28 −0 actionpack/lib/action_view/safe_buffer.rb
  32. +25 −3 actionpack/lib/action_view/template/handlers/erb.rb
  33. +1 −1 actionpack/lib/action_view/test_case.rb
  34. +65 −29 actionpack/test/abstract_unit.rb
  35. +0 −1 actionpack/test/activerecord/active_record_store_test.rb
  36. +11 −11 actionpack/test/controller/caching_test.rb
  37. +1 −4 actionpack/test/controller/integration_test.rb
  38. +83 −67 actionpack/test/controller/mime_responds_test.rb
  39. +1 −1 actionpack/test/{ → controller}/new_base/base_test.rb
  40. +1 −1 actionpack/test/{ → controller}/new_base/content_negotiation_test.rb
  41. +3 −3 actionpack/test/{ → controller}/new_base/content_type_test.rb
  42. +1 −1 actionpack/test/{ → controller}/new_base/etag_test.rb
  43. 0 actionpack/test/{ → controller}/new_base/metal_test.rb
  44. 0 actionpack/test/{ → controller}/new_base/middleware_test.rb
  45. +6 −6 actionpack/test/{ → controller}/new_base/render_action_test.rb
  46. +30 −41 actionpack/test/{ → controller}/new_base/render_file_test.rb
  47. +1 −1 actionpack/test/{ → controller}/new_base/render_implicit_action_test.rb
  48. +3 −3 actionpack/test/{ → controller}/new_base/render_layout_test.rb
  49. +1 −1 actionpack/test/{ → controller}/new_base/render_partial_test.rb
  50. +1 −1 actionpack/test/{ → controller}/new_base/render_rjs_test.rb
  51. +3 −3 actionpack/test/{ → controller}/new_base/render_template_test.rb
  52. +3 −3 actionpack/test/{ → controller}/new_base/render_test.rb
  53. +1 −1 actionpack/test/{ → controller}/new_base/render_text_test.rb
  54. 0 actionpack/test/{ → controller}/new_base/render_xml_test.rb
  55. +19 −0 actionpack/test/controller/output_escaping_test.rb
  56. +1 −1 actionpack/test/controller/render_test.rb
  57. +0 −1 actionpack/test/controller/rescue_test.rb
  58. +3 −59 actionpack/test/controller/routing_test.rb
  59. +8 −9 actionpack/test/controller/verification_test.rb
  60. +0 −1 actionpack/test/controller/webservice_test.rb
  61. +0 −1 actionpack/test/dispatch/request/json_params_parsing_test.rb
  62. +0 −1 actionpack/test/dispatch/request/multipart_params_parsing_test.rb
  63. +0 −1 actionpack/test/dispatch/request/query_string_parsing_test.rb
  64. +0 −1 actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb
  65. +0 −1 actionpack/test/dispatch/request/xml_params_parsing_test.rb
  66. +0 −1 actionpack/test/dispatch/session/cookie_store_test.rb
  67. +0 −1 actionpack/test/dispatch/session/mem_cache_store_test.rb
  68. +40 −0 actionpack/test/dispatch/string_coercion_test.rb
  69. +18 −13 actionpack/test/lib/controller/fake_controllers.rb
  70. +96 −0 actionpack/test/lib/controller/fake_models.rb
  71. +7 −8 actionpack/test/{javascript → template}/ajax_test.rb
  72. +12 −0 actionpack/test/template/asset_tag_helper_test.rb
  73. +12 −0 actionpack/test/template/erb_util_test.rb
  74. +2 −100 actionpack/test/template/form_helper_test.rb
  75. 0 actionpack/test/{ → template}/html-scanner/cdata_node_test.rb
  76. 0 actionpack/test/{ → template}/html-scanner/document_test.rb
  77. 0 actionpack/test/{ → template}/html-scanner/node_test.rb
  78. 0 actionpack/test/{ → template}/html-scanner/sanitizer_test.rb
  79. 0 actionpack/test/{ → template}/html-scanner/tag_node_test.rb
  80. 0 actionpack/test/{ → template}/html-scanner/text_node_test.rb
  81. 0 actionpack/test/{ → template}/html-scanner/tokenizer_test.rb
  82. +21 −0 actionpack/test/template/raw_output_helper_test.rb
  83. +2 −1 actionpack/test/template/record_tag_helper_test.rb
  84. +1 −1 actionpack/test/template/render_test.rb
  85. +10 −1 actionpack/test/template/sanitize_helper_test.rb
  86. +1 −0 actionpack/test/template/tag_helper_test.rb
  87. +2 −1 actionpack/test/{view → template}/test_case_test.rb
  88. +23 −14 actionpack/test/template/test_test.rb
  89. +1 −1 actionpack/test/template/url_helper_test.rb
  90. +17 −0 actionpack/test/ts_isolated.rb
  91. +41 −0 actionpack/test/view/safe_buffer_test.rb
  92. +5 −2 activemodel/lib/active_model/attribute_methods.rb
  93. +30 −48 activemodel/lib/active_model/lint.rb
  94. +46 −0 activemodel/test/cases/attribute_methods_test.rb
  95. +8 −32 activemodel/test/cases/lint_test.rb
  96. +38 −27 activerecord/lib/active_record/base.rb
  97. +63 −20 activerecord/lib/active_record/nested_attributes.rb
  98. +1 −1 activerecord/test/cases/base_test.rb
  99. +62 −4 activerecord/test/cases/nested_attributes_test.rb
  100. +4 −0 activerecord/test/models/pirate.rb
  101. +36 −6 activeresource/lib/active_resource/base.rb
  102. +4 −1 activeresource/lib/active_resource/exceptions.rb
  103. +22 −16 activeresource/test/cases/base/load_test.rb
  104. +67 −3 activeresource/test/cases/base_test.rb
  105. +1 −1 activeresource/test/cases/observing_test.rb
  106. +1 −1 activeresource/test/connection_test.rb
  107. +7 −0 activesupport/lib/active_support/cache.rb
  108. +2 −0 activesupport/lib/active_support/cache/memory_store.rb
  109. +5 −5 activesupport/lib/active_support/cache/strategy/local_cache.rb
  110. +2 −1 activesupport/lib/active_support/core_ext/string.rb
  111. +43 −0 activesupport/lib/active_support/core_ext/string/output_safety.rb
  112. +3 −1 activesupport/lib/active_support/message_verifier.rb
  113. +3 −1 activesupport/lib/active_support/testing/isolation.rb
  114. +19 −0 activesupport/test/caching_test.rb
  115. +86 −0 activesupport/test/core_ext/string_ext_test.rb
  116. +6 −0 activesupport/test/message_verifier_test.rb
  117. +1 −0 ci/ci_build.rb
  118. +471 −13 railties/lib/rails/application.rb
  119. +0 −86 railties/lib/rails/commands/ncgi/listener
  120. +1 −5 railties/lib/rails/core.rb
  121. +0 −239 railties/lib/rails/fcgi_handler.rb
  122. +1 −1 railties/lib/rails/generators/erb/scaffold/templates/index.html.erb
  123. +1 −1 railties/lib/rails/generators/erb/scaffold/templates/show.html.erb
  124. +0 −16 railties/lib/rails/generators/rails/app/app_generator.rb
  125. +6 −7 railties/lib/rails/generators/rails/app/templates/config/boot.rb
  126. +0 −24 railties/lib/rails/generators/rails/app/templates/dispatchers/dispatch.fcgi
  127. +0 −10 railties/lib/rails/generators/rails/app/templates/dispatchers/dispatch.rb
  128. +0 −97 railties/lib/rails/generators/rails/app/templates/dispatchers/gateway.cgi
  129. +99 −0 railties/lib/rails/initializable.rb
  130. +3 −557 railties/lib/rails/initializer.rb
  131. +0 −1,137 railties/lib/rails/initializer_old.rb
  132. +0 −5 railties/lib/rails/tasks/framework.rake
  133. +1 −1 railties/rails.gemspec
  134. +0 −8 railties/test/abstract_unit.rb
  135. +52 −0 railties/test/application/console_test.rb
  136. +89 −0 railties/test/application/generators_test.rb
  137. +194 −0 railties/test/application/initializer_test.rb
  138. +8 −1 railties/test/application/load_test.rb
  139. +101 −0 railties/test/application/plugins_test.rb
  140. +0 −43 railties/test/console_app_test.rb
  141. +0 −268 railties/test/fcgi_dispatcher_test.rb
  142. +0 −12 railties/test/generators/app_generator_test.rb
  143. +68 −0 railties/test/initializable_test.rb
  144. +51 −0 railties/test/initializer/initialize_i18n_test.rb
  145. +1 −1 railties/test/initializer/path_test.rb
  146. +0 −482 railties/test/initializer_test.rb
  147. +12 −1 railties/test/isolation/abstract_unit.rb
  148. +0 −165 railties/test/new_initializer_test.rb
  149. +10 −7 railties/test/plugin_loader_test.rb
  150. +13 −3 railties/test/plugin_locator_test.rb
  151. +13 −2 railties/test/plugin_test.rb
View
1 .gitignore
@@ -30,5 +30,4 @@ railties/guides/output
actionpack/bin
vendor/gems/
*/vendor/gems/
-bin/
railties/tmp
View
2 actionmailer/test/fixtures/helpers/example_helper.rb
@@ -1,5 +1,5 @@
module ExampleHelper
def example_format(text)
- "<em><strong><small>#{text}</small></strong></em>"
+ "<em><strong><small>#{h(text)}</small></strong></em>".html_safe!
end
end
View
1 actionpack/Gemfile
@@ -4,6 +4,7 @@ gem "rack", "~> 1.0.0"
gem "rack-test", "~> 0.5.0"
gem "activesupport", "3.0.pre", :vendored_at => rails_root.join("activesupport")
gem "activemodel", "3.0.pre", :vendored_at => rails_root.join("activemodel")
+gem "erubis", "~> 2.6.0"
only :test do
gem "mocha"
View
11 actionpack/Rakefile
@@ -34,22 +34,21 @@ end
desc "Run all unit tests"
task :test => [:test_action_pack, :test_active_record_integration]
-TESTS_GLOB = "test/{abstract,controller,dispatch,new_base,template,html-scanner,view}/**/*_test.rb"
-
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(TESTS_GLOB).sort
+ t.test_files = Dir.glob('test/{abstract,controller,dispatch,template}/**/*_test.rb').sort
t.verbose = true
# t.warning = true
end
-task :isolated_test do
- ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
- Dir.glob(TESTS_GLOB).all? { |file| system(ruby, '-Ilib:test', file) } or raise "Failures"
+namespace :test do
+ Rake::TestTask.new(:isolated) do |t|
+ t.pattern = 'test/ts_isolated.rb'
+ end
end
desc 'ActiveRecord Integration Tests'
View
2 actionpack/lib/action_controller/dispatch/dispatcher.rb
@@ -50,7 +50,7 @@ def define_dispatcher_callbacks(cache_classes)
def new
# DEPRECATE Rails application fallback
- Rails.application
+ Rails.application.new
end
end
end
View
2 actionpack/lib/action_controller/metal/session_management.rb
@@ -16,7 +16,7 @@ def session_store=(store)
self.session_store = ActiveRecord::SessionStore
else
@@session_store = store.is_a?(Symbol) ?
- Session.const_get(store.to_s.camelize) :
+ ActionDispatch::Session.const_get(store.to_s.camelize) :
store
end
end
View
1 actionpack/lib/action_dispatch.rb
@@ -39,6 +39,7 @@ module ActionDispatch
autoload :Rescue, 'action_dispatch/middleware/rescue'
autoload :ShowExceptions, 'action_dispatch/middleware/show_exceptions'
autoload :Static, 'action_dispatch/middleware/static'
+ autoload :StringCoercion, 'action_dispatch/middleware/string_coercion'
autoload :Assertions, 'action_dispatch/testing/assertions'
autoload :Integration, 'action_dispatch/testing/integration'
View
7 actionpack/lib/action_dispatch/http/mime_type.rb
@@ -10,7 +10,12 @@ def symbols
%w(<< concat shift unshift push pop []= clear compact! collect!
delete delete_at delete_if flatten! map! insert reject! reverse!
replace slice! sort! uniq!).each do |method|
- define_method(method) {|*args| @symbols = nil; super(*args) }
+ module_eval <<-CODE
+ def #{method}(*args)
+ @symbols = nil
+ super
+ end
+ CODE
end
end
View
29 actionpack/lib/action_dispatch/middleware/string_coercion.rb
@@ -0,0 +1,29 @@
+module ActionDispatch
+ class StringCoercion
+ class UglyBody < ActiveSupport::BasicObject
+ def initialize(body)
+ @body = body
+ end
+
+ def each
+ @body.each do |part|
+ yield part.to_s
+ end
+ end
+
+ private
+ def method_missing(*args, &block)
+ @body.__send__(*args, &block)
+ end
+ end
+
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ status, headers, body = @app.call(env)
+ [status, headers, UglyBody.new(body)]
+ end
+ end
+end
View
6 actionpack/lib/action_view.rb
@@ -44,11 +44,11 @@ def self.load_all!
autoload :TextTemplate, 'action_view/template/text'
autoload :Helpers, 'action_view/helpers'
autoload :FileSystemResolverWithFallback, 'action_view/template/resolver'
+ autoload :SafeBuffer, 'action_view/safe_buffer'
end
-class ERB
- autoload :Util, 'action_view/erb/util'
-end
+require 'action_view/erb/util'
+
I18n.load_path << "#{File.dirname(__FILE__)}/action_view/locale/en.yml"
View
13 actionpack/lib/action_view/base.rb
@@ -236,7 +236,16 @@ def self.for_controller(controller)
# they are in AC.
if controller.class.respond_to?(:_helper_serial)
klass = @views[controller.class._helper_serial] ||= Class.new(self) do
- Subclasses.const_set(controller.class.name.gsub(/::/, '__'), self)
+ const_set(:CONTROLLER_CLASS, controller.class)
+
+ # Try to make stack traces clearer
+ def self.name
+ "ActionView for #{CONTROLLER_CLASS}"
+ end
+
+ def inspect
+ "#<#{self.class.name}>"
+ end
if controller.respond_to?(:_helpers)
include controller._helpers
@@ -255,7 +264,7 @@ def initialize(view_paths = [], assigns_for_first_render = {}, controller = nil,
@assigns = assigns_for_first_render.each { |key, value| instance_variable_set("@#{key}", value) }
@controller = controller
@helpers = self.class.helpers || Module.new
- @_content_for = Hash.new {|h,k| h[k] = "" }
+ @_content_for = Hash.new {|h,k| h[k] = ActionView::SafeBuffer.new }
self.view_paths = view_paths
end
View
12 actionpack/lib/action_view/erb/util.rb
@@ -15,9 +15,19 @@ module Util
# puts html_escape("is a > 0 & a < 10?")
# # => is a &gt; 0 &amp; a &lt; 10?
def html_escape(s)
- s.to_s.gsub(/[&"><]/) { |special| HTML_ESCAPE[special] }
+ s = s.to_s
+ if s.html_safe?
+ s
+ else
+ s.gsub(/[&"><]/) { |special| HTML_ESCAPE[special] }.html_safe!
+ end
end
+ alias h html_escape
+
+ module_function :html_escape
+ module_function :h
+
# A utility method for escaping HTML entities in JSON strings.
# This method is also aliased as <tt>j</tt>.
#
View
2 actionpack/lib/action_view/helpers.rb
@@ -15,6 +15,7 @@ module Helpers #:nodoc:
autoload :JavaScriptHelper, 'action_view/helpers/javascript_helper'
autoload :NumberHelper, 'action_view/helpers/number_helper'
autoload :PrototypeHelper, 'action_view/helpers/prototype_helper'
+ autoload :RawOutputHelper, 'action_view/helpers/raw_output_helper'
autoload :RecordIdentificationHelper, 'action_view/helpers/record_identification_helper'
autoload :RecordTagHelper, 'action_view/helpers/record_tag_helper'
autoload :SanitizeHelper, 'action_view/helpers/sanitize_helper'
@@ -46,6 +47,7 @@ module ClassMethods
include JavaScriptHelper
include NumberHelper
include PrototypeHelper
+ include RawOutputHelper
include RecordIdentificationHelper
include RecordTagHelper
include SanitizeHelper
View
3 actionpack/lib/action_view/helpers/active_model_helper.rb
@@ -6,7 +6,7 @@
module ActionView
class Base
- @@field_error_proc = Proc.new{ |html_tag, instance| "<div class=\"fieldWithErrors\">#{html_tag}</div>" }
+ @@field_error_proc = Proc.new{ |html_tag, instance| "<div class=\"fieldWithErrors\">#{html_tag}</div>".html_safe! }
cattr_accessor :field_error_proc
end
@@ -91,6 +91,7 @@ def form(record_name, options = {})
yield contents if block_given?
contents << submit_tag(submit_value)
contents << '</form>'
+ contents.html_safe!
end
# Returns a string containing the error message attached to the +method+ on the +object+ if one exists.
View
6 actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -289,7 +289,7 @@ def javascript_include_tag(*sources)
else
sources = expand_javascript_sources(sources, recursive)
ensure_javascript_sources!(sources) if cache
- sources.collect { |source| javascript_src_tag(source, options) }.join("\n")
+ sources.collect { |source| javascript_src_tag(source, options) }.join("\n").html_safe!
end
end
@@ -440,7 +440,7 @@ def stylesheet_link_tag(*sources)
else
sources = expand_stylesheet_sources(sources, recursive)
ensure_stylesheet_sources!(sources) if cache
- sources.collect { |source| stylesheet_tag(source, options) }.join("\n")
+ sources.collect { |source| stylesheet_tag(source, options) }.join("\n").html_safe!
end
end
@@ -584,7 +584,7 @@ def video_tag(sources, options = {})
if sources.is_a?(Array)
content_tag("video", options) do
- sources.map { |source| tag("source", :src => source) }.join
+ sources.map { |source| tag("source", :src => source) }.join.html_safe!
end
else
options[:src] = path_to_video(sources)
View
2 actionpack/lib/action_view/helpers/capture_helper.rb
@@ -143,7 +143,7 @@ def content_for?(name)
# Defaults to a new empty string.
def with_output_buffer(buf = nil) #:nodoc:
unless buf
- buf = ''
+ buf = ActionView::SafeBuffer.new
buf.force_encoding(output_buffer.encoding) if buf.respond_to?(:force_encoding)
end
self.output_buffer, old_buffer = buf, output_buffer
View
6 actionpack/lib/action_view/helpers/date_helper.rb
@@ -916,15 +916,15 @@ def separator(type)
class InstanceTag #:nodoc:
def to_date_select_tag(options = {}, html_options = {})
- datetime_selector(options, html_options).select_date
+ datetime_selector(options, html_options).select_date.html_safe!
end
def to_time_select_tag(options = {}, html_options = {})
- datetime_selector(options, html_options).select_time
+ datetime_selector(options, html_options).select_time.html_safe!
end
def to_datetime_select_tag(options = {}, html_options = {})
- datetime_selector(options, html_options).select_datetime
+ datetime_selector(options, html_options).select_datetime.html_safe!
end
private
View
4 actionpack/lib/action_view/helpers/form_helper.rb
@@ -282,7 +282,7 @@ def form_for(record_or_name_or_array, *args, &proc)
concat(form_tag(options.delete(:url) || {}, options.delete(:html) || {}))
fields_for(object_name, *(args << options), &proc)
- concat('</form>')
+ concat('</form>'.html_safe!)
end
def apply_form_for_options!(object_or_array, options) #:nodoc:
@@ -809,7 +809,7 @@ def to_check_box_tag(options = {}, checked_value = "1", unchecked_value = "0")
add_default_name_and_id(options)
hidden = tag("input", "name" => options["name"], "type" => "hidden", "value" => options['disabled'] && checked ? checked_value : unchecked_value)
checkbox = tag("input", options)
- hidden + checkbox
+ (hidden + checkbox).html_safe!
end
def to_boolean_select_tag(options = {})
View
2 actionpack/lib/action_view/helpers/form_options_helper.rb
@@ -296,7 +296,7 @@ def options_for_select(container, selected = nil)
options << %(<option value="#{html_escape(value.to_s)}"#{selected_attribute}#{disabled_attribute}>#{html_escape(text.to_s)}</option>)
end
- options_for_select.join("\n")
+ options_for_select.join("\n").html_safe!
end
# Returns a string of option tags that have been compiled by iterating over the +collection+ and assigning the
View
6 actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -440,7 +440,7 @@ def field_set_tag(legend = nil, options = nil, &block)
concat(tag(:fieldset, options, true))
concat(content_tag(:legend, legend)) unless legend.blank?
concat(content)
- concat("</fieldset>")
+ concat("</fieldset>".html_safe!)
end
private
@@ -467,14 +467,14 @@ def extra_tags_for_form(html_options)
def form_tag_html(html_options)
extra_tags = extra_tags_for_form(html_options)
- tag(:form, html_options, true) + extra_tags
+ (tag(:form, html_options, true) + extra_tags).html_safe!
end
def form_tag_in_block(html_options, &block)
content = capture(&block)
concat(form_tag_html(html_options))
concat(content)
- concat("</form>")
+ concat("</form>".html_safe!)
end
def token_tag
View
1 actionpack/lib/action_view/helpers/number_helper.rb
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/big_decimal/conversions'
require 'active_support/core_ext/float/rounding'
module ActionView
View
2 actionpack/lib/action_view/helpers/prototype_helper.rb
@@ -395,7 +395,7 @@ def remote_form_for(record_or_name_or_array, *args, &proc)
concat(form_remote_tag(options))
fields_for(object_name, *(args << options), &proc)
- concat('</form>')
+ concat('</form>'.html_safe!)
end
alias_method :form_remote_for, :remote_form_for
View
9 actionpack/lib/action_view/helpers/raw_output_helper.rb
@@ -0,0 +1,9 @@
+module ActionView #:nodoc:
+ module Helpers #:nodoc:
+ module RawOutputHelper
+ def raw(stringish)
+ stringish.to_s.html_safe!
+ end
+ end
+ end
+end
View
6 actionpack/lib/action_view/helpers/record_tag_helper.rb
@@ -15,7 +15,7 @@ module RecordTagHelper
def div_for(record, *args, &block)
content_tag_for(:div, record, *args, &block)
end
-
+
# content_tag_for creates an HTML element with id and class parameters
# that relate to the specified Active Record object. For example:
#
@@ -34,7 +34,7 @@ def div_for(record, *args, &block)
# <% content_tag_for(:tr, @person, :foo) do %> ...
#
# produces:
- #
+ #
# <tr id="foo_person_123" class="person">...
#
# content_tag_for also accepts a hash of options, which will be converted to
@@ -50,7 +50,7 @@ def div_for(record, *args, &block)
def content_tag_for(tag_name, record, *args, &block)
prefix = args.first.is_a?(Hash) ? nil : args.shift
options = args.extract_options!
- options.merge!({ :class => "#{dom_class(record)} #{options[:class]}".strip, :id => dom_id(record, prefix) })
+ options.merge!({ :class => "#{dom_class(record, prefix)} #{options[:class]}".strip, :id => dom_id(record, prefix) })
content_tag(tag_name, options, &block)
end
end
View
12 actionpack/lib/action_view/helpers/sanitize_helper.rb
@@ -49,7 +49,11 @@ module SanitizeHelper
# confuse browsers.
#
def sanitize(html, options = {})
- self.class.white_list_sanitizer.sanitize(html, options)
+ returning self.class.white_list_sanitizer.sanitize(html, options) do |sanitized|
+ if sanitized
+ sanitized.html_safe!
+ end
+ end
end
# Sanitizes a block of CSS code. Used by +sanitize+ when it comes across a style attribute.
@@ -72,7 +76,11 @@ def sanitize_css(style)
# strip_tags("<div id='top-bar'>Welcome to my website!</div>")
# # => Welcome to my website!
def strip_tags(html)
- self.class.full_sanitizer.sanitize(html)
+ returning self.class.full_sanitizer.sanitize(html) do |sanitized|
+ if sanitized
+ sanitized.html_safe!
+ end
+ end
end
# Strips all link tags from +text+ leaving just the link text.
View
8 actionpack/lib/action_view/helpers/tag_helper.rb
@@ -41,7 +41,7 @@ module TagHelper
# tag("img", { :src => "open &amp; shut.png" }, false, false)
# # => <img src="open &amp; shut.png" />
def tag(name, options = nil, open = false, escape = true)
- "<#{name}#{tag_options(options, escape) if options}#{open ? ">" : " />"}"
+ "<#{name}#{tag_options(options, escape) if options}#{open ? ">" : " />"}".html_safe!
end
# Returns an HTML block tag of type +name+ surrounding the +content+. Add
@@ -94,7 +94,7 @@ def content_tag(name, content_or_options_with_block = nil, options = nil, escape
# cdata_section(File.read("hello_world.txt"))
# # => <![CDATA[<hello from a text file]]>
def cdata_section(content)
- "<![CDATA[#{content}]]>"
+ "<![CDATA[#{content}]]>".html_safe!
end
# Returns an escaped version of +html+ without affecting existing escaped entities.
@@ -128,7 +128,7 @@ def block_called_from_erb?(block)
def content_tag_string(name, content, options, escape = true)
tag_options = tag_options(options, escape) if options
- "<#{name}#{tag_options}>#{content}</#{name}>"
+ "<#{name}#{tag_options}>#{content}</#{name}>".html_safe!
end
def tag_options(options, escape = true)
@@ -143,7 +143,7 @@ def tag_options(options, escape = true)
attrs << %(#{key}="#{final_value}")
end
end
- " #{attrs.sort * ' '}" unless attrs.empty?
+ " #{attrs.sort * ' '}".html_safe! unless attrs.empty?
end
end
end
View
10 actionpack/lib/action_view/helpers/url_helper.rb
@@ -93,7 +93,7 @@ def url_for(options = {})
polymorphic_path(options)
end
- escape ? escape_once(url) : url
+ (escape ? escape_once(url) : url).html_safe!
end
# Creates a link tag of the given +name+ using a URL created by the set
@@ -220,7 +220,7 @@ def link_to(*args, &block)
if block_given?
options = args.first || {}
html_options = args.second
- concat(link_to(capture(&block), options, html_options))
+ concat(link_to(capture(&block), options, html_options).html_safe!)
else
name = args[0]
options = args[1] || {}
@@ -238,7 +238,7 @@ def link_to(*args, &block)
end
href_attr = "href=\"#{url}\"" unless href
- "<a #{href_attr}#{tag_options}>#{name || url}</a>"
+ "<a #{href_attr}#{tag_options}>#{ERB::Util.h(name || url)}</a>".html_safe!
end
end
@@ -309,8 +309,8 @@ def button_to(name, options = {}, html_options = {})
html_options.merge!("type" => "submit", "value" => name)
- "<form method=\"#{form_method}\" action=\"#{escape_once url}\" class=\"button-to\"><div>" +
- method_tag + tag("input", html_options) + request_token_tag + "</div></form>"
+ ("<form method=\"#{form_method}\" action=\"#{escape_once url}\" class=\"button-to\"><div>" +
+ method_tag + tag("input", html_options) + request_token_tag + "</div></form>").html_safe!
end
View
7 actionpack/lib/action_view/paths.rb
@@ -1,8 +1,11 @@
module ActionView #:nodoc:
class PathSet < Array #:nodoc:
- def self.type_cast(obj)
+ def self.type_cast(obj, cache = nil)
+ # TODO: Clean this up
if obj.is_a?(String)
- cache = !defined?(Rails) || !Rails.respond_to?(:configuration) || Rails.configuration.cache_classes
+ if cache.nil?
+ cache = !defined?(Rails) || Rails.application.config.cache_classes
+ end
FileSystemResolverWithFallback.new(obj, :cache => cache)
else
obj
View
7 actionpack/lib/action_view/render/partials.rb
@@ -223,7 +223,7 @@ def render_collection
end
result = template ? collection_with_template(template) : collection_without_template
- result.join(spacer)
+ result.join(spacer).html_safe!
end
def collection_with_template(template)
@@ -296,7 +296,10 @@ def find_template(path = @path)
end
def _find_template(path)
- prefix = @view.controller.controller_path unless path.include?(?/)
+ if controller = @view.controller
+ prefix = controller.controller_path unless path.include?(?/)
+ end
+
@view.find(path, {:formats => @view.formats}, prefix, true)
end
View
22 actionpack/lib/action_view/render/rendering.rb
@@ -14,6 +14,7 @@ def render(options = {}, locals = {}, &block) #:nodoc:
case options
when Hash
layout = options[:layout]
+ options[:locals] ||= {}
if block_given?
return concat(_render_partial(options.merge(:partial => layout), &block))
@@ -25,11 +26,11 @@ def render(options = {}, locals = {}, &block) #:nodoc:
if file = options[:file]
template = find(file, {:formats => formats})
- _render_template(template, layout, :locals => options[:locals] || {})
+ _render_template(template, layout, :locals => options[:locals])
elsif inline = options[:inline]
_render_inline(inline, layout, options)
elsif text = options[:text]
- _render_text(text, layout, options)
+ _render_text(text, layout, options[:locals])
end
when :update
update_page(&block)
@@ -80,16 +81,19 @@ def _layout_for(name = nil)
def _render_inline(inline, layout, options)
handler = Template.handler_class_for_extension(options[:type] || "erb")
- template = Template.new(options[:inline], "inline #{options[:inline].inspect}", handler, {})
- locals = options[:locals] || {}
+ template = Template.new(options[:inline],
+ "inline #{options[:inline].inspect}", handler, {})
+
+ locals = options[:locals]
content = template.render(self, locals)
- content = layout.render(self, locals) {|*name| _layout_for(*name) { content } } if layout
- content
+ _render_text(content, layout, locals)
end
- def _render_text(text, layout, options)
- text = layout.render(self, options[:locals]) { text } if layout
- text
+ def _render_text(content, layout, locals)
+ content = layout.render(self, locals) do |*name|
+ _layout_for(*name) { content }
+ end if layout
+ content
end
# This is the API to render a ViewContext's template from a controller.
View
28 actionpack/lib/action_view/safe_buffer.rb
@@ -0,0 +1,28 @@
+
+module ActionView #:nodoc:
+ class SafeBuffer < String
+ def <<(value)
+ if value.html_safe?
+ super(value)
+ else
+ super(CGI.escapeHTML(value))
+ end
+ end
+
+ def concat(value)
+ self << value
+ end
+
+ def html_safe?
+ true
+ end
+
+ def html_safe!
+ self
+ end
+
+ def to_s
+ self
+ end
+ end
+end
View
28 actionpack/lib/action_view/template/handlers/erb.rb
@@ -1,7 +1,31 @@
require 'active_support/core_ext/class/attribute_accessors'
+require 'active_support/core_ext/string/output_safety'
+require 'erubis'
module ActionView
module TemplateHandlers
+ class Erubis < ::Erubis::Eruby
+ def add_preamble(src)
+ src << "@output_buffer = ActionView::SafeBuffer.new;"
+ end
+
+ def add_text(src, text)
+ src << "@output_buffer << ('" << escape_text(text) << "'.html_safe!);"
+ end
+
+ def add_expr_literal(src, code)
+ src << '@output_buffer << ((' << code << ').to_s);'
+ end
+
+ def add_expr_escaped(src, code)
+ src << '@output_buffer << ' << escaped_expr(code) << ';'
+ end
+
+ def add_postamble(src)
+ src << '@output_buffer.to_s'
+ end
+ end
+
class ERB < TemplateHandler
include Compilable
@@ -15,11 +39,9 @@ class ERB < TemplateHandler
self.default_format = Mime::HTML
def compile(template)
- require 'erb'
-
magic = $1 if template.source =~ /\A(<%#.*coding[:=]\s*(\S+)\s*-?%>)/
erb = "#{magic}<% __in_erb_template=true %>#{template.source}"
- ::ERB.new(erb, nil, erb_trim_mode, '@output_buffer').src
+ Erubis.new(erb, :trim=>(self.class.erb_trim_mode == "-")).src
end
end
end
View
2 actionpack/lib/action_view/test_case.rb
@@ -55,7 +55,7 @@ def initialize
setup :setup_with_controller
def setup_with_controller
@controller = TestController.new
- @output_buffer = ''
+ @output_buffer = ActionView::SafeBuffer.new
@rendered = ''
self.class.send(:include_helper_modules!)
View
94 actionpack/test/abstract_unit.rb
@@ -51,23 +51,73 @@
ORIGINAL_LOCALES = I18n.available_locales.map {|locale| locale.to_s }.sort
FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
+FIXTURES = Pathname.new(FIXTURE_LOAD_PATH)
-class ActionController::IntegrationTest < ActiveSupport::TestCase
- @@app = ActionDispatch::MiddlewareStack.new { |middleware|
- middleware.use "ActionDispatch::ShowExceptions"
- middleware.use "ActionDispatch::Callbacks"
- middleware.use "ActionDispatch::ParamsParser"
- middleware.use "Rack::Head"
- }.build(ActionController::Routing::Routes)
-end
+module SetupOnce
+ extend ActiveSupport::Concern
-module ActionView
- class TestCase
- setup do
- ActionController::Routing::Routes.draw do |map|
- map.connect ':controller/:action/:id'
+ included do
+ cattr_accessor :setup_once_block
+ self.setup_once_block = nil
+
+ setup :run_setup_once
+ end
+
+ module ClassMethods
+ def setup_once(&block)
+ self.setup_once_block = block
+ end
+ end
+
+ private
+ def run_setup_once
+ if self.setup_once_block
+ self.setup_once_block.call
+ self.setup_once_block = nil
end
end
+end
+
+class ActiveSupport::TestCase
+ include SetupOnce
+
+ # Hold off drawing routes until all the possible controller classes
+ # have been loaded.
+ setup_once do
+ ActionController::Routing::Routes.draw do |map|
+ map.connect ':controller/:action/:id'
+ end
+ end
+end
+
+class ActionController::IntegrationTest < ActiveSupport::TestCase
+ def self.build_app(routes = nil)
+ ActionDispatch::MiddlewareStack.new { |middleware|
+ middleware.use "ActionDispatch::StringCoercion"
+ middleware.use "ActionDispatch::ShowExceptions"
+ middleware.use "ActionDispatch::Callbacks"
+ middleware.use "ActionDispatch::ParamsParser"
+ middleware.use "Rack::Head"
+ }.build(routes || ActionController::Routing::Routes)
+ end
+
+ self.app = build_app
+
+ def with_routing(&block)
+ real_routes = ActionController::Routing::Routes
+ ActionController::Routing.module_eval { remove_const :Routes }
+
+ temporary_routes = ActionController::Routing::RouteSet.new
+ self.class.app = self.class.build_app(temporary_routes)
+ ActionController::Routing.module_eval { const_set :Routes, temporary_routes }
+
+ yield temporary_routes
+ ensure
+ if ActionController::Routing.const_defined? :Routes
+ ActionController::Routing.module_eval { remove_const :Routes }
+ end
+ ActionController::Routing.const_set(:Routes, real_routes) if real_routes
+ self.class.app = self.class.build_app
end
end
@@ -138,18 +188,12 @@ def self.inherited(klass)
super
end
end
-
+
Base.view_paths = FIXTURE_LOAD_PATH
-
+
class TestCase
include TestProcess
- setup do
- ActionController::Routing::Routes.draw do |map|
- map.connect ':controller/:action/:id'
- end
- end
-
def assert_template(options = {}, message = nil)
validate_request!
@@ -192,11 +236,3 @@ def assert_template(options = {}, message = nil)
end
end
end
-
-class SimpleRouteCase < Rack::TestCase
- setup do
- ActionController::Routing::Routes.draw do |map|
- map.connect ':controller/:action/:id'
- end
- end
-end
View
1 actionpack/test/activerecord/active_record_store_test.rb
@@ -158,7 +158,6 @@ def with_test_route_set(options = {})
map.connect "/:action", :controller => "active_record_store_test/test"
end
@app = ActiveRecord::SessionStore.new(set, options.reverse_merge(:key => '_session_id'))
- reset!
yield
end
end
View
22 actionpack/test/controller/caching_test.rb
@@ -46,14 +46,8 @@ def trailing_slash
class PageCachingTest < ActionController::TestCase
def setup
super
- ActionController::Base.perform_caching = true
- ActionController::Routing::Routes.draw do |map|
- map.main '', :controller => 'posts', :format => nil
- map.formatted_posts 'posts.:format', :controller => 'posts'
- map.resources :posts
- map.connect ':controller/:action/:id'
- end
+ ActionController::Base.perform_caching = true
@request = ActionController::TestRequest.new
@request.host = 'hostname.com'
@@ -74,10 +68,16 @@ def teardown
end
def test_page_caching_resources_saves_to_correct_path_with_extension_even_if_default_route
- @params[:format] = 'rss'
- assert_equal '/posts.rss', @rewriter.rewrite(@params)
- @params[:format] = nil
- assert_equal '/', @rewriter.rewrite(@params)
+ with_routing do |set|
+ set.draw do |map|
+ map.main '', :controller => 'posts', :format => nil
+ map.formatted_posts 'posts.:format', :controller => 'posts'
+ end
+ @params[:format] = 'rss'
+ assert_equal '/posts.rss', @rewriter.rewrite(@params)
+ @params[:format] = nil
+ assert_equal '/', @rewriter.rewrite(@params)
+ end
end
def test_should_cache_get_with_ok_status
View
5 actionpack/test/controller/integration_test.rb
@@ -372,11 +372,8 @@ def test_generate_url_with_controller
def with_test_route_set
with_routing do |set|
set.draw do |map|
- map.with_options :controller => "IntegrationProcessTest::Integration" do |c|
- c.connect "/:action"
- end
+ map.connect "/:action", :controller => "integration_process_test/integration"
end
- reset!
yield
end
end
View
150 actionpack/test/controller/mime_responds_test.rb
@@ -527,12 +527,6 @@ def setup
super
ActionController::Base.use_accept_header = true
@request.host = "www.example.com"
-
- ActionController::Routing::Routes.draw do |map|
- map.resources :customers
- map.resources :quiz_stores, :has_many => :customers
- map.connect ":controller/:action/:id"
- end
end
def teardown
@@ -593,53 +587,59 @@ def test_using_resource
end
def test_using_resource_for_post_with_html
- post :using_resource
- assert_equal "text/html", @response.content_type
- assert_equal 302, @response.status
- assert_equal "http://www.example.com/customers/13", @response.location
- assert @response.redirect?
-
- errors = { :name => :invalid }
- Customer.any_instance.stubs(:errors).returns(errors)
- post :using_resource
- assert_equal "text/html", @response.content_type
- assert_equal 200, @response.status
- assert_equal "New world!\n", @response.body
- assert_nil @response.location
+ with_test_route_set do
+ post :using_resource
+ assert_equal "text/html", @response.content_type
+ assert_equal 302, @response.status
+ assert_equal "http://www.example.com/customers/13", @response.location
+ assert @response.redirect?
+
+ errors = { :name => :invalid }
+ Customer.any_instance.stubs(:errors).returns(errors)
+ post :using_resource
+ assert_equal "text/html", @response.content_type
+ assert_equal 200, @response.status
+ assert_equal "New world!\n", @response.body
+ assert_nil @response.location
+ end
end
def test_using_resource_for_post_with_xml
- @request.accept = "application/xml"
-
- post :using_resource
- assert_equal "application/xml", @response.content_type
- assert_equal 201, @response.status
- assert_equal "<name>david</name>", @response.body
- assert_equal "http://www.example.com/customers/13", @response.location
-
- errors = { :name => :invalid }
- Customer.any_instance.stubs(:errors).returns(errors)
- post :using_resource
- assert_equal "application/xml", @response.content_type
- assert_equal 422, @response.status
- assert_equal errors.to_xml, @response.body
- assert_nil @response.location
+ with_test_route_set do
+ @request.accept = "application/xml"
+
+ post :using_resource
+ assert_equal "application/xml", @response.content_type
+ assert_equal 201, @response.status
+ assert_equal "<name>david</name>", @response.body
+ assert_equal "http://www.example.com/customers/13", @response.location
+
+ errors = { :name => :invalid }
+ Customer.any_instance.stubs(:errors).returns(errors)
+ post :using_resource
+ assert_equal "application/xml", @response.content_type
+ assert_equal 422, @response.status
+ assert_equal errors.to_xml, @response.body
+ assert_nil @response.location
+ end
end
def test_using_resource_for_put_with_html
- put :using_resource
- assert_equal "text/html", @response.content_type
- assert_equal 302, @response.status
- assert_equal "http://www.example.com/customers/13", @response.location
- assert @response.redirect?
-
- errors = { :name => :invalid }
- Customer.any_instance.stubs(:errors).returns(errors)
- put :using_resource
- assert_equal "text/html", @response.content_type
- assert_equal 200, @response.status
- assert_equal "Edit world!\n", @response.body
- assert_nil @response.location
+ with_test_route_set do
+ put :using_resource
+ assert_equal "text/html", @response.content_type
+ assert_equal 302, @response.status
+ assert_equal "http://www.example.com/customers/13", @response.location
+ assert @response.redirect?
+
+ errors = { :name => :invalid }
+ Customer.any_instance.stubs(:errors).returns(errors)
+ put :using_resource
+ assert_equal "text/html", @response.content_type
+ assert_equal 200, @response.status
+ assert_equal "Edit world!\n", @response.body
+ assert_nil @response.location
+ end
end
def test_using_resource_for_put_with_xml
@@ -660,11 +660,13 @@ def test_using_resource_for_put_with_xml
end
def test_using_resource_for_delete_with_html
- Customer.any_instance.stubs(:destroyed?).returns(true)
- delete :using_resource
- assert_equal "text/html", @response.content_type
- assert_equal 302, @response.status
- assert_equal "http://www.example.com/customers", @response.location
+ with_test_route_set do
+ Customer.any_instance.stubs(:destroyed?).returns(true)
+ delete :using_resource
+ assert_equal "text/html", @response.content_type
+ assert_equal 302, @response.status
+ assert_equal "http://www.example.com/customers", @response.location
+ end
end
def test_using_resource_for_delete_with_xml
@@ -685,21 +687,23 @@ def test_using_resource_with_parent_for_get
end
def test_using_resource_with_parent_for_post
- @request.accept = "application/xml"
-
- post :using_resource_with_parent
- assert_equal "application/xml", @response.content_type
- assert_equal 201, @response.status
- assert_equal "<name>david</name>", @response.body
- assert_equal "http://www.example.com/quiz_stores/11/customers/13", @response.location
-
- errors = { :name => :invalid }
- Customer.any_instance.stubs(:errors).returns(errors)
- post :using_resource
- assert_equal "application/xml", @response.content_type
- assert_equal 422, @response.status
- assert_equal errors.to_xml, @response.body
- assert_nil @response.location
+ with_test_route_set do
+ @request.accept = "application/xml"
+
+ post :using_resource_with_parent
+ assert_equal "application/xml", @response.content_type
+ assert_equal 201, @response.status
+ assert_equal "<name>david</name>", @response.body
+ assert_equal "http://www.example.com/quiz_stores/11/customers/13", @response.location
+
+ errors = { :name => :invalid }
+ Customer.any_instance.stubs(:errors).returns(errors)
+ post :using_resource
+ assert_equal "application/xml", @response.content_type
+ assert_equal 422, @response.status
+ assert_equal errors.to_xml, @response.body
+ assert_nil @response.location
+ end
end
def test_using_resource_with_collection
@@ -773,6 +777,18 @@ def test_not_acceptable
get :default_overwritten
assert_equal 406, @response.status
end
+
+ private
+ def with_test_route_set
+ with_routing do |set|
+ set.draw do |map|
+ map.resources :customers
+ map.resources :quiz_stores, :has_many => :customers
+ map.connect ":controller/:action/:id"
+ end
+ yield
+ end
+ end
end
class AbstractPostController < ActionController::Base
View
2 actionpack/test/new_base/base_test.rb → ...ack/test/controller/new_base/base_test.rb
@@ -26,7 +26,7 @@ module Submodule
class ContainedEmptyController < ActionController::Base ; end
end
- class BaseTest < SimpleRouteCase
+ class BaseTest < Rack::TestCase
# :api: plugin
test "simple dispatching" do
get "/dispatching/simple/index"
View
2 ...test/new_base/content_negotiation_test.rb → ...ller/new_base/content_negotiation_test.rb
@@ -9,7 +9,7 @@ class BasicController < ActionController::Base
)]
end
- class TestContentNegotiation < SimpleRouteCase
+ class TestContentNegotiation < Rack::TestCase
test "A */* Accept header will return HTML" do
get "/content_negotiation/basic/hello", {}, "HTTP_ACCEPT" => "*/*"
assert_body "Hello world */*!"
View
6 ...onpack/test/new_base/content_type_test.rb → .../controller/new_base/content_type_test.rb
@@ -44,7 +44,7 @@ def set_as_nil_on_response_obj
end
end
- class ExplicitContentTypeTest < SimpleRouteCase
+ class ExplicitContentTypeTest < Rack::TestCase
test "default response is HTML and UTF8" do
get "/content_type/base"
@@ -67,7 +67,7 @@ class ExplicitContentTypeTest < SimpleRouteCase
end
end
- class ImpliedContentTypeTest < SimpleRouteCase
+ class ImpliedContentTypeTest < Rack::TestCase
test "sets Content-Type as text/html when rendering *.html.erb" do
get "/content_type/implied/i_am_html_erb"
@@ -93,7 +93,7 @@ class ImpliedContentTypeTest < SimpleRouteCase
end
end
- class ExplicitCharsetTest < SimpleRouteCase
+ class ExplicitCharsetTest < Rack::TestCase
test "setting the charset of the response directly on the response object" do
get "/content_type/charset/set_on_response_obj"
View
2 actionpack/test/new_base/etag_test.rb → ...ack/test/controller/new_base/etag_test.rb
@@ -16,7 +16,7 @@ def with_layout
end
end
- class EtagTest < SimpleRouteCase
+ class EtagTest < Rack::TestCase
describe "Rendering without any special etag options returns an etag that is an MD5 hash of its text"
test "an action without a layout" do
View
0 actionpack/test/new_base/metal_test.rb → ...ck/test/controller/new_base/metal_test.rb
File renamed without changes.
View
0 actionpack/test/new_base/middleware_test.rb → ...st/controller/new_base/middleware_test.rb
File renamed without changes.
View
12 ...npack/test/new_base/render_action_test.rb → ...controller/new_base/render_action_test.rb
@@ -45,7 +45,7 @@ def hello_world_with_custom_layout
end
- class RenderActionTest < SimpleRouteCase
+ class RenderActionTest < Rack::TestCase
test "rendering an action using :action => <String>" do
get "/render_action/basic/hello_world"
@@ -82,7 +82,7 @@ class RenderActionTest < SimpleRouteCase
end
end
- class RenderLayoutTest < SimpleRouteCase
+ class RenderLayoutTest < Rack::TestCase
describe "Both <controller_path>.html.erb and application.html.erb are missing"
test "rendering with layout => true" do
@@ -150,7 +150,7 @@ def with_builder_and_layout
end
end
- class LayoutTest < SimpleRouteCase
+ class LayoutTest < Rack::TestCase
describe "Only application.html.erb is present and <controller_path>.html.erb is missing"
test "rendering implicit application.html.erb as layout" do
@@ -189,7 +189,7 @@ class LayoutTest < SimpleRouteCase
end
end
- class TestLayout < SimpleRouteCase
+ class TestLayout < Rack::TestCase
testing BasicController
test "builder works with layouts" do
@@ -228,7 +228,7 @@ def hello_world_with_custom_layout
end
end
- class ControllerLayoutTest < SimpleRouteCase
+ class ControllerLayoutTest < Rack::TestCase
describe "Only <controller_path>.html.erb is present and application.html.erb is missing"
test "render hello_world and implicitly use <controller_path>.html.erb as a layout." do
@@ -286,7 +286,7 @@ def hello_world_with_layout_nil
end
end
- class ControllerLayoutTest < SimpleRouteCase
+ class ControllerLayoutTest < Rack::TestCase
describe "Both <controller_path>.html.erb and application.html.erb are present"
test "rendering implicitly use <controller_path>.html.erb over application.html.erb as a layout" do
View
71 actionpack/test/new_base/render_file_test.rb → ...t/controller/new_base/render_file_test.rb
@@ -1,110 +1,99 @@
require 'abstract_unit'
module RenderFile
-
class BasicController < ActionController::Base
- self.view_paths = File.dirname(__FILE__)
-
+ self.view_paths = File.dirname(__FILE__)
+
def index
- render :file => File.join(File.dirname(__FILE__), *%w[.. fixtures test hello_world])
+ render :file => File.join(File.dirname(__FILE__), *%w[.. .. fixtures test hello_world])
end
-
+
def with_instance_variables
@secret = 'in the sauce'
- render :file => File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb')
+ render :file => File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_ivar.erb')
end
-
+
def without_file_key
- render File.join(File.dirname(__FILE__), *%w[.. fixtures test hello_world])
+ render File.join(File.dirname(__FILE__), *%w[.. .. fixtures test hello_world])
end
-
+
def without_file_key_with_instance_variable
@secret = 'in the sauce'
- render File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb')
+ render File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_ivar.erb')
end
-
+
def relative_path
@secret = 'in the sauce'
- render :file => '../fixtures/test/render_file_with_ivar'
+ render :file => '../../fixtures/test/render_file_with_ivar'
end
-
+
def relative_path_with_dot
@secret = 'in the sauce'
- render :file => '../fixtures/test/dot.directory/render_file_with_ivar'
+ render :file => '../../fixtures/test/dot.directory/render_file_with_ivar'
end
-
+
def pathname
@secret = 'in the sauce'
- render :file => Pathname.new(File.dirname(__FILE__)).join(*%w[.. fixtures test dot.directory render_file_with_ivar.erb])
+ render :file => Pathname.new(File.dirname(__FILE__)).join(*%w[.. .. fixtures test dot.directory render_file_with_ivar.erb])
end
-
+
def with_locals
- path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_locals.erb')
+ path = File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_locals.erb')
render :file => path, :locals => {:secret => 'in the sauce'}
end
-
+
def without_file_key_with_locals
- path = File.expand_path('../fixtures/test/render_file_with_locals.erb')
+ path = FIXTURES.join('test/render_file_with_locals.erb').to_s
render path, :locals => {:secret => 'in the sauce'}
end
end
-
- class TestBasic < SimpleRouteCase
+
+ class TestBasic < Rack::TestCase
testing RenderFile::BasicController
-
- def setup
- @old_pwd = Dir.pwd
- Dir.chdir(File.dirname(__FILE__))
- end
-
- def teardown
- Dir.chdir(@old_pwd)
- end
-
+
test "rendering simple template" do
get :index
assert_response "Hello world!"
end
-
+
test "rendering template with ivar" do
get :with_instance_variables
assert_response "The secret is in the sauce\n"
end
-
+
test "rendering path without specifying the :file key" do
get :without_file_key
assert_response "Hello world!"
end
-
+
test "rendering path without specifying the :file key with ivar" do
get :without_file_key_with_instance_variable
assert_response "The secret is in the sauce\n"
end
-
+
test "rendering a relative path" do
get :relative_path
assert_response "The secret is in the sauce\n"
end
-
+
test "rendering a relative path with dot" do
get :relative_path_with_dot
assert_response "The secret is in the sauce\n"
end
-
+
test "rendering a Pathname" do
get :pathname
assert_response "The secret is in the sauce\n"
end
-
+
test "rendering file with locals" do
get :with_locals
assert_response "The secret is in the sauce\n"
end
-
+
test "rendering path without specifying the :file key with locals" do
get :without_file_key_with_locals
assert_response "The secret is in the sauce\n"
end
end
-
end
View
2 ...t/new_base/render_implicit_action_test.rb → ...r/new_base/render_implicit_action_test.rb
@@ -10,7 +10,7 @@ class SimpleController < ::ApplicationController
def hello_world() end
end
- class RenderImplicitActionTest < SimpleRouteCase
+ class RenderImplicitActionTest < Rack::TestCase
test "render a simple action with new explicit call to render" do
get "/render_implicit_action/simple/hello_world"
View
6 ...npack/test/new_base/render_layout_test.rb → ...controller/new_base/render_layout_test.rb
@@ -36,7 +36,7 @@ def index
end
end
- class RenderLayoutTest < SimpleRouteCase
+ class RenderLayoutTest < Rack::TestCase
test "rendering a normal template, but using the implicit layout" do
get "/controller_layouts/implicit/index"
@@ -58,7 +58,7 @@ class RenderLayoutTest < SimpleRouteCase
end
- class LayoutOptionsTest < SimpleRouteCase
+ class LayoutOptionsTest < Rack::TestCase
testing ControllerLayouts::ImplicitController
test "rendering with :layout => false leaves out the implicit layout" do
@@ -79,7 +79,7 @@ def explicit
end
end
- class MismatchFormatTest < SimpleRouteCase
+ class MismatchFormatTest < Rack::TestCase
testing ControllerLayouts::MismatchFormatController
test "if JS is selected, an HTML template is not also selected" do
View
2 ...pack/test/new_base/render_partial_test.rb → ...ontroller/new_base/render_partial_test.rb
@@ -15,7 +15,7 @@ def changing
end
end
- class TestPartial < SimpleRouteCase
+ class TestPartial < Rack::TestCase
testing BasicController
test "rendering a partial in ActionView doesn't pull the ivars again from the controller" do
View
2 actionpack/test/new_base/render_rjs_test.rb → ...st/controller/new_base/render_rjs_test.rb
@@ -21,7 +21,7 @@ def index_locale
end
end
- class TestBasic < SimpleRouteCase
+ class TestBasic < Rack::TestCase
testing BasicController
def setup
View
6 ...ack/test/new_base/render_template_test.rb → ...ntroller/new_base/render_template_test.rb
@@ -39,7 +39,7 @@ def builder_template
end
end
- class TestWithoutLayout < SimpleRouteCase
+ class TestWithoutLayout < Rack::TestCase
testing RenderTemplate::WithoutLayoutController
test "rendering a normal template with full path without layout" do
@@ -107,7 +107,7 @@ def with_custom_layout
end
end
- class TestWithLayout < SimpleRouteCase
+ class TestWithLayout < Rack::TestCase
describe "Rendering with :template using implicit or explicit layout"
test "rendering with implicit layout" do
@@ -158,7 +158,7 @@ def with_forward_slash
end
end
- class TestTemplateRenderWithForwardSlash < SimpleRouteCase
+ class TestTemplateRenderWithForwardSlash < Rack::TestCase
test "rendering a normal template with full path starting with a leading slash" do
get "/render_template/compatibility/without_layout/with_forward_slash"
View
6 actionpack/test/new_base/render_test.rb → ...k/test/controller/new_base/render_test.rb
@@ -35,7 +35,7 @@ def index
end
end
- class RenderTest < SimpleRouteCase
+ class RenderTest < Rack::TestCase
test "render with blank" do
get "/render/blank_render"
@@ -50,7 +50,7 @@ class RenderTest < SimpleRouteCase
end
end
- class TestOnlyRenderPublicActions < SimpleRouteCase
+ class TestOnlyRenderPublicActions < Rack::TestCase
describe "Only public methods on actual controllers are callable actions"
test "raises an exception when a method of Object is called" do
@@ -66,7 +66,7 @@ class TestOnlyRenderPublicActions < SimpleRouteCase
end
end
- class TestVariousObjectsAvailableInView < SimpleRouteCase
+ class TestVariousObjectsAvailableInView < Rack::TestCase
test "The request object is accessible in the view" do
get "/render/blank_render/access_request"
assert_body "The request: GET"
View
2 actionpack/test/new_base/render_text_test.rb → ...t/controller/new_base/render_text_test.rb
@@ -62,7 +62,7 @@ def with_ivar_in_layout
end
end
- class RenderTextTest < SimpleRouteCase
+ class RenderTextTest < Rack::TestCase
describe "Rendering text using render :text"
test "rendering text from a action with default options renders the text with the layout" do
View
0 actionpack/test/new_base/render_xml_test.rb → ...st/controller/new_base/render_xml_test.rb
File renamed without changes.
View
19 actionpack/test/controller/output_escaping_test.rb
@@ -0,0 +1,19 @@
+require 'abstract_unit'
+
+class OutputEscapingTest < ActiveSupport::TestCase
+
+ test "escape_html shouldn't die when passed nil" do
+ assert ERB::Util.h(nil).blank?
+ end
+
+ test "escapeHTML should escape strings" do
+ assert_equal "&lt;&gt;&quot;", ERB::Util.h("<>\"")
+ end
+
+ test "escapeHTML shouldn't touch explicitly safe strings" do
+ # TODO this seems easier to compose and reason about, but
+ # this should be verified
+ assert_equal "<", ERB::Util.h("<".html_safe!)
+ end
+
+end
View
2 actionpack/test/controller/render_test.rb
@@ -1050,7 +1050,7 @@ def test_rendering_with_conflicting_local_vars
def test_action_talk_to_layout
get :action_talk_to_layout
- assert_equal "<title>Talking to the layout</title>\nAction was here!", @response.body
+ assert_equal "<title>Talking to the layout</title>\n\nAction was here!", @response.body
end
# :addressed:
View
1 actionpack/test/controller/rescue_test.rb
@@ -347,7 +347,6 @@ def with_test_routing
map.connect 'invalid', :controller => "rescue_test/test", :action => 'invalid'
map.connect 'b00m', :controller => "rescue_test/test", :action => 'b00m'
end
- reset!
yield
end
end
View
62 actionpack/test/controller/routing_test.rb
@@ -669,21 +669,13 @@ def setup_request_method_routes_for(method)
%w(GET POST PUT DELETE).each do |request_method|
define_method("test_request_method_recognized_with_#{request_method}") do
- begin
- Object.const_set(:BooksController, Class.new(ActionController::Base))
-
- setup_request_method_routes_for(request_method)
-
- assert_nothing_raised { rs.recognize(@request) }
- assert_equal request_method.downcase, @request.path_parameters[:action]
- ensure
- Object.send(:remove_const, :BooksController) rescue nil
- end
+ setup_request_method_routes_for(request_method)
+ assert_nothing_raised { rs.recognize(@request) }
+ assert_equal request_method.downcase, @request.path_parameters[:action]
end
end
def test_recognize_array_of_methods
- Object.const_set(:BooksController, Class.new(ActionController::Base))
rs.draw do |r|
r.connect '/match', :controller => 'books', :action => 'get_or_post', :conditions => { :method => [:get, :post] }
r.connect '/match', :controller => 'books', :action => 'not_get_or_post'
@@ -701,13 +693,9 @@ def test_recognize_array_of_methods
@request.request_uri = "/match"
assert_nothing_raised { rs.recognize(@request) }
assert_equal 'not_get_or_post', @request.path_parameters[:action]
- ensure
- Object.send(:remove_const, :BooksController) rescue nil
end
def test_subpath_recognized
- Object.const_set(:SubpathBooksController, Class.new(ActionController::Base))
-
rs.draw do |r|