admin_controller_test.rb
来自「ruby on rails web敏捷开发之路第二版 源代码」· RB 代码 · 共 98 行
RB
98 行
#---# Excerpted from "Agile Web Development with Rails, 2nd Ed."# We make no guarantees that this code is fit for any purpose. # Visit http://www.pragmaticprogrammer.com/titles/rails2 for more book information.#---require File.dirname(__FILE__) + '/../test_helper'require 'admin_controller'# Re-raise errors caught by the controller.class AdminController; def rescue_action(e) raise e end; endclass AdminControllerTest < Test::Unit::TestCase fixtures :daves def setup @controller = AdminController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new @first_id = daves(:first).id end def test_index get :index assert_response :success assert_template 'list' end def test_list get :list assert_response :success assert_template 'list' assert_not_nil assigns(:daves) end def test_show get :show, :id => @first_id assert_response :success assert_template 'show' assert_not_nil assigns(:dave) assert assigns(:dave).valid? end def test_new get :new assert_response :success assert_template 'new' assert_not_nil assigns(:dave) end def test_create num_daves = Dave.count post :create, :dave => {} assert_response :redirect assert_redirected_to :action => 'list' assert_equal num_daves + 1, Dave.count end def test_edit get :edit, :id => @first_id assert_response :success assert_template 'edit' assert_not_nil assigns(:dave) assert assigns(:dave).valid? end def test_update post :update, :id => @first_id assert_response :redirect assert_redirected_to :action => 'show', :id => @first_id end def test_destroy assert_nothing_raised { Dave.find(@first_id) } post :destroy, :id => @first_id assert_response :redirect assert_redirected_to :action => 'list' assert_raise(ActiveRecord::RecordNotFound) { Dave.find(@first_id) } endend
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?