aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorArun Agrawal <arunagw@gmail.com>2014-05-02 11:26:31 +0200
committerArun Agrawal <arunagw@gmail.com>2014-05-02 15:38:58 +0200
commitc694c8e25cf55dfe26021d829c08729a6cddad87 (patch)
treeb37c814783b381f4669397ed219ca3be6cbc21a9 /railties
parente8c310edf6b69e5250a50e44e1605b495ae6ba03 (diff)
downloadrails-c694c8e25cf55dfe26021d829c08729a6cddad87.tar.gz
rails-c694c8e25cf55dfe26021d829c08729a6cddad87.tar.bz2
rails-c694c8e25cf55dfe26021d829c08729a6cddad87.zip
skip-git should not hit git commands plugin generators
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG.md6
-rw-r--r--railties/lib/rails/generators/rails/plugin/plugin_generator.rb20
-rw-r--r--railties/test/generators/plugin_generator_test.rb26
3 files changed, 38 insertions, 14 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index 6a31a923a7..480ec32443 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -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.
diff --git a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb
index 3c44086e25..584f776c01 100644
--- a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb
+++ b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb
@@ -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
@@ -305,16 +309,20 @@ task default: :test
end
def author
- @author ||= begin
- git_user_name = `git config user.name`.chomp rescue ''
- git_user_name.blank? ? "TODO: Write your name" : git_user_name
+ default = "TODO: Write your name"
+ if skip_git?
+ @author = default
+ else
+ @author = `git config user.name`.chomp rescue default
end
end
def email
- @email ||= begin
- git_user_email = `git config user.email`.chomp rescue ''
- git_user_email.blank? ? "TODO: Write your email address" : git_user_email
+ default = "TODO: Write your email address"
+ if skip_git?
+ @email = default
+ else
+ @email = `git config user.email`.chomp rescue default
end
end
diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb
index 61a4d2f347..69ff23eb95 100644
--- a/railties/test/generators/plugin_generator_test.rb
+++ b/railties/test/generators/plugin_generator_test.rb
@@ -372,11 +372,8 @@ class PluginGeneratorTest < Rails::Generators::TestCase
end
def test_git_name_and_email_in_gemspec_file
- name = `git config user.name`.chomp rescue ''
- name = "TODO: Write your name" if name.blank?
-
- email = `git config user.email`.chomp rescue ''
- email = "TODO: Write your email address" if email.blank?
+ 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|
@@ -385,9 +382,8 @@ class PluginGeneratorTest < Rails::Generators::TestCase
end
end
- def test_git_name_in_licence_file
- name = `git config user.name`.chomp rescue ''
- name = "TODO: Write your name" if name.blank?
+ 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|
@@ -395,6 +391,20 @@ class PluginGeneratorTest < Rails::Generators::TestCase
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) }