2010-01-12 18:41:04 -05:00
|
|
|
require "abstract_unit"
|
2010-06-24 07:23:43 -04:00
|
|
|
require "active_support/log_subscriber/test_helper"
|
|
|
|
require "action_view/log_subscriber"
|
2010-01-12 18:41:04 -05:00
|
|
|
require "controller/fake_models"
|
|
|
|
|
2010-02-15 09:44:30 -05:00
|
|
|
class AVLogSubscriberTest < ActiveSupport::TestCase
|
2010-06-24 07:23:43 -04:00
|
|
|
include ActiveSupport::LogSubscriber::TestHelper
|
2010-01-12 18:41:04 -05:00
|
|
|
|
|
|
|
def setup
|
2010-03-02 17:40:59 -05:00
|
|
|
super
|
2012-06-14 06:04:49 -04:00
|
|
|
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, {})
|
2010-01-12 18:41:04 -05:00
|
|
|
Rails.stubs(:root).returns(File.expand_path(FIXTURE_LOAD_PATH))
|
2010-06-24 07:23:43 -04:00
|
|
|
ActionView::LogSubscriber.attach_to :action_view
|
2010-01-12 18:41:04 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
super
|
2010-06-24 07:23:43 -04:00
|
|
|
ActiveSupport::LogSubscriber.log_subscribers.clear
|
2010-01-12 18:41:04 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def set_logger(logger)
|
2012-01-18 12:05:36 -05:00
|
|
|
ActionView::Base.logger = logger
|
2010-01-12 18:41:04 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_file_template
|
2011-09-22 09:37:38 -04:00
|
|
|
@view.render(:file => "test/hello_world")
|
2010-01-12 18:41:04 -05:00
|
|
|
wait
|
|
|
|
|
|
|
|
assert_equal 1, @logger.logged(:info).size
|
2010-09-22 15:03:39 -04:00
|
|
|
assert_match(/Rendered test\/hello_world\.erb/, @logger.logged(:info).last)
|
2010-01-12 18:41:04 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_text_template
|
2010-01-31 00:27:24 -05:00
|
|
|
@view.render(:text => "TEXT")
|
2010-01-12 18:41:04 -05:00
|
|
|
wait
|
|
|
|
|
|
|
|
assert_equal 1, @logger.logged(:info).size
|
2010-09-22 15:03:39 -04:00
|
|
|
assert_match(/Rendered text template/, @logger.logged(:info).last)
|
2010-01-12 18:41:04 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_inline_template
|
2010-01-31 00:27:24 -05:00
|
|
|
@view.render(:inline => "<%= 'TEXT' %>")
|
2010-01-12 18:41:04 -05:00
|
|
|
wait
|
|
|
|
|
|
|
|
assert_equal 1, @logger.logged(:info).size
|
2010-09-22 15:03:39 -04:00
|
|
|
assert_match(/Rendered inline template/, @logger.logged(:info).last)
|
2010-01-12 18:41:04 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_partial_template
|
|
|
|
@view.render(:partial => "test/customer")
|
|
|
|
wait
|
|
|
|
|
|
|
|
assert_equal 1, @logger.logged(:info).size
|
2010-09-22 15:03:39 -04:00
|
|
|
assert_match(/Rendered test\/_customer.erb/, @logger.logged(:info).last)
|
2010-01-12 18:41:04 -05:00
|
|
|
end
|
|
|
|
|
2010-01-15 11:55:08 -05:00
|
|
|
def test_render_partial_with_implicit_path
|
|
|
|
@view.render(Customer.new("david"), :greeting => "hi")
|
|
|
|
wait
|
|
|
|
|
|
|
|
assert_equal 1, @logger.logged(:info).size
|
2010-09-22 15:03:39 -04:00
|
|
|
assert_match(/Rendered customers\/_customer\.html\.erb/, @logger.logged(:info).last)
|
2010-01-15 11:55:08 -05:00
|
|
|
end
|
|
|
|
|
2010-01-12 18:41:04 -05:00
|
|
|
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
|
2010-09-22 15:03:39 -04:00
|
|
|
assert_match(/Rendered test\/_customer.erb/, @logger.logged(:info).last)
|
2010-01-12 18:41:04 -05:00
|
|
|
end
|
|
|
|
|
2010-01-15 11:55:08 -05:00
|
|
|
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
|
2010-09-22 15:03:39 -04:00
|
|
|
assert_match(/Rendered customers\/_customer\.html\.erb/, @logger.logged(:info).last)
|
2010-01-15 11:55:08 -05:00
|
|
|
end
|
|
|
|
|
2010-01-15 11:43:45 -05:00
|
|
|
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
|
2010-09-22 15:03:39 -04:00
|
|
|
assert_match(/Rendered collection/, @logger.logged(:info).last)
|
2010-01-15 11:43:45 -05:00
|
|
|
end
|
2010-09-22 15:03:39 -04:00
|
|
|
end
|