aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authoryuuji.yaginuma <yuuji.yaginuma@gmail.com>2017-02-18 16:42:48 +0900
committeryuuji.yaginuma <yuuji.yaginuma@gmail.com>2017-02-24 17:45:15 +0900
commit35a7a292645ee895e522769f657491e42d2a793a (patch)
treee8059c369f407808634c6c0fafe3f58ad36ef1dc /railties
parent6dccceef9c888e7e8a2cdcd46cd896eff75d64d9 (diff)
downloadrails-35a7a292645ee895e522769f657491e42d2a793a.tar.gz
rails-35a7a292645ee895e522769f657491e42d2a793a.tar.bz2
rails-35a7a292645ee895e522769f657491e42d2a793a.zip
Make adding gemfile entry work even if specify only the plugin name
Whether the command was executed within the rails application is checked by whether or not the application's path matches `app_path`. https://github.com/rails/rails/blob/5-0-stable/railties/lib/rails/generators/rails/plugin/plugin_generator.rb#L439..L441 Therefore, if only plugin name is specified in `app_path`, addition to Gemfile is not done. However, in the rails guide an example of specifying only plugin name is given, and it is considered that there are many cases where only plugin name is specified. For that reason, made it work even if only plugin name was specified.
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/generators/rails/plugin/plugin_generator.rb2
-rw-r--r--railties/test/generators/plugin_generator_test.rb15
2 files changed, 16 insertions, 1 deletions
diff --git a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb
index 49259f32c8..d8a41d4afe 100644
--- a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb
+++ b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb
@@ -432,7 +432,7 @@ end
end
def inside_application?
- rails_app_path && app_path =~ /^#{rails_app_path}/
+ rails_app_path && destination_root.start_with?(rails_app_path.to_s)
end
def relative_path
diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb
index ddfbc1a698..2ad0ab55d3 100644
--- a/railties/test/generators/plugin_generator_test.rb
+++ b/railties/test/generators/plugin_generator_test.rb
@@ -535,6 +535,21 @@ class PluginGeneratorTest < Rails::Generators::TestCase
FileUtils.rm gemfile_path
end
+ def test_creating_plugin_only_specify_plugin_name_in_app_directory_adds_gemfile_entry
+ # simulate application existence
+ gemfile_path = "#{Rails.root}/Gemfile"
+ Object.const_set("APP_PATH", Rails.root)
+ FileUtils.touch gemfile_path
+
+ FileUtils.cd(destination_root)
+ run_generator ["bukkits"]
+
+ assert_file gemfile_path, /gem 'bukkits', path: 'bukkits'/
+ ensure
+ Object.send(:remove_const, "APP_PATH")
+ FileUtils.rm gemfile_path
+ end
+
def test_skipping_gemfile_entry
# simulate application existence
gemfile_path = "#{Rails.root}/Gemfile"