Sha256: 5b830a1e3364103bfcdbc96bf649b76e1967ca96b308b96d989f84eb0273d65e

Contents?: true

Size: 1.88 KB

Versions: 2

Compression:

Stored size: 1.88 KB

Contents

require 'abstract_unit'

module RenderFile
  class BasicController < ActionController::Base
    self.view_paths = File.dirname(__FILE__)

    def index
      render :file => File.join(File.dirname(__FILE__), *%w[.. .. fixtures test hello_world])
    end

    def with_instance_variables
      @secret = 'in the sauce'
      render :file => File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_ivar')
    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(File.dirname(__FILE__)).join(*%w[.. .. fixtures test dot.directory render_file_with_ivar])
    end

    def with_locals
      path = File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_locals')
      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

2 entries across 2 versions & 1 rubygems

Version Path
activejob-lock-0.0.2 rails/actionpack/test/controller/new_base/render_file_test.rb
activejob-lock-0.0.1 rails/actionpack/test/controller/new_base/render_file_test.rb