Sha256: 4dbd23da3e9d132b14ac62587992c0a0744b78d0f4a0780e2106933c9720a092

Contents?: true

Size: 1.84 KB

Versions: 48

Compression:

Stored size: 1.84 KB

Contents

# 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: "../../fixtures/test/render_file_with_ivar"
    end

    def relative_path_with_dot
      @secret = "in the sauce"
      render file: "../../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
      get :index
      assert_response "Hello world!"
    end

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

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

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

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

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

Version data entries

48 entries across 48 versions & 2 rubygems

Version Path
jets-1.9.7 vendor/rails/actionpack/test/controller/new_base/render_file_test.rb
jets-1.9.6 vendor/rails/actionpack/test/controller/new_base/render_file_test.rb
jets-1.9.5 vendor/rails/actionpack/test/controller/new_base/render_file_test.rb
jets-1.9.4 vendor/rails/actionpack/test/controller/new_base/render_file_test.rb
jets-1.9.3 vendor/rails/actionpack/test/controller/new_base/render_file_test.rb
jets-1.9.2 vendor/rails/actionpack/test/controller/new_base/render_file_test.rb
jets-1.9.1 vendor/rails/actionpack/test/controller/new_base/render_file_test.rb
jets-1.9.0 vendor/rails/actionpack/test/controller/new_base/render_file_test.rb
jets-1.8.14 vendor/rails/actionpack/test/controller/new_base/render_file_test.rb
jets-1.8.13 vendor/rails/actionpack/test/controller/new_base/render_file_test.rb
jets-1.8.12 vendor/rails/actionpack/test/controller/new_base/render_file_test.rb
jets-1.8.11 vendor/rails/actionpack/test/controller/new_base/render_file_test.rb
jets-1.8.10 vendor/rails/actionpack/test/controller/new_base/render_file_test.rb
jets-1.8.9 vendor/rails/actionpack/test/controller/new_base/render_file_test.rb
jets-1.8.8 vendor/rails/actionpack/test/controller/new_base/render_file_test.rb
jets-1.8.7 vendor/rails/actionpack/test/controller/new_base/render_file_test.rb
jets-1.8.6 vendor/rails/actionpack/test/controller/new_base/render_file_test.rb
jets-1.8.5 vendor/rails/actionpack/test/controller/new_base/render_file_test.rb
jets-1.8.4 vendor/rails/actionpack/test/controller/new_base/render_file_test.rb
jets-1.8.3 vendor/rails/actionpack/test/controller/new_base/render_file_test.rb