`
peryt
  • 浏览: 54408 次
  • 来自: ...
最近访客 更多访客>>
社区版块
存档分类
最新评论
  • waiting: 既然都指定了dataType为'script'那就不必特别在b ...
    jQuery

9.2 sign in failure

 
阅读更多

start from TDD!!!

 

1. require 'spec_helper'

describe SessionsController do
  render_views
  .
  .
  .
  describe "POST 'create'" do

    describe "invalid signin" do

      before(:each) do
        @attr = { :email => "email@example.com", :password => "invalid" }
      end

      it "should re-render the new page" do
        post :create, :session => @attr
        response.should render_template('new')
      end

      it "should have the right title" do
        post :create, :session => @attr
        response.should have_selector("title", :content => "Sign in")
      end

      it "should have a flash.now message" do
        post :create, :session => @attr
        flash.now[:error].should =~ /invalid/i
      end
    end
  end
end

 

what 's flash.now[:error] and flash[:error]

we will explain it in a short article later.

 

2. let's write code to make the test pass!

 

 

def create
    user = User.authenticate(params[:session][:email],
                             params[:session][:password])
    if user.nil?
      flash.now[:error] = "Invalid email/password combination."
      @title = "Sign in"
      render 'new'
    else
      # Sign the user in and redirect to the user's show page.
    end
  end

a.  you may wondering, why we use user instead of @user,

because the user object will never be used again, so it is not needed to use a instance var, which will take more resource.

 

b. remember, render will just render the page, won't execute the action!!!

 

c. when using render, pls use flash.now[:error] = ""

when using redirect, pls use flash[:error] = ""

 

d. since we don't have models here, so we can't use something like @user.errors.full_messages to display errors, so we use flash.now[:error] to store the error messages.

 

 

ok, done, the test passed.

 

分享到:
评论

相关推荐

    DevExpress9.2完整版

    DevExpress9.2完整版 包含如下控件集: ---------------- DevExpress.BonusSkins.v9.2.dll DevExpress.Charts.v9.2.Core.dll DevExpress.Data.v9.2.Compact.dll DevExpress.Data.v9.2.dll DevExpress.Data.v9.2...

    cuda9.2和cudnn9.2.txt

    cuda9.2和cudnn9.2百度网盘

    CASS9.2完整版

    《南方CASS9.2:测绘工程的得力助手》 南方CASS,全称是Computer Aided Surveying and Mapping System,是由南方数码科技有限公司开发的一款专业级的测绘软件,主要用于地形地籍测绘、工程测量等领域。CASS9.2作为...

    qtp9.2.rar_QTP9.2

    【QTP 9.2 全面解析】 QuickTest Professional(QTP)是HP公司推出的一款自动化测试工具,主要用于功能测试和回归测试。QTP 9.2版本是该产品线的一个重要里程碑,它提供了更加强大和全面的自动化测试解决方案。在本...

    xilinx ISE9.2 安装序列号

    ### Xilinx ISE 9.2 安装与序列号详解 #### 一、Xilinx ISE 9.2 概述 Xilinx ISE (Integrated Software Environment) 9.2 是一款由Xilinx公司推出的集成开发环境,主要用于FPGA(Field Programmable Gate Array)...

    Ehlib 9.2 build 9.2.026 for D7-XE10.2

    EhLib 9.2 build 9.2.026 是一款专为 Delphi 开发者设计的组件库,适用于 Delphi 7 到 Delphi 10.2.3 的各个版本。这款控件组包的核心目标是增强应用程序在数据库数据处理和用户交互方面的功能,提供丰富的界面元素...

    erdas9.2安装步骤

    ### ERDAS 9.2 安装步骤详解 #### 一、准备工作 在开始安装ERDAS 9.2之前,请确保您的计算机系统满足以下条件: - 操作系统:支持Windows XP及以上版本。 - 硬盘空间:至少有1GB可用空间,建议更多以避免安装过程...

    PADS9.2update1withcrack

    PADS 9.2 Update 1 is designed to correct issues in PADS 9.2 and overlays an existing PADS 9.2 installation. PADS 9.2 Update 1 does not install standalone versions of Mentor products; it must be ...

    kettle9.2下载,亲测可用pdi-ce-9.2.0.0-290

    kettle9.2下载,亲测可用pdi-ce-9.2.0.0-290

    QTP9.2 完全版

    Quick Test Professional (QTP) 9.2 是一款强大的自动化测试工具,专为软件测试人员设计,用于简化和加速功能测试以及回归测试的过程。这款工具以其广泛的环境支持和多种应用程序类型的自动化测试能力而闻名。 安装...

    3 togaf9.2培训视频2020(19-24).rar

    a11第5章-课件1: TOGAF9.2企业架构标准TOGAF9.2设计实践.mp4 a12第5章课件2: TOGAF9.2企业架构标准TOGAF9.2设计实践.mp4 a13第5章课件3: TOGAF9.2企业架构标准TOGAF9.2设计实践.mp4 a14第5章课件4: TOGAF9.2企业架构...

    weblogic9.2安装过程

    WebLogic 9.2 安装过程详解 在 Unix 系统下安装 WebLogic 9.2 需要按照特定的步骤进行操作,以确保安装成功。在本文中,我们将详细介绍 WebLogic 9.2 的安装过程,并提供相关的命令和配置信息。 安装 WebLogic 9.2...

    EhLib 9.2 Build 9.2.025

    EHLib是一个DELPHI 下的非常棒的第三方Grid控件,比DELPHI自带的强大许多,但又比cxGrid小巧。适合做一些比较轻量级的桌面应用。这是最新的版本,为dcu版。

    OMNIC 9.2安装包.rar

    标题中的"OMNIC 9.2安装包.rar"指的是Thermo Scientific公司的OMNIC 9.2版本软件的安装包,这是一款专用于红外光谱分析的专业软件。红外光谱技术是一种利用物质对红外光的吸收特性来研究其分子结构和组成的方法,在...

    postgresql-9.2-windows

    postgresql 9.2 64位 windows 版本安装包。

    QTP 9.2安装图解

    QTP 9.2安装图解,如何安装QTP 9.2

    冰盾9.2 冰盾9.2

    冰盾9.2冰盾9.2冰盾9.2冰盾9.2

    arcgis 9.2 全系列授权文件

    《ArcGIS 9.2 全系列授权文件详解》 ArcGIS是Esri公司推出的地理信息系统(Geographic Information System,GIS)软件,广泛应用于地图制作、地理数据分析、空间建模等多个领域。本资源集合——"arcgis 9.2 全系列...

    VCDSLoader_v9.2.rar

    【VCDSLoader_v9.2.rar】是一款针对汽车电子系统的诊断和编程工具的更新包,主要服务于5053硬件的升级。这个压缩文件包含了所有必要的软件组件,以确保用户可以将他们的数据线升级到最新版本,即百分之一百可用的...

    arcgis desktop 9.2 crack

    arcgis desktop 9.2 crack

Global site tag (gtag.js) - Google Analytics