Skip to content

Commit

Permalink
Make sure plugin generator works with dummy app
Browse files Browse the repository at this point in the history
The dummy app is using sprockets, so we need to include sprocket-rails
if the sprockets is not skipped.

Fixes #43920.
  • Loading branch information
rafaelfranca committed Dec 20, 2021
1 parent 0906fc6 commit f292daa
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
4 changes: 1 addition & 3 deletions railties/lib/rails/generators/app_base.rb
Expand Up @@ -170,15 +170,13 @@ def web_server_gemfile_entry # :doc:
end

def asset_pipeline_gemfile_entry
return [] if options[:skip_asset_pipeline]
return if options[:skip_asset_pipeline]

if options[:asset_pipeline] == "sprockets"
GemfileEntry.floats "sprockets-rails",
"The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]"
elsif options[:asset_pipeline] == "propshaft"
GemfileEntry.floats "propshaft", "The modern asset pipeline for Rails [https://github.com/rails/propshaft]"
else
[]
end
end

Expand Down
Expand Up @@ -14,6 +14,10 @@ group :development do
end
<% end -%>

<% if engine? && !skip_sprockets? -%>
<%= asset_pipeline_gemfile_entry %>

<% end -%>
<% if rails_prerelease? -%>
# Your gem is dependent on a prerelease version of Rails. Once you can lock this
# dependency down to a specific version, move it to your gemspec.
Expand Down
33 changes: 33 additions & 0 deletions railties/test/generators/plugin_generator_test.rb
Expand Up @@ -291,6 +291,39 @@ def test_ensure_that_migration_tasks_work_with_mountable_option
assert $?.success?, "Command failed: #{output}"
end

def test_ensure_that_sprokets_is_required_when_mountable
run_generator [destination_root, "--mountable"]
assert_file "Gemfile", /^gem "sprockets-rails"/
end

def test_ensure_that_sprokets_is_required_when_full
run_generator [destination_root, "--full"]
assert_file "Gemfile", /^gem "sprockets-rails"/
end

def test_ensure_that_sprokets_is_not_required_when_not_mountable_or_full
run_generator
assert_file "Gemfile" do |content|
assert_no_match(/sprockets-rails/, content)
end
end

def test_ensure_that_sprokets_is_not_required_when_assets_pipeline_is_skipped
run_generator [destination_root, "--skip-asset-pipeline", "--mountable"]

assert_file "Gemfile" do |contents|
assert_no_match(/sprockets-rails/, contents)
end
end

def test_ensure_that_sprokets_is_not_required_when_assets_pipeline_is_not_sprockets
run_generator [destination_root, "--asset-pipeline=propshaft", "--mountable"]

assert_file "Gemfile" do |contents|
assert_no_match(/sprockets-rails/, contents)
end
end

def test_creating_engine_in_full_mode
run_generator [destination_root, "--full"]
assert_file "app/assets/stylesheets/bukkits"
Expand Down

0 comments on commit f292daa

Please sign in to comment.