From 4e2852a4870677cab12e61795a1c500058f8f111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@gmail.com> Date: Tue, 19 Jan 2010 12:17:52 +0100 Subject: Do not send rack.input or any other rack information to AD listeners. --- actionpack/test/dispatch/subscriber_test.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/subscriber_test.rb b/actionpack/test/dispatch/subscriber_test.rb index a7f1a2659a..3096c132e7 100644 --- a/actionpack/test/dispatch/subscriber_test.rb +++ b/actionpack/test/dispatch/subscriber_test.rb @@ -78,9 +78,8 @@ module DispatcherSubscriberTest log = @logger.logged(:info).first assert_equal 1, @logger.logged(:info).size - assert_match %r{^Processing "/" to text/html}, log - assert_match %r{\(for 127\.0\.0\.1}, log - assert_match %r{\[GET\]}, log + assert_match %r{^Started GET "/"}, log + assert_match %r{for 127\.0\.0\.1}, log end def test_subscriber_has_its_logged_flushed_after_request -- cgit v1.2.3 From 5a81dbf4894f112b73da160611c8be28b44c261f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@gmail.com> Date: Tue, 19 Jan 2010 12:22:22 +0100 Subject: Fix failing test. --- actionpack/test/controller/new_base/base_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/new_base/base_test.rb b/actionpack/test/controller/new_base/base_test.rb index 964780eaf2..579f9f349f 100644 --- a/actionpack/test/controller/new_base/base_test.rb +++ b/actionpack/test/controller/new_base/base_test.rb @@ -77,9 +77,9 @@ module Dispatching test "action methods" do assert_equal Set.new(%w( + index modify_response_headers modify_response_body_twice - index modify_response_body show_actions )), SimpleController.action_methods @@ -88,7 +88,7 @@ module Dispatching assert_equal Set.new, Submodule::ContainedEmptyController.action_methods get "/dispatching/simple/show_actions" - assert_body "actions: modify_response_headers, modify_response_body_twice, index, modify_response_body, show_actions" + assert_body "actions: index, modify_response_body, modify_response_body_twice, modify_response_headers, show_actions" end end end -- cgit v1.2.3 From a8e25a518ae8df1682c84affa3b986ca3627da12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@gmail.com> Date: Tue, 19 Jan 2010 12:52:10 +0100 Subject: Move parameters to the top on logging. --- .../test/activerecord/controller_runtime_test.rb | 4 +- actionpack/test/controller/subscriber_test.rb | 54 ++++++++++++---------- 2 files changed, 32 insertions(+), 26 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/activerecord/controller_runtime_test.rb b/actionpack/test/activerecord/controller_runtime_test.rb index d6f7cd80ab..37c7738301 100644 --- a/actionpack/test/activerecord/controller_runtime_test.rb +++ b/actionpack/test/activerecord/controller_runtime_test.rb @@ -37,8 +37,8 @@ module ControllerRuntimeSubscriberTest get :show wait - assert_equal 1, @logger.logged(:info).size - assert_match /\(Views: [\d\.]+ms | ActiveRecord: [\d\.]+ms\)/, @logger.logged(:info)[0] + assert_equal 2, @logger.logged(:info).size + assert_match /\(Views: [\d\.]+ms | ActiveRecord: [\d\.]+ms\)/, @logger.logged(:info)[1] end class SyncSubscriberTest < ActionController::TestCase diff --git a/actionpack/test/controller/subscriber_test.rb b/actionpack/test/controller/subscriber_test.rb index 24132ee928..950eecaf6f 100644 --- a/actionpack/test/controller/subscriber_test.rb +++ b/actionpack/test/controller/subscriber_test.rb @@ -63,13 +63,19 @@ module ActionControllerSubscriberTest ActionController::Base.logger = logger end + def test_start_processing + get :show + wait + assert_equal 2, logs.size + assert_equal "Processing by Another::SubscribersController#show as HTML", logs.first + end + def test_process_action get :show wait - assert_equal 1, logs.size - assert_match /Completed/, logs.first - assert_match /\[200\]/, logs.first - assert_match /Another::SubscribersController#show/, logs.first + assert_equal 2, logs.size + assert_match /Completed/, logs.last + assert_match /with 200/, logs.last end def test_process_action_without_parameters @@ -82,14 +88,14 @@ module ActionControllerSubscriberTest get :show, :id => '10' wait - assert_equal 2, logs.size - assert_equal 'Parameters: {"id"=>"10"}', logs[0] + assert_equal 3, logs.size + assert_equal 'Parameters: {"id"=>"10"}', logs[1] end def test_process_action_with_view_runtime get :show wait - assert_match /\(Views: [\d\.]+ms\)/, logs[0] + assert_match /\(Views: [\d\.]+ms\)/, logs[1] end def test_process_action_with_filter_parameters @@ -98,7 +104,7 @@ module ActionControllerSubscriberTest get :show, :lifo => 'Pratik', :amount => '420', :step => '1' wait - params = logs[0] + params = logs[1] assert_match /"amount"=>"\[FILTERED\]"/, params assert_match /"lifo"=>"\[FILTERED\]"/, params assert_match /"step"=>"1"/, params @@ -108,34 +114,34 @@ module ActionControllerSubscriberTest get :redirector wait - assert_equal 2, logs.size - assert_equal "Redirected to http://foo.bar/", logs[0] + assert_equal 3, logs.size + assert_equal "Redirected to http://foo.bar/", logs[1] end def test_send_data get :data_sender wait - assert_equal 2, logs.size - assert_match /Sent data omg\.txt/, logs[0] + assert_equal 3, logs.size + assert_match /Sent data omg\.txt/, logs[1] end def test_send_file get :file_sender wait - assert_equal 2, logs.size - assert_match /Sent file/, logs[0] - assert_match /test\/fixtures\/company\.rb/, logs[0] + assert_equal 3, logs.size + assert_match /Sent file/, logs[1] + assert_match /test\/fixtures\/company\.rb/, logs[1] end def test_send_xfile get :xfile_sender wait - assert_equal 2, logs.size - assert_match /Sent X\-Sendfile header/, logs[0] - assert_match /test\/fixtures\/company\.rb/, logs[0] + assert_equal 3, logs.size + assert_match /Sent X\-Sendfile header/, logs[1] + assert_match /test\/fixtures\/company\.rb/, logs[1] end def test_with_fragment_cache @@ -143,9 +149,9 @@ module ActionControllerSubscriberTest get :with_fragment_cache wait - assert_equal 3, logs.size - assert_match /Exist fragment\? views\/foo/, logs[0] - assert_match /Write fragment views\/foo/, logs[1] + assert_equal 4, logs.size + assert_match /Exist fragment\? views\/foo/, logs[1] + assert_match /Write fragment views\/foo/, logs[2] ensure ActionController::Base.perform_caching = true end @@ -155,9 +161,9 @@ module ActionControllerSubscriberTest get :with_page_cache wait - assert_equal 2, logs.size - assert_match /Write page/, logs[0] - assert_match /\/index\.html/, logs[0] + assert_equal 3, logs.size + assert_match /Write page/, logs[1] + assert_match /\/index\.html/, logs[1] ensure ActionController::Base.perform_caching = true end -- cgit v1.2.3 From 88ffba232987d00717560eaac7ab4f1104e054cd Mon Sep 17 00:00:00 2001 From: Joshua Peek <josh@joshpeek.com> Date: Tue, 19 Jan 2010 09:05:34 -0600 Subject: Disable ShowExceptions during integration tests --- .../dispatch/request/json_params_parsing_test.rb | 2 +- .../dispatch/request/xml_params_parsing_test.rb | 2 +- actionpack/test/dispatch/show_exceptions_test.rb | 22 +++++++++++----------- 3 files changed, 13 insertions(+), 13 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/request/json_params_parsing_test.rb b/actionpack/test/dispatch/request/json_params_parsing_test.rb index d3308f73cc..0faa99a912 100644 --- a/actionpack/test/dispatch/request/json_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/json_params_parsing_test.rb @@ -35,7 +35,7 @@ class JsonParamsParsingTest < ActionController::IntegrationTest begin $stderr = StringIO.new json = "[\"person]\": {\"name\": \"David\"}}" - post "/parse", json, {'CONTENT_TYPE' => 'application/json'} + post "/parse", json, {'CONTENT_TYPE' => 'application/json', 'action_dispatch.show_exceptions' => true} assert_response :error $stderr.rewind && err = $stderr.read assert err =~ /Error occurred while parsing request parameters/ diff --git a/actionpack/test/dispatch/request/xml_params_parsing_test.rb b/actionpack/test/dispatch/request/xml_params_parsing_test.rb index 96189e4ca2..488799ac2a 100644 --- a/actionpack/test/dispatch/request/xml_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/xml_params_parsing_test.rb @@ -43,7 +43,7 @@ class XmlParamsParsingTest < ActionController::IntegrationTest begin $stderr = StringIO.new xml = "<person><name>David</name><avatar type='file' name='me.jpg' content_type='image/jpg'>#{ActiveSupport::Base64.encode64('ABC')}</avatar></pineapple>" - post "/parse", xml, default_headers + post "/parse", xml, default_headers.merge('action_dispatch.show_exceptions' => true) assert_response :error $stderr.rewind && err = $stderr.read assert err =~ /Error occurred while parsing request parameters/ diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb index def86c8323..97da680f17 100644 --- a/actionpack/test/dispatch/show_exceptions_test.rb +++ b/actionpack/test/dispatch/show_exceptions_test.rb @@ -38,15 +38,15 @@ class ShowExceptionsTest < ActionController::IntegrationTest @app = ProductionApp self.remote_addr = '208.77.188.166' - get "/" + get "/", {}, {'action_dispatch.show_exceptions' => true} assert_response 500 assert_equal "500 error fixture\n", body - get "/not_found" + get "/not_found", {}, {'action_dispatch.show_exceptions' => true} assert_response 404 assert_equal "404 error fixture\n", body - get "/method_not_allowed" + get "/method_not_allowed", {}, {'action_dispatch.show_exceptions' => true} assert_response 405 assert_equal "", body end @@ -56,15 +56,15 @@ class ShowExceptionsTest < ActionController::IntegrationTest ['127.0.0.1', '::1'].each do |ip_address| self.remote_addr = ip_address - get "/" + get "/", {}, {'action_dispatch.show_exceptions' => true} assert_response 500 assert_match /puke/, body - get "/not_found" + get "/not_found", {}, {'action_dispatch.show_exceptions' => true} assert_response 404 assert_match /#{ActionController::UnknownAction.name}/, body - get "/method_not_allowed" + get "/method_not_allowed", {}, {'action_dispatch.show_exceptions' => true} assert_response 405 assert_match /ActionController::MethodNotAllowed/, body end @@ -78,11 +78,11 @@ class ShowExceptionsTest < ActionController::IntegrationTest @app = ProductionApp self.remote_addr = '208.77.188.166' - get "/" + get "/", {}, {'action_dispatch.show_exceptions' => true} assert_response 500 assert_equal "500 localized error fixture\n", body - get "/not_found" + get "/not_found", {}, {'action_dispatch.show_exceptions' => true} assert_response 404 assert_equal "404 error fixture\n", body ensure @@ -94,15 +94,15 @@ class ShowExceptionsTest < ActionController::IntegrationTest @app = DevelopmentApp self.remote_addr = '208.77.188.166' - get "/" + get "/", {}, {'action_dispatch.show_exceptions' => true} assert_response 500 assert_match /puke/, body - get "/not_found" + get "/not_found", {}, {'action_dispatch.show_exceptions' => true} assert_response 404 assert_match /#{ActionController::UnknownAction.name}/, body - get "/method_not_allowed" + get "/method_not_allowed", {}, {'action_dispatch.show_exceptions' => true} assert_response 405 assert_match /ActionController::MethodNotAllowed/, body end -- cgit v1.2.3 From 1a50d2e66a80c910fe1e2203eb2c993e5dbc4e5b Mon Sep 17 00:00:00 2001 From: Yehuda Katz <wycats@Yehuda-Katz.local> Date: Tue, 19 Jan 2010 22:35:09 -0800 Subject: Stop overriding LoadError.new to return a MissingSourceError (and sometimes nil!) --- actionpack/test/controller/new_base/base_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/new_base/base_test.rb b/actionpack/test/controller/new_base/base_test.rb index 579f9f349f..0b40f8ce95 100644 --- a/actionpack/test/controller/new_base/base_test.rb +++ b/actionpack/test/controller/new_base/base_test.rb @@ -22,7 +22,7 @@ module Dispatching end def show_actions - render :text => "actions: #{action_methods.to_a.join(', ')}" + render :text => "actions: #{action_methods.to_a.sort.join(', ')}" end protected -- cgit v1.2.3 From 6e26be69606c52dbccfad366661b455157c35be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@gmail.com> Date: Wed, 20 Jan 2010 14:41:23 +0100 Subject: Move ActionController::Translation to AbstractController::Translation. --- actionpack/test/abstract/translation_test.rb | 26 ++++++++++++++++++++++++++ actionpack/test/controller/translation_test.rb | 26 -------------------------- 2 files changed, 26 insertions(+), 26 deletions(-) create mode 100644 actionpack/test/abstract/translation_test.rb delete mode 100644 actionpack/test/controller/translation_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/abstract/translation_test.rb b/actionpack/test/abstract/translation_test.rb new file mode 100644 index 0000000000..0bf61a6556 --- /dev/null +++ b/actionpack/test/abstract/translation_test.rb @@ -0,0 +1,26 @@ +require 'abstract_unit' + +# class TranslatingController < ActionController::Base +# end + +class TranslationControllerTest < Test::Unit::TestCase + def setup + @controller = ActionController::Base.new + end + + def test_action_controller_base_responds_to_translate + assert @controller.respond_to?(:translate) + end + + def test_action_controller_base_responds_to_t + assert @controller.respond_to?(:t) + end + + def test_action_controller_base_responds_to_localize + assert @controller.respond_to?(:localize) + end + + def test_action_controller_base_responds_to_l + assert @controller.respond_to?(:l) + end +end \ No newline at end of file diff --git a/actionpack/test/controller/translation_test.rb b/actionpack/test/controller/translation_test.rb deleted file mode 100644 index 0bf61a6556..0000000000 --- a/actionpack/test/controller/translation_test.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'abstract_unit' - -# class TranslatingController < ActionController::Base -# end - -class TranslationControllerTest < Test::Unit::TestCase - def setup - @controller = ActionController::Base.new - end - - def test_action_controller_base_responds_to_translate - assert @controller.respond_to?(:translate) - end - - def test_action_controller_base_responds_to_t - assert @controller.respond_to?(:t) - end - - def test_action_controller_base_responds_to_localize - assert @controller.respond_to?(:localize) - end - - def test_action_controller_base_responds_to_l - assert @controller.respond_to?(:l) - end -end \ No newline at end of file -- cgit v1.2.3 From bd4f21fbac495fb28b6be993be808509e567239e Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist <s@sikachu.com> Date: Thu, 21 Jan 2010 04:37:10 +0700 Subject: Move filter_parameter_logging logic out of the controller and create ActionDispatch::ParametersFilter to handle parameter filteration instead. This will make filteration not depending on controller anymore. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim <jose.valim@gmail.com> --- actionpack/test/dispatch/request_test.rb | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index cb95ecea50..0a6180959e 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -453,6 +453,40 @@ class RequestTest < ActiveSupport::TestCase request.expects(:parameters).at_least_once.returns({}) assert_equal Mime::XML, request.negotiate_mime([Mime::XML, Mime::CSV]) end + + test "filter_parameters" do + request = stub_request + request.stubs(:request_parameters).returns({ "foo" => 1 }) + request.stubs(:query_parameters).returns({ "bar" => 2 }) + + assert_raises RuntimeError do + ActionDispatch::Http::ParametersFilter.filter_parameters + end + + test_hashes = [ + [{'foo'=>'bar'},{'foo'=>'bar'},%w'food'], + [{'foo'=>'bar'},{'foo'=>'[FILTERED]'},%w'foo'], + [{'foo'=>'bar', 'bar'=>'foo'},{'foo'=>'[FILTERED]', 'bar'=>'foo'},%w'foo baz'], + [{'foo'=>'bar', 'baz'=>'foo'},{'foo'=>'[FILTERED]', 'baz'=>'[FILTERED]'},%w'foo baz'], + [{'bar'=>{'foo'=>'bar','bar'=>'foo'}},{'bar'=>{'foo'=>'[FILTERED]','bar'=>'foo'}},%w'fo'], + [{'foo'=>{'foo'=>'bar','bar'=>'foo'}},{'foo'=>'[FILTERED]'},%w'f banana'], + [{'baz'=>[{'foo'=>'baz'}]}, {'baz'=>[{'foo'=>'[FILTERED]'}]}, %w(foo)]] + + test_hashes.each do |before_filter, after_filter, filter_words| + ActionDispatch::Http::ParametersFilter.filter_parameters(*filter_words) + assert_equal after_filter, request.__send__(:process_parameter_filter, before_filter) + + filter_words.push('blah') + ActionDispatch::Http::ParametersFilter.filter_parameters(*filter_words) do |key, value| + value.reverse! if key =~ /bargain/ + end + + before_filter['barg'] = {'bargain'=>'gain', 'blah'=>'bar', 'bar'=>{'bargain'=>{'blah'=>'foo'}}} + after_filter['barg'] = {'bargain'=>'niag', 'blah'=>'[FILTERED]', 'bar'=>{'bargain'=>{'blah'=>'[FILTERED]'}}} + + assert_equal after_filter, request.__send__(:process_parameter_filter, before_filter) + end + end protected -- cgit v1.2.3 From b1bc3b3cd352f68d79d7e232e9520eacb56ca41e Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist <s@sikachu.com> Date: Thu, 21 Jan 2010 11:48:27 +0700 Subject: Add deprecation warning for calling filter_parameter_logging ActionController::Base, and allow it to be configured in config.filter_parameters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim <jose.valim@gmail.com> --- actionpack/test/controller/filter_params_test.rb | 51 ------------------------ 1 file changed, 51 deletions(-) delete mode 100644 actionpack/test/controller/filter_params_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/controller/filter_params_test.rb b/actionpack/test/controller/filter_params_test.rb deleted file mode 100644 index 45949636c3..0000000000 --- a/actionpack/test/controller/filter_params_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'abstract_unit' - -class FilterParamController < ActionController::Base - def payment - head :ok - end -end - -class FilterParamTest < ActionController::TestCase - tests FilterParamController - - def test_filter_parameters_must_have_one_word - assert_raises RuntimeError do - FilterParamController.filter_parameter_logging - end - end - - def test_filter_parameters - assert FilterParamController.respond_to?(:filter_parameter_logging) - - test_hashes = [ - [{'foo'=>'bar'},{'foo'=>'bar'},%w'food'], - [{'foo'=>'bar'},{'foo'=>'[FILTERED]'},%w'foo'], - [{'foo'=>'bar', 'bar'=>'foo'},{'foo'=>'[FILTERED]', 'bar'=>'foo'},%w'foo baz'], - [{'foo'=>'bar', 'baz'=>'foo'},{'foo'=>'[FILTERED]', 'baz'=>'[FILTERED]'},%w'foo baz'], - [{'bar'=>{'foo'=>'bar','bar'=>'foo'}},{'bar'=>{'foo'=>'[FILTERED]','bar'=>'foo'}},%w'fo'], - [{'foo'=>{'foo'=>'bar','bar'=>'foo'}},{'foo'=>'[FILTERED]'},%w'f banana'], - [{'baz'=>[{'foo'=>'baz'}]}, {'baz'=>[{'foo'=>'[FILTERED]'}]}, %w(foo)]] - - test_hashes.each do |before_filter, after_filter, filter_words| - FilterParamController.filter_parameter_logging(*filter_words) - assert_equal after_filter, @controller.__send__(:filter_parameters, before_filter) - - filter_words.push('blah') - FilterParamController.filter_parameter_logging(*filter_words) do |key, value| - value.reverse! if key =~ /bargain/ - end - - before_filter['barg'] = {'bargain'=>'gain', 'blah'=>'bar', 'bar'=>{'bargain'=>{'blah'=>'foo'}}} - after_filter['barg'] = {'bargain'=>'niag', 'blah'=>'[FILTERED]', 'bar'=>{'bargain'=>{'blah'=>'[FILTERED]'}}} - - assert_equal after_filter, @controller.__send__(:filter_parameters, before_filter) - end - end - - def test_filter_parameters_is_protected - FilterParamController.filter_parameter_logging(:foo) - assert !FilterParamController.action_methods.include?('filter_parameters') - assert_raise(NoMethodError) { @controller.filter_parameters([{'password' => '[FILTERED]'}]) } - end -end -- cgit v1.2.3 From 31fddf2ace29518399f15f718ff408737e0031a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@gmail.com> Date: Thu, 21 Jan 2010 11:39:57 +0100 Subject: Tidy up new filter_parameters implementation. --- actionpack/test/controller/subscriber_test.rb | 5 ++- actionpack/test/dispatch/request_test.rb | 55 ++++++++++++++++++++------- 2 files changed, 46 insertions(+), 14 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/subscriber_test.rb b/actionpack/test/controller/subscriber_test.rb index 950eecaf6f..52434426f7 100644 --- a/actionpack/test/controller/subscriber_test.rb +++ b/actionpack/test/controller/subscriber_test.rb @@ -99,7 +99,8 @@ module ActionControllerSubscriberTest end def test_process_action_with_filter_parameters - Another::SubscribersController.filter_parameter_logging(:lifo, :amount) + ActionDispatch::Request.class_eval "alias :safe_process_parameter_filter :process_parameter_filter" + ActionDispatch::Request.filter_parameters(:lifo, :amount) get :show, :lifo => 'Pratik', :amount => '420', :step => '1' wait @@ -108,6 +109,8 @@ module ActionControllerSubscriberTest assert_match /"amount"=>"\[FILTERED\]"/, params assert_match /"lifo"=>"\[FILTERED\]"/, params assert_match /"step"=>"1"/, params + ensure + ActionDispatch::Request.class_eval "alias :process_parameter_filter :safe_process_parameter_filter" end def test_redirect_to diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index 0a6180959e..c5a75f5d21 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -453,16 +453,19 @@ class RequestTest < ActiveSupport::TestCase request.expects(:parameters).at_least_once.returns({}) assert_equal Mime::XML, request.negotiate_mime([Mime::XML, Mime::CSV]) end - - test "filter_parameters" do - request = stub_request - request.stubs(:request_parameters).returns({ "foo" => 1 }) - request.stubs(:query_parameters).returns({ "bar" => 2 }) - + + class FilterRequest < ActionDispatch::Request + end + + test "filter_parameters raises error without arguments" do assert_raises RuntimeError do - ActionDispatch::Http::ParametersFilter.filter_parameters + FilterRequest.filter_parameters end - + end + + test "process parameter filter" do + request = FilterRequest.new({}) + test_hashes = [ [{'foo'=>'bar'},{'foo'=>'bar'},%w'food'], [{'foo'=>'bar'},{'foo'=>'[FILTERED]'},%w'foo'], @@ -473,21 +476,47 @@ class RequestTest < ActiveSupport::TestCase [{'baz'=>[{'foo'=>'baz'}]}, {'baz'=>[{'foo'=>'[FILTERED]'}]}, %w(foo)]] test_hashes.each do |before_filter, after_filter, filter_words| - ActionDispatch::Http::ParametersFilter.filter_parameters(*filter_words) - assert_equal after_filter, request.__send__(:process_parameter_filter, before_filter) + FilterRequest.filter_parameters(*filter_words) + assert_equal after_filter, request.send(:process_parameter_filter, before_filter) filter_words.push('blah') - ActionDispatch::Http::ParametersFilter.filter_parameters(*filter_words) do |key, value| + + FilterRequest.filter_parameters(*filter_words) do |key, value| value.reverse! if key =~ /bargain/ end before_filter['barg'] = {'bargain'=>'gain', 'blah'=>'bar', 'bar'=>{'bargain'=>{'blah'=>'foo'}}} - after_filter['barg'] = {'bargain'=>'niag', 'blah'=>'[FILTERED]', 'bar'=>{'bargain'=>{'blah'=>'[FILTERED]'}}} + after_filter['barg'] = {'bargain'=>'niag', 'blah'=>'[FILTERED]', 'bar'=>{'bargain'=>{'blah'=>'[FILTERED]'}}} - assert_equal after_filter, request.__send__(:process_parameter_filter, before_filter) + assert_equal after_filter, request.send(:process_parameter_filter, before_filter) end end + test "filtered_parameters returns params filtered" do + FilterRequest.filter_parameters(:lifo, :amount) + + request = FilterRequest.new('action_dispatch.request.parameters' => + { 'lifo' => 'Pratik', 'amount' => '420', 'step' => '1' }) + + params = request.filtered_parameters + assert_equal "[FILTERED]", params["lifo"] + assert_equal "[FILTERED]", params["amount"] + assert_equal "1", params["step"] + end + + test "filtered_env filters env as a whole" do + FilterRequest.filter_parameters(:lifo, :amount) + + request = FilterRequest.new('action_dispatch.request.parameters' => + { 'amount' => '420', 'step' => '1' }, "RAW_POST_DATA" => "yada yada") + + request = FilterRequest.new(request.filtered_env) + + assert_equal "[FILTERED]", request.raw_post + assert_equal "[FILTERED]", request.params["amount"] + assert_equal "1", request.params["step"] + end + protected def stub_request(env={}) -- cgit v1.2.3 From dcb8b64975832ac75d92104da3c95876e56eec66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@gmail.com> Date: Thu, 21 Jan 2010 12:12:10 +0100 Subject: Add shortcut test to abstract/render_test.rb --- actionpack/test/abstract/render_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract/render_test.rb b/actionpack/test/abstract/render_test.rb index be0478b638..4bec44c9ae 100644 --- a/actionpack/test/abstract/render_test.rb +++ b/actionpack/test/abstract/render_test.rb @@ -33,6 +33,10 @@ module AbstractController render end + def shortcut + render "template" + end + def template_name render :_template_name => :template_name end @@ -73,6 +77,11 @@ module AbstractController assert_equal "With Default", @controller.response_body end + def test_render_template_through_shortcut + @controller.process(:shortcut) + assert_equal "With Template", @controller.response_body + end + def test_render_template_name @controller.process(:template_name) assert_equal "With Template Name", @controller.response_body -- cgit v1.2.3 From 378464a2e47bb849f3351cb8c87366554b7ce74d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@gmail.com> Date: Thu, 21 Jan 2010 13:05:30 +0100 Subject: Default to sync instrumentation. --- .../test/activerecord/controller_runtime_test.rb | 19 +--- actionpack/test/controller/subscriber_test.rb | 18 +--- actionpack/test/dispatch/subscriber_test.rb | 111 --------------------- actionpack/test/template/subscriber_test.rb | 13 +-- 4 files changed, 9 insertions(+), 152 deletions(-) delete mode 100644 actionpack/test/dispatch/subscriber_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/activerecord/controller_runtime_test.rb b/actionpack/test/activerecord/controller_runtime_test.rb index 37c7738301..ed8e324938 100644 --- a/actionpack/test/activerecord/controller_runtime_test.rb +++ b/actionpack/test/activerecord/controller_runtime_test.rb @@ -6,16 +6,15 @@ require 'action_controller/railties/subscriber' ActionController::Base.send :include, ActiveRecord::Railties::ControllerRuntime -module ControllerRuntimeSubscriberTest +class ControllerRuntimeSubscriberTest < ActionController::TestCase class SubscriberController < ActionController::Base def show render :inline => "<%= Project.all %>" end end - - def self.included(base) - base.tests SubscriberController - end + + include Rails::Subscriber::TestHelper + tests SubscriberController def setup @old_logger = ActionController::Base.logger @@ -40,14 +39,4 @@ module ControllerRuntimeSubscriberTest assert_equal 2, @logger.logged(:info).size assert_match /\(Views: [\d\.]+ms | ActiveRecord: [\d\.]+ms\)/, @logger.logged(:info)[1] end - - class SyncSubscriberTest < ActionController::TestCase - include Rails::Subscriber::SyncTestHelper - include ControllerRuntimeSubscriberTest - end - - class AsyncSubscriberTest < ActionController::TestCase - include Rails::Subscriber::AsyncTestHelper - include ControllerRuntimeSubscriberTest - end end \ No newline at end of file diff --git a/actionpack/test/controller/subscriber_test.rb b/actionpack/test/controller/subscriber_test.rb index 52434426f7..bd0c83413c 100644 --- a/actionpack/test/controller/subscriber_test.rb +++ b/actionpack/test/controller/subscriber_test.rb @@ -35,11 +35,9 @@ module Another end end -module ActionControllerSubscriberTest - - def self.included(base) - base.tests Another::SubscribersController - end +class ACSubscriberTest < ActionController::TestCase + tests Another::SubscribersController + include Rails::Subscriber::TestHelper def setup @old_logger = ActionController::Base.logger @@ -174,14 +172,4 @@ module ActionControllerSubscriberTest def logs @logs ||= @logger.logged(:info) end - - class SyncSubscriberTest < ActionController::TestCase - include Rails::Subscriber::SyncTestHelper - include ActionControllerSubscriberTest - end - - class AsyncSubscriberTest < ActionController::TestCase - include Rails::Subscriber::AsyncTestHelper - include ActionControllerSubscriberTest - end end diff --git a/actionpack/test/dispatch/subscriber_test.rb b/actionpack/test/dispatch/subscriber_test.rb deleted file mode 100644 index 3096c132e7..0000000000 --- a/actionpack/test/dispatch/subscriber_test.rb +++ /dev/null @@ -1,111 +0,0 @@ -require "abstract_unit" -require "rails/subscriber/test_helper" -require "action_dispatch/railties/subscriber" - -module DispatcherSubscriberTest - Boomer = lambda do |env| - req = ActionDispatch::Request.new(env) - case req.path - when "/" - [200, {}, []] - else - raise "puke!" - end - end - - App = ActionDispatch::Notifications.new(Boomer) - - def setup - Rails::Subscriber.add(:action_dispatch, ActionDispatch::Railties::Subscriber.new) - @app = App - super - - @events = [] - ActiveSupport::Notifications.subscribe do |*args| - @events << args - end - end - - def set_logger(logger) - ActionController::Base.logger = logger - end - - def test_publishes_notifications - get "/" - wait - - assert_equal 2, @events.size - before, after = @events - - assert_equal 'action_dispatch.before_dispatch', before[0] - assert_kind_of Hash, before[4][:env] - assert_equal 'GET', before[4][:env]["REQUEST_METHOD"] - - assert_equal 'action_dispatch.after_dispatch', after[0] - assert_kind_of Hash, after[4][:env] - assert_equal 'GET', after[4][:env]["REQUEST_METHOD"] - end - - def test_publishes_notifications_even_on_failures - begin - get "/puke" - rescue - end - - wait - - assert_equal 3, @events.size - before, after, exception = @events - - assert_equal 'action_dispatch.before_dispatch', before[0] - assert_kind_of Hash, before[4][:env] - assert_equal 'GET', before[4][:env]["REQUEST_METHOD"] - - assert_equal 'action_dispatch.after_dispatch', after[0] - assert_kind_of Hash, after[4][:env] - assert_equal 'GET', after[4][:env]["REQUEST_METHOD"] - - assert_equal 'action_dispatch.exception', exception[0] - assert_kind_of Hash, exception[4][:env] - assert_equal 'GET', exception[4][:env]["REQUEST_METHOD"] - assert_kind_of RuntimeError, exception[4][:exception] - end - - def test_subscriber_logs_notifications - get "/" - wait - - log = @logger.logged(:info).first - assert_equal 1, @logger.logged(:info).size - - assert_match %r{^Started GET "/"}, log - assert_match %r{for 127\.0\.0\.1}, log - end - - def test_subscriber_has_its_logged_flushed_after_request - assert_equal 0, @logger.flush_count - get "/" - wait - assert_equal 1, @logger.flush_count - end - - def test_subscriber_has_its_logged_flushed_even_after_busted_requests - assert_equal 0, @logger.flush_count - begin - get "/puke" - rescue - end - wait - assert_equal 1, @logger.flush_count - end - - class SyncSubscriberTest < ActionController::IntegrationTest - include Rails::Subscriber::SyncTestHelper - include DispatcherSubscriberTest - end - - class AsyncSubscriberTest < ActionController::IntegrationTest - include Rails::Subscriber::AsyncTestHelper - include DispatcherSubscriberTest - end -end \ No newline at end of file diff --git a/actionpack/test/template/subscriber_test.rb b/actionpack/test/template/subscriber_test.rb index af0b3102cf..5db2b16ac1 100644 --- a/actionpack/test/template/subscriber_test.rb +++ b/actionpack/test/template/subscriber_test.rb @@ -3,7 +3,8 @@ require "rails/subscriber/test_helper" require "action_view/railties/subscriber" require "controller/fake_models" -module ActionViewSubscriberTest +class AVSubscriberTest < ActiveSupport::TestCase + include Rails::Subscriber::TestHelper def setup @old_logger = ActionController::Base.logger @@ -89,14 +90,4 @@ module ActionViewSubscriberTest assert_equal 1, @logger.logged(:info).size assert_match /Rendered collection/, @logger.logged(:info).last end - - class SyncSubscriberTest < ActiveSupport::TestCase - include Rails::Subscriber::SyncTestHelper - include ActionViewSubscriberTest - end - - class AsyncSubscriberTest < ActiveSupport::TestCase - include Rails::Subscriber::AsyncTestHelper - include ActionViewSubscriberTest - end end \ No newline at end of file -- cgit v1.2.3 From fc4f237864541f5012f9b8cc8e0ec81960377e55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@gmail.com> Date: Thu, 21 Jan 2010 16:50:11 +0100 Subject: Make filter parameters based on request, so they can be modified for anything in the middleware stack. --- actionpack/test/controller/base_test.rb | 21 +++++++++++++-- actionpack/test/controller/subscriber_test.rb | 5 +--- actionpack/test/dispatch/request_test.rb | 39 +++++++++------------------ 3 files changed, 33 insertions(+), 32 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb index 1510a6a7e0..4fcfbacf4e 100644 --- a/actionpack/test/controller/base_test.rb +++ b/actionpack/test/controller/base_test.rb @@ -2,6 +2,9 @@ require 'abstract_unit' require 'logger' require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late +module Rails +end + # Provide some controller to run the tests on. module Submodule class ContainedEmptyController < ActionController::Base @@ -63,7 +66,7 @@ class DefaultUrlOptionsController < ActionController::Base end end -class ControllerClassTests < Test::Unit::TestCase +class ControllerClassTests < ActiveSupport::TestCase def test_controller_path assert_equal 'empty', EmptyController.controller_path assert_equal EmptyController.controller_path, EmptyController.new.controller_path @@ -74,7 +77,21 @@ class ControllerClassTests < Test::Unit::TestCase def test_controller_name assert_equal 'empty', EmptyController.controller_name assert_equal 'contained_empty', Submodule::ContainedEmptyController.controller_name - end + end + + def test_filter_parameter_logging + parameters = [] + config = mock(:config => mock(:filter_parameters => parameters)) + Rails.expects(:application).returns(config) + + assert_deprecated do + Class.new(ActionController::Base) do + filter_parameter_logging :password + end + end + + assert_equal [:password], parameters + end end class ControllerInstanceTests < Test::Unit::TestCase diff --git a/actionpack/test/controller/subscriber_test.rb b/actionpack/test/controller/subscriber_test.rb index bd0c83413c..152a0d0c04 100644 --- a/actionpack/test/controller/subscriber_test.rb +++ b/actionpack/test/controller/subscriber_test.rb @@ -97,8 +97,7 @@ class ACSubscriberTest < ActionController::TestCase end def test_process_action_with_filter_parameters - ActionDispatch::Request.class_eval "alias :safe_process_parameter_filter :process_parameter_filter" - ActionDispatch::Request.filter_parameters(:lifo, :amount) + @request.env["action_dispatch.parameter_filter"] = [:lifo, :amount] get :show, :lifo => 'Pratik', :amount => '420', :step => '1' wait @@ -107,8 +106,6 @@ class ACSubscriberTest < ActionController::TestCase assert_match /"amount"=>"\[FILTERED\]"/, params assert_match /"lifo"=>"\[FILTERED\]"/, params assert_match /"step"=>"1"/, params - ensure - ActionDispatch::Request.class_eval "alias :process_parameter_filter :safe_process_parameter_filter" end def test_redirect_to diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index c5a75f5d21..2b5c19361a 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -454,18 +454,7 @@ class RequestTest < ActiveSupport::TestCase assert_equal Mime::XML, request.negotiate_mime([Mime::XML, Mime::CSV]) end - class FilterRequest < ActionDispatch::Request - end - - test "filter_parameters raises error without arguments" do - assert_raises RuntimeError do - FilterRequest.filter_parameters - end - end - test "process parameter filter" do - request = FilterRequest.new({}) - test_hashes = [ [{'foo'=>'bar'},{'foo'=>'bar'},%w'food'], [{'foo'=>'bar'},{'foo'=>'[FILTERED]'},%w'foo'], @@ -473,18 +462,18 @@ class RequestTest < ActiveSupport::TestCase [{'foo'=>'bar', 'baz'=>'foo'},{'foo'=>'[FILTERED]', 'baz'=>'[FILTERED]'},%w'foo baz'], [{'bar'=>{'foo'=>'bar','bar'=>'foo'}},{'bar'=>{'foo'=>'[FILTERED]','bar'=>'foo'}},%w'fo'], [{'foo'=>{'foo'=>'bar','bar'=>'foo'}},{'foo'=>'[FILTERED]'},%w'f banana'], - [{'baz'=>[{'foo'=>'baz'}]}, {'baz'=>[{'foo'=>'[FILTERED]'}]}, %w(foo)]] + [{'baz'=>[{'foo'=>'baz'}]}, {'baz'=>[{'foo'=>'[FILTERED]'}]}, [/foo/]]] test_hashes.each do |before_filter, after_filter, filter_words| - FilterRequest.filter_parameters(*filter_words) + request = stub_request('action_dispatch.parameter_filter' => filter_words) assert_equal after_filter, request.send(:process_parameter_filter, before_filter) - filter_words.push('blah') - - FilterRequest.filter_parameters(*filter_words) do |key, value| + filter_words << 'blah' + filter_words << lambda { |key, value| value.reverse! if key =~ /bargain/ - end + } + request = stub_request('action_dispatch.parameter_filter' => filter_words) before_filter['barg'] = {'bargain'=>'gain', 'blah'=>'bar', 'bar'=>{'bargain'=>{'blah'=>'foo'}}} after_filter['barg'] = {'bargain'=>'niag', 'blah'=>'[FILTERED]', 'bar'=>{'bargain'=>{'blah'=>'[FILTERED]'}}} @@ -493,10 +482,9 @@ class RequestTest < ActiveSupport::TestCase end test "filtered_parameters returns params filtered" do - FilterRequest.filter_parameters(:lifo, :amount) - - request = FilterRequest.new('action_dispatch.request.parameters' => - { 'lifo' => 'Pratik', 'amount' => '420', 'step' => '1' }) + request = stub_request('action_dispatch.request.parameters' => + { 'lifo' => 'Pratik', 'amount' => '420', 'step' => '1' }, + 'action_dispatch.parameter_filter' => [:lifo, :amount]) params = request.filtered_parameters assert_equal "[FILTERED]", params["lifo"] @@ -505,12 +493,11 @@ class RequestTest < ActiveSupport::TestCase end test "filtered_env filters env as a whole" do - FilterRequest.filter_parameters(:lifo, :amount) - - request = FilterRequest.new('action_dispatch.request.parameters' => - { 'amount' => '420', 'step' => '1' }, "RAW_POST_DATA" => "yada yada") + request = stub_request('action_dispatch.request.parameters' => + { 'amount' => '420', 'step' => '1' }, "RAW_POST_DATA" => "yada yada", + 'action_dispatch.parameter_filter' => [:lifo, :amount]) - request = FilterRequest.new(request.filtered_env) + request = stub_request(request.filtered_env) assert_equal "[FILTERED]", request.raw_post assert_equal "[FILTERED]", request.params["amount"] -- cgit v1.2.3 From d618b7e3dcf2fe6040f025c02bf29691aefc8a71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@gmail.com> Date: Fri, 22 Jan 2010 17:57:36 +0100 Subject: Ensure strings given to render with slash are rendered relative to the configured _prefix. --- actionpack/test/abstract/render_test.rb | 35 ++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract/render_test.rb b/actionpack/test/abstract/render_test.rb index 4bec44c9ae..ffd430fa86 100644 --- a/actionpack/test/abstract/render_test.rb +++ b/actionpack/test/abstract/render_test.rb @@ -6,9 +6,16 @@ module AbstractController class ControllerRenderer < AbstractController::Base include AbstractController::Rendering + def _prefix + "renderer" + end + self.view_paths = [ActionView::FixtureResolver.new( "default.erb" => "With Default", "template.erb" => "With Template", + "renderer/string.erb" => "With String", + "renderer/symbol.erb" => "With Symbol", + "string/with_path.erb" => "With String With Path", "some/file.erb" => "With File", "template_name.erb" => "With Template Name" )] @@ -33,8 +40,16 @@ module AbstractController render end - def shortcut - render "template" + def string + render "string" + end + + def string_with_path + render "string/with_path" + end + + def symbol + render :symbol end def template_name @@ -77,9 +92,19 @@ module AbstractController assert_equal "With Default", @controller.response_body end - def test_render_template_through_shortcut - @controller.process(:shortcut) - assert_equal "With Template", @controller.response_body + def test_render_string + @controller.process(:string) + assert_equal "With String", @controller.response_body + end + + def test_render_symbol + @controller.process(:symbol) + assert_equal "With Symbol", @controller.response_body + end + + def test_render_string_with_path + @controller.process(:string_with_path) + assert_equal "With String With Path", @controller.response_body end def test_render_template_name -- cgit v1.2.3