Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overwrite bin/yarn when running app:binstub:yarn #41399

Merged
merged 1 commit into from Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions railties/lib/rails/generators/rails/app/app_generator.rb
Expand Up @@ -107,9 +107,7 @@ def bin_when_updating
end

def yarn_when_updating
return if File.exist?("bin/yarn")

template "bin/yarn" do |content|
template "bin/yarn", force: true do |content|
"#{shebang}\n" + content
end

Expand Down
16 changes: 16 additions & 0 deletions railties/test/application/rake_test.rb
Expand Up @@ -301,6 +301,22 @@ def test_copy_templates
end
end

test "app:binstub:yarn generates bin/yarn" do
yarn_binstub = File.join(app_path, "bin/yarn")
rails "app:binstub:yarn"

assert_path_exists yarn_binstub
assert_match %r/\A#!/, File.read(yarn_binstub)
end

test "app:binstub:yarn overwrites existing bin/yarn" do
yarn_binstub = File.join(app_path, "bin/yarn")
File.write(yarn_binstub, "existing")
rails "app:binstub:yarn"

assert_match %r/\A#!/, File.read(yarn_binstub)
end

def test_template_load_initializers
app_file "config/initializers/dummy.rb", "puts 'Hello, World!'"
app_file "template.rb", ""
Expand Down