Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Generators should use Rails.root instead of Dir.pwd [#3408 status:res…

…olved]

Signed-off-by: Yehuda Katz <wycats@gmail.com>
  • Loading branch information...
commit a288b74f1c75c6f100de7611a5093a421f1ad6d1 1 parent 8dcf91c
@josevalim josevalim authored wycats committed
Showing with 44 additions and 23 deletions.
  1. +17 −0 railties/lib/rails/generators/base.rb
  2. +1 −1  railties/test/generators/actions_test.rb
  3. +2 −2 railties/test/generators/app_generator_test.rb
  4. +1 −1  railties/test/generators/controller_generator_test.rb
  5. +1 −1  railties/test/generators/generator_generator_test.rb
  6. +8 −3 railties/test/generators/generators_test_helper.rb
  7. +1 −1  railties/test/generators/helper_generator_test.rb
  8. +1 −1  railties/test/generators/integration_test_generator_test.rb
  9. +1 −1  railties/test/generators/mailer_generator_test.rb
  10. +1 −1  railties/test/generators/metal_generator_test.rb
  11. +1 −1  railties/test/generators/migration_generator_test.rb
  12. +1 −1  railties/test/generators/model_generator_test.rb
  13. +1 −1  railties/test/generators/observer_generator_test.rb
  14. +1 −1  railties/test/generators/performance_test_generator_test.rb
  15. +1 −1  railties/test/generators/plugin_generator_test.rb
  16. +1 −1  railties/test/generators/resource_generator_test.rb
  17. +1 −1  railties/test/generators/scaffold_controller_generator_test.rb
  18. +1 −2  railties/test/generators/scaffold_generator_test.rb
  19. +1 −1  railties/test/generators/session_migration_generator_test.rb
  20. +1 −1  railties/test/generators/stylesheets_generator_test.rb
View
17 railties/lib/rails/generators/base.rb
@@ -12,6 +12,16 @@ class Base < Thor::Group
add_runtime_options!
+ # Always move to rails source root.
+ #
+ def initialize(*args) #:nodoc:
+ if !invoked?(args) && defined?(Rails.root) && Rails.root
+ self.destination_root = Rails.root
+ FileUtils.cd(destination_root)
+ end
+ super
+ end
+
# Automatically sets the source root based on the class name.
#
def self.source_root
@@ -247,6 +257,13 @@ def class_collisions(*class_names) #:nodoc:
end
end
+ # Check if this generator was invoked from another one by inspecting
+ # parameters.
+ #
+ def invoked?(args)
+ args.last.is_a?(Hash) && args.last.key?(:invocations)
+ end
+
# Use Rails default banner.
#
def self.banner
View
2  railties/test/generators/actions_test.rb
@@ -182,7 +182,7 @@ def run_generator
end
def generator(config={})
- @generator ||= Rails::Generators::Base.new([], {}, { :destination_root => destination_root }.merge!(config))
+ @generator ||= Rails::Generators::Base.new([], {}, config)
end
def action(*args, &block)
View
4 railties/test/generators/app_generator_test.rb
@@ -126,7 +126,7 @@ def test_rails_is_frozen
def test_template_from_dir_pwd
FileUtils.cd(Rails.root)
- assert_match /It works from file!/, run_generator(["-m", "lib/template.rb"])
+ assert_match /It works from file!/, run_generator(["-m", "../lib/template.rb"])
end
def test_template_raises_an_error_with_invalid_path
@@ -170,7 +170,7 @@ def run_generator(args=[])
end
def generator(options={})
- @generator ||= Rails::Generators::AppGenerator.new([destination_root], options, :destination_root => destination_root)
+ @generator ||= Rails::Generators::AppGenerator.new([destination_root], options)
end
def action(*args, &block)
View
2  railties/test/generators/controller_generator_test.rb
@@ -74,7 +74,7 @@ def test_actions_are_turned_into_methods
protected
def run_generator(args=["Account", "foo", "bar"])
- silence(:stdout) { Rails::Generators::ControllerGenerator.start args, :destination_root => destination_root }
+ silence(:stdout) { Rails::Generators::ControllerGenerator.start args }
end
end
View
2  railties/test/generators/generator_generator_test.rb
@@ -20,7 +20,7 @@ def test_generator_skeleton_is_created
protected
def run_generator(args=["awesome"], config={})
- silence(:stdout) { Rails::Generators::GeneratorGenerator.start args, config.merge(:destination_root => destination_root) }
+ silence(:stdout) { Rails::Generators::GeneratorGenerator.start args, config }
end
end
View
11 railties/test/generators/generators_test_helper.rb
@@ -1,5 +1,5 @@
# TODO: Fix this RAILS_ENV stuff
-RAILS_ENV = 'test'
+RAILS_ENV = 'test' unless defined?(RAILS_ENV)
require 'abstract_unit'
Rails.application.config.root = File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures'))
@@ -11,12 +11,17 @@
CURRENT_PATH = File.expand_path(Dir.pwd)
Rails::Generators.no_color!
+module Rails
+ def self.root
+ @root ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures', 'tmp'))
+ end
+end
+
class GeneratorsTestCase < Test::Unit::TestCase
include FileUtils
def destination_root
- @destination_root ||= File.expand_path(File.join(File.dirname(__FILE__),
- '..', 'fixtures', 'tmp'))
+ Rails.root
end
def setup
View
2  railties/test/generators/helper_generator_test.rb
@@ -54,7 +54,7 @@ def test_namespaced_and_not_namespaced_helpers
protected
def run_generator(args=["admin"])
- silence(:stdout) { Rails::Generators::HelperGenerator.start args, :destination_root => destination_root }
+ silence(:stdout) { Rails::Generators::HelperGenerator.start args }
end
end
View
2  railties/test/generators/integration_test_generator_test.rb
@@ -12,7 +12,7 @@ def test_integration_test_skeleton_is_created
protected
def run_generator(args=["integration"])
- silence(:stdout) { Rails::Generators::IntegrationTestGenerator.start args, :destination_root => destination_root }
+ silence(:stdout) { Rails::Generators::IntegrationTestGenerator.start args }
end
end
View
2  railties/test/generators/mailer_generator_test.rb
@@ -46,7 +46,7 @@ def test_actions_are_turned_into_methods
protected
def run_generator(args=["notifier", "foo", "bar"])
- silence(:stdout) { Rails::Generators::MailerGenerator.start args, :destination_root => destination_root }
+ silence(:stdout) { Rails::Generators::MailerGenerator.start args }
end
end
View
2  railties/test/generators/metal_generator_test.rb
@@ -17,7 +17,7 @@ def test_check_class_collision
protected
def run_generator(args=["foo"])
- silence(:stdout) { Rails::Generators::MetalGenerator.start args, :destination_root => destination_root }
+ silence(:stdout) { Rails::Generators::MetalGenerator.start args }
end
end
View
2  railties/test/generators/migration_generator_test.rb
@@ -53,7 +53,7 @@ def test_remove_migration_with_attributes
protected
def run_generator(args=[@migration])
- silence(:stdout) { Rails::Generators::MigrationGenerator.start args, :destination_root => destination_root }
+ silence(:stdout) { Rails::Generators::MigrationGenerator.start args }
end
end
View
2  railties/test/generators/model_generator_test.rb
@@ -175,7 +175,7 @@ def test_check_class_collision
protected
def run_generator(args=["Account", "name:string", "age:integer"], config={})
- silence(:stdout) { Rails::Generators::ModelGenerator.start args, config.merge(:destination_root => destination_root) }
+ silence(:stdout) { Rails::Generators::ModelGenerator.start args, config }
end
end
View
2  railties/test/generators/observer_generator_test.rb
@@ -27,7 +27,7 @@ def test_logs_if_the_test_framework_cannot_be_found
protected
def run_generator(args=["account"])
- silence(:stdout) { Rails::Generators::ObserverGenerator.start args, :destination_root => destination_root }
+ silence(:stdout) { Rails::Generators::ObserverGenerator.start args }
end
end
View
2  railties/test/generators/performance_test_generator_test.rb
@@ -12,7 +12,7 @@ def test_performance_test_skeleton_is_created
protected
def run_generator(args=["performance"])
- silence(:stdout) { Rails::Generators::PerformanceTestGenerator.start args, :destination_root => destination_root }
+ silence(:stdout) { Rails::Generators::PerformanceTestGenerator.start args }
end
end
View
2  railties/test/generators/plugin_generator_test.rb
@@ -50,7 +50,7 @@ def test_plugin_generator_on_revoke
protected
def run_generator(args=["plugin_fu"], config={})
- silence(:stdout) { Rails::Generators::PluginGenerator.start args, config.merge(:destination_root => destination_root) }
+ silence(:stdout){ Rails::Generators::PluginGenerator.start args, config }
end
end
View
2  railties/test/generators/resource_generator_test.rb
@@ -100,7 +100,7 @@ def test_route_is_removed_on_revoke
protected
def run_generator(args=["account"], config={})
- silence(:stdout) { Rails::Generators::ResourceGenerator.start args, config.merge(:destination_root => destination_root) }
+ silence(:stdout) { Rails::Generators::ResourceGenerator.start args, config }
end
end
View
2  railties/test/generators/scaffold_controller_generator_test.rb
@@ -139,7 +139,7 @@ def self.all(klass)
protected
def run_generator(args=["User", "name:string", "age:integer"])
- silence(:stdout) { Rails::Generators::ScaffoldControllerGenerator.start args, :destination_root => destination_root }
+ silence(:stdout) { Rails::Generators::ScaffoldControllerGenerator.start args }
end
end
View
3  railties/test/generators/scaffold_generator_test.rb
@@ -122,8 +122,7 @@ def test_scaffold_on_revoke
def run_generator(config={})
silence(:stdout) do
- Rails::Generators::ScaffoldGenerator.start ["product_line", "title:string", "price:integer"],
- config.merge(:destination_root => destination_root)
+ Rails::Generators::ScaffoldGenerator.start ["product_line", "title:string", "price:integer"], config
end
end
View
2  railties/test/generators/session_migration_generator_test.rb
@@ -28,7 +28,7 @@ def test_session_migration_with_custom_table_name
protected
def run_generator(args=[])
- silence(:stdout) { Rails::Generators::SessionMigrationGenerator.start args, :destination_root => destination_root }
+ silence(:stdout) { Rails::Generators::SessionMigrationGenerator.start args }
end
end
View
2  railties/test/generators/stylesheets_generator_test.rb
@@ -18,7 +18,7 @@ def test_stylesheets_are_not_deleted_on_revoke
protected
def run_generator(config={})
- silence(:stdout) { Rails::Generators::StylesheetsGenerator.start [], config.merge(:destination_root => destination_root) }
+ silence(:stdout) { Rails::Generators::StylesheetsGenerator.start [], config }
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.