<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>actionpack/lib/action_dispatch/middleware/string_coercion.rb</filename>
    </added>
    <added>
      <filename>actionpack/lib/action_view/helpers/raw_output_helper.rb</filename>
    </added>
    <added>
      <filename>actionpack/lib/action_view/safe_buffer.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/controller/new_base/base_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/controller/new_base/content_negotiation_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/controller/new_base/content_type_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/controller/new_base/etag_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/controller/new_base/metal_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/controller/new_base/middleware_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/controller/new_base/render_action_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/controller/new_base/render_file_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/controller/new_base/render_implicit_action_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/controller/new_base/render_layout_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/controller/new_base/render_partial_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/controller/new_base/render_rjs_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/controller/new_base/render_template_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/controller/new_base/render_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/controller/new_base/render_text_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/controller/new_base/render_xml_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/controller/output_escaping_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/dispatch/string_coercion_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/template/ajax_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/template/html-scanner/cdata_node_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/template/html-scanner/document_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/template/html-scanner/node_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/template/html-scanner/sanitizer_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/template/html-scanner/tag_node_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/template/html-scanner/text_node_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/template/html-scanner/tokenizer_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/template/raw_output_helper_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/template/test_case_test.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/ts_isolated.rb</filename>
    </added>
    <added>
      <filename>actionpack/test/view/safe_buffer_test.rb</filename>
    </added>
    <added>
      <filename>activemodel/test/cases/attribute_methods_test.rb</filename>
    </added>
    <added>
      <filename>activesupport/lib/active_support/core_ext/string/output_safety.rb</filename>
    </added>
    <added>
      <filename>railties/lib/rails/initializable.rb</filename>
    </added>
    <added>
      <filename>railties/test/application/console_test.rb</filename>
    </added>
    <added>
      <filename>railties/test/application/generators_test.rb</filename>
    </added>
    <added>
      <filename>railties/test/application/initializer_test.rb</filename>
    </added>
    <added>
      <filename>railties/test/application/plugins_test.rb</filename>
    </added>
    <added>
      <filename>railties/test/initializable_test.rb</filename>
    </added>
    <added>
      <filename>railties/test/initializer/initialize_i18n_test.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,5 +1,5 @@
 module ExampleHelper
   def example_format(text)
-    &quot;&lt;em&gt;&lt;strong&gt;&lt;small&gt;#{text}&lt;/small&gt;&lt;/strong&gt;&lt;/em&gt;&quot;
+    &quot;&lt;em&gt;&lt;strong&gt;&lt;small&gt;#{h(text)}&lt;/small&gt;&lt;/strong&gt;&lt;/em&gt;&quot;.html_safe!
   end
 end</diff>
      <filename>actionmailer/test/fixtures/helpers/example_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,6 +4,7 @@ gem &quot;rack&quot;, &quot;~&gt; 1.0.0&quot;
 gem &quot;rack-test&quot;, &quot;~&gt; 0.5.0&quot;
 gem &quot;activesupport&quot;, &quot;3.0.pre&quot;, :vendored_at =&gt; rails_root.join(&quot;activesupport&quot;)
 gem &quot;activemodel&quot;, &quot;3.0.pre&quot;, :vendored_at =&gt; rails_root.join(&quot;activemodel&quot;)
+gem &quot;erubis&quot;, &quot;~&gt; 2.6.0&quot;
 
 only :test do
   gem &quot;mocha&quot;</diff>
      <filename>actionpack/Gemfile</filename>
    </modified>
    <modified>
      <diff>@@ -34,22 +34,21 @@ end
 desc &quot;Run all unit tests&quot;
 task :test =&gt; [:test_action_pack, :test_active_record_integration]
 
-TESTS_GLOB = &quot;test/{abstract,controller,dispatch,new_base,template,html-scanner,view}/**/*_test.rb&quot;
-
 Rake::TestTask.new(:test_action_pack) do |t|
   t.libs &lt;&lt; '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 &quot;Failures&quot;
+namespace :test do
+  Rake::TestTask.new(:isolated) do |t|
+    t.pattern = 'test/ts_isolated.rb'
+  end
 end
 
 desc 'ActiveRecord Integration Tests'</diff>
      <filename>actionpack/Rakefile</filename>
    </modified>
    <modified>
      <diff>@@ -50,7 +50,7 @@ module ActionController
 
       def new
         # DEPRECATE Rails application fallback
-        Rails.application
+        Rails.application.new
       end
     end
   end</diff>
      <filename>actionpack/lib/action_controller/dispatch/dispatcher.rb</filename>
    </modified>
    <modified>
      <diff>@@ -16,7 +16,7 @@ module ActionController #:nodoc:
           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</diff>
      <filename>actionpack/lib/action_controller/metal/session_management.rb</filename>
    </modified>
    <modified>
      <diff>@@ -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'</diff>
      <filename>actionpack/lib/action_dispatch.rb</filename>
    </modified>
    <modified>
      <diff>@@ -10,7 +10,12 @@ module Mime
     %w(&lt;&lt; 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 &lt;&lt;-CODE
+        def #{method}(*args)
+          @symbols = nil
+          super
+        end
+      CODE
     end
   end
 </diff>
      <filename>actionpack/lib/action_dispatch/http/mime_type.rb</filename>
    </modified>
    <modified>
      <diff>@@ -44,11 +44,11 @@ module ActionView
   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 &lt;&lt; &quot;#{File.dirname(__FILE__)}/action_view/locale/en.yml&quot;
 </diff>
      <filename>actionpack/lib/action_view.rb</filename>
    </modified>
    <modified>
      <diff>@@ -236,7 +236,16 @@ module ActionView #:nodoc:
       # 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
+            &quot;ActionView for #{CONTROLLER_CLASS}&quot;
+          end
+
+          def inspect
+            &quot;#&lt;#{self.class.name}&gt;&quot;
+          end
 
           if controller.respond_to?(:_helpers)
             include controller._helpers
@@ -255,7 +264,7 @@ module ActionView #:nodoc:
       @assigns = assigns_for_first_render.each { |key, value| instance_variable_set(&quot;@#{key}&quot;, value) }
       @controller = controller
       @helpers = self.class.helpers || Module.new
-      @_content_for = Hash.new {|h,k| h[k] = &quot;&quot; }
+      @_content_for = Hash.new {|h,k| h[k] = ActionView::SafeBuffer.new }
       self.view_paths = view_paths
     end
 </diff>
      <filename>actionpack/lib/action_view/base.rb</filename>
    </modified>
    <modified>
      <diff>@@ -15,9 +15,19 @@ class ERB
     #   puts html_escape(&quot;is a &gt; 0 &amp; a &lt; 10?&quot;)
     #   # =&gt; is a &amp;gt; 0 &amp;amp; a &amp;lt; 10?
     def html_escape(s)
-      s.to_s.gsub(/[&amp;&quot;&gt;&lt;]/) { |special| HTML_ESCAPE[special] }
+      s = s.to_s
+      if s.html_safe?
+        s
+      else
+        s.gsub(/[&amp;&quot;&gt;&lt;]/) { |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 &lt;tt&gt;j&lt;/tt&gt;.
     #</diff>
      <filename>actionpack/lib/action_view/erb/util.rb</filename>
    </modified>
    <modified>
      <diff>@@ -15,6 +15,7 @@ module ActionView #: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 ActionView #:nodoc:
     include JavaScriptHelper
     include NumberHelper
     include PrototypeHelper
+    include RawOutputHelper
     include RecordIdentificationHelper
     include RecordTagHelper
     include SanitizeHelper</diff>
      <filename>actionpack/lib/action_view/helpers.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,7 +6,7 @@ require 'active_support/core_ext/kernel/reporting'
 
 module ActionView
   class Base
-    @@field_error_proc = Proc.new{ |html_tag, instance| &quot;&lt;div class=\&quot;fieldWithErrors\&quot;&gt;#{html_tag}&lt;/div&gt;&quot; }
+    @@field_error_proc = Proc.new{ |html_tag, instance| &quot;&lt;div class=\&quot;fieldWithErrors\&quot;&gt;#{html_tag}&lt;/div&gt;&quot;.html_safe! }
     cattr_accessor :field_error_proc
   end
 
@@ -91,6 +91,7 @@ module ActionView
         yield contents if block_given?
         contents &lt;&lt; submit_tag(submit_value)
         contents &lt;&lt; '&lt;/form&gt;'
+        contents.html_safe!
       end
 
       # Returns a string containing the error message attached to the +method+ on the +object+ if one exists.</diff>
      <filename>actionpack/lib/action_view/helpers/active_model_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -289,7 +289,7 @@ module ActionView
         else
           sources = expand_javascript_sources(sources, recursive)
           ensure_javascript_sources!(sources) if cache
-          sources.collect { |source| javascript_src_tag(source, options) }.join(&quot;\n&quot;)
+          sources.collect { |source| javascript_src_tag(source, options) }.join(&quot;\n&quot;).html_safe!
         end
       end
 
@@ -440,7 +440,7 @@ module ActionView
         else
           sources = expand_stylesheet_sources(sources, recursive)
           ensure_stylesheet_sources!(sources) if cache
-          sources.collect { |source| stylesheet_tag(source, options) }.join(&quot;\n&quot;)
+          sources.collect { |source| stylesheet_tag(source, options) }.join(&quot;\n&quot;).html_safe!
         end
       end
 
@@ -584,7 +584,7 @@ module ActionView
 
         if sources.is_a?(Array)
           content_tag(&quot;video&quot;, options) do
-            sources.map { |source| tag(&quot;source&quot;, :src =&gt; source) }.join
+            sources.map { |source| tag(&quot;source&quot;, :src =&gt; source) }.join.html_safe!
           end
         else
           options[:src] = path_to_video(sources)</diff>
      <filename>actionpack/lib/action_view/helpers/asset_tag_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -143,7 +143,7 @@ module ActionView
       # 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</diff>
      <filename>actionpack/lib/action_view/helpers/capture_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -916,15 +916,15 @@ module ActionView
 
     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</diff>
      <filename>actionpack/lib/action_view/helpers/date_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -282,7 +282,7 @@ module ActionView
 
         concat(form_tag(options.delete(:url) || {}, options.delete(:html) || {}))
         fields_for(object_name, *(args &lt;&lt; options), &amp;proc)
-        concat('&lt;/form&gt;')
+        concat('&lt;/form&gt;'.html_safe!)
       end
 
       def apply_form_for_options!(object_or_array, options) #:nodoc:
@@ -809,7 +809,7 @@ module ActionView
         add_default_name_and_id(options)
         hidden = tag(&quot;input&quot;, &quot;name&quot; =&gt; options[&quot;name&quot;], &quot;type&quot; =&gt; &quot;hidden&quot;, &quot;value&quot; =&gt; options['disabled'] &amp;&amp; checked ? checked_value : unchecked_value)
         checkbox = tag(&quot;input&quot;, options)
-        hidden + checkbox
+        (hidden + checkbox).html_safe!
       end
 
       def to_boolean_select_tag(options = {})</diff>
      <filename>actionpack/lib/action_view/helpers/form_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -296,7 +296,7 @@ module ActionView
           options &lt;&lt; %(&lt;option value=&quot;#{html_escape(value.to_s)}&quot;#{selected_attribute}#{disabled_attribute}&gt;#{html_escape(text.to_s)}&lt;/option&gt;)
         end
 
-        options_for_select.join(&quot;\n&quot;)
+        options_for_select.join(&quot;\n&quot;).html_safe!
       end
 
       # Returns a string of option tags that have been compiled by iterating over the +collection+ and assigning the</diff>
      <filename>actionpack/lib/action_view/helpers/form_options_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -440,7 +440,7 @@ module ActionView
         concat(tag(:fieldset, options, true))
         concat(content_tag(:legend, legend)) unless legend.blank?
         concat(content)
-        concat(&quot;&lt;/fieldset&gt;&quot;)
+        concat(&quot;&lt;/fieldset&gt;&quot;.html_safe!)
       end
 
       private
@@ -467,14 +467,14 @@ module ActionView
 
         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, &amp;block)
           content = capture(&amp;block)
           concat(form_tag_html(html_options))
           concat(content)
-          concat(&quot;&lt;/form&gt;&quot;)
+          concat(&quot;&lt;/form&gt;&quot;.html_safe!)
         end
 
         def token_tag</diff>
      <filename>actionpack/lib/action_view/helpers/form_tag_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,4 @@
+require 'active_support/core_ext/big_decimal/conversions'
 require 'active_support/core_ext/float/rounding'
 
 module ActionView</diff>
      <filename>actionpack/lib/action_view/helpers/number_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -395,7 +395,7 @@ module ActionView
 
         concat(form_remote_tag(options))
         fields_for(object_name, *(args &lt;&lt; options), &amp;proc)
-        concat('&lt;/form&gt;')
+        concat('&lt;/form&gt;'.html_safe!)
       end
       alias_method :form_remote_for, :remote_form_for
 </diff>
      <filename>actionpack/lib/action_view/helpers/prototype_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -15,7 +15,7 @@ module ActionView
       def div_for(record, *args, &amp;block)
         content_tag_for(:div, record, *args, &amp;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 @@ module ActionView
       #    &lt;% content_tag_for(:tr, @person, :foo) do %&gt; ...
       #
       # produces:
-      #    
+      #
       #    &lt;tr id=&quot;foo_person_123&quot; class=&quot;person&quot;&gt;...
       #
       # content_tag_for also accepts a hash of options, which will be converted to
@@ -50,7 +50,7 @@ module ActionView
       def content_tag_for(tag_name, record, *args, &amp;block)
         prefix  = args.first.is_a?(Hash) ? nil : args.shift
         options = args.extract_options!
-        options.merge!({ :class =&gt; &quot;#{dom_class(record)} #{options[:class]}&quot;.strip, :id =&gt; dom_id(record, prefix) })
+        options.merge!({ :class =&gt; &quot;#{dom_class(record, prefix)} #{options[:class]}&quot;.strip, :id =&gt; dom_id(record, prefix) })
         content_tag(tag_name, options, &amp;block)
       end
     end</diff>
      <filename>actionpack/lib/action_view/helpers/record_tag_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -49,7 +49,11 @@ module ActionView
       # 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 @@ module ActionView
       #   strip_tags(&quot;&lt;div id='top-bar'&gt;Welcome to my website!&lt;/div&gt;&quot;)
       #   # =&gt; 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.</diff>
      <filename>actionpack/lib/action_view/helpers/sanitize_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -41,7 +41,7 @@ module ActionView
       #   tag(&quot;img&quot;, { :src =&gt; &quot;open &amp;amp; shut.png&quot; }, false, false)
       #   # =&gt; &lt;img src=&quot;open &amp;amp; shut.png&quot; /&gt;
       def tag(name, options = nil, open = false, escape = true)
-        &quot;&lt;#{name}#{tag_options(options, escape) if options}#{open ? &quot;&gt;&quot; : &quot; /&gt;&quot;}&quot;
+        &quot;&lt;#{name}#{tag_options(options, escape) if options}#{open ? &quot;&gt;&quot; : &quot; /&gt;&quot;}&quot;.html_safe!
       end
 
       # Returns an HTML block tag of type +name+ surrounding the +content+. Add
@@ -94,7 +94,7 @@ module ActionView
       #   cdata_section(File.read(&quot;hello_world.txt&quot;))
       #   # =&gt; &lt;![CDATA[&lt;hello from a text file]]&gt;
       def cdata_section(content)
-        &quot;&lt;![CDATA[#{content}]]&gt;&quot;
+        &quot;&lt;![CDATA[#{content}]]&gt;&quot;.html_safe!
       end
 
       # Returns an escaped version of +html+ without affecting existing escaped entities.
@@ -128,7 +128,7 @@ module ActionView
 
         def content_tag_string(name, content, options, escape = true)
           tag_options = tag_options(options, escape) if options
-          &quot;&lt;#{name}#{tag_options}&gt;#{content}&lt;/#{name}&gt;&quot;
+          &quot;&lt;#{name}#{tag_options}&gt;#{content}&lt;/#{name}&gt;&quot;.html_safe!
         end
 
         def tag_options(options, escape = true)
@@ -143,7 +143,7 @@ module ActionView
                 attrs &lt;&lt; %(#{key}=&quot;#{final_value}&quot;)
               end
             end
-            &quot; #{attrs.sort * ' '}&quot; unless attrs.empty?
+            &quot; #{attrs.sort * ' '}&quot;.html_safe! unless attrs.empty?
           end
         end
     end</diff>
      <filename>actionpack/lib/action_view/helpers/tag_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -93,7 +93,7 @@ module ActionView
           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 @@ module ActionView
         if block_given?
           options      = args.first || {}
           html_options = args.second
-          concat(link_to(capture(&amp;block), options, html_options))
+          concat(link_to(capture(&amp;block), options, html_options).html_safe!)
         else
           name         = args[0]
           options      = args[1] || {}
@@ -238,7 +238,7 @@ module ActionView
           end
 
           href_attr = &quot;href=\&quot;#{url}\&quot;&quot; unless href
-          &quot;&lt;a #{href_attr}#{tag_options}&gt;#{name || url}&lt;/a&gt;&quot;
+          &quot;&lt;a #{href_attr}#{tag_options}&gt;#{ERB::Util.h(name || url)}&lt;/a&gt;&quot;.html_safe!
         end
       end
 
@@ -309,8 +309,8 @@ module ActionView
 
         html_options.merge!(&quot;type&quot; =&gt; &quot;submit&quot;, &quot;value&quot; =&gt; name)
 
-        &quot;&lt;form method=\&quot;#{form_method}\&quot; action=\&quot;#{escape_once url}\&quot; class=\&quot;button-to\&quot;&gt;&lt;div&gt;&quot; +
-          method_tag + tag(&quot;input&quot;, html_options) + request_token_tag + &quot;&lt;/div&gt;&lt;/form&gt;&quot;
+        (&quot;&lt;form method=\&quot;#{form_method}\&quot; action=\&quot;#{escape_once url}\&quot; class=\&quot;button-to\&quot;&gt;&lt;div&gt;&quot; +
+          method_tag + tag(&quot;input&quot;, html_options) + request_token_tag + &quot;&lt;/div&gt;&lt;/form&gt;&quot;).html_safe!
       end
 
 </diff>
      <filename>actionpack/lib/action_view/helpers/url_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,8 +1,11 @@
 module ActionView #:nodoc:
   class PathSet &lt; 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 =&gt; cache)
       else
         obj</diff>
      <filename>actionpack/lib/action_view/paths.rb</filename>
    </modified>
    <modified>
      <diff>@@ -223,7 +223,7 @@ module ActionView
         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 @@ module ActionView
       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 =&gt; @view.formats}, prefix, true)
       end
 </diff>
      <filename>actionpack/lib/action_view/render/partials.rb</filename>
    </modified>
    <modified>
      <diff>@@ -14,6 +14,7 @@ module ActionView
       case options
       when Hash
         layout = options[:layout]
+        options[:locals] ||= {}
 
         if block_given?
           return concat(_render_partial(options.merge(:partial =&gt; layout), &amp;block))
@@ -25,11 +26,11 @@ module ActionView
 
         if file = options[:file]
           template = find(file, {:formats =&gt; formats})
-          _render_template(template, layout, :locals =&gt; options[:locals] || {})
+          _render_template(template, layout, :locals =&gt; 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(&amp;block)
@@ -80,16 +81,19 @@ module ActionView
 
     def _render_inline(inline, layout, options)
       handler = Template.handler_class_for_extension(options[:type] || &quot;erb&quot;)
-      template = Template.new(options[:inline], &quot;inline #{options[:inline].inspect}&quot;, handler, {})
-      locals = options[:locals] || {}
+      template = Template.new(options[:inline],
+        &quot;inline #{options[:inline].inspect}&quot;, 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.</diff>
      <filename>actionpack/lib/action_view/render/rendering.rb</filename>
    </modified>
    <modified>
      <diff>@@ -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 &lt; ::Erubis::Eruby
+      def add_preamble(src)
+        src &lt;&lt; &quot;@output_buffer = ActionView::SafeBuffer.new;&quot;
+      end
+
+      def add_text(src, text)
+        src &lt;&lt; &quot;@output_buffer &lt;&lt; ('&quot; &lt;&lt; escape_text(text) &lt;&lt; &quot;'.html_safe!);&quot;
+      end
+
+      def add_expr_literal(src, code)
+        src &lt;&lt; '@output_buffer &lt;&lt; ((' &lt;&lt; code &lt;&lt; ').to_s);'
+      end
+
+      def add_expr_escaped(src, code)
+        src &lt;&lt; '@output_buffer &lt;&lt; ' &lt;&lt; escaped_expr(code) &lt;&lt; ';'
+      end
+
+      def add_postamble(src)
+        src &lt;&lt; '@output_buffer.to_s'
+      end
+    end
+
     class ERB &lt; TemplateHandler
       include Compilable
 
@@ -15,11 +39,9 @@ module ActionView
       self.default_format = Mime::HTML
 
       def compile(template)
-        require 'erb'
-
         magic = $1 if template.source =~ /\A(&lt;%#.*coding[:=]\s*(\S+)\s*-?%&gt;)/
         erb = &quot;#{magic}&lt;% __in_erb_template=true %&gt;#{template.source}&quot;
-        ::ERB.new(erb, nil, erb_trim_mode, '@output_buffer').src
+        Erubis.new(erb, :trim=&gt;(self.class.erb_trim_mode == &quot;-&quot;)).src
       end
     end
   end</diff>
      <filename>actionpack/lib/action_view/template/handlers/erb.rb</filename>
    </modified>
    <modified>
      <diff>@@ -55,7 +55,7 @@ module ActionView
     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!)</diff>
      <filename>actionpack/lib/action_view/test_case.rb</filename>
    </modified>
    <modified>
      <diff>@@ -51,23 +51,73 @@ I18n.backend.store_translations 'pt-BR', {}
 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 &lt; ActiveSupport::TestCase
-  @@app = ActionDispatch::MiddlewareStack.new { |middleware|
-    middleware.use &quot;ActionDispatch::ShowExceptions&quot;
-    middleware.use &quot;ActionDispatch::Callbacks&quot;
-    middleware.use &quot;ActionDispatch::ParamsParser&quot;
-    middleware.use &quot;Rack::Head&quot;
-  }.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(&amp;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 &lt; ActiveSupport::TestCase
+  def self.build_app(routes = nil)
+    ActionDispatch::MiddlewareStack.new { |middleware|
+      middleware.use &quot;ActionDispatch::StringCoercion&quot;
+      middleware.use &quot;ActionDispatch::ShowExceptions&quot;
+      middleware.use &quot;ActionDispatch::Callbacks&quot;
+      middleware.use &quot;ActionDispatch::ParamsParser&quot;
+      middleware.use &quot;Rack::Head&quot;
+    }.build(routes || ActionController::Routing::Routes)
+  end
+
+  self.app = build_app
+
+  def with_routing(&amp;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 @@ module ActionController
       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 @@ module ActionController
     end
   end
 end
-
-class SimpleRouteCase &lt; Rack::TestCase
-  setup do
-    ActionController::Routing::Routes.draw do |map|
-      map.connect ':controller/:action/:id'
-    end
-  end
-end</diff>
      <filename>actionpack/test/abstract_unit.rb</filename>
    </modified>
    <modified>
      <diff>@@ -158,7 +158,6 @@ class ActiveRecordStoreTest &lt; ActionController::IntegrationTest
           map.connect &quot;/:action&quot;, :controller =&gt; &quot;active_record_store_test/test&quot;
         end
         @app = ActiveRecord::SessionStore.new(set, options.reverse_merge(:key =&gt; '_session_id'))
-        reset!
         yield
       end
     end</diff>
      <filename>actionpack/test/activerecord/active_record_store_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -46,14 +46,8 @@ end
 class PageCachingTest &lt; ActionController::TestCase
   def setup
     super
-    ActionController::Base.perform_caching = true
 
-    ActionController::Routing::Routes.draw do |map|
-      map.main '', :controller =&gt; 'posts', :format =&gt; nil
-      map.formatted_posts 'posts.:format', :controller =&gt; '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 @@ class PageCachingTest &lt; ActionController::TestCase
   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 =&gt; 'posts', :format =&gt; nil
+        map.formatted_posts 'posts.:format', :controller =&gt; '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</diff>
      <filename>actionpack/test/controller/caching_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -372,11 +372,8 @@ class IntegrationProcessTest &lt; ActionController::IntegrationTest
     def with_test_route_set
       with_routing do |set|
         set.draw do |map|
-          map.with_options :controller =&gt; &quot;IntegrationProcessTest::Integration&quot; do |c|
-            c.connect &quot;/:action&quot;
-          end
+          map.connect &quot;/:action&quot;, :controller =&gt; &quot;integration_process_test/integration&quot;
         end
-        reset!
         yield
       end
     end</diff>
      <filename>actionpack/test/controller/integration_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -527,12 +527,6 @@ class RespondWithControllerTest &lt; ActionController::TestCase
     super
     ActionController::Base.use_accept_header = true
     @request.host = &quot;www.example.com&quot;
-
-    ActionController::Routing::Routes.draw do |map|
-      map.resources :customers
-      map.resources :quiz_stores, :has_many =&gt; :customers
-      map.connect &quot;:controller/:action/:id&quot;
-    end
   end
 
   def teardown
@@ -593,53 +587,59 @@ class RespondWithControllerTest &lt; ActionController::TestCase
   end
 
   def test_using_resource_for_post_with_html
-    post :using_resource
-    assert_equal &quot;text/html&quot;, @response.content_type
-    assert_equal 302, @response.status
-    assert_equal &quot;http://www.example.com/customers/13&quot;, @response.location
-    assert @response.redirect?
-
-    errors = { :name =&gt; :invalid }
-    Customer.any_instance.stubs(:errors).returns(errors)
-    post :using_resource
-    assert_equal &quot;text/html&quot;, @response.content_type
-    assert_equal 200, @response.status
-    assert_equal &quot;New world!\n&quot;, @response.body
-    assert_nil @response.location
+    with_test_route_set do
+      post :using_resource
+      assert_equal &quot;text/html&quot;, @response.content_type
+      assert_equal 302, @response.status
+      assert_equal &quot;http://www.example.com/customers/13&quot;, @response.location
+      assert @response.redirect?
+
+      errors = { :name =&gt; :invalid }
+      Customer.any_instance.stubs(:errors).returns(errors)
+      post :using_resource
+      assert_equal &quot;text/html&quot;, @response.content_type
+      assert_equal 200, @response.status
+      assert_equal &quot;New world!\n&quot;, @response.body
+      assert_nil @response.location
+    end
   end
 
   def test_using_resource_for_post_with_xml
-    @request.accept = &quot;application/xml&quot;
-
-    post :using_resource
-    assert_equal &quot;application/xml&quot;, @response.content_type
-    assert_equal 201, @response.status
-    assert_equal &quot;&lt;name&gt;david&lt;/name&gt;&quot;, @response.body
-    assert_equal &quot;http://www.example.com/customers/13&quot;, @response.location
-
-    errors = { :name =&gt; :invalid }
-    Customer.any_instance.stubs(:errors).returns(errors)
-    post :using_resource
-    assert_equal &quot;application/xml&quot;, @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 = &quot;application/xml&quot;
+
+      post :using_resource
+      assert_equal &quot;application/xml&quot;, @response.content_type
+      assert_equal 201, @response.status
+      assert_equal &quot;&lt;name&gt;david&lt;/name&gt;&quot;, @response.body
+      assert_equal &quot;http://www.example.com/customers/13&quot;, @response.location
+
+      errors = { :name =&gt; :invalid }
+      Customer.any_instance.stubs(:errors).returns(errors)
+      post :using_resource
+      assert_equal &quot;application/xml&quot;, @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 &quot;text/html&quot;, @response.content_type
-    assert_equal 302, @response.status
-    assert_equal &quot;http://www.example.com/customers/13&quot;, @response.location
-    assert @response.redirect?
-
-    errors = { :name =&gt; :invalid }
-    Customer.any_instance.stubs(:errors).returns(errors)
-    put :using_resource
-    assert_equal &quot;text/html&quot;, @response.content_type
-    assert_equal 200, @response.status
-    assert_equal &quot;Edit world!\n&quot;, @response.body
-    assert_nil @response.location
+    with_test_route_set do
+      put :using_resource
+      assert_equal &quot;text/html&quot;, @response.content_type
+      assert_equal 302, @response.status
+      assert_equal &quot;http://www.example.com/customers/13&quot;, @response.location
+      assert @response.redirect?
+
+      errors = { :name =&gt; :invalid }
+      Customer.any_instance.stubs(:errors).returns(errors)
+      put :using_resource
+      assert_equal &quot;text/html&quot;, @response.content_type
+      assert_equal 200, @response.status
+      assert_equal &quot;Edit world!\n&quot;, @response.body
+      assert_nil @response.location
+    end
   end
 
   def test_using_resource_for_put_with_xml
@@ -660,11 +660,13 @@ class RespondWithControllerTest &lt; ActionController::TestCase
   end
 
   def test_using_resource_for_delete_with_html
-    Customer.any_instance.stubs(:destroyed?).returns(true)
-    delete :using_resource
-    assert_equal &quot;text/html&quot;, @response.content_type
-    assert_equal 302, @response.status
-    assert_equal &quot;http://www.example.com/customers&quot;, @response.location
+    with_test_route_set do
+      Customer.any_instance.stubs(:destroyed?).returns(true)
+      delete :using_resource
+      assert_equal &quot;text/html&quot;, @response.content_type
+      assert_equal 302, @response.status
+      assert_equal &quot;http://www.example.com/customers&quot;, @response.location
+    end
   end
 
   def test_using_resource_for_delete_with_xml
@@ -685,21 +687,23 @@ class RespondWithControllerTest &lt; ActionController::TestCase
   end
 
   def test_using_resource_with_parent_for_post
-    @request.accept = &quot;application/xml&quot;
-
-    post :using_resource_with_parent
-    assert_equal &quot;application/xml&quot;, @response.content_type
-    assert_equal 201, @response.status
-    assert_equal &quot;&lt;name&gt;david&lt;/name&gt;&quot;, @response.body
-    assert_equal &quot;http://www.example.com/quiz_stores/11/customers/13&quot;, @response.location
-
-    errors = { :name =&gt; :invalid }
-    Customer.any_instance.stubs(:errors).returns(errors)
-    post :using_resource
-    assert_equal &quot;application/xml&quot;, @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 = &quot;application/xml&quot;
+
+      post :using_resource_with_parent
+      assert_equal &quot;application/xml&quot;, @response.content_type
+      assert_equal 201, @response.status
+      assert_equal &quot;&lt;name&gt;david&lt;/name&gt;&quot;, @response.body
+      assert_equal &quot;http://www.example.com/quiz_stores/11/customers/13&quot;, @response.location
+
+      errors = { :name =&gt; :invalid }
+      Customer.any_instance.stubs(:errors).returns(errors)
+      post :using_resource
+      assert_equal &quot;application/xml&quot;, @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 @@ class RespondWithControllerTest &lt; ActionController::TestCase
     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 =&gt; :customers
+          map.connect &quot;:controller/:action/:id&quot;
+        end
+        yield
+      end
+    end
 end
 
 class AbstractPostController &lt; ActionController::Base</diff>
      <filename>actionpack/test/controller/mime_responds_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1050,7 +1050,7 @@ class RenderTest &lt; ActionController::TestCase
 
   def test_action_talk_to_layout
     get :action_talk_to_layout
-    assert_equal &quot;&lt;title&gt;Talking to the layout&lt;/title&gt;\nAction was here!&quot;, @response.body
+    assert_equal &quot;&lt;title&gt;Talking to the layout&lt;/title&gt;\n\nAction was here!&quot;, @response.body
   end
 
   # :addressed:</diff>
      <filename>actionpack/test/controller/render_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -347,7 +347,6 @@ class RescueTest &lt; ActionController::IntegrationTest
           map.connect 'invalid', :controller =&gt; &quot;rescue_test/test&quot;, :action =&gt; 'invalid'
           map.connect 'b00m', :controller =&gt; &quot;rescue_test/test&quot;, :action =&gt; 'b00m'
         end
-        reset!
         yield
       end
     end</diff>
      <filename>actionpack/test/controller/rescue_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -669,21 +669,13 @@ class LegacyRouteSetTests &lt; Test::Unit::TestCase
 
   %w(GET POST PUT DELETE).each do |request_method|
     define_method(&quot;test_request_method_recognized_with_#{request_method}&quot;) 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 =&gt; 'books', :action =&gt; 'get_or_post', :conditions =&gt; { :method =&gt; [:get, :post] }
       r.connect '/match', :controller =&gt; 'books', :action =&gt; 'not_get_or_post'
@@ -701,13 +693,9 @@ class LegacyRouteSetTests &lt; Test::Unit::TestCase
     @request.request_uri = &quot;/match&quot;
     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|
       r.connect '/books/:id/edit', :controller =&gt; 'subpath_books', :action =&gt; 'edit'
       r.connect '/items/:id/:action', :controller =&gt; 'subpath_books'
@@ -730,13 +718,9 @@ class LegacyRouteSetTests &lt; Test::Unit::TestCase
     hash = rs.recognize_path &quot;/posts/7&quot;
     assert_not_nil hash
     assert_equal %w(subpath_books show 7), [hash[:controller], hash[:action], hash[:id]]
-  ensure
-    Object.send(:remove_const, :SubpathBooksController) rescue nil
   end
 
   def test_subpath_generated
-    Object.const_set(:SubpathBooksController, Class.new(ActionController::Base))
-
     rs.draw do |r|
       r.connect '/books/:id/edit', :controller =&gt; 'subpath_books', :action =&gt; 'edit'
       r.connect '/items/:id/:action', :controller =&gt; 'subpath_books'
@@ -746,8 +730,6 @@ class LegacyRouteSetTests &lt; Test::Unit::TestCase
     assert_equal &quot;/books/7/edit&quot;, rs.generate(:controller =&gt; &quot;subpath_books&quot;, :id =&gt; 7, :action =&gt; &quot;edit&quot;)
     assert_equal &quot;/items/15/complete&quot;, rs.generate(:controller =&gt; &quot;subpath_books&quot;, :id =&gt; 15, :action =&gt; &quot;complete&quot;)
     assert_equal &quot;/posts/new/preview&quot;, rs.generate(:controller =&gt; &quot;subpath_books&quot;, :action =&gt; &quot;preview&quot;)
-  ensure
-    Object.send(:remove_const, :SubpathBooksController) rescue nil
   end
 
   def test_failed_requirements_raises_exception_with_violated_requirements
@@ -1122,8 +1104,6 @@ class RouteSetTest &lt; ActiveSupport::TestCase
   end
 
   def test_recognize_with_conditions
-    Object.const_set(:PeopleController, Class.new)
-
     set.draw do |map|
       map.with_options(:controller =&gt; &quot;people&quot;) do |people|
         people.people  &quot;/people&quot;,     :action =&gt; &quot;index&quot;,   :conditions =&gt; { :method =&gt; :get }
@@ -1183,14 +1163,9 @@ class RouteSetTest &lt; ActiveSupport::TestCase
       assert_equal [:get, :put, :delete], e.allowed_methods
     end
     request.recycle!
-
-  ensure
-    Object.send(:remove_const, :PeopleController)
   end
 
   def test_recognize_with_alias_in_conditions
-    Object.const_set(:PeopleController, Class.new)
-
     set.draw do |map|
       map.people &quot;/people&quot;, :controller =&gt; 'people', :action =&gt; &quot;index&quot;,
         :conditions =&gt; { :method =&gt; :get }
@@ -1208,13 +1183,9 @@ class RouteSetTest &lt; ActiveSupport::TestCase
     assert_nothing_raised { set.recognize(request) }
     assert_equal(&quot;people&quot;, request.path_parameters[:controller])
     assert_equal(&quot;index&quot;, request.path_parameters[:action])
-  ensure
-    Object.send(:remove_const, :PeopleController)
   end
 
   def test_typo_recognition
-    Object.const_set(:ArticlesController, Class.new)
-
     set.draw do |map|
       map.connect 'articles/:year/:month/:day/:title',
              :controller =&gt; 'articles', :action =&gt; 'permalink',
@@ -1229,9 +1200,6 @@ class RouteSetTest &lt; ActiveSupport::TestCase
     assert_equal(&quot;11&quot;, request.path_parameters[:month])
     assert_equal(&quot;05&quot;, request.path_parameters[:day])
     assert_equal(&quot;a-very-interesting-article&quot;, request.path_parameters[:title])
-
-  ensure
-    Object.send(:remove_const, :ArticlesController)
   end
 
   def test_routing_traversal_does_not_load_extra_classes
@@ -1248,8 +1216,6 @@ class RouteSetTest &lt; ActiveSupport::TestCase
   end
 
   def test_recognize_with_conditions_and_format
-    Object.const_set(:PeopleController, Class.new)
-
     set.draw do |map|
       map.with_options(:controller =&gt; &quot;people&quot;) do |people|
         people.person  &quot;/people/:id&quot;, :action =&gt; &quot;show&quot;,    :conditions =&gt; { :method =&gt; :get }
@@ -1276,8 +1242,6 @@ class RouteSetTest &lt; ActiveSupport::TestCase
     assert_equal(&quot;show&quot;, request.path_parameters[:action])
     assert_equal(&quot;5&quot;, request.path_parameters[:id])
     assert_equal(&quot;png&quot;, request.path_parameters[:_format])
-  ensure
-    Object.send(:remove_const, :PeopleController)
   end
 
   def test_generate_with_default_action
@@ -1291,8 +1255,6 @@ class RouteSetTest &lt; ActiveSupport::TestCase
   end
 
   def test_root_map
-    Object.const_set(:PeopleController, Class.new)
-
     set.draw { |map| map.root :controller =&gt; &quot;people&quot; }
 
     request.path = &quot;&quot;
@@ -1300,13 +1262,9 @@ class RouteSetTest &lt; ActiveSupport::TestCase
     assert_nothing_raised { set.recognize(request) }
     assert_equal(&quot;people&quot;, request.path_parameters[:controller])
     assert_equal(&quot;index&quot;, request.path_parameters[:action])
-  ensure
-    Object.send(:remove_const, :PeopleController)
   end
 
   def test_namespace
-    Object.const_set(:Api, Module.new { |m| m.const_set(:ProductsController, Class.new) })
-
     set.draw do |map|
 
       map.namespace 'api' do |api|
@@ -1320,13 +1278,9 @@ class RouteSetTest &lt; ActiveSupport::TestCase
     assert_nothing_raised { set.recognize(request) }
     assert_equal(&quot;api/products&quot;, request.path_parameters[:controller])
     assert_equal(&quot;inventory&quot;, request.path_parameters[:action])
-  ensure
-    Object.send(:remove_const, :Api)
   end
 
   def test_namespaced_root_map
-    Object.const_set(:Api, Module.new { |m| m.const_set(:ProductsController, Class.new) })
-
     set.draw do |map|
 
       map.namespace 'api' do |api|
@@ -1340,13 +1294,9 @@ class RouteSetTest &lt; ActiveSupport::TestCase
     assert_nothing_raised { set.recognize(request) }
     assert_equal(&quot;api/products&quot;, request.path_parameters[:controller])
     assert_equal(&quot;index&quot;, request.path_parameters[:action])
-  ensure
-    Object.send(:remove_const, :Api)
   end
 
   def test_namespace_with_path_prefix
-    Object.const_set(:Api, Module.new { |m| m.const_set(:ProductsController, Class.new) })
-
     set.draw do |map|
       map.namespace 'api', :path_prefix =&gt; 'prefix' do |api|
         api.route 'inventory', :controller =&gt; &quot;products&quot;, :action =&gt; 'inventory'
@@ -1358,13 +1308,9 @@ class RouteSetTest &lt; ActiveSupport::TestCase
     assert_nothing_raised { set.recognize(request) }
     assert_equal(&quot;api/products&quot;, request.path_parameters[:controller])
     assert_equal(&quot;inventory&quot;, request.path_parameters[:action])
-  ensure
-    Object.send(:remove_const, :Api)
   end
 
   def test_namespace_with_blank_path_prefix
-    Object.const_set(:Api, Module.new { |m| m.const_set(:ProductsController, Class.new) })
-
     set.draw do |map|
       map.namespace 'api', :path_prefix =&gt; '' do |api|
         api.route 'inventory', :controller =&gt; &quot;products&quot;, :action =&gt; 'inventory'
@@ -1376,8 +1322,6 @@ class RouteSetTest &lt; ActiveSupport::TestCase
     assert_nothing_raised { set.recognize(request) }
     assert_equal(&quot;api/products&quot;, request.path_parameters[:controller])
     assert_equal(&quot;inventory&quot;, request.path_parameters[:action])
-  ensure
-    Object.send(:remove_const, :Api)
   end
 
   def test_generate_changes_controller_module</diff>
      <filename>actionpack/test/controller/routing_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -111,13 +111,6 @@ class VerificationTest &lt; ActionController::TestCase
 
   tests TestController
 
-  setup do
-    ActionController::Routing::Routes.draw do |map|
-      map.foo '/foo', :controller =&gt; 'test', :action =&gt; 'foo'
-      map.connect &quot;:controller/:action/:id&quot;
-    end
-  end
-
   def test_using_symbol_back_with_no_referrer
     assert_raise(ActionController::RedirectBackError) { get :guarded_with_back }
   end
@@ -130,8 +123,14 @@ class VerificationTest &lt; ActionController::TestCase
 
   def test_no_deprecation_warning_for_named_route
     assert_not_deprecated do
-      get :guarded_one_for_named_route_test, :two =&gt; &quot;not one&quot;
-      assert_redirected_to '/foo'
+      with_routing do |set|
+        set.draw do |map|
+          map.foo '/foo', :controller =&gt; 'test', :action =&gt; 'foo'
+          map.connect &quot;:controller/:action/:id&quot;
+        end
+        get :guarded_one_for_named_route_test, :two =&gt; &quot;not one&quot;
+        assert_redirected_to '/foo'
+      end
     end
   end
 </diff>
      <filename>actionpack/test/controller/verification_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -259,7 +259,6 @@ class WebServiceTest &lt; ActionController::IntegrationTest
             c.connect &quot;/&quot;, :action =&gt; &quot;assign_parameters&quot;
           end
         end
-        reset!
         yield
       end
     end</diff>
      <filename>actionpack/test/controller/webservice_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -59,7 +59,6 @@ class JsonParamsParsingTest &lt; ActionController::IntegrationTest
         set.draw do |map|
           map.connect ':action', :controller =&gt; &quot;json_params_parsing_test/test&quot;
         end
-        reset!
         yield
       end
     end</diff>
      <filename>actionpack/test/dispatch/request/json_params_parsing_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -153,7 +153,6 @@ class MultipartParamsParsingTest &lt; ActionController::IntegrationTest
         set.draw do |map|
           map.connect ':action', :controller =&gt; &quot;multipart_params_parsing_test/test&quot;
         end
-        reset!
         yield
       end
     end</diff>
      <filename>actionpack/test/dispatch/request/multipart_params_parsing_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -111,7 +111,6 @@ class QueryStringParsingTest &lt; ActionController::IntegrationTest
         set.draw do |map|
           map.connect ':action', :controller =&gt; &quot;query_string_parsing_test/test&quot;
         end
-        reset!
 
         get &quot;/parse&quot;, actual
         assert_response :ok</diff>
      <filename>actionpack/test/dispatch/request/query_string_parsing_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -132,7 +132,6 @@ class UrlEncodedParamsParsingTest &lt; ActionController::IntegrationTest
         set.draw do |map|
           map.connect ':action', :controller =&gt; &quot;url_encoded_params_parsing_test/test&quot;
         end
-        reset!
         yield
       end
     end</diff>
      <filename>actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -86,7 +86,6 @@ class XmlParamsParsingTest &lt; ActionController::IntegrationTest
         set.draw do |map|
           map.connect ':action', :controller =&gt; &quot;xml_params_parsing_test/test&quot;
         end
-        reset!
         yield
       end
     end</diff>
      <filename>actionpack/test/dispatch/request/xml_params_parsing_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -223,7 +223,6 @@ class CookieStoreTest &lt; ActionController::IntegrationTest
         end
         options = {:key =&gt; SessionKey, :secret =&gt; SessionSecret}.merge(options)
         @app = ActionDispatch::Session::CookieStore.new(set, options)
-        reset!
         yield
       end
     end</diff>
      <filename>actionpack/test/dispatch/session/cookie_store_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -115,7 +115,6 @@ class MemCacheStoreTest &lt; ActionController::IntegrationTest
           map.connect &quot;/:action&quot;, :controller =&gt; &quot;mem_cache_store_test/test&quot;
         end
         @app = ActionDispatch::Session::MemCacheStore.new(set, :key =&gt; '_session_id')
-        reset!
         yield
       end
     end</diff>
      <filename>actionpack/test/dispatch/session/mem_cache_store_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,22 +1,32 @@
 class &lt;&lt; Object; alias_method :const_available?, :const_defined?; end
 
-class ContentController &lt; ActionController::Base
-end
-class NotAController
-end
+class ContentController &lt; ActionController::Base; end
+class NotAController; end
+
 module Admin
   class &lt;&lt; self; alias_method :const_available?, :const_defined?; end
   class UserController &lt; ActionController::Base; end
   class NewsFeedController &lt; ActionController::Base; end
 end
-class ElsewhereController &lt; ActionController::Base; end
+
+module Api
+  class ProductsController &lt; ActionController::Base; end
+end
+
+# TODO: Reduce the number of test controllers we use
 class AddressesController &lt; ActionController::Base; end
-class SessionsController  &lt; ActionController::Base; end
-class FooController &lt; ActionController::Base; end
+class ArticlesController &lt; ActionController::Base; end
+class BarController &lt; ActionController::Base; end
+class BooksController &lt; ActionController::Base; end
+class BraveController &lt; ActionController::Base; end
 class CController &lt; ActionController::Base; end
+class ElsewhereController &lt; ActionController::Base; end
+class FooController &lt; ActionController::Base; end
 class HiController &lt; ActionController::Base; end
-class BraveController &lt; ActionController::Base; end
 class ImageController &lt; ActionController::Base; end
+class PeopleController &lt; ActionController::Base; end
+class SessionsController  &lt; ActionController::Base; end
+class SubpathBooksController &lt; ActionController::Base; end
 class WeblogController &lt; ActionController::Base; end
 
 # For speed test
@@ -34,8 +44,3 @@ class ChannelsController      &lt; SpeedController; end
 class ChannelVideosController &lt; SpeedController; end
 class LostPasswordsController &lt; SpeedController; end
 class PagesController         &lt; SpeedController; end
-
-ActionController::Routing::Routes.draw do |map|
-  map.route_one 'route_one', :controller =&gt; 'elsewhere', :action =&gt; 'flash_me'
-  map.connect ':controller/:action/:id'
-end</diff>
      <filename>actionpack/test/lib/controller/fake_controllers.rb</filename>
    </modified>
    <modified>
      <diff>@@ -51,3 +51,99 @@ module Quiz
   end
 end
 
+class Post &lt; Struct.new(:title, :author_name, :body, :secret, :written_on, :cost)
+  extend ActiveModel::Naming
+  include ActiveModel::Conversion
+
+  alias_method :secret?, :secret
+
+  def new_record=(boolean)
+    @new_record = boolean
+  end
+
+  def new_record?
+    @new_record
+  end
+
+  attr_accessor :author
+  def author_attributes=(attributes); end
+
+  attr_accessor :comments
+  def comments_attributes=(attributes); end
+
+  attr_accessor :tags
+  def tags_attributes=(attributes); end
+end
+
+class Comment
+  extend ActiveModel::Naming
+  include ActiveModel::Conversion
+
+  attr_reader :id
+  attr_reader :post_id
+  def initialize(id = nil, post_id = nil); @id, @post_id = id, post_id end
+  def save; @id = 1; @post_id = 1 end
+  def new_record?; @id.nil? end
+  def to_param; @id; end
+  def name
+    @id.nil? ? &quot;new #{self.class.name.downcase}&quot; : &quot;#{self.class.name.downcase} ##{@id}&quot;
+  end
+
+  attr_accessor :relevances
+  def relevances_attributes=(attributes); end
+
+end
+
+class Tag
+  extend ActiveModel::Naming
+  include ActiveModel::Conversion
+
+  attr_reader :id
+  attr_reader :post_id
+  def initialize(id = nil, post_id = nil); @id, @post_id = id, post_id end
+  def save; @id = 1; @post_id = 1 end
+  def new_record?; @id.nil? end
+  def to_param; @id; end
+  def value
+    @id.nil? ? &quot;new #{self.class.name.downcase}&quot; : &quot;#{self.class.name.downcase} ##{@id}&quot;
+  end
+
+  attr_accessor :relevances
+  def relevances_attributes=(attributes); end
+
+end
+
+class CommentRelevance
+  extend ActiveModel::Naming
+  include ActiveModel::Conversion
+
+  attr_reader :id
+  attr_reader :comment_id
+  def initialize(id = nil, comment_id = nil); @id, @comment_id = id, comment_id end
+  def save; @id = 1; @comment_id = 1 end
+  def new_record?; @id.nil? end
+  def to_param; @id; end
+  def value
+    @id.nil? ? &quot;new #{self.class.name.downcase}&quot; : &quot;#{self.class.name.downcase} ##{@id}&quot;
+  end
+end
+
+class TagRelevance
+  extend ActiveModel::Naming
+  include ActiveModel::Conversion
+
+  attr_reader :id
+  attr_reader :tag_id
+  def initialize(id = nil, tag_id = nil); @id, @tag_id = id, tag_id end
+  def save; @id = 1; @tag_id = 1 end
+  def new_record?; @id.nil? end
+  def to_param; @id; end
+  def value
+    @id.nil? ? &quot;new #{self.class.name.downcase}&quot; : &quot;#{self.class.name.downcase} ##{@id}&quot;
+  end
+end
+
+class Author &lt; Comment
+  attr_accessor :post
+  def post_attributes=(attributes); end
+end</diff>
      <filename>actionpack/test/lib/controller/fake_models.rb</filename>
    </modified>
    <modified>
      <diff>@@ -231,6 +231,11 @@ class AssetTagHelperTest &lt; ActionView::TestCase
     assert_dom_equal(%(&lt;script src=&quot;/javascripts/prototype.js?1&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;\n&lt;script src=&quot;/javascripts/effects.js?1&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;\n&lt;script src=&quot;/javascripts/dragdrop.js?1&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;\n&lt;script src=&quot;/javascripts/controls.js?1&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;\n&lt;script src=&quot;/javascripts/application.js?1&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;), javascript_include_tag(:defaults))
   end
 
+  def test_javascript_include_tag_is_html_safe
+    assert javascript_include_tag(:defaults).html_safe?
+    assert javascript_include_tag(&quot;prototype&quot;).html_safe?
+  end
+
   def test_register_javascript_include_default
     ENV[&quot;RAILS_ASSET_ID&quot;] = &quot;&quot;
     ActionView::Helpers::AssetTagHelper::register_javascript_include_default 'bank'
@@ -285,6 +290,13 @@ class AssetTagHelperTest &lt; ActionView::TestCase
     }
   end
 
+  def test_stylesheet_link_tag_is_html_safe
+    ENV[&quot;RAILS_ASSET_ID&quot;] = &quot;&quot;
+    assert stylesheet_link_tag('dir/file').html_safe?
+    assert stylesheet_link_tag('dir/other/file', 'dir/file2').html_safe?
+    assert stylesheet_tag('dir/file', {}).html_safe?
+  end
+
   def test_custom_stylesheet_expansions
     ENV[&quot;RAILS_ASSET_ID&quot;] = ''
     ActionView::Helpers::AssetTagHelper::register_stylesheet_expansion :robbery =&gt; [&quot;bank&quot;, &quot;robber&quot;]</diff>
      <filename>actionpack/test/template/asset_tag_helper_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -15,6 +15,18 @@ class ErbUtilTest &lt; Test::Unit::TestCase
     end
   end
   
+  def test_html_escape_is_html_safe
+    escaped = h(&quot;&lt;p&gt;&quot;)
+    assert_equal &quot;&amp;lt;p&amp;gt;&quot;, escaped
+    assert escaped.html_safe?
+  end
+
+  def test_html_escape_passes_html_escpe_unmodified
+    escaped = h(&quot;&lt;p&gt;&quot;.html_safe!)
+    assert_equal &quot;&lt;p&gt;&quot;, escaped
+    assert escaped.html_safe?
+  end
+
   def test_rest_in_ascii
     (0..127).to_a.map {|int| int.chr }.each do |chr|
       next if %w(&amp; &quot; &lt; &gt;).include?(chr)</diff>
      <filename>actionpack/test/template/erb_util_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,103 +1,5 @@
 require 'abstract_unit'
-
-silence_warnings do
-  class Post &lt; Struct.new(:title, :author_name, :body, :secret, :written_on, :cost)
-    extend ActiveModel::Naming
-    include ActiveModel::Conversion
-
-    alias_method :secret?, :secret
-
-    def new_record=(boolean)
-      @new_record = boolean
-    end
-
-    def new_record?
-      @new_record
-    end
-
-    attr_accessor :author
-    def author_attributes=(attributes); end
-
-    attr_accessor :comments
-    def comments_attributes=(attributes); end
-
-    attr_accessor :tags
-    def tags_attributes=(attributes); end
-  end
-
-  class Comment
-    extend ActiveModel::Naming
-    include ActiveModel::Conversion
-
-    attr_reader :id
-    attr_reader :post_id
-    def initialize(id = nil, post_id = nil); @id, @post_id = id, post_id end
-    def save; @id = 1; @post_id = 1 end
-    def new_record?; @id.nil? end
-    def to_param; @id; end
-    def name
-      @id.nil? ? &quot;new #{self.class.name.downcase}&quot; : &quot;#{self.class.name.downcase} ##{@id}&quot;
-    end
-
-    attr_accessor :relevances
-    def relevances_attributes=(attributes); end
-
-  end
-
-  class Tag
-    extend ActiveModel::Naming
-    include ActiveModel::Conversion
-
-    attr_reader :id
-    attr_reader :post_id
-    def initialize(id = nil, post_id = nil); @id, @post_id = id, post_id end
-    def save; @id = 1; @post_id = 1 end
-    def new_record?; @id.nil? end
-    def to_param; @id; end
-    def value
-      @id.nil? ? &quot;new #{self.class.name.downcase}&quot; : &quot;#{self.class.name.downcase} ##{@id}&quot;
-    end
-
-    attr_accessor :relevances
-    def relevances_attributes=(attributes); end
-
-  end
-
-  class CommentRelevance
-    extend ActiveModel::Naming
-    include ActiveModel::Conversion
-
-    attr_reader :id
-    attr_reader :comment_id
-    def initialize(id = nil, comment_id = nil); @id, @comment_id = id, comment_id end
-    def save; @id = 1; @comment_id = 1 end
-    def new_record?; @id.nil? end
-    def to_param; @id; end
-    def value
-      @id.nil? ? &quot;new #{self.class.name.downcase}&quot; : &quot;#{self.class.name.downcase} ##{@id}&quot;
-    end
-  end
-
-  class TagRelevance
-    extend ActiveModel::Naming
-    include ActiveModel::Conversion
-
-    attr_reader :id
-    attr_reader :tag_id
-    def initialize(id = nil, tag_id = nil); @id, @tag_id = id, tag_id end
-    def save; @id = 1; @tag_id = 1 end
-    def new_record?; @id.nil? end
-    def to_param; @id; end
-    def value
-      @id.nil? ? &quot;new #{self.class.name.downcase}&quot; : &quot;#{self.class.name.downcase} ##{@id}&quot;
-    end
-  end
-
-  class Author &lt; Comment
-    attr_accessor :post
-    def post_attributes=(attributes); end
-  end
-end
+require 'controller/fake_models'
 
 class FormHelperTest &lt; ActionView::TestCase
   tests ActionView::Helpers::FormHelper
@@ -1072,7 +974,7 @@ class FormHelperTest &lt; ActionView::TestCase
     (field_helpers - %w(hidden_field)).each do |selector|
       src = &lt;&lt;-END_SRC
         def #{selector}(field, *args, &amp;proc)
-          &quot;&lt;label for='\#{field}'&gt;\#{field.to_s.humanize}:&lt;/label&gt; &quot; + super + &quot;&lt;br/&gt;&quot;
+          (&quot;&lt;label for='\#{field}'&gt;\#{field.to_s.humanize}:&lt;/label&gt; &quot; + super + &quot;&lt;br/&gt;&quot;).html_safe!
         end
       END_SRC
       class_eval src, __FILE__, __LINE__</diff>
      <filename>actionpack/test/template/form_helper_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,5 @@
 require 'abstract_unit'
+require 'controller/fake_models'
 
 class Post
   extend ActiveModel::Naming
@@ -26,7 +27,7 @@ class RecordTagHelperTest &lt; ActionView::TestCase
   end
 
   def test_content_tag_for_prefix
-    expected = %(&lt;ul class=&quot;post&quot; id=&quot;archived_post_45&quot;&gt;&lt;/ul&gt;)
+    expected = %(&lt;ul class=&quot;archived_post&quot; id=&quot;archived_post_45&quot;&gt;&lt;/ul&gt;)
     actual = content_tag_for(:ul, @post, :archived) { }
     assert_dom_equal expected, actual
   end</diff>
      <filename>actionpack/test/template/record_tag_helper_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -229,7 +229,7 @@ module RenderTestCases
   end
 
   def test_render_with_nested_layout
-    assert_equal %(&lt;title&gt;title&lt;/title&gt;\n&lt;div id=&quot;column&quot;&gt;column&lt;/div&gt;\n&lt;div id=&quot;content&quot;&gt;content&lt;/div&gt;\n),
+    assert_equal %(&lt;title&gt;title&lt;/title&gt;\n\n\n&lt;div id=&quot;column&quot;&gt;column&lt;/div&gt;\n&lt;div id=&quot;content&quot;&gt;content&lt;/div&gt;\n),
       @view.render(:file =&gt; &quot;test/nested_layout.erb&quot;, :layout =&gt; &quot;layouts/yield&quot;)
   end
 </diff>
      <filename>actionpack/test/template/render_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -39,7 +39,16 @@ class SanitizeHelperTest &lt; ActionView::TestCase
     %{This is a test.\n\n\nIt no longer contains any HTML.\n}, strip_tags(
     %{&lt;title&gt;This is &lt;b&gt;a &lt;a href=&quot;&quot; target=&quot;_blank&quot;&gt;test&lt;/a&gt;&lt;/b&gt;.&lt;/title&gt;\n\n&lt;!-- it has a comment --&gt;\n\n&lt;p&gt;It no &lt;b&gt;longer &lt;strong&gt;contains &lt;em&gt;any &lt;strike&gt;HTML&lt;/strike&gt;&lt;/em&gt;.&lt;/strong&gt;&lt;/b&gt;&lt;/p&gt;\n}))
     assert_equal &quot;This has a  here.&quot;, strip_tags(&quot;This has a &lt;!-- comment --&gt; here.&quot;)
-    [nil, '', '   '].each { |blank| assert_equal blank, strip_tags(blank) }
+    [nil, '', '   '].each do |blank|
+      stripped = strip_tags(blank)
+      assert_equal blank, stripped
+      assert stripped.html_safe? unless blank.nil?
+    end
+    assert strip_tags(&quot;&lt;script&gt;&quot;).html_safe?
+  end
+
+  def test_sanitize_is_marked_safe
+    assert sanitize(&quot;&lt;html&gt;&lt;script&gt;&lt;/script&gt;&lt;/html&gt;&quot;).html_safe?
   end
 
   def assert_sanitized(text, expected = nil)</diff>
      <filename>actionpack/test/template/sanitize_helper_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -34,6 +34,7 @@ class TagHelperTest &lt; ActionView::TestCase
 
   def test_content_tag
     assert_equal &quot;&lt;a href=\&quot;create\&quot;&gt;Create&lt;/a&gt;&quot;, content_tag(&quot;a&quot;, &quot;Create&quot;, &quot;href&quot; =&gt; &quot;create&quot;)
+    assert content_tag(&quot;a&quot;, &quot;Create&quot;, &quot;href&quot; =&gt; &quot;create&quot;).html_safe?
     assert_equal content_tag(&quot;a&quot;, &quot;Create&quot;, &quot;href&quot; =&gt; &quot;create&quot;),
                  content_tag(&quot;a&quot;, &quot;Create&quot;, :href =&gt; &quot;create&quot;)
   end</diff>
      <filename>actionpack/test/template/tag_helper_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -19,32 +19,41 @@ module PeopleHelper
 end
 
 class PeopleHelperTest &lt; ActionView::TestCase
-  def setup
-    super
-    ActionController::Routing::Routes.draw do |map|
-      map.people 'people', :controller =&gt; 'people', :action =&gt; 'index'
-      map.connect ':controller/:action/:id'
-    end
-  end
-
   def test_title
     assert_equal &quot;&lt;h1&gt;Ruby on Rails&lt;/h1&gt;&quot;, title(&quot;Ruby on Rails&quot;)
   end
 
   def test_homepage_path
-    assert_equal &quot;/people&quot;, homepage_path
+    with_test_route_set do
+      assert_equal &quot;/people&quot;, homepage_path
+    end
   end
 
   def test_homepage_url
-    assert_equal &quot;http://test.host/people&quot;, homepage_url
+    with_test_route_set do
+      assert_equal &quot;http://test.host/people&quot;, homepage_url
+    end
   end
 
   def test_link_to_person
-    person = mock(:name =&gt; &quot;David&quot;)
-    person.class.extend ActiveModel::Naming
-    expects(:mocha_mock_path).with(person).returns(&quot;/people/1&quot;)
-    assert_equal '&lt;a href=&quot;/people/1&quot;&gt;David&lt;/a&gt;', link_to_person(person)
+    with_test_route_set do
+      person = mock(:name =&gt; &quot;David&quot;)
+      person.class.extend ActiveModel::Naming
+      expects(:mocha_mock_path).with(person).returns(&quot;/people/1&quot;)
+      assert_equal '&lt;a href=&quot;/people/1&quot;&gt;David&lt;/a&gt;', link_to_person(person)
+    end
   end
+
+  private
+    def with_test_route_set
+      with_routing do |set|
+        set.draw do |map|
+          map.people 'people', :controller =&gt; 'people', :action =&gt; 'index'
+          map.connect ':controller/:action/:id'
+        end
+        yield
+      end
+    end
 end
 
 class CrazyHelperTest &lt; ActionView::TestCase</diff>
      <filename>actionpack/test/template/test_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -139,7 +139,7 @@ class UrlHelperTest &lt; ActionView::TestCase
   end
 
   def test_link_tag_with_img
-    assert_dom_equal &quot;&lt;a href=\&quot;http://www.example.com\&quot;&gt;&lt;img src='/favicon.jpg' /&gt;&lt;/a&gt;&quot;, link_to(&quot;&lt;img src='/favicon.jpg' /&gt;&quot;, &quot;http://www.example.com&quot;)
+    assert_dom_equal &quot;&lt;a href=\&quot;http://www.example.com\&quot;&gt;&lt;img src='/favicon.jpg' alt=\&quot;Favicon\&quot;  /&gt;&lt;/a&gt;&quot;, link_to(image_tag(&quot;/favicon.jpg&quot;), &quot;http://www.example.com&quot;)
   end
 
   def test_link_with_nil_html_options</diff>
      <filename>actionpack/test/template/url_helper_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,6 @@
+require 'active_support/core_ext/hash/keys'
+require 'active_support/core_ext/class/inheritable_attributes'
+
 module ActiveModel
   class MissingAttributeError &lt; NoMethodError
   end
@@ -162,6 +165,7 @@ module ActiveModel
             end
           end
         end
+        @attribute_methods_generated = true
       end
 
       def undefine_attribute_methods
@@ -173,7 +177,6 @@ module ActiveModel
 
       def generated_attribute_methods #:nodoc:
         @generated_attribute_methods ||= begin
-          @attribute_methods_generated = true
           mod = Module.new
           include mod
           mod
@@ -219,7 +222,7 @@ module ActiveModel
         end
 
         def attribute_method_matchers #:nodoc:
-          @@attribute_method_matchers ||= []
+          read_inheritable_attribute(:attribute_method_matchers) || write_inheritable_attribute(:attribute_method_matchers, [])
         end
     end
 </diff>
      <filename>activemodel/lib/active_model/attribute_methods.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 # You can test whether an object is compliant with the ActiveModel API by
-# calling ActiveModel::Lint.test(object). It will emit a Test::Unit
-# output that tells you whether your object is fully compliant, or if not,
+# including ActiveModel::Lint::Tests in your TestCase. It will included
+# tests that tell you whether your object is fully compliant, or if not,
 # which aspects of the API are not implemented.
 #
 # These tests do not attempt to determine the semantic correctness of the
@@ -12,36 +12,15 @@
 # call to to_model. It is perfectly fine for to_model to return self.
 module ActiveModel
   module Lint
-    def self.test(object, verbosity = 2, output = STDOUT)
-      require &quot;test/unit&quot;
-      require &quot;test/unit/ui/console/testrunner&quot;
-
-      test_class = Class.new(::Test::Unit::TestCase) do
-        include Test
-
-        define_method(:setup) do
-          assert object.respond_to?(:to_model), &quot;The object should respond_to :to_model&quot;
-          @object = object.to_model
-          super
-        end
-      end
-
-      ::Test::Unit::UI::Console::TestRunner.new(test_class, verbosity, output).start
-    end
-
-    module Test
-      def assert_boolean(name, result)
-        assert result == true || result == false, &quot;#{name} should be a boolean&quot;
-      end
-
+    module Tests
       # valid?
       # ------
       #
       # Returns a boolean that specifies whether the object is in a valid or invalid
       # state.
       def test_valid?
-        assert @object.respond_to?(:valid?), &quot;The model should respond to valid?&quot;
-        assert_boolean &quot;valid?&quot;, @object.valid?
+        assert model.respond_to?(:valid?), &quot;The model should respond to valid?&quot;
+        assert_boolean model.valid?, &quot;valid?&quot;
       end
 
       # new_record?
@@ -53,13 +32,13 @@ module ActiveModel
       # collection. If it is persisted, a form for the object will put PUTed to the
       # URL for the object.
       def test_new_record?
-        assert @object.respond_to?(:new_record?), &quot;The model should respond to new_record?&quot;
-        assert_boolean &quot;new_record?&quot;, @object.new_record?
+        assert model.respond_to?(:new_record?), &quot;The model should respond to new_record?&quot;
+        assert_boolean model.new_record?, &quot;new_record?&quot;
       end
 
       def test_destroyed?
-        assert @object.respond_to?(:destroyed?), &quot;The model should respond to destroyed?&quot;
-        assert_boolean &quot;destroyed?&quot;, @object.destroyed?
+        assert model.respond_to?(:destroyed?), &quot;The model should respond to destroyed?&quot;
+        assert_boolean model.destroyed?, &quot;destroyed?&quot;
       end
 
       # errors
@@ -67,29 +46,32 @@ module ActiveModel
       #
       # Returns an object that has :[] and :full_messages defined on it. See below
       # for more details.
-      def setup
-        assert @object.respond_to?(:errors), &quot;The model should respond to errors&quot;
-        @errors = @object.errors
+
+      # Returns an Array of Strings that are the errors for the attribute in
+      # question. If localization is used, the Strings should be localized
+      # for the current locale. If no error is present, this method should
+      # return an empty Array.
+      def test_errors_aref
+        assert model.respond_to?(:errors), &quot;The model should respond to errors&quot;
+        assert model.errors[:hello].is_a?(Array), &quot;errors#[] should return an Array&quot;
       end
 
-      # This module tests the #errors object
-      module Errors
-        # Returns an Array of Strings that are the errors for the attribute in
-        # question. If localization is used, the Strings should be localized
-        # for the current locale. If no error is present, this method should
-        # return an empty Array.
-        def test_errors_aref
-          assert @errors[:hello].is_a?(Array), &quot;errors#[] should return an Array&quot;
-        end
+      # Returns an Array of all error messages for the object. Each message
+      # should contain information about the field, if applicable.
+      def test_errors_full_messages
+        assert model.respond_to?(:errors), &quot;The model should respond to errors&quot;
+        assert model.errors.full_messages.is_a?(Array), &quot;errors#full_messages should return an Array&quot;
+      end
 
-        # Returns an Array of all error messages for the object. Each message
-        # should contain information about the field, if applicable.
-        def test_errors_full_messages
-          assert @errors.full_messages.is_a?(Array), &quot;errors#full_messages should return an Array&quot;
+      private
+        def model
+          assert @model.respond_to?(:to_model), &quot;The object should respond_to to_model&quot;
+          @model.to_model
         end
-      end
 
-      include Errors
+        def assert_boolean(result, name)
+          assert result == true || result == false, &quot;#{name} should be a boolean&quot;
+        end
     end
   end
 end</diff>
      <filename>activemodel/lib/active_model/lint.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,15 +1,17 @@
 require &quot;cases/helper&quot;
 
-class TestLint &lt; ActiveModel::TestCase
-  class CompliantObject
+class LintTest &lt; ActiveModel::TestCase
+  include ActiveModel::Lint::Tests
+
+  class CompliantModel
     def to_model
       self
     end
-    
+
     def valid?()      true end
     def new_record?() true end
     def destroyed?()  true end
-    
+
     def errors
       obj = Object.new
       def obj.[](key)         [] end
@@ -17,34 +19,8 @@ class TestLint &lt; ActiveModel::TestCase
       obj
     end
   end
-  
-  def assert_output(object, failures, errors, *test_names)
-    ActiveModel::Lint.test(object, 3, output = StringIO.new)
-    regex =  %r{#{failures} failures, #{errors} errors}
-    assert_match regex, output.string
-    
-    test_names.each do |test_name|
-      assert_match test_name, output.string
-    end
-  end
-  
-  def test_valid
-    assert_output(CompliantObject.new, 0, 0, /test_valid/)
-  end
-  
-  def test_new_record
-    assert_output(CompliantObject.new, 0, 0, /test_new_record?/)
-  end
-  
-  def test_destroyed
-    assert_output(CompliantObject.new, 0, 0, /test_destroyed/)
-  end
-  
-  def test_errors_aref
-    assert_output(CompliantObject.new, 0, 0, /test_errors_aref/)
-  end
 
-  def test_errors_full_messages
-    assert_output(CompliantObject.new, 0, 0, /test_errors_aref/)
+  def setup
+    @model = CompliantModel.new
   end
 end</diff>
      <filename>activemodel/test/cases/lint_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2427,6 +2427,29 @@ module ActiveRecord #:nodoc:
         result
       end
 
+      # Cloned objects have no id assigned and are treated as new records. Note that this is a &quot;shallow&quot; clone
+      # as it copies the object's attributes only, not its associations. The extent of a &quot;deep&quot; clone is
+      # application specific and is therefore left to the application to implement according to its need.
+      def initialize_copy(other)
+        # Think the assertion which fails if the after_initialize callback goes at the end of the method is wrong. The
+        # deleted clone method called new which therefore called the after_initialize callback. It then went on to copy
+        # over the attributes. But if it's copying the attributes afterwards then it hasn't finished initializing right?
+        # For example in the test suite the topic model's after_initialize method sets the author_email_address to
+        # test@test.com. I would have thought this would mean that all cloned models would have an author email address
+        # of test@test.com. However the test_clone test method seems to test that this is not the case. As a result the
+        # after_initialize callback has to be run *before* the copying of the atrributes rather than afterwards in order
+        # for all tests to pass. This makes no sense to me.
+        callback(:after_initialize) if respond_to_without_attributes?(:after_initialize)
+        cloned_attributes = other.clone_attributes(:read_attribute_before_type_cast)
+        cloned_attributes.delete(self.class.primary_key)
+        @attributes = cloned_attributes
+        clear_aggregation_cache
+        @attributes_cache = {}
+        @new_record = true
+        ensure_proper_type
+        self.class.send(:scope, :create).each { |att, value| self.send(&quot;#{att}=&quot;, value) } if self.class.send(:scoped?, :create)
+      end
+
       # Returns a String, which Action Pack uses for constructing an URL to this
       # object. The default implementation returns this record's id as a String,
       # or nil if this record's unsaved.
@@ -2555,19 +2578,6 @@ module ActiveRecord #:nodoc:
         freeze
       end
 
-      # Returns a clone of the record that hasn't been assigned an id yet and
-      # is treated as a new record.  Note that this is a &quot;shallow&quot; clone:
-      # it copies the object's attributes only, not its associations.
-      # The extent of a &quot;deep&quot; clone is application-specific and is therefore
-      # left to the application to implement according to its need.
-      def clone
-        attrs = clone_attributes(:read_attribute_before_type_cast)
-        attrs.delete(self.class.primary_key)
-        record = self.class.new
-        record.send :instance_variable_set, '@attributes', attrs
-        record
-      end
-
       # Returns an instance of the specified +klass+ with the attributes of the current record. This is mostly useful in relation to
       # single-table inheritance structures where you want a subclass to appear as the superclass. This can be used along with record
       # identification in Action Pack to allow, say, &lt;tt&gt;Client &lt; Company&lt;/tt&gt; to do something like render &lt;tt&gt;:partial =&gt; @client.becomes(Company)&lt;/tt&gt;
@@ -2831,6 +2841,21 @@ module ActiveRecord #:nodoc:
         &quot;#&lt;#{self.class} #{attributes_as_nice_string}&gt;&quot;
       end
 
+    protected
+      def clone_attributes(reader_method = :read_attribute, attributes = {})
+        self.attribute_names.inject(attributes) do |attrs, name|
+          attrs[name] = clone_attribute_value(reader_method, name)
+          attrs
+        end
+      end
+
+      def clone_attribute_value(reader_method, attribute_name)
+        value = send(reader_method, attribute_name)
+        value.duplicable? ? value.clone : value
+      rescue TypeError, NoMethodError
+        value
+      end
+
     private
       def create_or_update
         raise ReadOnlyRecord if readonly?
@@ -3093,20 +3118,6 @@ module ActiveRecord #:nodoc:
         return string unless string.is_a?(String) &amp;&amp; string =~ /^---/
         YAML::load(string) rescue string
       end
-
-      def clone_attributes(reader_method = :read_attribute, attributes = {})
-        self.attribute_names.inject(attributes) do |attrs, name|
-          attrs[name] = clone_attribute_value(reader_method, name)
-          attrs
-        end
-      end
-
-      def clone_attribute_value(reader_method, attribute_name)
-        value = send(reader_method, attribute_name)
-        value.duplicable? ? value.clone : value
-      rescue TypeError, NoMethodError
-        value
-      end
   end
 
   Base.class_eval do</diff>
      <filename>activerecord/lib/active_record/base.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,11 +3,14 @@ require 'active_support/core_ext/object/try'
 
 module ActiveRecord
   module NestedAttributes #:nodoc:
+    class TooManyRecords &lt; ActiveRecordError
+    end
+
     extend ActiveSupport::Concern
 
     included do
-      class_inheritable_accessor :reject_new_nested_attributes_procs, :instance_writer =&gt; false
-      self.reject_new_nested_attributes_procs = {}
+      class_inheritable_accessor :nested_attributes_options, :instance_writer =&gt; false
+      self.nested_attributes_options = {}
     end
 
     # == Nested Attributes
@@ -127,6 +130,22 @@ module ActiveRecord
     #   member.posts.first.title # =&gt; 'Kari, the awesome Ruby documentation browser!'
     #   member.posts.second.title # =&gt; 'The egalitarian assumption of the modern citizen'
     #
+    #  Alternatively, :reject_if also accepts a symbol for using methods:
+    #
+    #    class Member &lt; ActiveRecord::Base
+    #      has_many :posts
+    #      accepts_nested_attributes_for :posts, :reject_if =&gt; :new_record?
+    #    end
+    #
+    #    class Member &lt; ActiveRecord::Base
+    #      has_many :posts
+    #      accepts_nested_attributes_for :posts, :reject_if =&gt; :reject_posts
+    #
+    #      def reject_posts(attributed)
+    #        attributed['title].blank?
+    #      end
+    #    end
+    #
     # If the hash contains an &lt;tt&gt;id&lt;/tt&gt; key that matches an already
     # associated record, the matching record will be modified:
     #
@@ -179,13 +198,20 @@ module ActiveRecord
       #   &lt;tt&gt;_destroy&lt;/tt&gt; key and a value that evaluates to +true+
       #   (eg. 1, '1', true, or 'true'). This option is off by default.
       # [:reject_if]
-      #   Allows you to specify a Proc that checks whether a record should be
-      #   built for a certain attribute hash. The hash is passed to the Proc
-      #   and the Proc should return either +true+ or +false+. When no Proc
-      #   is specified a record will be built for all attribute hashes that
+      #   Allows you to specify a Proc or a Symbol pointing to a method
+      #   that checks whether a record should be built for a certain attribute
+      #   hash. The hash is passed to the supplied Proc or the method
+      #   and it should return either +true+ or +false+. When no :reject_if
+      #   is specified, a record will be built for all attribute hashes that
       #   do not have a &lt;tt&gt;_destroy&lt;/tt&gt; value that evaluates to true.
       #   Passing &lt;tt&gt;:all_blank&lt;/tt&gt; instead of a Proc will create a proc
       #   that will reject a record where all the attributes are blank.
+      # [:limit]
+      #   Allows you to specify the maximum number of the associated records that
+      #   can be processes with the nested attributes. If the size of the
+      #   nested attributes array exceeds the specified limit, NestedAttributes::TooManyRecords
+      #   exception is raised. If omitted, any number associations can be processed.
+      #   Note that the :limit option is only applicable to one-to-many associations.
       #
       # Examples:
       #   # creates avatar_attributes=
@@ -197,7 +223,7 @@ module ActiveRecord
       def accepts_nested_attributes_for(*attr_names)
         options = { :allow_destroy =&gt; false }
         options.update(attr_names.extract_options!)
-        options.assert_valid_keys(:allow_destroy, :reject_if)
+        options.assert_valid_keys(:allow_destroy, :reject_if, :limit)
 
         attr_names.each do |association_name|
           if reflection = reflect_on_association(association_name)
@@ -210,10 +236,10 @@ module ActiveRecord
 
             reflection.options[:autosave] = true
 
-            self.reject_new_nested_attributes_procs[association_name.to_sym] = if options[:reject_if] == :all_blank
-              proc { |attributes| attributes.all? {|k,v| v.blank?} }
-            else
-              options[:reject_if]
+            self.nested_attributes_options[association_name.to_sym] = options
+
+            if options[:reject_if] == :all_blank
+              self.nested_attributes_options[association_name.to_sym][:reject_if] = proc { |attributes| attributes.all? {|k,v| v.blank?} }
             end
 
             # def pirate_attributes=(attributes)
@@ -221,7 +247,7 @@ module ActiveRecord
             # end
             class_eval %{
               def #{association_name}_attributes=(attributes)
-                assign_nested_attributes_for_#{type}_association(:#{association_name}, attributes, #{options[:allow_destroy]})
+                assign_nested_attributes_for_#{type}_association(:#{association_name}, attributes)
               end
             }, __FILE__, __LINE__
           else
@@ -265,8 +291,9 @@ module ActiveRecord
     # If the given attributes include a matching &lt;tt&gt;:id&lt;/tt&gt; attribute _and_ a
     # &lt;tt&gt;:_destroy&lt;/tt&gt; key set to a truthy value, then the existing record
     # will be marked for destruction.
-    def assign_nested_attributes_for_one_to_one_association(association_name, attributes, allow_destroy)
-      attributes = attributes.stringify_keys
+    def assign_nested_attributes_for_one_to_one_association(association_name, attributes)
+      options = self.nested_attributes_options[association_name]
+      attributes = attributes.with_indifferent_access
 
       if attributes['id'].blank?
         unless reject_new_record?(association_name, attributes)
@@ -278,7 +305,7 @@ module ActiveRecord
           end
         end
       elsif (existing_record = send(association_name)) &amp;&amp; existing_record.id.to_s == attributes['id'].to_s
-        assign_to_or_mark_for_destruction(existing_record, attributes, allow_destroy)
+        assign_to_or_mark_for_destruction(existing_record, attributes, options[:allow_destroy])
       end
     end
 
@@ -309,24 +336,30 @@ module ActiveRecord
     #     { :name =&gt; 'John' },
     #     { :id =&gt; '2', :_destroy =&gt; true }
     #   ])
-    def assign_nested_attributes_for_collection_association(association_name, attributes_collection, allow_destroy)
+    def assign_nested_attributes_for_collection_association(association_name, attributes_collection)
+      options = self.nested_attributes_options[association_name]
+
       unless attributes_collection.is_a?(Hash) || attributes_collection.is_a?(Array)
         raise ArgumentError, &quot;Hash or Array expected, got #{attributes_collection.class.name} (#{attributes_collection.inspect})&quot;
       end
 
+      if options[:limit] &amp;&amp; attributes_collection.size &gt; options[:limit]
+        raise TooManyRecords, &quot;Maximum #{options[:limit]} records are allowed. Got #{attributes_collection.size} records instead.&quot;
+      end
+
       if attributes_collection.is_a? Hash
         attributes_collection = attributes_collection.sort_by { |index, _| index.to_i }.map { |_, attributes| attributes }
       end
 
       attributes_collection.each do |attributes|
-        attributes = attributes.stringify_keys
+        attributes = attributes.with_indifferent_access
 
         if attributes['id'].blank?
           unless reject_new_record?(association_name, attributes)
             send(association_name).build(attributes.except(*UNASSIGNABLE_KEYS))
           end
         elsif existing_record = send(association_name).detect { |record| record.id.to_s == attributes['id'].to_s }
-          assign_to_or_mark_for_destruction(existing_record, attributes, allow_destroy)
+          assign_to_or_mark_for_destruction(existing_record, attributes, options[:allow_destroy])
         end
       end
     end
@@ -351,8 +384,18 @@ module ActiveRecord
     # has_destroy_flag? or if a &lt;tt&gt;:reject_if&lt;/tt&gt; proc exists for this
     # association and evaluates to +true+.
     def reject_new_record?(association_name, attributes)
-      has_destroy_flag?(attributes) ||
-        self.class.reject_new_nested_attributes_procs[association_name].try(:call, attributes)
+      has_destroy_flag?(attributes) || call_reject_if(association_name, attributes)
+    end
+
+    def call_reject_if(association_name, attributes)
+      callback = self.nested_attributes_options[association_name][:reject_if]
+
+      case callback
+      when Symbol
+        method(callback).arity == 0 ? send(callback) : send(callback, attributes)
+      when Proc
+        callback.try(:call, attributes)
+      end
     end
   end
 end</diff>
      <filename>activerecord/lib/active_record/nested_attributes.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1352,7 +1352,7 @@ class BasicsTest &lt; ActiveRecord::TestCase
     cloned_topic.title[&quot;a&quot;] = &quot;c&quot;
     assert_equal &quot;b&quot;, topic.title[&quot;a&quot;]
 
-    #test if attributes set as part of after_initialize are cloned correctly
+    # test if attributes set as part of after_initialize are cloned correctly
     assert_equal topic.author_email_address, cloned_topic.author_email_address
 
     # test if saved clone object differs from original</diff>
      <filename>activerecord/test/cases/base_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -29,13 +29,13 @@ class TestNestedAttributesInGeneral &lt; ActiveRecord::TestCase
     Pirate.accepts_nested_attributes_for :ship, :allow_destroy =&gt; true, :reject_if =&gt; proc { |attributes| attributes.empty? }
   end
 
-  def test_base_should_have_an_empty_reject_new_nested_attributes_procs
-    assert_equal Hash.new, ActiveRecord::Base.reject_new_nested_attributes_procs
+  def test_base_should_have_an_empty_nested_attributes_options
+    assert_equal Hash.new, ActiveRecord::Base.nested_attributes_options
   end
 
-  def test_should_add_a_proc_to_reject_new_nested_attributes_procs
+  def test_should_add_a_proc_to_nested_attributes_options
     [:parrots, :birds, :birds_with_reject_all_blank].each do |name|
-      assert_instance_of Proc, Pirate.reject_new_nested_attributes_procs[name]
+      assert_instance_of Proc, Pirate.nested_attributes_options[name][:reject_if]
     end
   end
 
@@ -84,6 +84,34 @@ class TestNestedAttributesInGeneral &lt; ActiveRecord::TestCase
     ship = Ship.create!(:name =&gt; 'Nights Dirty Lightning')
     ship._delete
   end
+
+  def test_reject_if_method_without_arguments
+    Pirate.accepts_nested_attributes_for :ship, :reject_if =&gt; :new_record?
+
+    pirate = Pirate.new(:catchphrase =&gt; &quot;Stop wastin' me time&quot;)
+    pirate.ship_attributes = { :name =&gt; 'Black Pearl' }
+    assert_no_difference('Ship.count') { pirate.save! }
+  end
+
+  def test_reject_if_method_with_arguments
+    Pirate.accepts_nested_attributes_for :ship, :reject_if =&gt; :reject_empty_ships_on_create
+
+    pirate = Pirate.new(:catchphrase =&gt; &quot;Stop wastin' me time&quot;)
+    pirate.ship_attributes = { :name =&gt; 'Red Pearl', :_reject_me_if_new =&gt; true }
+    assert_no_difference('Ship.count') { pirate.save! }
+
+    # pirate.reject_empty_ships_on_create returns false for saved records
+    pirate.ship_attributes = { :name =&gt; 'Red Pearl', :_reject_me_if_new =&gt; true }
+    assert_difference('Ship.count') { pirate.save! }
+  end
+
+  def test_reject_if_with_indifferent_keys
+    Pirate.accepts_nested_attributes_for :ship, :reject_if =&gt; proc {|attributes| attributes[:name].blank? }
+
+    pirate = Pirate.new(:catchphrase =&gt; &quot;Stop wastin' me time&quot;)
+    pirate.ship_attributes = { :name =&gt; 'Hello Pearl' }
+    assert_difference('Ship.count') { pirate.save! }
+  end
 end
 
 class TestNestedAttributesOnAHasOneAssociation &lt; ActiveRecord::TestCase
@@ -575,3 +603,33 @@ class TestNestedAttributesOnAHasAndBelongsToManyAssociation &lt; ActiveRecord::Test
 
   include NestedAttributesOnACollectionAssociationTests
 end
+
+class TestNestedAttributesLimit &lt; ActiveRecord::TestCase
+  def setup
+    Pirate.accepts_nested_attributes_for :parrots, :limit =&gt; 2
+
+    @pirate = Pirate.create!(:catchphrase =&gt; &quot;Don' botharrr talkin' like one, savvy?&quot;)
+  end
+
+  def teardown
+    Pirate.accepts_nested_attributes_for :parrots, :allow_destroy =&gt; true, :reject_if =&gt; proc { |attributes| attributes.empty? }
+  end
+
+  def test_limit_with_less_records
+    @pirate.attributes = { :parrots_attributes =&gt; { 'foo' =&gt; { :name =&gt; 'Big Big Love' } } }
+    assert_difference('Parrot.count') { @pirate.save! }
+  end
+
+  def test_limit_with_number_exact_records
+    @pirate.attributes = { :parrots_attributes =&gt; { 'foo' =&gt; { :name =&gt; 'Lovely Day' }, 'bar' =&gt; { :name =&gt; 'Blown Away' } } }
+    assert_difference('Parrot.count', 2) { @pirate.save! }
+  end
+
+  def test_limit_with_exceeding_records
+    assert_raises(ActiveRecord::NestedAttributes::TooManyRecords) do
+      @pirate.attributes = { :parrots_attributes =&gt; { 'foo' =&gt; { :name =&gt; 'Lovely Day' },
+                                                      'bar' =&gt; { :name =&gt; 'Blown Away' },
+                                                      'car' =&gt; { :name =&gt; 'The Happening' }} }
+    end
+  end
+end</diff>
      <filename>activerecord/test/cases/nested_attributes_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -45,6 +45,10 @@ class Pirate &lt; ActiveRecord::Base
     @ship_log ||= []
   end
 
+  def reject_empty_ships_on_create(attributes)
+    attributes.delete('_reject_me_if_new').present? &amp;&amp; new_record?
+  end
+
   private
     def log_before_add(record)
       log(record, &quot;before_adding_method&quot;)</diff>
      <filename>activerecord/test/models/pirate.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,7 @@
 require 'active_support'
 require 'active_support/core_ext/class/attribute_accessors'
 require 'active_support/core_ext/class/inheritable_attributes'
+require 'active_support/core_ext/hash/indifferent_access'
 require 'active_support/core_ext/kernel/reporting'
 require 'active_support/core_ext/module/attr_accessor_with_default'
 require 'active_support/core_ext/module/delegation'
@@ -155,7 +156,7 @@ module ActiveResource
   #
   # &lt;tt&gt;404&lt;/tt&gt; is just one of the HTTP error response codes that Active Resource will handle with its own exception. The
   # following HTTP response codes will also result in these exceptions:
-  # 
+  #
   # * 200..399 - Valid response, no exception (other than 301, 302)
   # * 301, 302 - ActiveResource::Redirection
   # * 400 - ActiveResource::BadRequest
@@ -414,7 +415,7 @@ module ActiveResource
 
       attr_accessor_with_default(:collection_name) { ActiveSupport::Inflector.pluralize(element_name) } #:nodoc:
       attr_accessor_with_default(:primary_key, 'id') #:nodoc:
-      
+
       # Gets the \prefix for a resource's nested URL (e.g., &lt;tt&gt;prefix/collectionname/1.xml&lt;/tt&gt;)
       # This method is regenerated at runtime based on what the \prefix is set to.
       def prefix(options={})
@@ -770,7 +771,7 @@ module ActiveResource
     #   my_other_course = Course.new(:name =&gt; &quot;Philosophy: Reason and Being&quot;, :lecturer =&gt; &quot;Ralph Cling&quot;)
     #   my_other_course.save
     def initialize(attributes = {})
-      @attributes     = {}
+      @attributes     = {}.with_indifferent_access
       @prefix_options = {}
       load(attributes)
     end
@@ -915,7 +916,7 @@ module ActiveResource
     def save
       new? ? create : update
     end
-    
+
     # Saves the resource.
     #
     # If the resource is new, it is created via +POST+, otherwise the
@@ -924,7 +925,7 @@ module ActiveResource
     # With &lt;tt&gt;save!&lt;/tt&gt; validations always run. If any of them fail
     # ActiveResource::ResourceInvalid gets raised, and nothing is POSTed to
     # the remote system.
-    # See ActiveResource::Validations for more information. 
+    # See ActiveResource::Validations for more information.
     #
     # There's a series of callbacks associated with &lt;tt&gt;save!&lt;/tt&gt;. If any
     # of the &lt;tt&gt;before_*&lt;/tt&gt; callbacks return +false+ the action is
@@ -1099,6 +1100,36 @@ module ActiveResource
       self
     end
 
+    # Updates a single attribute and then saves the object.
+    #
+    # Note: Unlike ActiveRecord::Base.update_attribute, this method &lt;b&gt;is&lt;/b&gt;
+    # subject to normal validation routines as an update sends the whole body
+    # of the resource in the request.  (See Validations).
+    #
+    # As such, this method is equivalent to calling update_attributes with a single attribute/value pair.
+    #
+    # If the saving fails because of a connection or remote service error, an
+    # exception will be raised.  If saving fails because the resource is
+    # invalid then &lt;tt&gt;false&lt;/tt&gt; will be returned.
+    def update_attribute(name, value)
+      self.send(&quot;#{name}=&quot;.to_sym, value)
+      self.save
+    end
+
+    # Updates this resource with all the attributes from the passed-in Hash
+    # and requests that the record be saved.
+    #
+    # If the saving fails because of a connection or remote service error, an
+    # exception will be raised.  If saving fails because the resource is
+    # invalid then &lt;tt&gt;false&lt;/tt&gt; will be returned.
+    #
+    # Note: Though this request can be made with a partial set of the
+    # resource's attributes, the full body of the request will still be sent
+    # in the save request to the remote service.
+    def update_attributes(attributes)
+      load(attributes) &amp;&amp; save
+    end
+
     # For checking &lt;tt&gt;respond_to?&lt;/tt&gt; without searching the attributes (which is faster).
     alias_method :respond_to_without_attributes?, :respond_to?
 
@@ -1119,7 +1150,6 @@ module ActiveResource
       super
     end
 
-
     protected
       def connection(refresh = false)
         self.class.connection(refresh)</diff>
      <filename>activeresource/lib/active_resource/base.rb</filename>
    </modified>
    <modified>
      <diff>@@ -8,7 +8,10 @@ module ActiveResource
     end
 
     def to_s
-      &quot;Failed with #{response.code} #{response.message if response.respond_to?(:message)}&quot;
+      message = &quot;Failed.&quot;
+      message &lt;&lt; &quot;  Response code = #{response.code}.&quot; if response.respond_to?(:code)
+      message &lt;&lt; &quot;  Response message = #{response.message}.&quot; if response.respond_to?(:message)
+      message
     end
   end
 </diff>
      <filename>activeresource/lib/active_resource/exceptions.rb</filename>
    </modified>
    <modified>
      <diff>@@ -15,26 +15,21 @@ module Highrise
 
   module Deeply
     module Nested
-
       class Note &lt; ActiveResource::Base
         self.site = &quot;http://37s.sunrise.i:3000&quot;
       end
 
-       class Comment &lt; ActiveResource::Base
-         self.site = &quot;http://37s.sunrise.i:3000&quot;
-       end
-
-       module TestDifferentLevels
-
-         class Note &lt; ActiveResource::Base
-           self.site = &quot;http://37s.sunrise.i:3000&quot;
-         end
-
-       end
+      class Comment &lt; ActiveResource::Base
+        self.site = &quot;http://37s.sunrise.i:3000&quot;
+      end
 
+      module TestDifferentLevels
+        class Note &lt; ActiveResource::Base
+          self.site = &quot;http://37s.sunrise.i:3000&quot;
+        end
+      end
     end
   end
-
 end
 
 
@@ -68,6 +63,19 @@ class BaseLoadTest &lt; Test::Unit::TestCase
     assert_equal @matz.stringify_keys, @person.load(@matz).attributes
   end
 
+  def test_after_load_attributes_are_accessible
+    assert_equal Hash.new, @person.attributes
+    assert_equal @matz.stringify_keys, @person.load(@matz).attributes
+    assert_equal @matz[:name], @person.attributes['name']
+  end
+
+  def test_after_load_attributes_are_accessible_via_indifferent_access
+    assert_equal Hash.new, @person.attributes
+    assert_equal @matz.stringify_keys, @person.load(@matz).attributes
+    assert_equal @matz[:name], @person.attributes['name']
+    assert_equal @matz[:name], @person.attributes[:name]
+  end
+
   def test_load_one_with_existing_resource
     address = @person.load(:street_address =&gt; @first_address).street_address
     assert_kind_of StreetAddress, address
@@ -143,7 +151,7 @@ class BaseLoadTest &lt; Test::Unit::TestCase
     assert_kind_of String, places.first
     assert_equal @deep[:street][:state][:places].first, places.first
   end
-  
+
   def test_nested_collections_within_the_same_namespace
     n = Highrise::Note.new(:comments =&gt; [{ :name =&gt; &quot;1&quot; }])
     assert_kind_of Highrise::Comment, n.comments.first
@@ -158,6 +166,4 @@ class BaseLoadTest &lt; Test::Unit::TestCase
     n = Highrise::Deeply::Nested::TestDifferentLevels::Note.new(:comments =&gt; [{ :name =&gt; &quot;1&quot; }])
     assert_kind_of Highrise::Deeply::Nested::Comment, n.comments.first
   end
-
-
 end</diff>
      <filename>activeresource/test/cases/base/load_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -11,12 +11,12 @@ class BaseTest &lt; Test::Unit::TestCase
     @matz  = { :id =&gt; 1, :name =&gt; 'Matz' }.to_xml(:root =&gt; 'person')
     @david = { :id =&gt; 2, :name =&gt; 'David' }.to_xml(:root =&gt; 'person')
     @greg  = { :id =&gt; 3, :name =&gt; 'Greg' }.to_xml(:root =&gt; 'person')
-    @addy  = { :id =&gt; 1, :street =&gt; '12345 Street' }.to_xml(:root =&gt; 'address')
+    @addy  = { :id =&gt; 1, :street =&gt; '12345 Street', :country =&gt; 'Australia' }.to_xml(:root =&gt; 'address')
     @default_request_headers = { 'Content-Type' =&gt; 'application/xml' }
     @rick = { :name =&gt; &quot;Rick&quot;, :age =&gt; 25 }.to_xml(:root =&gt; &quot;person&quot;)
     @people = [{ :id =&gt; 1, :name =&gt; 'Matz' }, { :id =&gt; 2, :name =&gt; 'David' }].to_xml(:root =&gt; 'people')
     @people_david = [{ :id =&gt; 2, :name =&gt; 'David' }].to_xml(:root =&gt; 'people')
-    @addresses = [{ :id =&gt; 1, :street =&gt; '12345 Street' }].to_xml(:root =&gt; 'addresses')
+    @addresses = [{ :id =&gt; 1, :street =&gt; '12345 Street', :country =&gt; 'Australia' }].to_xml(:root =&gt; 'addresses')
 
     # - deep nested resource -
     # - Luis (Customer)
@@ -102,6 +102,9 @@ class BaseTest &lt; Test::Unit::TestCase
     Person.password = nil
   end
 
+  ########################################################################
+  # Tests relating to setting up the API-connection configuration
+  ########################################################################
 
   def test_site_accessor_accepts_uri_or_string_argument
     site = URI.parse('http://localhost')
@@ -509,6 +512,11 @@ class BaseTest &lt; Test::Unit::TestCase
     assert_not_equal(first_connection, second_connection, 'Connection should be re-created')
   end
 
+
+  ########################################################################
+  # Tests for setting up remote URLs for a given model (including adding
+  # parameters appropriately)
+  ########################################################################
   def test_collection_name
     assert_equal &quot;people&quot;, Person.collection_name
   end
@@ -637,6 +645,10 @@ class BaseTest &lt; Test::Unit::TestCase
     assert_equal [:person_id].to_set, StreetAddress.__send__(:prefix_parameters)
   end
 
+
+  ########################################################################
+  # Tests basic CRUD functions (find/save/create etc)
+  ########################################################################
   def test_respond_to
     matz = Person.find(1)
     assert matz.respond_to?(:name)
@@ -813,6 +825,55 @@ class BaseTest &lt; Test::Unit::TestCase
     assert_raise(ActiveResource::ResourceConflict) { Person.find(2).save }
   end
 
+
+  ######
+  # update_attribute(s)(!)
+
+  def test_update_attribute_as_symbol
+    matz = Person.first
+    matz.expects(:save).returns(true)
+
+    assert_equal &quot;Matz&quot;, matz.name
+    assert matz.update_attribute(:name, &quot;David&quot;)
+    assert_equal &quot;David&quot;, matz.name
+  end
+
+  def test_update_attribute_as_string
+    matz = Person.first
+    matz.expects(:save).returns(true)
+
+    assert_equal &quot;Matz&quot;, matz.name
+    assert matz.update_attribute('name', &quot;David&quot;)
+    assert_equal &quot;David&quot;, matz.name
+  end
+
+
+  def test_update_attributes_as_symbols
+    addy = StreetAddress.first(:params =&gt; {:person_id =&gt; 1})
+    addy.expects(:save).returns(true)
+
+    assert_equal &quot;12345 Street&quot;, addy.street
+    assert_equal &quot;Australia&quot;, addy.country
+    assert addy.update_attributes(:street =&gt; '54321 Street', :country =&gt; 'USA')
+    assert_equal &quot;54321 Street&quot;, addy.street
+    assert_equal &quot;USA&quot;, addy.country
+  end
+
+  def test_update_attributes_as_strings
+    addy = StreetAddress.first(:params =&gt; {:person_id =&gt; 1})
+    addy.expects(:save).returns(true)
+
+    assert_equal &quot;12345 Street&quot;, addy.street
+    assert_equal &quot;Australia&quot;, addy.country
+    assert addy.update_attributes('street' =&gt; '54321 Street', 'country' =&gt; 'USA')
+    assert_equal &quot;54321 Street&quot;, addy.street
+    assert_equal &quot;USA&quot;, addy.country
+  end
+
+
+  #####
+  # Mayhem and destruction
+
   def test_destroy
     assert Person.find(1).destroy
     ActiveResource::HttpMock.respond_to do |mock|
@@ -852,7 +913,7 @@ class BaseTest &lt; Test::Unit::TestCase
     end
     assert_raise(ActiveResource::ResourceNotFound) { StreetAddress.find(1, :params =&gt; { :person_id =&gt; 1 }) }
   end
-  
+
   def test_delete_with_410_gone
     assert Person.delete(1)
     ActiveResource::HttpMock.respond_to do |mock|
@@ -861,6 +922,9 @@ class BaseTest &lt; Test::Unit::TestCase
     assert_raise(ActiveResource::ResourceGone) { Person.find(1) }
   end
 
+  ########################################################################
+  # Tests the more miscelaneous helper methods
+  ########################################################################
   def test_exists
     # Class method.
     assert !Person.exists?(nil)</diff>
      <filename>activeresource/test/cases/base_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -10,7 +10,7 @@ class ObservingTest &lt; Test::Unit::TestCase
 
     %w( after_create after_destroy after_save after_update
         before_create before_destroy before_save before_update).each do |method|
-          define_method(method) { log method }
+          define_method(method) { |*| log method }
     end
 
     private</diff>
      <filename>activeresource/test/cases/observing_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -83,7 +83,7 @@ class ConnectionTest &lt; Test::Unit::TestCase
     begin
       handle_response ResponseHeaderStub.new(405, &quot;HTTP Failed...&quot;, &quot;GET, POST&quot;)
     rescue ActiveResource::MethodNotAllowed =&gt; e
-      assert_equal &quot;Failed with 405 HTTP Failed...&quot;, e.message
+      assert_equal &quot;Failed.  Response code = 405.  Response message = HTTP Failed....&quot;, e.message
       assert_equal [:get, :post], e.allowed_methods
     end
   end</diff>
      <filename>activeresource/test/connection_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -115,6 +115,13 @@ module ActiveSupport
         self
       end
 
+      def mute
+        previous_silence, @silence = defined?(@silence) &amp;&amp; @silence, true
+        yield
+      ensure
+        @silence = previous_silence
+      end
+
       # Fetches data from the cache, using the given key. If there is data in
       # the cache with the given key, then that data is returned.
       #</diff>
      <filename>activesupport/lib/active_support/cache.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/duplicable'
+
 module ActiveSupport
   module Cache
     # A cache store implementation which stores everything into memory in the</diff>
      <filename>activesupport/lib/active_support/cache/memory_store.rb</filename>
    </modified>
    <modified>
      <diff>@@ -44,7 +44,7 @@ module ActiveSupport
             nil
           elsif value.nil?
             value = super
-            local_cache.write(key, value || NULL) if local_cache
+            local_cache.mute { local_cache.write(key, value || NULL) } if local_cache
             value.duplicable? ? value.dup : value
           else
             # forcing the value to be immutable
@@ -54,12 +54,12 @@ module ActiveSupport
 
         def write(key, value, options = nil)
           value = value.to_s if respond_to?(:raw?) &amp;&amp; raw?(options)
-          local_cache.write(key, value || NULL) if local_cache
+          local_cache.mute { local_cache.write(key, value || NULL) } if local_cache
           super
         end
 
         def delete(key, options = nil)
-          local_cache.write(key, NULL) if local_cache
+          local_cache.mute { local_cache.write(key, NULL) } if local_cache
           super
         end
 
@@ -76,7 +76,7 @@ module ActiveSupport
 
         def increment(key, amount = 1)
           if value = super
-            local_cache.write(key, value.to_s) if local_cache
+            local_cache.mute { local_cache.write(key, value.to_s) } if local_cache
             value
           else
             nil
@@ -85,7 +85,7 @@ module ActiveSupport
 
         def decrement(key, amount = 1)
           if value = super
-            local_cache.write(key, value.to_s) if local_cache
+            local_cache.mute { local_cache.write(key, value.to_s) } if local_cache
             value
           else
             nil</diff>
      <filename>activesupport/lib/active_support/cache/strategy/local_cache.rb</filename>
    </modified>
    <modified>
      <diff>@@ -7,4 +7,5 @@ require 'active_support/core_ext/string/access'
 require 'active_support/core_ext/string/iterators'
 require 'active_support/core_ext/string/xchar'
 require 'active_support/core_ext/string/behavior'
-require 'active_support/core_ext/string/interpolation'
\ No newline at end of file
+require 'active_support/core_ext/string/interpolation'
+require 'active_support/core_ext/string/output_safety'
\ No newline at end of file</diff>
      <filename>activesupport/lib/active_support/core_ext/string.rb</filename>
    </modified>
    <modified>
      <diff>@@ -26,8 +26,10 @@ module ActiveSupport
     end
     
     def verify(signed_message)
+      raise InvalidSignature if signed_message.blank?
+
       data, digest = signed_message.split(&quot;--&quot;)
-      if secure_compare(digest, generate_digest(data))
+      if data.present? &amp;&amp; digest.present? &amp;&amp; secure_compare(digest, generate_digest(data))
         Marshal.load(ActiveSupport::Base64.decode64(data))
       else
         raise InvalidSignature</diff>
      <filename>activesupport/lib/active_support/message_verifier.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,5 @@
+require 'active_support/core_ext/load_error'
+
 module ActiveSupport
   module Testing
     class ProxyTestResult
@@ -107,4 +109,4 @@ if ENV['ISOLATION_TEST']
       super &amp;&amp; test.method_name == ENV['ISOLATION_TEST']
     end
   end
-end
\ No newline at end of file
+end</diff>
      <filename>activesupport/lib/active_support/testing/isolation.rb</filename>
    </modified>
    <modified>
      <diff>@@ -342,3 +342,22 @@ uses_memcached 'memcached backed store' do
     include CacheStoreBehavior
   end
 end
+
+class CacheStoreLoggerTest &lt; ActiveSupport::TestCase
+  def setup
+    @cache = ActiveSupport::Cache.lookup_store(:memory_store)
+
+    @buffer = StringIO.new
+    @cache.logger = Logger.new(@buffer)
+  end
+
+  def test_logging
+    @cache.fetch('foo') { 'bar' }
+    assert @buffer.string.present?
+  end
+
+  def test_mute_logging
+    @cache.mute { @cache.fetch('foo') { 'bar' } }
+    assert @buffer.string.blank?
+  end
+end</diff>
      <filename>activesupport/test/caching_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -356,3 +356,89 @@ class StringBytesizeTest &lt; Test::Unit::TestCase
     assert_equal 3, 'foo'.bytesize
   end
 end
+
+class OutputSafetyTest &lt; ActiveSupport::TestCase
+  def setup
+    @string = &quot;hello&quot;
+  end
+
+  test &quot;A string is unsafe by default&quot; do
+    assert !@string.html_safe?
+  end
+
+  test &quot;A string can be marked safe&quot; do
+    @string.html_safe!
+    assert @string.html_safe?
+  end
+
+  test &quot;Marking a string safe returns the string&quot; do
+    assert_equal @string, @string.html_safe!
+  end
+
+  test &quot;Adding a safe string to another safe string returns a safe string&quot; do
+    @other_string = &quot;other&quot;.html_safe!
+    @string.html_safe!
+    @combination = @other_string + @string
+
+    assert_equal &quot;otherhello&quot;, @combination
+    assert @combination.html_safe?
+  end
+
+  test &quot;Adding an unsafe string to a safe string returns an unsafe string&quot; do
+    @other_string = &quot;other&quot;.html_safe!
+    @combination = @other_string + @string
+    @other_combination = @string + @other_string
+
+    assert_equal &quot;otherhello&quot;, @combination
+    assert_equal &quot;helloother&quot;, @other_combination
+
+    assert !@combination.html_safe?
+    assert !@other_combination.html_safe?
+  end
+
+  test &quot;Concatting safe onto unsafe yields unsafe&quot; do
+    @other_string = &quot;other&quot;
+    @string.html_safe!
+
+    @other_string.concat(@string)
+    assert !@other_string.html_safe?
+  end
+
+  test &quot;Concatting unsafe onto safe yields unsafe&quot; do
+    @other_string = &quot;other&quot;.html_safe!
+
+    @other_string.concat(@string)
+    assert !@other_string.html_safe?
+  end
+
+  test &quot;Concatting safe onto safe yields safe&quot; do
+    @other_string = &quot;other&quot;.html_safe!
+    @string.html_safe!
+
+    @other_string.concat(@string)
+    assert @other_string.html_safe?
+  end
+
+  test &quot;Concatting safe onto unsafe with &lt;&lt; yields unsafe&quot; do
+    @other_string = &quot;other&quot;
+    @string.html_safe!
+
+    @other_string &lt;&lt; @string
+    assert !@other_string.html_safe?
+  end
+
+  test &quot;Concatting unsafe onto safe with &lt;&lt; yields unsafe&quot; do
+    @other_string = &quot;other&quot;.html_safe!
+
+    @other_string &lt;&lt; @string
+    assert !@other_string.html_safe?
+  end
+
+  test &quot;Concatting safe onto safe with &lt;&lt; yields safe&quot; do
+    @other_string = &quot;other&quot;.html_safe!
+    @string.html_safe!
+
+    @other_string &lt;&lt; @string
+    assert @other_string.html_safe?
+  end
+end</diff>
      <filename>activesupport/test/core_ext/string_ext_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -18,10 +18,16 @@ class MessageVerifierTest &lt; Test::Unit::TestCase
     assert_equal @data, @verifier.verify(message)
   end
 
+  def test_missing_signature_raises
+    assert_not_verified(nil)
+    assert_not_verified(&quot;&quot;)
+  end
+
   def test_tampered_data_raises
     data, hash = @verifier.generate(@data).split(&quot;--&quot;)
     assert_not_verified(&quot;#{data.reverse}--#{hash}&quot;)
     assert_not_verified(&quot;#{data}--#{hash.reverse}&quot;)
+    assert_not_verified(&quot;purejunk&quot;)
   end
 
   def assert_not_verified(message)</diff>
      <filename>activesupport/test/message_verifier_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -66,6 +66,7 @@ cd &quot;#{root_dir}/actionpack&quot; do
   puts &quot;[CruiseControl] Building ActionPack&quot;
   puts
   build_results[:actionpack] = system 'gem bundle &amp;&amp; rake'
+  build_results[:actionpack_isolated] = system 'rake test:isolated'
 end
 
 cd &quot;#{root_dir}/actionmailer&quot; do</diff>
      <filename>ci/ci_build.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,29 +1,487 @@
 module Rails
   class Application
+    extend Initializable
 
-    def self.config
-      @config ||= Configuration.new
+    class &lt;&lt; self
+      def config
+        @config ||= Configuration.new
+      end
+
+      # TODO: change the plugin loader to use config
+      alias configuration config
+
+      def config=(config)
+        @config = config
+      end
+
+      def plugin_loader
+        @plugin_loader ||= config.plugin_loader.new(self)
+      end
+
+      def routes
+        ActionController::Routing::Routes
+      end
+
+      def middleware
+        config.middleware
+      end
+
+      def call(env)
+        @app ||= middleware.build(routes)
+        @app.call(env)
+      end
+
+      def new
+        initializers.run
+        self
+      end
+    end
+
+    initializer :initialize_rails do
+      Rails.initializers.run
+    end
+
+    # Set the &lt;tt&gt;$LOAD_PATH&lt;/tt&gt; based on the value of
+    # Configuration#load_paths. Duplicates are removed.
+    initializer :set_load_path do
+      config.paths.add_to_load_path
+      $LOAD_PATH.uniq!
+    end
+
+    # Bail if boot.rb is outdated
+    initializer :freak_out_if_boot_rb_is_outdated do
+      unless defined?(Rails::BOOTSTRAP_VERSION)
+        abort %{Your config/boot.rb is outdated: Run &quot;rake rails:update&quot;.}
+      end
+    end
+
+    # Requires all frameworks specified by the Configuration#frameworks
+    # list. By default, all frameworks (Active Record, Active Support,
+    # Action Pack, Action Mailer, and Active Resource) are loaded.
+    initializer :require_frameworks do
+      begin
+        require 'active_support'
+        require 'active_support/core_ext/kernel/reporting'
+        require 'active_support/core_ext/logger'
+
+        # TODO: This is here to make Sam Ruby's tests pass. Needs discussion.
+        require 'active_support/core_ext/numeric/bytes'
+        config.frameworks.each { |framework| require(framework.to_s) }
+      rescue LoadError =&gt; e
+        # Re-raise as RuntimeError because Mongrel would swallow LoadError.
+        raise e.to_s
+      end
+    end
+
+    # Set the paths from which Rails will automatically load source files, and
+    # the load_once paths.
+    initializer :set_autoload_paths do
+      require 'active_support/dependencies'
+      ActiveSupport::Dependencies.load_paths = config.load_paths.uniq
+      ActiveSupport::Dependencies.load_once_paths = config.load_once_paths.uniq
+
+      extra = ActiveSupport::Dependencies.load_once_paths - ActiveSupport::Dependencies.load_paths
+      unless extra.empty?
+        abort &lt;&lt;-end_error
+          load_once_paths must be a subset of the load_paths.
+          Extra items in load_once_paths: #{extra * ','}
+        end_error
+      end
+
+      # Freeze the arrays so future modifications will fail rather than do nothing mysteriously
+      config.load_once_paths.freeze
+    end
+
+    # Adds all load paths from plugins to the global set of load paths, so that
+    # code from plugins can be required (explicitly or automatically via ActiveSupport::Dependencies).
+    initializer :add_plugin_load_paths do
+      require 'active_support/dependencies'
+      plugin_loader.add_plugin_load_paths
+    end
+
+    # Create tmp directories
+    initializer :ensure_tmp_directories_exist do
+      %w(cache pids sessions sockets).each do |dir_to_make|
+        FileUtils.mkdir_p(File.join(config.root_path, 'tmp', dir_to_make))
+      end
+    end
+
+    # Loads the environment specified by Configuration#environment_path, which
+    # is typically one of development, test, or production.
+    initializer :load_environment do
+      silence_warnings do
+        next if @environment_loaded
+        next unless File.file?(config.environment_path)
+
+        @environment_loaded = true
+        constants = self.class.constants
+
+        eval(IO.read(config.environment_path), binding, config.environment_path)
+
+        (self.class.constants - constants).each do |const|
+          Object.const_set(const, self.class.const_get(const))
+        end
+      end
+    end
+
+    initializer :add_gem_load_paths do
+      require 'rails/gem_dependency'
+      Rails::GemDependency.add_frozen_gem_path
+      unless config.gems.empty?
+        require &quot;rubygems&quot;
+        config.gems.each { |gem| gem.add_load_paths }
+      end
+    end
+
+    # Preload all frameworks specified by the Configuration#frameworks.
+    # Used by Passenger to ensure everything's loaded before forking and
+    # to avoid autoload race conditions in JRuby.
+    initializer :preload_frameworks do
+      if config.preload_frameworks
+        config.frameworks.each do |framework|
+          # String#classify and #constantize aren't available yet.
+          toplevel = Object.const_get(framework.to_s.gsub(/(?:^|_)(.)/) { $1.upcase })
+          toplevel.load_all! if toplevel.respond_to?(:load_all!)
+        end
+      end
+    end
+
+    # This initialization routine does nothing unless &lt;tt&gt;:active_record&lt;/tt&gt;
+    # is one of the frameworks to load (Configuration#frameworks). If it is,
+    # this sets the database configuration from Configuration#database_configuration
+    # and then establishes the connection.
+    initializer :initialize_database do
+      if config.frameworks.include?(:active_record)
+        ActiveRecord::Base.configurations = config.database_configuration
+        ActiveRecord::Base.establish_connection
+      end
+    end
+
+    # Include middleware to serve up static assets
+    initializer :initialize_static_server do
+      if config.frameworks.include?(:action_controller) &amp;&amp; config.serve_static_assets
+        config.middleware.use(ActionDispatch::Static, Rails.public_path)
+      end
+    end
+
+    initializer :initialize_middleware_stack do
+      if config.frameworks.include?(:action_controller)
+        config.middleware.use(::Rack::Lock) unless ActionController::Base.allow_concurrency
+        config.middleware.use(ActionDispatch::ShowExceptions, ActionController::Base.consider_all_requests_local)
+        config.middleware.use(ActionDispatch::Callbacks, ActionController::Dispatcher.prepare_each_request)
+        config.middleware.use(lambda { ActionController::Base.session_store }, lambda { ActionController::Base.session_options })
+        config.middleware.use(ActionDispatch::ParamsParser)
+        config.middleware.use(::Rack::MethodOverride)
+        config.middleware.use(::Rack::Head)
+        config.middleware.use(ActionDispatch::StringCoercion)
+      end
+    end
+
+    initializer :initialize_cache do
+      unless defined?(RAILS_CACHE)
+        silence_warnings { Object.const_set &quot;RAILS_CACHE&quot;, ActiveSupport::Cache.lookup_store(config.cache_store) }
+
+        if RAILS_CACHE.respond_to?(:middleware)
+          # Insert middleware to setup and teardown local cache for each request
+          config.middleware.insert_after(:&quot;Rack::Lock&quot;, RAILS_CACHE.middleware)
+        end
+      end
+    end
+
+    initializer :initialize_framework_caches do
+      if config.frameworks.include?(:action_controller)
+        ActionController::Base.cache_store ||= RAILS_CACHE
+      end
+    end
+
+    initializer :initialize_logger do
+      # if the environment has explicitly defined a logger, use it
+      next if Rails.logger
+
+      unless logger = config.logger
+        begin
+          logger = ActiveSupport::BufferedLogger.new(config.log_path)
+          logger.level = ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase)
+          if RAILS_ENV == &quot;production&quot;
+            logger.auto_flushing = false
+          end
+        rescue StandardError =&gt; e
+          logger = ActiveSupport::BufferedLogger.new(STDERR)
+          logger.level = ActiveSupport::BufferedLogger::WARN
+          logger.warn(
+            &quot;Rails Error: Unable to access log file. Please ensure that #{config.log_path} exists and is chmod 0666. &quot; +
+            &quot;The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.&quot;
+          )
+        end
+      end
+
+      # TODO: Why are we silencing warning here?
+      silence_warnings { Object.const_set &quot;RAILS_DEFAULT_LOGGER&quot;, logger }
+    end
+
+    # Sets the logger for Active Record, Action Controller, and Action Mailer
+    # (but only for those frameworks that are to be loaded). If the framework's
+    # logger is already set, it is not changed, otherwise it is set to use
+    # RAILS_DEFAULT_LOGGER.
+    initializer :initialize_framework_logging do
+      for framework in ([ :active_record, :action_controller, :action_mailer ] &amp; config.frameworks)
+        framework.to_s.camelize.constantize.const_get(&quot;Base&quot;).logger ||= Rails.logger
+      end
+
+      ActiveSupport::Dependencies.logger ||= Rails.logger
+      Rails.cache.logger ||= Rails.logger
+    end
+
+    # Sets the dependency loading mechanism based on the value of
+    # Configuration#cache_classes.
+    initializer :initialize_dependency_mechanism do
+      # TODO: Remove files from the $&quot; and always use require
+      ActiveSupport::Dependencies.mechanism = config.cache_classes ? :require : :load
+    end
+
+    # Loads support for &quot;whiny nil&quot; (noisy warnings when methods are invoked
+    # on +nil+ values) if Configuration#whiny_nils is true.
+    initializer :initialize_whiny_nils do
+      require('active_support/whiny_nil') if config.whiny_nils
+    end
+
+    # Sets the default value for Time.zone, and turns on ActiveRecord::Base#time_zone_aware_attributes.
+    # If assigned value cannot be matched to a TimeZone, an exception will be raised.
+    initializer :initialize_time_zone do
+      if config.time_zone
+        zone_default = Time.__send__(:get_zone, config.time_zone)
+
+        unless zone_default
+          raise \
+            'Value assigned to config.time_zone not recognized.' +
+            'Run &quot;rake -D time&quot; for a list of tasks for finding appropriate time zone names.'
+        end
+
+        Time.zone_default = zone_default
+
+        if config.frameworks.include?(:active_record)
+          ActiveRecord::Base.time_zone_aware_attributes = true
+          ActiveRecord::Base.default_timezone = :utc
+        end
+      end
+    end
+
+    # Set the i18n configuration from config.i18n but special-case for the load_path which should be
+    # appended to what's already set instead of overwritten.
+    initializer :initialize_i18n do
+      config.i18n.each do |setting, value|
+        if setting == :load_path
+          I18n.load_path += value
+        else
+          I18n.send(&quot;#{setting}=&quot;, value)
+        end
+      end
+    end
+
+    # Initializes framework-specific settings for each of the loaded frameworks
+    # (Configuration#frameworks). The available settings map to the accessors
+    # on each of the corresponding Base classes.
+    initializer :initialize_framework_settings do
+      config.frameworks.each do |framework|
+        base_class = framework.to_s.camelize.constantize.const_get(&quot;Base&quot;)
+
+        config.send(framework).each do |setting, value|
+          base_class.send(&quot;#{setting}=&quot;, value)
+        end
+      end
+      config.active_support.each do |setting, value|
+        ActiveSupport.send(&quot;#{setting}=&quot;, value)
+      end
     end
 
-    def self.config=(config)
-      @config = config
+    # Sets +ActionController::Base#view_paths+ and +ActionMailer::Base#template_root+
+    # (but only for those frameworks that are to be loaded). If the framework's
+    # paths have already been set, it is not changed, otherwise it is
+    # set to use Configuration#view_path.
+    initializer :initialize_framework_views do
+      if config.frameworks.include?(:action_view)
+        view_path = ActionView::PathSet.type_cast(config.view_path, config.cache_classes)
+        ActionMailer::Base.template_root  = view_path if config.frameworks.include?(:action_mailer) &amp;&amp; ActionMailer::Base.view_paths.blank?
+        ActionController::Base.view_paths = view_path if config.frameworks.include?(:action_controller) &amp;&amp; ActionController::Base.view_paths.blank?
+      end
     end
 
-    def config
-      self.class.config
+    initializer :initialize_metal do
+      # TODO: Make Rails and metal work without ActionController
+      if config.frameworks.include?(:action_controller)
+        Rails::Rack::Metal.requested_metals = config.metals
+        Rails::Rack::Metal.metal_paths += plugin_loader.engine_metal_paths
+
+        config.middleware.insert_before(
+          :&quot;ActionDispatch::ParamsParser&quot;,
+          Rails::Rack::Metal, :if =&gt; Rails::Rack::Metal.metals.any?)
+      end
+    end
+
+    initializer :check_for_unbuilt_gems do
+      unbuilt_gems = config.gems.select {|gem| gem.frozen? &amp;&amp; !gem.built? }
+      if unbuilt_gems.size &gt; 0
+        # don't print if the gems:build rake tasks are being run
+        unless $gems_build_rake_task
+          abort &lt;&lt;-end_error
+  The following gems have native components that need to be built
+  #{unbuilt_gems.map { |gemm| &quot;#{gemm.name}  #{gemm.requirement}&quot; } * &quot;\n  &quot;}
+
+  You're running:
+  ruby #{Gem.ruby_version} at #{Gem.ruby}
+  rubygems #{Gem::RubyGemsVersion} at #{Gem.path * ', '}
+
+  Run `rake gems:build` to build the unbuilt gems.
+          end_error
+        end
+      end
     end
 
-    def routes
-      ActionController::Routing::Routes
+    initializer :load_gems do
+      unless $gems_rake_task
+        config.gems.each { |gem| gem.load }
+      end
+    end
+
+    # Loads all plugins in &lt;tt&gt;config.plugin_paths&lt;/tt&gt;.  &lt;tt&gt;plugin_paths&lt;/tt&gt;
+    # defaults to &lt;tt&gt;vendor/plugins&lt;/tt&gt; but may also be set to a list of
+    # paths, such as
+    #   config.plugin_paths = [&quot;#{RAILS_ROOT}/lib/plugins&quot;, &quot;#{RAILS_ROOT}/vendor/plugins&quot;]
+    #
+    # In the default implementation, as each plugin discovered in &lt;tt&gt;plugin_paths&lt;/tt&gt; is initialized:
+    # * its +lib+ directory, if present, is added to the load path (immediately after the applications lib directory)
+    # * &lt;tt&gt;init.rb&lt;/tt&gt; is evaluated, if present
+    #
+    # After all plugins are loaded, duplicates are removed from the load path.
+    # If an array of plugin names is specified in config.plugins, only those plugins will be loaded
+    # and they plugins will be loaded in that order. Otherwise, plugins are loaded in alphabetical
+    # order.
+    #
+    # if config.plugins ends contains :all then the named plugins will be loaded in the given order and all other
+    # plugins will be loaded in alphabetical order
+    initializer :load_plugins do
+      plugin_loader.load_plugins
+    end
+
+    # TODO: Figure out if this needs to run a second time
+    # load_gems
+
+    initializer :check_gem_dependencies do
+      unloaded_gems = config.gems.reject { |g| g.loaded? }
+      if unloaded_gems.size &gt; 0
+        configuration.gems_dependencies_loaded = false
+        # don't print if the gems rake tasks are being run
+        unless $gems_rake_task
+          abort &lt;&lt;-end_error
+  Missing these required gems:
+  #{unloaded_gems.map { |gemm| &quot;#{gemm.name}  #{gemm.requirement}&quot; } * &quot;\n  &quot;}
+
+  You're running:
+  ruby #{Gem.ruby_version} at #{Gem.ruby}
+  rubygems #{Gem::RubyGemsVersion} at #{Gem.path * ', '}
+
+  Run `rake gems:install` to install the missing gems.
+          end_error
+        end
+      else
+        configuration.gems_dependencies_loaded = true
+      end
+    end
+
+    # # bail out if gems are missing - note that check_gem_dependencies will have
+    # # already called abort() unless $gems_rake_task is set
+    # return unless gems_dependencies_loaded
+
+    initializer :load_application_initializers do
+      if config.gems_dependencies_loaded
+        Dir[&quot;#{configuration.root_path}/config/initializers/**/*.rb&quot;].sort.each do |initializer|
+          load(initializer)
+        end
+      end
+    end
+
+    # Fires the user-supplied after_initialize block (Configuration#after_initialize)
+    initializer :after_initialize do
+      if config.gems_dependencies_loaded
+        configuration.after_initialize_blocks.each do |block|
+          block.call
+        end
+      end
+    end
+
+    # # Setup database middleware after initializers have run
+    initializer :initialize_database_middleware do
+      if configuration.frameworks.include?(:active_record)
+        if configuration.frameworks.include?(:action_controller) &amp;&amp; ActionController::Base.session_store &amp;&amp;
+            ActionController::Base.session_store.name == 'ActiveRecord::SessionStore'
+          configuration.middleware.insert_before :&quot;ActiveRecord::SessionStore&quot;, ActiveRecord::ConnectionAdapters::ConnectionManagement
+          configuration.middleware.insert_before :&quot;ActiveRecord::SessionStore&quot;, ActiveRecord::QueryCache
+        else
+          configuration.middleware.use ActiveRecord::ConnectionAdapters::ConnectionManagement
+          configuration.middleware.use ActiveRecord::QueryCache
+        end
+      end
+    end
+
+    # TODO: Make a DSL way to limit an initializer to a particular framework
+
+    # # Prepare dispatcher callbacks and run 'prepare' callbacks
+    initializer :prepare_dispatcher do
+      next unless configuration.frameworks.include?(:action_controller)
+      require 'rails/dispatcher' unless defined?(::Dispatcher)
+      Dispatcher.define_dispatcher_callbacks(configuration.cache_classes)
+    end
+
+    # Routing must be initialized after plugins to allow the former to extend the routes
+    # ---
+    # If Action Controller is not one of the loaded frameworks (Configuration#frameworks)
+    # this does nothing. Otherwise, it loads the routing definitions and sets up
+    # loading module used to lazily load controllers (Configuration#controller_paths).
+    initializer :initialize_routing do
+      next unless configuration.frameworks.include?(:action_controller)
+
+      ActionController::Routing.controller_paths += configuration.controller_paths
+      ActionController::Routing::Routes.add_configuration_file(configuration.routes_configuration_file)
+      ActionController::Routing::Routes.reload!
+    end
+    #
+    # # Observers are loaded after plugins in case Observers or observed models are modified by plugins.
+    initializer :load_observers do
+      if config.gems_dependencies_loaded &amp;&amp; configuration.frameworks.include?(:active_record)
+        ActiveRecord::Base.instantiate_observers
+      end
+    end
+
+    # Eager load application classes
+    initializer :load_application_classes do
+      next if $rails_rake_task
+
+      if configuration.cache_classes
+        configuration.eager_load_paths.each do |load_path|
+          matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/
+          Dir.glob(&quot;#{load_path}/**/*.rb&quot;).sort.each do |file|
+            require_dependency file.sub(matcher, '\1')
+          end
+        end
+      end
     end
 
-    def middleware
-      config.middleware
+    # Disable dependency loading during request cycle
+    initializer :disable_dependency_loading do
+      if configuration.cache_classes &amp;&amp; !configuration.dependency_loading
+        ActiveSupport::Dependencies.unhook!
+      end
     end
 
-    def call(env)
-      @app ||= middleware.build(routes)
-      @app.call(env)
+    # Configure generators if they were already loaded
+    # ===
+    # TODO: Does this need to be an initializer here?
+    initializer :initialize_generators do
+      if defined?(Rails::Generators)
+        Rails::Generators.no_color! unless config.generators.colorize_logging
+        Rails::Generators.aliases.deep_merge! config.generators.aliases
+        Rails::Generators.options.deep_merge! config.generators.options
+      end
     end
   end
 end</diff>
      <filename>railties/lib/rails/application.rb</filename>
    </modified>
    <modified>
      <diff>@@ -15,11 +15,7 @@ module Rails
 
     # The Configuration instance used to configure the Rails environment
     def configuration
-      @@configuration
-    end
-
-    def configuration=(configuration)
-      @@configuration = configuration
+      application.configuration
     end
 
     def initialized?</diff>
      <filename>railties/lib/rails/core.rb</filename>
    </modified>
    <modified>
      <diff>@@ -13,7 +13,7 @@
 &lt;%% @&lt;%= plural_name %&gt;.each do |&lt;%= singular_name %&gt;| %&gt;
   &lt;tr&gt;
 &lt;% for attribute in attributes -%&gt;
-    &lt;td&gt;&lt;%%=h &lt;%= singular_name %&gt;.&lt;%= attribute.name %&gt; %&gt;&lt;/td&gt;
+    &lt;td&gt;&lt;%%= &lt;%= singular_name %&gt;.&lt;%= attribute.name %&gt; %&gt;&lt;/td&gt;
 &lt;% end -%&gt;
     &lt;td&gt;&lt;%%= link_to 'Show', &lt;%= singular_name %&gt; %&gt;&lt;/td&gt;
     &lt;td&gt;&lt;%%= link_to 'Edit', edit_&lt;%= singular_name %&gt;_path(&lt;%= singular_name %&gt;) %&gt;&lt;/td&gt;</diff>
      <filename>railties/lib/rails/generators/erb/scaffold/templates/index.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,7 @@
 &lt;% for attribute in attributes -%&gt;
 &lt;p&gt;
   &lt;b&gt;&lt;%= attribute.human_name %&gt;:&lt;/b&gt;
-  &lt;%%=h @&lt;%= singular_name %&gt;.&lt;%= attribute.name %&gt; %&gt;
+  &lt;%%= @&lt;%= singular_name %&gt;.&lt;%= attribute.name %&gt; %&gt;
 &lt;/p&gt;
 
 &lt;% end -%&gt;</diff>
      <filename>railties/lib/rails/generators/erb/scaffold/templates/show.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -18,9 +18,6 @@ module Rails::Generators
     class_option :template, :type =&gt; :string, :aliases =&gt; &quot;-m&quot;,
                             :desc =&gt; &quot;Path to an application template (can be a filesystem path or URL).&quot;
 
-    class_option :with_dispatchers, :type =&gt; :boolean, :aliases =&gt; &quot;-D&quot;, :default =&gt; false,
-                                    :desc =&gt; &quot;Add CGI/FastCGI/mod_ruby dispatchers code&quot;
-
     class_option :skip_activerecord, :type =&gt; :boolean, :aliases =&gt; &quot;-O&quot;, :default =&gt; false,
                                    :desc =&gt; &quot;Skip ActiveRecord files&quot;
 
@@ -113,19 +110,6 @@ module Rails::Generators
       directory &quot;public&quot;, &quot;public&quot;, :recursive =&gt; false # Do small steps, so anyone can overwrite it.
     end
 
-    def create_dispatch_files
-      return unless options[:with_dispatchers]
-
-      template &quot;dispatchers/dispatch.rb&quot;, &quot;public/dispatch.rb&quot;
-      chmod &quot;public/dispatch.rb&quot;, 0755, :verbose =&gt; false
-
-      template &quot;dispatchers/dispatch.rb&quot;, &quot;public/dispatch.cgi&quot;
-      chmod &quot;public/dispatch.cgi&quot;, 0755, :verbose =&gt; false
-
-      template &quot;dispatchers/dispatch.fcgi&quot;, &quot;public/dispatch.fcgi&quot;
-      chmod &quot;public/dispatch.fcgi&quot;, 0755, :verbose =&gt; false
-    end
-
     def create_public_image_files
       directory &quot;public/images&quot;
     end</diff>
      <filename>railties/lib/rails/generators/rails/app/app_generator.rb</filename>
    </modified>
    <modified>
      <diff>@@ -40,20 +40,20 @@ module Rails
 
   class Boot
     def run
-      load_initializer
       set_load_paths
+      load_initializer
     end
 
     def set_load_paths
       %w(
-        railties
-        railties/lib
-        activesupport/lib
+        actionmailer/lib
         actionpack/lib
+        activemodel/lib
         activerecord/lib
-        actionmailer/lib
         activeresource/lib
-        actionwebservice/lib
+        activesupport/lib
+        railties/lib
+        railties
       ).reverse_each do |path|
         path = &quot;#{framework_root_path}/#{path}&quot;
         $LOAD_PATH.unshift(path) if File.directory?(path)
@@ -68,7 +68,6 @@ module Rails
 
   class VendorBoot &lt; Boot
     def load_initializer
-      $:.unshift(&quot;#{framework_root_path}/railties/lib&quot;)
       require &quot;rails&quot;
       install_gem_spec_stubs
       Rails::GemDependency.add_frozen_gem_path</diff>
      <filename>railties/lib/rails/generators/rails/app/templates/config/boot.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,6 @@
 require &quot;pathname&quot;
 
+require 'rails/initializable'
 require 'rails/application'
 require 'rails/railties_path'
 require 'rails/version'
@@ -12,571 +13,16 @@ require 'rails/configuration'
 RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
 
 module Rails
-  # Sanity check to make sure this file is only loaded once
-  # TODO: Get to the point where this can be removed.
-  raise &quot;It looks like initializer.rb was required twice&quot; if defined?(Initializer)
-
   class Initializer
     class Error &lt; StandardError ; end
-
-    class Base
-      class &lt;&lt; self
-        def run(&amp;blk)
-          define_method(:run, &amp;blk)
-        end
-
-        def config=(config)
-          @@config = config
-        end
-
-        def config
-          @@config || Configuration.new
-        end
-        alias configuration config
-
-        def gems_dependencies_loaded
-          config.gems_dependencies_loaded
-        end
-
-        def plugin_loader
-          @plugin_loader ||= configuration.plugin_loader.new(self)
-        end
-      end
-
-      def gems_dependencies_loaded
-        self.class.gems_dependencies_loaded
-      end
-
-      def plugin_loader
-        self.class.plugin_loader
-      end
-    end
-
-    class Runner
-
-      attr_reader :names, :initializers
-      attr_accessor :config
-      alias configuration config
-
-      def initialize(parent = nil)
-        @names        = parent ? parent.names.dup        : {}
-        @initializers = parent ? parent.initializers.dup : []
-      end
-
-      def add(name, options = {}, &amp;block)
-        # If :before or :after is specified, set the index to the right spot
-        if other = options[:before] || options[:after]
-          raise Error, &quot;The #{other.inspect} initializer does not exist&quot; unless @names[other]
-          index = @initializers.index(@names[other])
-          index += 1 if options[:after]
-        end
-
-        @initializers.insert(index || -1, block)
-        @names[name] = block
-      end
-
-      def delete(name)
-        @names[name].tap do |initializer|
-          @initializers.delete(initializer)
-          @names.delete(name)
-        end
-      end
-
-      def run_initializer(initializer)
-        init_block = initializer.is_a?(Proc) ? initializer : @names[initializer]
-        container = Class.new(Base, &amp;init_block).new
-        container.run if container.respond_to?(:run)
-      end
-
-      def run(initializer = nil)
-        Rails.configuration = Base.config = @config
-
-        if initializer
-          run_initializer(initializer)
-        else
-          @initializers.each {|block| run_initializer(block) }
-        end
-      end
-    end
-
-    def self.default
-      @default ||= Runner.new
-    end
-
     def self.run(initializer = nil, config = nil)
-      # TODO: Clean this all up
       if initializer
-        default.config = config
-        default.run(initializer)
+        # Deprecated
       else
         Rails.application = Class.new(Application)
         yield Rails.application.config if block_given?
-        default.config = Rails.application.config
-        default.run
-      end
-    end
-  end
-
-  # Check for valid Ruby version (1.8.2 or 1.8.4 or higher). This is done in an
-  # external file, so we can use it from the `rails` program as well without duplication.
-  Initializer.default.add :check_ruby_version do
-    require 'rails/ruby_version_check'
-  end
-
-  # Bail if boot.rb is outdated
-  Initializer.default.add :freak_out_if_boot_rb_is_outdated do
-    unless defined?(Rails::BOOTSTRAP_VERSION)
-      abort %{Your config/boot.rb is outdated: Run &quot;rake rails:update&quot;.}
-    end
-  end
-
-  # Set the &lt;tt&gt;$LOAD_PATH&lt;/tt&gt; based on the value of
-  # Configuration#load_paths. Duplicates are removed.
-  Initializer.default.add :set_load_path do
-    configuration.paths.add_to_load_path
-    $LOAD_PATH.uniq!
-  end
-
-  # Requires all frameworks specified by the Configuration#frameworks
-  # list. By default, all frameworks (Active Record, Active Support,
-  # Action Pack, Action Mailer, and Active Resource) are loaded.
-  Initializer.default.add :require_frameworks do
-    begin
-      require 'active_support'
-      require 'active_support/core_ext/kernel/reporting'
-      require 'active_support/core_ext/logger'
-
-      # TODO: This is here to make Sam Ruby's tests pass. Needs discussion.
-      require 'active_support/core_ext/numeric/bytes'
-      configuration.frameworks.each { |framework| require(framework.to_s) }
-    rescue LoadError =&gt; e
-      # Re-raise as RuntimeError because Mongrel would swallow LoadError.
-      raise e.to_s
-    end
-  end
-
-  # Set the paths from which Rails will automatically load source files, and
-  # the load_once paths.
-  Initializer.default.add :set_autoload_paths do
-    require 'active_support/dependencies'
-    ActiveSupport::Dependencies.load_paths = configuration.load_paths.uniq
-    ActiveSupport::Dependencies.load_once_paths = configuration.load_once_paths.uniq
-
-    extra = ActiveSupport::Dependencies.load_once_paths - ActiveSupport::Dependencies.load_paths
-    unless extra.empty?
-      abort &lt;&lt;-end_error
-        load_once_paths must be a subset of the load_paths.
-        Extra items in load_once_paths: #{extra * ','}
-      end_error
-    end
-
-    # Freeze the arrays so future modifications will fail rather than do nothing mysteriously
-    configuration.load_once_paths.freeze
-  end
-
-  # Adds all load paths from plugins to the global set of load paths, so that
-  # code from plugins can be required (explicitly or automatically via ActiveSupport::Dependencies).
-  Initializer.default.add :add_plugin_load_paths do
-    require 'active_support/dependencies'
-    plugin_loader.add_plugin_load_paths
-  end
-
-  # Create tmp directories
-  Initializer.default.add :ensure_tmp_directories_exist do
-    %w(cache pids sessions sockets).each do |dir_to_make|
-      FileUtils.mkdir_p(File.join(configuration.root_path, 'tmp', dir_to_make))
-    end
-  end
-
-  # Loads the environment specified by Configuration#environment_path, which
-  # is typically one of development, test, or production.
-  Initializer.default.add :load_environment do
-    silence_warnings do
-      next if @environment_loaded
-      next unless File.file?(configuration.environment_path)
-
-      @environment_loaded = true
-
-      config = configuration
-      constants = self.class.constants
-
-      eval(IO.read(configuration.environment_path), binding, configuration.environment_path)
-
-      (self.class.constants - constants).each do |const|
-        Object.const_set(const, self.class.const_get(const))
-      end
-    end
-  end
-
-  Initializer.default.add :add_gem_load_paths do
-    require 'rails/gem_dependency'
-    Rails::GemDependency.add_frozen_gem_path
-    unless config.gems.empty?
-      require &quot;rubygems&quot;
-      config.gems.each { |gem| gem.add_load_paths }
-    end
-  end
-
-  # Preload all frameworks specified by the Configuration#frameworks.
-  # Used by Passenger to ensure everything's loaded before forking and
-  # to avoid autoload race conditions in JRuby.
-  Initializer.default.add :preload_frameworks do
-    if configuration.preload_frameworks
-      configuration.frameworks.each do |framework|
-        # String#classify and #constantize aren't available yet.
-        toplevel = Object.const_get(framework.to_s.gsub(/(?:^|_)(.)/) { $1.upcase })
-        toplevel.load_all! if toplevel.respond_to?(:load_all!)
-      end
-    end
-  end
-
-  # For Ruby 1.8, this initialization sets $KCODE to 'u' to enable the
-  # multibyte safe operations. Plugin authors supporting other encodings
-  # should override this behaviour and set the relevant +default_charset+
-  # on ActionController::Base.
-  #
-  # For Ruby 1.9, UTF-8 is the default internal and external encoding.
-  Initializer.default.add :initialize_encoding do
-    if RUBY_VERSION &lt; '1.9'
-      $KCODE='u'
-    else
-      Encoding.default_external = Encoding::UTF_8
-    end
-  end
-
-  # This initialization routine does nothing unless &lt;tt&gt;:active_record&lt;/tt&gt;
-  # is one of the frameworks to load (Configuration#frameworks). If it is,
-  # this sets the database configuration from Configuration#database_configuration
-  # and then establishes the connection.
-  Initializer.default.add :initialize_database do
-    if configuration.frameworks.include?(:active_record)
-      ActiveRecord::Base.configurations = configuration.database_configuration
-      ActiveRecord::Base.establish_connection
-    end
-  end
-
-  # Include middleware to serve up static assets
-  Initializer.default.add :initialize_static_server do
-    if configuration.frameworks.include?(:action_controller) &amp;&amp; configuration.serve_static_assets
-      configuration.middleware.use(ActionDispatch::Static, Rails.public_path)
-    end
-  end
-
-  Initializer.default.add :initialize_middleware_stack do
-    if configuration.frameworks.include?(:action_controller)
-      configuration.middleware.use(::Rack::Lock) unless ActionController::Base.allow_concurrency
-      configuration.middleware.use(ActionDispatch::ShowExceptions, ActionController::Base.consider_all_requests_local)
-      configuration.middleware.use(ActionDispatch::Callbacks, ActionController::Dispatcher.prepare_each_request)
-      configuration.middleware.use(lambda { ActionController::Base.session_store }, lambda { ActionController::Base.session_options })
-      configuration.middleware.use(ActionDispatch::ParamsParser)
-      configuration.middleware.use(::Rack::MethodOverride)
-      configuration.middleware.use(::Rack::Head)
-    end
-  end
-
-  Initializer.default.add :initialize_cache do
-    unless defined?(RAILS_CACHE)
-      silence_warnings { Object.const_set &quot;RAILS_CACHE&quot;, ActiveSupport::Cache.lookup_store(configuration.cache_store) }
-
-      if RAILS_CACHE.respond_to?(:middleware)
-        # Insert middleware to setup and teardown local cache for each request
-        configuration.middleware.insert_after(:&quot;Rack::Lock&quot;, RAILS_CACHE.middleware)
-      end
-    end
-  end
-
-  Initializer.default.add :initialize_framework_caches do
-    if configuration.frameworks.include?(:action_controller)
-      ActionController::Base.cache_store ||= RAILS_CACHE
-    end
-  end
-
-  Initializer.default.add :initialize_logger do
-    # if the environment has explicitly defined a logger, use it
-    next if Rails.logger
-
-    unless logger = configuration.logger
-      begin
-        logger = ActiveSupport::BufferedLogger.new(configuration.log_path)
-        logger.level = ActiveSupport::BufferedLogger.const_get(configuration.log_level.to_s.upcase)
-        if RAILS_ENV == &quot;production&quot;
-          logger.auto_flushing = false
-        end
-      rescue StandardError =&gt; e
-        logger = ActiveSupport::BufferedLogger.new(STDERR)
-        logger.level = ActiveSupport::BufferedLogger::WARN
-        logger.warn(
-          &quot;Rails Error: Unable to access log file. Please ensure that #{configuration.log_path} exists and is chmod 0666. &quot; +
-          &quot;The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.&quot;
-        )
+        Rails.application.new
       end
     end
-
-    # TODO: Why are we silencing warning here?
-    silence_warnings { Object.const_set &quot;RAILS_DEFAULT_LOGGER&quot;, logger }
-  end
-
-  # Sets the logger for Active Record, Action Controller, and Action Mailer
-  # (but only for those frameworks that are to be loaded). If the framework's
-  # logger is already set, it is not changed, otherwise it is set to use
-  # RAILS_DEFAULT_LOGGER.
-  Initializer.default.add :initialize_framework_logging do
-    for framework in ([ :active_record, :action_controller, :action_mailer ] &amp; configuration.frameworks)
-      framework.to_s.camelize.constantize.const_get(&quot;Base&quot;).logger ||= Rails.logger
-    end
-
-    ActiveSupport::Dependencies.logger ||= Rails.logger
-    Rails.cache.logger ||= Rails.logger
-  end
-
-  # Sets the dependency loading mechanism based on the value of
-  # Configuration#cache_classes.
-  Initializer.default.add :initialize_dependency_mechanism do
-    # TODO: Remove files from the $&quot; and always use require
-    ActiveSupport::Dependencies.mechanism = configuration.cache_classes ? :require : :load
-  end
-
-  # Loads support for &quot;whiny nil&quot; (noisy warnings when methods are invoked
-  # on +nil+ values) if Configuration#whiny_nils is true.
-  Initializer.default.add :initialize_whiny_nils do
-    require('active_support/whiny_nil') if configuration.whiny_nils
-  end
-
-
-  # Sets the default value for Time.zone, and turns on ActiveRecord::Base#time_zone_aware_attributes.
-  # If assigned value cannot be matched to a TimeZone, an exception will be raised.
-  Initializer.default.add :initialize_time_zone do
-    if configuration.time_zone
-      zone_default = Time.__send__(:get_zone, configuration.time_zone)
-
-      unless zone_default
-        raise \
-          'Value assigned to config.time_zone not recognized.' +
-          'Run &quot;rake -D time&quot; for a list of tasks for finding appropriate time zone names.'
-      end
-
-      Time.zone_default = zone_default
-
-      if configuration.frameworks.include?(:active_record)
-        ActiveRecord::Base.time_zone_aware_attributes = true
-        ActiveRecord::Base.default_timezone = :utc
-      end
-    end
-  end
-
-  # Set the i18n configuration from config.i18n but special-case for the load_path which should be
-  # appended to what's already set instead of overwritten.
-  Initializer.default.add :initialize_i18n do
-    configuration.i18n.each do |setting, value|
-      if setting == :load_path
-        I18n.load_path += value
-      else
-        I18n.send(&quot;#{setting}=&quot;, value)
-      end
-    end
-  end
-
-  # Initializes framework-specific settings for each of the loaded frameworks
-  # (Configuration#frameworks). The available settings map to the accessors
-  # on each of the corresponding Base classes.
-  Initializer.default.add :initialize_framework_settings do
-    configuration.frameworks.each do |framework|
-      base_class = framework.to_s.camelize.constantize.const_get(&quot;Base&quot;)
-
-      configuration.send(framework).each do |setting, value|
-        base_class.send(&quot;#{setting}=&quot;, value)
-      end
-    end
-    configuration.active_support.each do |setting, value|
-      ActiveSupport.send(&quot;#{setting}=&quot;, value)
-    end
-  end
-
-  # Sets +ActionController::Base#view_paths+ and +ActionMailer::Base#template_root+
-  # (but only for those frameworks that are to be loaded). If the framework's
-  # paths have already been set, it is not changed, otherwise it is
-  # set to use Configuration#view_path.
-  Initializer.default.add :initialize_framework_views do
-    if configuration.frameworks.include?(:action_view)
-      view_path = ActionView::PathSet.type_cast(configuration.view_path)
-      ActionMailer::Base.template_root  = view_path if configuration.frameworks.include?(:action_mailer) &amp;&amp; ActionMailer::Base.view_paths.blank?
-      ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller) &amp;&amp; ActionController::Base.view_paths.blank?
-    end
-  end
-
-  Initializer.default.add :initialize_metal do
-    # TODO: Make Rails and metal work without ActionController
-    if defined?(ActionController)
-      Rails::Rack::Metal.requested_metals = configuration.metals
-      Rails::Rack::Metal.metal_paths += plugin_loader.engine_metal_paths
-
-      configuration.middleware.insert_before(
-        :&quot;ActionDispatch::ParamsParser&quot;,
-        Rails::Rack::Metal, :if =&gt; Rails::Rack::Metal.metals.any?)
-    end
-  end
-
-  Initializer.default.add :check_for_unbuilt_gems do
-    unbuilt_gems = config.gems.select {|gem| gem.frozen? &amp;&amp; !gem.built? }
-    if unbuilt_gems.size &gt; 0
-      # don't print if the gems:build rake tasks are being run
-      unless $gems_build_rake_task
-        abort &lt;&lt;-end_error
-The following gems have native components that need to be built
-#{unbuilt_gems.map { |gemm| &quot;#{gemm.name}  #{gemm.requirement}&quot; } * &quot;\n  &quot;}
-
-You're running:
-ruby #{Gem.ruby_version} at #{Gem.ruby}
-rubygems #{Gem::RubyGemsVersion} at #{Gem.path * ', '}
-
-Run `rake gems:build` to build the unbuilt gems.
-        end_error
-      end
-    end
-  end
-
-  Initializer.default.add :load_gems do
-    unless $gems_rake_task
-      config.gems.each { |gem| gem.load }
-    end
-  end
-
-  # Loads all plugins in &lt;tt&gt;config.plugin_paths&lt;/tt&gt;.  &lt;tt&gt;plugin_paths&lt;/tt&gt;
-  # defaults to &lt;tt&gt;vendor/plugins&lt;/tt&gt; but may also be set to a list of
-  # paths, such as
-  #   config.plugin_paths = [&quot;#{RAILS_ROOT}/lib/plugins&quot;, &quot;#{RAILS_ROOT}/vendor/plugins&quot;]
-  #
-  # In the default implementation, as each plugin discovered in &lt;tt&gt;plugin_paths&lt;/tt&gt; is initialized:
-  # * its +lib+ directory, if present, is added to the load path (immediately after the applications lib directory)
-  # * &lt;tt&gt;init.rb&lt;/tt&gt; is evaluated, if present
-  #
-  # After all plugins are loaded, duplicates are removed from the load path.
-  # If an array of plugin names is specified in config.plugins, only those plugins will be loaded
-  # and they plugins will be loaded in that order. Otherwise, plugins are loaded in alphabetical
-  # order.
-  #
-  # if config.plugins ends contains :all then the named plugins will be loaded in the given order and all other
-  # plugins will be loaded in alphabetical order
-  Initializer.default.add :load_plugins do
-    plugin_loader.load_plugins
-  end
-
-  # TODO: Figure out if this needs to run a second time
-  # load_gems
-
-  Initializer.default.add :check_gem_dependencies do
-    unloaded_gems = config.gems.reject { |g| g.loaded? }
-    if unloaded_gems.size &gt; 0
-      configuration.gems_dependencies_loaded = false
-      # don't print if the gems rake tasks are being run
-      unless $gems_rake_task
-        abort &lt;&lt;-end_error
-Missing these required gems:
-#{unloaded_gems.map { |gemm| &quot;#{gemm.name}  #{gemm.requirement}&quot; } * &quot;\n  &quot;}
-
-You're running:
-ruby #{Gem.ruby_version} at #{Gem.ruby}
-rubygems #{Gem::RubyGemsVersion} at #{Gem.path * ', '}
-
-Run `rake gems:install` to install the missing gems.
-        end_error
-      end
-    else
-      configuration.gems_dependencies_loaded = true
-    end
-  end
-
-  # # bail out if gems are missing - note that check_gem_dependencies will have
-  # # already called abort() unless $gems_rake_task is set
-  # return unless gems_dependencies_loaded
-
-  Initializer.default.add :load_application_initializers do
-    if gems_dependencies_loaded
-      Dir[&quot;#{configuration.root_path}/config/initializers/**/*.rb&quot;].sort.each do |initializer|
-        load(initializer)
-      end
-    end
-  end
-
-  # Fires the user-supplied after_initialize block (Configuration#after_initialize)
-  Initializer.default.add :after_initialize do
-    if gems_dependencies_loaded
-      configuration.after_initialize_blocks.each do |block|
-        block.call
-      end
-    end
-  end
-
-  # # Setup database middleware after initializers have run
-  Initializer.default.add :initialize_database_middleware do
-    if configuration.frameworks.include?(:active_record)
-      if configuration.frameworks.include?(:action_controller) &amp;&amp; ActionController::Base.session_store &amp;&amp;
-          ActionController::Base.session_store.name == 'ActiveRecord::SessionStore'
-        configuration.middleware.insert_before :&quot;ActiveRecord::SessionStore&quot;, ActiveRecord::ConnectionAdapters::ConnectionManagement
-        configuration.middleware.insert_before :&quot;ActiveRecord::SessionStore&quot;, ActiveRecord::QueryCache
-      else
-        configuration.middleware.use ActiveRecord::ConnectionAdapters::ConnectionManagement
-        configuration.middleware.use ActiveRecord::QueryCache
-      end
-    end
-  end
-
-  # TODO: Make a DSL way to limit an initializer to a particular framework
-
-  # # Prepare dispatcher callbacks and run 'prepare' callbacks
-  Initializer.default.add :prepare_dispatcher do
-    next unless configuration.frameworks.include?(:action_controller)
-    require 'rails/dispatcher' unless defined?(::Dispatcher)
-    Dispatcher.define_dispatcher_callbacks(configuration.cache_classes)
-  end
-
-  # Routing must be initialized after plugins to allow the former to extend the routes
-  # ---
-  # If Action Controller is not one of the loaded frameworks (Configuration#frameworks)
-  # this does nothing. Otherwise, it loads the routing definitions and sets up
-  # loading module used to lazily load controllers (Configuration#controller_paths).
-  Initializer.default.add :initialize_routing do
-    next unless configuration.frameworks.include?(:action_controller)
-
-    ActionController::Routing.controller_paths += configuration.controller_paths
-    ActionController::Routing::Routes.add_configuration_file(configuration.routes_configuration_file)
-    ActionController::Routing::Routes.reload!
-  end
-  #
-  # # Observers are loaded after plugins in case Observers or observed models are modified by plugins.
-  Initializer.default.add :load_observers do
-    if gems_dependencies_loaded &amp;&amp; configuration.frameworks.include?(:active_record)
-      ActiveRecord::Base.instantiate_observers
-    end
-  end
-
-  # Eager load application classes
-  Initializer.default.add :load_application_classes do
-    next if $rails_rake_task
-
-    if configuration.cache_classes
-      configuration.eager_load_paths.each do |load_path|
-        matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/
-        Dir.glob(&quot;#{load_path}/**/*.rb&quot;).sort.each do |file|
-          require_dependency file.sub(matcher, '\1')
-        end
-      end
-    end
-  end
-
-  # Disable dependency loading during request cycle
-  Initializer.default.add :disable_dependency_loading do
-    if configuration.cache_classes &amp;&amp; !configuration.dependency_loading
-      ActiveSupport::Dependencies.unhook!
-    end
-  end
-
-  # Configure generators if they were already loaded
-  Initializer.default.add :initialize_generators do
-    if defined?(Rails::Generators)
-      Rails::Generators.no_color! unless config.generators.colorize_logging
-      Rails::Generators.aliases.deep_merge! config.generators.aliases
-      Rails::Generators.options.deep_merge! config.generators.options
-    end
   end
 end</diff>
      <filename>railties/lib/rails/initializer.rb</filename>
    </modified>
    <modified>
      <diff>@@ -110,11 +110,6 @@ namespace :rails do
       invoke_from_app_generator :create_prototype_files
     end
 
-    desc &quot;Generate dispatcher files in RAILS_ROOT/public&quot;
-    task :generate_dispatchers do
-      invoke_from_app_generator :create_dispatch_files
-    end
-
     desc &quot;Add new scripts to the application script/ directory&quot;
     task :scripts do
       invoke_from_app_generator :create_script_files</diff>
      <filename>railties/lib/rails/tasks/framework.rake</filename>
    </modified>
    <modified>
      <diff>@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
   s.rdoc_options &lt;&lt; '--exclude' &lt;&lt; '.'
   s.has_rdoc = false
 
-  s.files = Dir['CHANGELOG', 'README', 'bin/**/*', 'builtin/**/*', 'guides/**/*', 'lib/**/*']
+  s.files = Dir['CHANGELOG', 'README', 'bin/**/*', 'builtin/**/*', 'guides/**/*', 'lib/**/{*,.[a-z]*}']
   s.require_path = 'lib'
   s.bindir = &quot;bin&quot;
   s.executables = [&quot;rails&quot;]</diff>
      <filename>railties/rails.gemspec</filename>
    </modified>
    <modified>
      <diff>@@ -25,11 +25,3 @@ if defined?(RAILS_ROOT)
 else
   RAILS_ROOT = File.dirname(__FILE__)
 end
-
-def uses_gem(gem_name, test_name, version = '&gt; 0')
-  gem gem_name.to_s, version
-  require gem_name.to_s
-  yield
-rescue LoadError
-  $stderr.puts &quot;Skipping #{test_name} tests. `gem install #{gem_name}` and try again.&quot;
-end</diff>
      <filename>railties/test/abstract_unit.rb</filename>
    </modified>
    <modified>
      <diff>@@ -40,7 +40,14 @@ module ApplicationTests
 
     test &quot;Rails.application is available after config.ru has been racked up&quot; do
       rackup
-      assert Rails.application.new.is_a?(Rails::Application)
+      assert Rails.application.new &lt; Rails::Application
+    end
+
+    # Passenger still uses AC::Dispatcher, so we need to
+    # keep it working for now
+    test &quot;deprecated ActionController::Dispatcher still works&quot; do
+      rackup
+      assert ActionController::Dispatcher.new &lt; Rails::Application
     end
 
     test &quot;the config object is available on the application object&quot; do</diff>
      <filename>railties/test/application/load_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -53,18 +53,6 @@ class AppGeneratorTest &lt; GeneratorsTestCase
     assert_match /Invalid value for \-\-database option/, content
   end
 
-  def test_dispatchers_are_not_added_by_default
-    run_generator
-    assert_no_file &quot;public/dispatch.cgi&quot;
-    assert_no_file &quot;public/dispatch.fcgi&quot;
-  end
-
-  def test_dispatchers_are_added_if_required
-    run_generator [&quot;--with-dispatchers&quot;]
-    assert_file &quot;public/dispatch.cgi&quot;
-    assert_file &quot;public/dispatch.fcgi&quot;
-  end
-
   def test_config_database_is_added_by_default
     run_generator
     assert_file &quot;config/database.yml&quot;, /sqlite3/</diff>
      <filename>railties/test/generators/app_generator_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -12,7 +12,7 @@ class PathsTest &lt; Test::Unit::TestCase
         ActionController::Base.session_store = nil
       end
     end
-    @paths = Rails::Initializer.default.config.paths
+    @paths = Rails.application.config.paths
   end
 
   def root(*path)</diff>
      <filename>railties/test/initializer/path_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,490 +6,8 @@ require 'action_view'
 require 'action_mailer'
 require 'active_record'
 
-# Mocks out the configuration
-module Rails
-  def self.configuration
-    Rails::Configuration.new
-  end
-
-  module Generators
-    def self.clear_aliases!
-      @aliases = nil
-    end
-
-    def self.clear_options!
-      @@options = nil
-    end
-  end
-end
-
-
-class ConfigurationMock &lt; Rails::Configuration
-  attr_reader :environment_path
-
-  def initialize(envpath)
-    super()
-    @environment_path = envpath
-  end
-end
-
-class Initializer_load_environment_Test &lt; Test::Unit::TestCase
-  def test_load_environment_with_constant
-    config = ConfigurationMock.new(&quot;#{File.dirname(__FILE__)}/fixtures/environment_with_constant.rb&quot;)
-    assert_nil $initialize_test_set_from_env
-    Rails::Initializer.run(:load_environment, config)
-    assert_equal &quot;success&quot;, $initialize_test_set_from_env
-  ensure
-    $initialize_test_set_from_env = nil
-  end
-end
-
-class Initializer_eager_loading_Test &lt; Test::Unit::TestCase
-  def setup
-    @config = ConfigurationMock.new(&quot;&quot;)
-    @config.cache_classes = true
-    @config.load_paths = [File.expand_path(File.dirname(__FILE__) + &quot;/fixtures/eager&quot;)]
-    @config.eager_load_paths = [File.expand_path(File.dirname(__FILE__) + &quot;/fixtures/eager&quot;)]
-    @initializer = Rails::Initializer.default
-    @initializer.config = @config
-    @initializer.run(:set_load_path)
-    @initializer.run(:set_autoload_paths)
-  end
-
-  def test_eager_loading_loads_parent_classes_before_children
-    assert_nothing_raised do
-      @initializer.run(:load_application_classes)
-    end
-  end
-end
-
-class Initializer_after_initialize_with_blocks_environment_Test &lt; Test::Unit::TestCase
-  def setup
-    config = ConfigurationMock.new(&quot;&quot;)
-    config.after_initialize do
-      $test_after_initialize_block1 = &quot;success&quot;
-    end
-    config.after_initialize do
-      $test_after_initialize_block2 = &quot;congratulations&quot;
-    end
-    assert_nil $test_after_initialize_block1
-    assert_nil $test_after_initialize_block2
-
-    config.expects(:gems_dependencies_loaded).returns(true)
-    Rails::Initializer.run(:after_initialize, config)
-  end
-
-  def teardown
-    $test_after_initialize_block1 = nil
-    $test_after_initialize_block2 = nil
-  end
-
-  def test_should_have_called_the_first_after_initialize_block
-    assert_equal &quot;success&quot;, $test_after_initialize_block1
-  end
-
-  def test_should_have_called_the_second_after_initialize_block
-    assert_equal &quot;congratulations&quot;, $test_after_initialize_block2
-  end
-end
-
-class Initializer_after_initialize_with_no_block_environment_Test &lt; Test::Unit::TestCase
-  def setup
-    config = ConfigurationMock.new(&quot;&quot;)
-    config.after_initialize do
-      $test_after_initialize_block1 = &quot;success&quot;
-    end
-    config.after_initialize # don't pass a block, this is what we're testing!
-    config.after_initialize do
-      $test_after_initialize_block2 = &quot;congratulations&quot;
-    end
-    assert_nil $test_after_initialize_block1
-
-    config.expects(:gems_dependencies_loaded).returns(true)
-    Rails::Initializer.run(:after_initialize, config)
-  end
-
-  def teardown
-    $test_after_initialize_block1 = nil
-    $test_after_initialize_block2 = nil
-  end
-
-  def test_should_have_called_the_first_after_initialize_block
-    assert_equal &quot;success&quot;, $test_after_initialize_block1, &quot;should still get set&quot;
-  end
-
-  def test_should_have_called_the_second_after_initialize_block
-    assert_equal &quot;congratulations&quot;, $test_after_initialize_block2
-  end
-end
-
-class ConfigurationFrameworkPathsTests &lt; Test::Unit::TestCase
-  def setup
-    @config = Rails::Configuration.new
-    @config.frameworks.clear
-    @initializer = Rails::Initializer.default
-    @initializer.config = @config
-
-    File.stubs(:directory?).returns(true)
-    Rails::Initializer.run(:set_root_path, @config)
-  end
-
-  def test_minimal
-    expected = %w(railties railties/lib activesupport/lib)
-    assert_equal expected.map {|e| &quot;#{@config.framework_root_path}/#{e}&quot;}, @config.framework_paths
-  end
-
-  def test_actioncontroller_or_actionview_add_actionpack
-    @config.frameworks &lt;&lt; :action_controller
-    assert_framework_path &quot;actionpack/lib&quot;
-
-    @config.frameworks = [:action_view]
-    assert_framework_path 'actionpack/lib'
-  end
-
-  def test_paths_for_ar_ares_and_mailer
-    [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework|
-      @config.frameworks = [framework]
-      assert_framework_path &quot;#{framework.to_s.gsub('_', '')}/lib&quot;
-    end
-  end
-
-  def test_unknown_framework_raises_error
-    @config.frameworks &lt;&lt; :action_foo
-
-    Class.any_instance.expects(:require).raises(LoadError)
-
-    assert_raise RuntimeError do
-      @initializer.run(:require_frameworks)
-    end
-  end
-
-  def test_action_mailer_load_paths_set_only_if_action_mailer_in_use
-    @config.frameworks = [:action_controller]
-    @initializer.config = @config
-    @initializer.run :require_frameworks
-
-    assert_nothing_raised NameError do
-      @initializer.run :load_view_paths
-    end
-  end
-
-  def test_action_controller_load_paths_set_only_if_action_controller_in_use
-    @config.frameworks = []
-    @initializer.run :require_frameworks
-
-    assert_nothing_raised NameError do
-      @initializer.run :load_view_paths
-    end
-  end
-
-  protected
-    def assert_framework_path(path)
-      assert @config.framework_paths.include?(&quot;#{@config.framework_root_path}/#{path}&quot;),
-        &quot;&lt;#{path.inspect}&gt; not found among &lt;#{@config.framework_paths.inspect}&gt;&quot;
-    end
-end
-
 require 'plugin_test_helper'
 
-class InitializerPluginLoadingTests &lt; Test::Unit::TestCase
-  def setup
-    @configuration     = Rails::Configuration.new
-    @configuration.frameworks -= [:action_mailer]
-    @configuration.plugin_paths &lt;&lt; plugin_fixture_root_path
-    @initializer       = Rails::Initializer.default
-    @initializer.config = @configuration
-    @valid_plugin_path = plugin_fixture_path('default/stubby')
-    @empty_plugin_path = plugin_fixture_path('default/empty')
-  end
-
-  def test_no_plugins_are_loaded_if_the_configuration_has_an_empty_plugin_list
-    only_load_the_following_plugins! []
-    @initializer.run :load_plugins
-    assert_equal [], @configuration.loaded_plugins
-  end
-
-  def test_only_the_specified_plugins_are_located_in_the_order_listed
-    plugin_names = [:plugin_with_no_lib_dir, :acts_as_chunky_bacon]
-    only_load_the_following_plugins! plugin_names
-    load_plugins!
-    assert_plugins plugin_names, @configuration.loaded_plugins
-  end
-
-  def test_all_plugins_are_loaded_when_registered_plugin_list_is_untouched
-    failure_tip = &quot;It's likely someone has added a new plugin fixture without updating this list&quot;
-    load_plugins!
-    assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @configuration.loaded_plugins, failure_tip
-  end
-
-  def test_all_plugins_loaded_when_all_is_used
-    plugin_names = [:stubby, :acts_as_chunky_bacon, :all]
-    only_load_the_following_plugins! plugin_names
-    load_plugins!
-    failure_tip = &quot;It's likely someone has added a new plugin fixture without updating this list&quot;
-    assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :engine, :gemlike, :plugin_with_no_lib_dir], @configuration.loaded_plugins, failure_tip
-  end
-
-  def test_all_plugins_loaded_after_all
-    plugin_names = [:stubby, :all, :acts_as_chunky_bacon]
-    only_load_the_following_plugins! plugin_names
-    load_plugins!
-    failure_tip = &quot;It's likely someone has added a new plugin fixture without updating this list&quot;
-    assert_plugins [:stubby, :a, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @configuration.loaded_plugins, failure_tip
-  end
-
-  def test_plugin_names_may_be_strings
-    plugin_names = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir]
-    only_load_the_following_plugins! plugin_names
-    load_plugins!
-    failure_tip = &quot;It's likely someone has added a new plugin fixture without updating this list&quot;
-    assert_plugins plugin_names, @configuration.loaded_plugins, failure_tip
-  end
-
-  def test_registering_a_plugin_name_that_does_not_exist_raises_a_load_error
-    only_load_the_following_plugins! [:stubby, :acts_as_a_non_existant_plugin]
-    assert_raise(LoadError) do
-      load_plugins!
-    end
-  end
-
-  def test_load_error_messages_mention_missing_plugins_and_no_others
-    valid_plugin_names = [:stubby, :acts_as_chunky_bacon]
-    invalid_plugin_names = [:non_existant_plugin1, :non_existant_plugin2]
-    only_load_the_following_plugins!( valid_plugin_names + invalid_plugin_names )
-    begin
-      load_plugins!
-      flunk &quot;Expected a LoadError but did not get one&quot;
-    rescue LoadError =&gt; e
-      failure_tip = &quot;It's likely someone renamed or deleted plugin fixtures without updating this test&quot;
-      assert_plugins valid_plugin_names, @configuration.loaded_plugins, failure_tip
-      invalid_plugin_names.each do |plugin|
-        assert_match(/#{plugin.to_s}/, e.message, &quot;LoadError message should mention plugin '#{plugin}'&quot;)
-      end
-      valid_plugin_names.each do |plugin|
-        assert_no_match(/#{plugin.to_s}/, e.message, &quot;LoadError message should not mention '#{plugin}'&quot;)
-      end
-
-    end
-  end
-
-  def test_should_ensure_all_loaded_plugins_load_paths_are_added_to_the_load_path
-    only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon]
-
-    @initializer.run(:add_plugin_load_paths)
-
-    assert $LOAD_PATH.include?(File.join(plugin_fixture_path('default/stubby'), 'lib'))
-    assert $LOAD_PATH.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib'))
-  end
-
-  private
-
-    def load_plugins!
-      @initializer.run(:add_plugin_load_paths)
-      @initializer.run(:load_plugins)
-    end
-end
-
-class InitializerGeneratorsTests &lt; Test::Unit::TestCase
-
-  def setup
-    @configuration = Rails::Configuration.new
-    @initializer   = Rails::Initializer.default
-    @initializer.config = @configuration
-  end
-
-  def test_generators_default_values
-    assert_equal(true, @configuration.generators.colorize_logging)
-    assert_equal({}, @configuration.generators.aliases)
-    assert_equal({}, @configuration.generators.options)
-  end
-
-  def test_generators_set_rails_options
-    @configuration.generators.orm = :datamapper
-    @configuration.generators.test_framework = :rspec
-    expected = { :rails =&gt; { :orm =&gt; :datamapper, :test_framework =&gt; :rspec } }
-    assert_equal expected, @configuration.generators.options
-  end
-
-  def test_generators_set_rails_aliases
-    @configuration.generators.aliases = { :rails =&gt; { :test_framework =&gt; &quot;-w&quot; } }
-    expected = { :rails =&gt; { :test_framework =&gt; &quot;-w&quot; } }
-    assert_equal expected, @configuration.generators.aliases
-  end
-
-  def test_generators_aliases_and_options_on_initialization
-    @configuration.generators.rails :aliases =&gt; { :test_framework =&gt; &quot;-w&quot; }
-    @configuration.generators.orm :datamapper
-    @configuration.generators.test_framework :rspec
-
-    @initializer.run(:initialize_generators)
-
-    assert_equal :rspec, Rails::Generators.options[:rails][:test_framework]
-    assert_equal &quot;-w&quot;, Rails::Generators.aliases[:rails][:test_framework]
-  end
-
-  def test_generators_no_color_on_initialization
-    @configuration.generators.colorize_logging = false
-    @initializer.run(:initialize_generators)
-    assert_equal Thor::Base.shell, Thor::Shell::Basic
-  end
-
-  def test_generators_with_hashes_for_options_and_aliases
-    @configuration.generators do |g|
-      g.orm    :datamapper, :migration =&gt; false
-      g.plugin :aliases =&gt; { :generator =&gt; &quot;-g&quot; },
-               :generator =&gt; true
-    end
-
-    expected = {
-      :rails =&gt; { :orm =&gt; :datamapper },
-      :plugin =&gt; { :generator =&gt; true },
-      :datamapper =&gt; { :migration =&gt; false }
-    }
-
-    assert_equal expected, @configuration.generators.options
-    assert_equal({ :plugin =&gt; { :generator =&gt; &quot;-g&quot; } }, @configuration.generators.aliases)
-  end
-
-  def test_generators_with_hashes_are_deep_merged
-    @configuration.generators do |g|
-      g.orm    :datamapper, :migration =&gt; false
-      g.plugin :aliases =&gt; { :generator =&gt; &quot;-g&quot; },
-               :generator =&gt; true
-    end
-    @initializer.run(:initialize_generators)
-
-    assert Rails::Generators.aliases.size &gt;= 1
-    assert Rails::Generators.options.size &gt;= 1
-  end
-
-  protected
-
-    def teardown
-      Rails::Generators.clear_aliases!
-      Rails::Generators.clear_options!
-    end
-end
-
-class InitializerSetupI18nTests &lt; Test::Unit::TestCase
-  def test_no_config_locales_dir_present_should_return_empty_load_path
-    File.stubs(:exist?).returns(false)
-    assert_equal [], Rails::Configuration.new.i18n.load_path
-  end
-
-  def test_config_locales_dir_present_should_be_added_to_load_path
-    File.stubs(:exist?).returns(true)
-    Dir.stubs(:[]).returns([ &quot;my/test/locale.yml&quot; ])
-    assert_equal [ &quot;my/test/locale.yml&quot; ], Rails::Configuration.new.i18n.load_path
-  end
-
-  def test_config_defaults_should_be_added_with_config_settings
-    File.stubs(:exist?).returns(true)
-    Dir.stubs(:[]).returns([ &quot;my/test/locale.yml&quot; ])
-
-    config = Rails::Configuration.new
-    config.i18n.load_path &lt;&lt; &quot;my/other/locale.yml&quot;
-
-    assert_equal [ &quot;my/test/locale.yml&quot;, &quot;my/other/locale.yml&quot; ], config.i18n.load_path
-  end
-
-  def test_config_defaults_and_settings_should_be_added_to_i18n_defaults
-    File.stubs(:exist?).returns(true)
-    Dir.stubs(:[]).returns([ &quot;my/test/locale.yml&quot; ])
-
-    config = Rails::Configuration.new
-    config.i18n.load_path &lt;&lt; &quot;my/other/locale.yml&quot;
-
-    Rails::Initializer.run(:initialize_i18n, config)
-    assert_equal [
-     File.expand_path(File.dirname(__FILE__) + &quot;/../../activesupport/lib/active_support/locale/en.yml&quot;),
-     File.expand_path(File.dirname(__FILE__) + &quot;/../../actionpack/lib/action_view/locale/en.yml&quot;),
-     File.expand_path(File.dirname(__FILE__) + &quot;/../../activemodel/lib/active_model/locale/en.yml&quot;),
-     File.expand_path(File.dirname(__FILE__) + &quot;/../../activerecord/lib/active_record/locale/en.yml&quot;),
-     File.expand_path(File.dirname(__FILE__) + &quot;/../../railties/test/fixtures/plugins/engines/engine/config/locales/en.yml&quot;),
-     &quot;my/test/locale.yml&quot;,
-     &quot;my/other/locale.yml&quot; ], I18n.load_path.collect { |path| path =~ /\.\./ ? File.expand_path(path) : path }
-  end
-
-  def test_setting_another_default_locale
-    config = Rails::Configuration.new
-    config.i18n.default_locale = :de
-    Rails::Initializer.run(:initialize_i18n, config)
-    assert_equal :de, I18n.default_locale
-  end
-end
-
-class InitializerDatabaseMiddlewareTest &lt; Test::Unit::TestCase
-  def setup
-    @config = Rails::Configuration.new
-    @config.frameworks = [:active_record, :action_controller, :action_view]
-  end
-
-  def test_initialize_database_middleware_doesnt_perform_anything_when_active_record_not_in_frameworks
-    @config.frameworks.clear
-    @config.expects(:middleware).never
-    Rails::Initializer.run(:initialize_database_middleware, @config)
-  end
-
-  def test_database_middleware_initializes_when_session_store_is_active_record
-    store = ActionController::Base.session_store
-    ActionController::Base.session_store = ActiveRecord::SessionStore
-
-    @config.middleware.expects(:insert_before).with(:&quot;ActiveRecord::SessionStore&quot;, ActiveRecord::ConnectionAdapters::ConnectionManagement)
-    @config.middleware.expects(:insert_before).with(:&quot;ActiveRecord::SessionStore&quot;, ActiveRecord::QueryCache)
-
-    Rails::Initializer.run(:initialize_database_middleware, @config)
-  ensure
-    ActionController::Base.session_store = store
-  end
-
-  def test_database_middleware_doesnt_initialize_when_session_store_is_not_active_record
-    store = ActionController::Base.session_store
-    ActionController::Base.session_store = ActionDispatch::Session::CookieStore
-
-    # Define the class, so we don't have to actually make it load
-    eval(&quot;class ActiveRecord::ConnectionAdapters::ConnectionManagement; end&quot;)
-
-    @config.middleware.expects(:use).with(ActiveRecord::ConnectionAdapters::ConnectionManagement)
-    @config.middleware.expects(:use).with(ActiveRecord::QueryCache)
-
-    Rails::Initializer.run(:initialize_database_middleware, @config)
-  ensure
-    ActionController::Base.session_store = store
-  end
-
-  def test_ensure_database_middleware_doesnt_use_action_controller_on_initializing
-    @config.frameworks -= [:action_controller]
-    store = ActionController::Base.session_store
-    ActionController::Base.session_store = ActiveRecord::SessionStore
-
-    @config.middleware.expects(:use).with(ActiveRecord::ConnectionAdapters::ConnectionManagement)
-    @config.middleware.expects(:use).with(ActiveRecord::QueryCache)
-
-    Rails::Initializer.run(:initialize_database_middleware, @config)
-  ensure
-    ActionController::Base.session_store = store
-    @config.frameworks += [:action_controller]
-  end
-end
-
-class InitializerViewPathsTest  &lt; Test::Unit::TestCase
-  def setup
-    @config = Rails::Configuration.new
-    @config.frameworks = [:action_view, :action_controller, :action_mailer]
-
-    ActionController::Base.stubs(:view_paths).returns(stub)
-    ActionMailer::Base.stubs(:view_paths).returns(stub)
-  end
-
-  def test_load_view_paths_doesnt_perform_anything_when_action_view_not_in_frameworks
-    @config.frameworks -= [:action_view]
-    ActionController::Base.view_paths.expects(:load!).never
-    ActionMailer::Base.view_paths.expects(:load!).never
-    Rails::Initializer.run(:load_view_paths, @config)
-  end
-end
-
 class RailsRootTest &lt; Test::Unit::TestCase
   def test_rails_dot_root_equals_rails_root
     assert_equal RAILS_ROOT, Rails.root.to_s</diff>
      <filename>railties/test/initializer_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -7,6 +7,8 @@
 # It is also good to know what is the bare minimum to get
 # Rails booted up.
 
+require 'fileutils'
+
 # TODO: Remove rubygems when possible
 require 'rubygems'
 require 'test/unit'
@@ -30,6 +32,14 @@ module TestHelpers
     def app_path(*args)
       tmp_path(*%w[app] + args)
     end
+
+    def framework_path
+      RAILS_FRAMEWORK_ROOT
+    end
+
+    def rails_root
+      app_path
+    end
   end
 
   module Rack
@@ -87,7 +97,8 @@ module TestHelpers
     end
 
     def app_file(path, contents)
-      File.open(app_path(path), 'w') do |f|
+      FileUtils.mkdir_p File.dirname(&quot;#{app_path}/#{path}&quot;)
+      File.open(&quot;#{app_path}/#{path}&quot;, 'w') do |f|
         f.puts contents
       end
     end</diff>
      <filename>railties/test/isolation/abstract_unit.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,10 +5,13 @@ $:.unshift File.dirname(__FILE__) + &quot;/../../actionmailer/lib&quot;
 require 'action_controller'
 require 'action_mailer'
 
-# Mocks out the configuration
-module Rails
-  def self.configuration
-    Rails::Configuration.new
+# TODO: Rewrite all these tests
+class FakeInitializerSlashApplication
+  attr_reader :config
+  alias configuration config
+
+  def initialize
+    @config = Rails::Configuration.new
   end
 end
 
@@ -18,10 +21,10 @@ class TestPluginLoader &lt; Test::Unit::TestCase
   def setup
     reset_load_path!
 
-    @configuration     = Rails::Configuration.new
+    @initializer      = FakeInitializerSlashApplication.new
+    @configuration    = @initializer.config
+    Rails.application = @initializer
     @configuration.plugin_paths &lt;&lt; plugin_fixture_root_path
-    @initializer       = Rails::Initializer.default
-    @initializer.config = @configuration
     @valid_plugin_path = plugin_fixture_path('default/stubby')
     @empty_plugin_path = plugin_fixture_path('default/empty')
 </diff>
      <filename>railties/test/plugin_loader_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,15 @@
 require 'plugin_test_helper'
 
+# TODO: Rewrite all these tests
+class FakeInitializerSlashApplication
+  attr_reader :config
+  alias configuration config
+
+  def initialize
+    @config = Rails::Configuration.new
+  end
+end
+
 class PluginLocatorTest &lt; Test::Unit::TestCase
   def test_should_require_subclasses_to_implement_the_plugins_method
     assert_raise(RuntimeError) do
@@ -23,12 +33,12 @@ end
 
 class PluginFileSystemLocatorTest &lt; Test::Unit::TestCase
   def setup
-    @configuration = Rails::Configuration.new
+    @initializer      = FakeInitializerSlashApplication.new
+    @configuration    = @initializer.config
+    Rails.application = @initializer
     # We need to add our testing plugin directory to the plugin paths so
     # the locator knows where to look for our plugins
     @configuration.plugin_paths &lt;&lt; plugin_fixture_root_path
-    @initializer       = Rails::Initializer.default
-    @initializer.config = @configuration
     @locator           = Rails::Plugin::FileSystemLocator.new(@initializer)
     @valid_plugin_path = plugin_fixture_path('default/stubby')
     @empty_plugin_path = plugin_fixture_path('default/empty')</diff>
      <filename>railties/test/plugin_locator_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,9 +1,20 @@
 require 'plugin_test_helper'
 
+# TODO: Rewrite all these tests
+class FakeInitializerSlashApplication
+  attr_reader :config
+  alias configuration config
+
+  def initialize
+    @config = Rails::Configuration.new
+  end
+end
+
 class PluginTest &lt; Test::Unit::TestCase
   def setup
-    @initializer         = Rails::Initializer.default
-    @initializer.config  = Rails::Configuration.new
+    @initializer      = FakeInitializerSlashApplication.new
+    @configuration    = @initializer.config
+    Rails.application = @initializer
     @valid_plugin_path   = plugin_fixture_path('default/stubby')
     @empty_plugin_path   = plugin_fixture_path('default/empty')
     @gemlike_plugin_path = plugin_fixture_path('default/gemlike')</diff>
      <filename>railties/test/plugin_test.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>actionpack/test/html-scanner/cdata_node_test.rb</filename>
    </removed>
    <removed>
      <filename>actionpack/test/html-scanner/document_test.rb</filename>
    </removed>
    <removed>
      <filename>actionpack/test/html-scanner/node_test.rb</filename>
    </removed>
    <removed>
      <filename>actionpack/test/html-scanner/sanitizer_test.rb</filename>
    </removed>
    <removed>
      <filename>actionpack/test/html-scanner/tag_node_test.rb</filename>
    </removed>
    <removed>
      <filename>actionpack/test/html-scanner/text_node_test.rb</filename>
    </removed>
    <removed>
      <filename>actionpack/test/html-scanner/tokenizer_test.rb</filename>
    </removed>
    <removed>
      <filename>actionpack/test/javascript/ajax_test.rb</filename>
    </removed>
    <removed>
      <filename>actionpack/test/new_base/base_test.rb</filename>
    </removed>
    <removed>
      <filename>actionpack/test/new_base/content_negotiation_test.rb</filename>
    </removed>
    <removed>
      <filename>actionpack/test/new_base/content_type_test.rb</filename>
    </removed>
    <removed>
      <filename>actionpack/test/new_base/etag_test.rb</filename>
    </removed>
    <removed>
      <filename>actionpack/test/new_base/metal_test.rb</filename>
    </removed>
    <removed>
      <filename>actionpack/test/new_base/middleware_test.rb</filename>
    </removed>
    <removed>
      <filename>actionpack/test/new_base/render_action_test.rb</filename>
    </removed>
    <removed>
      <filename>actionpack/test/new_base/render_file_test.rb</filename>
    </removed>
    <removed>
      <filename>actionpack/test/new_base/render_implicit_action_test.rb</filename>
    </removed>
    <removed>
      <filename>actionpack/test/new_base/render_layout_test.rb</filename>
    </removed>
    <removed>
      <filename>actionpack/test/new_base/render_partial_test.rb</filename>
    </removed>
    <removed>
      <filename>actionpack/test/new_base/render_rjs_test.rb</filename>
    </removed>
    <removed>
      <filename>actionpack/test/new_base/render_template_test.rb</filename>
    </removed>
    <removed>
      <filename>actionpack/test/new_base/render_test.rb</filename>
    </removed>
    <removed>
      <filename>actionpack/test/new_base/render_text_test.rb</filename>
    </removed>
    <removed>
      <filename>actionpack/test/new_base/render_xml_test.rb</filename>
    </removed>
    <removed>
      <filename>actionpack/test/view/test_case_test.rb</filename>
    </removed>
    <removed>
      <filename>railties/lib/rails/commands/ncgi/listener</filename>
    </removed>
    <removed>
      <filename>railties/lib/rails/fcgi_handler.rb</filename>
    </removed>
    <removed>
      <filename>railties/lib/rails/generators/rails/app/templates/dispatchers/dispatch.fcgi</filename>
    </removed>
    <removed>
      <filename>railties/lib/rails/generators/rails/app/templates/dispatchers/dispatch.rb</filename>
    </removed>
    <removed>
      <filename>railties/lib/rails/generators/rails/app/templates/dispatchers/gateway.cgi</filename>
    </removed>
    <removed>
      <filename>railties/lib/rails/initializer_old.rb</filename>
    </removed>
    <removed>
      <filename>railties/test/console_app_test.rb</filename>
    </removed>
    <removed>
      <filename>railties/test/fcgi_dispatcher_test.rb</filename>
    </removed>
    <removed>
      <filename>railties/test/new_initializer_test.rb</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>dd2779e1b83b4d867d47dd286ec0c919f5df12a9</id>
    </parent>
    <parent>
      <id>b9ce8216fa849a47ad0b0f99fa510e226a23c12e</id>
    </parent>
  </parents>
  <author>
    <name>Pratik Naik</name>
    <email>pratiknaik@gmail.com</email>
  </author>
  <url>http://github.com/lifo/docrails/commit/66ee2654ff243f03595a402fa15e1eea1b5b45be</url>
  <id>66ee2654ff243f03595a402fa15e1eea1b5b45be</id>
  <committed-date>2009-10-10T09:15:11-07:00</committed-date>
  <authored-date>2009-10-10T09:15:11-07:00</authored-date>
  <message>Merge commit 'mainstream/master'</message>
  <tree>3f1055e03082f0c767719e8cba5155e4207779e0</tree>
  <committer>
    <name>Pratik Naik</name>
    <email>pratiknaik@gmail.com</email>
  </committer>
</commit>
