From ac015b1d07241f9702af41b079d27985c9b9a20f Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Fri, 16 Apr 2010 15:33:15 -0700 Subject: Revert "Avoid deprecation warnings and potential TypeErrors [#4404 state:resolved]" Revert "protected instance variables added to the deprecated config accessor This reverts commit 4bce5ba600596b5e7afec9b097866ac259c5940a and 0ee2d3c89a893f0c53924cbb756c7e9be616eb8f. --- actionpack/lib/abstract_controller/assigns.rb | 4 ++-- actionpack/lib/abstract_controller/rendering.rb | 2 +- actionpack/lib/action_controller/deprecated/base.rb | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/actionpack/lib/abstract_controller/assigns.rb b/actionpack/lib/abstract_controller/assigns.rb index 4f58cac91f..21459c6d51 100644 --- a/actionpack/lib/abstract_controller/assigns.rb +++ b/actionpack/lib/abstract_controller/assigns.rb @@ -6,7 +6,7 @@ module AbstractController def view_assigns hash = {} variables = instance_variable_names - variables -= config.protected_instance_variables if config.respond_to?(:protected_instance_variables) + variables -= protected_instance_variables if respond_to?(:protected_instance_variables) variables.each { |name| hash[name] = instance_variable_get(name) } hash end @@ -18,4 +18,4 @@ module AbstractController view_assigns.each { |k,v| object.instance_variable_set(k, v) } end end -end +end \ No newline at end of file diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index f1e6f7deb6..d2db366140 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -126,7 +126,7 @@ module AbstractController def view_assigns hash = {} variables = instance_variable_names - variables -= config.protected_instance_variables if config.respond_to?(:protected_instance_variables) + variables -= protected_instance_variables if respond_to?(:protected_instance_variables) variables.each { |name| hash[name.to_s[1..-1]] = instance_variable_get(name) } hash end diff --git a/actionpack/lib/action_controller/deprecated/base.rb b/actionpack/lib/action_controller/deprecated/base.rb index f91f637db8..57203ce95f 100644 --- a/actionpack/lib/action_controller/deprecated/base.rb +++ b/actionpack/lib/action_controller/deprecated/base.rb @@ -154,7 +154,6 @@ module ActionController deprecated_config_accessor :helpers_path deprecated_config_accessor :javascripts_dir deprecated_config_accessor :page_cache_directory - deprecated_config_accessor :protected_instance_variables deprecated_config_accessor :relative_url_root, "relative_url_root is ineffective. Please stop using it" deprecated_config_accessor :stylesheets_dir -- cgit v1.2.3 From c16c248912e4ae3b6a64e6acdbf1a1e0dd2feb26 Mon Sep 17 00:00:00 2001 From: Sam Elliott Date: Fri, 16 Apr 2010 23:24:57 +0100 Subject: mail_to with :encode => :javascript now outputs safe html Signed-off-by: Carl Lerche --- actionpack/lib/action_view/helpers/url_helper.rb | 2 +- actionpack/test/template/url_helper_test.rb | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 0b748d700b..4ffc5ea127 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -504,7 +504,7 @@ module ActionView "document.write('#{content_tag("a", name || email_address_obfuscated.html_safe, html_options.merge({ "href" => "mailto:"+email_address+extras }))}');".each_byte do |c| string << sprintf("%%%x", c) end - "" + "".html_safe elsif encode == "hex" email_address_encoded = '' email_address_obfuscated.each_byte do |c| diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index de63030714..4474949749 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -356,11 +356,15 @@ class UrlHelperTest < ActiveSupport::TestCase end def test_mail_to_with_javascript - assert_dom_equal "", mail_to("me@domain.com", "My email", :encode => "javascript") + snippet = mail_to("me@domain.com", "My email", :encode => "javascript") + assert_dom_equal "", snippet + assert snippet.html_safe? end def test_mail_to_with_javascript_unicode - assert_dom_equal "", mail_to("unicode@example.com", "únicode", :encode => "javascript") + snippet = mail_to("unicode@example.com", "únicode", :encode => "javascript") + assert_dom_equal "", snippet + assert snippet.html_safe end def test_mail_with_options -- cgit v1.2.3 From 457f7709e964a62a24562010c0f79445976cce8b Mon Sep 17 00:00:00 2001 From: wycats Date: Fri, 16 Apr 2010 21:56:35 -0400 Subject: Missing requires --- actionpack/lib/action_dispatch/http/response.rb | 1 + actionpack/lib/action_view/test_case.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index 362e5ec970..8b730a97ee 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -1,6 +1,7 @@ require 'digest/md5' require 'active_support/core_ext/module/delegation' require 'active_support/core_ext/object/blank' +require 'active_support/core_ext/class/attribute_accessors' module ActionDispatch # :nodoc: # Represents an HTTP response generated by a controller action. One can use diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index ddea9cfd92..beda7743bf 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -1,4 +1,5 @@ require 'active_support/core_ext/object/blank' +require 'action_controller' require 'action_controller/test_case' require 'action_view' -- cgit v1.2.3 From dadf35b2a9b0abb6421bc08f2fedba3dbe819d5e Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 16 Apr 2010 23:06:58 -0300 Subject: avoid warning: ambiguous first argument; put parentheses or even spaces --- activesupport/test/time_zone_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index 58035ebbcd..3b7fbb7808 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -282,7 +282,7 @@ class TimeZoneTest < Test::Unit::TestCase def test_unknown_zone_with_utc_offset zone = ActiveSupport::TimeZone.create("bogus", -21_600) - assert_equal -21_600, zone.utc_offset + assert_equal(-21_600, zone.utc_offset) end def test_new -- cgit v1.2.3 From e85100da0a780c7da5d0daf6498861f96c44f40b Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 16 Apr 2010 23:44:39 -0300 Subject: Added missing require --- actionpack/test/controller/mime_responds_test.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index 53cd3f0801..c8ba8bcaf3 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -1,5 +1,6 @@ require 'abstract_unit' require 'controller/fake_models' +require 'active_support/core_ext/hash/conversions' class RespondToController < ActionController::Base layout :set_layout -- cgit v1.2.3 From cd6578f6a12e1b221a2d8a1e79e4c6f1209d874d Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 16 Apr 2010 20:47:40 -0700 Subject: fixing invalid yaml [#4424 state:resolved] Signed-off-by: wycats --- activerecord/test/fixtures/binaries.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/activerecord/test/fixtures/binaries.yml b/activerecord/test/fixtures/binaries.yml index d150c5708e..ec8f2facdc 100644 --- a/activerecord/test/fixtures/binaries.yml +++ b/activerecord/test/fixtures/binaries.yml @@ -1,6 +1,7 @@ flowers: id: 1 - data: !binary | /9j/4AAQSkZJRgABAQEASABIAAD/2wBDAA0JCQoKCg4LCw4UDQsNFBcRDg4R + data: !binary |- + /9j/4AAQSkZJRgABAQEASABIAAD/2wBDAA0JCQoKCg4LCw4UDQsNFBcRDg4R FxsVFRUVFRsbFRcXFxcVGxoeICEgHhonJyoqJyc1NTU1NTY2NjY2NjY2Njb/ 2wBDAQ4NDRERERcRERcXExQTFx0ZGhoZHSYdHR4dHSYsJCAgICAkLCgrJiYm KygvLywsLy82NjY2NjY2NjY2NjY2Njb/wAARCACvAIMDAREAAhEBAxEB/8QA -- cgit v1.2.3 From d92e3111fed2a5372d4bb8ac66c9d8542f730488 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 16 Apr 2010 21:35:10 -0700 Subject: making yaml tests less specific to emitter. [#4425 state:resolved] Signed-off-by: wycats --- activerecord/test/cases/base_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 591e04a077..2f4243a6aa 100755 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -2095,7 +2095,8 @@ class BasicsTest < ActiveRecord::TestCase assert_equal written_on_in_current_timezone, xml.elements["//written-on"].text assert_equal "datetime" , xml.elements["//written-on"].attributes['type'] - assert_equal "--- Have a nice day\n" , xml.elements["//content"].text + assert_match(/^--- Have a nice day\n/ , xml.elements["//content"].text) + assert_equal 'Have a nice day' , YAML.load(xml.elements["//content"].text) assert_equal "yaml" , xml.elements["//content"].attributes['type'] assert_equal "david@loudthinking.com", xml.elements["//author-email-address"].text -- cgit v1.2.3 From b7693dc028cea513724681a70dfd4f3e294bbc54 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 16 Apr 2010 21:49:52 -0700 Subject: working around syck defects by optionally matching a space [#4426 state:resolved] Signed-off-by: wycats --- activerecord/test/cases/xml_serialization_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/test/cases/xml_serialization_test.rb b/activerecord/test/cases/xml_serialization_test.rb index 2849ff11b7..f5a18827d8 100644 --- a/activerecord/test/cases/xml_serialization_test.rb +++ b/activerecord/test/cases/xml_serialization_test.rb @@ -79,7 +79,7 @@ class DefaultXmlSerializationTest < ActiveRecord::TestCase end def test_should_serialize_yaml - assert_match %r{--- \n:gem: ruby\n}, @xml + assert_match %r{---\s?\n:gem: ruby\n}, @xml end end -- cgit v1.2.3 From 9a3a4d6aefa7e2ca94340754eb5541bea1783de0 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Fri, 16 Apr 2010 22:16:21 +0200 Subject: Make i18n fallbacks configurable and fallback to the default locale by default in production [#4428 state:resolved] Allows to configure locale fallbacks through config.i18n.fallbacks. The default setting config.i18n.fallbacks = true in production.rb will make I18n.t lookup fallback to the I18n.default_locale if a translation could not be found for the current or given locale. config.fallbacks = true config.fallbacks.map = { :ca => :es } config.fallbacks.defaults = [:'es-ES', :es] config.fallbacks = [:'es-ES', :es] config.fallbacks = { :ca => :es } config.fallbacks = [:'es-ES', :es, { :ca => :es }] Signed-off-by: Pratik Naik --- activesupport/lib/active_support/railtie.rb | 35 +++++++++ .../templates/config/environments/production.rb.tt | 4 + railties/test/railties/i18n_railtie_test.rb | 86 ++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 railties/test/railties/i18n_railtie_test.rb diff --git a/activesupport/lib/active_support/railtie.rb b/activesupport/lib/active_support/railtie.rb index b8d54ff839..0243157e35 100644 --- a/activesupport/lib/active_support/railtie.rb +++ b/activesupport/lib/active_support/railtie.rb @@ -33,6 +33,7 @@ module I18n config.i18n = ActiveSupport::OrderedOptions.new config.i18n.railties_load_path = [] config.i18n.load_path = [] + config.i18n.fallbacks = ActiveSupport::OrderedOptions.new initializer "i18n.initialize" do ActiveSupport.on_load(:i18n) do @@ -53,6 +54,8 @@ module I18n app.config.i18n.load_path.unshift(*value) when :load_path I18n.load_path += value + when :fallbacks + init_fallbacks(value) if value && validate_fallbacks(value) else I18n.send("#{setting}=", value) end @@ -60,5 +63,37 @@ module I18n I18n.reload! end + + class << self + protected + + def init_fallbacks(fallbacks) + include_fallbacks_module + args = case fallbacks + when ActiveSupport::OrderedOptions + [*(fallbacks[:defaults] || []) << fallbacks[:map]].compact + when Hash, Array + Array.wrap(fallbacks) + else # TrueClass + [] + end + I18n.fallbacks = I18n::Locale::Fallbacks.new(*args) + end + + def include_fallbacks_module + I18n.backend.class.send(:include, I18n::Backend::Fallbacks) + end + + def validate_fallbacks(fallbacks) + case fallbacks + when ActiveSupport::OrderedOptions + !fallbacks.empty? + when TrueClass, Array, Hash + true + else + raise "Unexpected fallback type #{fallbacks.inspect}" + end + end + end end end \ No newline at end of file diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt index f902120453..b9fb13b640 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt @@ -39,4 +39,8 @@ # Enable threaded mode # config.threadsafe! + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation can not be found) + config.i18n.fallbacks = true end diff --git a/railties/test/railties/i18n_railtie_test.rb b/railties/test/railties/i18n_railtie_test.rb new file mode 100644 index 0000000000..51684aa838 --- /dev/null +++ b/railties/test/railties/i18n_railtie_test.rb @@ -0,0 +1,86 @@ +require "isolation/abstract_unit" + +module RailtiesTest + class I18nRailtieTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + FileUtils.rm_rf("#{app_path}/config/environments") + require "rails/all" + @old_path = I18n.load_path + end + + def teardown + I18n.load_path = @old_path || [] + I18n.backend = nil + end + + def load_app + require "#{app_path}/config/environment" + end + + def assert_fallbacks(fallbacks) + fallbacks.each do |locale, expected| + actual = I18n.fallbacks[locale] + assert_equal expected, actual, "expected fallbacks for #{locale.inspect} to be #{expected.inspect}, but were #{actual.inspect}" + end + end + + def assert_no_fallbacks + assert !I18n.backend.class.included_modules.include?(I18n::Backend::Fallbacks) + end + + test "config.i18n.load_path gets added to I18n.load_path" do + I18n.load_path = ['existing/path/to/locales'] + I18n::Railtie.config.i18n.load_path = ['new/path/to/locales'] + load_app + + assert I18n.load_path.include?('existing/path/to/locales') + assert I18n.load_path.include?('new/path/to/locales') + end + + test "not using config.i18n.fallbacks does not initialize I18n.fallbacks" do + I18n.backend = Class.new { include I18n::Backend::Base }.new # can't uninclude modules, so use a tmp backend class + load_app + assert_no_fallbacks + end + + test "config.i18n.fallbacks = true initializes I18n.fallbacks with default settings" do + I18n::Railtie.config.i18n.fallbacks = true + load_app + assert_fallbacks :de => [:de, :en] + end + + test "config.i18n.fallbacks.defaults = [:'en-US'] initializes fallbacks with en-US as a fallback default" do + I18n::Railtie.config.i18n.fallbacks.defaults = [:'en-US'] + load_app + assert_fallbacks :de => [:de, :'en-US', :en] + end + + test "config.i18n.fallbacks.map = { :ca => :'es-ES' } initializes fallbacks with a mapping ca => es-ES" do + I18n::Railtie.config.i18n.fallbacks.map = { :ca => :'es-ES' } + load_app + assert_fallbacks :ca => [:ca, :"es-ES", :es, :en] + end + + test "[shortcut] config.i18n.fallbacks = [:'en-US'] initializes fallbacks with en-US as a fallback default" do + I18n::Railtie.config.i18n.fallbacks = [:'en-US'] + load_app + assert_fallbacks :de => [:de, :'en-US', :en] + end + + test "[shortcut] config.i18n.fallbacks = [{ :ca => :'es-ES' }] initializes fallbacks with a mapping de-AT => de-DE" do + I18n::Railtie.config.i18n.fallbacks.map = { :ca => :'es-ES' } + load_app + assert_fallbacks :ca => [:ca, :"es-ES", :es, :en] + end + + test "[shortcut] config.i18n.fallbacks = [:'en-US', { :ca => :'es-ES' }] initializes fallbacks with the given arguments" do + I18n::Railtie.config.i18n.fallbacks = [:'en-US', { :ca => :'es-ES' }] + load_app + assert_fallbacks :ca => [:ca, :"es-ES", :es, :'en-US', :en] + end + end +end \ No newline at end of file -- cgit v1.2.3 From d4d352bf94f8d2b6fc5684706ed2b33da77203fd Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sat, 17 Apr 2010 12:54:52 -0700 Subject: fisting codes so it will parse [#4430 state:resolved] Signed-off-by: wycats --- actionpack/test/template/erb_util_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actionpack/test/template/erb_util_test.rb b/actionpack/test/template/erb_util_test.rb index 06155b1f30..d3129d0e1a 100644 --- a/actionpack/test/template/erb_util_test.rb +++ b/actionpack/test/template/erb_util_test.rb @@ -4,12 +4,12 @@ class ErbUtilTest < Test::Unit::TestCase include ERB::Util ERB::Util::HTML_ESCAPE.each do |given, expected| - define_method "test_html_escape_#{expected.gsub /\W/, ''}" do + define_method "test_html_escape_#{expected.gsub(/\W/, '')}" do assert_equal expected, html_escape(given) end unless given == '"' - define_method "test_json_escape_#{expected.gsub /\W/, ''}" do + define_method "test_json_escape_#{expected.gsub(/\W/, '')}" do assert_equal ERB::Util::JSON_ESCAPE[given], json_escape(given) end end -- cgit v1.2.3 From 4327ad51abfddde822766702d154df11bd5b47a3 Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Sat, 17 Apr 2010 14:52:37 -0500 Subject: access assigns as a method or hash, with strings or symbols [#4431 state:resolved] --- actionpack/lib/action_dispatch/testing/test_process.rb | 4 ++-- actionpack/test/controller/test_test.rb | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_dispatch/testing/test_process.rb b/actionpack/lib/action_dispatch/testing/test_process.rb index d4eecac2de..79f309cae7 100644 --- a/actionpack/lib/action_dispatch/testing/test_process.rb +++ b/actionpack/lib/action_dispatch/testing/test_process.rb @@ -3,13 +3,13 @@ require 'action_dispatch/middleware/flash' module ActionDispatch module TestProcess def assigns(key = nil) - assigns = {} + assigns = {}.with_indifferent_access @controller.instance_variable_names.each do |ivar| next if ActionController::Base.protected_instance_variables.include?(ivar) assigns[ivar[1..-1]] = @controller.instance_variable_get(ivar) end - key.nil? ? assigns : assigns[key.to_s] + key.nil? ? assigns : assigns[key] end def session diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb index 6f1ce2fef7..f9fc7a0976 100644 --- a/actionpack/test/controller/test_test.rb +++ b/actionpack/test/controller/test_test.rb @@ -113,6 +113,11 @@ XML render :nothing => true end + def test_assigns + @foo = "foo" + render :nothing => true + end + private def rescue_action(e) raise e @@ -230,6 +235,17 @@ XML assert_equal "OK", @response.body end + def test_assigns + process :test_assigns + # assigns can be accessed using assigns(key) + # or assigns[key], where key is a string or + # a symbol + assert_equal "foo", assigns(:foo) + assert_equal "foo", assigns("foo") + assert_equal "foo", assigns[:foo] + assert_equal "foo", assigns["foo"] + end + def test_assert_tag_tag process :test_html_output -- cgit v1.2.3 From afcd252205d84ebf5ffd0659301c604a7beba2bb Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 17 Apr 2010 15:16:38 -0700 Subject: removes code written for Ruby < 1.8.7 --- .../lib/active_support/core_ext/string/multibyte.rb | 7 ------- activesupport/test/core_ext/string_ext_test.rb | 12 ------------ 2 files changed, 19 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/string/multibyte.rb b/activesupport/lib/active_support/core_ext/string/multibyte.rb index 13208c6ee2..42e053d0f8 100644 --- a/activesupport/lib/active_support/core_ext/string/multibyte.rb +++ b/activesupport/lib/active_support/core_ext/string/multibyte.rb @@ -49,13 +49,6 @@ class String def is_utf8? ActiveSupport::Multibyte::Chars.consumes?(self) end - - unless '1.8.7 and later'.respond_to?(:chars) - def chars - ActiveSupport::Deprecation.warn('String#chars has been deprecated in favor of String#mb_chars.', caller) - mb_chars - end - end else def mb_chars #:nodoc self diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index 234e41c772..58ca215970 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -230,18 +230,6 @@ class CoreExtStringMultibyteTest < ActiveSupport::TestCase assert !BYTE_STRING.is_utf8? end - if RUBY_VERSION < '1.8.7' - def test_core_ext_adds_chars - assert UNICODE_STRING.respond_to?(:chars) - end - - def test_chars_warns_about_deprecation - assert_deprecated("String#chars") do - ''.chars - end - end - end - if RUBY_VERSION < '1.9' def test_mb_chars_returns_self_when_kcode_not_set with_kcode('none') do -- cgit v1.2.3 From 8c7e8976e97d96f514e22b04fc1afb9453134076 Mon Sep 17 00:00:00 2001 From: Diego Carrion Date: Fri, 16 Apr 2010 20:04:29 -0300 Subject: added shorthand support for routes like /projects/status(.:format) Signed-off-by: Jeremy Kemper --- actionpack/CHANGELOG | 2 ++ actionpack/lib/action_dispatch/routing/mapper.rb | 6 +++--- actionpack/test/dispatch/routing_test.rb | 9 +++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 388169d981..064e06bf92 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *Rails 3.0.0 [beta 4/release candidate] (unreleased)* +* Add support for shorthand routes like /projects/status(.:format) #4423 [Diego Carrion] + * Changed translate helper so that it doesn’t mark every translation as safe HTML. Only keys with a "_html" suffix and keys named "html" are considered to be safe HTML. All other translations are left untouched. [Craig Davey] diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 53585740ce..ef2826a4e8 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -66,8 +66,8 @@ module ActionDispatch path = normalize_path(path) if using_match_shorthand?(path, options) - options[:to] ||= path[1..-1].sub(%r{/([^/]*)$}, '#\1') - options[:as] ||= path[1..-1].gsub("/", "_") + options[:to] ||= path[1..-1].sub(%r{/([^/]*)$}, '#\1').sub(%r{\(.*\)}, '') + options[:as] ||= path[1..-1].gsub("/", "_").sub(%r{\(.*\)}, '') end [ path, options ] @@ -80,7 +80,7 @@ module ActionDispatch # match "account/overview" def using_match_shorthand?(path, options) - path && options.except(:via, :anchor, :to, :as).empty? && path =~ %r{^/[\w\/]+$} + path && options.except(:via, :anchor, :to, :as).empty? && path =~ %r{^/[\w+/?]+(\(.*\))*$} end def normalize_path(path) diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 8940990712..5bca476b27 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -54,6 +54,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest match "/local/:action", :controller => "local" + match "/projects/status(.:format)" + constraints(:ip => /192\.168\.1\.\d\d\d/) do get 'admin' => "queenbee#index" end @@ -426,6 +428,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_projects_status + with_test_routes do + assert_equal '/projects/status', url_for(:controller => 'projects', :action => 'status', :only_path => true) + assert_equal '/projects/status.json', url_for(:controller => 'projects', :action => 'status', :format => 'json', :only_path => true) + end + end + def test_projects with_test_routes do get '/projects' -- cgit v1.2.3 From 4309c1fda3d778b16569b74a7d86ec19b5e994a3 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sat, 17 Apr 2010 19:08:49 -0300 Subject: perform_caching is now delegated to config on instance and class level --- actionpack/lib/action_controller/caching.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb index b3fa129929..0da0ca1893 100644 --- a/actionpack/lib/action_controller/caching.rb +++ b/actionpack/lib/action_controller/caching.rb @@ -63,8 +63,9 @@ module ActionController #:nodoc: included do extend ConfigMethods - @@perform_caching = true - cattr_accessor :perform_caching + delegate :perform_caching, :perform_caching=, :to => :config + singleton_class.delegate :perform_caching, :perform_caching=, :to => :config + self.perform_caching = true end -- cgit v1.2.3 From 9c4ac84e495c1476758aa8bcc764f6c1a935f404 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sat, 17 Apr 2010 19:10:10 -0300 Subject: perform_caching should be accessed through the controller here --- actionpack/lib/action_view/helpers/cache_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionpack/lib/action_view/helpers/cache_helper.rb b/actionpack/lib/action_view/helpers/cache_helper.rb index 9c6fc752e5..a904af56bb 100644 --- a/actionpack/lib/action_view/helpers/cache_helper.rb +++ b/actionpack/lib/action_view/helpers/cache_helper.rb @@ -39,7 +39,7 @@ module ActionView private # TODO: Create an object that has caching read/write on it def fragment_for(name = {}, options = nil, &block) #:nodoc: - if controller.class.perform_caching + if controller.perform_caching if controller.fragment_exist?(name, options) controller.read_fragment(name, options) else -- cgit v1.2.3 From c4846c99c51a33bd66933dd0fd5dacfac99fb9de Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 18 Apr 2010 00:12:08 -0300 Subject: Missing require added --- activerecord/test/cases/xml_serialization_test.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/activerecord/test/cases/xml_serialization_test.rb b/activerecord/test/cases/xml_serialization_test.rb index f5a18827d8..b1c75ec8cd 100644 --- a/activerecord/test/cases/xml_serialization_test.rb +++ b/activerecord/test/cases/xml_serialization_test.rb @@ -4,6 +4,7 @@ require 'models/post' require 'models/author' require 'models/tagging' require 'models/comment' +require 'models/company_in_module' class XmlSerializationTest < ActiveRecord::TestCase def test_should_serialize_default_root -- cgit v1.2.3 From b7ea64a86c03becdbdd417cc79cc1d2ad20a30bc Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 18 Apr 2010 03:46:01 -0300 Subject: remove code for Ruby < 1.8.7 --- activesupport/lib/active_support/core_ext/benchmark.rb | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/benchmark.rb b/activesupport/lib/active_support/core_ext/benchmark.rb index ae57b152e8..2d110155a5 100644 --- a/activesupport/lib/active_support/core_ext/benchmark.rb +++ b/activesupport/lib/active_support/core_ext/benchmark.rb @@ -1,18 +1,6 @@ require 'benchmark' class << Benchmark - # Earlier Ruby had a slower implementation. - if RUBY_VERSION < '1.8.7' - remove_method :realtime - - def realtime - r0 = Time.now - yield - r1 = Time.now - r1.to_f - r0.to_f - end - end - def ms 1000 * realtime { yield } end -- cgit v1.2.3 From 978c80d6e347b060dc11ee666c8a3a61fc9408a4 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 18 Apr 2010 14:02:46 -0300 Subject: Missing require added --- actionpack/lib/action_dispatch/middleware/params_parser.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/actionpack/lib/action_dispatch/middleware/params_parser.rb b/actionpack/lib/action_dispatch/middleware/params_parser.rb index 1524b00d5b..09fb1f998a 100644 --- a/actionpack/lib/action_dispatch/middleware/params_parser.rb +++ b/actionpack/lib/action_dispatch/middleware/params_parser.rb @@ -1,3 +1,4 @@ +require 'active_support/core_ext/hash/conversions.rb' require 'action_dispatch/http/request' module ActionDispatch -- cgit v1.2.3 From 64373937a393518a6e6a63255176ca297d3c009e Mon Sep 17 00:00:00 2001 From: Phil Smith Date: Thu, 15 Apr 2010 22:31:15 -0700 Subject: Make the migration generator handle pre-existing migrations with the same timestamp. In the event a migration already exists with that number, the new migration's timestamp will be incremented by 1. [#4412 state:resolved] Signed-off-by: Michael Koziarski --- activerecord/lib/rails/generators/active_record.rb | 5 +++-- railties/test/generators/migration_generator_test.rb | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/rails/generators/active_record.rb b/activerecord/lib/rails/generators/active_record.rb index 1ca838b4f2..d2b1e86857 100644 --- a/activerecord/lib/rails/generators/active_record.rb +++ b/activerecord/lib/rails/generators/active_record.rb @@ -19,10 +19,11 @@ module ActiveRecord # Implement the required interface for Rails::Generators::Migration. # def self.next_migration_number(dirname) #:nodoc: + next_migration_number = current_migration_number(dirname) + 1 if ActiveRecord::Base.timestamped_migrations - Time.now.utc.strftime("%Y%m%d%H%M%S") + [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max else - "%.3d" % (current_migration_number(dirname) + 1) + "%.3d" % next_migration_number end end end diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb index 762f84d579..6ea722e239 100644 --- a/railties/test/generators/migration_generator_test.rb +++ b/railties/test/generators/migration_generator_test.rb @@ -10,6 +10,19 @@ class MigrationGeneratorTest < Rails::Generators::TestCase assert_migration "db/migrate/#{migration}.rb", /class ChangeTitleBodyFromPosts < ActiveRecord::Migration/ end + def test_migrations_generated_simultaneously + migrations = ["change_title_body_from_posts", "change_email_from_comments"] + + first_migration_number, second_migration_number = migrations.collect do |migration| + run_generator [migration] + file_name = migration_file_name "db/migrate/#{migration}.rb" + + File.basename(file_name).split('_').first + end + + assert_not_equal first_migration_number, second_migration_number + end + def test_migration_with_class_name migration = "ChangeTitleBodyFromPosts" run_generator [migration] -- cgit v1.2.3 From 03aa7877f7b3a0eb5ed1bb48a30be74194c4177a Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 18 Apr 2010 23:01:44 -0700 Subject: MemoryStore#read_multi(*keys) for dev-mode compatibility with memcache store --- activesupport/lib/active_support/cache/memory_store.rb | 8 +++++++- activesupport/test/caching_test.rb | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/cache/memory_store.rb b/activesupport/lib/active_support/cache/memory_store.rb index e6085d97ec..379922f986 100644 --- a/activesupport/lib/active_support/cache/memory_store.rb +++ b/activesupport/lib/active_support/cache/memory_store.rb @@ -21,6 +21,12 @@ module ActiveSupport @data = {} end + def read_multi(*names) + results = {} + names.each { |n| results[n] = read(n) } + results + end + def read(name, options = nil) super do @data[name] @@ -45,7 +51,7 @@ module ActiveSupport end end - def exist?(name,options = nil) + def exist?(name, options = nil) super do @data.has_key?(name) end diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index d96f8e1de5..e62e7ef9aa 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -185,6 +185,13 @@ class MemoryStoreTest < ActiveSupport::TestCase @cache.write('foo', bar) assert_nothing_raised { bar.gsub!(/.*/, 'baz') } end + + def test_multi_get + @cache.write('foo', 1) + @cache.write('goo', 2) + result = @cache.read_multi('foo', 'goo') + assert_equal({'foo' => 1, 'goo' => 2}, result) + end end uses_memcached 'memcached backed store' do -- cgit v1.2.3 From c52dbdc888e4bffab076a8443b7573ca2c9c1291 Mon Sep 17 00:00:00 2001 From: eparreno Date: Sat, 17 Apr 2010 23:45:08 +0200 Subject: fix testing guide: fonts and code format --- railties/guides/source/testing.textile | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile index c4f7ff8e92..206ed6e75c 100644 --- a/railties/guides/source/testing.textile +++ b/railties/guides/source/testing.textile @@ -108,7 +108,7 @@ tag is considered Ruby code. When this fixture is loaded, the +size+ attribute o h5. Fixtures in Action -Rails by default automatically loads all fixtures from the 'test/fixtures' folder for your unit and functional test. Loading involves three steps: +Rails by default automatically loads all fixtures from the +test/fixtures+ folder for your unit and functional test. Loading involves three steps: * Remove any existing data from the table corresponding to the fixture * Load the fixture data into the table @@ -142,7 +142,7 @@ In Rails, unit tests are what you write to test your models. For this guide we will be using Rails _scaffolding_. It will create the model, a migration, controller and views for the new resource in a single operation. It will also create a full test suite following Rails best practices. I will be using examples from this generated code and would be supplementing it with additional examples where necessary. -NOTE: For more information on Rails _scaffolding_, refer to "Getting Started with Rails":getting_started.html +NOTE: For more information on Rails scaffolding, refer to "Getting Started with Rails":getting_started.html When you use +rails generate scaffold+, for a resource among other things it creates a test stub in the +test/unit+ folder: @@ -221,9 +221,9 @@ $ rake db:migrate $ rake db:test:load -Above +rake db:migrate+ runs any pending migrations on the _development_ environment and updates +db/schema.rb+. +rake db:test:load+ recreates the test database from the current db/schema.rb. On subsequent attempts it is a good to first run +db:test:prepare+ as it first checks for pending migrations and warns you appropriately. +Above +rake db:migrate+ runs any pending migrations on the _development_ environment and updates +db/schema.rb+. +rake db:test:load+ recreates the test database from the current +db/schema.rb+. On subsequent attempts it is a good to first run +db:test:prepare+ as it first checks for pending migrations and warns you appropriately. -NOTE: +db:test:prepare+ will fail with an error if db/schema.rb doesn't exists. +NOTE: +db:test:prepare+ will fail with an error if +db/schema.rb+ doesn't exists. h5. Rake Tasks for Preparing your Application for Testing @@ -256,7 +256,7 @@ This will run all the test methods from the test case. You can also run a particular test method from the test case by using the +-n+ switch with the +test method name+. -
+
 $ ruby unit/post_test.rb -n test_truth
 
 Loaded suite unit/post_test
@@ -265,7 +265,7 @@ Started
 Finished in 0.023513 seconds.
 
 1 tests, 1 assertions, 0 failures, 0 errors
-
+ The +.+ (dot) above indicates a passing test. When a test fails you see an +F+; when a test throws an error you see an +E+ in its place. The last line of the output is the summary. @@ -280,7 +280,7 @@ end Let us run this newly added test. -
+
 $ ruby unit/post_test.rb -n test_should_not_save_post_without_title
 Loaded suite -e
 Started
@@ -292,7 +292,7 @@ test_should_not_save_post_without_title(PostTest) [/test/unit/post_test.rb:6]:
  is not true.
 
 1 tests, 1 assertions, 1 failures, 0 errors
-
+ In the output, +F+ denotes a failure. You can see the corresponding trace shown under +1)+ along with the name of the failing test. The next few lines contain the stack trace followed by a message which mentions the actual value and the expected value by the assertion. The default assertion messages provide just enough information to help pinpoint the error. To make the assertion failure message more readable every assertion provides an optional message parameter, as shown here: @@ -305,12 +305,12 @@ end Running this test shows the friendlier assertion message: -
+
   1) Failure:
 test_should_not_save_post_without_title(PostTest) [/test/unit/post_test.rb:6]:
 Saved the post without a title.
  is not true.
-
+ Now to get this test to pass we can add a model level validation for the _title_ field. @@ -322,7 +322,7 @@ end Now the test should pass. Let us verify by running the test again: -
+
 $ ruby unit/post_test.rb -n test_should_not_save_post_without_title
 Loaded suite unit/post_test
 Started
@@ -330,7 +330,7 @@ Started
 Finished in 0.193608 seconds.
 
 1 tests, 1 assertions, 0 failures, 0 errors
-
+ Now if you noticed we first wrote a test which fails for a desired functionality, then we wrote some code which adds the functionality and finally we ensured that our test passes. This approach to software development is referred to as _Test-Driven Development_ (TDD). @@ -348,7 +348,7 @@ end Now you can see even more output in the console from running the tests: -
+
 $ ruby unit/post_test.rb -n test_should_report_error
 Loaded suite -e
 Started
@@ -361,7 +361,7 @@ NameError: undefined local variable or method `some_undefined_variable' for #
+
 
 Notice the 'E' in the output. It denotes a test with error.
 
@@ -446,7 +446,7 @@ test "should get index" do
 end
 
 
-In the +test_should_get_index+ test, Rails simulates a request on the action called index, making sure the request was successful and also ensuring that it assigns a valid +posts+ instance variable.
+In the +test_should_get_index+ test, Rails simulates a request on the action called +index+, making sure the request was successful and also ensuring that it assigns a valid +posts+ instance variable.
 
 The +get+ method kicks off the web request and populates the results into the response. It accepts 4 arguments:
 
-- 
cgit v1.2.3


From 9428473f9de014e993152fe08277047db0f21848 Mon Sep 17 00:00:00 2001
From: Xavier Noria 
Date: Sat, 17 Apr 2010 16:43:31 +0200
Subject: AS guide: AS no longer extends Pathname

---
 railties/guides/source/active_support_core_extensions.textile | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index 398d2b2392..32738fe070 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -2662,10 +2662,6 @@ h3. Extensions to +Process+
 
 ...
 
-h3. Extensions to +Pathname+
-
-...
-
 h3. Extensions to +File+
 
 h4. +atomic_write+
-- 
cgit v1.2.3


From 0f0b40d3b6ff8598624574beab92e4ac87481c1c Mon Sep 17 00:00:00 2001
From: Xavier Noria 
Date: Sun, 18 Apr 2010 00:05:09 +0200
Subject: revises the rdoc of String#ord

---
 activesupport/lib/active_support/core_ext/string/conversions.rb | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb
index 52946f9037..d70f5d7241 100644
--- a/activesupport/lib/active_support/core_ext/string/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/string/conversions.rb
@@ -3,7 +3,11 @@ require 'active_support/core_ext/time/publicize_conversion_methods'
 require 'active_support/core_ext/time/calculations'
 
 class String
-  # 'a'.ord == 'a'[0] for Ruby 1.9 forward compatibility.
+  # Returns the ASCII code of the first character of the string, assuming it belongs to ASCII.
+  #
+  # This method is defined for Ruby 1.9 forward compatibility on ASCII characters.
+  #
+  # See also ActiveSupport::Multibyte::Chars#ord.
   def ord
     self[0]
   end unless method_defined?(:ord)
-- 
cgit v1.2.3


From bb19f2087623d2a716d0187cbc644bf606bac2db Mon Sep 17 00:00:00 2001
From: Xavier Noria 
Date: Sun, 18 Apr 2010 11:55:07 +0200
Subject: much complete rdoc for String#ord

---
 .../active_support/core_ext/string/conversions.rb  | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb
index d70f5d7241..4cc36147f8 100644
--- a/activesupport/lib/active_support/core_ext/string/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/string/conversions.rb
@@ -3,11 +3,27 @@ require 'active_support/core_ext/time/publicize_conversion_methods'
 require 'active_support/core_ext/time/calculations'
 
 class String
-  # Returns the ASCII code of the first character of the string, assuming it belongs to ASCII.
+  # Returns the codepoint of the first character of the string, assuming a
+  # single-byte character encoding:
   #
-  # This method is defined for Ruby 1.9 forward compatibility on ASCII characters.
+  #   "a".ord # => 97
+  #   "à".ord # => 224, in ISO-8859-1
   #
-  # See also ActiveSupport::Multibyte::Chars#ord.
+  # This method is defined in Ruby 1.8 for Ruby 1.9 forward compatibility on
+  # these character encodings.
+  #
+  # ActiveSupport::Multibyte::Chars#ord is forward compatible with
+  # Ruby 1.9 on UTF8 strings:
+  #
+  #   "a".mb_chars.ord # => 97
+  #   "à".mb_chars.ord # => 224, in UTF8
+  #
+  # Note that the 224 is different in both examples. In ISO-8859-1 "à" is
+  # represented as a single byte, 224. In UTF8 it is represented with two
+  # bytes, namely 195 and 160, but its Unicode codepoint is 224. If we
+  # call +ord+ on the UTF8 string "à" the return value will be 195. That is
+  # not an error, because UTF8 is unsupported, the call itself would be
+  # bogus.
   def ord
     self[0]
   end unless method_defined?(:ord)
-- 
cgit v1.2.3


From 15efaa701aae036031df604877b985eb2e59327e Mon Sep 17 00:00:00 2001
From: Rohit Arondekar 
Date: Mon, 19 Apr 2010 05:04:19 -0700
Subject: Fixes to the getting started guide

---
 railties/guides/source/getting_started.textile | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index cbace177f9..09190f5800 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -87,7 +87,7 @@ Action View manages the views of your Rails application. It can create both HTML
 
 h5. Action Dispatch
 
-Action Dispatch handles routing of web requests and dispatches them as you want, either to your application, any other Rack application.
+Action Dispatch handles routing of web requests and dispatches them as you want, either to your application or any other Rack application.
 
 h5. Action Mailer
 
@@ -356,19 +356,19 @@ The scaffold generator will build 15 files in your application, along with some
 |_.File                                       |_.Purpose|
 |db/migrate/20100207214725_create_posts.rb.rb    |Migration to create the posts table in your database (your name will include a different timestamp)|
 |app/models/post.rb                           |The Post model|
-|test/unit/post_test.rb                       |Unit testing harness for the posts model|
 |test/fixtures/posts.yml                      |Dummy posts for use in testing|
 |app/controllers/posts_controller.rb          |The Posts controller|
 |app/views/posts/index.html.erb               |A view to display an index of all posts |
 |app/views/posts/edit.html.erb                |A view to edit an existing post|
 |app/views/posts/show.html.erb                |A view to display a single post|
 |app/views/posts/new.html.erb                 |A view to create a new post|
-|app/views/posts/_form.html.erb               |A view to control the overall look and feel of the other posts views|
-|app/views/layouts/posts.html.erb             |A view to control the overall look and feel of the other posts views|
+|app/views/posts/_form.html.erb               |A partial to control the overall look and feel of the form used in edit and new views|
+|app/views/layouts/posts.html.erb             |A view to control the overall look and feel of the other post views|
+|app/helpers/posts_helper.rb                  |Helper functions to be used from the post views|
+|test/unit/post_test.rb                       |Unit testing harness for the posts model|
 |test/functional/posts_controller_test.rb     |Functional testing harness for the posts controller|
-|app/helpers/posts_helper.rb                  |Helper functions to be used from the posts views|
-|config/routes.rb                             |Edited to include routing information for posts|
 |test/unit/helpers/posts_helper_test.rb       |Unit testing harness for the posts helper|
+|config/routes.rb                             |Edited to include routing information for posts|
 |public/stylesheets/scaffold.css              |Cascading style sheet to make the scaffolded views look better|
 
 h4. Running a Migration
-- 
cgit v1.2.3


From ad4615e97896428ca140411081442f1b5e7d6089 Mon Sep 17 00:00:00 2001
From: Cheah Chu Yeow 
Date: Mon, 19 Apr 2010 18:29:18 +0800
Subject: Rails on Rack Rails guide: indicate that Metal pieces now require an
 "X-Cascade" header with a value of "pass" to continue the Metal chain
 execution instead of a HTTP 404 response. Also removed reference to old code.

---
 railties/guides/source/rails_on_rack.textile | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)

diff --git a/railties/guides/source/rails_on_rack.textile b/railties/guides/source/rails_on_rack.textile
index d0d86e99f2..512be43668 100644
--- a/railties/guides/source/rails_on_rack.textile
+++ b/railties/guides/source/rails_on_rack.textile
@@ -247,7 +247,7 @@ class Poller
     if env["PATH_INFO"] =~ /^\/poller/
       [200, {"Content-Type" => "text/html"}, ["Hello, World!"]]
     else
-      [404, {"Content-Type" => "text/html"}, ["Not Found"]]
+      [404, {"Content-Type" => "text/html", "X-Cascade" => "pass"}, ["Not Found"]]
     end
   end
 end
@@ -257,23 +257,13 @@ Metal applications within +app/metal+ folders in plugins will also be discovered
 
 Metal applications are an optimization. You should make sure to "understand the related performance implications":http://weblog.rubyonrails.org/2008/12/20/performance-of-rails-metal before using it.
 
-h4. Execution Order
-
-All Metal Applications are executed by +Rails::Rack::Metal+ middleware, which is a part of the +ActionController::MiddlewareStack+ chain.
+WARNING: To continue the Metal chain execution, return an +X-Cascade+ HTTP header with a value of +pass+.
 
-Here's the primary method responsible for running the Metal applications:
+h4. Execution Order
 
-
-def call(env)
-  @metals.keys.each do |app|
-    result = app.call(env)
-    return result unless result[0].to_i == 404
-  end
-  @app.call(env)
-end
-
+All Metal Applications are executed in alphabetical order of their filenames, so +aaa.rb+ will come before +bbb.rb+ in the metal chain.
 
-In the code above, +@metals+ is an ordered hash of metal applications. Due to the default alphabetical ordering, +aaa.rb+ will come before +bbb.rb+ in the metal chain.
+You can override the default ordering in your environment. Simply add a line like the following to +config/application.rb+
 
 It is, however, possible to override the default ordering in your environment. Simply add a line like the following to +config/environment.rb+
 
@@ -283,8 +273,6 @@ config.metals = ["Bbb", "Aaa"]
 
 Each string in the array should be the name of your metal class. If you do this then be warned that any metal applications not listed will not be loaded.
 
-WARNING: Metal applications cannot return the HTTP Status +404+ to a client, as it is used for continuing the Metal chain execution. Please use normal Rails controllers or a custom middleware if returning +404+ is a requirement.
-
 h3. Resources
 
 h4. Learning Rack
-- 
cgit v1.2.3