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

Ensures that Rails options are split by whitespace when generating Rails 6.y.z apps #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@ source 'https://rubygems.org'
gemspec

gem 'rails', ENV['RAILS_VERSION'] if ENV['RAILS_VERSION']

case ENV['RAILS_VERSION']
when /^6\./
# This will only be necessary until release 6.0.1 is published (please see
# https://github.com/rails/rails/issues/36954#issuecomment-522171807)
gem 'sass-rails', '~> 6.0'
when /^5\./
gem 'sprockets', '~> 3.7'
end
21 changes: 20 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@ task :generate_test_gem => ['engine_cart:setup'] do
require "rails/generators/rails/plugin/plugin_generator"

pwd = Dir.pwd
Rails::Generators::PluginGenerator.start ['internal_test_gem']
generator_args = ['internal_test_gem']
generator_args << '--skip-javascript' if ENV.fetch('RAILS_VERSION', '') >= '6.0'

Rails::Generators::PluginGenerator.start generator_args

if Rails.version.to_f < 6.0 || Rails.version.to_f == 6.0
gemspec_file_path = "#{pwd}/internal_test_gem/.engine_cart.yml"
File.open(gemspec_file_path, 'w') do |f|
f.write('rails_options: "--skip-javascript"')
end
end

Dir.chdir(pwd)

Expand All @@ -30,6 +40,14 @@ task :generate_test_gem => ['engine_cart:setup'] do
IO.write(".internal_test_gem/internal_test_gem.gemspec", File.open(".internal_test_gem/internal_test_gem.gemspec") {|f| f.read.gsub(/.*homepage.*/, "")})
IO.write(".internal_test_gem/internal_test_gem.gemspec", File.open(".internal_test_gem/internal_test_gem.gemspec") {|f| f.read.gsub(/.*sqlite3.*/, "")})

if Rails.version.to_f < 6.0 || Rails.version.to_f == 6.0
gemspec_file_path = ".internal_test_gem/internal_test_gem.gemspec"
IO.write(gemspec_file_path,
File.open(gemspec_file_path) { |f|
f.read.gsub(/(spec.add_dependency "rails".+$)/, "\\1\n spec.add_dependency 'sprockets', '~> 3.7'")
Copy link
Author

@jrgriffiniii jrgriffiniii Nov 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hoping that this will no longer be necessary with rails/rails#36954 (comment) in 6.0.1, as I suspect that this is related to errors raised when using 4.0.0 as the sprockets dependency.

})
end

Rake::Task['engine_cart:inject_gemfile_extras'].invoke
EngineCart.within_test_app do
system "git init"
Expand All @@ -56,6 +74,7 @@ task :generate_test_gem => ['engine_cart:setup'] do

system("bundle exec rake engine_cart:prepare")
Bundler.clean_system "bundle install --quiet"
system("bundle update --conservative sprockets")
end
end

Expand Down
6 changes: 5 additions & 1 deletion lib/engine_cart/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ def templates_path
##
# Additional options when generating a test rails application
def rails_options
Array(options[:rails_options])
rails_options_values = options.fetch(:rails_options)
return [] if rails_options_values.nil?

rails_options = parse_options(rails_options_values)
Array(rails_options)
end

def extra_fingerprinted_files
Expand Down
23 changes: 23 additions & 0 deletions spec/integration/engine_cart_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,29 @@
end
end

if ENV.fetch('RAILS_VERSION', 0).to_f >= 6.0
context "when JavaScript support is disabled" do
before do
FileUtils.mv(".engine_cart.yml", ".engine_cart.yml.disabled")
FileUtils.cp(".engine_cart.yml.disabled", ".engine_cart.yml")

config_file = open(".engine_cart.yml", "a")
config_file.write(" --skip-javascript")
config_file.close
end

after do
FileUtils.rm(".engine_cart.yml")
FileUtils.mv(".engine_cart.yml.disabled", ".engine_cart.yml")
end

it "should not insert webpacker tools" do
`bundle exec rake engine_cart:generate`
expect(File).not_to exist(".internal_test_app/bin/yarn")
end
end
end

it "should not recreate an existing rails app when the engine_cart:generate task is reinvoked" do
EngineCart.within_test_app do
`bundle exec rake engine_cart:generate`
Expand Down