From 29f13beda35e30b472c6617fcf3fc5cc22d3468a Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 26 Sep 2010 12:06:19 -0300 Subject: port is appended twice to HTTP_HOST when host already has the port --- actionpack/lib/action_dispatch/testing/integration.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 84039c06ab..404b6185c2 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -257,19 +257,19 @@ module ActionDispatch end end - port = host.split(':')[1] + hostname, port = host.split(':') env = { :method => method, :params => parameters, - "SERVER_NAME" => host.split(':')[0], + "SERVER_NAME" => hostname, "SERVER_PORT" => (port ? port : (https? ? "443" : "80")), "HTTPS" => https? ? "on" : "off", "rack.url_scheme" => https? ? "https" : "http", "REQUEST_URI" => path, - "HTTP_HOST" => [host, port].compact.join(':'), + "HTTP_HOST" => host, "REMOTE_ADDR" => remote_addr, "CONTENT_TYPE" => "application/x-www-form-urlencoded", "HTTP_ACCEPT" => accept -- cgit v1.2.3 From db23e321413aedcfb30207da80bfe06a0eb90e8b Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 26 Sep 2010 17:43:26 -0300 Subject: Not need to do this double ternary --- actionpack/lib/action_dispatch/testing/integration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 404b6185c2..41729beefb 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -264,7 +264,7 @@ module ActionDispatch :params => parameters, "SERVER_NAME" => hostname, - "SERVER_PORT" => (port ? port : (https? ? "443" : "80")), + "SERVER_PORT" => port || https? ? "443" : "80", "HTTPS" => https? ? "on" : "off", "rack.url_scheme" => https? ? "https" : "http", -- cgit v1.2.3 From 56de4e9a8090e2e617a0d478d38c0fccfce7d725 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 26 Sep 2010 17:54:00 -0300 Subject: Fix the precedence issue here --- actionpack/lib/action_dispatch/testing/integration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 41729beefb..50bdad1b1c 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -264,7 +264,7 @@ module ActionDispatch :params => parameters, "SERVER_NAME" => hostname, - "SERVER_PORT" => port || https? ? "443" : "80", + "SERVER_PORT" => port || (https? ? "443" : "80"), "HTTPS" => https? ? "on" : "off", "rack.url_scheme" => https? ? "https" : "http", -- cgit v1.2.3 From 2d274a520857b159bd4dd0206fc7cd09a9356b86 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Wed, 22 Sep 2010 16:03:39 -0300 Subject: Use parentheses when using assert_match followed by a regexp to avoid warnings. --- .../test/activerecord/controller_runtime_test.rb | 4 ++-- .../test/controller/action_pack_assertions_test.rb | 2 +- actionpack/test/controller/caching_test.rb | 6 ++--- actionpack/test/controller/log_subscriber_test.rb | 26 +++++++++++----------- actionpack/test/controller/mime_responds_test.rb | 4 ++-- actionpack/test/controller/render_other_test.rb | 6 ++--- actionpack/test/controller/test_test.rb | 2 +- actionpack/test/controller/url_for_test.rb | 2 +- actionpack/test/dispatch/cookies_test.rb | 10 ++++----- actionpack/test/dispatch/request_test.rb | 6 ++--- .../test/dispatch/session/cookie_store_test.rb | 2 +- actionpack/test/dispatch/show_exceptions_test.rb | 14 ++++++------ actionpack/test/template/asset_tag_helper_test.rb | 2 +- actionpack/test/template/atom_feed_helper_test.rb | 2 +- actionpack/test/template/log_subscriber_test.rb | 18 +++++++-------- actionpack/test/template/tag_helper_test.rb | 4 ++-- actionpack/test/template/test_case_test.rb | 6 ++--- 17 files changed, 58 insertions(+), 58 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/activerecord/controller_runtime_test.rb b/actionpack/test/activerecord/controller_runtime_test.rb index cfd86d704d..16fc901760 100644 --- a/actionpack/test/activerecord/controller_runtime_test.rb +++ b/actionpack/test/activerecord/controller_runtime_test.rb @@ -37,6 +37,6 @@ class ControllerRuntimeLogSubscriberTest < ActionController::TestCase wait assert_equal 2, @logger.logged(:info).size - assert_match /\(Views: [\d\.]+ms | ActiveRecord: [\d\.]+ms\)/, @logger.logged(:info)[1] + assert_match(/\(Views: [\d\.]+ms | ActiveRecord: [\d\.]+ms\)/, @logger.logged(:info)[1]) end -end \ No newline at end of file +end diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index 443191d4fa..a0092a9f73 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -314,7 +314,7 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase def test_redirect_url_match process :redirect_external assert @response.redirect? - assert_match /rubyonrails/, @response.redirect_url + assert_match(/rubyonrails/, @response.redirect_url) assert !/perloffrails/.match(@response.redirect_url) end diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index a83f5155f8..8030499235 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -728,7 +728,7 @@ CACHED get :html_fragment_cached_with_partial assert_response :success assert_match(/Old fragment caching in a partial/, @response.body) - assert_match "Old fragment caching in a partial", @store.read('views/test.host/functional_caching/html_fragment_cached_with_partial') + assert_match("Old fragment caching in a partial", @store.read('views/test.host/functional_caching/html_fragment_cached_with_partial')) end def test_render_inline_before_fragment_caching @@ -736,14 +736,14 @@ CACHED assert_response :success assert_match(/Some inline content/, @response.body) assert_match(/Some cached content/, @response.body) - assert_match "Some cached content", @store.read('views/test.host/functional_caching/inline_fragment_cached') + assert_match("Some cached content", @store.read('views/test.host/functional_caching/inline_fragment_cached')) end def test_fragment_caching_in_rjs_partials xhr :get, :js_fragment_cached_with_partial assert_response :success assert_match(/Old fragment caching in a partial/, @response.body) - assert_match "Old fragment caching in a partial", @store.read('views/test.host/functional_caching/js_fragment_cached_with_partial') + assert_match("Old fragment caching in a partial", @store.read('views/test.host/functional_caching/js_fragment_cached_with_partial')) end def test_html_formatted_fragment_caching diff --git a/actionpack/test/controller/log_subscriber_test.rb b/actionpack/test/controller/log_subscriber_test.rb index 7f7246d15c..b5bc0e9e9a 100644 --- a/actionpack/test/controller/log_subscriber_test.rb +++ b/actionpack/test/controller/log_subscriber_test.rb @@ -72,8 +72,8 @@ class ACLogSubscriberTest < ActionController::TestCase get :show wait assert_equal 2, logs.size - assert_match /Completed/, logs.last - assert_match /200 OK/, logs.last + assert_match(/Completed/, logs.last) + assert_match(/200 OK/, logs.last) end def test_process_action_without_parameters @@ -93,7 +93,7 @@ class ACLogSubscriberTest < ActionController::TestCase def test_process_action_with_view_runtime get :show wait - assert_match /\(Views: [\d\.]+ms\)/, logs[1] + assert_match(/\(Views: [\d\.]+ms\)/, logs[1]) end def test_process_action_with_filter_parameters @@ -103,9 +103,9 @@ class ACLogSubscriberTest < ActionController::TestCase wait params = logs[1] - assert_match /"amount"=>"\[FILTERED\]"/, params - assert_match /"lifo"=>"\[FILTERED\]"/, params - assert_match /"step"=>"1"/, params + assert_match(/"amount"=>"\[FILTERED\]"/, params) + assert_match(/"lifo"=>"\[FILTERED\]"/, params) + assert_match(/"step"=>"1"/, params) end def test_redirect_to @@ -121,7 +121,7 @@ class ACLogSubscriberTest < ActionController::TestCase wait assert_equal 3, logs.size - assert_match /Sent data file\.txt/, logs[1] + assert_match(/Sent data file\.txt/, logs[1]) end def test_send_file @@ -129,8 +129,8 @@ class ACLogSubscriberTest < ActionController::TestCase wait assert_equal 3, logs.size - assert_match /Sent file/, logs[1] - assert_match /test\/fixtures\/company\.rb/, logs[1] + assert_match(/Sent file/, logs[1]) + assert_match(/test\/fixtures\/company\.rb/, logs[1]) end def test_with_fragment_cache @@ -139,8 +139,8 @@ class ACLogSubscriberTest < ActionController::TestCase wait assert_equal 4, logs.size - assert_match /Exist fragment\? views\/foo/, logs[1] - assert_match /Write fragment views\/foo/, logs[2] + assert_match(/Exist fragment\? views\/foo/, logs[1]) + assert_match(/Write fragment views\/foo/, logs[2]) ensure @controller.config.perform_caching = true end @@ -163,8 +163,8 @@ class ACLogSubscriberTest < ActionController::TestCase wait assert_equal 3, logs.size - assert_match /Write page/, logs[1] - assert_match /\/index\.html/, logs[1] + assert_match(/Write page/, logs[1]) + assert_match(/\/index\.html/, logs[1]) ensure @controller.config.perform_caching = true end diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index 8c0af0dc30..adccfa028f 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -784,8 +784,8 @@ class RespondWithControllerTest < ActionController::TestCase get :using_resource_with_collection assert_equal "application/xml", @response.content_type assert_equal 200, @response.status - assert_match /david<\/name>/, @response.body - assert_match /jamis<\/name>/, @response.body + assert_match(/david<\/name>/, @response.body) + assert_match(/jamis<\/name>/, @response.body) end def test_using_resource_with_action diff --git a/actionpack/test/controller/render_other_test.rb b/actionpack/test/controller/render_other_test.rb index dfc4f2db8c..3117be6e81 100644 --- a/actionpack/test/controller/render_other_test.rb +++ b/actionpack/test/controller/render_other_test.rb @@ -224,15 +224,15 @@ class RenderOtherTest < ActionController::TestCase get :update_page_with_instance_variables assert_template nil assert_equal 'text/javascript; charset=utf-8', @response.headers["Content-Type"] - assert_match /balance/, @response.body - assert_match /\$37/, @response.body + assert_match(/balance/, @response.body) + assert_match(/\$37/, @response.body) end def test_update_page_with_view_method get :update_page_with_view_method assert_template nil assert_equal 'text/javascript; charset=utf-8', @response.headers["Content-Type"] - assert_match /2 people/, @response.body + assert_match(/2 people/, @response.body) end def test_should_render_html_formatted_partial_with_rjs diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb index e90fc49542..edda0d0a30 100644 --- a/actionpack/test/controller/test_test.rb +++ b/actionpack/test/controller/test_test.rb @@ -591,7 +591,7 @@ XML assert false, "expected RuntimeError, got nothing" rescue RuntimeError => error assert true - assert_match %r{@#{variable} is nil}, error.message + assert_match(%r{@#{variable} is nil}, error.message) rescue => error assert false, "expected RuntimeError, got #{error.class}" end diff --git a/actionpack/test/controller/url_for_test.rb b/actionpack/test/controller/url_for_test.rb index 2d0c019128..4c07ca4cc3 100644 --- a/actionpack/test/controller/url_for_test.rb +++ b/actionpack/test/controller/url_for_test.rb @@ -219,7 +219,7 @@ module AbstractController def test_hash_recursive_and_array_parameters url = W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :id => 101, :query => {:person => {:name => 'Bob', :position => ['prof', 'art director']}, :hobby => 'piercing'}) - assert_match %r(^/c/a/101), url + assert_match(%r(^/c/a/101), url) params = extract_params(url) assert_equal params[0], { 'query[hobby]' => 'piercing' }.to_query assert_equal params[1], { 'query[person][name]' => 'Bob' }.to_query diff --git a/actionpack/test/dispatch/cookies_test.rb b/actionpack/test/dispatch/cookies_test.rb index 360fb351df..efdc1f5d93 100644 --- a/actionpack/test/dispatch/cookies_test.rb +++ b/actionpack/test/dispatch/cookies_test.rb @@ -47,7 +47,7 @@ class CookiesTest < ActionController::TestCase cookies["user_name"] = { :value => "david", :httponly => true } head :ok end - + def authenticate_with_secure cookies["user_name"] = { :value => "david", :secure => true } head :ok @@ -133,7 +133,7 @@ class CookiesTest < ActionController::TestCase assert_cookie_header "user_name=david; path=/; HttpOnly" assert_equal({"user_name" => "david"}, @response.cookies) end - + def test_setting_cookie_with_secure get :authenticate_with_secure assert_cookie_header "user_name=david; path=/; secure" @@ -169,8 +169,8 @@ class CookiesTest < ActionController::TestCase def test_permanent_cookie get :set_permanent_cookie - assert_match /Jamie/, @response.headers["Set-Cookie"] - assert_match %r(#{20.years.from_now.utc.year}), @response.headers["Set-Cookie"] + assert_match(/Jamie/, @response.headers["Set-Cookie"]) + assert_match(%r(#{20.years.from_now.utc.year}), @response.headers["Set-Cookie"]) end def test_signed_cookie @@ -185,7 +185,7 @@ class CookiesTest < ActionController::TestCase def test_permanent_signed_cookie get :set_permanent_signed_cookie - assert_match %r(#{20.years.from_now.utc.year}), @response.headers["Set-Cookie"] + assert_match(%r(#{20.years.from_now.utc.year}), @response.headers["Set-Cookie"]) assert_equal 100, @controller.send(:cookies).signed[:remember_me] end diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index a8b8f9377b..a53d4f1edd 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -45,9 +45,9 @@ class RequestTest < ActiveSupport::TestCase e = assert_raise(ActionDispatch::RemoteIp::IpSpoofAttackError) { request.remote_ip } - assert_match /IP spoofing attack/, e.message - assert_match /HTTP_X_FORWARDED_FOR="1.1.1.1"/, e.message - assert_match /HTTP_CLIENT_IP="2.2.2.2"/, e.message + assert_match(/IP spoofing attack/, e.message) + assert_match(/HTTP_X_FORWARDED_FOR="1.1.1.1"/, e.message) + assert_match(/HTTP_CLIENT_IP="2.2.2.2"/, e.message) # turn IP Spoofing detection off. # This is useful for sites that are aimed at non-IP clients. The typical diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb index b436fb5518..3489f628ed 100644 --- a/actionpack/test/dispatch/session/cookie_store_test.rb +++ b/actionpack/test/dispatch/session/cookie_store_test.rb @@ -279,7 +279,7 @@ class CookieStoreTest < ActionDispatch::IntegrationTest def test_session_store_with_explicit_domain with_test_route_set(:domain => "example.es") do get '/set_session_value' - assert_match /domain=example\.es/, headers['Set-Cookie'] + assert_match(/domain=example\.es/, headers['Set-Cookie']) headers['Set-Cookie'] end end diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb index 5b181600e8..4ede1ab47c 100644 --- a/actionpack/test/dispatch/show_exceptions_test.rb +++ b/actionpack/test/dispatch/show_exceptions_test.rb @@ -58,15 +58,15 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest get "/", {}, {'action_dispatch.show_exceptions' => true} assert_response 500 - assert_match /puke/, body + assert_match(/puke/, body) get "/not_found", {}, {'action_dispatch.show_exceptions' => true} assert_response 404 - assert_match /#{ActionController::UnknownAction.name}/, body + assert_match(/#{ActionController::UnknownAction.name}/, body) get "/method_not_allowed", {}, {'action_dispatch.show_exceptions' => true} assert_response 405 - assert_match /ActionController::MethodNotAllowed/, body + assert_match(/ActionController::MethodNotAllowed/, body) end end @@ -96,15 +96,15 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest get "/", {}, {'action_dispatch.show_exceptions' => true} assert_response 500 - assert_match /puke/, body + assert_match(/puke/, body) get "/not_found", {}, {'action_dispatch.show_exceptions' => true} assert_response 404 - assert_match /#{ActionController::UnknownAction.name}/, body + assert_match(/#{ActionController::UnknownAction.name}/, body) get "/method_not_allowed", {}, {'action_dispatch.show_exceptions' => true} assert_response 405 - assert_match /ActionController::MethodNotAllowed/, body + assert_match(/ActionController::MethodNotAllowed/, body) end test "does not show filtered parameters" do @@ -113,6 +113,6 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest get "/", {"foo"=>"bar"}, {'action_dispatch.show_exceptions' => true, 'action_dispatch.parameter_filter' => [:foo]} assert_response 500 - assert_match ""foo"=>"[FILTERED]"", body + assert_match(""foo"=>"[FILTERED]"", body) end end diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index ec28d4442c..3abcdfbc1e 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -975,7 +975,7 @@ class AssetTagHelperNonVhostTest < ActionView::TestCase def test_should_wildcard_asset_host_between_zero_and_four @controller.config.asset_host = 'http://a%d.example.com' - assert_match %r(http://a[0123].example.com/collaboration/hieraki/images/xml.png), image_path('xml.png') + assert_match(%r(http://a[0123].example.com/collaboration/hieraki/images/xml.png), image_path('xml.png')) end def test_asset_host_without_protocol_should_use_request_protocol diff --git a/actionpack/test/template/atom_feed_helper_test.rb b/actionpack/test/template/atom_feed_helper_test.rb index 9f0a975255..36102bbc4f 100644 --- a/actionpack/test/template/atom_feed_helper_test.rb +++ b/actionpack/test/template/atom_feed_helper_test.rb @@ -203,7 +203,7 @@ class AtomFeedTest < ActionController::TestCase def test_feed_should_use_default_language_if_none_is_given with_restful_routing(:scrolls) do get :index, :id => "defaults" - assert_match %r{xml:lang="en-US"}, @response.body + assert_match(%r{xml:lang="en-US"}, @response.body) end end diff --git a/actionpack/test/template/log_subscriber_test.rb b/actionpack/test/template/log_subscriber_test.rb index eb1e548672..6fb8d39818 100644 --- a/actionpack/test/template/log_subscriber_test.rb +++ b/actionpack/test/template/log_subscriber_test.rb @@ -29,7 +29,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase wait assert_equal 1, @logger.logged(:info).size - assert_match /Rendered test\/hello_world\.erb/, @logger.logged(:info).last + assert_match(/Rendered test\/hello_world\.erb/, @logger.logged(:info).last) end def test_render_text_template @@ -37,7 +37,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase wait assert_equal 1, @logger.logged(:info).size - assert_match /Rendered text template/, @logger.logged(:info).last + assert_match(/Rendered text template/, @logger.logged(:info).last) end def test_render_inline_template @@ -45,7 +45,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase wait assert_equal 1, @logger.logged(:info).size - assert_match /Rendered inline template/, @logger.logged(:info).last + assert_match(/Rendered inline template/, @logger.logged(:info).last) end def test_render_partial_template @@ -53,7 +53,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase wait assert_equal 1, @logger.logged(:info).size - assert_match /Rendered test\/_customer.erb/, @logger.logged(:info).last + assert_match(/Rendered test\/_customer.erb/, @logger.logged(:info).last) end def test_render_partial_with_implicit_path @@ -62,7 +62,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase wait assert_equal 1, @logger.logged(:info).size - assert_match /Rendered customers\/_customer\.html\.erb/, @logger.logged(:info).last + assert_match(/Rendered customers\/_customer\.html\.erb/, @logger.logged(:info).last) end def test_render_collection_template @@ -70,7 +70,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase wait assert_equal 1, @logger.logged(:info).size - assert_match /Rendered test\/_customer.erb/, @logger.logged(:info).last + assert_match(/Rendered test\/_customer.erb/, @logger.logged(:info).last) end def test_render_collection_with_implicit_path @@ -79,7 +79,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase wait assert_equal 1, @logger.logged(:info).size - assert_match /Rendered customers\/_customer\.html\.erb/, @logger.logged(:info).last + assert_match(/Rendered customers\/_customer\.html\.erb/, @logger.logged(:info).last) end def test_render_collection_template_without_path @@ -88,6 +88,6 @@ class AVLogSubscriberTest < ActiveSupport::TestCase wait assert_equal 1, @logger.logged(:info).size - assert_match /Rendered collection/, @logger.logged(:info).last + assert_match(/Rendered collection/, @logger.logged(:info).last) end -end \ No newline at end of file +end diff --git a/actionpack/test/template/tag_helper_test.rb b/actionpack/test/template/tag_helper_test.rb index 85ac515660..cca161bc80 100644 --- a/actionpack/test/template/tag_helper_test.rb +++ b/actionpack/test/template/tag_helper_test.rb @@ -11,8 +11,8 @@ class TagHelperTest < ActionView::TestCase def test_tag_options str = tag("p", "class" => "show", :class => "elsewhere") - assert_match /class="show"/, str - assert_match /class="elsewhere"/, str + assert_match(/class="show"/, str) + assert_match(/class="elsewhere"/, str) end def test_tag_options_rejects_nil_option diff --git a/actionpack/test/template/test_case_test.rb b/actionpack/test/template/test_case_test.rb index f766c2c0b6..8526db61cc 100644 --- a/actionpack/test/template/test_case_test.rb +++ b/actionpack/test/template/test_case_test.rb @@ -112,7 +112,7 @@ module ActionView @controller.controller_path = 'test' @customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')] - assert_match /Hello: EloyHello: Manfred/, render(:partial => 'test/from_helper') + assert_match(/Hello: EloyHello: Manfred/, render(:partial => 'test/from_helper')) end end @@ -201,7 +201,7 @@ module ActionView @controller.controller_path = "test" @customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')] - assert_match /Hello: EloyHello: Manfred/, render(:file => 'test/list') + assert_match(/Hello: EloyHello: Manfred/, render(:file => 'test/list')) end test "is able to render partials from templates and also use instance variables after view has been referenced" do @@ -210,7 +210,7 @@ module ActionView view @customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')] - assert_match /Hello: EloyHello: Manfred/, render(:file => 'test/list') + assert_match(/Hello: EloyHello: Manfred/, render(:file => 'test/list')) end end -- cgit v1.2.3 From 535371e956b648daff80b1c727b609749ac7137b Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Wed, 22 Sep 2010 16:04:42 -0300 Subject: Fix indentation. --- .../controller/request_forgery_protection_test.rb | 37 +++++++++++----------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/controller/request_forgery_protection_test.rb b/actionpack/test/controller/request_forgery_protection_test.rb index 5af25a0894..2c9aa6187b 100644 --- a/actionpack/test/controller/request_forgery_protection_test.rb +++ b/actionpack/test/controller/request_forgery_protection_test.rb @@ -55,26 +55,25 @@ module RequestForgeryProtectionTests ActionController::Base.request_forgery_protection_token = nil end - def test_should_render_form_with_token_tag - get :index - assert_select 'form>div>input[name=?][value=?]', 'authenticity_token', @token - end - - def test_should_render_button_to_with_token_tag - get :show_button - assert_select 'form>div>input[name=?][value=?]', 'authenticity_token', @token - end - - def test_should_allow_get - get :index - assert_response :success - end - - def test_should_allow_post_without_token_on_unsafe_action - post :unsafe - assert_response :success - end + get :index + assert_select 'form>div>input[name=?][value=?]', 'authenticity_token', @token + end + + def test_should_render_button_to_with_token_tag + get :show_button + assert_select 'form>div>input[name=?][value=?]', 'authenticity_token', @token + end + + def test_should_allow_get + get :index + assert_response :success + end + + def test_should_allow_post_without_token_on_unsafe_action + post :unsafe + assert_response :success + end def test_should_not_allow_html_post_without_token @request.env['CONTENT_TYPE'] = Mime::URL_ENCODED_FORM.to_s -- cgit v1.2.3 From 5d773f8dedef85f3ef5d3bdebcedd72716002268 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Wed, 22 Sep 2010 16:11:15 -0300 Subject: Remove warning "URI.unescape is obsolete" from actionpack. --- actionpack/lib/action_controller/caching/actions.rb | 6 +++++- actionpack/lib/action_controller/caching/pages.rb | 6 +++++- actionpack/lib/action_controller/test_case.rb | 6 +++++- actionpack/lib/action_dispatch/routing/mapper.rb | 18 +++++++++--------- actionpack/lib/action_dispatch/routing/route_set.rb | 12 ++++++++++-- 5 files changed, 34 insertions(+), 14 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb index a3591eafbe..e00f4a7b1d 100644 --- a/actionpack/lib/action_controller/caching/actions.rb +++ b/actionpack/lib/action_controller/caching/actions.rb @@ -161,7 +161,11 @@ module ActionController #:nodoc: def normalize!(path) path << 'index' if path[-1] == ?/ path << ".#{extension}" if extension and !path.ends_with?(extension) - URI.unescape(path) + uri_parser.unescape(path) + end + + def uri_parser + @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI end end end diff --git a/actionpack/lib/action_controller/caching/pages.rb b/actionpack/lib/action_controller/caching/pages.rb index 4f7a5d3f55..b845c6f6f9 100644 --- a/actionpack/lib/action_controller/caching/pages.rb +++ b/actionpack/lib/action_controller/caching/pages.rb @@ -99,7 +99,7 @@ module ActionController #:nodoc: private def page_cache_file(path) - name = (path.empty? || path == "/") ? "/index" : URI.unescape(path.chomp('/')) + name = (path.empty? || path == "/") ? "/index" : uri_parser.unescape(path.chomp('/')) name << page_cache_extension unless (name.split('/').last || name).include? '.' return name end @@ -111,6 +111,10 @@ module ActionController #:nodoc: def instrument_page_cache(name, path) ActiveSupport::Notifications.instrument("#{name}.action_controller", :path => path){ yield } end + + def uri_parser + @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI + end end # Expires the page that was cached with the +options+ as a key. Example: diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index f5ae1c3fff..eeffce1612 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -127,7 +127,11 @@ module ActionController class Result < ::Array #:nodoc: def to_s() join '/' end def self.new_escaped(strings) - new strings.collect {|str| URI.unescape str} + new strings.collect {|str| uri_parser.unescape str} + end + + def uri_parser + @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI end end diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index fe85acb94e..8ddf67c0cf 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -395,10 +395,10 @@ module ActionDispatch # namespace "admin" do # resources :posts, :comments # end - # + # # This will create a number of routes for each of the posts and comments # controller. For Admin::PostsController, Rails will create: - # + # # GET /admin/photos # GET /admin/photos/new # POST /admin/photos @@ -406,33 +406,33 @@ module ActionDispatch # GET /admin/photos/1/edit # PUT /admin/photos/1 # DELETE /admin/photos/1 - # + # # If you want to route /photos (without the prefix /admin) to # Admin::PostsController, you could use - # + # # scope :module => "admin" do # resources :posts, :comments # end # # or, for a single case - # + # # resources :posts, :module => "admin" - # + # # If you want to route /admin/photos to PostsController # (without the Admin:: module prefix), you could use - # + # # scope "/admin" do # resources :posts, :comments # end # # or, for a single case - # + # # resources :posts, :path => "/admin" # # In each of these cases, the named routes remain the same as if you did # not use scope. In the last case, the following paths map to # PostsController: - # + # # GET /admin/photos # GET /admin/photos/new # POST /admin/photos diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 1a5f21bd09..b885a573d5 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -66,7 +66,11 @@ module ActionDispatch end def split_glob_param!(params) - params[@glob_param] = params[@glob_param].split('/').map { |v| URI.unescape(v) } + params[@glob_param] = params[@glob_param].split('/').map { |v| uri_parser.unescape(v) } + end + + def uri_parser + @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI end end @@ -543,7 +547,7 @@ module ActionDispatch params.each do |key, value| if value.is_a?(String) value = value.dup.force_encoding(Encoding::BINARY) if value.encoding_aware? - params[key] = URI.unescape(value) + params[key] = uri_parser.unescape(value) end end @@ -560,6 +564,10 @@ module ActionDispatch end private + def uri_parser + @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI + end + def handle_positional_args(options) return unless args = options.delete(:_positional_args) -- cgit v1.2.3 From 5ced275ac1fc8d52654521bf61742cb7f2f0d796 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 24 Sep 2010 13:01:31 -0300 Subject: Remove old method before redefining it. --- actionpack/lib/action_dispatch/routing/route_set.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index b885a573d5..ebb9e194c7 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -161,6 +161,7 @@ module ActionDispatch # We use module_eval to avoid leaks @module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1 + remove_method :#{selector} if method_defined?(:#{selector}) def #{selector}(*args) options = args.extract_options! @@ -194,6 +195,7 @@ module ActionDispatch hash_access_method = hash_access_name(name, kind) @module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1 + remove_method :#{selector} if method_defined?(:#{selector}) def #{selector}(*args) url_for(#{hash_access_method}(*args)) end -- cgit v1.2.3 From bb2f53b4090768e4750af66c6fed15d6596bb11c Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 24 Sep 2010 13:04:51 -0300 Subject: Initialize @as before plural method is called. --- actionpack/lib/action_dispatch/routing/mapper.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 8ddf67c0cf..f6d625e7c3 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -676,6 +676,7 @@ module ActionDispatch DEFAULT_ACTIONS = [:show, :create, :update, :destroy, :new, :edit] def initialize(entities, options) + @as = nil @name = entities.to_s @path = (options.delete(:path) || @name).to_s @controller = (options.delete(:controller) || plural).to_s -- cgit v1.2.3 From b9fa46ca97b448d8cf5b285750341da50d417f8a Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 24 Sep 2010 15:39:59 -0300 Subject: Initialize @_etag. --- actionpack/lib/action_dispatch/http/response.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index ff5e96fdf7..a5d082c6a2 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -43,6 +43,7 @@ module ActionDispatch # :nodoc: @writer = lambda { |x| @body << x } @block = nil @length = 0 + @_etag = nil @status, @header = status, header self.body = body -- cgit v1.2.3 From 986bad6a3b89fed39c02f87068210f0c74e083cd Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 24 Sep 2010 15:40:14 -0300 Subject: Remove warning "too many arguments for format string" when interpolating with empty hash. --- actionpack/lib/action_dispatch/routing/mapper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index f6d625e7c3..5e95d8ed39 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -350,7 +350,7 @@ module ActionDispatch options = args.last.is_a?(Hash) ? args.pop : {} path = args.shift || block - path_proc = path.is_a?(Proc) ? path : proc { |params| path % params } + path_proc = path.is_a?(Proc) ? path : proc { |params| params.empty? ? path : (path % params) } status = options[:status] || 301 lambda do |env| -- cgit v1.2.3 From cd681681e655b155b8f739d8042389a58be28111 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 24 Sep 2010 15:41:01 -0300 Subject: Initialize @_routes if it doesn't exists. --- actionpack/lib/action_dispatch/routing/url_for.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb index e836cf7c8e..045c9ec77d 100644 --- a/actionpack/lib/action_dispatch/routing/url_for.rb +++ b/actionpack/lib/action_dispatch/routing/url_for.rb @@ -128,6 +128,7 @@ module ActionDispatch when String options when nil, Hash + @_routes ||= nil _routes.url_for((options || {}).reverse_merge!(url_options).symbolize_keys) else polymorphic_url(options) -- cgit v1.2.3 From 24ef32fe93a701c0b65a0aedf7c361ff3364c42b Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 24 Sep 2010 15:41:19 -0300 Subject: Ask is @controller is defined to avoid warning. --- actionpack/lib/action_dispatch/testing/assertions/routing.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index c5fed1fc8f..4293ed19e1 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -171,7 +171,7 @@ module ActionDispatch # ROUTES TODO: These assertions should really work in an integration context def method_missing(selector, *args, &block) - if @controller && @routes && @routes.named_routes.helpers.include?(selector) + if defined?(@controller) && @controller && @routes && @routes.named_routes.helpers.include?(selector) @controller.send(selector, *args, &block) else super -- cgit v1.2.3 From 53b91b11ccb18551d6193dc5e96571c24c688e6a Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 24 Sep 2010 15:41:42 -0300 Subject: Avoid uninitialized variable warning, reuse @integration_session. --- .../lib/action_dispatch/testing/integration.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 50bdad1b1c..3204115e9f 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -182,6 +182,7 @@ module ActionDispatch reset! end + remove_method :default_url_options def default_url_options { :host => host, :protocol => https? ? "https" : "http" } end @@ -319,10 +320,10 @@ module ActionDispatch %w(get post put head delete cookies assigns xml_http_request xhr get_via_redirect post_via_redirect).each do |method| define_method(method) do |*args| - reset! unless @integration_session + reset! unless integration_session # reset the html_document variable, but only for new get/post calls @html_document = nil unless %w(cookies assigns).include?(method) - @integration_session.__send__(method, *args).tap do + integration_session.__send__(method, *args).tap do copy_session_variables! end end @@ -347,7 +348,7 @@ module ActionDispatch # Copy the instance variables from the current session instance into the # test instance. def copy_session_variables! #:nodoc: - return unless @integration_session + return unless integration_session %w(controller response request).each do |var| instance_variable_set("@#{var}", @integration_session.__send__(var)) end @@ -357,21 +358,26 @@ module ActionDispatch include ActionDispatch::Routing::UrlFor def url_options - reset! unless @integration_session - @integration_session.url_options + reset! unless integration_session + integration_session.url_options end # Delegate unhandled messages to the current session instance. def method_missing(sym, *args, &block) - reset! unless @integration_session - if @integration_session.respond_to?(sym) - @integration_session.__send__(sym, *args, &block).tap do + reset! unless integration_session + if integration_session.respond_to?(sym) + integration_session.__send__(sym, *args, &block).tap do copy_session_variables! end else super end end + + private + def integration_session + @integration_session ||= nil + end end end -- cgit v1.2.3 From 0cb1d87cd5e2a76c9cd12b5387dd8f25318d494b Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 24 Sep 2010 15:42:27 -0300 Subject: Remove duplicated test. --- actionpack/test/dispatch/routing_test.rb | 8 -------- 1 file changed, 8 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index bdef04efc6..53b13501b2 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -1216,14 +1216,6 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - def test_index - with_test_routes do - assert_equal '/info', info_path - get '/info' - assert_equal 'projects#info', @response.body - end - end - def test_match_shorthand_with_no_scope with_test_routes do assert_equal '/account/overview', account_overview_path -- cgit v1.2.3 From dafb4bd33ba26bf8ca3455db270fee843c8bd2fd Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Wed, 22 Sep 2010 16:53:02 -0300 Subject: Don't shadow outer local variables. --- actionpack/lib/action_dispatch/testing/test_request.rb | 2 +- actionpack/lib/action_view/testing/resolvers.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/testing/test_request.rb b/actionpack/lib/action_dispatch/testing/test_request.rb index c587a36930..abc2e9afcc 100644 --- a/actionpack/lib/action_dispatch/testing/test_request.rb +++ b/actionpack/lib/action_dispatch/testing/test_request.rb @@ -66,7 +66,7 @@ module ActionDispatch def accept=(mime_types) @env.delete('action_dispatch.request.accepts') - @env['HTTP_ACCEPT'] = Array(mime_types).collect { |mime_types| mime_types.to_s }.join(",") + @env['HTTP_ACCEPT'] = Array(mime_types).collect { |mime_type| mime_type.to_s }.join(",") end def cookies diff --git a/actionpack/lib/action_view/testing/resolvers.rb b/actionpack/lib/action_view/testing/resolvers.rb index 97de2471cf..b2b62528a9 100644 --- a/actionpack/lib/action_view/testing/resolvers.rb +++ b/actionpack/lib/action_view/testing/resolvers.rb @@ -22,10 +22,10 @@ module ActionView #:nodoc: end templates = [] - @hash.select { |k,v| k =~ /^#{query}$/ }.each do |path, source| - handler, format = extract_handler_and_format(path, formats) - templates << Template.new(source, path, handler, - :virtual_path => path, :format => format) + @hash.select { |k,v| k =~ /^#{query}$/ }.each do |_path, source| + handler, format = extract_handler_and_format(_path, formats) + templates << Template.new(source, _path, handler, + :virtual_path => _path, :format => format) end templates.sort_by {|t| -t.identifier.match(/^#{query}$/).captures.reject(&:blank?).size } -- cgit v1.2.3 From 583ddf22a2a9d9f903ff0f2dba72cc04e80a378f Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Wed, 22 Sep 2010 16:47:22 -0300 Subject: Remove more warnings shadowing outer local variable. --- actionpack/lib/action_controller/metal/helpers.rb | 6 +++--- .../action_controller/vendor/html-scanner/html/node.rb | 6 +++--- .../lib/action_dispatch/testing/assertions/selector.rb | 4 ++-- actionpack/test/dispatch/response_test.rb | 16 ++++++++-------- actionpack/test/template/text_helper_test.rb | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/metal/helpers.rb b/actionpack/lib/action_controller/metal/helpers.rb index 4d5d534c75..f10fc66b52 100644 --- a/actionpack/lib/action_controller/metal/helpers.rb +++ b/actionpack/lib/action_controller/metal/helpers.rb @@ -96,9 +96,9 @@ module ActionController def all_helpers_from_path(path) helpers = [] - Array.wrap(path).each do |path| - extract = /^#{Regexp.quote(path.to_s)}\/?(.*)_helper.rb$/ - helpers += Dir["#{path}/**/*_helper.rb"].map { |file| file.sub(extract, '\1') } + Array.wrap(path).each do |p| + extract = /^#{Regexp.quote(p.to_s)}\/?(.*)_helper.rb$/ + helpers += Dir["#{p}/**/*_helper.rb"].map { |file| file.sub(extract, '\1') } end helpers.sort! helpers.uniq! diff --git a/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb b/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb index 85250721e7..c82324dee6 100644 --- a/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb +++ b/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb @@ -18,12 +18,12 @@ module HTML #:nodoc: hash[k] = Conditions.new(v) when :children hash[k] = v = keys_to_symbols(v) - v.each do |k,v2| - case k + v.each do |key,v2| + case key when :count, :greater_than, :less_than # keys are valid, and require no further processing when :only - v[k] = Conditions.new(v2) + v[key] = Conditions.new(v2) else raise "illegal key #{k.inspect} => #{v2.inspect}" end diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb index e1015c62cd..86fba87586 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb @@ -513,8 +513,8 @@ module ActionDispatch node.content.gsub(/)?/m) { Rack::Utils.escapeHTML($1) } end - selected = elements.map do |element| - text = element.children.select{ |c| not c.tag? }.map{ |c| fix_content[c] }.join + selected = elements.map do |ele| + text = ele.children.select{ |c| not c.tag? }.map{ |c| fix_content[c] }.join root = HTML::Document.new(CGI.unescapeHTML("#{text}")).root css_select(root, "encoded:root", &block)[0] end diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb index c20fa10f63..1efb664304 100644 --- a/actionpack/test/dispatch/response_test.rb +++ b/actionpack/test/dispatch/response_test.rb @@ -120,10 +120,10 @@ class ResponseTest < ActiveSupport::TestCase end test "read cache control" do - resp = ActionDispatch::Response.new.tap { |resp| - resp.cache_control[:public] = true - resp.etag = '123' - resp.body = 'Hello' + resp = ActionDispatch::Response.new.tap { |_resp| + _resp.cache_control[:public] = true + _resp.etag = '123' + _resp.body = 'Hello' } resp.to_a @@ -135,10 +135,10 @@ class ResponseTest < ActiveSupport::TestCase end test "read charset and content type" do - resp = ActionDispatch::Response.new.tap { |resp| - resp.charset = 'utf-16' - resp.content_type = Mime::XML - resp.body = 'Hello' + resp = ActionDispatch::Response.new.tap { |_resp| + _resp.charset = 'utf-16' + _resp.content_type = Mime::XML + _resp.body = 'Hello' } resp.to_a diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index 88ec6fc740..43e920f9b5 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -491,7 +491,7 @@ class TextHelperTest < ActionView::TestCase url = "http://api.rubyonrails.com/Foo.html" email = "fantabulous@shiznadel.ic" - assert_equal %(

#{url[0...7]}...
#{email[0...7]}...

), auto_link("

#{url}
#{email}

") { |url| truncate(url, :length => 10) } + assert_equal %(

#{url[0...7]}...
#{email[0...7]}...

), auto_link("

#{url}
#{email}

") { |u| truncate(u, :length => 10) } end def test_auto_link_with_block_with_html -- cgit v1.2.3 From 1ed18fcc91e8e908f26291f6ec9ffbd61e48195f Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 24 Sep 2010 16:07:01 -0300 Subject: Initialize @cookies. --- actionpack/lib/action_dispatch/testing/test_request.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/testing/test_request.rb b/actionpack/lib/action_dispatch/testing/test_request.rb index abc2e9afcc..cf440a1fad 100644 --- a/actionpack/lib/action_dispatch/testing/test_request.rb +++ b/actionpack/lib/action_dispatch/testing/test_request.rb @@ -13,6 +13,7 @@ module ActionDispatch env = Rails.application.env_config.merge(env) if defined?(Rails.application) super(DEFAULT_ENV.merge(env)) + @cookies = nil self.host = 'test.host' self.remote_addr = '0.0.0.0' self.user_agent = 'Rails Testing' -- cgit v1.2.3 From 74d7664b607a7ca2770c937a832b3339d7bf8203 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 24 Sep 2010 16:07:17 -0300 Subject: Avoid uninitialized variable warning. --- actionpack/lib/action_view/helpers/date_helper.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index 9891478606..3aee4fb773 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -923,6 +923,7 @@ module ActionView private def datetime_selector(options, html_options) datetime = value(object) || default_datetime(options) + @auto_index ||= nil options = options.dup options[:field_name] = @method_name -- cgit v1.2.3 From e7c833fca9c18807245bf1a75cbb212a626e278c Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 24 Sep 2010 16:07:37 -0300 Subject: Define @emitted_hidden_id if it doesn't exists and reuse it if it does. --- actionpack/lib/action_view/helpers/form_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 3ebc6601e5..8bae6d2796 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1237,7 +1237,7 @@ module ActionView end def emitted_hidden_id? - @emitted_hidden_id + @emitted_hidden_id ||= nil end private -- cgit v1.2.3 From 2f59cd6fd6c54bd55d4cd55f59cae413e961626a Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 24 Sep 2010 16:08:04 -0300 Subject: Remove method previous method if already defined. --- actionpack/lib/action_view/test_case.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index ff35fb7df4..32fd8c5e21 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -127,6 +127,7 @@ module ActionView def say_no_to_protect_against_forgery! _helpers.module_eval do + remove_method :protect_against_forgery? if method_defined?(:protect_against_forgery?) def protect_against_forgery? false end -- cgit v1.2.3 From d95a16c5263d1fa53914540ee023e9031d884a22 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 24 Sep 2010 16:52:47 -0300 Subject: Initialize @_request and @_response. --- actionpack/lib/action_controller/metal.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb index 96cb5977d5..7fcc4e7211 100644 --- a/actionpack/lib/action_controller/metal.rb +++ b/actionpack/lib/action_controller/metal.rb @@ -85,6 +85,8 @@ module ActionController def initialize(*) @_headers = {"Content-Type" => "text/html"} @_status = 200 + @_request = nil + @_response = nil super end @@ -99,7 +101,7 @@ module ActionController # Basic implementations for content_type=, location=, and headers are # provided to reduce the dependency on the RackDelegation module # in Renderer and Redirector. - + def content_type=(type) headers["Content-Type"] = type.to_s end -- cgit v1.2.3 From d0621fde885ca0b61c75d0fd0b03bd431d736b42 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 24 Sep 2010 16:53:06 -0300 Subject: Avoid uninitialized variable warning. --- actionpack/lib/action_controller/test_case.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index eeffce1612..676828957a 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -421,7 +421,7 @@ module ActionController @request.env.delete('PATH_INFO') - if @controller + if defined?(@controller) && @controller @controller.request = @request @controller.params = {} end -- cgit v1.2.3 From c2940a6bf4b101eafc0c9d968f4e702473156613 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 24 Sep 2010 16:57:28 -0300 Subject: Refactor method to avoid warnings and not run unnecessary code. --- .../action_dispatch/testing/assertions/routing.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index 4293ed19e1..0cdc69760b 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -146,25 +146,25 @@ module ActionDispatch # def with_routing old_routes, @routes = @routes, ActionDispatch::Routing::RouteSet.new - old_controller, @controller = @controller, @controller.clone if @controller - _routes = @routes - - # Unfortunately, there is currently an abstraction leak between AC::Base - # and AV::Base which requires having the URL helpers in both AC and AV. - # To do this safely at runtime for tests, we need to bump up the helper serial - # to that the old AV subclass isn't cached. - # - # TODO: Make this unnecessary - if @controller + if defined?(@controller) && @controller + old_controller, @controller = @controller, @controller.clone + + # Unfortunately, there is currently an abstraction leak between AC::Base + # and AV::Base which requires having the URL helpers in both AC and AV. + # To do this safely at runtime for tests, we need to bump up the helper serial + # to that the old AV subclass isn't cached. + # + # TODO: Make this unnecessary @controller.singleton_class.send(:include, _routes.url_helpers) @controller.view_context_class = Class.new(@controller.view_context_class) do include _routes.url_helpers end end + _routes = @routes yield @routes ensure @routes = old_routes - if @controller + if defined?(@controller) && @controller @controller = old_controller end end -- cgit v1.2.3 From bb71f182ddf53333d4b3cabe111d7ba58d8cbe23 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 24 Sep 2010 16:59:57 -0300 Subject: Rename duplicated test name. --- actionpack/test/controller/selector_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/test/controller/selector_test.rb b/actionpack/test/controller/selector_test.rb index 23ccbf6987..8ce9e43402 100644 --- a/actionpack/test/controller/selector_test.rb +++ b/actionpack/test/controller/selector_test.rb @@ -471,7 +471,7 @@ class SelectorTest < Test::Unit::TestCase end - def test_first_and_last + def test_only_child_and_only_type_first_and_last # Only child. parse(%Q{
}) select("table:only-child") -- cgit v1.2.3 From 023c2020b3f94dadb86ead782c07006732d9ab56 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 24 Sep 2010 17:02:26 -0300 Subject: Initialize @_routes if not defined yet, avoiding more warnings. --- actionpack/lib/action_controller/metal/url_for.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/metal/url_for.rb b/actionpack/lib/action_controller/metal/url_for.rb index 85c6b0a9b5..f43fc3f609 100644 --- a/actionpack/lib/action_controller/metal/url_for.rb +++ b/actionpack/lib/action_controller/metal/url_for.rb @@ -6,6 +6,7 @@ module ActionController def url_options options = {} + @_routes ||= nil if _routes.equal?(env["action_dispatch.routes"]) options[:script_name] = request.script_name.dup end -- cgit v1.2.3 From 50decfbc0e2e58961cc3665710922860d38ee2fb Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 24 Sep 2010 17:07:54 -0300 Subject: _routes must be inside @controller conditional. --- actionpack/lib/action_dispatch/testing/assertions/routing.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index 0cdc69760b..1390b74a95 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -148,6 +148,7 @@ module ActionDispatch old_routes, @routes = @routes, ActionDispatch::Routing::RouteSet.new if defined?(@controller) && @controller old_controller, @controller = @controller, @controller.clone + _routes = @routes # Unfortunately, there is currently an abstraction leak between AC::Base # and AV::Base which requires having the URL helpers in both AC and AV. @@ -160,7 +161,6 @@ module ActionDispatch include _routes.url_helpers end end - _routes = @routes yield @routes ensure @routes = old_routes -- cgit v1.2.3 From 918dc27345319fbabf25a43bd65b613878b3a66e Mon Sep 17 00:00:00 2001 From: thedarkone Date: Mon, 27 Sep 2010 14:50:39 +0200 Subject: Compile ActionController::Base.config's methods to avoid method_missing overhead. --- actionpack/lib/action_controller/railtie.rb | 10 ++++++++++ actionpack/lib/action_view/base.rb | 3 +-- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index aea28d9265..4c57d82f1c 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -26,6 +26,10 @@ module ActionController options.stylesheets_dir ||= paths.public.stylesheets.to_a.first options.page_cache_directory ||= paths.public.to_a.first + # make sure readers methods get compiled + options.asset_path ||= nil + options.asset_host ||= nil + ActiveSupport.on_load(:action_controller) do include app.routes.mounted_helpers extend ::AbstractController::Railties::RoutesHelpers.with(app.routes) @@ -33,5 +37,11 @@ module ActionController options.each { |k,v| send("#{k}=", v) } end end + + config.after_initialize do + ActiveSupport.on_load(:action_controller) do + config.crystalize! if config.respond_to?(:crystalize!) + end + end end end diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 3fa46d0f43..0bef3e3a08 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -209,8 +209,7 @@ module ActionView #:nodoc: @_request = controller.request if controller.respond_to?(:request) end - config = controller && controller.respond_to?(:config) ? controller.config : {} - @_config = ActiveSupport::InheritableOptions.new(config) + @_config = controller && controller.respond_to?(:config) ? controller.config.inheritable_copy : {} @_content_for = Hash.new { |h,k| h[k] = ActiveSupport::SafeBuffer.new } @_virtual_path = nil -- cgit v1.2.3 From 05e53b4c1a3422131f73598848b0332cdc793f69 Mon Sep 17 00:00:00 2001 From: thedarkone Date: Wed, 22 Sep 2010 20:18:05 +0200 Subject: Optimize relative_url_root rewriting code. --- actionpack/lib/action_view/helpers/asset_tag_helper.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 687cb83d75..bf57321e86 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -718,6 +718,10 @@ module ActionView "#{host}#{source}" end + def rewrite_relative_url_root(source, relative_url_root) + relative_url_root && !source.starts_with?("#{relative_url_root}/") ? "#{relative_url_root}#{source}" : source + end + # Add the the extension +ext+ if not present. Return full URLs otherwise untouched. # Prefix with /dir/ if lacking a leading +/+. Account for relative URL # roots. Rewrite the asset path for cache-busting asset ids. Include @@ -733,9 +737,7 @@ module ActionView source = rewrite_asset_path(source, config.asset_path) has_request = controller.respond_to?(:request) - if has_request && include_host && source !~ %r{^#{controller.config.relative_url_root}/} - source = "#{controller.config.relative_url_root}#{source}" - end + source = rewrite_relative_url_root(source, controller.config.relative_url_root) if has_request && include_host source = rewrite_host_and_protocol(source, has_request) if include_host source -- cgit v1.2.3 From 7b2d51817d58336324bce5de422ff82fcab8e18a Mon Sep 17 00:00:00 2001 From: thedarkone Date: Wed, 22 Sep 2010 22:38:13 +0200 Subject: Make asset extension rewriting faster. --- actionpack/lib/action_view/helpers/asset_tag_helper.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index bf57321e86..7576177392 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -705,9 +705,15 @@ module ActionView private - def rewrite_extension?(source, dir, ext) - source_ext = File.extname(source)[1..-1] - ext && (source_ext.blank? || (ext != source_ext && File.exist?(File.join(config.assets_dir, dir, "#{source}.#{ext}")))) + def rewrite_extension(source, dir, ext) + source_ext = File.extname(source) + + if source_ext.empty? + "#{source}.#{ext}" + elsif ext != source_ext[1..-1] + with_ext = "#{source}.#{ext}" + with_ext if File.exist?(File.join(config.assets_dir, dir, with_ext)) + end || source end def rewrite_host_and_protocol(source, has_request) @@ -729,8 +735,8 @@ module ActionView def compute_public_path(source, dir, ext = nil, include_host = true) return source if is_uri?(source) - source += ".#{ext}" if rewrite_extension?(source, dir, ext) - source = "/#{dir}/#{source}" unless source[0] == ?/ + source = rewrite_extension(source, dir, ext) if ext + source = "/#{dir}/#{source}" unless source[0] == ?/ if controller.respond_to?(:env) && controller.env["action_dispatch.asset_path"] source = rewrite_asset_path(source, controller.env["action_dispatch.asset_path"]) end -- cgit v1.2.3 From 86bcccf8dfced5e9428407a71f02c1dcc186f2ba Mon Sep 17 00:00:00 2001 From: thedarkone Date: Thu, 23 Sep 2010 18:08:43 +0200 Subject: No need to create a separate lambda for each call. --- .../lib/action_dispatch/routing/route_set.rb | 29 +++++++++++----------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 1a5f21bd09..60b1342d55 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -334,6 +334,19 @@ module ActionDispatch end class Generator #:nodoc: + PARAMETERIZE = { + :parameterize => lambda do |name, value| + if name == :controller + value + elsif value.is_a?(Array) + value.map { |v| Rack::Mount::Utils.escape_uri(v.to_param) }.join('/') + else + return nil unless param = value.to_param + param.split('/').map { |v| Rack::Mount::Utils.escape_uri(v) }.join("/") + end + end + } + attr_reader :options, :recall, :set, :named_route def initialize(options, recall, set, extras = false) @@ -422,7 +435,7 @@ module ActionDispatch end def generate - path, params = @set.set.generate(:path_info, named_route, options, recall, opts) + path, params = @set.set.generate(:path_info, named_route, options, recall, PARAMETERIZE) raise_routing_error unless path @@ -436,20 +449,6 @@ module ActionDispatch raise_routing_error end - def opts - parameterize = lambda do |name, value| - if name == :controller - value - elsif value.is_a?(Array) - value.map { |v| Rack::Mount::Utils.escape_uri(v.to_param) }.join('/') - else - return nil unless param = value.to_param - param.split('/').map { |v| Rack::Mount::Utils.escape_uri(v) }.join("/") - end - end - {:parameterize => parameterize} - end - def raise_routing_error raise ActionController::RoutingError.new("No route matches #{options.inspect}") end -- cgit v1.2.3 From 8fdb34b2373b13eee24a403a3af398cddb2a5ad0 Mon Sep 17 00:00:00 2001 From: thedarkone Date: Mon, 27 Sep 2010 15:11:19 +0200 Subject: Cache url_options on a per-request basis. --- actionpack/lib/action_controller/metal/url_for.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/metal/url_for.rb b/actionpack/lib/action_controller/metal/url_for.rb index 85c6b0a9b5..ef1071bb3d 100644 --- a/actionpack/lib/action_controller/metal/url_for.rb +++ b/actionpack/lib/action_controller/metal/url_for.rb @@ -5,16 +5,18 @@ module ActionController include AbstractController::UrlFor def url_options - options = {} - if _routes.equal?(env["action_dispatch.routes"]) - options[:script_name] = request.script_name.dup - end + @_url_options ||= begin + options = {} + if _routes.equal?(env["action_dispatch.routes"]) + options[:script_name] = request.script_name.dup + end - super.merge(options).reverse_merge( - :host => request.host_with_port, - :protocol => request.protocol, - :_path_segments => request.symbolized_path_parameters - ) + super.merge(options).reverse_merge( + :host => request.host_with_port, + :protocol => request.protocol, + :_path_segments => request.symbolized_path_parameters + ).freeze + end end end end -- cgit v1.2.3 From e12e2fb4f660da479110b35b375694bf267aedfb Mon Sep 17 00:00:00 2001 From: thedarkone Date: Mon, 27 Sep 2010 17:37:40 +0200 Subject: Cache 2 of Request's commonly called methods. --- actionpack/lib/action_dispatch/http/url.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/http/url.rb b/actionpack/lib/action_dispatch/http/url.rb index 2e39d0dbc2..3e5cd6a2f9 100644 --- a/actionpack/lib/action_dispatch/http/url.rb +++ b/actionpack/lib/action_dispatch/http/url.rb @@ -15,12 +15,12 @@ module ActionDispatch # Returns 'https://' if this is an SSL request and 'http://' otherwise. def protocol - ssl? ? 'https://' : 'http://' + @protocol ||= ssl? ? 'https://' : 'http://' end # Is this an SSL request? def ssl? - @env['HTTPS'] == 'on' || @env['HTTP_X_FORWARDED_PROTO'] == 'https' + @ssl ||= @env['HTTPS'] == 'on' || @env['HTTP_X_FORWARDED_PROTO'] == 'https' end # Returns the \host for this request, such as "example.com". -- cgit v1.2.3 From 7cee1587f14638e61a33d12114a0d5ae2620d62b Mon Sep 17 00:00:00 2001 From: thedarkone Date: Sat, 25 Sep 2010 16:15:21 +0200 Subject: options[:action] is very likely to be nil. --- actionpack/lib/action_dispatch/routing/polymorphic_routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb index 02ba5236ee..eaef09d445 100644 --- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb +++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb @@ -105,7 +105,7 @@ module ActionDispatch else [ record_or_hash_or_array ] end - inflection = if options[:action].to_s == "new" + inflection = if options[:action] && options[:action].to_s == "new" args.pop :singular elsif (record.respond_to?(:persisted?) && !record.persisted?) -- cgit v1.2.3 From e1bccc5169ba18238aa0bde720384efc74c533b0 Mon Sep 17 00:00:00 2001 From: thedarkone Date: Sat, 25 Sep 2010 16:40:53 +0200 Subject: Simple .empty? test will do fine here (rails_asset_id returns nice strings). --- actionpack/lib/action_view/helpers/asset_tag_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 7576177392..59d1c8b7eb 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -810,7 +810,7 @@ module ActionView end asset_id = rails_asset_id(source) - if asset_id.blank? + if asset_id.empty? source else source + "?#{asset_id}" -- cgit v1.2.3 From 70357666bc86629c8d10501209105b144855ddbc Mon Sep 17 00:00:00 2001 From: thedarkone Date: Sat, 25 Sep 2010 16:42:35 +0200 Subject: Do a single string interpolation. --- actionpack/lib/action_view/helpers/asset_tag_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 59d1c8b7eb..efd238c692 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -813,7 +813,7 @@ module ActionView if asset_id.empty? source else - source + "?#{asset_id}" + "#{source}?#{asset_id}" end end -- cgit v1.2.3 From 5b81d1f3ef1f1b06495eadcc1c2d110d76ac1de3 Mon Sep 17 00:00:00 2001 From: thedarkone Date: Mon, 27 Sep 2010 17:42:32 +0200 Subject: Hash#empty? is faster than Enumerable#any? when used on a Hash. --- actionpack/lib/action_dispatch/routing/route_set.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 60b1342d55..eeec10a403 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -443,7 +443,7 @@ module ActionDispatch return [path, params.keys] if @extras - path << "?#{params.to_query}" if params.any? + path << "?#{params.to_query}" unless params.empty? path rescue Rack::Mount::RoutingError raise_routing_error -- cgit v1.2.3 From 7d9f605f8072ef473e2c30800b91493b56af5b2b Mon Sep 17 00:00:00 2001 From: thedarkone Date: Sun, 26 Sep 2010 14:04:51 +0200 Subject: Clean up url_for. --- actionpack/lib/action_view/helpers/url_helper.rb | 4 +--- 1 file changed, 1 insertion(+), 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 f8147840ed..8d1def05de 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -95,7 +95,7 @@ module ActionView # # => javascript:history.back() def url_for(options = {}) options ||= {} - url = case options + case options when String options when Hash @@ -106,8 +106,6 @@ module ActionView else polymorphic_path(options) end - - url end # Creates a link tag of the given +name+ using a URL created by the set -- cgit v1.2.3 From dcabc6c04301a44d875447e4f88534ca04a538d6 Mon Sep 17 00:00:00 2001 From: thedarkone Date: Sun, 26 Sep 2010 14:24:48 +0200 Subject: Remove dead code. --- actionpack/lib/action_view/helpers/url_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 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 8d1def05de..98ea75502f 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -591,9 +591,9 @@ module ActionView html_options['data-remote'] = 'true' end - confirm = html_options.delete("confirm") - method, href = html_options.delete("method"), html_options['href'] + confirm = html_options.delete('confirm') + method = html_options.delete('method') add_confirm_to_attributes!(html_options, confirm) if confirm add_method_to_attributes!(html_options, method) if method -- cgit v1.2.3 From b127e0cac97886d9fcaaea7b91f88becd2fcff2c Mon Sep 17 00:00:00 2001 From: thedarkone Date: Mon, 27 Sep 2010 17:43:27 +0200 Subject: Performance: refactor convert_options_to_data_attributes. --- actionpack/lib/action_view/helpers/url_helper.rb | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 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 98ea75502f..1c3ca78d28 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -584,20 +584,24 @@ module ActionView private def convert_options_to_data_attributes(options, html_options) - html_options = {} if html_options.nil? - html_options = html_options.stringify_keys + if html_options.nil? + link_to_remote_options?(options) ? {'data-remote' => 'true'} : {} + else + html_options = html_options.stringify_keys + html_options['data-remote'] = 'true' if link_to_remote_options?(options) || link_to_remote_options?(html_options) - if (options.is_a?(Hash) && options.key?('remote') && options.delete('remote')) || (html_options.is_a?(Hash) && html_options.key?('remote') && html_options.delete('remote')) - html_options['data-remote'] = 'true' - end + confirm = html_options.delete('confirm') + method = html_options.delete('method') + add_confirm_to_attributes!(html_options, confirm) if confirm + add_method_to_attributes!(html_options, method) if method - confirm = html_options.delete('confirm') - method = html_options.delete('method') - add_confirm_to_attributes!(html_options, confirm) if confirm - add_method_to_attributes!(html_options, method) if method + html_options + end + end - html_options + def link_to_remote_options?(options) + options.is_a?(Hash) && options.key?('remote') && options.delete('remote') end def add_confirm_to_attributes!(html_options, confirm) -- cgit v1.2.3 From bb47927d914480218b003d322c8e8ebcd388093e Mon Sep 17 00:00:00 2001 From: thedarkone Date: Mon, 27 Sep 2010 17:44:11 +0200 Subject: Convert unless/else into if/else. --- actionpack/lib/action_dispatch/routing/polymorphic_routes.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb index eaef09d445..49e237f8db 100644 --- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb +++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb @@ -168,10 +168,7 @@ module ActionDispatch end def build_named_route_call(records, inflection, options = {}) - unless records.is_a?(Array) - record = extract_record(records) - route = [] - else + if records.is_a?(Array) record = records.pop route = records.map do |parent| if parent.is_a?(Symbol) || parent.is_a?(String) @@ -180,6 +177,9 @@ module ActionDispatch ActiveModel::Naming.route_key(parent).singularize end end + else + record = extract_record(records) + route = [] end if record.is_a?(Symbol) || record.is_a?(String) -- cgit v1.2.3 From dc09cc055ab79ec8181ec4089449c94759700e51 Mon Sep 17 00:00:00 2001 From: thedarkone Date: Sun, 26 Sep 2010 14:45:27 +0200 Subject: Assume compute_asset_host returns reasonable values. --- actionpack/lib/action_view/helpers/asset_tag_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index efd238c692..c1dfbe5dc3 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -718,7 +718,7 @@ module ActionView def rewrite_host_and_protocol(source, has_request) host = compute_asset_host(source) - if has_request && host.present? && !is_uri?(host) + if has_request && host && !is_uri?(host) host = "#{controller.request.protocol}#{host}" end "#{host}#{source}" -- cgit v1.2.3 From 6067d1620075c1c311bbae01993453cd80967804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 27 Sep 2010 20:42:02 +0200 Subject: Call it compile_methods! and do the same on AM. --- actionpack/lib/action_controller/railtie.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index 4c57d82f1c..0ade42ba2d 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -38,9 +38,9 @@ module ActionController end end - config.after_initialize do + initializer "action_controller.compile_config_methods" do ActiveSupport.on_load(:action_controller) do - config.crystalize! if config.respond_to?(:crystalize!) + config.compile_methods! if config.respond_to?(:compile_methods!) end end end -- cgit v1.2.3 From 8aa3684e07db81244c61c9ac98347831a976666b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 27 Sep 2010 21:14:18 +0200 Subject: Do not cache the script name outcome. --- actionpack/lib/action_controller/metal/url_for.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/metal/url_for.rb b/actionpack/lib/action_controller/metal/url_for.rb index ef1071bb3d..333eeaeffb 100644 --- a/actionpack/lib/action_controller/metal/url_for.rb +++ b/actionpack/lib/action_controller/metal/url_for.rb @@ -5,17 +5,19 @@ module ActionController include AbstractController::UrlFor def url_options - @_url_options ||= begin - options = {} - if _routes.equal?(env["action_dispatch.routes"]) + @_url_options ||= super.reverse_merge( + :host => request.host_with_port, + :protocol => request.protocol, + :_path_segments => request.symbolized_path_parameters + ).freeze + + if _routes.equal?(env["action_dispatch.routes"]) + @_url_options.dup.tap do |options| options[:script_name] = request.script_name.dup + options.freeze end - - super.merge(options).reverse_merge( - :host => request.host_with_port, - :protocol => request.protocol, - :_path_segments => request.symbolized_path_parameters - ).freeze + else + @_url_options end end end -- cgit v1.2.3 From 2f326b7f27349b933fe617d83b3f80c6573ce5d8 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Mon, 27 Sep 2010 15:13:11 -0300 Subject: Remove warning "URI.unescape is obsolete" from actionpack. Signed-off-by: Santiago Pastorino --- actionpack/lib/action_controller.rb | 1 + actionpack/lib/action_controller/caching/actions.rb | 6 ++---- actionpack/lib/action_controller/caching/pages.rb | 3 ++- actionpack/lib/action_controller/test_case.rb | 4 ---- actionpack/lib/action_controller/uri_parser.rb | 9 +++++++++ actionpack/lib/action_dispatch/routing/route_set.rb | 6 ++---- 6 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 actionpack/lib/action_controller/uri_parser.rb (limited to 'actionpack') diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb index e02578eafd..787439db87 100644 --- a/actionpack/lib/action_controller.rb +++ b/actionpack/lib/action_controller.rb @@ -8,6 +8,7 @@ module ActionController autoload :Caching autoload :Metal autoload :Middleware + autoload :UriParser autoload_under "metal" do autoload :Compatibility diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb index e00f4a7b1d..cd352f69fc 100644 --- a/actionpack/lib/action_controller/caching/actions.rb +++ b/actionpack/lib/action_controller/caching/actions.rb @@ -141,6 +141,8 @@ module ActionController #:nodoc: end class ActionCachePath + include UriParser + attr_reader :path, :extension # If +infer_extension+ is true, the cache path extension is looked up from the request's @@ -163,10 +165,6 @@ module ActionController #:nodoc: path << ".#{extension}" if extension and !path.ends_with?(extension) uri_parser.unescape(path) end - - def uri_parser - @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI - end end end end diff --git a/actionpack/lib/action_controller/caching/pages.rb b/actionpack/lib/action_controller/caching/pages.rb index b845c6f6f9..f0e00718ac 100644 --- a/actionpack/lib/action_controller/caching/pages.rb +++ b/actionpack/lib/action_controller/caching/pages.rb @@ -1,5 +1,4 @@ require 'fileutils' -require 'uri' require 'active_support/core_ext/class/attribute_accessors' module ActionController #:nodoc: @@ -58,6 +57,8 @@ module ActionController #:nodoc: end module ClassMethods + include UriParser + # Expires the page that was cached with the +path+ as a key. Example: # expire_page "/lists/show" def expire_page(path) diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 676828957a..f1ff57f0cb 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -129,10 +129,6 @@ module ActionController def self.new_escaped(strings) new strings.collect {|str| uri_parser.unescape str} end - - def uri_parser - @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI - end end def assign_parameters(routes, controller_path, action, parameters = {}) diff --git a/actionpack/lib/action_controller/uri_parser.rb b/actionpack/lib/action_controller/uri_parser.rb new file mode 100644 index 0000000000..8e2a3f69eb --- /dev/null +++ b/actionpack/lib/action_controller/uri_parser.rb @@ -0,0 +1,9 @@ +require 'uri' + +module ActionController #:nodoc: + module UriParser + def uri_parser + @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI + end + end +end diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index a203ee5934..4289e78641 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -5,6 +5,8 @@ require 'active_support/core_ext/object/to_query' module ActionDispatch module Routing class RouteSet #:nodoc: + include ActionController::UriParser + PARAMETERS_KEY = 'action_dispatch.request.path_parameters' class Dispatcher #:nodoc: @@ -68,10 +70,6 @@ module ActionDispatch def split_glob_param!(params) params[@glob_param] = params[@glob_param].split('/').map { |v| uri_parser.unescape(v) } end - - def uri_parser - @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI - end end # A NamedRouteCollection instance is a collection of named routes, and also -- cgit v1.2.3 From 1ab2ab07b5e7c4031c014175887e9f20b8f60a4c Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Mon, 27 Sep 2010 15:18:35 -0300 Subject: Remove more warnings shadowing outer local variable. Signed-off-by: Santiago Pastorino --- actionpack/lib/action_controller/metal/helpers.rb | 6 +++--- .../action_controller/vendor/html-scanner/html/node.rb | 6 +++--- .../lib/action_dispatch/testing/assertions/selector.rb | 4 ++-- actionpack/test/dispatch/response_test.rb | 16 ++++++++-------- actionpack/test/template/text_helper_test.rb | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/metal/helpers.rb b/actionpack/lib/action_controller/metal/helpers.rb index f10fc66b52..d14831b763 100644 --- a/actionpack/lib/action_controller/metal/helpers.rb +++ b/actionpack/lib/action_controller/metal/helpers.rb @@ -96,9 +96,9 @@ module ActionController def all_helpers_from_path(path) helpers = [] - Array.wrap(path).each do |p| - extract = /^#{Regexp.quote(p.to_s)}\/?(.*)_helper.rb$/ - helpers += Dir["#{p}/**/*_helper.rb"].map { |file| file.sub(extract, '\1') } + Array.wrap(path).each do |_path| + extract = /^#{Regexp.quote(_path.to_s)}\/?(.*)_helper.rb$/ + helpers += Dir["#{_path}/**/*_helper.rb"].map { |file| file.sub(extract, '\1') } end helpers.sort! helpers.uniq! diff --git a/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb b/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb index c82324dee6..22b3243104 100644 --- a/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb +++ b/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb @@ -18,14 +18,14 @@ module HTML #:nodoc: hash[k] = Conditions.new(v) when :children hash[k] = v = keys_to_symbols(v) - v.each do |key,v2| + v.each do |key,value| case key when :count, :greater_than, :less_than # keys are valid, and require no further processing when :only - v[key] = Conditions.new(v2) + v[key] = Conditions.new(value) else - raise "illegal key #{k.inspect} => #{v2.inspect}" + raise "illegal key #{key.inspect} => #{value.inspect}" end end else diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb index 86fba87586..353be10d20 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb @@ -513,8 +513,8 @@ module ActionDispatch node.content.gsub(/)?/m) { Rack::Utils.escapeHTML($1) } end - selected = elements.map do |ele| - text = ele.children.select{ |c| not c.tag? }.map{ |c| fix_content[c] }.join + selected = elements.map do |_element| + text = _element.children.select{ |c| not c.tag? }.map{ |c| fix_content[c] }.join root = HTML::Document.new(CGI.unescapeHTML("#{text}")).root css_select(root, "encoded:root", &block)[0] end diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb index 1efb664304..cd0418c338 100644 --- a/actionpack/test/dispatch/response_test.rb +++ b/actionpack/test/dispatch/response_test.rb @@ -120,10 +120,10 @@ class ResponseTest < ActiveSupport::TestCase end test "read cache control" do - resp = ActionDispatch::Response.new.tap { |_resp| - _resp.cache_control[:public] = true - _resp.etag = '123' - _resp.body = 'Hello' + resp = ActionDispatch::Response.new.tap { |response| + response.cache_control[:public] = true + response.etag = '123' + response.body = 'Hello' } resp.to_a @@ -135,10 +135,10 @@ class ResponseTest < ActiveSupport::TestCase end test "read charset and content type" do - resp = ActionDispatch::Response.new.tap { |_resp| - _resp.charset = 'utf-16' - _resp.content_type = Mime::XML - _resp.body = 'Hello' + resp = ActionDispatch::Response.new.tap { |response| + response.charset = 'utf-16' + response.content_type = Mime::XML + response.body = 'Hello' } resp.to_a diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index 43e920f9b5..9e9ed9120d 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -491,7 +491,7 @@ class TextHelperTest < ActionView::TestCase url = "http://api.rubyonrails.com/Foo.html" email = "fantabulous@shiznadel.ic" - assert_equal %(

#{url[0...7]}...
#{email[0...7]}...

), auto_link("

#{url}
#{email}

") { |u| truncate(u, :length => 10) } + assert_equal %(

#{url[0...7]}...
#{email[0...7]}...

), auto_link("

#{url}
#{email}

") { |_url| truncate(_url, :length => 10) } end def test_auto_link_with_block_with_html -- cgit v1.2.3 From 8adb24016d76a2257b79f4566de66e1b88e56c71 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Mon, 27 Sep 2010 16:17:32 -0300 Subject: Define @_routes inside method, makes more sense and will be initialized when called anywhere. Signed-off-by: Santiago Pastorino --- actionpack/lib/action_dispatch/routing/route_set.rb | 2 +- actionpack/lib/action_dispatch/routing/url_for.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 4289e78641..66b487ba6d 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -318,7 +318,7 @@ module ActionDispatch singleton_class.send(:define_method, :_routes) { routes } end - define_method(:_routes) { @_routes || routes } + define_method(:_routes) { @_routes ||= nil; @_routes || routes } end helpers diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb index 045c9ec77d..e836cf7c8e 100644 --- a/actionpack/lib/action_dispatch/routing/url_for.rb +++ b/actionpack/lib/action_dispatch/routing/url_for.rb @@ -128,7 +128,6 @@ module ActionDispatch when String options when nil, Hash - @_routes ||= nil _routes.url_for((options || {}).reverse_merge!(url_options).symbolize_keys) else polymorphic_url(options) -- cgit v1.2.3 From dd83140b24dcb8a27e226c9de286318a44d7fab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 27 Sep 2010 22:58:31 +0200 Subject: Properly initialize variables inside the initialize method. --- actionpack/lib/action_dispatch/routing/route_set.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 66b487ba6d..e25b30ffa6 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -304,9 +304,9 @@ module ActionDispatch extend ActiveSupport::Concern include UrlFor - @routes = routes + @_routes = routes class << self - delegate :url_for, :to => '@routes' + delegate :url_for, :to => '@_routes' end extend routes.named_routes.module @@ -318,7 +318,12 @@ module ActionDispatch singleton_class.send(:define_method, :_routes) { routes } end - define_method(:_routes) { @_routes ||= nil; @_routes || routes } + def initialize(*) + @_routes = nil + super + end + + define_method(:_routes) { @_routes || routes } end helpers -- cgit v1.2.3 From 72f37bd8bc5b3beb1e8a2d1ac2de2c045cd0cfd2 Mon Sep 17 00:00:00 2001 From: Diego Carrion Date: Sat, 18 Sep 2010 11:00:23 -0300 Subject: renderer calls object.to_json when rendering :json => object [#5655 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/lib/action_controller/metal/renderers.rb | 2 +- actionpack/test/controller/render_json_test.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/metal/renderers.rb b/actionpack/lib/action_controller/metal/renderers.rb index 0be07cd1fc..f9b226b7c9 100644 --- a/actionpack/lib/action_controller/metal/renderers.rb +++ b/actionpack/lib/action_controller/metal/renderers.rb @@ -71,7 +71,7 @@ module ActionController end add :json do |json, options| - json = ActiveSupport::JSON.encode(json, options) unless json.respond_to?(:to_str) + json = json.to_json(options) unless json.respond_to?(:to_str) json = "#{options[:callback]}(#{json})" unless options[:callback].blank? self.content_type ||= Mime::JSON self.response_body = json diff --git a/actionpack/test/controller/render_json_test.rb b/actionpack/test/controller/render_json_test.rb index 5958b18d80..6dd2a9f23d 100644 --- a/actionpack/test/controller/render_json_test.rb +++ b/actionpack/test/controller/render_json_test.rb @@ -9,6 +9,10 @@ class RenderJsonTest < ActionController::TestCase hash.except!(*options[:except]) if options[:except] hash end + + def to_json(options = {}) + super :except => [:c, :e] + end end class TestController < ActionController::Base @@ -49,6 +53,10 @@ class RenderJsonTest < ActionController::TestCase def render_json_with_extra_options render :json => JsonRenderable.new, :except => [:c, :e] end + + def render_json_without_options + render :json => JsonRenderable.new + end end tests TestController @@ -109,4 +117,9 @@ class RenderJsonTest < ActionController::TestCase assert_equal '{"a":"b"}', @response.body assert_equal 'application/json', @response.content_type end + + def test_render_json_calls_to_json_from_object + get :render_json_without_options + assert_equal '{"a":"b"}', @response.body + end end -- cgit v1.2.3 From 8aa86babad2eddb5244ba79b4e3b5702e7e77217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 28 Sep 2010 00:39:10 +0200 Subject: Fix tests on 1.9.2. --- actionpack/lib/action_controller/metal.rb | 1 + actionpack/lib/action_dispatch/routing/route_set.rb | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb index 7fcc4e7211..ace1aabe03 100644 --- a/actionpack/lib/action_controller/metal.rb +++ b/actionpack/lib/action_controller/metal.rb @@ -87,6 +87,7 @@ module ActionController @_status = 200 @_request = nil @_response = nil + @_routes = nil super end diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index e25b30ffa6..9271191f6d 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -318,11 +318,6 @@ module ActionDispatch singleton_class.send(:define_method, :_routes) { routes } end - def initialize(*) - @_routes = nil - super - end - define_method(:_routes) { @_routes || routes } end -- cgit v1.2.3 From 197a995bc548e206bb907c40d75f8ed70fa5a923 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Mon, 27 Sep 2010 20:57:26 -0300 Subject: Move uri parser to AS as URI.parser method to reuse it in AP and ARes. --- actionpack/lib/action_controller.rb | 2 +- actionpack/lib/action_controller/caching/actions.rb | 4 +--- actionpack/lib/action_controller/caching/pages.rb | 8 +------- actionpack/lib/action_controller/uri_parser.rb | 9 --------- actionpack/lib/action_dispatch/routing/route_set.rb | 10 ++-------- 5 files changed, 5 insertions(+), 28 deletions(-) delete mode 100644 actionpack/lib/action_controller/uri_parser.rb (limited to 'actionpack') diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb index 787439db87..5b81cd39f4 100644 --- a/actionpack/lib/action_controller.rb +++ b/actionpack/lib/action_controller.rb @@ -8,7 +8,6 @@ module ActionController autoload :Caching autoload :Metal autoload :Middleware - autoload :UriParser autoload_under "metal" do autoload :Compatibility @@ -73,4 +72,5 @@ require 'active_support/core_ext/load_error' require 'active_support/core_ext/module/attr_internal' require 'active_support/core_ext/module/delegation' require 'active_support/core_ext/name_error' +require 'active_support/core_ext/uri' require 'active_support/inflector' diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb index cd352f69fc..d69d96b974 100644 --- a/actionpack/lib/action_controller/caching/actions.rb +++ b/actionpack/lib/action_controller/caching/actions.rb @@ -141,8 +141,6 @@ module ActionController #:nodoc: end class ActionCachePath - include UriParser - attr_reader :path, :extension # If +infer_extension+ is true, the cache path extension is looked up from the request's @@ -163,7 +161,7 @@ module ActionController #:nodoc: def normalize!(path) path << 'index' if path[-1] == ?/ path << ".#{extension}" if extension and !path.ends_with?(extension) - uri_parser.unescape(path) + URI.parser.unescape(path) end end end diff --git a/actionpack/lib/action_controller/caching/pages.rb b/actionpack/lib/action_controller/caching/pages.rb index f0e00718ac..df4d500069 100644 --- a/actionpack/lib/action_controller/caching/pages.rb +++ b/actionpack/lib/action_controller/caching/pages.rb @@ -57,8 +57,6 @@ module ActionController #:nodoc: end module ClassMethods - include UriParser - # Expires the page that was cached with the +path+ as a key. Example: # expire_page "/lists/show" def expire_page(path) @@ -100,7 +98,7 @@ module ActionController #:nodoc: private def page_cache_file(path) - name = (path.empty? || path == "/") ? "/index" : uri_parser.unescape(path.chomp('/')) + name = (path.empty? || path == "/") ? "/index" : URI.parser.unescape(path.chomp('/')) name << page_cache_extension unless (name.split('/').last || name).include? '.' return name end @@ -112,10 +110,6 @@ module ActionController #:nodoc: def instrument_page_cache(name, path) ActiveSupport::Notifications.instrument("#{name}.action_controller", :path => path){ yield } end - - def uri_parser - @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI - end end # Expires the page that was cached with the +options+ as a key. Example: diff --git a/actionpack/lib/action_controller/uri_parser.rb b/actionpack/lib/action_controller/uri_parser.rb deleted file mode 100644 index 8e2a3f69eb..0000000000 --- a/actionpack/lib/action_controller/uri_parser.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'uri' - -module ActionController #:nodoc: - module UriParser - def uri_parser - @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI - end - end -end diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 66b487ba6d..66e6ecc74c 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -5,8 +5,6 @@ require 'active_support/core_ext/object/to_query' module ActionDispatch module Routing class RouteSet #:nodoc: - include ActionController::UriParser - PARAMETERS_KEY = 'action_dispatch.request.path_parameters' class Dispatcher #:nodoc: @@ -68,7 +66,7 @@ module ActionDispatch end def split_glob_param!(params) - params[@glob_param] = params[@glob_param].split('/').map { |v| uri_parser.unescape(v) } + params[@glob_param] = params[@glob_param].split('/').map { |v| URI.parser.unescape(v) } end end @@ -546,7 +544,7 @@ module ActionDispatch params.each do |key, value| if value.is_a?(String) value = value.dup.force_encoding(Encoding::BINARY) if value.encoding_aware? - params[key] = uri_parser.unescape(value) + params[key] = URI.parser.unescape(value) end end @@ -563,10 +561,6 @@ module ActionDispatch end private - def uri_parser - @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI - end - def handle_positional_args(options) return unless args = options.delete(:_positional_args) -- cgit v1.2.3 From 71acc2737aa346ee57f9fc21252a508ae83367a4 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 07:57:26 +0800 Subject: Move uri parser to AS as URI.parser method to reuse it in AP and ARes. --- actionpack/lib/action_controller.rb | 2 +- actionpack/lib/action_controller/caching/actions.rb | 4 +--- actionpack/lib/action_controller/caching/pages.rb | 8 +------- actionpack/lib/action_controller/uri_parser.rb | 9 --------- actionpack/lib/action_dispatch/routing/route_set.rb | 10 ++-------- 5 files changed, 5 insertions(+), 28 deletions(-) delete mode 100644 actionpack/lib/action_controller/uri_parser.rb (limited to 'actionpack') diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb index 787439db87..5b81cd39f4 100644 --- a/actionpack/lib/action_controller.rb +++ b/actionpack/lib/action_controller.rb @@ -8,7 +8,6 @@ module ActionController autoload :Caching autoload :Metal autoload :Middleware - autoload :UriParser autoload_under "metal" do autoload :Compatibility @@ -73,4 +72,5 @@ require 'active_support/core_ext/load_error' require 'active_support/core_ext/module/attr_internal' require 'active_support/core_ext/module/delegation' require 'active_support/core_ext/name_error' +require 'active_support/core_ext/uri' require 'active_support/inflector' diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb index cd352f69fc..d69d96b974 100644 --- a/actionpack/lib/action_controller/caching/actions.rb +++ b/actionpack/lib/action_controller/caching/actions.rb @@ -141,8 +141,6 @@ module ActionController #:nodoc: end class ActionCachePath - include UriParser - attr_reader :path, :extension # If +infer_extension+ is true, the cache path extension is looked up from the request's @@ -163,7 +161,7 @@ module ActionController #:nodoc: def normalize!(path) path << 'index' if path[-1] == ?/ path << ".#{extension}" if extension and !path.ends_with?(extension) - uri_parser.unescape(path) + URI.parser.unescape(path) end end end diff --git a/actionpack/lib/action_controller/caching/pages.rb b/actionpack/lib/action_controller/caching/pages.rb index f0e00718ac..df4d500069 100644 --- a/actionpack/lib/action_controller/caching/pages.rb +++ b/actionpack/lib/action_controller/caching/pages.rb @@ -57,8 +57,6 @@ module ActionController #:nodoc: end module ClassMethods - include UriParser - # Expires the page that was cached with the +path+ as a key. Example: # expire_page "/lists/show" def expire_page(path) @@ -100,7 +98,7 @@ module ActionController #:nodoc: private def page_cache_file(path) - name = (path.empty? || path == "/") ? "/index" : uri_parser.unescape(path.chomp('/')) + name = (path.empty? || path == "/") ? "/index" : URI.parser.unescape(path.chomp('/')) name << page_cache_extension unless (name.split('/').last || name).include? '.' return name end @@ -112,10 +110,6 @@ module ActionController #:nodoc: def instrument_page_cache(name, path) ActiveSupport::Notifications.instrument("#{name}.action_controller", :path => path){ yield } end - - def uri_parser - @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI - end end # Expires the page that was cached with the +options+ as a key. Example: diff --git a/actionpack/lib/action_controller/uri_parser.rb b/actionpack/lib/action_controller/uri_parser.rb deleted file mode 100644 index 8e2a3f69eb..0000000000 --- a/actionpack/lib/action_controller/uri_parser.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'uri' - -module ActionController #:nodoc: - module UriParser - def uri_parser - @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI - end - end -end diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 9271191f6d..8d9f0cfdeb 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -5,8 +5,6 @@ require 'active_support/core_ext/object/to_query' module ActionDispatch module Routing class RouteSet #:nodoc: - include ActionController::UriParser - PARAMETERS_KEY = 'action_dispatch.request.path_parameters' class Dispatcher #:nodoc: @@ -68,7 +66,7 @@ module ActionDispatch end def split_glob_param!(params) - params[@glob_param] = params[@glob_param].split('/').map { |v| uri_parser.unescape(v) } + params[@glob_param] = params[@glob_param].split('/').map { |v| URI.parser.unescape(v) } end end @@ -546,7 +544,7 @@ module ActionDispatch params.each do |key, value| if value.is_a?(String) value = value.dup.force_encoding(Encoding::BINARY) if value.encoding_aware? - params[key] = uri_parser.unescape(value) + params[key] = URI.parser.unescape(value) end end @@ -563,10 +561,6 @@ module ActionDispatch end private - def uri_parser - @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI - end - def handle_positional_args(options) return unless args = options.delete(:_positional_args) -- cgit v1.2.3 From b8c565fbd68343b419b05a53b4e1844062d1197e Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 15:10:15 -0300 Subject: Initialize @app if it doesn't exists. --- actionpack/lib/action_dispatch/testing/integration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 3204115e9f..8c05462d0d 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -308,7 +308,7 @@ module ActionDispatch include ActionDispatch::Assertions def app - @app + @app ||= nil end # Reset the current session. This is useful for testing multiple sessions -- cgit v1.2.3 From 4bce8e3c7510cd1bc1821af208d05e8c87349fb2 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 15:10:55 -0300 Subject: No need to call super here. Use yield instead block.call --- actionpack/lib/action_dispatch/middleware/stack.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/middleware/stack.rb b/actionpack/lib/action_dispatch/middleware/stack.rb index db7f342bc5..9ea188c3e2 100644 --- a/actionpack/lib/action_dispatch/middleware/stack.rb +++ b/actionpack/lib/action_dispatch/middleware/stack.rb @@ -41,9 +41,8 @@ module ActionDispatch end end - def initialize(*args, &block) - super(*args) - block.call(self) if block_given? + def initialize(*args) + yield(self) if block_given? end def insert(index, *args, &block) -- cgit v1.2.3 From 8ee27afd064bccfc63b21f126109a9b20ce72bd5 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 15:21:44 -0300 Subject: Don't define _test_case method if already defined. --- actionpack/lib/action_view/test_case.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index 32fd8c5e21..de23a67cb6 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -137,8 +137,10 @@ module ActionView def make_test_case_available_to_view! test_case_instance = self _helpers.module_eval do - define_method(:_test_case) { test_case_instance } - private :_test_case + unless private_method_defined?(:_test_case) + define_method(:_test_case) { test_case_instance } + private :_test_case + end end end -- cgit v1.2.3 From 1ef2b47fb12a94f960b34c4bb1e6ad1f9c900e18 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 28 Sep 2010 11:22:16 -0700 Subject: convert inject to map + join --- actionpack/lib/action_view/helpers/form_options_helper.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index 43cbba8a0a..83434a9340 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -395,12 +395,12 @@ module ActionView # Note: Only the and tags are returned, so you still have to # wrap the output in an appropriate ' + "\n" - expected << %{\n" - - expected << %{\n" - - assert_dom_equal expected, date_select("post", "written_on", :order=>[:year, :month], :include_blank=>true) - end - def test_date_select_cant_override_discard_hour @post = Post.new @post.written_on = Date.new(2004, 6, 15) -- cgit v1.2.3 From f63f90134ad46059e7848515d8be5284644bd95c Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 15:30:16 -0300 Subject: Rename duplicated test, and give it a correct name. Remove nonsense line. --- actionpack/test/template/form_helper_test.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index b3fae4d564..abc98ebe69 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -106,7 +106,6 @@ class FormHelperTest < ActionView::TestCase if object.is_a?(Hash) && object[:use_route].blank? && object[:controller].blank? object.merge!(:controller => "main", :action => "index") end - object super end @@ -269,7 +268,7 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, hidden_field("post", "title", :value => nil) end - def test_text_field_with_options + def test_hidden_field_with_options assert_dom_equal '', hidden_field("post", "title", :value => "Something Else") end -- cgit v1.2.3 From dc2cd266cdd99661709772b3ccdf87ab66c682a1 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 15:30:59 -0300 Subject: Rename tests to avoid name collisions and warnings when running rake task. --- actionpack/test/template/number_helper_i18n_test.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/template/number_helper_i18n_test.rb b/actionpack/test/template/number_helper_i18n_test.rb index 8561019461..c82ead663f 100644 --- a/actionpack/test/template/number_helper_i18n_test.rb +++ b/actionpack/test/template/number_helper_i18n_test.rb @@ -41,7 +41,7 @@ class NumberHelperTest < ActionView::TestCase :custom_units_for_number_to_human => {:mili => "mm", :centi => "cm", :deci => "dm", :unit => "m", :ten => "dam", :hundred => "hm", :thousand => "km"} end - def test_number_to_currency + def test_number_to_i18n_currency assert_equal("&$ - 10.00", number_to_currency(10, :locale => 'ts')) end @@ -51,7 +51,7 @@ class NumberHelperTest < ActionView::TestCase end end - def test_number_with_precision + def test_number_with_i18n_precision #Delimiter was set to "" assert_equal("10000", number_with_precision(10000, :locale => 'ts')) @@ -60,12 +60,12 @@ class NumberHelperTest < ActionView::TestCase end - def test_number_with_delimiter + def test_number_with_i18n_delimiter #Delimiter "," and separator "." assert_equal("1,000,000.234", number_with_delimiter(1000000.234, :locale => 'ts')) end - def test_number_to_percentage + def test_number_to_i18n_percentage # to see if strip_insignificant_zeros is true assert_equal("1%", number_to_percentage(1, :locale => 'ts')) # precision is 2, significant should be inherited @@ -74,7 +74,7 @@ class NumberHelperTest < ActionView::TestCase assert_equal("12434%", number_to_percentage(12434, :locale => 'ts')) end - def test_number_to_human_size + def test_number_to_i18n_human_size #b for bytes and k for kbytes assert_equal("2 k", number_to_human_size(2048, :locale => 'ts')) assert_equal("42 b", number_to_human_size(42, :locale => 'ts')) -- cgit v1.2.3 From 699fb81def8f0d242962a81d2f492c6a8eed4211 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 15:31:29 -0300 Subject: Initialize @_virtual_path path ivar. --- actionpack/test/template/template_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack') diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb index fbc9350c69..d2c740a39e 100644 --- a/actionpack/test/template/template_test.rb +++ b/actionpack/test/template/template_test.rb @@ -6,6 +6,7 @@ class TestERBTemplate < ActiveSupport::TestCase class Context def initialize @output_buffer = "original" + @_virtual_path = nil end def hello -- cgit v1.2.3 From 04c4f47fed6ced3f4158107b7cc40a7ea1b4913c Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 15:33:48 -0300 Subject: Initialize @sub_templates --- actionpack/lib/action_view/template/error.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/template/error.rb b/actionpack/lib/action_view/template/error.rb index b1839b65e5..423e1e0bf5 100644 --- a/actionpack/lib/action_view/template/error.rb +++ b/actionpack/lib/action_view/template/error.rb @@ -52,6 +52,7 @@ module ActionView def initialize(template, assigns, original_exception) @template, @assigns, @original_exception = template, assigns.dup, original_exception + @sub_templates = nil @backtrace = original_exception.backtrace end -- cgit v1.2.3 From 97174980e5bf01e0ba80aed77a72ae4409a24be7 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 15:43:03 -0300 Subject: Remove duplicated method. --- actionpack/test/template/javascript_helper_test.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb index a8ca19931b..2e7484afaf 100644 --- a/actionpack/test/template/javascript_helper_test.rb +++ b/actionpack/test/template/javascript_helper_test.rb @@ -22,8 +22,6 @@ class JavaScriptHelperTest < ActionView::TestCase ActiveSupport.escape_html_entities_in_json = false end - def _evaluate_assigns_and_ivars() end - def test_escape_javascript assert_equal '', escape_javascript(nil) assert_equal %(This \\"thing\\" is really\\n netos\\'), escape_javascript(%(This "thing" is really\n netos')) -- cgit v1.2.3 From 059d609a1a59300faefdc2d4186bae13b30c9699 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 15:46:30 -0300 Subject: Avoid more uninitialized variable warnings. --- actionpack/lib/abstract_controller/rendering.rb | 2 +- actionpack/lib/action_dispatch/testing/assertions/selector.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 5d9b35d297..cc6a7f4047 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -66,7 +66,7 @@ module AbstractController attr_writer :view_context_class def view_context_class - @view_context_class || self.class.view_context_class + (@view_context_class ||= nil) || self.class.view_context_class end def initialize(*) diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb index 9ae4f65db9..f5ecb9a199 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb @@ -187,6 +187,7 @@ module ActionDispatch def assert_select(*args, &block) # Start with optional element followed by mandatory selector. arg = args.shift + @selected ||= nil if arg.is_a?(HTML::Node) # First argument is a node (tag or text, but also HTML root), @@ -197,7 +198,7 @@ module ActionDispatch # This usually happens when passing a node/element that # happens to be nil. raise ArgumentError, "First argument is either selector or element to select, but nil found. Perhaps you called assert_select with an element that does not exist?" - elsif defined?(@selected) && @selected + elsif @selected root = HTML::Node.new(nil) root.children.concat @selected else -- cgit v1.2.3 From 9027721b11436144e65bceb9e29ad8669b02582a Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 15:48:45 -0300 Subject: Add parenthesis to avoid syntax warnings. --- actionpack/test/template/prototype_helper_test.rb | 2 +- actionpack/test/template/tag_helper_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb index 036a44730c..a6aa848a00 100644 --- a/actionpack/test/template/prototype_helper_test.rb +++ b/actionpack/test/template/prototype_helper_test.rb @@ -71,7 +71,7 @@ class PrototypeHelperBaseTest < ActionView::TestCase end def create_generator - block = Proc.new { |*args| yield *args if block_given? } + block = Proc.new { |*args| yield(*args) if block_given? } JavaScriptGenerator.new self, &block end end diff --git a/actionpack/test/template/tag_helper_test.rb b/actionpack/test/template/tag_helper_test.rb index cca161bc80..c742683821 100644 --- a/actionpack/test/template/tag_helper_test.rb +++ b/actionpack/test/template/tag_helper_test.rb @@ -103,7 +103,7 @@ class TagHelperTest < ActionView::TestCase def test_skip_invalid_escaped_attributes ['&1;', 'dfa3;', '& #123;'].each do |escaped| - assert_equal %(), tag('a', :href => escaped) + assert_equal %(), tag('a', :href => escaped) end end -- cgit v1.2.3 From 7c8b43ed4fba035033e28cc47358fc3908584880 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 15:53:32 -0300 Subject: Ask if the instance variable is defined before asking for it, avoid *many* warnings. --- actionpack/lib/action_view/helpers/form_helper.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 8bae6d2796..7e49052c24 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -991,7 +991,11 @@ module ActionView end def object - @object || @template_object.instance_variable_get("@#{@object_name}") + if @object + @object + elsif @template_object.instance_variable_defined?("@#{@object_name}") + @template_object.instance_variable_get("@#{@object_name}") + end rescue NameError # As @object_name may contain the nested syntax (item[subobject]) we # need to fallback to nil. -- cgit v1.2.3 From dda3431942973a09d81176660350d9516dbabf68 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 16:02:31 -0300 Subject: Remove useless use of :: in void context. --- actionpack/test/dispatch/mime_type_test.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/test/dispatch/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb index 369212e2d0..4c2b95550c 100644 --- a/actionpack/test/dispatch/mime_type_test.rb +++ b/actionpack/test/dispatch/mime_type_test.rb @@ -41,7 +41,6 @@ class MimeTypeTest < ActiveSupport::TestCase begin Mime::Type.register("image/gif", :gif) assert_nothing_raised do - Mime::GIF assert_equal Mime::GIF, Mime::SET.last end ensure -- cgit v1.2.3 From 7129dd95d0a5edbbb686ed6b827de64c745ec5ef Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 16:08:00 -0300 Subject: undef method if already defined. --- actionpack/test/dispatch/request/xml_params_parsing_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack') diff --git a/actionpack/test/dispatch/request/xml_params_parsing_test.rb b/actionpack/test/dispatch/request/xml_params_parsing_test.rb index 16669614d6..ad9de02eb4 100644 --- a/actionpack/test/dispatch/request/xml_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/xml_params_parsing_test.rb @@ -18,6 +18,7 @@ class XmlParamsParsingTest < ActionDispatch::IntegrationTest test "parses a strict rack.input" do class Linted + undef call if method_defined?(:call) def call(env) bar = env['action_dispatch.request.request_parameters']['foo'] result = "#{bar}" -- cgit v1.2.3 From c9416546a209847e2167edf49de7b4f6c9950694 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 16:09:31 -0300 Subject: Use parenthesis to avoid ambiguous first argument warning. --- actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb index d18b162a93..c3fa4dba0a 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb @@ -19,7 +19,7 @@ <% end %> <% traces.each do |name, trace| %> -
;"> +
;">
<%=h trace.join "\n" %>
<% end %> -- cgit v1.2.3 From 540e87256df08d350e9eb572408e5f68fa59f42b Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 16:12:07 -0300 Subject: Remove remaining warnings on _trace by adding parenthesis to gsub arguments. --- .../lib/action_dispatch/middleware/templates/rescues/_trace.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb index c3fa4dba0a..8771b5fd6d 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb @@ -12,14 +12,14 @@
<% names.each do |name| %> <% - show = "document.getElementById('#{name.gsub /\s/, '-'}').style.display='block';" - hide = (names - [name]).collect {|hide_name| "document.getElementById('#{hide_name.gsub /\s/, '-'}').style.display='none';"} + show = "document.getElementById('#{name.gsub(/\s/, '-')}').style.display='block';" + hide = (names - [name]).collect {|hide_name| "document.getElementById('#{hide_name.gsub(/\s/, '-')}').style.display='none';"} %> <%= name %> <%= '|' unless names.last == name %> <% end %> <% traces.each do |name, trace| %> -
;"> +
;">
<%=h trace.join "\n" %>
<% end %> -- cgit v1.2.3 From 6286b63f27b6b36b9603c4c68600f8f352b84137 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 16:20:48 -0300 Subject: Remove warings from rescues: don't define more than once debug_hash method and ask if @response if defined. --- .../middleware/templates/rescues/_request_and_response.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb index e963b04524..97f7cf0bbe 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb @@ -14,7 +14,7 @@ def debug_hash(hash) hash.sort_by { |k, v| k.to_s }.map { |k, v| "#{k}: #{v.inspect rescue $!.message}" }.join("\n") - end + end unless self.class.method_defined?(:debug_hash) %>

Request

@@ -28,4 +28,4 @@

Response

-

Headers:

<%=h @response ? @response.headers.inspect.gsub(',', ",\n") : 'None' %>

+

Headers:

<%=h defined?(@response) ? @response.headers.inspect.gsub(',', ",\n") : 'None' %>

-- cgit v1.2.3 From eea61a030e96625c53c57b63f0a9449850cf78df Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 16:24:42 -0300 Subject: Initialize @compiled_at if it is not. --- actionpack/lib/action_dispatch/middleware/static.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/middleware/static.rb b/actionpack/lib/action_dispatch/middleware/static.rb index 581cadbeb4..6d442b91f5 100644 --- a/actionpack/lib/action_dispatch/middleware/static.rb +++ b/actionpack/lib/action_dispatch/middleware/static.rb @@ -7,6 +7,7 @@ module ActionDispatch @compiled_at = Regexp.compile(/^#{Regexp.escape(at)}/) unless @at.blank? @compiled_root = Regexp.compile(/^#{Regexp.escape(root)}/) @file_server = ::Rack::File.new(root) + @compiled_at ||= nil end def match?(path) -- cgit v1.2.3 From dc37bd778a46df8a584e27b3a1add519bbbe8ebb Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 16:25:06 -0300 Subject: Initialize @trusted_proxies. --- actionpack/test/dispatch/request_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack') diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index a53d4f1edd..3efed8bef6 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -474,6 +474,7 @@ protected def stub_request(env = {}) ip_spoofing_check = env.key?(:ip_spoofing_check) ? env.delete(:ip_spoofing_check) : true + @trusted_proxies ||= nil ip_app = ActionDispatch::RemoteIp.new(Proc.new { }, ip_spoofing_check, @trusted_proxies) tld_length = env.key?(:tld_length) ? env.delete(:tld_length) : 1 ip_app.call(env) -- cgit v1.2.3 From da8f9ca4329499fc9cc9c3f999a9d6eecdc801d3 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 16:27:05 -0300 Subject: Remove more warnings on variables. --- actionpack/lib/action_dispatch/routing/url_for.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb index e836cf7c8e..7be0f2769a 100644 --- a/actionpack/lib/action_dispatch/routing/url_for.rb +++ b/actionpack/lib/action_dispatch/routing/url_for.rb @@ -136,6 +136,7 @@ module ActionDispatch protected def _with_routes(routes) + @_routes ||= nil old_routes, @_routes = @_routes, routes yield ensure -- cgit v1.2.3 From 4d6e178f888c8287eb59e14bd9ecb77b4d71455b Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 16:31:21 -0300 Subject: Remove method if exists, avoid calling Array#first so many times. --- actionpack/lib/action_dispatch/middleware/callbacks.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/middleware/callbacks.rb b/actionpack/lib/action_dispatch/middleware/callbacks.rb index e4ae480bfb..0bb950d1cc 100644 --- a/actionpack/lib/action_dispatch/middleware/callbacks.rb +++ b/actionpack/lib/action_dispatch/middleware/callbacks.rb @@ -19,9 +19,11 @@ module ActionDispatch # replace the existing callback. Passing an identifier is a suggested # practice if the code adding a preparation block may be reloaded. def self.to_prepare(*args, &block) - if args.first.is_a?(Symbol) && block_given? - define_method :"__#{args.first}", &block - set_callback(:prepare, :"__#{args.first}") + first_arg = args.first + if first_arg.is_a?(Symbol) && block_given? + remove_method :"__#{first_arg}" if method_defined?(:"__#{first_arg}") + define_method :"__#{first_arg}", &block + set_callback(:prepare, :"__#{first_arg}") else set_callback(:prepare, *args, &block) end -- cgit v1.2.3 From c8db1adc0d33228882d8d35d706a3744f7c3d958 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 16:40:28 -0300 Subject: Remove duplicated class test. copy/paste fail? --- ...nder_partial_with_record_identification_test.rb | 32 ---------------------- 1 file changed, 32 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/activerecord/render_partial_with_record_identification_test.rb b/actionpack/test/activerecord/render_partial_with_record_identification_test.rb index df50c3dc6f..43c534c111 100644 --- a/actionpack/test/activerecord/render_partial_with_record_identification_test.rb +++ b/actionpack/test/activerecord/render_partial_with_record_identification_test.rb @@ -93,38 +93,6 @@ class RenderPartialWithRecordIdentificationTest < ActiveRecordTestCase end end -class RenderPartialWithRecordIdentificationController < ActionController::Base - def render_with_has_many_and_belongs_to_association - @developer = Developer.find(1) - render :partial => @developer.projects - end - - def render_with_has_many_association - @topic = Topic.find(1) - render :partial => @topic.replies - end - - def render_with_has_many_through_association - @developer = Developer.find(:first) - render :partial => @developer.topics - end - - def render_with_belongs_to_association - @reply = Reply.find(1) - render :partial => @reply.topic - end - - def render_with_record - @developer = Developer.find(:first) - render :partial => @developer - end - - def render_with_record_collection - @developers = Developer.find(:all) - render :partial => @developers - end -end - class Game < Struct.new(:name, :id) extend ActiveModel::Naming include ActiveModel::Conversion -- cgit v1.2.3 From 19d9fffb9b8350b03cf8b1e3a3249eba06d22c1a Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 17:08:10 -0300 Subject: Use redefine_method instead define_method, it may be already defined. --- actionpack/lib/action_dispatch/routing/route_set.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 66e6ecc74c..71a320ce9c 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -313,7 +313,7 @@ module ActionDispatch # Yes plz - JP included do routes.install_helpers(self) - singleton_class.send(:define_method, :_routes) { routes } + singleton_class.send(:redefine_method, :_routes) { routes } end define_method(:_routes) { @_routes ||= nil; @_routes || routes } -- cgit v1.2.3 From 3f94b45262577b70a1d9f3aea45e0e4f07a2bbaa Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 17:08:43 -0300 Subject: Remove more warnings: no need to define attr_accessor if already exists. Initialize ivar. --- actionpack/lib/action_controller/test_case.rb | 8 +++++--- actionpack/test/controller/render_test.rb | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index f1ff57f0cb..70a5de7f30 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -462,9 +462,11 @@ module ActionController # The exception is stored in the exception accessor for further inspection. module RaiseActionExceptions def self.included(base) - base.class_eval do - attr_accessor :exception - protected :exception, :exception= + unless base.method_defined?(:exception) && base.method_defined?(:exception=) + base.class_eval do + attr_accessor :exception + protected :exception, :exception= + end end end diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 42723c834e..5d1341af1b 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -327,6 +327,7 @@ class TestController < ActionController::Base end def default_render + @alternate_default_render ||= nil if @alternate_default_render @alternate_default_render.call else -- cgit v1.2.3 From 9917356d66a9dc6d7f8ea864d996faa1f020167d Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 17:16:18 -0300 Subject: Remove more warnings by initializing variables in test. --- actionpack/test/controller/render_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'actionpack') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 5d1341af1b..15e298e5fc 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -276,6 +276,7 @@ class TestController < ActionController::Base # :ported: def builder_layout_test + @name = nil render :action => "hello", :layout => "layouts/builder" end @@ -340,14 +341,17 @@ class TestController < ActionController::Base end def layout_test_with_different_layout + @variable_for_layout = nil render :action => "hello_world", :layout => "standard" end def layout_test_with_different_layout_and_string_action + @variable_for_layout = nil render "hello_world", :layout => "standard" end def layout_test_with_different_layout_and_symbol_action + @variable_for_layout = nil render :hello_world, :layout => "standard" end @@ -356,6 +360,7 @@ class TestController < ActionController::Base end def layout_overriding_layout + @variable_for_layout = nil render :action => "hello_world", :layout => "standard" end @@ -644,6 +649,7 @@ class TestController < ActionController::Base private def determine_layout + @variable_for_layout ||= nil case action_name when "hello_world", "layout_test", "rendering_without_layout", "rendering_nothing_on_layout", "render_text_hello_world", -- cgit v1.2.3 From c648a4cb944bac6900bad084be5c701e32ae1b0d Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 17:18:48 -0300 Subject: Remove useless string line causing a warning. --- actionpack/test/fixtures/test/hello_world_from_rxml.builder | 1 - 1 file changed, 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/test/fixtures/test/hello_world_from_rxml.builder b/actionpack/test/fixtures/test/hello_world_from_rxml.builder index 8455b11edc..619a97ba96 100644 --- a/actionpack/test/fixtures/test/hello_world_from_rxml.builder +++ b/actionpack/test/fixtures/test/hello_world_from_rxml.builder @@ -1,4 +1,3 @@ xml.html do xml.p "Hello" end -"String return value" -- cgit v1.2.3 From 3abd0593a62e2be118b783efe55f63ab3324a4d7 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 17:32:18 -0300 Subject: Initialize ivars in tests. --- actionpack/test/controller/caching_test.rb | 1 + actionpack/test/controller/render_other_test.rb | 1 + actionpack/test/controller/webservice_test.rb | 1 + 3 files changed, 3 insertions(+) (limited to 'actionpack') diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index 8030499235..914ae56032 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -185,6 +185,7 @@ class ActionCachingTestController < CachingController def with_layout @cache_this = MockTime.now.to_f.to_s + @title = nil render :text => @cache_this, :layout => true end diff --git a/actionpack/test/controller/render_other_test.rb b/actionpack/test/controller/render_other_test.rb index 3117be6e81..eda777e7a7 100644 --- a/actionpack/test/controller/render_other_test.rb +++ b/actionpack/test/controller/render_other_test.rb @@ -120,6 +120,7 @@ class RenderOtherTest < ActionController::TestCase private def default_render + @alternate_default_render ||= nil if @alternate_default_render @alternate_default_render.call else diff --git a/actionpack/test/controller/webservice_test.rb b/actionpack/test/controller/webservice_test.rb index 5564775a48..6ba4c6c48d 100644 --- a/actionpack/test/controller/webservice_test.rb +++ b/actionpack/test/controller/webservice_test.rb @@ -24,6 +24,7 @@ class WebServiceTest < ActionDispatch::IntegrationTest def setup @controller = TestController.new + @integration_session = nil end def test_check_parameters -- cgit v1.2.3 From 80a98e9b258f5b335ee035edc7aa520819532075 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 17:35:17 -0300 Subject: Use instance_variable_defined? instead instance_variable_get in tests. --- actionpack/test/controller/action_pack_assertions_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index a0092a9f73..d9d258e593 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -234,13 +234,13 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase def test_template_objects_exist process :assign_this - assert !@controller.instance_variable_get(:"@hi") + assert !@controller.instance_variable_defined?(:"@hi") assert @controller.instance_variable_get(:"@howdy") end def test_template_objects_missing process :nothing - assert_nil @controller.instance_variable_get(:@howdy) + assert !@controller.instance_variable_defined?(:@howdy) end def test_empty_flash -- cgit v1.2.3 From ad2c21089e435527641d891a30ff8f695114071b Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 17:44:26 -0300 Subject: Define @title to avoid warnings. --- actionpack/test/controller/capture_test.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'actionpack') diff --git a/actionpack/test/controller/capture_test.rb b/actionpack/test/controller/capture_test.rb index 47253f22b8..eb426e855b 100644 --- a/actionpack/test/controller/capture_test.rb +++ b/actionpack/test/controller/capture_test.rb @@ -6,18 +6,22 @@ class CaptureController < ActionController::Base def self.controller_path; "test"; end def content_for + @title = nil render :layout => "talk_from_action" end def content_for_with_parameter + @title = nil render :layout => "talk_from_action" end def content_for_concatenated + @title = nil render :layout => "talk_from_action" end def non_erb_block_content_for + @title = nil render :layout => "talk_from_action" end -- cgit v1.2.3 From 523f98099d331908db6ab4c45f7657e61a8a4d5f Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 18:01:48 -0300 Subject: Remove more warnings on AP. --- actionpack/lib/action_dispatch/middleware/session/abstract_store.rb | 4 ++-- actionpack/lib/action_dispatch/testing/assertions/selector.rb | 3 ++- actionpack/test/controller/filters_test.rb | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb index 348a2d1eb2..ea49b30630 100644 --- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb @@ -102,8 +102,8 @@ module ActionDispatch def destroy clear - @by.send(:destroy, @env) if @by - @env[ENV_SESSION_OPTIONS_KEY][:id] = nil if @env && @env[ENV_SESSION_OPTIONS_KEY] + @by.send(:destroy, @env) if defined?(@by) && @by + @env[ENV_SESSION_OPTIONS_KEY][:id] = nil if defined?(@env) && @env && @env[ENV_SESSION_OPTIONS_KEY] @loaded = false end diff --git a/actionpack/lib/action_dispatch/testing/assertions/selector.rb b/actionpack/lib/action_dispatch/testing/assertions/selector.rb index f5ecb9a199..2b862fb7d6 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/selector.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/selector.rb @@ -67,7 +67,7 @@ module ActionDispatch arg = args.shift elsif arg == nil raise ArgumentError, "First argument is either selector or element to select, but nil found. Perhaps you called assert_select with an element that does not exist?" - elsif @selected + elsif defined?(@selected) && @selected matches = [] @selected.each do |selected| @@ -443,6 +443,7 @@ module ActionDispatch assert_block("") { true } # to count the assertion if block_given? && !([:remove, :show, :hide, :toggle].include? rjs_type) begin + @selected ||= nil in_scope, @selected = @selected, matches yield matches ensure diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index cf4a461622..d13ebc705a 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -669,7 +669,7 @@ class FilterTest < ActionController::TestCase assert_equal %w( ensure_login find_user ), assigns["ran_filter"] test_process(ConditionalSkippingController, "login") - assert_nil @controller.instance_variable_get("@ran_after_filter") + assert !@controller.instance_variable_defined?("@ran_after_filter") test_process(ConditionalSkippingController, "change_password") assert_equal %w( clean_up ), @controller.instance_variable_get("@ran_after_filter") end -- cgit v1.2.3 From d1e976da7f8981c5cdbf8ee6520281fa78863f2f Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 18:10:32 -0300 Subject: Silence warnings here, only setting Encoding.default_external for testing. --- actionpack/test/template/render_test.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index c17bec891b..205fdcf345 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -319,10 +319,11 @@ class LazyViewRenderTest < ActiveSupport::TestCase end def with_external_encoding(encoding) - old, Encoding.default_external = Encoding.default_external, encoding + old = Encoding.default_external + silence_warnings { Encoding.default_external = encoding } yield ensure - Encoding.default_external = old + silence_warnings { Encoding.default_external = old } end end end -- cgit v1.2.3 From a0f95a887eaca32dd9d65a719c967865c7d4d664 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 18:11:57 -0300 Subject: Silence warnings here, only setting Encoding.default_external for testing. --- actionpack/test/template/template_test.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb index d2c740a39e..36fc9ccf91 100644 --- a/actionpack/test/template/template_test.rb +++ b/actionpack/test/template/template_test.rb @@ -124,10 +124,11 @@ class TestERBTemplate < ActiveSupport::TestCase end def with_external_encoding(encoding) - old, Encoding.default_external = Encoding.default_external, encoding + old = Encoding.default_external + silence_warnings { Encoding.default_external = encoding } yield ensure - Encoding.default_external = old + silence_warnings { Encoding.default_external = old } end end end -- cgit v1.2.3 From e8041042006eb7cb3253f1bdb38d6e2fe9a785d7 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 18:16:26 -0300 Subject: Use helper method here. --- actionpack/test/template/template_test.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb index 36fc9ccf91..c7c33af670 100644 --- a/actionpack/test/template/template_test.rb +++ b/actionpack/test/template/template_test.rb @@ -83,12 +83,11 @@ class TestERBTemplate < ActiveSupport::TestCase # is set to something other than UTF-8, we don't # get any errors and get back a UTF-8 String. def test_default_external_works - Encoding.default_external = "ISO-8859-1" - @template = new_template("hello \xFCmlat") - assert_equal Encoding::UTF_8, render.encoding - assert_equal "hello \u{fc}mlat", render - ensure - Encoding.default_external = "UTF-8" + with_external_encoding "ISO-8859-1" do + @template = new_template("hello \xFCmlat") + assert_equal Encoding::UTF_8, render.encoding + assert_equal "hello \u{fc}mlat", render + end end def test_encoding_can_be_specified_with_magic_comment -- cgit v1.2.3 From 357f59447d79a09d7a84fa8c2bc7892b5fc02ca9 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 18:20:54 -0300 Subject: Initialize @path. --- actionpack/lib/action_view/template/resolver.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/template/resolver.rb b/actionpack/lib/action_view/template/resolver.rb index c9e20ca14e..a261e08dbc 100644 --- a/actionpack/lib/action_view/template/resolver.rb +++ b/actionpack/lib/action_view/template/resolver.rb @@ -6,6 +6,7 @@ module ActionView # = Action View Resolver class Resolver def initialize + @path = nil @cached = Hash.new { |h1,k1| h1[k1] = Hash.new { |h2,k2| h2[k2] = Hash.new { |h3, k3| h3[k3] = {} } } } end -- cgit v1.2.3 From 0fa9c5392ec24a7d1017d03aa00a2bac32f53158 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 18:25:24 -0300 Subject: Define @_layout if it is not defined. --- actionpack/lib/abstract_controller/layouts.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack') diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index 958e7f7ec8..bbc9739f14 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -345,6 +345,7 @@ module AbstractController # * template - The template object for the default layout (or nil) def _default_layout(require_layout = false) begin + @_layout ||= nil layout_name = _layout if action_has_layout? rescue NameError => e raise NoMethodError, -- cgit v1.2.3 From 0c08d8bd758a15b137ba3523c3cde8b371cf725a Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 18:25:52 -0300 Subject: Fix more warnings by defining variables and using instance_variable_defined? instead instance_variable_get. --- actionpack/test/abstract/callbacks_test.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/abstract/callbacks_test.rb b/actionpack/test/abstract/callbacks_test.rb index b2d4d5f79a..2d02078020 100644 --- a/actionpack/test/abstract/callbacks_test.rb +++ b/actionpack/test/abstract/callbacks_test.rb @@ -47,6 +47,7 @@ module AbstractController end def index + @text ||= nil self.response_body = @text.to_s end end @@ -152,7 +153,7 @@ module AbstractController test "when :except is specified, an after filter is not triggered on that action" do result = @controller.process(:index) - assert_nil @controller.instance_variable_get("@authenticated") + assert !@controller.instance_variable_defined?("@authenticated") end end @@ -196,7 +197,7 @@ module AbstractController test "when :except is specified with an array, an after filter is not triggered on that action" do result = @controller.process(:index) - assert_nil @controller.instance_variable_get("@authenticated") + assert !@controller.instance_variable_defined?("@authenticated") end end @@ -204,6 +205,7 @@ module AbstractController before_filter :first, :only => :index def not_index + @text ||= nil self.response_body = @text.to_s end end -- cgit v1.2.3 From 3e336f9ab70305386e941b2bed34e1dfac80a9f8 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 18:31:52 -0300 Subject: Use redefine_method since baz is already defined. --- actionpack/test/fixtures/alternate_helpers/foo_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/test/fixtures/alternate_helpers/foo_helper.rb b/actionpack/test/fixtures/alternate_helpers/foo_helper.rb index a956fce6fa..2528584473 100644 --- a/actionpack/test/fixtures/alternate_helpers/foo_helper.rb +++ b/actionpack/test/fixtures/alternate_helpers/foo_helper.rb @@ -1,3 +1,3 @@ module FooHelper - def baz() end + redefine_method(:baz) {} end -- cgit v1.2.3 From 454960d9fbd248871b4592f34b427992b009b15a Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 18:35:02 -0300 Subject: Redefine duplicated test name. --- actionpack/test/template/html-scanner/tag_node_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/test/template/html-scanner/tag_node_test.rb b/actionpack/test/template/html-scanner/tag_node_test.rb index 9c8fcdc8fc..3d1976c1c2 100644 --- a/actionpack/test/template/html-scanner/tag_node_test.rb +++ b/actionpack/test/template/html-scanner/tag_node_test.rb @@ -221,7 +221,7 @@ class TagNodeTest < Test::Unit::TestCase assert !m.match(:after => {:tag => "span", :attributes => {:k => true}}) end - def test_to_s + def test_tag_to_s t = tag("") tag("hello", t) tag("
", t) -- cgit v1.2.3 From 34fc10954959e1e60a1afb83071b98240344e460 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 18:36:45 -0300 Subject: Redefine duplicated test name. --- actionpack/test/controller/render_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 15e298e5fc..7ca784c467 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -1027,7 +1027,7 @@ class RenderTest < ActionController::TestCase assert_equal " ", @response.body end - def test_render_to_string + def test_render_to_string_not_deprecated assert_not_deprecated { get :hello_in_a_string } assert_equal "How's there? goodbyeHello: davidHello: marygoodbye\n", @response.body end -- cgit v1.2.3 From 783e9b8de536a51ea28633623145ba3b2ec6397a Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 18:38:25 -0300 Subject: Change test to avoid warnings. --- actionpack/test/dispatch/request/multipart_params_parsing_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb index 1ae514ebf7..073dd3ddad 100644 --- a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb @@ -68,7 +68,7 @@ class MultipartParamsParsingTest < ActionDispatch::IntegrationTest assert_equal 'file.txt', file.original_filename assert_equal "text/plain", file.content_type - assert ('a' * 20480) == file.read + assert_equal(('a' * 20480), file.read) end test "parses binary file" do -- cgit v1.2.3 From d5bb640eb02fa9cae6e99f2c5b7d91c986bc65f1 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 18:40:38 -0300 Subject: Remove methods to avoid warnings. --- actionpack/test/controller/rescue_test.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionpack') diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index cefbc548c0..a2418bb7c0 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -3,10 +3,12 @@ require 'abstract_unit' module ActionDispatch class ShowExceptions private + remove_method :public_path def public_path "#{FIXTURE_LOAD_PATH}/public" end + remove_method :logger # Silence logger def logger nil -- cgit v1.2.3 From 623ef13b775985198ea2615466d5b06ef45a1411 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 18:48:58 -0300 Subject: Fix test that wasn't running at all. --- actionpack/test/template/html-scanner/tag_node_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/test/template/html-scanner/tag_node_test.rb b/actionpack/test/template/html-scanner/tag_node_test.rb index 3d1976c1c2..0d87f1bd42 100644 --- a/actionpack/test/template/html-scanner/tag_node_test.rb +++ b/actionpack/test/template/html-scanner/tag_node_test.rb @@ -55,7 +55,7 @@ class TagNodeTest < Test::Unit::TestCase def test_to_s node = tag("") - assert_equal %(), node.to_s + assert_equal %(), node.to_s end def test_tag -- cgit v1.2.3 From 17599abc9c06f30ff23d7ad47a3f029e32c26c88 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 28 Sep 2010 18:50:46 -0300 Subject: Enable warnings now that they can be readed. --- actionpack/Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/Rakefile b/actionpack/Rakefile index 521ee6913a..a6ce08113f 100644 --- a/actionpack/Rakefile +++ b/actionpack/Rakefile @@ -18,7 +18,7 @@ Rake::TestTask.new(:test_action_pack) do |t| # this will not happen automatically and the tests (as a whole) will error t.test_files = Dir.glob('test/{abstract,controller,dispatch,template}/**/*_test.rb').sort - #t.warning = true + t.warning = true t.verbose = true end -- cgit v1.2.3 From 14f9904e0fc6d8a1e5627ac64c4b5b14e95177c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 29 Sep 2010 11:18:31 +0200 Subject: Avoid (@_var ||= nil) pattern by using initialize methods and ensuring everyone calls super as expected. --- actionpack/lib/abstract_controller/layouts.rb | 4 +-- actionpack/lib/abstract_controller/rendering.rb | 2 +- actionpack/lib/abstract_controller/url_for.rb | 1 - actionpack/lib/action_dispatch/middleware/stack.rb | 4 +++ .../lib/action_dispatch/middleware/static.rb | 3 +-- actionpack/lib/action_dispatch/routing/url_for.rb | 6 ++++- .../lib/action_dispatch/testing/integration.rb | 1 + actionpack/lib/action_view/helpers/form_helper.rb | 31 ++++++++++++---------- actionpack/lib/action_view/test_case.rb | 22 +++++++-------- actionpack/test/abstract/layouts_test.rb | 2 +- 10 files changed, 42 insertions(+), 34 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index bbc9739f14..5c853c3034 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -345,11 +345,9 @@ module AbstractController # * template - The template object for the default layout (or nil) def _default_layout(require_layout = false) begin - @_layout ||= nil layout_name = _layout if action_has_layout? rescue NameError => e - raise NoMethodError, - "You specified #{@_layout.inspect} as the layout, but no such method was found" + raise e.class, "Coult not render layout: #{e.message}" end if require_layout && action_has_layout? && !layout_name diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index cc6a7f4047..5d9b35d297 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -66,7 +66,7 @@ module AbstractController attr_writer :view_context_class def view_context_class - (@view_context_class ||= nil) || self.class.view_context_class + @view_context_class || self.class.view_context_class end def initialize(*) diff --git a/actionpack/lib/abstract_controller/url_for.rb b/actionpack/lib/abstract_controller/url_for.rb index 2e9de22ecd..e5d5bef6b4 100644 --- a/actionpack/lib/abstract_controller/url_for.rb +++ b/actionpack/lib/abstract_controller/url_for.rb @@ -1,7 +1,6 @@ module AbstractController module UrlFor extend ActiveSupport::Concern - include ActionDispatch::Routing::UrlFor def _routes diff --git a/actionpack/lib/action_dispatch/middleware/stack.rb b/actionpack/lib/action_dispatch/middleware/stack.rb index 9ea188c3e2..e3cd779756 100644 --- a/actionpack/lib/action_dispatch/middleware/stack.rb +++ b/actionpack/lib/action_dispatch/middleware/stack.rb @@ -41,7 +41,11 @@ module ActionDispatch end end + # Use this instead of super to work around a warning. + alias :array_initialize :initialize + def initialize(*args) + array_initialize(*args) yield(self) if block_given? end diff --git a/actionpack/lib/action_dispatch/middleware/static.rb b/actionpack/lib/action_dispatch/middleware/static.rb index 6d442b91f5..cf13938331 100644 --- a/actionpack/lib/action_dispatch/middleware/static.rb +++ b/actionpack/lib/action_dispatch/middleware/static.rb @@ -4,10 +4,9 @@ module ActionDispatch class FileHandler def initialize(at, root) @at, @root = at.chomp('/'), root.chomp('/') - @compiled_at = Regexp.compile(/^#{Regexp.escape(at)}/) unless @at.blank? + @compiled_at = (Regexp.compile(/^#{Regexp.escape(at)}/) unless @at.blank?) @compiled_root = Regexp.compile(/^#{Regexp.escape(root)}/) @file_server = ::Rack::File.new(root) - @compiled_at ||= nil end def match?(path) diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb index 7be0f2769a..bfdea41f60 100644 --- a/actionpack/lib/action_dispatch/routing/url_for.rb +++ b/actionpack/lib/action_dispatch/routing/url_for.rb @@ -98,6 +98,11 @@ module ActionDispatch end end + def initialize(*) + @_routes = nil + super + end + def url_options default_url_options end @@ -136,7 +141,6 @@ module ActionDispatch protected def _with_routes(routes) - @_routes ||= nil old_routes, @_routes = @_routes, routes yield ensure diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 8c05462d0d..4d25bb8d7b 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -171,6 +171,7 @@ module ActionDispatch # Create and initialize a new Session instance. def initialize(app) + super @app = app # If the app is a Rails app, make url_helpers available on the session diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 7e49052c24..c47fac05ef 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -850,7 +850,7 @@ module ActionView extend ActiveSupport::Concern include Helpers::CaptureHelper, Context, Helpers::TagHelper, Helpers::FormTagHelper - attr_reader :method_name, :object_name + attr_reader :object, :method_name, :object_name DEFAULT_FIELD_OPTIONS = { "size" => 30 } DEFAULT_RADIO_OPTIONS = { } @@ -859,14 +859,9 @@ module ActionView def initialize(object_name, method_name, template_object, object = nil) @object_name, @method_name = object_name.to_s.dup, method_name.to_s.dup @template_object = template_object - @object = object - if @object_name.sub!(/\[\]$/,"") || @object_name.sub!(/\[\]\]$/,"]") - if (object ||= @template_object.instance_variable_get("@#{Regexp.last_match.pre_match}")) && object.respond_to?(:to_param) - @auto_index = object.to_param - else - raise ArgumentError, "object[] naming but object param and @object var don't exist or don't respond to to_param: #{object.inspect}" - end - end + @object_name.sub!(/\[\]$/,"") || @object_name.sub!(/\[\]\]$/,"]") + @object = retrieve_object(object) + @auto_index = retrieve_autoindex(Regexp.last_match.pre_match) if Regexp.last_match end def to_label_tag(text = nil, options = {}, &block) @@ -990,18 +985,26 @@ module ActionView content_tag(tag_name, value(object), options) end - def object - if @object - @object + def retrieve_object(object) + if object + object elsif @template_object.instance_variable_defined?("@#{@object_name}") @template_object.instance_variable_get("@#{@object_name}") end rescue NameError - # As @object_name may contain the nested syntax (item[subobject]) we - # need to fallback to nil. + # As @object_name may contain the nested syntax (item[subobject]) we need to fallback to nil. nil end + def retrieve_autoindex(pre_match) + object = self.object || @template_object.instance_variable_get("@#{pre_match}") + if object && object.respond_to?(:to_param) + object.to_param + else + raise ArgumentError, "object[] naming but object param and @object var don't exist or don't respond to to_param: #{object.inspect}" + end + end + def value(object) self.class.value(object, @method_name) end diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index de23a67cb6..915c2f90d7 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -20,12 +20,12 @@ module ActionView end def initialize + super self.class.controller_path = "" @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new @request.env.delete('PATH_INFO') - @params = {} end end @@ -156,15 +156,15 @@ module ActionView # The instance of ActionView::Base that is used by +render+. def view @view ||= begin - view = ActionView::Base.new(ActionController::Base.view_paths, {}, @controller) - view.singleton_class.send :include, _helpers - view.singleton_class.send :include, @controller._routes.url_helpers - view.singleton_class.send :delegate, :alert, :notice, :to => "request.flash" - view.extend(Locals) - view.locals = self.locals - view.output_buffer = self.output_buffer - view - end + view = ActionView::Base.new(ActionController::Base.view_paths, {}, @controller) + view.singleton_class.send :include, _helpers + view.singleton_class.send :include, @controller._routes.url_helpers + view.singleton_class.send :delegate, :alert, :notice, :to => "request.flash" + view.extend(Locals) + view.locals = self.locals + view.output_buffer = self.output_buffer + view + end end alias_method :_view, :view @@ -201,7 +201,7 @@ module ActionView def method_missing(selector, *args) if @controller.respond_to?(:_routes) && - @controller._routes.named_routes.helpers.include?(selector) + @controller._routes.named_routes.helpers.include?(selector) @controller.__send__(selector, *args) else super diff --git a/actionpack/test/abstract/layouts_test.rb b/actionpack/test/abstract/layouts_test.rb index f580ad40f7..5ed6aa68b5 100644 --- a/actionpack/test/abstract/layouts_test.rb +++ b/actionpack/test/abstract/layouts_test.rb @@ -225,7 +225,7 @@ module AbstractControllerTests end test "when the layout is specified as a symbol and the method doesn't exist, raise an exception" do - assert_raises(NoMethodError) { WithSymbolAndNoMethod.new.process(:index) } + assert_raises(NameError) { WithSymbolAndNoMethod.new.process(:index) } end test "when the layout is specified as a symbol and the method returns something besides a string/false/nil, raise an exception" do -- cgit v1.2.3 From 392df0fc06a985e607c89c8a0090cb036adc5b7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 29 Sep 2010 11:19:22 +0200 Subject: @_etag is not used anywhere. --- actionpack/lib/action_dispatch/http/response.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index a5d082c6a2..151c90167b 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -43,7 +43,6 @@ module ActionDispatch # :nodoc: @writer = lambda { |x| @body << x } @block = nil @length = 0 - @_etag = nil @status, @header = status, header self.body = body @@ -141,7 +140,6 @@ module ActionDispatch # :nodoc: assign_default_content_type_and_charset! handle_conditional_get! self["Set-Cookie"] = self["Set-Cookie"].join("\n") if self["Set-Cookie"].respond_to?(:join) - self["ETag"] = @_etag if @_etag super end -- cgit v1.2.3 From b1ae796284850e29d5ad0fc769e55ed4a43676a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 29 Sep 2010 11:28:38 +0200 Subject: Fix an error on 1.8.7. --- actionpack/lib/action_dispatch/testing/integration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 4d25bb8d7b..fee8cad9f5 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -171,7 +171,7 @@ module ActionDispatch # Create and initialize a new Session instance. def initialize(app) - super + super() @app = app # If the app is a Rails app, make url_helpers available on the session -- cgit v1.2.3 From f63d35fba55867111427bfeb54c31b11e02d5d3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 29 Sep 2010 14:24:32 +0200 Subject: Ensure that named routes do not overwrite previously defined routes. --- actionpack/lib/action_dispatch/routing/mapper.rb | 23 +++++++++++++---------- actionpack/test/dispatch/routing_test.rb | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+), 10 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 5e95d8ed39..0cb02c5b80 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -62,7 +62,6 @@ module ActionDispatch if using_match_shorthand?(path_without_format, @options) to_shorthand = @options[:to].blank? @options[:to] ||= path_without_format[1..-1].sub(%r{/([^/]*)$}, '#\1') - @options[:as] ||= Mapper.normalize_name(path_without_format) end @options.merge!(default_controller_and_action(to_shorthand)) @@ -924,9 +923,14 @@ module ActionDispatch if action.to_s =~ /^[\w\/]+$/ options[:action] ||= action unless action.to_s.include?("/") - options[:as] = name_for_action(action, options[:as]) else - options[:as] = name_for_action(options[:as]) + action = nil + end + + if options.key?(:as) && !options[:as] + options.delete(:as) + else + options[:as] = name_for_action(options[:as], action) end super(path, options) @@ -1092,18 +1096,16 @@ module ActionDispatch path || @scope[:path_names][name.to_sym] || name.to_s end - def prefix_name_for_action(action, as) - if as.present? + def prefix_name_for_action(as, action) + if as as.to_s - elsif as - nil elsif !canonical_action?(action, @scope[:scope_level]) action.to_s end end - def name_for_action(action, as=nil) - prefix = prefix_name_for_action(action, as) + def name_for_action(as, action) + prefix = prefix_name_for_action(as, action) prefix = Mapper.normalize_name(prefix) if prefix name_prefix = @scope[:as] @@ -1127,7 +1129,8 @@ module ActionDispatch [name_prefix, member_name, prefix] end - name.select(&:present?).join("_").presence + candidate = name.select(&:present?).join("_").presence + candidate unless as.nil? && @set.routes.map(&:name).include?(candidate) end end diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 53b13501b2..5c188a60c7 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -442,6 +442,15 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get :preview, :on => :member end + scope :as => "routes" do + get "/c/:id", :as => :collision, :to => "collision#show" + get "/collision", :to => "collision#show" + get "/no_collision", :to => "collision#show", :as => nil + + get "/fc/:id", :as => :forced_collision, :to => "forced_collision#show" + get "/forced_collision", :as => :forced_collision, :to => "forced_collision#show" + end + match '/purchases/:token/:filename', :to => 'purchases#fetch', :token => /[[:alnum:]]{10}/, @@ -2120,6 +2129,15 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest assert_raises(ActionController::RoutingError){ list_todo_path(:list_id => '2', :id => '1') } end + def test_named_routes_collision_is_avoided_unless_explicitly_given_as + assert_equal "/c/1", routes_collision_path(1) + assert_equal "/forced_collision", routes_forced_collision_path + end + + def test_explicitly_avoiding_the_named_route + assert !respond_to?(:routes_no_collision_path) + end + def test_controller_name_with_leading_slash_raise_error assert_raise(ArgumentError) do self.class.stub_controllers do |routes| -- cgit v1.2.3 From 626881577949ffce8370e097aa3efb3fec47d4f5 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Wed, 29 Sep 2010 12:40:01 -0300 Subject: Initialize @view_context_class and cache view_context_class value. --- actionpack/lib/abstract_controller/rendering.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 5d9b35d297..918def3e81 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -66,7 +66,7 @@ module AbstractController attr_writer :view_context_class def view_context_class - @view_context_class || self.class.view_context_class + @view_context_class ||= self.class.view_context_class end def initialize(*) -- cgit v1.2.3 From bc0e7f4e374d4f72d1254f51e8c116f358826855 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Wed, 29 Sep 2010 11:10:38 -0300 Subject: Test correct method behaviour. --- actionpack/test/controller/capture_test.rb | 6 +++++- actionpack/test/fixtures/test/proper_block_detection.erb | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/controller/capture_test.rb b/actionpack/test/controller/capture_test.rb index eb426e855b..d78acb8ce8 100644 --- a/actionpack/test/controller/capture_test.rb +++ b/actionpack/test/controller/capture_test.rb @@ -25,6 +25,10 @@ class CaptureController < ActionController::Base render :layout => "talk_from_action" end + def proper_block_detection + @todo = "some todo" + end + def rescue_action(e) raise end end @@ -66,8 +70,8 @@ class CaptureTest < ActionController::TestCase end def test_proper_block_detection - @todo = "some todo" get :proper_block_detection + assert_equal "some todo", @response.body end private diff --git a/actionpack/test/fixtures/test/proper_block_detection.erb b/actionpack/test/fixtures/test/proper_block_detection.erb index 23564dbcee..b55efbb25d 100644 --- a/actionpack/test/fixtures/test/proper_block_detection.erb +++ b/actionpack/test/fixtures/test/proper_block_detection.erb @@ -1 +1 @@ -<%= @todo %> +<%= @todo %> \ No newline at end of file -- cgit v1.2.3 From 152580ee00205b42de45950d69349c6eab6dd291 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Wed, 29 Sep 2010 11:37:08 -0300 Subject: Don't try to interpolate string if there's no interpolation point at all. --- actionpack/lib/action_dispatch/routing/mapper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 0cb02c5b80..189da138d8 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -349,7 +349,7 @@ module ActionDispatch options = args.last.is_a?(Hash) ? args.pop : {} path = args.shift || block - path_proc = path.is_a?(Proc) ? path : proc { |params| params.empty? ? path : (path % params) } + path_proc = path.is_a?(Proc) ? path : proc { |params| (params.empty? || !path.match(/%{\w*}/)) ? path : (path % params) } status = options[:status] || 301 lambda do |env| -- cgit v1.2.3 From 8823b85010a217df555b981a453384e24ce7da47 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Wed, 29 Sep 2010 12:13:58 -0300 Subject: Remove redundant conditional. --- actionpack/lib/action_dispatch/testing/assertions/response.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb index 10b122557a..e381b9abdf 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/response.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb @@ -84,11 +84,7 @@ module ActionDispatch when %r{^\w[\w\d+.-]*:.*} fragment when String - if fragment =~ %r{^\w[\w\d+.-]*:.*} - fragment - else - @request.protocol + @request.host_with_port + fragment - end + @request.protocol + @request.host_with_port + fragment when :back raise RedirectBackError unless refer = @request.headers["Referer"] refer -- cgit v1.2.3 From c37800aae123d21d53a49433cac2e0a2479c6bbd Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Wed, 29 Sep 2010 12:55:43 -0300 Subject: _ is not a valid scheme name character, \w includes it and also is redundant with \d. 'The scheme name consists of a letter followed by any combination of letters, digits, and the plus ("+"), period ("."), or hyphen ("-") characters; and is terminated by a colon (":").' --- actionpack/lib/action_dispatch/testing/assertions/response.rb | 2 +- actionpack/test/controller/action_pack_assertions_test.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb index e381b9abdf..1558c3ae05 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/response.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb @@ -81,7 +81,7 @@ module ActionDispatch def normalize_argument_to_redirection(fragment) case fragment - when %r{^\w[\w\d+.-]*:.*} + when %r{^\w[A-Za-z\d+.-]*:.*} fragment when String @request.protocol + @request.host_with_port + fragment diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index d9d258e593..5a8b763717 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -32,6 +32,8 @@ class ActionPackAssertionsController < ActionController::Base def redirect_to_path() redirect_to '/some/path' end + def redirect_invalid_external_route() redirect_to 'ht_tp://www.rubyonrails.org' end + def redirect_to_named_route() redirect_to route_one_url end def redirect_external() redirect_to "http://www.rubyonrails.org"; end @@ -368,6 +370,11 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase end end + def test_redirect_invalid_external_route + process :redirect_invalid_external_route + assert_redirected_to "http://test.hostht_tp://www.rubyonrails.org" + end + def test_redirected_to_url_full_url process :redirect_to_path assert_redirected_to 'http://test.host/some/path' -- cgit v1.2.3 From 258f7b586e68ab8e6421ea3e43707ada5db20fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 29 Sep 2010 10:34:37 -0700 Subject: Fix a small typo (ht: masterkain) --- actionpack/lib/abstract_controller/layouts.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index 5c853c3034..e706dbd902 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -347,7 +347,7 @@ module AbstractController begin layout_name = _layout if action_has_layout? rescue NameError => e - raise e.class, "Coult not render layout: #{e.message}" + raise e.class, "Could not render layout: #{e.message}" end if require_layout && action_has_layout? && !layout_name -- cgit v1.2.3 From 6371e5b99f933ebe462784b5272fdf12e9602e5a Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Wed, 29 Sep 2010 14:35:24 -0300 Subject: We can't assign @view_context_class here, define super() in test instead if we want to avoid warnings. --- actionpack/lib/abstract_controller/rendering.rb | 2 +- actionpack/test/controller/filters_test.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 918def3e81..5d9b35d297 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -66,7 +66,7 @@ module AbstractController attr_writer :view_context_class def view_context_class - @view_context_class ||= self.class.view_context_class + @view_context_class || self.class.view_context_class end def initialize(*) diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index d13ebc705a..dfc90943e1 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -314,6 +314,7 @@ class FilterTest < ActionController::TestCase def initialize @@execution_log = "" + super() end before_filter { |c| c.class.execution_log << " before procfilter " } -- cgit v1.2.3 From c57f5d58ea5ba60b0997017ab322481377c81c2c Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 29 Sep 2010 10:39:17 -0700 Subject: no need to call e.class --- actionpack/lib/abstract_controller/layouts.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index e706dbd902..b68c7d9216 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -347,7 +347,7 @@ module AbstractController begin layout_name = _layout if action_has_layout? rescue NameError => e - raise e.class, "Could not render layout: #{e.message}" + raise e, "Could not render layout: #{e.message}" end if require_layout && action_has_layout? && !layout_name -- cgit v1.2.3 From 1c0be7baac8e736e2ddd659ac2d6ef1845f756c7 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 29 Sep 2010 11:34:51 -0700 Subject: fixing space error --- actionpack/test/controller/log_subscriber_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/test/controller/log_subscriber_test.rb b/actionpack/test/controller/log_subscriber_test.rb index b5bc0e9e9a..10873708fe 100644 --- a/actionpack/test/controller/log_subscriber_test.rb +++ b/actionpack/test/controller/log_subscriber_test.rb @@ -23,7 +23,7 @@ module Another def with_fragment_cache render :inline => "<%= cache('foo'){ 'bar' } %>" end - + def with_fragment_cache_and_percent_in_key render :inline => "<%= cache('foo%bar'){ 'Contains % sign in key' } %>" end -- cgit v1.2.3 From a5f8f5908116081a3461409eda53e62d997d5b40 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 29 Sep 2010 11:47:27 -0700 Subject: dry up action_methods --- actionpack/lib/abstract_controller/base.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/abstract_controller/base.rb b/actionpack/lib/abstract_controller/base.rb index 85270d84d8..ce88803a9c 100644 --- a/actionpack/lib/abstract_controller/base.rb +++ b/actionpack/lib/abstract_controller/base.rb @@ -61,13 +61,13 @@ module AbstractController def action_methods @action_methods ||= begin # All public instance methods of this class, including ancestors - methods = public_instance_methods(true).map { |m| m.to_s }.to_set - + methods = (public_instance_methods(true) - # Except for public instance methods of Base and its ancestors - internal_methods.map { |m| m.to_s } + + internal_methods + # Be sure to include shadowed public instance methods of this class - public_instance_methods(false).map { |m| m.to_s } - + public_instance_methods(false)).map { |x| x.to_s } - # And always exclude explicitly hidden actions - hidden_actions + hidden_actions.to_a # Clear out AS callback method pollution methods.reject { |method| method =~ /_one_time_conditions/ } -- cgit v1.2.3 From 1d9a219307ec5cc506635ee0bd3d368955d5b4a6 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 29 Sep 2010 11:53:34 -0700 Subject: oops, missed a uniq --- actionpack/lib/abstract_controller/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/abstract_controller/base.rb b/actionpack/lib/abstract_controller/base.rb index ce88803a9c..f9f6eb945e 100644 --- a/actionpack/lib/abstract_controller/base.rb +++ b/actionpack/lib/abstract_controller/base.rb @@ -65,7 +65,7 @@ module AbstractController # Except for public instance methods of Base and its ancestors internal_methods + # Be sure to include shadowed public instance methods of this class - public_instance_methods(false)).map { |x| x.to_s } - + public_instance_methods(false)).uniq.map { |x| x.to_s } - # And always exclude explicitly hidden actions hidden_actions.to_a -- cgit v1.2.3 From 2437356cdacf2b774147b4da38de1d137e0a8b26 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 29 Sep 2010 15:37:38 -0700 Subject: removing lollerject --- actionpack/lib/action_controller/metal/http_authentication.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/metal/http_authentication.rb b/actionpack/lib/action_controller/metal/http_authentication.rb index 6a7e170306..53444f31a8 100644 --- a/actionpack/lib/action_controller/metal/http_authentication.rb +++ b/actionpack/lib/action_controller/metal/http_authentication.rb @@ -214,7 +214,7 @@ module ActionController def encode_credentials(http_method, credentials, password, password_is_ha1) credentials[:response] = expected_response(http_method, credentials[:uri], credentials, password, password_is_ha1) - "Digest " + credentials.sort_by {|x| x[0].to_s }.inject([]) {|a, v| a << "#{v[0]}='#{v[1]}'" }.join(', ') + "Digest " + credentials.sort_by {|x| x[0].to_s }.map {|v| "#{v[0]}='#{v[1]}'" }.join(', ') end def decode_credentials_header(request) -- cgit v1.2.3 From 3f88f26d1e17277dfa85a22bb01c1db558b6addf Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 29 Sep 2010 15:41:06 -0700 Subject: removing more lolinject --- .../lib/action_controller/metal/http_authentication.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/metal/http_authentication.rb b/actionpack/lib/action_controller/metal/http_authentication.rb index 53444f31a8..e0c5eaca84 100644 --- a/actionpack/lib/action_controller/metal/http_authentication.rb +++ b/actionpack/lib/action_controller/metal/http_authentication.rb @@ -423,14 +423,13 @@ module ActionController # Returns nil if no token is found. def token_and_options(request) if header = request.authorization.to_s[/^Token (.*)/] - values = $1.split(','). - inject({}) do |memo, value| - value.strip! # remove any spaces between commas and values - key, value = value.split(/\=\"?/) # split key=value pairs - value.chomp!('"') # chomp trailing " in value - value.gsub!(/\\\"/, '"') # unescape remaining quotes - memo.update(key => value) - end + values = Hash[$1.split(',').map do |value| + value.strip! # remove any spaces between commas and values + key, value = value.split(/\=\"?/) # split key=value pairs + value.chomp!('"') # chomp trailing " in value + value.gsub!(/\\\"/, '"') # unescape remaining quotes + [key, value] + end] [values.delete("token"), values.with_indifferent_access] end end -- cgit v1.2.3 From ab0d216b670e13d6f65e82dfdeb3d08c75101274 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 29 Sep 2010 15:43:27 -0700 Subject: reduce function calls on Array --- actionpack/lib/action_controller/metal/http_authentication.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/metal/http_authentication.rb b/actionpack/lib/action_controller/metal/http_authentication.rb index e0c5eaca84..547cec7081 100644 --- a/actionpack/lib/action_controller/metal/http_authentication.rb +++ b/actionpack/lib/action_controller/metal/http_authentication.rb @@ -441,9 +441,8 @@ module ActionController # # Returns String. def encode_credentials(token, options = {}) - values = ["token=#{token.to_s.inspect}"] - options.each do |key, value| - values << "#{key}=#{value.to_s.inspect}" + values = ["token=#{token.to_s.inspect}"] + options.map do |key, value| + "#{key}=#{value.to_s.inspect}" end "Token #{values * ", "}" end -- cgit v1.2.3 From 78ac9c2be738ff48c847a26ae8fc4464e881e184 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 29 Sep 2010 16:09:58 -0700 Subject: dry up method checking in the request object --- actionpack/lib/action_dispatch/http/request.rb | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index 7a28228817..09d6ba8223 100644 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -54,11 +54,7 @@ module ActionDispatch # the application should use), this \method returns the overridden # value, not the original. def request_method - @request_method ||= begin - method = env["REQUEST_METHOD"] - HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}") - method - end + @request_method ||= check_method(env["REQUEST_METHOD"]) end # Returns a symbol form of the #request_method @@ -70,11 +66,7 @@ module ActionDispatch # even if it was overridden by middleware. See #request_method for # more information. def method - @method ||= begin - method = env["rack.methodoverride.original_method"] || env['REQUEST_METHOD'] - HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}") - method - end + @method ||= check_method(env["rack.methodoverride.original_method"] || env['REQUEST_METHOD']) end # Returns a symbol form of the #method @@ -246,5 +238,12 @@ module ActionDispatch def local? LOCALHOST.any? { |local_ip| local_ip === remote_addr && local_ip === remote_ip } end + + private + + def check_method(name) + HTTP_METHOD_LOOKUP[name] || raise(ActionController::UnknownHttpMethod, "#{name}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}") + name + end end end -- cgit v1.2.3 From 2eef53b163353898a0f96d559e3f80600eb6ba15 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 29 Sep 2010 16:17:56 -0700 Subject: removing useless code --- actionpack/lib/action_view/helpers/form_options_helper.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index 83434a9340..7d6aca0470 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -297,7 +297,6 @@ module ActionView def options_for_select(container, selected = nil) return container if String === container - container = container.to_a if Hash === container selected, disabled = extract_selected_and_disabled(selected).map do | r | Array.wrap(r).map(&:to_s) end -- cgit v1.2.3 From a40e3c1a9604ab3737ad2465c8f6a6db0fe0cc78 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 29 Sep 2010 16:40:47 -0700 Subject: removing crazy finalizer code until there is proof that we need it --- actionpack/lib/action_view/template.rb | 9 --------- 1 file changed, 9 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index a999a0b7d7..405e1736ba 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -101,14 +101,6 @@ module ActionView attr_reader :source, :identifier, :handler, :virtual_path, :formats, :original_encoding - Finalizer = proc do |method_name, mod| - proc do - mod.module_eval do - remove_possible_method method_name - end - end - end - def initialize(source, identifier, handler, details) @source = source @identifier = identifier @@ -253,7 +245,6 @@ module ActionView begin mod.module_eval(source, identifier, 0) - ObjectSpace.define_finalizer(self, Finalizer[method_name, mod]) method_name rescue Exception => e # errors from template code -- cgit v1.2.3 From 8efdffeda31b520b9b534dc614c6039404288c26 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Thu, 30 Sep 2010 02:22:00 +0800 Subject: no need of nil check --- actionpack/lib/action_controller/test_case.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 70a5de7f30..1af75fc2d7 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -394,7 +394,7 @@ module ActionController parameters ||= {} @request.assign_parameters(@routes, @controller.class.name.underscore.sub(/_controller$/, ''), action.to_s, parameters) - @request.session = ActionController::TestSession.new(session) unless session.nil? + @request.session = ActionController::TestSession.new(session) if session @request.session["flash"] = @request.flash.update(flash || {}) @request.session["flash"].sweep -- cgit v1.2.3 From 692f5184c405b3b0f9b6ac02c37aaefb7d2ffb62 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Thu, 30 Sep 2010 02:24:47 +0800 Subject: no need to check for nil? --- actionpack/lib/action_dispatch/middleware/session/abstract_store.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb index ea49b30630..db0187c015 100644 --- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb @@ -165,7 +165,7 @@ module ActionDispatch return response unless value cookie = { :value => value } - unless options[:expire_after].nil? + if options[:expire_after] cookie[:expires] = Time.now + options.delete(:expire_after) end -- cgit v1.2.3 From 08a08d97dd1307ab9544cc55fbd398c6acdc4c89 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Thu, 30 Sep 2010 02:26:22 +0800 Subject: no need to check for nil? --- actionpack/lib/action_view/helpers/form_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index c47fac05ef..cabe272cc7 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1015,7 +1015,7 @@ module ActionView module ClassMethods def value(object, method_name) - object.send method_name unless object.nil? + object.send method_name if object end def value_before_type_cast(object, method_name) @@ -1055,7 +1055,7 @@ module ActionView private def add_default_name_and_id_for_value(tag_value, options) - unless tag_value.nil? + if tag_value pretty_tag_value = tag_value.to_s.gsub(/\s/, "_").gsub(/[^-\w]/, "").downcase specified_id = options["id"] add_default_name_and_id(options) -- cgit v1.2.3 From 618407db56b39a4130e05779339534ae2ebf883e Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Thu, 30 Sep 2010 02:27:13 +0800 Subject: another case of extra nil? check --- actionpack/lib/action_view/helpers/text_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 3bc5afc2c4..94348cf9fa 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -365,7 +365,7 @@ module ActionView # <% end %> def current_cycle(name = "default") cycle = get_cycle(name) - cycle.current_value unless cycle.nil? + cycle.current_value if cycle end # Resets a cycle so that it starts from the first element the next time -- cgit v1.2.3 From 29c32e832908e13f0e360bbe47c80d5578bffba1 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 29 Sep 2010 17:57:39 -0700 Subject: tag value can be false, so nil? check is necessary --- actionpack/lib/action_view/helpers/form_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index cabe272cc7..1836baaf12 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1055,7 +1055,7 @@ module ActionView private def add_default_name_and_id_for_value(tag_value, options) - if tag_value + unless tag_value.nil? pretty_tag_value = tag_value.to_s.gsub(/\s/, "_").gsub(/[^-\w]/, "").downcase specified_id = options["id"] add_default_name_and_id(options) -- cgit v1.2.3 From 7e057d11aa21383394e570d0de8f4d5f3729d024 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 29 Sep 2010 18:23:33 -0700 Subject: fixing regexp warnings --- actionpack/lib/action_dispatch/routing/mapper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 189da138d8..0c6e1b37a7 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -349,7 +349,7 @@ module ActionDispatch options = args.last.is_a?(Hash) ? args.pop : {} path = args.shift || block - path_proc = path.is_a?(Proc) ? path : proc { |params| (params.empty? || !path.match(/%{\w*}/)) ? path : (path % params) } + path_proc = path.is_a?(Proc) ? path : proc { |params| (params.empty? || !path.match(/%\{\w*\}/)) ? path : (path % params) } status = options[:status] || 301 lambda do |env| -- cgit v1.2.3 From 31752f3516e5977b459cc713ae50515b20fda67b Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 29 Sep 2010 18:32:51 -0700 Subject: avoid creating a block if possible --- actionpack/lib/action_dispatch/routing/mapper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 0c6e1b37a7..0a888505d2 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -345,10 +345,10 @@ module ActionDispatch # Redirect any path to another path: # # match "/stories" => redirect("/posts") - def redirect(*args, &block) + def redirect(*args) options = args.last.is_a?(Hash) ? args.pop : {} - path = args.shift || block + path = args.shift || Proc.new path_proc = path.is_a?(Proc) ? path : proc { |params| (params.empty? || !path.match(/%\{\w*\}/)) ? path : (path % params) } status = options[:status] || 301 -- cgit v1.2.3 From 69f97f469747777ed1c457715f5361f6b8a0ab7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 30 Sep 2010 07:25:06 +0200 Subject: Use .find here as it is simpler and faster. --- actionpack/lib/action_dispatch/routing/mapper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 0a888505d2..47aed0273c 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -1130,7 +1130,7 @@ module ActionDispatch end candidate = name.select(&:present?).join("_").presence - candidate unless as.nil? && @set.routes.map(&:name).include?(candidate) + candidate unless as.nil? && @set.routes.find { |r| r.name == candidate } end end -- cgit v1.2.3 From 22b11a41cc764bc0f7b0c0f518a5289230428597 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sat, 25 Sep 2010 19:22:32 +0200 Subject: Allow mounting engines at '/' Without that commit script_name always become '/', which results in paths like //posts/1 instead of /posts/1 --- .../lib/action_dispatch/routing/route_set.rb | 2 +- actionpack/test/dispatch/prefix_generation_test.rb | 93 ++++++++++++++++++---- 2 files changed, 78 insertions(+), 17 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 5d18dfe369..99a3019f3a 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -511,7 +511,7 @@ module ActionDispatch end script_name = options.delete(:script_name) - path = (script_name.blank? ? _generate_prefix(options) : script_name).to_s + path = (script_name.blank? ? _generate_prefix(options) : script_name.chomp('/')).to_s path_options = options.except(*RESERVED_OPTIONS) path_options = yield(path_options) if block_given? diff --git a/actionpack/test/dispatch/prefix_generation_test.rb b/actionpack/test/dispatch/prefix_generation_test.rb index 26d76557dd..18f28deee4 100644 --- a/actionpack/test/dispatch/prefix_generation_test.rb +++ b/actionpack/test/dispatch/prefix_generation_test.rb @@ -1,8 +1,23 @@ require 'abstract_unit' +require 'rack/test' module TestGenerationPrefix + class Post + extend ActiveModel::Naming + + def to_param + "1" + end + + def self.model_name + klass = "Post" + def klass.name; self end + + ActiveModel::Name.new(klass) + end + end + class WithMountedEngine < ActionDispatch::IntegrationTest - require 'rack/test' include Rack::Test::Methods class BlogEngine @@ -55,21 +70,6 @@ module TestGenerationPrefix # force draw RailsApplication.routes - class Post - extend ActiveModel::Naming - - def to_param - "1" - end - - def self.model_name - klass = "Post" - def klass.name; self end - - ActiveModel::Name.new(klass) - end - end - class ::InsideEngineGeneratingController < ActionController::Base include BlogEngine.routes.url_helpers include RailsApplication.routes.mounted_helpers @@ -253,4 +253,65 @@ module TestGenerationPrefix assert_equal "http://www.example.com/awesome/blog/posts/1", path end end + + class EngineMountedAtRoot < ActionDispatch::IntegrationTest + include Rack::Test::Methods + + class BlogEngine + def self.routes + @routes ||= begin + routes = ActionDispatch::Routing::RouteSet.new + routes.draw do + match "/posts/:id", :to => "posts#show", :as => :post + end + + routes + end + end + + def self.call(env) + env['action_dispatch.routes'] = routes + routes.call(env) + end + end + + class RailsApplication + def self.routes + @routes ||= begin + routes = ActionDispatch::Routing::RouteSet.new + routes.draw do + mount BlogEngine => "/" + end + + routes + end + end + + def self.call(env) + env['action_dispatch.routes'] = routes + routes.call(env) + end + end + + # force draw + RailsApplication.routes + + class ::PostsController < ActionController::Base + include BlogEngine.routes.url_helpers + include RailsApplication.routes.mounted_helpers + + def show + render :text => post_path(:id => params[:id]) + end + end + + def app + RailsApplication + end + + test "generating path inside engine" do + get "/posts/1" + assert_equal "/posts/1", last_response.body + end + end end -- cgit v1.2.3 From ec5d846ac6137e60d81257041e4fde82c0480b32 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sun, 26 Sep 2010 00:17:06 +0200 Subject: Properly reload routes defined in class definition Sometimes it's easier to define routes inside Engine or Application class definition (e.g. one file applications). The problem with such case is that if there is a plugin that has config/routes.rb file, it will trigger routes reload on application. Since routes definition for application is not in config/routes.rb file routes_reloader will fail to reload application's routes properly. With this commit you can pass routes definition as a block to routes method, which will allow to properly reload it: class MyApp::Application < Rails::Application routes do resources :users end end --- actionpack/lib/action_dispatch/routing/route_set.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 99a3019f3a..32f41934f1 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -1,6 +1,7 @@ require 'rack/mount' require 'forwardable' require 'active_support/core_ext/object/to_query' +require 'active_support/core_ext/hash/slice' module ActionDispatch module Routing -- cgit v1.2.3 From 6a55ca346e543e4e112648cca2a01230c32b21ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 30 Sep 2010 11:40:51 +0200 Subject: Revert "removing crazy finalizer code until there is proof that we need it" This reverts commit a40e3c1a9604ab3737ad2465c8f6a6db0fe0cc78. --- actionpack/lib/action_view/template.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index 405e1736ba..164d177dcc 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -101,6 +101,16 @@ module ActionView attr_reader :source, :identifier, :handler, :virtual_path, :formats, :original_encoding + # This finalizer is needed (and exactly with a proc inside another proc) + # otherwise templates leak in development. + Finalizer = proc do |method_name, mod| + proc do + mod.module_eval do + remove_possible_method method_name + end + end + end + def initialize(source, identifier, handler, details) @source = source @identifier = identifier @@ -245,6 +255,7 @@ module ActionView begin mod.module_eval(source, identifier, 0) + ObjectSpace.define_finalizer(self, Finalizer[method_name, mod]) method_name rescue Exception => e # errors from template code -- cgit v1.2.3