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(-) (limited to 'actionpack') 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(-) (limited to 'actionpack') 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(+) (limited to 'actionpack') 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 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(+) (limited to 'actionpack') 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 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(-) (limited to 'actionpack') 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(-) (limited to 'actionpack') 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 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(-) (limited to 'actionpack') 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(-) (limited to 'actionpack') 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(-) (limited to 'actionpack') 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 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(+) (limited to 'actionpack') 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