Controllers are tricky to test, and there's no perfect way to do it. In this episode you will see how I test controllers, and my reasoning behind it.
describe MenuItemsController, "creating a new menu item" do
integrate_views
fixtures :menu_items
it "should redirect to index with a notice on successful save" do
MenuItem.any_instance.stubs(:valid?).returns(true)
post 'create'
assigns[:menu_item].should_not be_new_record
flash[:notice].should_not be_nil
response.should redirect_to(menu_items_path)
end
it "should re-render new template on failed save" do
MenuItem.any_instance.stubs(:valid?).returns(false)
post 'create'
assigns[:menu_item].should be_new_record
flash[:notice].should be_nil
response.should render_template('new')
end
it "should pass params to menu item" do
post 'create', :menu_item => { :name => 'Plain' }
assigns[:menu_item].name.should == 'Plain'
end
end
分享到:
相关推荐
### TabBarControllers:导航与标签栏控制器的深度解析 在iOS应用开发中,导航和标签栏控制器(TabBarControllers)是构建用户界面的关键组件。它们不仅提供了流畅的用户体验,还帮助开发者有效地组织和呈现应用...
Spring Boot (Part 1) - Testing REST Controllers"针对Spring Boot应用,介绍了如何测试RESTful API的控制器层。这里会涉及到Spring的测试支持,如WebMvcTest注解,以及如何使用MockMvc进行HTTP请求的模拟。 "1. ...
### 集成式TFT-LCD时序控制器与RSDS列驱动接口技术解析 #### 概述 本文旨在探讨新一代集成式薄膜晶体管液晶显示器(Thin Film Transistor Liquid Crystal Display, TFT-LCD)时序控制器(Timing Controller, TCON...
标题与描述中的核心知识点是关于“Output Feedback Controllers for Systems with Structured Uncertainty”的设计与实现。这涉及到在具有结构化不确定性的系统中设计输出反馈控制器,以确保系统的性能水平,尤其是...
《PID Controllers: Theory, Design, and Tuning》一书由Karl J. Astrom和Tore Hagglund共同撰写,是该领域的经典之作。本书不仅涵盖了PID控制器的基本理论,还深入探讨了设计方法及调优技巧,对于提升工业过程的...
- **The Web Services API**: For integrating Salesforce with external systems. - **The Bulk API**: For handling large data loads efficiently. - **The Force.com Migration Tool**: For automating metadata...
在本文中,我们将深入探讨Laravel框架中的控制器(Controllers),这是Laravel开发的重要组成部分。Laravel是一个优雅且强大的PHP Web应用程序开发框架,它提供了一系列工具和最佳实践,使得Web应用的构建变得更加...
### 关于PCIe GbE Controllers Open Source Software Developer’s Manual的知识点 #### 一、概述 本手册(《PCIe GbE Controllers Open Source Software Developer’s Manual》)是一份针对Intel网卡产品线的开放...
docker kube-controllers 镜像 使用方法: 1、保存到/tmp下 2、docker load -i /tmp/kube-controllers-3.10.2.tar 验证: docker images
PSoC® is a scalable and reconfigurable platform architecture for a family of programmable embedded system controllers with ARM® Cortex™ CPUs (single and multi-core). The PSoC 63 product family, ...
"AVR controllers_avr_"这个标题可能指的是一个关于AVR微控制器的资源集合,可能是代码示例、教程或项目文件。 在"avr microcontrollers programs"的描述中,我们可以理解为这个压缩包可能包含了与AVR微控制器编程...
资源名称:教你使用view controllers以及创建展示图片内容简介:通过教你制作一个上架应用 PicDecor来教你使用 view controllers以及创建展示图片本章教大家开发一个应用 PicDecor,这个应用可以允许用户从相册上传...
As an example, a chapter dealing with HVDC Light applications is included providing recent information on both on-shore and off-shore applications of wind farms. HVDC and FACTS Controllers: ...
本资源“PID controllers:theory design and tuning”是一份详细的英文原版教材,内容清晰,非扫描版本,为深入理解PID控制器的原理、设计方法以及调参技巧提供了宝贵的资料。 PID控制器的工作原理基于三个基本...
Abstract: An anti-windup scheme for proportional-integral-derivative controllers is presented. The approach is based on the combined use of back-calculation and conditional integration anti- windup ...
根据提供的文件信息,本书《PID Controllers: Theory, Design, and Tuning》第二版由Karl J. Astrom和Tore Häglund共同撰写,是一部关于比例积分微分(Proportional-Integral-Derivative,简称PID)控制器的经典...