From 6ee461237a04122559bf9871df602eec4079cd08 Mon Sep 17 00:00:00 2001 From: Stefan Sprenger Date: Thu, 26 May 2011 17:54:31 +0200 Subject: We're now using generators directly --- railties/test/generators/plugin_new_generator_test.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'railties') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 528c73ffaf..32d7c58267 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -232,7 +232,6 @@ class CustomPluginGeneratorTest < Rails::Generators::TestCase assert_file 'spec/dummy' assert_file 'Rakefile', /task :default => :spec/ assert_file 'Rakefile', /# spec tasks in rakefile/ - assert_file 'script/rails', %r{spec/dummy} end protected -- cgit v1.2.3 From 60281af200180d752b8300bdad3c0a869d56347f Mon Sep 17 00:00:00 2001 From: Stefan Sprenger Date: Thu, 26 May 2011 17:57:46 +0200 Subject: Move load_generators from Rails::Application to Rails::Engine --- railties/lib/rails/application.rb | 12 ------------ railties/lib/rails/engine.rb | 12 ++++++++++++ 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 953233d774..497d4b5ac3 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -105,14 +105,6 @@ module Rails self end - def load_generators(app=self) - initialize_generators - railties.all { |r| r.load_generators(app) } - Rails::Generators.configure!(app.config.generators) - super - self - end - def load_console(app=self) initialize_console railties.all { |r| r.load_console(app) } @@ -195,10 +187,6 @@ module Rails end end - def initialize_generators - require "rails/generators" - end - def initialize_console require "pp" require "rails/console/app" diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 383be1802f..b358de89d0 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -330,6 +330,14 @@ module Rails autoload :Configuration, "rails/engine/configuration" autoload :Railties, "rails/engine/railties" + def load_generators(app=self) + initialize_generators + railties.all { |r| r.load_generators(app) } + Rails::Generators.configure!(app.config.generators) + super + self + end + class << self attr_accessor :called_from, :isolated alias :isolated? :isolated @@ -567,6 +575,10 @@ module Rails protected + def initialize_generators + require "rails/generators" + end + def routes? defined?(@routes) end -- cgit v1.2.3 From 835c9cee3ede273030bae5dcf465176d64b287dd Mon Sep 17 00:00:00 2001 From: Stefan Sprenger Date: Thu, 26 May 2011 17:59:00 +0200 Subject: Introducing engine commands --- railties/lib/rails/commands/generate.rb | 7 +++- railties/lib/rails/engine/commands.rb | 37 ++++++++++++++++++++++ .../rails/plugin_new/templates/script/rails.tt | 7 ++-- 3 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 railties/lib/rails/engine/commands.rb (limited to 'railties') diff --git a/railties/lib/rails/commands/generate.rb b/railties/lib/rails/commands/generate.rb index b6f9a003d1..1f742f8853 100644 --- a/railties/lib/rails/commands/generate.rb +++ b/railties/lib/rails/commands/generate.rb @@ -7,4 +7,9 @@ if ARGV.first.in?([nil, "-h", "--help"]) end name = ARGV.shift -Rails::Generators.invoke name, ARGV, :behavior => :invoke, :destination_root => Rails.root + +if defined?(ENGINE_ROOT) + Rails::Generators.invoke name, ARGV, :behavior => :invoke, :destination_root => ENGINE_ROOT +else + Rails::Generators.invoke name, ARGV, :behavior => :invoke, :destination_root => Rails.root +end diff --git a/railties/lib/rails/engine/commands.rb b/railties/lib/rails/engine/commands.rb new file mode 100644 index 0000000000..33a7cd5805 --- /dev/null +++ b/railties/lib/rails/engine/commands.rb @@ -0,0 +1,37 @@ +require 'active_support/core_ext/object/inclusion' + +ARGV << '--help' if ARGV.empty? + +aliases = { + "g" => "generate" +} + +command = ARGV.shift +command = aliases[command] || command + +case command +when 'generate' + require 'rails/generators' + + require ENGINE_PATH + engine = ::Rails::Engine.find(ENGINE_ROOT) + engine.load_generators + + require 'rails/commands/generate' + +when '--version', '-v' + ARGV.unshift '--version' + require 'rails/commands/application' + +else + puts "Error: Command not recognized" unless command.in?(['-h', '--help']) + puts <<-EOT +Usage: rails COMMAND [ARGS] + +The common rails commands available for engines are: + generate Generate new code (short-cut alias: "g") + +All commands can be run with -h for more information. + EOT + exit(1) +end diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt b/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt index 65d82abf6d..0d7becad4f 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt +++ b/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt @@ -1,4 +1,7 @@ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. -ENGINE_PATH = File.expand_path('../..', __FILE__) -load File.expand_path('../../<%= dummy_path %>/script/rails', __FILE__) +ENGINE_ROOT = File.expand_path('../..', __FILE__) +ENGINE_PATH = File.expand_path('../../lib/<%= name -%>/engine', __FILE__) + +require 'rails/all' +require 'rails/engine/commands' -- cgit v1.2.3 From 9935c308f14df1eab1e1334dc007bae999dab92f Mon Sep 17 00:00:00 2001 From: Stefan Sprenger Date: Fri, 27 May 2011 08:25:56 +0200 Subject: Fix and test ENGINE_PATH and ENGINE_ROOT --- .../rails/generators/rails/plugin_new/templates/script/rails.tt | 4 ++-- railties/test/generators/plugin_new_generator_test.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt b/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt index 0d7becad4f..aa87d1b50c 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt +++ b/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt @@ -1,7 +1,7 @@ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. -ENGINE_ROOT = File.expand_path('../..', __FILE__) -ENGINE_PATH = File.expand_path('../../lib/<%= name -%>/engine', __FILE__) +ENGINE_ROOT = File.expand_path('../..', __FILE__) +ENGINE_PATH = File.expand_path('../../lib/<%= name -%>/engine', __FILE__) require 'rails/all' require 'rails/engine/commands' diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 32d7c58267..25663ef109 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -177,6 +177,14 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_file "bukkits.gemspec", /s.version = "0.0.1"/ end + def test_usage_of_engine_commands + run_generator + assert_file "script/rails", /ENGINE_PATH = File.expand_path\('..\/..\/lib\/bukkits\/engine', __FILE__\)/ + assert_file "script/rails", /ENGINE_ROOT = File.expand_path\('..\/..', __FILE__\)/ + assert_file "script/rails", /require 'rails\/all'/ + assert_file "script/rails", /require 'rails\/engine\/commands/ + end + def test_shebang run_generator assert_file "script/rails", /#!\/usr\/bin\/env ruby/ -- cgit v1.2.3 From b7476767e608a1835dde5acdb43db2b9c55ce3f8 Mon Sep 17 00:00:00 2001 From: Stefan Sprenger Date: Fri, 27 May 2011 08:46:32 +0200 Subject: Move requiring engine out of the switch case --- railties/lib/rails/engine/commands.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/engine/commands.rb b/railties/lib/rails/engine/commands.rb index 33a7cd5805..b77fef8ffd 100644 --- a/railties/lib/rails/engine/commands.rb +++ b/railties/lib/rails/engine/commands.rb @@ -9,14 +9,13 @@ aliases = { command = ARGV.shift command = aliases[command] || command +require ENGINE_PATH +engine = ::Rails::Engine.find(ENGINE_ROOT) + case command when 'generate' require 'rails/generators' - - require ENGINE_PATH - engine = ::Rails::Engine.find(ENGINE_ROOT) engine.load_generators - require 'rails/commands/generate' when '--version', '-v' -- cgit v1.2.3 From d111de8139b5d44945afb1a4ecd5960fcba6b366 Mon Sep 17 00:00:00 2001 From: Stefan Sprenger Date: Fri, 27 May 2011 11:52:45 +0200 Subject: We're using module not class for namespacing --- railties/test/railties/engine_test.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'railties') diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index b5b21f9ebe..4c1da76c7d 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -15,7 +15,7 @@ module RailtiesTest @plugin = engine "bukkits" do |plugin| plugin.write "lib/bukkits.rb", <<-RUBY - class Bukkits + module Bukkits class Engine < ::Rails::Engine railtie_name "bukkits" end @@ -32,7 +32,7 @@ module RailtiesTest test "initializers are executed after application configuration initializers" do @plugin.write "lib/bukkits.rb", <<-RUBY - class Bukkits + module Bukkits class Engine < ::Rails::Engine initializer "dummy_initializer" do end @@ -73,7 +73,7 @@ module RailtiesTest add_to_config("config.action_dispatch.show_exceptions = false") @plugin.write "lib/bukkits.rb", <<-RUBY - class Bukkits + module Bukkits class Engine < ::Rails::Engine endpoint lambda { |env| [200, {'Content-Type' => 'text/html'}, ['Hello World']] } config.middleware.use ::RailtiesTest::EngineTest::Upcaser @@ -123,7 +123,7 @@ module RailtiesTest test "it provides routes as default endpoint" do @plugin.write "lib/bukkits.rb", <<-RUBY - class Bukkits + module Bukkits class Engine < ::Rails::Engine end end @@ -149,7 +149,7 @@ module RailtiesTest test "engine can load its own plugins" do @plugin.write "lib/bukkits.rb", <<-RUBY - class Bukkits + module Bukkits class Engine < ::Rails::Engine end end @@ -166,7 +166,7 @@ module RailtiesTest test "engine does not load plugins that already exists in application" do @plugin.write "lib/bukkits.rb", <<-RUBY - class Bukkits + module Bukkits class Engine < ::Rails::Engine end end @@ -189,7 +189,7 @@ module RailtiesTest test "it loads its environment file" do @plugin.write "lib/bukkits.rb", <<-RUBY - class Bukkits + module Bukkits class Engine < ::Rails::Engine end end @@ -208,7 +208,7 @@ module RailtiesTest test "it passes router in env" do @plugin.write "lib/bukkits.rb", <<-RUBY - class Bukkits + module Bukkits class Engine < ::Rails::Engine endpoint lambda { |env| [200, {'Content-Type' => 'text/html'}, 'hello'] } end -- cgit v1.2.3 From a0ee2270d3e0bdcc0433e4af56c616f71553378c Mon Sep 17 00:00:00 2001 From: Stefan Sprenger Date: Fri, 27 May 2011 12:12:59 +0200 Subject: Fix appending ' --- railties/test/generators/plugin_new_generator_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 25663ef109..1cb7af150e 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -182,7 +182,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_file "script/rails", /ENGINE_PATH = File.expand_path\('..\/..\/lib\/bukkits\/engine', __FILE__\)/ assert_file "script/rails", /ENGINE_ROOT = File.expand_path\('..\/..', __FILE__\)/ assert_file "script/rails", /require 'rails\/all'/ - assert_file "script/rails", /require 'rails\/engine\/commands/ + assert_file "script/rails", /require 'rails\/engine\/commands'/ end def test_shebang -- cgit v1.2.3 From 5f00592466bd91107ecdfd055140cb2b36e29f50 Mon Sep 17 00:00:00 2001 From: Stefan Sprenger Date: Fri, 27 May 2011 13:25:35 +0200 Subject: Refactor identifying generator's destination root --- railties/lib/rails/commands/generate.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/commands/generate.rb b/railties/lib/rails/commands/generate.rb index 1f742f8853..1fb2d98834 100644 --- a/railties/lib/rails/commands/generate.rb +++ b/railties/lib/rails/commands/generate.rb @@ -8,8 +8,5 @@ end name = ARGV.shift -if defined?(ENGINE_ROOT) - Rails::Generators.invoke name, ARGV, :behavior => :invoke, :destination_root => ENGINE_ROOT -else - Rails::Generators.invoke name, ARGV, :behavior => :invoke, :destination_root => Rails.root -end +root = defined?(ENGINE_ROOT) ? ENGINE_ROOT : Rails.root +Rails::Generators.invoke name, ARGV, :behavior => :invoke, :destination_root => root -- cgit v1.2.3 From e38d3752c377b400aea1d0b854bebf3734664cd7 Mon Sep 17 00:00:00 2001 From: Stefan Sprenger Date: Fri, 27 May 2011 13:44:10 +0200 Subject: Generate script/rails only if --full is given --- .../lib/rails/generators/rails/plugin_new/plugin_new_generator.rb | 2 ++ railties/test/generators/plugin_new_generator_test.rb | 6 +++--- railties/test/generators/shared_generator_tests.rb | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb index 00f90f9498..184fe19c06 100644 --- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb @@ -126,6 +126,8 @@ task :default => :test end def script(force = false) + return unless full? + directory "script", :force => force do |content| "#{shebang}\n" + content end diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 1cb7af150e..e87fd265ce 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -12,7 +12,6 @@ DEFAULT_PLUGIN_FILES = %w( lib lib/bukkits.rb lib/tasks/bukkits_tasks.rake - script/rails test/bukkits_test.rb test/test_helper.rb test/dummy @@ -150,6 +149,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_file "config/routes.rb", /Rails.application.routes.draw do/ assert_file "lib/bukkits/engine.rb", /module Bukkits\n class Engine < ::Rails::Engine\n end\nend/ assert_file "lib/bukkits.rb", /require "bukkits\/engine"/ + assert_file "script/rails" end def test_being_quiet_while_creating_dummy_application @@ -178,7 +178,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase end def test_usage_of_engine_commands - run_generator + run_generator [destination_root, "--full"] assert_file "script/rails", /ENGINE_PATH = File.expand_path\('..\/..\/lib\/bukkits\/engine', __FILE__\)/ assert_file "script/rails", /ENGINE_ROOT = File.expand_path\('..\/..', __FILE__\)/ assert_file "script/rails", /require 'rails\/all'/ @@ -186,7 +186,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase end def test_shebang - run_generator + run_generator [destination_root, "--full"] assert_file "script/rails", /#!\/usr\/bin\/env ruby/ end diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb index be9aef8a41..d3074afd91 100644 --- a/railties/test/generators/shared_generator_tests.rb +++ b/railties/test/generators/shared_generator_tests.rb @@ -67,12 +67,12 @@ module SharedGeneratorTests end def test_shebang_is_added_to_rails_file - run_generator [destination_root, "--ruby", "foo/bar/baz"] + run_generator [destination_root, "--ruby", "foo/bar/baz", "--full"] assert_file "script/rails", /#!foo\/bar\/baz/ end def test_shebang_when_is_the_same_as_default_use_env - run_generator [destination_root, "--ruby", Thor::Util.ruby_command] + run_generator [destination_root, "--ruby", Thor::Util.ruby_command, "--full"] assert_file "script/rails", /#!\/usr\/bin\/env/ end -- cgit v1.2.3 From 0ac5c03f169b3e3055040e84ca088df134c2bfbb Mon Sep 17 00:00:00 2001 From: Stefan Sprenger Date: Fri, 27 May 2011 13:50:42 +0200 Subject: Add destroy to engine's commands --- railties/lib/rails/engine/commands.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/engine/commands.rb b/railties/lib/rails/engine/commands.rb index b77fef8ffd..59b7c4d67f 100644 --- a/railties/lib/rails/engine/commands.rb +++ b/railties/lib/rails/engine/commands.rb @@ -13,10 +13,10 @@ require ENGINE_PATH engine = ::Rails::Engine.find(ENGINE_ROOT) case command -when 'generate' +when 'generate', 'destroy' require 'rails/generators' engine.load_generators - require 'rails/commands/generate' + require "rails/commands/#{command}" when '--version', '-v' ARGV.unshift '--version' @@ -29,6 +29,7 @@ Usage: rails COMMAND [ARGS] The common rails commands available for engines are: generate Generate new code (short-cut alias: "g") + destroy Undo code generated with "generate" All commands can be run with -h for more information. EOT -- cgit v1.2.3 From fd59a3a1d7d81f6a9b54e2f958b78d929f6db9fc Mon Sep 17 00:00:00 2001 From: Stefan Sprenger Date: Fri, 27 May 2011 13:56:39 +0200 Subject: We moved engine commands to rails/engine/commands --- railties/lib/rails/commands.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb index 39627a3094..bf6644c782 100644 --- a/railties/lib/rails/commands.rb +++ b/railties/lib/rails/commands.rb @@ -23,11 +23,7 @@ when 'generate', 'destroy', 'plugin' require APP_PATH Rails.application.require_environment! - if defined?(ENGINE_PATH) && engine = Rails::Engine.find(ENGINE_PATH) - Rails.application.load_generators(engine) - else - Rails.application.load_generators - end + Rails.application.load_generators require "rails/commands/#{command}" end -- cgit v1.2.3 From 32d35bac09a2d9c86d8893384959c7811df50130 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Mon, 6 Jun 2011 17:17:37 +1000 Subject: Add beginnings of test for generators within the context of an engine --- railties/test/engine/generators_test.rb | 54 +++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 railties/test/engine/generators_test.rb (limited to 'railties') diff --git a/railties/test/engine/generators_test.rb b/railties/test/engine/generators_test.rb new file mode 100644 index 0000000000..6b2c83275b --- /dev/null +++ b/railties/test/engine/generators_test.rb @@ -0,0 +1,54 @@ +# require 'isolation/abstract_unit' + +require 'fileutils' + +require 'test/unit' +require 'rubygems' + +# TODO: Remove setting this magic constant +RAILS_FRAMEWORK_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../..") + +# These files do not require any others and are needed +# to run the tests +require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/testing/isolation" +require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/testing/declarative" +require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/core_ext/kernel/reporting" +require "#{RAILS_FRAMEWORK_ROOT}/railties/lib/rails/generators/test_case" + +module EngineTests + class ControllerGenerator < Rails::Generators::TestCase + include ActiveSupport::Testing::Isolation + + TMP_PATH = File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. tmp])) + self.destination_root = File.join(TMP_PATH, "foo_bar") + + def tmp_path(*args) + File.join(TMP_PATH, *args) + end + + def engine_path + tmp_path('foo_bar') + end + + def build_engine + FileUtils.mkdir_p(engine_path) + FileUtils.rm_r(engine_path) + environment = File.expand_path('../../../../load_paths', __FILE__) + if File.exist?("#{environment}.rb") + require_environment = "-r #{environment}" + end + `#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/bin/rails plugin new #{engine_path} --full --mountable` + end + + def setup + build_engine + end + + def test_omg + Dir.chdir(engine_path) do + `rails g controller topics` + assert_file "app/controllers/foo_bar/topics_controller.rb" + end + end + end +end -- cgit v1.2.3 From 77616702df35da2f095dfbaf229b0ae500eaa113 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Mon, 6 Jun 2011 17:23:11 +1000 Subject: Clean up engine generators_test code and add test for models correctly namespaced --- railties/test/engine/generators_test.rb | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'railties') diff --git a/railties/test/engine/generators_test.rb b/railties/test/engine/generators_test.rb index 6b2c83275b..f335c16a8c 100644 --- a/railties/test/engine/generators_test.rb +++ b/railties/test/engine/generators_test.rb @@ -29,26 +29,38 @@ module EngineTests def engine_path tmp_path('foo_bar') end - - def build_engine - FileUtils.mkdir_p(engine_path) - FileUtils.rm_r(engine_path) + + def rails(cmd) environment = File.expand_path('../../../../load_paths', __FILE__) if File.exist?("#{environment}.rb") require_environment = "-r #{environment}" end - `#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/bin/rails plugin new #{engine_path} --full --mountable` + `#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/bin/rails #{cmd}` + end + + def build_engine + FileUtils.mkdir_p(engine_path) + FileUtils.rm_r(engine_path) + + rails("plugin new #{engine_path} --full --mountable") end def setup build_engine end - def test_omg + def test_controllers_are_correctly_namespaced Dir.chdir(engine_path) do - `rails g controller topics` + rails("g controller topics") assert_file "app/controllers/foo_bar/topics_controller.rb" end end + + def test_models_are_correctly_namespaced + Dir.chdir(engine_path) do + rails("g model topic") + assert_file "app/models/foo_bar/topic.rb" + end + end end end -- cgit v1.2.3 From a60624d6c08af9ed7e514ed8b4f87c8915c8bb55 Mon Sep 17 00:00:00 2001 From: Stefan Sprenger Date: Tue, 7 Jun 2011 09:16:15 +0200 Subject: Clean up engine's generator test and use bundle exec for invoking generators --- railties/test/engine/generators_test.rb | 43 +++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 13 deletions(-) (limited to 'railties') diff --git a/railties/test/engine/generators_test.rb b/railties/test/engine/generators_test.rb index f335c16a8c..bda1f0a23b 100644 --- a/railties/test/engine/generators_test.rb +++ b/railties/test/engine/generators_test.rb @@ -1,5 +1,3 @@ -# require 'isolation/abstract_unit' - require 'fileutils' require 'test/unit' @@ -16,20 +14,24 @@ require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/core_ext/kerne require "#{RAILS_FRAMEWORK_ROOT}/railties/lib/rails/generators/test_case" module EngineTests - class ControllerGenerator < Rails::Generators::TestCase + class GeneratorTest < Rails::Generators::TestCase include ActiveSupport::Testing::Isolation - + TMP_PATH = File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. tmp])) self.destination_root = File.join(TMP_PATH, "foo_bar") def tmp_path(*args) File.join(TMP_PATH, *args) end - + def engine_path tmp_path('foo_bar') end + def bundle_exec(cmd) + `bundle exec rails #{cmd}` + end + def rails(cmd) environment = File.expand_path('../../../../load_paths', __FILE__) if File.exist?("#{environment}.rb") @@ -37,29 +39,44 @@ module EngineTests end `#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/bin/rails #{cmd}` end - + def build_engine FileUtils.mkdir_p(engine_path) FileUtils.rm_r(engine_path) - + rails("plugin new #{engine_path} --full --mountable") + + Dir.chdir(engine_path) do + File.open("Gemfile", "w") do |f| + f.write <<-GEMFILE.gsub(/^ {12}/, '') + source "http://rubygems.org" + + gem 'rails', :path => '#{RAILS_FRAMEWORK_ROOT}' + gem 'sqlite3' + + if RUBY_VERSION < '1.9' + gem "ruby-debug", ">= 0.10.3" + end + GEMFILE + end + end end def setup build_engine end - + def test_controllers_are_correctly_namespaced Dir.chdir(engine_path) do - rails("g controller topics") - assert_file "app/controllers/foo_bar/topics_controller.rb" + bundle_exec("g controller topics") + assert_file "app/controllers/foo_bar/topics_controller.rb", /FooBar::TopicsController/ end end - + def test_models_are_correctly_namespaced Dir.chdir(engine_path) do - rails("g model topic") - assert_file "app/models/foo_bar/topic.rb" + bundle_exec("g model topic") + assert_file "app/models/foo_bar/topic.rb", /FooBar::Topic/ end end end -- cgit v1.2.3 From 5afd83c03b8c7ef67b66b828b087221733124e95 Mon Sep 17 00:00:00 2001 From: Stefan Sprenger Date: Tue, 7 Jun 2011 09:31:07 +0200 Subject: Add test for helper generator --- railties/test/engine/generators_test.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/test/engine/generators_test.rb b/railties/test/engine/generators_test.rb index bda1f0a23b..4af315f696 100644 --- a/railties/test/engine/generators_test.rb +++ b/railties/test/engine/generators_test.rb @@ -28,7 +28,7 @@ module EngineTests tmp_path('foo_bar') end - def bundle_exec(cmd) + def bundled_rails(cmd) `bundle exec rails #{cmd}` end @@ -68,16 +68,23 @@ module EngineTests def test_controllers_are_correctly_namespaced Dir.chdir(engine_path) do - bundle_exec("g controller topics") + bundled_rails("g controller topics") assert_file "app/controllers/foo_bar/topics_controller.rb", /FooBar::TopicsController/ end end def test_models_are_correctly_namespaced Dir.chdir(engine_path) do - bundle_exec("g model topic") + bundled_rails("g model topic") assert_file "app/models/foo_bar/topic.rb", /FooBar::Topic/ end end + + def test_helpers_are_correctly_namespaced + Dir.chdir(engine_path) do + bundled_rails("g helper topics") + assert_file "app/helpers/foo_bar/topics_helper.rb", /FooBar::TopicsHelper/ + end + end end end -- cgit v1.2.3 From 402163916b0d65c33208f3ebf1a488dce93d7ad3 Mon Sep 17 00:00:00 2001 From: Stefan Sprenger Date: Tue, 7 Jun 2011 09:33:17 +0200 Subject: Move test/engine/generators_test.rb to test/railties/generators_test.rb --- railties/test/engine/generators_test.rb | 90 ------------------------------- railties/test/railties/generators_test.rb | 90 +++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 90 deletions(-) delete mode 100644 railties/test/engine/generators_test.rb create mode 100644 railties/test/railties/generators_test.rb (limited to 'railties') diff --git a/railties/test/engine/generators_test.rb b/railties/test/engine/generators_test.rb deleted file mode 100644 index 4af315f696..0000000000 --- a/railties/test/engine/generators_test.rb +++ /dev/null @@ -1,90 +0,0 @@ -require 'fileutils' - -require 'test/unit' -require 'rubygems' - -# TODO: Remove setting this magic constant -RAILS_FRAMEWORK_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../..") - -# These files do not require any others and are needed -# to run the tests -require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/testing/isolation" -require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/testing/declarative" -require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/core_ext/kernel/reporting" -require "#{RAILS_FRAMEWORK_ROOT}/railties/lib/rails/generators/test_case" - -module EngineTests - class GeneratorTest < Rails::Generators::TestCase - include ActiveSupport::Testing::Isolation - - TMP_PATH = File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. tmp])) - self.destination_root = File.join(TMP_PATH, "foo_bar") - - def tmp_path(*args) - File.join(TMP_PATH, *args) - end - - def engine_path - tmp_path('foo_bar') - end - - def bundled_rails(cmd) - `bundle exec rails #{cmd}` - end - - def rails(cmd) - environment = File.expand_path('../../../../load_paths', __FILE__) - if File.exist?("#{environment}.rb") - require_environment = "-r #{environment}" - end - `#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/bin/rails #{cmd}` - end - - def build_engine - FileUtils.mkdir_p(engine_path) - FileUtils.rm_r(engine_path) - - rails("plugin new #{engine_path} --full --mountable") - - Dir.chdir(engine_path) do - File.open("Gemfile", "w") do |f| - f.write <<-GEMFILE.gsub(/^ {12}/, '') - source "http://rubygems.org" - - gem 'rails', :path => '#{RAILS_FRAMEWORK_ROOT}' - gem 'sqlite3' - - if RUBY_VERSION < '1.9' - gem "ruby-debug", ">= 0.10.3" - end - GEMFILE - end - end - end - - def setup - build_engine - end - - def test_controllers_are_correctly_namespaced - Dir.chdir(engine_path) do - bundled_rails("g controller topics") - assert_file "app/controllers/foo_bar/topics_controller.rb", /FooBar::TopicsController/ - end - end - - def test_models_are_correctly_namespaced - Dir.chdir(engine_path) do - bundled_rails("g model topic") - assert_file "app/models/foo_bar/topic.rb", /FooBar::Topic/ - end - end - - def test_helpers_are_correctly_namespaced - Dir.chdir(engine_path) do - bundled_rails("g helper topics") - assert_file "app/helpers/foo_bar/topics_helper.rb", /FooBar::TopicsHelper/ - end - end - end -end diff --git a/railties/test/railties/generators_test.rb b/railties/test/railties/generators_test.rb new file mode 100644 index 0000000000..e32970c2e5 --- /dev/null +++ b/railties/test/railties/generators_test.rb @@ -0,0 +1,90 @@ +require 'fileutils' + +require 'test/unit' +require 'rubygems' + +# TODO: Remove setting this magic constant +RAILS_FRAMEWORK_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../..") + +# These files do not require any others and are needed +# to run the tests +require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/testing/isolation" +require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/testing/declarative" +require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/core_ext/kernel/reporting" +require "#{RAILS_FRAMEWORK_ROOT}/railties/lib/rails/generators/test_case" + +module RailtiesTests + class GeneratorTest < Rails::Generators::TestCase + include ActiveSupport::Testing::Isolation + + TMP_PATH = File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. tmp])) + self.destination_root = File.join(TMP_PATH, "foo_bar") + + def tmp_path(*args) + File.join(TMP_PATH, *args) + end + + def engine_path + tmp_path('foo_bar') + end + + def bundled_rails(cmd) + `bundle exec rails #{cmd}` + end + + def rails(cmd) + environment = File.expand_path('../../../../load_paths', __FILE__) + if File.exist?("#{environment}.rb") + require_environment = "-r #{environment}" + end + `#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/bin/rails #{cmd}` + end + + def build_engine + FileUtils.mkdir_p(engine_path) + FileUtils.rm_r(engine_path) + + rails("plugin new #{engine_path} --full --mountable") + + Dir.chdir(engine_path) do + File.open("Gemfile", "w") do |f| + f.write <<-GEMFILE.gsub(/^ {12}/, '') + source "http://rubygems.org" + + gem 'rails', :path => '#{RAILS_FRAMEWORK_ROOT}' + gem 'sqlite3' + + if RUBY_VERSION < '1.9' + gem "ruby-debug", ">= 0.10.3" + end + GEMFILE + end + end + end + + def setup + build_engine + end + + def test_controllers_are_correctly_namespaced + Dir.chdir(engine_path) do + bundled_rails("g controller topics") + assert_file "app/controllers/foo_bar/topics_controller.rb", /FooBar::TopicsController/ + end + end + + def test_models_are_correctly_namespaced + Dir.chdir(engine_path) do + bundled_rails("g model topic") + assert_file "app/models/foo_bar/topic.rb", /FooBar::Topic/ + end + end + + def test_helpers_are_correctly_namespaced + Dir.chdir(engine_path) do + bundled_rails("g helper topics") + assert_file "app/helpers/foo_bar/topics_helper.rb", /FooBar::TopicsHelper/ + end + end + end +end -- cgit v1.2.3 From 1a06530aa50e1aed5c7dff6f1256abb555c497b6 Mon Sep 17 00:00:00 2001 From: Stefan Sprenger Date: Tue, 7 Jun 2011 10:23:45 +0200 Subject: Added regression tests --- railties/test/railties/generators_test.rb | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'railties') diff --git a/railties/test/railties/generators_test.rb b/railties/test/railties/generators_test.rb index e32970c2e5..69ba03673e 100644 --- a/railties/test/railties/generators_test.rb +++ b/railties/test/railties/generators_test.rb @@ -1,16 +1,6 @@ -require 'fileutils' +RAILS_ISOLATION_COMMAND = "engine" +require "isolation/abstract_unit" -require 'test/unit' -require 'rubygems' - -# TODO: Remove setting this magic constant -RAILS_FRAMEWORK_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../..") - -# These files do not require any others and are needed -# to run the tests -require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/testing/isolation" -require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/testing/declarative" -require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/core_ext/kernel/reporting" require "#{RAILS_FRAMEWORK_ROOT}/railties/lib/rails/generators/test_case" module RailtiesTests @@ -70,6 +60,7 @@ module RailtiesTests Dir.chdir(engine_path) do bundled_rails("g controller topics") assert_file "app/controllers/foo_bar/topics_controller.rb", /FooBar::TopicsController/ + assert_no_file "app/controllers/topics_controller.rb" end end @@ -77,6 +68,7 @@ module RailtiesTests Dir.chdir(engine_path) do bundled_rails("g model topic") assert_file "app/models/foo_bar/topic.rb", /FooBar::Topic/ + assert_no_file "app/models/topic.rb" end end @@ -84,6 +76,7 @@ module RailtiesTests Dir.chdir(engine_path) do bundled_rails("g helper topics") assert_file "app/helpers/foo_bar/topics_helper.rb", /FooBar::TopicsHelper/ + assert_no_file "app/helpers/topics_helper.rb" end end end -- cgit v1.2.3 From f18283194bfb43fc020be37d6fa7cd3149fa8b5e Mon Sep 17 00:00:00 2001 From: Stefan Sprenger Date: Tue, 7 Jun 2011 11:21:38 +0200 Subject: Use namespace if it's a mountable engine --- railties/lib/rails/engine/commands.rb | 1 + railties/lib/rails/generators.rb | 10 ++++++ railties/lib/rails/generators/named_base.rb | 4 +-- railties/lib/rails/railtie.rb | 5 +++ railties/test/railties/generators_test.rb | 53 ++++++++++++++++++++++++----- 5 files changed, 61 insertions(+), 12 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/engine/commands.rb b/railties/lib/rails/engine/commands.rb index 59b7c4d67f..3b0920e213 100644 --- a/railties/lib/rails/engine/commands.rb +++ b/railties/lib/rails/engine/commands.rb @@ -15,6 +15,7 @@ engine = ::Rails::Engine.find(ENGINE_ROOT) case command when 'generate', 'destroy' require 'rails/generators' + Rails::Generators.namespace = engine.railtie_namespace engine.load_generators require "rails/commands/#{command}" diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 09e505a75b..508d5359ba 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -90,6 +90,16 @@ module Rails @options ||= DEFAULT_OPTIONS.dup end + def self.namespace + @namespace ||= if defined?(Rails) && Rails.application + Rails.application.class.parents.detect { |n| n.respond_to?(:_railtie) } + end + end + + def self.namespace=(namespace) + @namespace ||= namespace + end + # Hold configured generators fallbacks. If a plugin developer wants a # generator group to fallback to another group in case of missing generators, # they can add a fallback. diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index 7e7f8d2d08..c6c0392f43 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -63,9 +63,7 @@ module Rails end def namespace - @namespace ||= if defined?(Rails) && Rails.application - Rails.application.class.parents.detect { |n| n.respond_to?(:_railtie) } - end + Rails::Generators.namespace end def namespaced? diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index 65c567d72f..5f50943626 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -1,6 +1,7 @@ require 'rails/initializable' require 'rails/configuration' require 'active_support/inflector' +require 'active_support/core_ext/module/introspection' module Rails # Railtie is the core of the Rails framework and provides several hooks to extend @@ -192,5 +193,9 @@ module Rails def load_generators(app) self.class.generators.each { |block| block.call(app) } end + + def railtie_namespace + @railtie_namespace ||= self.class.parents.detect { |n| n.respond_to?(:_railtie) } + end end end diff --git a/railties/test/railties/generators_test.rb b/railties/test/railties/generators_test.rb index 69ba03673e..4f96e4d9ef 100644 --- a/railties/test/railties/generators_test.rb +++ b/railties/test/railties/generators_test.rb @@ -30,11 +30,13 @@ module RailtiesTests `#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/bin/rails #{cmd}` end - def build_engine + def build_engine(is_mountable=false) FileUtils.mkdir_p(engine_path) FileUtils.rm_r(engine_path) - rails("plugin new #{engine_path} --full --mountable") + mountable = is_mountable ? "--mountable" : "" + + rails("plugin new #{engine_path} --full #{mountable}") Dir.chdir(engine_path) do File.open("Gemfile", "w") do |f| @@ -52,32 +54,65 @@ module RailtiesTests end end + def build_mountable_engine + build_engine(true) + end + def setup - build_engine end - def test_controllers_are_correctly_namespaced + def test_controllers_are_correctly_namespaced_when_engine_is_mountable + build_mountable_engine Dir.chdir(engine_path) do bundled_rails("g controller topics") - assert_file "app/controllers/foo_bar/topics_controller.rb", /FooBar::TopicsController/ + assert_file "app/controllers/foo_bar/topics_controller.rb", /module FooBar\n class TopicsController/ assert_no_file "app/controllers/topics_controller.rb" end end - def test_models_are_correctly_namespaced + def test_models_are_correctly_namespaced_when_engine_is_mountable + build_mountable_engine Dir.chdir(engine_path) do bundled_rails("g model topic") - assert_file "app/models/foo_bar/topic.rb", /FooBar::Topic/ + assert_file "app/models/foo_bar/topic.rb", /module FooBar\n class Topic/ assert_no_file "app/models/topic.rb" end end - def test_helpers_are_correctly_namespaced + def test_helpers_are_correctly_namespaced_when_engine_is_mountable + build_mountable_engine Dir.chdir(engine_path) do bundled_rails("g helper topics") - assert_file "app/helpers/foo_bar/topics_helper.rb", /FooBar::TopicsHelper/ + assert_file "app/helpers/foo_bar/topics_helper.rb", /module FooBar\n module TopicsHelper/ assert_no_file "app/helpers/topics_helper.rb" end end + + def test_controllers_are_not_namespaced_when_engine_is_not_mountable + build_engine + Dir.chdir(engine_path) do + bundled_rails("g controller topics") + assert_file "app/controllers/topics_controller.rb", /class TopicsController/ + assert_no_file "app/controllers/foo_bar/topics_controller.rb" + end + end + + def test_models_are_not_namespaced_when_engine_is_not_mountable + build_engine + Dir.chdir(engine_path) do + bundled_rails("g model topic") + assert_file "app/models/topic.rb", /class Topic/ + assert_no_file "app/models/foo_bar/topic.rb" + end + end + + def test_helpers_are_not_namespaced_when_engine_is_not_mountable + build_engine + Dir.chdir(engine_path) do + bundled_rails("g helper topics") + assert_file "app/helpers/topics_helper.rb", /module TopicsHelper/ + assert_no_file "app/helpers/foo_bar/topics_helper.rb" + end + end end end -- cgit v1.2.3 From 64f337eeb0072616520c8ec7f40e2fdd5b90f26e Mon Sep 17 00:00:00 2001 From: Stefan Sprenger Date: Tue, 7 Jun 2011 11:26:38 +0200 Subject: Don't create full Rails application if RAILS_ISOLATION_COMMAND equals engine --- railties/test/isolation/abstract_unit.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index 69208ce4c3..a13da12ae1 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -280,4 +280,4 @@ Module.new do end f.puts "require 'rails/all'" end -end +end unless RAILS_ISOLATION_COMMAND=="engine" -- cgit v1.2.3 From 8ea90ffdb8a08438e72054518f8f0b54c628b3ea Mon Sep 17 00:00:00 2001 From: Stefan Sprenger Date: Tue, 7 Jun 2011 11:36:11 +0200 Subject: Use mattr_accessor :namespace --- railties/lib/rails/generators.rb | 12 ++---------- railties/test/railties/generators_test.rb | 3 --- 2 files changed, 2 insertions(+), 13 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 508d5359ba..355b05ce0b 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -20,6 +20,8 @@ module Rails autoload :ResourceHelpers, 'rails/generators/resource_helpers' autoload :TestCase, 'rails/generators/test_case' + mattr_accessor :namespace + DEFAULT_ALIASES = { :rails => { :actions => '-a', @@ -90,16 +92,6 @@ module Rails @options ||= DEFAULT_OPTIONS.dup end - def self.namespace - @namespace ||= if defined?(Rails) && Rails.application - Rails.application.class.parents.detect { |n| n.respond_to?(:_railtie) } - end - end - - def self.namespace=(namespace) - @namespace ||= namespace - end - # Hold configured generators fallbacks. If a plugin developer wants a # generator group to fallback to another group in case of missing generators, # they can add a fallback. diff --git a/railties/test/railties/generators_test.rb b/railties/test/railties/generators_test.rb index 4f96e4d9ef..963518880d 100644 --- a/railties/test/railties/generators_test.rb +++ b/railties/test/railties/generators_test.rb @@ -58,9 +58,6 @@ module RailtiesTests build_engine(true) end - def setup - end - def test_controllers_are_correctly_namespaced_when_engine_is_mountable build_mountable_engine Dir.chdir(engine_path) do -- cgit v1.2.3 From 246c36757065aa74a88b67db4c70e9e5cf3bd8b3 Mon Sep 17 00:00:00 2001 From: Stefan Sprenger Date: Tue, 7 Jun 2011 12:16:05 +0200 Subject: Use RAILS_ISOLATED_ENGINE and fix namespaced generators tests --- railties/test/abstract_unit.rb | 1 - railties/test/generators/namespaced_generators_test.rb | 10 +--------- railties/test/isolation/abstract_unit.rb | 2 +- railties/test/railties/generators_test.rb | 2 +- 4 files changed, 3 insertions(+), 12 deletions(-) (limited to 'railties') diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index 8b38081667..1c3f8a701a 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -10,7 +10,6 @@ require 'active_support/core_ext/logger' require 'action_controller' require 'rails/all' -# TODO: Remove these hacks module TestApp class Application < Rails::Application config.root = File.dirname(__FILE__) diff --git a/railties/test/generators/namespaced_generators_test.rb b/railties/test/generators/namespaced_generators_test.rb index 17cbac0912..dd1e4bdac1 100644 --- a/railties/test/generators/namespaced_generators_test.rb +++ b/railties/test/generators/namespaced_generators_test.rb @@ -7,15 +7,7 @@ require 'rails/generators/rails/scaffold/scaffold_generator' class NamespacedGeneratorTestCase < Rails::Generators::TestCase def setup - TestApp::Application.isolate_namespace(TestApp) - end - - def teardown - if TestApp.respond_to?(:_railtie) - TestApp.singleton_class.send(:undef_method, :_railtie) - TestApp.singleton_class.send(:undef_method, :table_name_prefix) - TestApp::Application.isolated = false - end + Rails::Generators.namespace = TestApp end end diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index a13da12ae1..53d3f288d9 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -280,4 +280,4 @@ Module.new do end f.puts "require 'rails/all'" end -end unless RAILS_ISOLATION_COMMAND=="engine" +end unless defined?(RAILS_ISOLATED_ENGINE) diff --git a/railties/test/railties/generators_test.rb b/railties/test/railties/generators_test.rb index 963518880d..fe59dcd52b 100644 --- a/railties/test/railties/generators_test.rb +++ b/railties/test/railties/generators_test.rb @@ -1,4 +1,4 @@ -RAILS_ISOLATION_COMMAND = "engine" +RAILS_ISOLATED_ENGINE = true require "isolation/abstract_unit" require "#{RAILS_FRAMEWORK_ROOT}/railties/lib/rails/generators/test_case" -- cgit v1.2.3 From 331d58fb04821546b1e622290432a2dd13e52301 Mon Sep 17 00:00:00 2001 From: Stefan Sprenger Date: Tue, 7 Jun 2011 14:07:32 +0200 Subject: Prepend bundle exec to get the correct Rake version --- railties/test/railties/shared_tests.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/test/railties/shared_tests.rb b/railties/test/railties/shared_tests.rb index 659551d08a..d8ea58166e 100644 --- a/railties/test/railties/shared_tests.rb +++ b/railties/test/railties/shared_tests.rb @@ -54,7 +54,7 @@ module RailtiesTest add_to_config "ActiveRecord::Base.timestamped_migrations = false" Dir.chdir(app_path) do - output = `rake bukkits:install:migrations` + output = `bundle exec rake bukkits:install:migrations` assert File.exists?("#{app_path}/db/migrate/2_create_users.rb") assert File.exists?("#{app_path}/db/migrate/3_add_last_name_to_users.rb") @@ -63,7 +63,7 @@ module RailtiesTest assert_match /NOTE: Migration 3_create_sessions.rb from bukkits has been skipped/, output assert_equal 3, Dir["#{app_path}/db/migrate/*.rb"].length - output = `rake railties:install:migrations` + output = `bundle exec rake railties:install:migrations` assert File.exists?("#{app_path}/db/migrate/4_create_yaffles.rb") assert_match /NOTE: Migration 3_create_sessions.rb from bukkits has been skipped/, output @@ -71,7 +71,7 @@ module RailtiesTest assert_no_match /2_create_users/, output migrations_count = Dir["#{app_path}/db/migrate/*.rb"].length - output = `rake railties:install:migrations` + output = `bundle exec rake railties:install:migrations` assert_equal migrations_count, Dir["#{app_path}/db/migrate/*.rb"].length end -- cgit v1.2.3