From da5978c22374b8a3b15a421ff4920e0940435253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 13 Jan 2010 00:41:04 +0100 Subject: Add subscriber for ActionPack and move all logging inside it. --- actionpack/test/template/subscriber_test.rb | 74 +++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 actionpack/test/template/subscriber_test.rb (limited to 'actionpack/test/template/subscriber_test.rb') diff --git a/actionpack/test/template/subscriber_test.rb b/actionpack/test/template/subscriber_test.rb new file mode 100644 index 0000000000..a73ff2e932 --- /dev/null +++ b/actionpack/test/template/subscriber_test.rb @@ -0,0 +1,74 @@ +require "abstract_unit" +require "rails/subscriber/test_helper" +require "action_view/railties/subscriber" +require "controller/fake_models" + +module ActionViewSubscriberTest + Rails::Subscriber.add(:action_view, ActionView::Railties::Subscriber.new) + + def setup + @old_logger = ActionController::Base.logger + @view = ActionView::Base.new(ActionController::Base.view_paths, {}) + Rails.stubs(:root).returns(File.expand_path(FIXTURE_LOAD_PATH)) + super + end + + def teardown + super + ActionController::Base.logger = @old_logger + end + + def set_logger(logger) + ActionController::Base.logger = logger + end + + def test_render_file_template + @view.render(:file => "test/hello_world.erb") + wait + + assert_equal 1, @logger.logged(:info).size + assert_match /Rendered test\/hello_world\.erb/, @logger.logged(:info).last + end + + def test_render_text_template + @view.render(:text => "OMG") + wait + + assert_equal 1, @logger.logged(:info).size + assert_match /Rendered text template/, @logger.logged(:info).last + end + + def test_render_inline_template + @view.render(:inline => "<%= 'OMG' %>") + wait + + assert_equal 1, @logger.logged(:info).size + assert_match /Rendered inline template/, @logger.logged(:info).last + end + + def test_render_partial_template + @view.render(:partial => "test/customer") + wait + + assert_equal 1, @logger.logged(:info).size + assert_match /Rendered test\/_customer.erb/, @logger.logged(:info).last + end + + def test_render_collection_template + @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), Customer.new("mary") ]) + wait + + assert_equal 1, @logger.logged(:info).size + assert_match /Rendered test\/_customer.erb/, @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 b0d35ad00c3d7f6f63aa7ae8f3d3cb802bb90d69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 13 Jan 2010 01:04:33 +0100 Subject: Test fragment/page cache and send data/file notifications. --- actionpack/test/template/subscriber_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'actionpack/test/template/subscriber_test.rb') diff --git a/actionpack/test/template/subscriber_test.rb b/actionpack/test/template/subscriber_test.rb index a73ff2e932..2f58638364 100644 --- a/actionpack/test/template/subscriber_test.rb +++ b/actionpack/test/template/subscriber_test.rb @@ -4,17 +4,18 @@ require "action_view/railties/subscriber" require "controller/fake_models" module ActionViewSubscriberTest - Rails::Subscriber.add(:action_view, ActionView::Railties::Subscriber.new) def setup @old_logger = ActionController::Base.logger @view = ActionView::Base.new(ActionController::Base.view_paths, {}) Rails.stubs(:root).returns(File.expand_path(FIXTURE_LOAD_PATH)) + Rails::Subscriber.add(:action_view, ActionView::Railties::Subscriber.new) super end def teardown super + Rails::Subscriber.subscribers.clear ActionController::Base.logger = @old_logger end -- cgit v1.2.3 From 1c30ec23fef2479cd037945e57a74e5c89c9ece1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 15 Jan 2010 17:43:45 +0100 Subject: In heterogeneous collections, neither the @path nor the @template are available, so we need to tell that we are simply rendering a collection. --- actionpack/test/template/subscriber_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'actionpack/test/template/subscriber_test.rb') diff --git a/actionpack/test/template/subscriber_test.rb b/actionpack/test/template/subscriber_test.rb index 2f58638364..d64637f141 100644 --- a/actionpack/test/template/subscriber_test.rb +++ b/actionpack/test/template/subscriber_test.rb @@ -63,6 +63,16 @@ module ActionViewSubscriberTest assert_match /Rendered test\/_customer.erb/, @logger.logged(:info).last end + def test_render_collection_template_without_path + @view.stubs(:controller_path).returns("test") + @view.render([ GoodCustomer.new("david"), Customer.new("mary") ], :greeting => "hi") + wait + + 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 -- cgit v1.2.3 From 13d76b6170886493369f94693e61364044e4316a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 15 Jan 2010 17:55:08 +0100 Subject: Add some implicit path tests to Subscriber. --- actionpack/test/template/subscriber_test.rb | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'actionpack/test/template/subscriber_test.rb') diff --git a/actionpack/test/template/subscriber_test.rb b/actionpack/test/template/subscriber_test.rb index d64637f141..af0b3102cf 100644 --- a/actionpack/test/template/subscriber_test.rb +++ b/actionpack/test/template/subscriber_test.rb @@ -55,6 +55,15 @@ module ActionViewSubscriberTest assert_match /Rendered test\/_customer.erb/, @logger.logged(:info).last end + def test_render_partial_with_implicit_path + @view.stubs(:controller_path).returns("test") + @view.render(Customer.new("david"), :greeting => "hi") + wait + + assert_equal 1, @logger.logged(:info).size + assert_match /Rendered customers\/_customer\.html\.erb/, @logger.logged(:info).last + end + def test_render_collection_template @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), Customer.new("mary") ]) wait @@ -63,6 +72,15 @@ module ActionViewSubscriberTest assert_match /Rendered test\/_customer.erb/, @logger.logged(:info).last end + def test_render_collection_with_implicit_path + @view.stubs(:controller_path).returns("test") + @view.render([ Customer.new("david"), Customer.new("mary") ], :greeting => "hi") + wait + + assert_equal 1, @logger.logged(:info).size + assert_match /Rendered customers\/_customer\.html\.erb/, @logger.logged(:info).last + end + def test_render_collection_template_without_path @view.stubs(:controller_path).returns("test") @view.render([ GoodCustomer.new("david"), Customer.new("mary") ], :greeting => "hi") @@ -72,7 +90,6 @@ module ActionViewSubscriberTest assert_match /Rendered collection/, @logger.logged(:info).last end - class SyncSubscriberTest < ActiveSupport::TestCase include Rails::Subscriber::SyncTestHelper include ActionViewSubscriberTest -- cgit v1.2.3