Skip to content

Commit fedb0e2

Browse files
committed
Merge pull request rails#6628 from fredwu/fix_skip_gemspec
Fixed the Gemfile when gemspec is skipped in the 'rails plugin new' command
2 parents 560b143 + 126586a commit fedb0e2

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

railties/lib/rails/generators/rails/plugin_new/templates/Gemfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
11
source "http://rubygems.org"
22

3+
<% if options[:skip_gemspec] -%>
4+
<%= '# ' if options.dev? || options.edge? -%>gem "rails", "~> <%= Rails::VERSION::STRING %>"
5+
<% if full? && !options[:skip_javascript] -%>
6+
# gem "<%= "#{options[:javascript]}-rails" %>"
7+
<% end -%>
8+
<% else -%>
39
# Declare your gem's dependencies in <%= name %>.gemspec.
410
# Bundler will treat runtime dependencies like base dependencies, and
511
# development dependencies will be added by default to the :development group.
612
gemspec
13+
<% end -%>
714
15+
<% unless options[:javascript] == 'jquery' -%>
816
# jquery-rails is used by the dummy application
917
gem "jquery-rails"
1018
19+
<% end -%>
20+
<% if options[:skip_gemspec] -%>
21+
group :development do
22+
gem "<%= gem_for_database %>"
23+
end
24+
<% else -%>
1125
# Declare any dependencies that are still in development here instead of in
1226
# your gemspec. These might include edge Rails or gems from your path or
1327
# Git. Remember to move these dependencies to your gemspec before releasing
1428
# your gem to rubygems.org.
29+
<% end -%>
1530
1631
<% if options.dev? || options.edge? -%>
1732
# Your gem is dependent on dev or edge Rails. Once you can lock this

railties/test/generators/plugin_new_generator_test.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,32 @@ def test_skipping_test_unit
269269
def test_skipping_gemspec
270270
run_generator [destination_root, "--skip-gemspec"]
271271
assert_no_file "bukkits.gemspec"
272+
assert_file "Gemfile" do |contents|
273+
assert_no_match('gemspec', contents)
274+
assert_match(/gem "rails", "~> #{Rails::VERSION::STRING}"/, contents)
275+
assert_match(/group :development do\n gem "sqlite3"\nend/, contents)
276+
assert_no_match(/# gem "jquery-rails"/, contents)
277+
end
278+
end
279+
280+
def test_skipping_gemspec_in_full_mode
281+
run_generator [destination_root, "--skip-gemspec", "--full"]
282+
assert_no_file "bukkits.gemspec"
283+
assert_file "Gemfile" do |contents|
284+
assert_no_match('gemspec', contents)
285+
assert_match(/gem "rails", "~> #{Rails::VERSION::STRING}"/, contents)
286+
assert_match(/group :development do\n gem "sqlite3"\nend/, contents)
287+
assert_match(/# gem "jquery-rails"/, contents)
288+
assert_no_match(/# jquery-rails is used by the dummy application\ngem "jquery-rails"/, contents)
289+
end
290+
end
291+
292+
def test_skipping_gemspec_in_full_mode_with_javascript_option
293+
run_generator [destination_root, "--skip-gemspec", "--full", "--javascript=prototype"]
294+
assert_file "Gemfile" do |contents|
295+
assert_match(/# gem "prototype-rails"/, contents)
296+
assert_match(/# jquery-rails is used by the dummy application\ngem "jquery-rails"/, contents)
297+
end
272298
end
273299

274300
def test_creating_plugin_in_app_directory_adds_gemfile_entry

0 commit comments

Comments
 (0)