Skip to content

Commit cbb6a26

Browse files
committed
Do not run bundle install when generating a new plugin.
Since bundler 1.12.0, the gemspec is validated so the `bundle install` command will fail just after the gem is created causing confusion to the users. This change was a bug fix to correctly validate gemspecs.
1 parent c740160 commit cbb6a26

File tree

6 files changed

+114
-103
lines changed

6 files changed

+114
-103
lines changed

railties/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
* Do not run `bundle install` when generating a new plugin.
2+
3+
Since bundler 1.12.0, the gemspec is validated so the `bundle install`
4+
command will fail just after the gem is created causing confusion to the
5+
users. This change was a bug fix to correctly validate gemspecs.
6+
7+
*Rafael Mendonça França*
8+
9+
110
## Rails 5.0.0 (June 30, 2016) ##
11+
212
* Ensure `/rails/info` routes match in development for apps with a catch-all globbing route.
313

414
*Nicholas Firth-McCoy*

railties/lib/rails/generators/app_base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def rails_gemfile_entry
242242
] + dev_edge_common
243243
elsif options.edge?
244244
[
245-
GemfileEntry.github('rails', 'rails/rails')
245+
GemfileEntry.github('rails', 'rails/rails', '5-0-stable')
246246
] + dev_edge_common
247247
else
248248
[GemfileEntry.version('rails',

railties/lib/rails/generators/rails/plugin/plugin_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def finish_template
258258
build(:leftovers)
259259
end
260260

261-
public_task :apply_rails_template, :run_bundle
261+
public_task :apply_rails_template
262262

263263
def run_after_bundle_callbacks
264264
@after_bundle_callbacks.each do |callback|

railties/test/generators/app_generator_test.rb

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,21 @@ def test_web_console_with_edge_option
597597
end
598598
end
599599

600+
def test_generation_runs_bundle_install
601+
assert_generates_with_bundler
602+
end
603+
604+
def test_dev_option
605+
assert_generates_with_bundler dev: true
606+
rails_path = File.expand_path('../../..', Rails.root)
607+
assert_file 'Gemfile', /^gem\s+["']rails["'],\s+path:\s+["']#{Regexp.escape(rails_path)}["']$/
608+
end
609+
610+
def test_edge_option
611+
assert_generates_with_bundler edge: true
612+
assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["'],\s+branch:\s+["']#{Regexp.escape("5-0-stable")}["']$}
613+
end
614+
600615
def test_spring
601616
run_generator
602617
assert_gem 'spring'
@@ -754,41 +769,61 @@ def test_after_bundle_callback
754769

755770
protected
756771

757-
def stub_rails_application(root)
758-
Rails.application.config.root = root
759-
Rails.application.class.stub(:name, "Myapp") do
760-
yield
772+
def stub_rails_application(root)
773+
Rails.application.config.root = root
774+
Rails.application.class.stub(:name, "Myapp") do
775+
yield
776+
end
761777
end
762-
end
763778

764-
def action(*args, &block)
765-
capture(:stdout) { generator.send(*args, &block) }
766-
end
779+
def action(*args, &block)
780+
capture(:stdout) { generator.send(*args, &block) }
781+
end
767782

768-
def assert_gem(gem, constraint = nil)
769-
if constraint
770-
assert_file "Gemfile", /^\s*gem\s+["']#{gem}["'], #{constraint}$*/
771-
else
772-
assert_file "Gemfile", /^\s*gem\s+["']#{gem}["']$*/
783+
def assert_gem(gem, constraint = nil)
784+
if constraint
785+
assert_file "Gemfile", /^\s*gem\s+["']#{gem}["'], #{constraint}$*/
786+
else
787+
assert_file "Gemfile", /^\s*gem\s+["']#{gem}["']$*/
788+
end
773789
end
774-
end
775790

776-
def assert_listen_related_configuration
777-
assert_gem 'listen'
778-
assert_gem 'spring-watcher-listen'
791+
def assert_listen_related_configuration
792+
assert_gem 'listen'
793+
assert_gem 'spring-watcher-listen'
779794

780-
assert_file 'config/environments/development.rb' do |content|
781-
assert_match(/^\s*config.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content)
795+
assert_file 'config/environments/development.rb' do |content|
796+
assert_match(/^\s*config.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content)
797+
end
782798
end
783-
end
784799

785-
def assert_no_listen_related_configuration
786-
assert_file 'Gemfile' do |content|
787-
assert_no_match(/listen/, content)
800+
def assert_no_listen_related_configuration
801+
assert_file 'Gemfile' do |content|
802+
assert_no_match(/listen/, content)
803+
end
804+
805+
assert_file 'config/environments/development.rb' do |content|
806+
assert_match(/^\s*# config.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content)
807+
end
788808
end
789809

790-
assert_file 'config/environments/development.rb' do |content|
791-
assert_match(/^\s*# config.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content)
810+
def assert_generates_with_bundler(options = {})
811+
generator([destination_root], options)
812+
813+
command_check = -> command do
814+
@install_called ||= 0
815+
816+
case command
817+
when 'install'
818+
@install_called += 1
819+
assert_equal 1, @install_called, "install expected to be called once, but was called #{@install_called} times"
820+
when 'exec spring binstub --all'
821+
# Called when running tests with spring, let through unscathed.
822+
end
823+
end
824+
825+
generator.stub :bundle_command, command_check do
826+
quietly { generator.invoke_all }
827+
end
792828
end
793-
end
794829
end

railties/test/generators/plugin_generator_test.rb

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,24 @@ def test_ensure_that_database_option_is_passed_to_app_generator
193193
assert_file "test/dummy/config/database.yml", /postgres/
194194
end
195195

196-
def test_generation_runs_bundle_install_with_full_and_mountable
197-
result = run_generator [destination_root, "--mountable", "--full", "--dev"]
198-
assert_match(/run bundle install/, result)
199-
assert $?.success?, "Command failed: #{result}"
200-
assert_file "#{destination_root}/Gemfile.lock" do |contents|
201-
assert_match(/bukkits/, contents)
202-
end
196+
def test_generation_runs_bundle_install
197+
assert_generates_without_bundler
198+
end
199+
200+
def test_dev_option
201+
assert_generates_without_bundler(dev: true)
202+
rails_path = File.expand_path('../../..', Rails.root)
203+
assert_file 'Gemfile', /^gem\s+["']rails["'],\s+path:\s+["']#{Regexp.escape(rails_path)}["']$/
204+
end
205+
206+
def test_edge_option
207+
assert_generates_without_bundler(edge: true)
208+
assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["'],\s+branch:\s+["']#{Regexp.escape("5-0-stable")}["']$}
209+
end
210+
211+
def test_generation_does_not_run_bundle_install_with_full_and_mountable
212+
assert_generates_without_bundler(mountable: true, full: true, dev: true)
213+
assert_no_file "#{destination_root}/Gemfile.lock"
203214
end
204215

205216
def test_skipping_javascripts_without_mountable_option
@@ -682,48 +693,38 @@ def test_generate_application_job_when_does_not_exist_in_mountable_engine
682693
end
683694
end
684695

685-
def test_after_bundle_callback
686-
path = 'http://example.org/rails_template'
687-
template = %{ after_bundle { run 'echo ran after_bundle' } }
688-
template.instance_eval "def read; self; end" # Make the string respond to read
696+
protected
689697

690-
check_open = -> *args do
691-
assert_equal [ path, 'Accept' => 'application/x-thor-template' ], args
692-
template
698+
def action(*args, &block)
699+
silence(:stdout){ generator.send(*args, &block) }
693700
end
694701

695-
sequence = ['install', 'echo ran after_bundle']
696-
@sequence_step ||= 0
697-
ensure_bundler_first = -> command do
698-
assert_equal sequence[@sequence_step], command, "commands should be called in sequence #{sequence}"
699-
@sequence_step += 1
702+
def default_files
703+
::DEFAULT_PLUGIN_FILES
700704
end
701705

702-
generator([destination_root], template: path).stub(:open, check_open, template) do
703-
generator.stub(:bundle_command, ensure_bundler_first) do
704-
generator.stub(:run, ensure_bundler_first) do
705-
quietly { generator.invoke_all }
706-
end
706+
def assert_match_sqlite3(contents)
707+
if defined?(JRUBY_VERSION)
708+
assert_match(/group :development do\n gem 'activerecord-jdbcsqlite3-adapter'\nend/, contents)
709+
else
710+
assert_match(/group :development do\n gem 'sqlite3'\nend/, contents)
707711
end
708712
end
709713

710-
assert_equal 2, @sequence_step
711-
end
714+
def assert_generates_without_bundler(options = {})
715+
generator([destination_root], options)
712716

713-
protected
714-
def action(*args, &block)
715-
silence(:stdout){ generator.send(*args, &block) }
716-
end
717-
718-
def default_files
719-
::DEFAULT_PLUGIN_FILES
720-
end
717+
command_check = -> command do
718+
case command
719+
when 'install'
720+
flunk "install expected to not be called"
721+
when 'exec spring binstub --all'
722+
# Called when running tests with spring, let through unscathed.
723+
end
724+
end
721725

722-
def assert_match_sqlite3(contents)
723-
if defined?(JRUBY_VERSION)
724-
assert_match(/group :development do\n gem 'activerecord-jdbcsqlite3-adapter'\nend/, contents)
725-
else
726-
assert_match(/group :development do\n gem 'sqlite3'\nend/, contents)
726+
generator.stub :bundle_command, command_check do
727+
quietly { generator.invoke_all }
728+
end
727729
end
728-
end
729730
end

railties/test/generators/shared_generator_tests.rb

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,6 @@ def test_skeleton_is_created
2626
default_files.each { |path| assert_file path }
2727
end
2828

29-
def assert_generates_with_bundler(options = {})
30-
generator([destination_root], options)
31-
32-
command_check = -> command do
33-
@install_called ||= 0
34-
35-
case command
36-
when 'install'
37-
@install_called += 1
38-
assert_equal 1, @install_called, "install expected to be called once, but was called #{@install_called} times"
39-
when 'exec spring binstub --all'
40-
# Called when running tests with spring, let through unscathed.
41-
end
42-
end
43-
44-
generator.stub :bundle_command, command_check do
45-
quietly { generator.invoke_all }
46-
end
47-
end
48-
49-
def test_generation_runs_bundle_install
50-
assert_generates_with_bundler
51-
end
52-
5329
def test_plugin_new_generate_pretend
5430
run_generator ["testapp", "--pretend"]
5531
default_files.each{ |path| assert_no_file File.join("testapp",path) }
@@ -114,17 +90,6 @@ def test_template_is_executed_when_supplied_an_https_path
11490
end
11591
end
11692

117-
def test_dev_option
118-
assert_generates_with_bundler dev: true
119-
rails_path = File.expand_path('../../..', Rails.root)
120-
assert_file 'Gemfile', /^gem\s+["']rails["'],\s+path:\s+["']#{Regexp.escape(rails_path)}["']$/
121-
end
122-
123-
def test_edge_option
124-
assert_generates_with_bundler edge: true
125-
assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["']$}
126-
end
127-
12893
def test_skip_gemfile
12994
assert_not_called(generator([destination_root], skip_gemfile: true), :bundle_command) do
13095
quietly { generator.invoke_all }

0 commit comments

Comments
 (0)