aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/application/basic_rendering_test.rb
blob: 00ba433a05dc771f10d98fa026f76150e842b628 (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
require 'isolation/abstract_unit'
require 'rack/test'

module ApplicationTests
  class BasicRenderingTest < ActiveSupport::TestCase
    include ActiveSupport::Testing::Isolation
    include Rack::Test::Methods

    def setup
      build_app
    end

    def teardown
      teardown_app
    end

    test "Rendering without ActionView" do
      gsub_app_file 'config/application.rb', "require 'rails/all'", <<-RUBY
        require "active_model/railtie"
        require "action_controller/railtie"
      RUBY

      # Turn off ActionView and jquery-rails (it depends on AV)
      $:.reject! {|path| path =~ /(actionview|jquery\-rails)/ }
      boot_rails

      app_file 'app/controllers/pages_controller.rb', <<-RUBY
        class PagesController < ApplicationController
          def render_hello_world
            render text: "Hello World!"
          end

          def render_nothing
            render nothing: true
          end

          def no_render; end

          def raise_error
            render foo: "bar"
          end
        end
      RUBY

      get '/pages/render_hello_world'
      assert_equal 200, last_response.status
      assert_equal "Hello World!", last_response.body
      assert_equal "text/plain; charset=utf-8", last_response.content_type

      get '/pages/render_nothing'
      assert_equal 200, last_response.status
      assert_equal " ", last_response.body
      assert_equal "text/plain; charset=utf-8", last_response.content_type

      get '/pages/no_render'
      assert_equal 500, last_response.status

      get '/pages/raise_error'
      assert_equal 500, last_response.status
    end
  end
end