Use full path instead of filename for require (#11262)
This commit is contained in:
parent
286758ac2d
commit
8564c52d9d
3 changed files with 8 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
require "rails_helper"
|
||||
require Rails.root.join(
|
||||
"<%= script_name %>",
|
||||
"<%= script_path %>",
|
||||
)
|
||||
|
||||
describe DataUpdateScripts::<%= class_name %> do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue