mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
make generated controller test work correctly
Since the `#file_name` that not consideration for the namespace, if generate a controller with a namespace, not the correct url helper generation, it had become an error to run the test. Modified to generate the correct url helper, even if it is produced a namespace with controller.
This commit is contained in:
parent
333aab3d51
commit
229064cf3a
3 changed files with 14 additions and 1 deletions
|
@ -161,6 +161,10 @@ module Rails
|
||||||
@route_url ||= class_path.collect {|dname| "/" + dname }.join + "/" + plural_file_name
|
@route_url ||= class_path.collect {|dname| "/" + dname }.join + "/" + plural_file_name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def url_helper_prefix
|
||||||
|
@url_helper_prefix ||= (class_path + [file_name]).join('_')
|
||||||
|
end
|
||||||
|
|
||||||
# Tries to retrieve the application name or simply return application.
|
# Tries to retrieve the application name or simply return application.
|
||||||
def application_name
|
def application_name
|
||||||
if defined?(Rails) && Rails.application
|
if defined?(Rails) && Rails.application
|
||||||
|
|
|
@ -13,7 +13,7 @@ class <%= class_name %>ControllerTest < ActionDispatch::IntegrationTest
|
||||||
<% else -%>
|
<% else -%>
|
||||||
<% actions.each do |action| -%>
|
<% actions.each do |action| -%>
|
||||||
test "should get <%= action %>" do
|
test "should get <%= action %>" do
|
||||||
get <%= file_name %>_<%= action %>_url
|
get <%= url_helper_prefix %>_<%= action %>_url
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -234,6 +234,11 @@ module ApplicationTests
|
||||||
assert_match "0 failures, 0 errors, 0 skips", run_test_command('')
|
assert_match "0 failures, 0 errors, 0 skips", run_test_command('')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_generated_controller_works_with_rails_test
|
||||||
|
create_controller
|
||||||
|
assert_match "0 failures, 0 errors, 0 skips", run_test_command('')
|
||||||
|
end
|
||||||
|
|
||||||
def test_run_multiple_folders
|
def test_run_multiple_folders
|
||||||
create_test_file :models, 'account'
|
create_test_file :models, 'account'
|
||||||
create_test_file :controllers, 'accounts_controller'
|
create_test_file :controllers, 'accounts_controller'
|
||||||
|
@ -449,6 +454,10 @@ module ApplicationTests
|
||||||
run_migration
|
run_migration
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_controller
|
||||||
|
script 'generate controller admin/dashboard index'
|
||||||
|
end
|
||||||
|
|
||||||
def run_migration
|
def run_migration
|
||||||
Dir.chdir(app_path) { `bin/rake db:migrate` }
|
Dir.chdir(app_path) { `bin/rake db:migrate` }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue