aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/abstract_controller/abstract_controller_test.rb
blob: a5026fb0da5ddcc11d788be8c48990a60d4ccba4 (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
$:.unshift(File.dirname(__FILE__) + '/../../lib')
$:.unshift(File.dirname(__FILE__) + '/../../../activesupport/lib')

require 'test/unit'
require 'active_support'
require 'active_support/test_case'
require 'action_controller'

begin
  require 'ruby-debug'
  Debugger.settings[:autoeval] = true
  Debugger.start
rescue LoadError
  # Debugging disabled. `gem install ruby-debug` to enable.
end

require 'action_controller/abstract/base'
require 'action_controller/abstract/renderer'

module AbstractController
  module Testing
  
    class SimpleController < AbstractController::Base
    end
    
    class Me < SimpleController
      def index
        self.response_body = "Hello world"
        "Something else"
      end
    end
    
    class TestBasic < ActiveSupport::TestCase
      test "dispatching works" do
        result = Me.process(:index)
        assert_equal "Hello world", result.response_obj[:body]
      end
    end
    
    class RenderingController < AbstractController::Base
      include Renderer
            
      append_view_path File.expand_path(File.join(File.dirname(__FILE__), "views"))
    end
    
    class Me2 < RenderingController
      def index
        render "index.erb"
      end
    end
    
    class TestRenderer < ActiveSupport::TestCase
      test "rendering templates works" do
        result = Me2.process(:index)
        assert_equal "Hello from index.erb", result.response_obj[:body]
      end
    end
    
  end
end