Changing directories during the test breaks file loading when ran by itself
This commit is contained in:
parent
660eb068d3
commit
7eaed071a2
|
@ -51,6 +51,7 @@ I18n.backend.store_translations 'pt-BR', {}
|
||||||
ORIGINAL_LOCALES = I18n.available_locales.map {|locale| locale.to_s }.sort
|
ORIGINAL_LOCALES = I18n.available_locales.map {|locale| locale.to_s }.sort
|
||||||
|
|
||||||
FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
|
FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
|
||||||
|
FIXTURES = Pathname.new(FIXTURE_LOAD_PATH)
|
||||||
|
|
||||||
class ActionController::IntegrationTest < ActiveSupport::TestCase
|
class ActionController::IntegrationTest < ActiveSupport::TestCase
|
||||||
def self.build_app(routes = nil)
|
def self.build_app(routes = nil)
|
||||||
|
|
|
@ -1,110 +1,99 @@
|
||||||
require 'abstract_unit'
|
require 'abstract_unit'
|
||||||
|
|
||||||
module RenderFile
|
module RenderFile
|
||||||
|
|
||||||
class BasicController < ActionController::Base
|
class BasicController < ActionController::Base
|
||||||
self.view_paths = File.dirname(__FILE__)
|
self.view_paths = File.dirname(__FILE__)
|
||||||
|
|
||||||
def index
|
def index
|
||||||
render :file => File.join(File.dirname(__FILE__), *%w[.. .. fixtures test hello_world])
|
render :file => File.join(File.dirname(__FILE__), *%w[.. .. fixtures test hello_world])
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_instance_variables
|
def with_instance_variables
|
||||||
@secret = 'in the sauce'
|
@secret = 'in the sauce'
|
||||||
render :file => File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_ivar.erb')
|
render :file => File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_ivar.erb')
|
||||||
end
|
end
|
||||||
|
|
||||||
def without_file_key
|
def without_file_key
|
||||||
render File.join(File.dirname(__FILE__), *%w[.. .. fixtures test hello_world])
|
render File.join(File.dirname(__FILE__), *%w[.. .. fixtures test hello_world])
|
||||||
end
|
end
|
||||||
|
|
||||||
def without_file_key_with_instance_variable
|
def without_file_key_with_instance_variable
|
||||||
@secret = 'in the sauce'
|
@secret = 'in the sauce'
|
||||||
render File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_ivar.erb')
|
render File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_ivar.erb')
|
||||||
end
|
end
|
||||||
|
|
||||||
def relative_path
|
def relative_path
|
||||||
@secret = 'in the sauce'
|
@secret = 'in the sauce'
|
||||||
render :file => '../../fixtures/test/render_file_with_ivar'
|
render :file => '../../fixtures/test/render_file_with_ivar'
|
||||||
end
|
end
|
||||||
|
|
||||||
def relative_path_with_dot
|
def relative_path_with_dot
|
||||||
@secret = 'in the sauce'
|
@secret = 'in the sauce'
|
||||||
render :file => '../../fixtures/test/dot.directory/render_file_with_ivar'
|
render :file => '../../fixtures/test/dot.directory/render_file_with_ivar'
|
||||||
end
|
end
|
||||||
|
|
||||||
def pathname
|
def pathname
|
||||||
@secret = 'in the sauce'
|
@secret = 'in the sauce'
|
||||||
render :file => Pathname.new(File.dirname(__FILE__)).join(*%w[.. .. fixtures test dot.directory render_file_with_ivar.erb])
|
render :file => Pathname.new(File.dirname(__FILE__)).join(*%w[.. .. fixtures test dot.directory render_file_with_ivar.erb])
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_locals
|
def with_locals
|
||||||
path = File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_locals.erb')
|
path = File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_locals.erb')
|
||||||
render :file => path, :locals => {:secret => 'in the sauce'}
|
render :file => path, :locals => {:secret => 'in the sauce'}
|
||||||
end
|
end
|
||||||
|
|
||||||
def without_file_key_with_locals
|
def without_file_key_with_locals
|
||||||
path = File.expand_path('../../fixtures/test/render_file_with_locals.erb')
|
path = FIXTURES.join('test/render_file_with_locals.erb').to_s
|
||||||
render path, :locals => {:secret => 'in the sauce'}
|
render path, :locals => {:secret => 'in the sauce'}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class TestBasic < SimpleRouteCase
|
class TestBasic < SimpleRouteCase
|
||||||
testing RenderFile::BasicController
|
testing RenderFile::BasicController
|
||||||
|
|
||||||
def setup
|
|
||||||
@old_pwd = Dir.pwd
|
|
||||||
Dir.chdir(File.dirname(__FILE__))
|
|
||||||
end
|
|
||||||
|
|
||||||
def teardown
|
|
||||||
Dir.chdir(@old_pwd)
|
|
||||||
end
|
|
||||||
|
|
||||||
test "rendering simple template" do
|
test "rendering simple template" do
|
||||||
get :index
|
get :index
|
||||||
assert_response "Hello world!"
|
assert_response "Hello world!"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "rendering template with ivar" do
|
test "rendering template with ivar" do
|
||||||
get :with_instance_variables
|
get :with_instance_variables
|
||||||
assert_response "The secret is in the sauce\n"
|
assert_response "The secret is in the sauce\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "rendering path without specifying the :file key" do
|
test "rendering path without specifying the :file key" do
|
||||||
get :without_file_key
|
get :without_file_key
|
||||||
assert_response "Hello world!"
|
assert_response "Hello world!"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "rendering path without specifying the :file key with ivar" do
|
test "rendering path without specifying the :file key with ivar" do
|
||||||
get :without_file_key_with_instance_variable
|
get :without_file_key_with_instance_variable
|
||||||
assert_response "The secret is in the sauce\n"
|
assert_response "The secret is in the sauce\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "rendering a relative path" do
|
test "rendering a relative path" do
|
||||||
get :relative_path
|
get :relative_path
|
||||||
assert_response "The secret is in the sauce\n"
|
assert_response "The secret is in the sauce\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "rendering a relative path with dot" do
|
test "rendering a relative path with dot" do
|
||||||
get :relative_path_with_dot
|
get :relative_path_with_dot
|
||||||
assert_response "The secret is in the sauce\n"
|
assert_response "The secret is in the sauce\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "rendering a Pathname" do
|
test "rendering a Pathname" do
|
||||||
get :pathname
|
get :pathname
|
||||||
assert_response "The secret is in the sauce\n"
|
assert_response "The secret is in the sauce\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "rendering file with locals" do
|
test "rendering file with locals" do
|
||||||
get :with_locals
|
get :with_locals
|
||||||
assert_response "The secret is in the sauce\n"
|
assert_response "The secret is in the sauce\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "rendering path without specifying the :file key with locals" do
|
test "rendering path without specifying the :file key with locals" do
|
||||||
get :without_file_key_with_locals
|
get :without_file_key_with_locals
|
||||||
assert_response "The secret is in the sauce\n"
|
assert_response "The secret is in the sauce\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue