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 ```ruby
require "rails_helper" require "rails_helper"
require Rails.root.join( require Rails.root.join(
"20201103042915_backfill_column_for_articles.rb", "lib/data_updates/20201103042915_backfill_column_for_articles.rb",
) )
describe DataUpdateScripts::BackfillColumnForArticles do describe DataUpdateScripts::BackfillColumnForArticles do

View file

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

View file

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