aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test/template/log_subscriber_test.rb
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2013-04-17 00:06:11 +0200
committerŁukasz Strzałkowski <lukasz.strzalkowski@gmail.com>2013-06-20 17:23:16 +0200
commiteb23754ebbfbf2d465cc0f900720704fb3703633 (patch)
tree5bd1764233b59075341611b1e857d418c794d812 /actionview/test/template/log_subscriber_test.rb
parent5bcdf4faa6da7acb762dab680372f8520a0533c2 (diff)
downloadrails-eb23754ebbfbf2d465cc0f900720704fb3703633.tar.gz
rails-eb23754ebbfbf2d465cc0f900720704fb3703633.tar.bz2
rails-eb23754ebbfbf2d465cc0f900720704fb3703633.zip
Move template tests from actionpack to actionview
Diffstat (limited to 'actionview/test/template/log_subscriber_test.rb')
-rw-r--r--actionview/test/template/log_subscriber_test.rb91
1 files changed, 91 insertions, 0 deletions
diff --git a/actionview/test/template/log_subscriber_test.rb b/actionview/test/template/log_subscriber_test.rb
new file mode 100644
index 0000000000..7f4c84929f
--- /dev/null
+++ b/actionview/test/template/log_subscriber_test.rb
@@ -0,0 +1,91 @@
+require "abstract_unit"
+require "active_support/log_subscriber/test_helper"
+require "action_view/log_subscriber"
+require "controller/fake_models"
+
+class AVLogSubscriberTest < ActiveSupport::TestCase
+ include ActiveSupport::LogSubscriber::TestHelper
+
+ def setup
+ super
+ view_paths = ActionController::Base.view_paths
+ lookup_context = ActionView::LookupContext.new(view_paths, {}, ["test"])
+ renderer = ActionView::Renderer.new(lookup_context)
+ @view = ActionView::Base.new(renderer, {})
+ Rails.stubs(:root).returns(File.expand_path(FIXTURE_LOAD_PATH))
+ ActionView::LogSubscriber.attach_to :action_view
+ end
+
+ def teardown
+ super
+ ActiveSupport::LogSubscriber.log_subscribers.clear
+ end
+
+ def set_logger(logger)
+ ActionView::Base.logger = logger
+ end
+
+ def test_render_file_template
+ @view.render(:file => "test/hello_world")
+ 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 => "TEXT")
+ 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 => "<%= 'TEXT' %>")
+ 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_partial_with_implicit_path
+ @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
+
+ assert_equal 1, @logger.logged(:info).size
+ assert_match(/Rendered test\/_customer.erb/, @logger.logged(:info).last)
+ end
+
+ def test_render_collection_with_implicit_path
+ @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.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
+end