From 6a8d91897bae19f5d30f51a2731d9bbf7f41ac2e Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Tue, 5 May 2015 22:40:16 +0900 Subject: set engine's route in the functional test is generated in the engine --- .../test_unit/controller/templates/functional_test.rb | 6 ++++++ .../test_unit/scaffold/templates/functional_test.rb | 3 +++ railties/test/generators/plugin_generator_test.rb | 15 +++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/railties/lib/rails/generators/test_unit/controller/templates/functional_test.rb b/railties/lib/rails/generators/test_unit/controller/templates/functional_test.rb index 509bd60564..7106096b60 100644 --- a/railties/lib/rails/generators/test_unit/controller/templates/functional_test.rb +++ b/railties/lib/rails/generators/test_unit/controller/templates/functional_test.rb @@ -2,6 +2,12 @@ require 'test_helper' <% module_namespacing do -%> class <%= class_name %>ControllerTest < ActionController::TestCase +<% if defined?(ENGINE_ROOT) -%> + setup do + @routes = Engine.routes + end + +<% end -%> <% if actions.empty? -%> # test "the truth" do # assert true diff --git a/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb b/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb index 76313575e9..d2799994f1 100644 --- a/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +++ b/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb @@ -4,6 +4,9 @@ require 'test_helper' class <%= controller_class_name %>ControllerTest < ActionController::TestCase setup do @<%= singular_table_name %> = <%= table_name %>(:one) +<% if defined?(ENGINE_ROOT) -%> + @routes = Engine.routes +<% end -%> end test "should get index" do diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index d6e5f4bd89..0716783d42 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -508,6 +508,21 @@ class PluginGeneratorTest < Rails::Generators::TestCase assert_match(/namespace :admin/, contents) assert_no_match(/namespace :bukkit/, contents) end + assert_file "test/controllers/bukkits/admin/dashboard_controller_test.rb" do |contents| + assert_match(/@routes = Engine.routes/, contents) + end + end + + def test_generating_scaffold_controller_inside_mountable_engine + run_generator [destination_root, "--mountable"] + + capture(:stdout) do + `#{destination_root}/bin/rails g scaffold User name:string age:integer` + end + + assert_file "test/controllers/bukkits/users_controller_test.rb" do |contents| + assert_match(/@routes = Engine.routes/, contents) + end end def test_git_name_and_email_in_gemspec_file -- cgit v1.2.3 From c861ef283fb94576a4025e4eb8d62808034ab2ee Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sun, 31 May 2015 21:28:51 +0900 Subject: add engine's namespace to fixture name --- .../rails/generators/test_unit/scaffold/scaffold_generator.rb | 9 +++++++++ .../generators/test_unit/scaffold/templates/functional_test.rb | 2 +- railties/test/generators/plugin_generator_test.rb | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb index 2e1f55f2a6..a3beebbfd5 100644 --- a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb @@ -15,6 +15,15 @@ module TestUnit # :nodoc: File.join("test/controllers", controller_class_path, "#{controller_file_name}_controller_test.rb") end + def fixture_name + @fixture_name ||= + if defined?(ENGINE_ROOT) + namespaced_path + "_" + table_name + else + table_name + end + end + private def attributes_hash diff --git a/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb b/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb index d2799994f1..d12a5ba733 100644 --- a/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +++ b/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb @@ -3,7 +3,7 @@ require 'test_helper' <% module_namespacing do -%> class <%= controller_class_name %>ControllerTest < ActionController::TestCase setup do - @<%= singular_table_name %> = <%= table_name %>(:one) + @<%= singular_table_name %> = <%= fixture_name %>(:one) <% if defined?(ENGINE_ROOT) -%> @routes = Engine.routes <% end -%> diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index 0716783d42..57da8ab268 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -521,6 +521,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase end assert_file "test/controllers/bukkits/users_controller_test.rb" do |contents| + assert_match(/@user = bukkits_users\(:one\)/, contents) assert_match(/@routes = Engine.routes/, contents) end end -- cgit v1.2.3 From 36127934751d61e08d0858db97e7a35aa6417f79 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sun, 31 May 2015 21:41:47 +0900 Subject: add test to run generated test files inside mountable engine --- railties/test/generators/plugin_generator_test.rb | 16 ---------------- .../generators/scaffold_controller_generator_test.rb | 11 +++++++++++ railties/test/generators/scaffold_generator_test.rb | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index 57da8ab268..d6e5f4bd89 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -508,22 +508,6 @@ class PluginGeneratorTest < Rails::Generators::TestCase assert_match(/namespace :admin/, contents) assert_no_match(/namespace :bukkit/, contents) end - assert_file "test/controllers/bukkits/admin/dashboard_controller_test.rb" do |contents| - assert_match(/@routes = Engine.routes/, contents) - end - end - - def test_generating_scaffold_controller_inside_mountable_engine - run_generator [destination_root, "--mountable"] - - capture(:stdout) do - `#{destination_root}/bin/rails g scaffold User name:string age:integer` - end - - assert_file "test/controllers/bukkits/users_controller_test.rb" do |contents| - assert_match(/@user = bukkits_users\(:one\)/, contents) - assert_match(/@routes = Engine.routes/, contents) - end end def test_git_name_and_email_in_gemspec_file diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb index 34e752cea1..7c282377d7 100644 --- a/railties/test/generators/scaffold_controller_generator_test.rb +++ b/railties/test/generators/scaffold_controller_generator_test.rb @@ -174,4 +174,15 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase end end end + + def test_controller_tests_pass_by_default_inside_mountable_engine + Dir.chdir(destination_root) { `bundle exec rails plugin new bukkits --mountable` } + + engine_path = File.join(destination_root, "bukkits") + + Dir.chdir(engine_path) do + quietly { `bin/rails g controller dashboard foo` } + assert_match(/2 runs, 2 assertions, 0 failures, 0 errors/, `bundle exec rake test 2>&1`) + end + end end diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index ee06802874..8f43747b9e 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -393,4 +393,18 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_match(/password_digest: <%= BCrypt::Password.create\('secret'\) %>/, content) end end + + def test_scaffold_tests_pass_by_default_inside_mountable_engine + Dir.chdir(destination_root) { `bundle exec rails plugin new bukkits --mountable` } + + engine_path = File.join(destination_root, "bukkits") + + Dir.chdir(engine_path) do + quietly do + `bin/rails g scaffold User name:string age:integer; + bundle exec rake db:migrate` + end + assert_match(/8 runs, 13 assertions, 0 failures, 0 errors/, `bundle exec rake test 2>&1`) + end + end end -- cgit v1.2.3