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/test') 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 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 --- railties/test/generators/plugin_new_generator_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'railties/test') 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 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/test') 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/test') 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 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 --- railties/test/generators/plugin_new_generator_test.rb | 6 +++--- railties/test/generators/shared_generator_tests.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'railties/test') 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 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/test') 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/test') 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/test') 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/test') 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/test') 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/test') 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/test/railties/generators_test.rb | 53 +++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 9 deletions(-) (limited to 'railties/test') 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/test') 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/test/railties/generators_test.rb | 3 --- 1 file changed, 3 deletions(-) (limited to 'railties/test') 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/test') 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/test') 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