diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-08-09 23:50:27 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-08-09 23:50:27 -0300 |
commit | 6e6cfb665af0ffc1283efa40f14615e1f3917c16 (patch) | |
tree | ebdf8a9cfe14871b326746ad551be7575b110c6b | |
parent | 8d0c107a60a5f240c7a6e9caee4ad10cff8fe63e (diff) | |
parent | 22d863d272eea25eaa391c07532e4f1279c46721 (diff) | |
download | rails-6e6cfb665af0ffc1283efa40f14615e1f3917c16.tar.gz rails-6e6cfb665af0ffc1283efa40f14615e1f3917c16.tar.bz2 rails-6e6cfb665af0ffc1283efa40f14615e1f3917c16.zip |
Merge pull request #21176 from y-yagi/fix_scaffold_tests_inside_api_engine
make generated scaffold functional tests work inside API engines
-rw-r--r-- | railties/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb | 5 | ||||
-rw-r--r-- | railties/test/generators/scaffold_generator_test.rb | 28 |
2 files changed, 32 insertions, 1 deletions
diff --git a/railties/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb b/railties/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb index 896b38bc8f..f302cd6c3d 100644 --- a/railties/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb +++ b/railties/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb @@ -3,7 +3,10 @@ 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 mountable_engine? -%> + @routes = Engine.routes +<% end -%> end test "should get index" do diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index a853bfbe21..0c3808a9a0 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -505,4 +505,32 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_match(/8 runs, 13 assertions, 0 failures, 0 errors/, `bin/rails test 2>&1`) end end + + def test_scaffold_tests_pass_by_default_inside_api_mountable_engine + Dir.chdir(destination_root) { `bundle exec rails plugin new bukkits --mountable --api` } + + 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(/6 runs, 8 assertions, 0 failures, 0 errors/, `bin/rails test 2>&1`) + end + end + + def test_scaffold_tests_pass_by_default_inside_api_full_engine + Dir.chdir(destination_root) { `bundle exec rails plugin new bukkits --full --api` } + + 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(/6 runs, 8 assertions, 0 failures, 0 errors/, `bin/rails test 2>&1`) + end + end end |