提交 4cfcf1ee 编写于 作者: M Matthew Draper 提交者: GitHub

Merge pull request #29176 from bogdanvlviv/define-path-with__dir__

Define path with __dir__
......@@ -90,7 +90,7 @@ group :cable do
end
# Add your own local bundler stuff.
local_gemfile = File.dirname(__FILE__) + "/.Gemfile"
local_gemfile = File.expand_path(".Gemfile", __dir__)
instance_eval File.read local_gemfile if File.exist? local_gemfile
group :test do
......
require "net/http"
$:.unshift File.expand_path("..", __FILE__)
$:.unshift __dir__
require "tasks/release"
require "railties/lib/rails/api/task"
......
......@@ -409,7 +409,7 @@ application. The recommended basic setup is as follows:
```ruby
# cable/config.ru
require ::File.expand_path('../../config/environment', __FILE__)
require ::File.expand_path('../config/environment', __dir__)
Rails.application.eager_load!
run ActionCable.server
......
......@@ -3,15 +3,13 @@ require "pathname"
require "open3"
require "action_cable"
dir = File.dirname(__FILE__)
task default: :test
task package: %w( assets:compile assets:verify )
Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = Dir.glob("#{dir}/test/**/*_test.rb")
t.test_files = Dir.glob("#{__dir__}/test/**/*_test.rb")
t.warning = true
t.verbose = true
t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION)
......@@ -46,7 +44,7 @@ namespace :assets do
desc "Verify compiled Action Cable assets"
task :verify do
file = "lib/assets/compiled/action_cable.js"
pathname = Pathname.new("#{dir}/#{file}")
pathname = Pathname.new("#{__dir__}/#{file}")
print "[verify] #{file} exists "
if pathname.exist?
......@@ -64,8 +62,8 @@ namespace :assets do
fail
end
print "[verify] #{dir} can be required as a module "
_, stderr, status = Open3.capture3("node", "--print", "window = {}; require('#{dir}');")
print "[verify] #{__dir__} can be required as a module "
_, stderr, status = Open3.capture3("node", "--print", "window = {}; require('#{__dir__}');")
if status.success?
puts "[OK]"
else
......
version = File.read(File.expand_path("../../RAILS_VERSION", __FILE__)).strip
version = File.read(File.expand_path("../RAILS_VERSION", __dir__)).strip
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
......
module Rails
module Generators
class ChannelGenerator < NamedBase
source_root File.expand_path("../templates", __FILE__)
source_root File.expand_path("templates", __dir__)
argument :actions, type: :array, default: [], banner: "method method"
......
......@@ -11,7 +11,7 @@
end
# Require all the stubs and models
Dir[File.dirname(__FILE__) + "/stubs/*.rb"].each { |file| require file }
Dir[File.expand_path("stubs/*.rb", __dir__)].each { |file| require file }
class ActionCable::TestCase < ActiveSupport::TestCase
def wait_for_async
......
version = File.read(File.expand_path("../../RAILS_VERSION", __FILE__)).strip
version = File.read(File.expand_path("../RAILS_VERSION", __dir__)).strip
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
......
module Rails
module Generators
class MailerGenerator < NamedBase
source_root File.expand_path("../templates", __FILE__)
source_root File.expand_path("templates", __dir__)
argument :actions, type: :array, default: [], banner: "method method"
......
......@@ -9,7 +9,7 @@
module Rails
def self.root
File.expand_path("../", File.dirname(__FILE__))
File.expand_path("..", __dir__)
end
end
......@@ -28,7 +28,7 @@ def self.root
# Disable available locale checks to avoid warnings running the test suite.
I18n.enforce_available_locales = false
FIXTURE_LOAD_PATH = File.expand_path("fixtures", File.dirname(__FILE__))
FIXTURE_LOAD_PATH = File.expand_path("fixtures", __dir__)
ActionMailer::Base.view_paths = FIXTURE_LOAD_PATH
class ActiveSupport::TestCase
......
......@@ -5,7 +5,7 @@
CACHE_DIR = "test_cache"
# Don't change '/../temp/' cavalierly or you might hose something you don't want hosed
FILE_STORE_PATH = File.join(File.dirname(__FILE__), "/../temp/", CACHE_DIR)
FILE_STORE_PATH = File.join(__dir__, "/../temp/", CACHE_DIR)
class FragmentCachingMailer < ActionMailer::Base
abstract!
......
......@@ -36,7 +36,7 @@ def test_deliver_is_notified
end
def test_receive_is_notified
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email")
fixture = File.read(File.expand_path("fixtures/raw_email", __dir__))
TestMailer.receive(fixture)
wait
assert_equal(1, @logger.logged(:info).size)
......
......@@ -26,7 +26,7 @@ namespace :test do
end
task :lines do
load File.expand_path("..", File.dirname(__FILE__)) + "/tools/line_statistics"
load File.expand_path("..", __dir__) + "/tools/line_statistics"
files = FileList["lib/**/*.rb"]
CodeTools::LineStatistics.new(files).print_loc
end
......
version = File.read(File.expand_path("../../RAILS_VERSION", __FILE__)).strip
version = File.read(File.expand_path("../RAILS_VERSION", __dir__)).strip
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
......
......@@ -82,7 +82,7 @@ def to_svg
end
def visualizer(paths, title = "FSM")
viz_dir = File.join File.dirname(__FILE__), "..", "visualizer"
viz_dir = File.join __dir__, "..", "visualizer"
fsm_js = File.read File.join(viz_dir, "fsm.js")
fsm_css = File.read File.join(viz_dir, "fsm.css")
erb = File.read File.join(viz_dir, "index.html.erb")
......
......@@ -10,7 +10,7 @@ module ActionDispatch
# This middleware is responsible for logging exceptions and
# showing a debugging page in case the request is local.
class DebugExceptions
RESCUES_TEMPLATE_PATH = File.expand_path("../templates", __FILE__)
RESCUES_TEMPLATE_PATH = File.expand_path("templates", __dir__)
class DebugView < ActionView::Base
def debug_params(params)
......
$:.unshift(File.dirname(__FILE__) + "/lib")
$:.unshift(File.dirname(__FILE__) + "/fixtures/helpers")
$:.unshift(File.dirname(__FILE__) + "/fixtures/alternate_helpers")
$:.unshift File.expand_path("lib", __dir__)
$:.unshift File.expand_path("fixtures/helpers", __dir__)
$:.unshift File.expand_path("fixtures/alternate_helpers", __dir__)
require "active_support/core_ext/kernel/reporting"
......@@ -56,7 +56,7 @@ def root; end;
# Disable available locale checks to avoid warnings running the test suite.
I18n.enforce_available_locales = false
FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), "fixtures")
FIXTURE_LOAD_PATH = File.join(__dir__, "fixtures")
SharedTestRoutes = ActionDispatch::Routing::RouteSet.new
......@@ -156,7 +156,7 @@ def with_routing(&block)
end
def with_autoload_path(path)
path = File.join(File.dirname(__FILE__), "fixtures", path)
path = File.join(__dir__, "fixtures", path)
if ActiveSupport::Dependencies.autoload_paths.include?(path)
yield
else
......
......@@ -83,7 +83,7 @@ def raise_exception_on_post
end
def render_file_absolute_path
render file: File.expand_path("../../../README.rdoc", __FILE__)
render file: File.expand_path("../../README.rdoc", __dir__)
end
def render_file_relative_path
......
require "abstract_unit"
module TestApiFileUtils
def file_path() File.expand_path(__FILE__) end
def file_path() __FILE__ end
def file_data() @data ||= File.open(file_path, "rb") { |f| f.read } end
end
......
......@@ -4,7 +4,7 @@
CACHE_DIR = "test_cache"
# Don't change '/../temp/' cavalierly or you might hose something you don't want hosed
FILE_STORE_PATH = File.join(File.dirname(__FILE__), "/../temp/", CACHE_DIR)
FILE_STORE_PATH = File.join(__dir__, "../temp/", CACHE_DIR)
class FragmentCachingMetalTestController < ActionController::Metal
abstract!
......
require "abstract_unit"
ActionController::Base.helpers_path = File.expand_path("../../fixtures/helpers", __FILE__)
ActionController::Base.helpers_path = File.expand_path("../fixtures/helpers", __dir__)
module Fun
class GamesController < ActionController::Base
......@@ -48,7 +48,7 @@ class MeTooController < JustMeController
class HelpersPathsController < ActionController::Base
paths = ["helpers2_pack", "helpers1_pack"].map do |path|
File.join(File.expand_path("../../fixtures", __FILE__), path)
File.join(File.expand_path("../fixtures", __dir__), path)
end
$:.unshift(*paths)
......@@ -61,7 +61,7 @@ def index
end
class HelpersTypoController < ActionController::Base
path = File.expand_path("../../fixtures/helpers_typo", __FILE__)
path = File.expand_path("../fixtures/helpers_typo", __dir__)
$:.unshift(path)
self.helpers_path = path
end
......@@ -178,7 +178,7 @@ def test_all_helpers
end
def test_all_helpers_with_alternate_helper_dir
@controller_class.helpers_path = File.expand_path("../../fixtures/alternate_helpers", __FILE__)
@controller_class.helpers_path = File.expand_path("../fixtures/alternate_helpers", __dir__)
# Reload helpers
@controller_class._helpers = Module.new
......
......@@ -1091,7 +1091,7 @@ def app
end
def self.fixture_path
File.dirname(__FILE__) + "/../fixtures/multipart"
File.expand_path("../fixtures/multipart", __dir__)
end
routes.draw do
......
......@@ -152,7 +152,7 @@ def blocking_stream
end
def write_sleep_autoload
path = File.join(File.dirname(__FILE__), "../fixtures")
path = File.expand_path("../fixtures", __dir__)
ActiveSupport::Dependencies.autoload_paths << path
response.headers["Content-Type"] = "text/event-stream"
......
......@@ -29,7 +29,7 @@ def test_javascript_with_no_format_only_star_star
end
class AbstractPostController < ActionController::Base
self.view_paths = File.dirname(__FILE__) + "/../../fixtures/post_test/"
self.view_paths = File.expand_path("../../fixtures/post_test", __dir__)
end
# For testing layouts which are set automatically
......
......@@ -2,15 +2,15 @@
module RenderFile
class BasicController < ActionController::Base
self.view_paths = File.dirname(__FILE__)
self.view_paths = __dir__
def index
render file: File.join(File.dirname(__FILE__), *%w[.. .. fixtures test hello_world])
render file: File.expand_path("../../fixtures/test/hello_world", __dir__)
end
def with_instance_variables
@secret = "in the sauce"
render file: File.join(File.dirname(__FILE__), "../../fixtures/test/render_file_with_ivar")
render file: File.expand_path("../../fixtures/test/render_file_with_ivar", __dir__)
end
def relative_path
......@@ -25,11 +25,11 @@ def relative_path_with_dot
def pathname
@secret = "in the sauce"
render file: Pathname.new(File.dirname(__FILE__)).join(*%w[.. .. fixtures test dot.directory render_file_with_ivar])
render file: Pathname.new(__dir__).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")
path = File.expand_path("../../fixtures/test/render_file_with_locals", __dir__)
render file: path, locals: { secret: "in the sauce" }
end
end
......
......@@ -6,7 +6,7 @@ class SimpleController < ::ApplicationController
"render_implicit_action/simple/hello_world.html.erb" => "Hello world!",
"render_implicit_action/simple/hyphen-ated.html.erb" => "Hello hyphen-ated!",
"render_implicit_action/simple/not_implemented.html.erb" => "Not Implemented"
), ActionView::FileSystemResolver.new(File.expand_path("../../../controller", __FILE__))]
), ActionView::FileSystemResolver.new(File.expand_path("../../controller", __dir__))]
def hello_world() end
end
......
......@@ -257,7 +257,7 @@ def determine_layout
module TemplateModificationHelper
private
def modify_template(name)
path = File.expand_path("../../fixtures/#{name}.erb", __FILE__)
path = File.expand_path("../fixtures/#{name}.erb", __dir__)
original = File.read(path)
File.write(path, "#{original} Modified!")
ActionView::LookupContext::DetailsKey.clear
......@@ -287,9 +287,9 @@ def setup
def test_dynamic_render_with_file
# This is extremely bad, but should be possible to do.
assert File.exist?(File.join(File.dirname(__FILE__), "../../test/abstract_unit.rb"))
assert File.exist?(File.expand_path("../../test/abstract_unit.rb", __dir__))
response = get :dynamic_render_with_file, params: { id: '../\\../test/abstract_unit.rb' }
assert_equal File.read(File.join(File.dirname(__FILE__), "../../test/abstract_unit.rb")),
assert_equal File.read(File.expand_path("../../test/abstract_unit.rb", __dir__)),
response.body
end
......@@ -306,16 +306,16 @@ def test_dynamic_render_with_absolute_path
end
def test_dynamic_render
assert File.exist?(File.join(File.dirname(__FILE__), "../../test/abstract_unit.rb"))
assert File.exist?(File.expand_path("../../test/abstract_unit.rb", __dir__))
assert_raises ActionView::MissingTemplate do
get :dynamic_render, params: { id: '../\\../test/abstract_unit.rb' }
end
end
def test_permitted_dynamic_render_file_hash
assert File.exist?(File.join(File.dirname(__FILE__), "../../test/abstract_unit.rb"))
assert File.exist?(File.expand_path("../../test/abstract_unit.rb", __dir__))
response = get :dynamic_render_permit, params: { id: { file: '../\\../test/abstract_unit.rb' } }
assert_equal File.read(File.join(File.dirname(__FILE__), "../../test/abstract_unit.rb")),
assert_equal File.read(File.expand_path("../../test/abstract_unit.rb", __dir__)),
response.body
end
......
......@@ -2,7 +2,7 @@
module TestFileUtils
def file_name() File.basename(__FILE__) end
def file_path() File.expand_path(__FILE__) end
def file_path() __FILE__ end
def file_data() @data ||= File.open(file_path, "rb") { |f| f.read } end
end
......
......@@ -122,7 +122,7 @@ def test_file_upload
end
def test_send_file
send_file(File.expand_path(__FILE__))
send_file(__FILE__)
end
def redirect_to_same_controller
......@@ -780,7 +780,7 @@ def test_multiple_mixed_method_process_should_scrub_rack_input
end
end
FILES_DIR = File.dirname(__FILE__) + "/../fixtures/multipart"
FILES_DIR = File.expand_path("../fixtures/multipart", __dir__)
READ_BINARY = "rb:binary"
READ_PLAIN = "r:binary"
......@@ -855,7 +855,7 @@ def test_fixture_file_upload_relative_to_fixture_path
end
def test_fixture_file_upload_ignores_fixture_path_given_full_path
TestCaseTest.stub :fixture_path, File.dirname(__FILE__) do
TestCaseTest.stub :fixture_path, __dir__ do
uploaded_file = fixture_file_upload("#{FILES_DIR}/ruby_on_rails.jpg", "image/jpg")
assert_equal File.open("#{FILES_DIR}/ruby_on_rails.jpg", READ_PLAIN).read, uploaded_file.read
end
......
......@@ -21,7 +21,7 @@ def read
end
end
FIXTURE_PATH = File.dirname(__FILE__) + "/../../fixtures/multipart"
FIXTURE_PATH = File.expand_path("../../fixtures/multipart", __dir__)
def teardown
TestController.last_request_parameters = nil
......
......@@ -107,7 +107,7 @@ def teardown
query = [
"customers[boston][first][name]=David",
"something_else=blah",
"logo=#{File.expand_path(__FILE__)}"
"logo=#{__FILE__}"
].join("&")
expected = {
"customers" => {
......@@ -118,7 +118,7 @@ def teardown
}
},
"something_else" => "blah",
"logo" => File.expand_path(__FILE__),
"logo" => __FILE__,
}
assert_parses expected, query
end
......
......@@ -2,8 +2,6 @@ require "rake/testtask"
require "fileutils"
require "open3"
dir = File.dirname(__FILE__)
desc "Default Task"
task default: :test
......@@ -95,7 +93,7 @@ namespace :assets do
desc "Verify compiled Action View assets"
task :verify do
file = "lib/assets/compiled/rails-ujs.js"
pathname = Pathname.new("#{dir}/#{file}")
pathname = Pathname.new("#{__dir__}/#{file}")
print "[verify] #{file} exists "
if pathname.exist?
......@@ -113,11 +111,11 @@ namespace :assets do
fail
end
print "[verify] #{dir} can be required as a module "
print "[verify] #{__dir__} can be required as a module "
js = <<-JS
window = { Event: class {} }
class Element {}
require('#{dir}')
require('#{__dir__}')
JS
_, stderr, status = Open3.capture3("node", "--print", js)
if status.success?
......@@ -130,7 +128,7 @@ namespace :assets do
end
task :lines do
load File.expand_path("..", File.dirname(__FILE__)) + "/tools/line_statistics"
load File.join(File.expand_path("..", __dir__), "/tools/line_statistics")
files = FileList["lib/**/*.rb"]
CodeTools::LineStatistics.new(files).print_loc
end
version = File.read(File.expand_path("../../RAILS_VERSION", __FILE__)).strip
version = File.read(File.expand_path("../RAILS_VERSION", __dir__)).strip
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
......
......@@ -92,5 +92,5 @@ def self.eager_load!
require "active_support/core_ext/string/output_safety"
ActiveSupport.on_load(:i18n) do
I18n.load_path << "#{File.dirname(__FILE__)}/action_view/locale/en.yml"
I18n.load_path << File.expand_path("action_view/locale/en.yml", __dir__)
end
$:.unshift(File.dirname(__FILE__) + "/lib")
$:.unshift(File.dirname(__FILE__) + "/fixtures/helpers")
$:.unshift(File.dirname(__FILE__) + "/fixtures/alternate_helpers")
$:.unshift File.expand_path("lib", __dir__)
$:.unshift File.expand_path("fixtures/helpers", __dir__)
$:.unshift File.expand_path("fixtures/alternate_helpers", __dir__)
ENV["TMPDIR"] = File.join(File.dirname(__FILE__), "tmp")
ENV["TMPDIR"] = File.expand_path("tmp", __dir__)
require "active_support/core_ext/kernel/reporting"
......@@ -47,7 +47,7 @@ def env
I18n.backend.store_translations "pt-BR", {}
ORIGINAL_LOCALES = I18n.available_locales.map(&:to_s).sort
FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), "fixtures")
FIXTURE_LOAD_PATH = File.expand_path("fixtures", __dir__)
module RenderERBUtils
def view
......@@ -133,7 +133,7 @@ class BasicController
def config
@config ||= ActiveSupport::InheritableOptions.new(ActionController::Base.config).tap do |config|
# VIEW TODO: View tests should not require a controller
public_dir = File.expand_path("../fixtures/public", __FILE__)
public_dir = File.expand_path("fixtures/public", __dir__)
config.assets_dir = public_dir
config.javascripts_dir = "#{public_dir}/javascripts"
config.stylesheets_dir = "#{public_dir}/stylesheets"
......@@ -196,7 +196,7 @@ def with_routing(&block)
end
def with_autoload_path(path)
path = File.join(File.dirname(__FILE__), "fixtures", path)
path = File.join(File.expand_path("fixtures", __dir__), path)
if ActiveSupport::Dependencies.autoload_paths.include?(path)
yield
else
......
......@@ -42,7 +42,7 @@ def render(options = {})
super
end
append_view_path File.expand_path(File.join(File.dirname(__FILE__), "views"))
append_view_path File.expand_path("views", __dir__)
end
class Me2 < RenderingController
......@@ -152,7 +152,7 @@ def setup
class OverridingLocalPrefixes < AbstractController::Base
include AbstractController::Rendering
include ActionView::Rendering
append_view_path File.expand_path(File.join(File.dirname(__FILE__), "views"))
append_view_path File.expand_path("views", __dir__)
def index
render
......
require "abstract_unit"
ActionController::Base.helpers_path = File.expand_path("../../../fixtures/helpers", __FILE__)
ActionController::Base.helpers_path = File.expand_path("../../fixtures/helpers", __dir__)
module AbstractController
module Testing
......@@ -51,7 +51,7 @@ class AbstractHelpersBlock < ControllerWithHelpers
class AbstractInvalidHelpers < AbstractHelpers
include ActionController::Helpers
path = File.expand_path("../../../fixtures/helpers_missing", __FILE__)
path = File.expand_path("../../fixtures/helpers_missing", __dir__)
$:.unshift(path)
self.helpers_path = path
end
......
......@@ -2,7 +2,7 @@
require "active_support/logger"
class CaptureController < ActionController::Base
self.view_paths = [ File.dirname(__FILE__) + "/../../fixtures/actionpack" ]
self.view_paths = [ File.expand_path("../../fixtures/actionpack", __dir__) ]
def self.controller_name; "test"; end
def self.controller_path; "test"; end
......
......@@ -5,7 +5,7 @@
# method has access to the view_paths array when looking for a layout to automatically assign.
old_load_paths = ActionController::Base.view_paths
ActionController::Base.view_paths = [ File.dirname(__FILE__) + "/../../fixtures/actionpack/layout_tests/" ]
ActionController::Base.view_paths = [ File.expand_path("../../fixtures/actionpack/layout_tests", __dir__) ]
class LayoutTest < ActionController::Base
def self.controller_path; "views" end
......@@ -96,7 +96,7 @@ def render(*args)
end
class AbsolutePathLayoutController < LayoutTest
layout File.expand_path(File.expand_path(__FILE__) + "/../../../fixtures/actionpack/layout_tests/layouts/layout_test")
layout File.expand_path("../../fixtures/actionpack/layout_tests/layouts/layout_test", __dir__)
end
class HasOwnLayoutController < LayoutTest
......@@ -117,7 +117,7 @@ class HasNilLayoutProc < LayoutTest
class PrependsViewPathController < LayoutTest
def hello
prepend_view_path File.dirname(__FILE__) + "/../../fixtures/actionpack/layout_tests/alt/"
prepend_view_path File.expand_path("../../fixtures/actionpack/layout_tests/alt", __dir__)
render layout: "alt"
end
end
......
......@@ -56,7 +56,7 @@ def hello_world
end
def hello_world_file
render file: File.expand_path("../../../fixtures/actionpack/hello", __FILE__), formats: [:html]
render file: File.expand_path("../../fixtures/actionpack/hello", __dir__), formats: [:html]
end
# :ported:
......@@ -125,7 +125,7 @@ def hello_world_with_layout_false
# :ported:
def render_file_with_instance_variables
@secret = "in the sauce"
path = File.join(File.dirname(__FILE__), "../../fixtures/test/render_file_with_ivar")
path = File.expand_path("../../fixtures/test/render_file_with_ivar", __dir__)
render file: path
end
......@@ -142,21 +142,21 @@ def render_file_not_using_full_path_with_dot_in_path
def render_file_using_pathname
@secret = "in the sauce"
render file: Pathname.new(File.dirname(__FILE__)).join("..", "..", "fixtures", "test", "dot.directory", "render_file_with_ivar")
render file: Pathname.new(__dir__).join("..", "..", "fixtures", "test", "dot.directory", "render_file_with_ivar")
end
def render_file_from_template
@secret = "in the sauce"
@path = File.expand_path(File.join(File.dirname(__FILE__), "../../fixtures/test/render_file_with_ivar"))
@path = File.expand_path("../../fixtures/test/render_file_with_ivar", __dir__)
end
def render_file_with_locals
path = File.join(File.dirname(__FILE__), "../../fixtures/test/render_file_with_locals")
path = File.expand_path("../../fixtures/test/render_file_with_locals", __dir__)
render file: path, locals: { secret: "in the sauce" }
end
def render_file_as_string_with_locals
path = File.expand_path(File.join(File.dirname(__FILE__), "../../fixtures/test/render_file_with_locals"))
path = File.expand_path("../../fixtures/test/render_file_with_locals", __dir__)
render file: path, locals: { secret: "in the sauce" }
end
......
......@@ -13,7 +13,7 @@ class ActiveRecordTestConnector
# Try to grab AR
unless defined?(ActiveRecord) && defined?(FixtureSet)
begin
PATH_TO_AR = "#{File.dirname(__FILE__)}/../../activerecord/lib"
PATH_TO_AR = File.expand_path("../../activerecord/lib", __dir__)
raise LoadError, "#{PATH_TO_AR} doesn't exist" unless File.directory?(PATH_TO_AR)
$LOAD_PATH.unshift PATH_TO_AR
require "active_record"
......@@ -58,13 +58,13 @@ def setup_connection
# Load actionpack sqlite3 tables
def load_schema
File.read(File.dirname(__FILE__) + "/fixtures/db_definitions/sqlite.sql").split(";").each do |sql|
File.read(File.expand_path("fixtures/db_definitions/sqlite.sql", __dir__)).split(";").each do |sql|
ActiveRecord::Base.connection.execute(sql) unless sql.blank?
end
end
def require_fixture_models
Dir.glob(File.dirname(__FILE__) + "/fixtures/*.rb").each { |f| require f }
Dir.glob(File.expand_path("fixtures/*.rb", __dir__)).each { |f| require f }
end
end
end
......
......@@ -14,7 +14,7 @@ def initialize(template_path)
end
class FixtureFinder < ActionView::LookupContext
FIXTURES_DIR = "#{File.dirname(__FILE__)}/../fixtures/digestor"
FIXTURES_DIR = File.expand_path("../fixtures/digestor", __dir__)
def initialize(details = {})
super(ActionView::PathSet.new(["digestor", "digestor/api"]), details, [])
......
......@@ -138,7 +138,7 @@ def test_render_file_at_top_level
end
def test_render_file_with_full_path
template_path = File.join(File.dirname(__FILE__), "../fixtures/test/hello_world")
template_path = File.expand_path("../fixtures/test/hello_world", __dir__)
assert_equal "Hello world!", @view.render(file: template_path)
end
......@@ -160,7 +160,7 @@ def test_render_partial_from_default
end
def test_render_outside_path
assert File.exist?(File.join(File.dirname(__FILE__), "../../test/abstract_unit.rb"))
assert File.exist?(File.expand_path("../../test/abstract_unit.rb", __dir__))
assert_raises ActionView::MissingTemplate do
@view.render(template: "../\\../test/abstract_unit.rb")
end
......
......@@ -2,7 +2,7 @@
class ResolverPatternsTest < ActiveSupport::TestCase
def setup
path = File.expand_path("../../fixtures/", __FILE__)
path = File.expand_path("../fixtures", __dir__)
pattern = ":prefix/{:formats/,}:action{.:formats,}{+:variants,}{.:handlers,}"
@resolver = ActionView::FileSystemResolver.new(path, pattern)
end
......
$LOAD_PATH.unshift File.expand_path("..", __FILE__)
$LOAD_PATH.unshift __dir__
require "server"
run UJS::Server
......@@ -44,9 +44,8 @@ namespace :test do
namespace :isolated do
task adapter => "test:env:#{adapter}" do
dir = File.dirname(__FILE__)
Dir.glob("#{dir}/test/cases/**/*_test.rb").all? do |file|
sh(Gem.ruby, "-w", "-I#{dir}/lib", "-I#{dir}/test", file)
Dir.glob("#{__dir__}/test/cases/**/*_test.rb").all? do |file|
sh(Gem.ruby, "-w", "-I#{__dir__}/lib", "-I#{__dir__}/test", file)
end || raise("Failures")
end
end
......
version = File.read(File.expand_path("../../RAILS_VERSION", __FILE__)).strip
version = File.read(File.expand_path("../RAILS_VERSION", __dir__)).strip
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
......
......@@ -12,7 +12,7 @@ class JobGenerator < Rails::Generators::NamedBase # :nodoc:
hook_for :test_framework
def self.default_generator_root
File.dirname(__FILE__)
__dir__
end
def create_job_file
......
ActiveJob::Base.queue_adapter = :delayed_job
$LOAD_PATH << File.dirname(__FILE__) + "/../support/delayed_job"
$LOAD_PATH << File.expand_path("../support/delayed_job", __dir__)
Delayed::Worker.delay_jobs = false
Delayed::Worker.backend = :test
......@@ -5,7 +5,7 @@
rails_command("db:migrate")
initializer "activejob.rb", <<-CODE
require "#{File.expand_path("../jobs_manager.rb", __FILE__)}"
require "#{File.expand_path("jobs_manager.rb", __dir__)}"
JobsManager.current_manager.setup
CODE
......
......@@ -7,7 +7,7 @@
require "tmpdir"
dummy_app_path = Dir.mktmpdir + "/dummy"
dummy_app_template = File.expand_path("../dummy_app_template.rb", __FILE__)
dummy_app_template = File.expand_path("dummy_app_template.rb", __dir__)
args = Rails::Generators::ARGVScrubber.new(["new", dummy_app_path, "--skip-gemfile", "--skip-bundle",
"--skip-git", "--skip-spring", "-d", "sqlite3", "--skip-javascript", "--force", "--quiet",
"--template", dummy_app_template]).prepare!
......
require "rake/testtask"
dir = File.dirname(__FILE__)
task default: :test
task :package
Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = Dir.glob("#{dir}/test/cases/**/*_test.rb")
t.test_files = Dir.glob("#{__dir__}/test/cases/**/*_test.rb")
t.warning = true
t.verbose = true
t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION)
......@@ -16,8 +14,8 @@ end
namespace :test do
task :isolated do
Dir.glob("#{dir}/test/**/*_test.rb").all? do |file|
sh(Gem.ruby, "-w", "-I#{dir}/lib", "-I#{dir}/test", file)
Dir.glob("#{__dir__}/test/**/*_test.rb").all? do |file|
sh(Gem.ruby, "-w", "-I#{__dir__}/lib", "-I#{__dir__}/test", file)
end || raise("Failures")
end
end
version = File.read(File.expand_path("../../RAILS_VERSION", __FILE__)).strip
version = File.read(File.expand_path("../RAILS_VERSION", __dir__)).strip
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
......
......@@ -68,5 +68,5 @@ def self.eager_load!
end
ActiveSupport.on_load(:i18n) do
I18n.load_path << File.dirname(__FILE__) + "/active_model/locale/en.yml"
I18n.load_path << File.expand_path("active_model/locale/en.yml", __dir__)
end
......@@ -435,4 +435,4 @@ def initialize(model)
end
end
Dir[File.dirname(__FILE__) + "/validations/*.rb"].each { |file| require file }
Dir[File.expand_path("validations/*.rb", __dir__)].each { |file| require file }
require "rake/testtask"
require File.expand_path(File.dirname(__FILE__)) + "/test/config"
require File.expand_path(File.dirname(__FILE__)) + "/test/support/config"
require File.expand_path("test/config", __dir__)
require File.expand_path("test/support/config", __dir__)
def run_without_aborting(*tasks)
errors = []
......@@ -134,7 +134,7 @@ task drop_postgresql_databases: "db:postgresql:drop"
task rebuild_postgresql_databases: "db:postgresql:rebuild"
task :lines do
load File.expand_path("..", File.dirname(__FILE__)) + "/tools/line_statistics"
load File.expand_path("../tools/line_statistics", __dir__)
files = FileList["lib/active_record/**/*.rb"]
CodeTools::LineStatistics.new(files).print_loc
end
version = File.read(File.expand_path("../../RAILS_VERSION", __FILE__)).strip
version = File.read(File.expand_path("../RAILS_VERSION", __dir__)).strip
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
......
......@@ -177,5 +177,5 @@ def self.eager_load!
end
ActiveSupport.on_load(:i18n) do
I18n.load_path << File.dirname(__FILE__) + "/active_record/locale/en.yml"
I18n.load_path << File.expand_path("active_record/locale/en.yml", __dir__)
end
......@@ -10,7 +10,7 @@ class Base < Rails::Generators::NamedBase # :nodoc:
# Set the current directory as base for the inherited generators.
def self.base_root
File.dirname(__FILE__)
__dir__
end
end
end
......
......@@ -96,7 +96,7 @@ def test_via_to_sql_with_complicating_connection
end
def test_write_binary
data = File.read(File.join(File.dirname(__FILE__), "..", "..", "..", "assets", "example.log"))
data = File.read(File.join(__dir__, "..", "..", "..", "assets", "example.log"))
assert(data.size > 1)
record = ByteaDataType.create(payload: data)
assert_not record.new_record?
......
......@@ -954,7 +954,7 @@ def test_habtm_with_reflection_using_class_name_and_fixtures
assert_not_nil Developer._reflections["shared_computers"]
# Checking the fixture for named association is important here, because it's the only way
# we've been able to reproduce this bug
assert_not_nil File.read(File.expand_path("../../../fixtures/developers.yml", __FILE__)).index("shared_computers")
assert_not_nil File.read(File.expand_path("../../fixtures/developers.yml", __dir__)).index("shared_computers")
assert_equal developers(:david).shared_computers.first, computers(:laptop)
end
......
......@@ -316,7 +316,7 @@ def test_new_without_storing_full_sti_class
end
def test_new_with_autoload_paths
path = File.expand_path("../../models/autoloadable", __FILE__)
path = File.expand_path("../models/autoloadable", __dir__)
ActiveSupport::Dependencies.autoload_paths << path
firm = Company.new(type: "ExtraFirm")
......
......@@ -13,7 +13,7 @@ def test_has_one_with_reload
# development environment. Note that meanwhile the class Pet is not
# reloaded, simulating a class that is present in a plugin.
Object.class_eval { remove_const :Owner }
Kernel.load(File.expand_path(File.join(File.dirname(__FILE__), "../models/owner.rb")))
Kernel.load(File.expand_path("../models/owner.rb", __dir__))
pet = Pet.find_by_name("parrot")
pet.owner = Owner.find_by_name("ashley")
......
......@@ -123,8 +123,8 @@ def test_yaml_encoding_keeps_mutations
def yaml_fixture(file_name)
path = File.expand_path(
"../../support/yaml_compatibility_fixtures/#{file_name}.yml",
__FILE__
"../support/yaml_compatibility_fixtures/#{file_name}.yml",
__dir__
)
File.read(path)
end
......
TEST_ROOT = File.expand_path(File.dirname(__FILE__))
TEST_ROOT = __dir__
ASSETS_ROOT = TEST_ROOT + "/assets"
FIXTURES_ROOT = TEST_ROOT + "/fixtures"
MIGRATIONS_ROOT = TEST_ROOT + "/migrations"
......
version = File.read(File.expand_path("../../RAILS_VERSION", __FILE__)).strip
version = File.read(File.expand_path("../RAILS_VERSION", __dir__)).strip
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
......
#!/usr/bin/env ruby
begin
$:.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
$:.unshift(File.expand_path("../lib", __dir__))
require "active_support"
rescue IOError
end
......
(Dir["#{File.dirname(__FILE__)}/core_ext/*.rb"]).each do |path|
Dir.glob(File.expand_path("core_ext/*.rb", __dir__)).each do |path|
require path
end
......@@ -102,7 +102,7 @@ def _extract_callstack(callstack)
end
end
RAILS_GEM_ROOT = File.expand_path("../../../../..", __FILE__) + "/"
RAILS_GEM_ROOT = File.expand_path("../../../..", __dir__)
def ignored_callstack(path)
path.start_with?(RAILS_GEM_ROOT) || path.start_with?(RbConfig::CONFIG["rubylibdir"])
......
......@@ -10,4 +10,4 @@
require "active_support/lazy_load_hooks"
ActiveSupport.run_load_hooks(:i18n)
I18n.load_path << "#{File.dirname(__FILE__)}/locale/en.yml"
I18n.load_path << File.expand_path("locale/en.yml", __dir__)
......@@ -357,7 +357,7 @@ class << self
# Returns the directory in which the data files are stored.
def self.dirname
File.dirname(__FILE__) + "/../values/"
File.expand_path("../values", __dir__)
end
# Returns the filename for the data file for this version.
......
......@@ -104,7 +104,7 @@ def test_warnings_should_be_enabled_on_first_load
with_loading "dependencies" do
old_warnings, ActiveSupport::Dependencies.warnings_on_first_load = ActiveSupport::Dependencies.warnings_on_first_load, true
filename = "check_warnings"
expanded = File.expand_path("#{File.dirname(__FILE__)}/dependencies/#{filename}")
expanded = File.expand_path("dependencies/#{filename}", __dir__)
$check_warnings_load_count = 0
assert_not ActiveSupport::Dependencies.loaded.include?(expanded)
......@@ -293,7 +293,7 @@ def test_throwing_discards_autoloaded_constants
end
def test_doesnt_break_normal_require
path = File.expand_path("../autoloading_fixtures/load_path", __FILE__)
path = File.expand_path("autoloading_fixtures/load_path", __dir__)
original_path = $:.dup
$:.push(path)
with_autoloading_fixtures do
......@@ -312,7 +312,7 @@ def test_doesnt_break_normal_require
end
def test_doesnt_break_normal_require_nested
path = File.expand_path("../autoloading_fixtures/load_path", __FILE__)
path = File.expand_path("autoloading_fixtures/load_path", __dir__)
original_path = $:.dup
$:.push(path)
......@@ -332,7 +332,7 @@ def test_doesnt_break_normal_require_nested
end
def test_require_returns_true_when_file_not_yet_required
path = File.expand_path("../autoloading_fixtures/load_path", __FILE__)
path = File.expand_path("autoloading_fixtures/load_path", __dir__)
original_path = $:.dup
$:.push(path)
......@@ -345,7 +345,7 @@ def test_require_returns_true_when_file_not_yet_required
end
def test_require_returns_true_when_file_not_yet_required_even_when_no_new_constants_added
path = File.expand_path("../autoloading_fixtures/load_path", __FILE__)
path = File.expand_path("autoloading_fixtures/load_path", __dir__)
original_path = $:.dup
$:.push(path)
......@@ -359,7 +359,7 @@ def test_require_returns_true_when_file_not_yet_required_even_when_no_new_consta
end
def test_require_returns_false_when_file_already_required
path = File.expand_path("../autoloading_fixtures/load_path", __FILE__)
path = File.expand_path("autoloading_fixtures/load_path", __dir__)
original_path = $:.dup
$:.push(path)
......@@ -379,7 +379,7 @@ def test_require_raises_load_error_when_file_not_found
end
def test_load_returns_true_when_file_found
path = File.expand_path("../autoloading_fixtures/load_path", __FILE__)
path = File.expand_path("autoloading_fixtures/load_path", __dir__)
original_path = $:.dup
$:.push(path)
......@@ -438,7 +438,7 @@ def test_loadable_constants_for_path_should_handle_empty_autoloads
def test_loadable_constants_for_path_should_handle_relative_paths
fake_root = "dependencies"
relative_root = File.dirname(__FILE__) + "/dependencies"
relative_root = File.expand_path("dependencies", __dir__)
["", "/"].each do |suffix|
with_loading fake_root + suffix do
assert_equal ["A::B"], ActiveSupport::Dependencies.loadable_constants_for_path(relative_root + "/a/b")
......@@ -463,7 +463,7 @@ def test_loadable_constants_for_path_should_uniq_results
end
def test_loadable_constants_with_load_path_without_trailing_slash
path = File.dirname(__FILE__) + "/autoloading_fixtures/class_folder/inline_class.rb"
path = File.expand_path("autoloading_fixtures/class_folder/inline_class.rb", __dir__)
with_loading "autoloading_fixtures/class/" do
assert_equal [], ActiveSupport::Dependencies.loadable_constants_for_path(path)
end
......@@ -991,7 +991,7 @@ def test_remove_constant_handles_double_colon_at_start
def test_remove_constant_does_not_trigger_loading_autoloads
constant = "ShouldNotBeAutoloaded"
Object.class_eval do
autoload constant, File.expand_path("../autoloading_fixtures/should_not_be_required", __FILE__)
autoload constant, File.expand_path("autoloading_fixtures/should_not_be_required", __dir__)
end
assert_nil ActiveSupport::Dependencies.remove_constant(constant), "Kernel#autoload has been triggered by remove_constant"
......
module DependenciesTestHelpers
def with_loading(*from)
old_mechanism, ActiveSupport::Dependencies.mechanism = ActiveSupport::Dependencies.mechanism, :load
this_dir = File.dirname(__FILE__)
this_dir = __dir__
parent_dir = File.dirname(this_dir)
path_copy = $LOAD_PATH.dup
$LOAD_PATH.unshift(parent_dir) unless $LOAD_PATH.include?(parent_dir)
......
......@@ -3,7 +3,7 @@
require "pathname"
class FileFixturesTest < ActiveSupport::TestCase
self.file_fixture_path = File.expand_path("../../file_fixtures", __FILE__)
self.file_fixture_path = File.expand_path("../file_fixtures", __dir__)
test "#file_fixture returns Pathname to file fixture" do
path = file_fixture("sample.txt")
......@@ -20,7 +20,7 @@ class FileFixturesTest < ActiveSupport::TestCase
end
class FileFixturesPathnameDirectoryTest < ActiveSupport::TestCase
self.file_fixture_path = Pathname.new(File.expand_path("../../file_fixtures", __FILE__))
self.file_fixture_path = Pathname.new(File.expand_path("../file_fixtures", __dir__))
test "#file_fixture_path returns Pathname to file fixture" do
path = file_fixture("sample.txt")
......
......@@ -2,7 +2,7 @@
XMLMiniEngineTest.run_with_platform("java") do
class JDOMEngineTest < XMLMiniEngineTest
FILES_DIR = File.dirname(__FILE__) + "/../fixtures/xml"
FILES_DIR = File.expand_path("../fixtures/xml", __dir__)
def test_not_allowed_to_expand_entities_to_files
attack_xml = <<-EOT
......
......@@ -15,7 +15,7 @@
require "action_controller/railtie"
class TestApp < Rails::Application
config.root = File.dirname(__FILE__)
config.root = __dir__
config.session_store :cookie_store, key: "cookie_store_key"
secrets.secret_token = "secret_token"
secrets.secret_key_base = "secret_key_base"
......
......@@ -14,7 +14,7 @@
require "action_controller/railtie"
class TestApp < Rails::Application
config.root = File.dirname(__FILE__)
config.root = __dir__
secrets.secret_token = "secret_token"
secrets.secret_key_base = "secret_key_base"
......
......@@ -15,7 +15,7 @@ def guide(name, url, options = {}, &block)
end
def documents_by_section
@documents_by_section ||= YAML.load_file(File.expand_path("../../source/#{@language ? @language + '/' : ''}documents.yaml", __FILE__))
@documents_by_section ||= YAML.load_file(File.expand_path("../source/#{@language ? @language + '/' : ''}documents.yaml", __dir__))
end
def documents_flat
......
......@@ -96,7 +96,7 @@ This is the generator just created:
```ruby
class InitializerGenerator < Rails::Generators::NamedBase
source_root File.expand_path("../templates", __FILE__)
source_root File.expand_path("templates", __dir__)
end
```
......@@ -122,7 +122,7 @@ And now let's change the generator to copy this template when invoked:
```ruby
class InitializerGenerator < Rails::Generators::NamedBase
source_root File.expand_path("../templates", __FILE__)
source_root File.expand_path("templates", __dir__)
def copy_initializer_file
copy_file "initializer.rb", "config/initializers/#{file_name}.rb"
......
......@@ -277,6 +277,6 @@ relative paths to your template's location.
```ruby
def source_paths
[File.expand_path(File.dirname(__FILE__))]
[__dir__]
end
```
......@@ -356,7 +356,7 @@ send_file('/var/www/uploads/' + params[:filename])
Simply pass a file name like "../../../etc/passwd" to download the server's login information. A simple solution against this, is to _check that the requested file is in the expected directory_:
```ruby
basename = File.expand_path(File.join(File.dirname(__FILE__), '../../files'))
basename = File.expand_path('../../files', __dir__)
filename = File.expand_path(File.join(basename, @file.public_filename))
raise if basename !=
File.expand_path(File.join(File.dirname(filename), '../../../'))
......
version = File.read(File.expand_path("../RAILS_VERSION", __FILE__)).strip
version = File.read(File.expand_path("RAILS_VERSION", __dir__)).strip
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
......
......@@ -16,10 +16,10 @@ namespace :test do
dash_i = [
"test",
"lib",
"#{File.dirname(__FILE__)}/../activesupport/lib",
"#{File.dirname(__FILE__)}/../actionpack/lib",
"#{File.dirname(__FILE__)}/../actionview/lib",
"#{File.dirname(__FILE__)}/../activemodel/lib"
"#{__dir__}/../activesupport/lib",
"#{__dir__}/../actionpack/lib",
"#{__dir__}/../actionview/lib",
"#{__dir__}/../activemodel/lib"
]
ruby "-w", "-I#{dash_i.join ':'}", file
end
......@@ -27,7 +27,7 @@ namespace :test do
end
Rake::TestTask.new("test:regular") do |t|
t.libs << "test" << "#{File.dirname(__FILE__)}/../activesupport/lib"
t.libs << "test" << "#{__dir__}/../activesupport/lib"
t.pattern = "test/**/*_test.rb"
t.warning = false
t.verbose = true
......
#!/usr/bin/env ruby
git_path = File.expand_path("../../../.git", __FILE__)
git_path = File.expand_path("../../.git", __dir__)
if File.exist?(git_path)
railties_path = File.expand_path("../../lib", __FILE__)
railties_path = File.expand_path("../lib", __dir__)
$:.unshift(railties_path)
end
require "rails/cli"
class Rails::ApplicationController < ActionController::Base # :nodoc:
self.view_paths = File.expand_path("../templates", __FILE__)
self.view_paths = File.expand_path("templates", __dir__)
layout "application"
private
......
......@@ -5,7 +5,7 @@ module Actions
# This allows us to run `rails server` from other directories, but still get
# the main config.ru and properly set the tmp directory.
def set_application_directory!
Dir.chdir(File.expand_path("../../", APP_PATH)) unless File.exist?(File.expand_path("config.ru"))
Dir.chdir(File.expand_path("../..", APP_PATH)) unless File.exist?(File.expand_path("config.ru"))
end
def require_application_and_environment!
......
......@@ -40,7 +40,7 @@ module Rails
#
# class MyEngine < Rails::Engine
# # Add a load path for this specific Engine
# config.autoload_paths << File.expand_path("../lib/some/path", __FILE__)
# config.autoload_paths << File.expand_path("lib/some/path", __dir__)
#
# initializer "my_engine.add_middleware" do |app|
# app.middleware.use MyEngine::Middleware
......
activesupport_path = File.expand_path("../../../../activesupport/lib", __FILE__)
activesupport_path = File.expand_path("../../../activesupport/lib", __dir__)
$:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)
require "thor/group"
......
......@@ -215,7 +215,7 @@ def self.default_source_root
# Returns the base root for a common set of generators. This is used to dynamically
# guess the default source root.
def self.base_root
File.dirname(__FILE__)
__dir__
end
# Cache source root and add lib/generators/base/generator/templates to
......
......@@ -3,7 +3,7 @@
module Css # :nodoc:
module Generators # :nodoc:
class AssetsGenerator < Rails::Generators::NamedBase # :nodoc:
source_root File.expand_path("../templates", __FILE__)
source_root File.expand_path("templates", __dir__)
def copy_stylesheet
copy_file "stylesheet.css", File.join("app/assets/stylesheets", class_path, "#{file_name}.css")
......
......@@ -3,7 +3,7 @@
module Js # :nodoc:
module Generators # :nodoc:
class AssetsGenerator < Rails::Generators::NamedBase # :nodoc:
source_root File.expand_path("../templates", __FILE__)
source_root File.expand_path("templates", __dir__)
def copy_javascript
copy_file "javascript.js", File.join("app/assets/javascripts", class_path, "#{file_name}.js")
......
......@@ -201,7 +201,7 @@ def vendor
module Generators
# We need to store the RAILS_DEV_PATH in a constant, otherwise the path
# can change in Ruby 1.8.7 when we FileUtils.cd.
RAILS_DEV_PATH = File.expand_path("../../../../../..", File.dirname(__FILE__))
RAILS_DEV_PATH = File.expand_path("../../../../../..", __dir__)
RESERVED_NAMES = %w[application destroy plugin runner test]
class AppGenerator < AppBase # :nodoc:
......
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
load Gem.bin_path('bundler', 'bundle')
......@@ -3,7 +3,7 @@ require 'fileutils'
include FileUtils
# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
APP_ROOT = Pathname.new File.expand_path('..', __dir__)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
......
......@@ -3,7 +3,7 @@ require 'fileutils'
include FileUtils
# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
APP_ROOT = Pathname.new File.expand_path('..', __dir__)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
......
require File.expand_path('../../config/environment', __FILE__)
require File.expand_path('../config/environment', __dir__)
require 'rails/test_help'
class ActiveSupport::TestCase
......
class <%= class_name %>Generator < Rails::Generators::NamedBase
source_root File.expand_path('../templates', __FILE__)
source_root File.expand_path('templates', __dir__)
end
$:.push File.expand_path("../lib", __FILE__)
$:.push File.expand_path("lib", __dir__)
# Maintain your gem's version:
require "<%= namespaced_name %>/version"
......
......@@ -15,7 +15,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
end
<% if engine? && !options[:skip_active_record] && with_dummy_app? -%>
APP_RAKEFILE = File.expand_path("../<%= dummy_path -%>/Rakefile", __FILE__)
APP_RAKEFILE = File.expand_path("<%= dummy_path -%>/Rakefile", __dir__)
load 'rails/tasks/engine.rake'
<% end %>
......
# This command will automatically be run when you run "rails" with Rails gems
# installed from the root of your application.
ENGINE_ROOT = File.expand_path('../..', __FILE__)
ENGINE_PATH = File.expand_path('../../lib/<%= namespaced_name -%>/engine', __FILE__)
APP_PATH = File.expand_path('../../<%= dummy_path -%>/config/application', __FILE__)
ENGINE_ROOT = File.expand_path('..', __dir__)
ENGINE_PATH = File.expand_path('../lib/<%= namespaced_name -%>/engine', __dir__)
APP_PATH = File.expand_path('../<%= dummy_path -%>/config/application', __dir__)
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
require 'rails/all'
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册