aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r--actionpack/test/controller/base_test.rb21
-rw-r--r--actionpack/test/controller/filter_params_test.rb51
-rw-r--r--actionpack/test/controller/new_base/base_test.rb6
-rw-r--r--actionpack/test/controller/subscriber_test.rb74
-rw-r--r--actionpack/test/controller/translation_test.rb26
5 files changed, 56 insertions, 122 deletions
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/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
diff --git a/actionpack/test/controller/new_base/base_test.rb b/actionpack/test/controller/new_base/base_test.rb
index 964780eaf2..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
@@ -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
diff --git a/actionpack/test/controller/subscriber_test.rb b/actionpack/test/controller/subscriber_test.rb
index 24132ee928..152a0d0c04 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
@@ -63,13 +61,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,23 +86,23 @@ 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
- Another::SubscribersController.filter_parameter_logging(:lifo, :amount)
+ @request.env["action_dispatch.parameter_filter"] = [:lifo, :amount]
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 +112,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 +147,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 +159,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
@@ -165,14 +169,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/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