aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template/subscriber_test.rb
blob: 2f58638364ce2aab3e5258bfee97a830aa2f4693 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require "abstract_unit"
require "rails/subscriber/test_helper"
require "action_view/railties/subscriber"
require "controller/fake_models"

module ActionViewSubscriberTest

  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

  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