Use full path instead of filename for require (#11262)

This commit is contained in:
Michael Kohl 2020-11-05 08:09:03 +07:00 committed by GitHub
parent 286758ac2d
commit 8564c52d9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 8 deletions

View file

@ -45,7 +45,7 @@ The generator will also automatically create the corresponding spec file.
```ruby
require "rails_helper"
require Rails.root.join(
"20201103042915_backfill_column_for_articles.rb",
"lib/data_updates/20201103042915_backfill_column_for_articles.rb",
)
describe DataUpdateScripts::BackfillColumnForArticles do

View file

@ -3,10 +3,7 @@ class DataUpdateGenerator < Rails::Generators::NamedBase
class_option :spec, type: :boolean, default: true
def create_data_update_file
template(
"data_update.rb.tt",
File.join("lib", "data_update_scripts", class_path, script_name),
)
template("data_update.rb.tt", script_path)
return unless options["spec"]
@ -16,7 +13,10 @@ class DataUpdateGenerator < Rails::Generators::NamedBase
)
end
def script_name
@script_name ||= "#{Time.current.utc.strftime('%Y%m%d%H%M%S')}_#{file_name}.rb"
def script_path
@script_path ||= begin
script_name = "#{Time.current.utc.strftime('%Y%m%d%H%M%S')}_#{file_name}.rb"
File.join("lib", "data_update_scripts", class_path, script_name)
end
end
end

View file

@ -1,6 +1,6 @@
require "rails_helper"
require Rails.root.join(
"<%= script_name %>",
"<%= script_path %>",
)
describe DataUpdateScripts::<%= class_name %> do