mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge branch 'remove-test-case'
This commit is contained in:
commit
89f776402d
9 changed files with 64 additions and 52 deletions
|
@ -129,6 +129,18 @@ module Rails
|
|||
uncountable? ? "#{plural_table_name}_index" : plural_table_name
|
||||
end
|
||||
|
||||
def show_helper
|
||||
"#{singular_table_name}_url(@#{singular_table_name})"
|
||||
end
|
||||
|
||||
def edit_helper
|
||||
"edit_#{show_helper}"
|
||||
end
|
||||
|
||||
def new_helper
|
||||
"new_#{singular_table_name}_url"
|
||||
end
|
||||
|
||||
def singular_table_name
|
||||
@singular_table_name ||= (pluralize_table_names? ? table_name.singularize : table_name)
|
||||
end
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
require 'test_helper'
|
||||
|
||||
<% module_namespacing do -%>
|
||||
class <%= class_name %>ControllerTest < ActionController::TestCase
|
||||
class <%= class_name %>ControllerTest < ActionDispatch::IntegrationTest
|
||||
<% if mountable_engine? -%>
|
||||
setup do
|
||||
@routes = Engine.routes
|
||||
end
|
||||
include Engine.routes.url_helpers
|
||||
|
||||
<% end -%>
|
||||
<% if actions.empty? -%>
|
||||
|
@ -15,7 +13,7 @@ class <%= class_name %>ControllerTest < ActionController::TestCase
|
|||
<% else -%>
|
||||
<% actions.each do |action| -%>
|
||||
test "should get <%= action %>" do
|
||||
get :<%= action %>
|
||||
get <%= file_name %>_<%= action %>_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
|
|
|
@ -1,40 +1,41 @@
|
|||
require 'test_helper'
|
||||
|
||||
<% module_namespacing do -%>
|
||||
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
||||
class <%= controller_class_name %>ControllerTest < ActionDispatch::IntegrationTest
|
||||
<% if mountable_engine? -%>
|
||||
include Engine.routes.url_helpers
|
||||
|
||||
<% end -%>
|
||||
setup do
|
||||
@<%= singular_table_name %> = <%= fixture_name %>(:one)
|
||||
<% if mountable_engine? -%>
|
||||
@routes = Engine.routes
|
||||
<% end -%>
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
get :index
|
||||
get <%= index_helper %>_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create <%= singular_table_name %>" do
|
||||
assert_difference('<%= class_name %>.count') do
|
||||
post :create, params: { <%= "#{singular_table_name}: { #{attributes_hash} }" %> }
|
||||
post <%= index_helper %>_url, params: { <%= "#{singular_table_name}: { #{attributes_hash} }" %> }
|
||||
end
|
||||
|
||||
assert_response 201
|
||||
end
|
||||
|
||||
test "should show <%= singular_table_name %>" do
|
||||
get :show, params: { id: <%= "@#{singular_table_name}" %> }
|
||||
get <%= show_helper %>
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should update <%= singular_table_name %>" do
|
||||
patch :update, params: { id: <%= "@#{singular_table_name}" %>, <%= "#{singular_table_name}: { #{attributes_hash} }" %> }
|
||||
patch <%= show_helper %>, params: { <%= "#{singular_table_name}: { #{attributes_hash} }" %> }
|
||||
assert_response 200
|
||||
end
|
||||
|
||||
test "should destroy <%= singular_table_name %>" do
|
||||
assert_difference('<%= class_name %>.count', -1) do
|
||||
delete :destroy, params: { id: <%= "@#{singular_table_name}" %> }
|
||||
delete <%= show_helper %>
|
||||
end
|
||||
|
||||
assert_response 204
|
||||
|
|
|
@ -1,50 +1,51 @@
|
|||
require 'test_helper'
|
||||
|
||||
<% module_namespacing do -%>
|
||||
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
||||
class <%= controller_class_name %>ControllerTest < ActionDispatch::IntegrationTest
|
||||
<%- if mountable_engine? -%>
|
||||
include Engine.routes.url_helpers
|
||||
<% end -%>
|
||||
|
||||
setup do
|
||||
@<%= singular_table_name %> = <%= fixture_name %>(:one)
|
||||
<% if mountable_engine? -%>
|
||||
@routes = Engine.routes
|
||||
<% end -%>
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
get :index
|
||||
get <%= index_helper %>_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
get :new
|
||||
get <%= new_helper %>
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create <%= singular_table_name %>" do
|
||||
assert_difference('<%= class_name %>.count') do
|
||||
post :create, params: { <%= "#{singular_table_name}: { #{attributes_hash} }" %> }
|
||||
post <%= index_helper %>_url, params: { <%= "#{singular_table_name}: { #{attributes_hash} }" %> }
|
||||
end
|
||||
|
||||
assert_redirected_to <%= singular_table_name %>_path(<%= class_name %>.last)
|
||||
end
|
||||
|
||||
test "should show <%= singular_table_name %>" do
|
||||
get :show, params: { id: <%= "@#{singular_table_name}" %> }
|
||||
get <%= show_helper %>
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get edit" do
|
||||
get :edit, params: { id: <%= "@#{singular_table_name}" %> }
|
||||
get <%= edit_helper %>
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should update <%= singular_table_name %>" do
|
||||
patch :update, params: { id: <%= "@#{singular_table_name}" %>, <%= "#{singular_table_name}: { #{attributes_hash} }" %> }
|
||||
patch <%= show_helper %>, params: { <%= "#{singular_table_name}: { #{attributes_hash} }" %> }
|
||||
assert_redirected_to <%= singular_table_name %>_path(<%= "@#{singular_table_name}" %>)
|
||||
end
|
||||
|
||||
test "should destroy <%= singular_table_name %>" do
|
||||
assert_difference('<%= class_name %>.count', -1) do
|
||||
delete :destroy, params: { id: <%= "@#{singular_table_name}" %> }
|
||||
delete <%= show_helper %>
|
||||
end
|
||||
|
||||
assert_redirected_to <%= index_helper %>_path
|
||||
|
|
|
@ -186,7 +186,7 @@ module ApplicationTests
|
|||
def test_scaffold_tests_pass_by_default
|
||||
output = Dir.chdir(app_path) do
|
||||
`bin/rails generate scaffold user username:string password:string;
|
||||
bin/rake db:migrate test`
|
||||
RAILS_ENV=test bin/rake db:migrate test`
|
||||
end
|
||||
|
||||
assert_match(/7 runs, 12 assertions, 0 failures, 0 errors/, output)
|
||||
|
@ -205,7 +205,7 @@ module ApplicationTests
|
|||
|
||||
output = Dir.chdir(app_path) do
|
||||
`bin/rails generate scaffold user username:string password:string;
|
||||
bin/rake db:migrate test`
|
||||
RAILS_ENV=test bin/rake db:migrate test`
|
||||
end
|
||||
|
||||
assert_match(/5 runs, 7 assertions, 0 failures, 0 errors/, output)
|
||||
|
@ -218,7 +218,7 @@ module ApplicationTests
|
|||
|
||||
output = Dir.chdir(app_path) do
|
||||
`bin/rails generate scaffold LineItems product:references cart:belongs_to;
|
||||
bin/rake db:migrate test`
|
||||
RAILS_ENV=test bin/rake db:migrate test`
|
||||
end
|
||||
|
||||
assert_match(/7 runs, 12 assertions, 0 failures, 0 errors/, output)
|
||||
|
|
|
@ -218,7 +218,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
|
|||
/class ProductLinesController < ApplicationController/
|
||||
|
||||
assert_file "test/controllers/test_app/product_lines_controller_test.rb",
|
||||
/module TestApp\n class ProductLinesControllerTest < ActionController::TestCase/
|
||||
/module TestApp\n class ProductLinesControllerTest < ActionDispatch::IntegrationTest/
|
||||
|
||||
# Views
|
||||
%w(index edit new show _form).each do |view|
|
||||
|
@ -285,7 +285,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
|
|||
end
|
||||
|
||||
assert_file "test/controllers/test_app/admin/roles_controller_test.rb",
|
||||
/module TestApp\n class Admin::RolesControllerTest < ActionController::TestCase/
|
||||
/module TestApp\n class Admin::RolesControllerTest < ActionDispatch::IntegrationTest/
|
||||
|
||||
# Views
|
||||
%w(index edit new show _form).each do |view|
|
||||
|
@ -352,7 +352,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
|
|||
end
|
||||
|
||||
assert_file "test/controllers/test_app/admin/user/special/roles_controller_test.rb",
|
||||
/module TestApp\n class Admin::User::Special::RolesControllerTest < ActionController::TestCase/
|
||||
/module TestApp\n class Admin::User::Special::RolesControllerTest < ActionDispatch::IntegrationTest/
|
||||
|
||||
# Views
|
||||
%w(index edit new show _form).each do |view|
|
||||
|
@ -418,6 +418,6 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
|
|||
assert_match(%r(require_dependency "test_app/application_controller"), content)
|
||||
end
|
||||
assert_file "test/controllers/test_app/admin/roles_controller_test.rb",
|
||||
/module TestApp\n class Admin::RolesControllerTest < ActionController::TestCase/
|
||||
/module TestApp\n class Admin::RolesControllerTest < ActionDispatch::IntegrationTest/
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,7 +33,7 @@ class ResourceGeneratorTest < Rails::Generators::TestCase
|
|||
def test_resource_controller_with_pluralized_class_name
|
||||
run_generator
|
||||
assert_file "app/controllers/accounts_controller.rb", /class AccountsController < ApplicationController/
|
||||
assert_file "test/controllers/accounts_controller_test.rb", /class AccountsControllerTest < ActionController::TestCase/
|
||||
assert_file "test/controllers/accounts_controller_test.rb", /class AccountsControllerTest < ActionDispatch::IntegrationTest/
|
||||
|
||||
assert_file "app/helpers/accounts_helper.rb", /module AccountsHelper/
|
||||
end
|
||||
|
|
|
@ -104,10 +104,10 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
|
|||
run_generator ["User", "name:string", "age:integer", "organization:references{polymorphic}"]
|
||||
|
||||
assert_file "test/controllers/users_controller_test.rb" do |content|
|
||||
assert_match(/class UsersControllerTest < ActionController::TestCase/, content)
|
||||
assert_match(/class UsersControllerTest < ActionDispatch::IntegrationTest/, content)
|
||||
assert_match(/test "should get index"/, content)
|
||||
assert_match(/post :create, params: \{ user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id, organization_type: @user\.organization_type \} \}/, content)
|
||||
assert_match(/patch :update, params: \{ id: @user, user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id, organization_type: @user\.organization_type \} \}/, content)
|
||||
assert_match(/post users_url, params: \{ user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id, organization_type: @user\.organization_type \} \}/, content)
|
||||
assert_match(/patch user_url\(@user\), params: \{ user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id, organization_type: @user\.organization_type \} \}/, content)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -115,10 +115,10 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
|
|||
run_generator ["User"]
|
||||
|
||||
assert_file "test/controllers/users_controller_test.rb" do |content|
|
||||
assert_match(/class UsersControllerTest < ActionController::TestCase/, content)
|
||||
assert_match(/class UsersControllerTest < ActionDispatch::IntegrationTest/, content)
|
||||
assert_match(/test "should get index"/, content)
|
||||
assert_match(/post :create, params: \{ user: \{ \} \}/, content)
|
||||
assert_match(/patch :update, params: \{ id: @user, user: \{ \} \}/, content)
|
||||
assert_match(/post users_url, params: \{ user: \{ \} \}/, content)
|
||||
assert_match(/patch user_url\(@user\), params: \{ user: \{ \} \}/, content)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -236,10 +236,10 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
|
|||
run_generator ["User", "name:string", "age:integer", "organization:references{polymorphic}", "--api"]
|
||||
|
||||
assert_file "test/controllers/users_controller_test.rb" do |content|
|
||||
assert_match(/class UsersControllerTest < ActionController::TestCase/, content)
|
||||
assert_match(/class UsersControllerTest < ActionDispatch::IntegrationTest/, content)
|
||||
assert_match(/test "should get index"/, content)
|
||||
assert_match(/post :create, params: \{ user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id, organization_type: @user\.organization_type \} \}/, content)
|
||||
assert_match(/patch :update, params: \{ id: @user, user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id, organization_type: @user\.organization_type \} \}/, content)
|
||||
assert_match(/post users_url, params: \{ user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id, organization_type: @user\.organization_type \} \}/, content)
|
||||
assert_match(/patch user_url\(@user\), params: \{ user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id, organization_type: @user\.organization_type \} \}/, content)
|
||||
assert_no_match(/assert_redirected_to/, content)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -57,9 +57,9 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
|
|||
end
|
||||
|
||||
assert_file "test/controllers/product_lines_controller_test.rb" do |test|
|
||||
assert_match(/class ProductLinesControllerTest < ActionController::TestCase/, test)
|
||||
assert_match(/post :create, params: \{ product_line: \{ product_id: @product_line\.product_id, title: @product_line\.title, user_id: @product_line\.user_id \} \}/, test)
|
||||
assert_match(/patch :update, params: \{ id: @product_line, product_line: \{ product_id: @product_line\.product_id, title: @product_line\.title, user_id: @product_line\.user_id \} \}/, test)
|
||||
assert_match(/class ProductLinesControllerTest < ActionDispatch::IntegrationTest/, test)
|
||||
assert_match(/post product_lines_url, params: \{ product_line: \{ product_id: @product_line\.product_id, title: @product_line\.title, user_id: @product_line\.user_id \} \}/, test)
|
||||
assert_match(/patch product_line_url\(@product_line\), params: \{ product_line: \{ product_id: @product_line\.product_id, title: @product_line\.title, user_id: @product_line\.user_id \} \}/, test)
|
||||
end
|
||||
|
||||
# Views
|
||||
|
@ -135,9 +135,9 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
|
|||
end
|
||||
|
||||
assert_file "test/controllers/product_lines_controller_test.rb" do |test|
|
||||
assert_match(/class ProductLinesControllerTest < ActionController::TestCase/, test)
|
||||
assert_match(/post :create, params: \{ product_line: \{ product_id: @product_line\.product_id, title: @product_line\.title, user_id: @product_line\.user_id \} \}/, test)
|
||||
assert_match(/patch :update, params: \{ id: @product_line, product_line: \{ product_id: @product_line\.product_id, title: @product_line\.title, user_id: @product_line\.user_id \} \}/, test)
|
||||
assert_match(/class ProductLinesControllerTest < ActionDispatch::IntegrationTest/, test)
|
||||
assert_match(/post product_lines_url, params: \{ product_line: \{ product_id: @product_line\.product_id, title: @product_line\.title, user_id: @product_line\.user_id \} \}/, test)
|
||||
assert_match(/patch product_line_url\(@product_line\), params: \{ product_line: \{ product_id: @product_line\.product_id, title: @product_line\.title, user_id: @product_line\.user_id \} \}/, test)
|
||||
assert_no_match(/assert_redirected_to/, test)
|
||||
end
|
||||
|
||||
|
@ -161,10 +161,10 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
|
|||
run_generator ["product_line"]
|
||||
|
||||
assert_file "test/controllers/product_lines_controller_test.rb" do |content|
|
||||
assert_match(/class ProductLinesControllerTest < ActionController::TestCase/, content)
|
||||
assert_match(/class ProductLinesControllerTest < ActionDispatch::IntegrationTest/, content)
|
||||
assert_match(/test "should get index"/, content)
|
||||
assert_match(/post :create, params: \{ product_line: \{ \} \}/, content)
|
||||
assert_match(/patch :update, params: \{ id: @product_line, product_line: \{ \} \}/, content)
|
||||
assert_match(/post product_lines_url, params: \{ product_line: \{ \} \}/, content)
|
||||
assert_match(/patch product_line_url\(@product_line\), params: \{ product_line: \{ \} \}/, content)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -250,7 +250,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
|
|||
end
|
||||
|
||||
assert_file "test/controllers/admin/roles_controller_test.rb",
|
||||
/class Admin::RolesControllerTest < ActionController::TestCase/
|
||||
/class Admin::RolesControllerTest < ActionDispatch::IntegrationTest/
|
||||
|
||||
# Views
|
||||
%w(index edit new show _form).each do |view|
|
||||
|
|
Loading…
Reference in a new issue