提交 939d5a49 编写于 作者: Y Yves Senn

Merge pull request #20387 from y-yagi/fix_engine_generated_controller_test

set engine's route in the functional test is generated in the engine
* Make generated scaffold functional tests work inside engines.
*Yuji Yaginuma*
* Generator a `.keep` file in the `tmp` folder by default as many scripts
assume the existence of this folder and most would fail if it is absent.
......
......@@ -2,6 +2,12 @@
<% 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
......
......@@ -15,6 +15,15 @@ def create_test_files
File.join("test/controllers", controller_class_path, "#{controller_file_name}_controller_test.rb")
end
def fixture_name
@fixture_name ||=
if defined?(ENGINE_ROOT)
"%s_%s" % [namespaced_path, table_name]
else
table_name
end
end
private
def attributes_hash
......
......@@ -3,7 +3,10 @@
<% 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 -%>
end
test "should get index" do
......
......@@ -174,4 +174,15 @@ def test_model_name_option
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
......@@ -393,4 +393,18 @@ def test_scaffold_generator_password_digest
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册