mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #14941 from arunagw/hbakhtiyor-new-plugin-command-advanced-config
Plugin gemspec
This commit is contained in:
commit
504adac36e
5 changed files with 65 additions and 3 deletions
|
@ -1,3 +1,9 @@
|
|||
* Reading name and email from git for plugin gemspec.
|
||||
|
||||
Fixes #9589.
|
||||
|
||||
*Arun Agrawal*, *Abd ar-Rahman Hamidi*, *Roman Shmatov*
|
||||
|
||||
* Fix `console` and `generators` blocks defined at different environments.
|
||||
|
||||
Fixes #14748.
|
||||
|
|
|
@ -288,6 +288,10 @@ task default: :test
|
|||
options[:mountable]
|
||||
end
|
||||
|
||||
def skip_git?
|
||||
options[:skip_git]
|
||||
end
|
||||
|
||||
def with_dummy_app?
|
||||
options[:skip_test_unit].blank? || options[:dummy_path] != 'test/dummy'
|
||||
end
|
||||
|
@ -304,6 +308,24 @@ task default: :test
|
|||
@camelized ||= name.gsub(/\W/, '_').squeeze('_').camelize
|
||||
end
|
||||
|
||||
def author
|
||||
default = "TODO: Write your name"
|
||||
if skip_git?
|
||||
@author = default
|
||||
else
|
||||
@author = `git config user.name`.chomp rescue default
|
||||
end
|
||||
end
|
||||
|
||||
def email
|
||||
default = "TODO: Write your email address"
|
||||
if skip_git?
|
||||
@email = default
|
||||
else
|
||||
@email = `git config user.email`.chomp rescue default
|
||||
end
|
||||
end
|
||||
|
||||
def valid_const?
|
||||
if original_name =~ /[^0-9a-zA-Z_]+/
|
||||
raise Error, "Invalid plugin name #{original_name}. Please give a name which use only alphabetic or numeric or \"_\" characters."
|
||||
|
|
|
@ -7,8 +7,8 @@ require "<%= name %>/version"
|
|||
Gem::Specification.new do |s|
|
||||
s.name = "<%= name %>"
|
||||
s.version = <%= camelized %>::VERSION
|
||||
s.authors = ["TODO: Your name"]
|
||||
s.email = ["TODO: Your email"]
|
||||
s.authors = ["<%= author %>"]
|
||||
s.email = ["<%= email %>"]
|
||||
s.homepage = "TODO"
|
||||
s.summary = "TODO: Summary of <%= camelized %>."
|
||||
s.description = "TODO: Description of <%= camelized %>."
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Copyright <%= Date.today.year %> YOURNAME
|
||||
Copyright <%= Date.today.year %> <%= author %>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
|
|
@ -371,6 +371,40 @@ class PluginGeneratorTest < Rails::Generators::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_git_name_and_email_in_gemspec_file
|
||||
name = `git config user.name`.chomp rescue "TODO: Write your name"
|
||||
email = `git config user.email`.chomp rescue "TODO: Write your email address"
|
||||
|
||||
run_generator [destination_root]
|
||||
assert_file "bukkits.gemspec" do |contents|
|
||||
assert_match(/#{Regexp.escape(name)}/, contents)
|
||||
assert_match(/#{Regexp.escape(email)}/, contents)
|
||||
end
|
||||
end
|
||||
|
||||
def test_git_name_in_license_file
|
||||
name = `git config user.name`.chomp rescue "TODO: Write your name"
|
||||
|
||||
run_generator [destination_root]
|
||||
assert_file "MIT-LICENSE" do |contents|
|
||||
assert_match(/#{Regexp.escape(name)}/, contents)
|
||||
end
|
||||
end
|
||||
|
||||
def test_no_details_from_git_when_skip_git
|
||||
name = "TODO: Write your name"
|
||||
email = "TODO: Write your email address"
|
||||
|
||||
run_generator [destination_root, '--skip-git']
|
||||
assert_file "MIT-LICENSE" do |contents|
|
||||
assert_match(/#{Regexp.escape(name)}/, contents)
|
||||
end
|
||||
assert_file "bukkits.gemspec" do |contents|
|
||||
assert_match(/#{Regexp.escape(name)}/, contents)
|
||||
assert_match(/#{Regexp.escape(email)}/, contents)
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
def action(*args, &block)
|
||||
silence(:stdout){ generator.send(*args, &block) }
|
||||
|
|
Loading…
Reference in a new issue