aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/new_base/render_file_test.rb
blob: 01d0223519d85867977784fb5b7cb48f793b89d0 (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
76
77
78
79
80
81
82
83
84
# frozen_string_literal: true

require "abstract_unit"

module RenderFile
  class BasicController < ActionController::Base
    self.view_paths = __dir__

    def index
      render file: File.expand_path("../../fixtures/test/hello_world", __dir__)
    end

    def with_instance_variables
      @secret = "in the sauce"
      render file: File.expand_path("../../fixtures/test/render_file_with_ivar", __dir__)
    end

    def relative_path
      @secret = "in the sauce"
      render file: "../actionpack/test/fixtures/test/render_file_with_ivar"
    end

    def relative_path_with_dot
      @secret = "in the sauce"
      render file: "../actionpack/test/fixtures/test/dot.directory/render_file_with_ivar"
    end

    def pathname
      @secret = "in the sauce"
      render file: Pathname.new(__dir__).join(*%w[.. .. fixtures test dot.directory render_file_with_ivar])
    end

    def with_locals
      path = File.expand_path("../../fixtures/test/render_file_with_locals", __dir__)
      render file: path, locals: { secret: "in the sauce" }
    end
  end

  class TestBasic < Rack::TestCase
    testing RenderFile::BasicController

    test "rendering simple template" do
      assert_deprecated do
        get :index
      end
      assert_response "Hello world!"
    end

    test "rendering template with ivar" do
      assert_deprecated do
        get :with_instance_variables
      end
      assert_response "The secret is in the sauce\n"
    end

    test "rendering a relative path" do
      assert_deprecated do
        get :relative_path
      end
      assert_response "The secret is in the sauce\n"
    end

    test "rendering a relative path with dot" do
      assert_deprecated do
        get :relative_path_with_dot
      end
      assert_response "The secret is in the sauce\n"
    end

    test "rendering a Pathname" do
      assert_deprecated do
        get :pathname
      end
      assert_response "The secret is in the sauce\n"
    end

    test "rendering file with locals" do
      assert_deprecated do
        get :with_locals
      end
      assert_response "The secret is in the sauce\n"
    end
  end
end