aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/subscriber_test.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-01-13 01:04:33 +0100
committerJosé Valim <jose.valim@gmail.com>2010-01-13 01:19:24 +0100
commitb0d35ad00c3d7f6f63aa7ae8f3d3cb802bb90d69 (patch)
tree2d8f3aa4b362db150d092a883a27ca46a0af6a63 /actionpack/test/controller/subscriber_test.rb
parentda5978c22374b8a3b15a421ff4920e0940435253 (diff)
downloadrails-b0d35ad00c3d7f6f63aa7ae8f3d3cb802bb90d69.tar.gz
rails-b0d35ad00c3d7f6f63aa7ae8f3d3cb802bb90d69.tar.bz2
rails-b0d35ad00c3d7f6f63aa7ae8f3d3cb802bb90d69.zip
Test fragment/page cache and send data/file notifications.
Diffstat (limited to 'actionpack/test/controller/subscriber_test.rb')
-rw-r--r--actionpack/test/controller/subscriber_test.rb104
1 files changed, 93 insertions, 11 deletions
diff --git a/actionpack/test/controller/subscriber_test.rb b/actionpack/test/controller/subscriber_test.rb
index e2c6150c5e..485143d7b0 100644
--- a/actionpack/test/controller/subscriber_test.rb
+++ b/actionpack/test/controller/subscriber_test.rb
@@ -11,11 +11,31 @@ module Another
def redirector
redirect_to "http://foo.bar/"
end
+
+ def data_sender
+ send_data "cool data", :filename => "omg.txt"
+ end
+
+ def xfile_sender
+ send_file File.expand_path("company.rb", FIXTURE_LOAD_PATH), :x_sendfile => true
+ end
+
+ def file_sender
+ send_file File.expand_path("company.rb", FIXTURE_LOAD_PATH)
+ end
+
+ def with_fragment_cache
+ render :inline => "<%= cache('foo'){ 'bar' } %>"
+ end
+
+ def with_page_cache
+ cache_page("Super soaker", "/index.html")
+ render :nothing => true
+ end
end
end
module ActionControllerSubscriberTest
- Rails::Subscriber.add(:action_controller, ActionController::Railties::Subscriber.new)
def self.included(base)
base.tests Another::SubscribersController
@@ -28,11 +48,19 @@ module ActionControllerSubscriberTest
def setup
@old_logger = ActionController::Base.logger
+
+ @cache_path = File.expand_path('../temp/test_cache', File.dirname(__FILE__))
+ ActionController::Base.page_cache_directory = @cache_path
+ ActionController::Base.cache_store = :file_store, @cache_path
+
+ Rails::Subscriber.add(:action_controller, ActionController::Railties::Subscriber.new)
super
end
def teardown
super
+ Rails::Subscriber.subscribers.clear
+ FileUtils.rm_rf(@cache_path)
ActionController::Base.logger = @old_logger
end
@@ -43,34 +71,34 @@ module ActionControllerSubscriberTest
def test_process_action
get :show
wait
- assert_equal 3, @logger.logged(:info).size
- assert_match /Processed\sAnother::SubscribersController#show/, @logger.logged(:info)[0]
+ assert_equal 3, logs.size
+ assert_match /Processed\sAnother::SubscribersController#show/, logs[0]
end
def test_process_action_without_parameters
get :show
wait
- assert_nil @logger.logged(:info).detect {|l| l =~ /Parameters/ }
+ assert_nil logs.detect {|l| l =~ /Parameters/ }
end
def test_process_action_with_parameters
get :show, :id => '10'
wait
- assert_equal 4, @logger.logged(:info).size
- assert_equal 'Parameters: {"id"=>"10"}', @logger.logged(:info)[1]
+ assert_equal 4, logs.size
+ assert_equal 'Parameters: {"id"=>"10"}', logs[1]
end
def test_process_action_with_view_runtime
get :show
wait
- assert_match /View runtime/, @logger.logged(:info)[1]
+ assert_match /View runtime/, logs[1]
end
def test_process_action_with_status_and_request_uri
get :show
wait
- last = @logger.logged(:info).last
+ last = logs.last
assert_match /Completed/, last
assert_match /200/, last
assert_match /another\/subscribers\/show/, last
@@ -82,7 +110,7 @@ module ActionControllerSubscriberTest
get :show, :lifo => 'Pratik', :amount => '420', :step => '1'
wait
- params = @logger.logged(:info)[1]
+ params = logs[1]
assert_match /"amount"=>"\[FILTERED\]"/, params
assert_match /"lifo"=>"\[FILTERED\]"/, params
assert_match /"step"=>"1"/, params
@@ -92,8 +120,62 @@ module ActionControllerSubscriberTest
get :redirector
wait
- assert_equal 3, @logger.logged(:info).size
- assert_equal "Redirected to http://foo.bar/ with status 302", @logger.logged(:info)[0]
+ assert_equal 3, logs.size
+ assert_equal "Redirected to http://foo.bar/ with status 302", logs[0]
+ end
+
+ def test_send_data
+ get :data_sender
+ wait
+
+ assert_equal 4, logs.size
+ assert_match /Sent data omg\.txt/, logs[0]
+ end
+
+ def test_send_file
+ get :file_sender
+ wait
+
+ assert_equal 4, logs.size
+ assert_match /Sent file/, logs[0]
+ assert_match /test\/fixtures\/company\.rb/, logs[0]
+ end
+
+ def test_send_xfile
+ get :xfile_sender
+ wait
+
+ assert_equal 3, logs.size
+ assert_match /Sent X\-Sendfile header/, logs[0]
+ assert_match /test\/fixtures\/company\.rb/, logs[0]
+ end
+
+ def test_with_fragment_cache
+ ActionController::Base.perform_caching = true
+ get :with_fragment_cache
+ wait
+
+ assert_equal 5, logs.size
+ assert_match /Exist fragment\? views\/foo/, logs[0]
+ assert_match /Write fragment views\/foo/, logs[1]
+ ensure
+ ActionController::Base.perform_caching = true
+ end
+
+ def test_with_page_cache
+ ActionController::Base.perform_caching = true
+ get :with_page_cache
+ wait
+
+ assert_equal 4, logs.size
+ assert_match /Write page/, logs[0]
+ assert_match /\/index\.html/, logs[0]
+ ensure
+ ActionController::Base.perform_caching = true
+ end
+
+ def logs
+ @logs ||= @logger.logged(:info)
end
class SyncSubscriberTest < ActionController::TestCase