aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--railties/lib/rails/generators/rails/plugin/plugin_generator.rb14
-rw-r--r--railties/test/generators/plugin_generator_test.rb24
2 files changed, 30 insertions, 8 deletions
diff --git a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb
index 1b63d5faa0..3c44086e25 100644
--- a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb
+++ b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb
@@ -305,19 +305,17 @@ task default: :test
end
def author
- if @author.nil?
- git_user_name = `git config user.name`.chomp
- @author = git_user_name.empty? ? "TODO: Write your name" : git_user_name
+ @author ||= begin
+ git_user_name = `git config user.name`.chomp rescue ''
+ git_user_name.blank? ? "TODO: Write your name" : git_user_name
end
- @author
end
def email
- if @email.nil?
- git_user_email = `git config user.email`.chomp
- @email = git_user_email.empty? ? "TODO: Write your email address" : git_user_email
+ @email ||= begin
+ git_user_email = `git config user.email`.chomp rescue ''
+ git_user_email.blank? ? "TODO: Write your email address" : git_user_email
end
- @email
end
def valid_const?
diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb
index 853af80111..61a4d2f347 100644
--- a/railties/test/generators/plugin_generator_test.rb
+++ b/railties/test/generators/plugin_generator_test.rb
@@ -371,6 +371,30 @@ class PluginGeneratorTest < Rails::Generators::TestCase
end
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?
+
+ 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_licence_file
+ name = `git config user.name`.chomp rescue ''
+ name = "TODO: Write your name" if name.blank?
+
+ run_generator [destination_root]
+ assert_file "MIT-LICENSE" do |contents|
+ assert_match(/#{Regexp.escape(name)}/, contents)
+ end
+ end
+
protected
def action(*args, &block)
silence(:stdout){ generator.send(*args, &block) }