Controller generators should be creating IntegrationTest stubs instead of ControllerTest
This commit is contained in:
parent
cd355a8eeb
commit
5541d640cf
|
@ -1,7 +1,7 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
<% module_namespacing do -%>
|
<% module_namespacing do -%>
|
||||||
class <%= class_name %>ControllerTest < ActionController::TestCase
|
class <%= class_name %>ControllerTest < ActionDispatch::IntegrationTest
|
||||||
<% if mountable_engine? -%>
|
<% if mountable_engine? -%>
|
||||||
setup do
|
setup do
|
||||||
@routes = Engine.routes
|
@routes = Engine.routes
|
||||||
|
@ -15,7 +15,7 @@ class <%= class_name %>ControllerTest < ActionController::TestCase
|
||||||
<% else -%>
|
<% else -%>
|
||||||
<% actions.each do |action| -%>
|
<% actions.each do |action| -%>
|
||||||
test "should get <%= action %>" do
|
test "should get <%= action %>" do
|
||||||
get :<%= action %>
|
get url_for(action: :<%= action %>)
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
<% module_namespacing do -%>
|
<% module_namespacing do -%>
|
||||||
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
class <%= controller_class_name %>ControllerTest < ActionDispatch::IntegrationTest
|
||||||
setup do
|
setup do
|
||||||
@<%= singular_table_name %> = <%= fixture_name %>(:one)
|
@<%= singular_table_name %> = <%= fixture_name %>(:one)
|
||||||
<% if mountable_engine? -%>
|
<% if mountable_engine? -%>
|
||||||
|
@ -10,31 +10,31 @@ class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should get index" do
|
test "should get index" do
|
||||||
get :index
|
get url_for( controller: :<%= controller_name %>, action: :index )
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should create <%= singular_table_name %>" do
|
test "should create <%= singular_table_name %>" do
|
||||||
assert_difference('<%= class_name %>.count') do
|
assert_difference('<%= class_name %>.count') do
|
||||||
post :create, params: { <%= "#{singular_table_name}: { #{attributes_hash} }" %> }
|
post url_for( controller: :<%= controller_name %>, action: :create, <%= "#{singular_table_name}: { #{attributes_hash} }" %> )
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_response 201
|
assert_response 201
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should show <%= singular_table_name %>" do
|
test "should show <%= singular_table_name %>" do
|
||||||
get :show, params: { id: <%= "@#{singular_table_name}" %> }
|
get url_for( controller: :<%= controller_name %>, action: :show, id: <%= "@#{singular_table_name}" %> )
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should update <%= singular_table_name %>" do
|
test "should update <%= singular_table_name %>" do
|
||||||
patch :update, params: { id: <%= "@#{singular_table_name}" %>, <%= "#{singular_table_name}: { #{attributes_hash} }" %> }
|
patch url_for( controller: :<%= controller_name %>, action: :update, id: <%= "@#{singular_table_name}" %>, <%= "#{singular_table_name}: { #{attributes_hash} }" %> )
|
||||||
assert_response 200
|
assert_response 200
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should destroy <%= singular_table_name %>" do
|
test "should destroy <%= singular_table_name %>" do
|
||||||
assert_difference('<%= class_name %>.count', -1) do
|
assert_difference('<%= class_name %>.count', -1) do
|
||||||
delete :destroy, params: { id: <%= "@#{singular_table_name}" %> }
|
delete url_for( controller: :<%= controller_name %>, action: :destroy, id: <%= "@#{singular_table_name}" %> )
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_response 204
|
assert_response 204
|
||||||
|
|
|
@ -1,50 +1,51 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
<% module_namespacing do -%>
|
<% module_namespacing do -%>
|
||||||
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
class <%= controller_class_name %>ControllerTest < ActionDispatch::IntegrationTest
|
||||||
setup do
|
setup do
|
||||||
@<%= singular_table_name %> = <%= fixture_name %>(:one)
|
@<%= singular_table_name %> = <%= fixture_name %>(:one)
|
||||||
<% if mountable_engine? -%>
|
<% if mountable_engine? -%>
|
||||||
|
|
||||||
@routes = Engine.routes
|
@routes = Engine.routes
|
||||||
<% end -%>
|
<% end -%>
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should get index" do
|
test "should get index" do
|
||||||
get :index
|
get url_for( controller: :<%= controller_name %>, action: :index )
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should get new" do
|
test "should get new" do
|
||||||
get :new
|
get url_for( controller: :<%= controller_name %>, action: :new )
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should create <%= singular_table_name %>" do
|
test "should create <%= singular_table_name %>" do
|
||||||
assert_difference('<%= class_name %>.count') do
|
assert_difference('<%= class_name %>.count') do
|
||||||
post :create, params: { <%= "#{singular_table_name}: { #{attributes_hash} }" %> }
|
post url_for( controller: :<%= controller_name %>, action: :create, <%= "#{singular_table_name}: { #{attributes_hash} }" %> )
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_redirected_to <%= singular_table_name %>_path(<%= class_name %>.last)
|
assert_redirected_to <%= singular_table_name %>_path(<%= class_name %>.last)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should show <%= singular_table_name %>" do
|
test "should show <%= singular_table_name %>" do
|
||||||
get :show, params: { id: <%= "@#{singular_table_name}" %> }
|
get url_for( controller: :<%= controller_name %>, action: :show, id: <%= "@#{singular_table_name}" %> )
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should get edit" do
|
test "should get edit" do
|
||||||
get :edit, params: { id: <%= "@#{singular_table_name}" %> }
|
get url_for( controller: :<%= controller_name %>, action: :edit, id: <%= "@#{singular_table_name}" %> )
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should update <%= singular_table_name %>" do
|
test "should update <%= singular_table_name %>" do
|
||||||
patch :update, params: { id: <%= "@#{singular_table_name}" %>, <%= "#{singular_table_name}: { #{attributes_hash} }" %> }
|
patch url_for( controller: :<%= controller_name %>, action: :update, id: <%= "@#{singular_table_name}" %>, <%= "#{singular_table_name}: { #{attributes_hash} }" %> )
|
||||||
assert_redirected_to <%= singular_table_name %>_path(<%= "@#{singular_table_name}" %>)
|
assert_redirected_to <%= singular_table_name %>_path(<%= "@#{singular_table_name}" %>)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should destroy <%= singular_table_name %>" do
|
test "should destroy <%= singular_table_name %>" do
|
||||||
assert_difference('<%= class_name %>.count', -1) do
|
assert_difference('<%= class_name %>.count', -1) do
|
||||||
delete :destroy, params: { id: <%= "@#{singular_table_name}" %> }
|
delete url_for( controller: :<%= controller_name %>, action: :destroy, id: <%= "@#{singular_table_name}" %> )
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_redirected_to <%= index_helper %>_path
|
assert_redirected_to <%= index_helper %>_path
|
||||||
|
|
|
@ -26,7 +26,7 @@ class CodeStatisticsCalculatorTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
test 'count number of methods in MiniTest file' do
|
test 'count number of methods in MiniTest file' do
|
||||||
code = <<-RUBY
|
code = <<-RUBY
|
||||||
class FooTest < ActionController::TestCase
|
class FooTest < ActionDispatch::IntegrationTest
|
||||||
test 'expectation' do
|
test 'expectation' do
|
||||||
assert true
|
assert true
|
||||||
end
|
end
|
||||||
|
|
|
@ -218,7 +218,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
|
||||||
/class ProductLinesController < ApplicationController/
|
/class ProductLinesController < ApplicationController/
|
||||||
|
|
||||||
assert_file "test/controllers/test_app/product_lines_controller_test.rb",
|
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
|
# Views
|
||||||
%w(index edit new show _form).each do |view|
|
%w(index edit new show _form).each do |view|
|
||||||
|
@ -285,7 +285,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_file "test/controllers/test_app/admin/roles_controller_test.rb",
|
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
|
# Views
|
||||||
%w(index edit new show _form).each do |view|
|
%w(index edit new show _form).each do |view|
|
||||||
|
@ -352,7 +352,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_file "test/controllers/test_app/admin/user/special/roles_controller_test.rb",
|
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
|
# Views
|
||||||
%w(index edit new show _form).each do |view|
|
%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)
|
assert_match(%r(require_dependency "test_app/application_controller"), content)
|
||||||
end
|
end
|
||||||
assert_file "test/controllers/test_app/admin/roles_controller_test.rb",
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,7 +33,7 @@ class ResourceGeneratorTest < Rails::Generators::TestCase
|
||||||
def test_resource_controller_with_pluralized_class_name
|
def test_resource_controller_with_pluralized_class_name
|
||||||
run_generator
|
run_generator
|
||||||
assert_file "app/controllers/accounts_controller.rb", /class AccountsController < ApplicationController/
|
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/
|
assert_file "app/helpers/accounts_helper.rb", /module AccountsHelper/
|
||||||
end
|
end
|
||||||
|
|
|
@ -104,7 +104,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
|
||||||
run_generator ["User", "name:string", "age:integer", "organization:references{polymorphic}"]
|
run_generator ["User", "name:string", "age:integer", "organization:references{polymorphic}"]
|
||||||
|
|
||||||
assert_file "test/controllers/users_controller_test.rb" do |content|
|
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(/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(/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(/patch :update, params: \{ id: @user, user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id, organization_type: @user\.organization_type \} \}/, content)
|
||||||
|
@ -115,7 +115,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
|
||||||
run_generator ["User"]
|
run_generator ["User"]
|
||||||
|
|
||||||
assert_file "test/controllers/users_controller_test.rb" do |content|
|
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(/test "should get index"/, content)
|
||||||
assert_match(/post :create, params: \{ user: \{ \} \}/, content)
|
assert_match(/post :create, params: \{ user: \{ \} \}/, content)
|
||||||
assert_match(/patch :update, params: \{ id: @user, user: \{ \} \}/, content)
|
assert_match(/patch :update, params: \{ id: @user, user: \{ \} \}/, content)
|
||||||
|
@ -236,7 +236,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
|
||||||
run_generator ["User", "name:string", "age:integer", "organization:references{polymorphic}", "--api"]
|
run_generator ["User", "name:string", "age:integer", "organization:references{polymorphic}", "--api"]
|
||||||
|
|
||||||
assert_file "test/controllers/users_controller_test.rb" do |content|
|
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(/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(/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(/patch :update, params: \{ id: @user, user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id, organization_type: @user\.organization_type \} \}/, content)
|
||||||
|
|
|
@ -57,7 +57,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_file "test/controllers/product_lines_controller_test.rb" do |test|
|
assert_file "test/controllers/product_lines_controller_test.rb" do |test|
|
||||||
assert_match(/class ProductLinesControllerTest < ActionController::TestCase/, test)
|
assert_match(/class ProductLinesControllerTest < ActionDispatch::IntegrationTest/, 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(/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(/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)
|
||||||
end
|
end
|
||||||
|
@ -135,7 +135,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_file "test/controllers/product_lines_controller_test.rb" do |test|
|
assert_file "test/controllers/product_lines_controller_test.rb" do |test|
|
||||||
assert_match(/class ProductLinesControllerTest < ActionController::TestCase/, test)
|
assert_match(/class ProductLinesControllerTest < ActionDispatch::IntegrationTest/, 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(/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(/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_no_match(/assert_redirected_to/, test)
|
assert_no_match(/assert_redirected_to/, test)
|
||||||
|
@ -161,7 +161,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
|
||||||
run_generator ["product_line"]
|
run_generator ["product_line"]
|
||||||
|
|
||||||
assert_file "test/controllers/product_lines_controller_test.rb" do |content|
|
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(/test "should get index"/, content)
|
||||||
assert_match(/post :create, params: \{ product_line: \{ \} \}/, content)
|
assert_match(/post :create, params: \{ product_line: \{ \} \}/, content)
|
||||||
assert_match(/patch :update, params: \{ id: @product_line, product_line: \{ \} \}/, content)
|
assert_match(/patch :update, params: \{ id: @product_line, product_line: \{ \} \}/, content)
|
||||||
|
@ -250,7 +250,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_file "test/controllers/admin/roles_controller_test.rb",
|
assert_file "test/controllers/admin/roles_controller_test.rb",
|
||||||
/class Admin::RolesControllerTest < ActionController::TestCase/
|
/class Admin::RolesControllerTest < ActionDispatch::IntegrationTest/
|
||||||
|
|
||||||
# Views
|
# Views
|
||||||
%w(index edit new show _form).each do |view|
|
%w(index edit new show _form).each do |view|
|
||||||
|
|
|
@ -6,7 +6,7 @@ module ActionController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class InfoControllerTest < ActionController::TestCase
|
class InfoControllerTest < ActionDispatch::IntegrationTest
|
||||||
tests Rails::InfoController
|
tests Rails::InfoController
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
|
|
Loading…
Reference in New Issue