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