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
This commit is contained in:
commit
939d5a4932
|
@ -1,3 +1,7 @@
|
|||
* 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 @@ 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
|
||||
|
|
|
@ -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)
|
||||
"%s_%s" % [namespaced_path, table_name]
|
||||
else
|
||||
table_name
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def attributes_hash
|
||||
|
|
|
@ -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 defined?(ENGINE_ROOT) -%>
|
||||
@routes = Engine.routes
|
||||
<% end -%>
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue