Ruby on rails开发从头来(windows)(二十七)- 测试驱动开发 - 编程入门网
1 tests, 7 assertions, 0 failures, 0 errors
---------------------------------------------------------- Ruby on rails开发从头来(windows)(二十七)- 测试驱动开发(4)时间:2011-12-02 博客园 Cure4.在实现search.rhtml和results.rhtml的时候,我碰到了一些问题,用测试用例都可以选出数据来,但是通过页面就怎么也不行了,把log里的sql贴出来到phpMyAdmin里执行,也能选出数据,真不知道是怎么回事,自己对rails的理解还不深,自己胡乱写了这些代码,先把代码都帖出来,等自己对rails有更深入的理解的时候看能不能找到问题。同时也请高人指点 search_controller_test.rb: require File.dirname(__FILE__) + ''/../test_helper'' require ''search_controller'' # Re-raise errors caught by the controller.class SearchController; def rescue_action(e) raise e end; end class SearchControllerTest < Test::Unit::TestCase fixtures :products def setup @controller = SearchController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new end def test_search get :search, :title => "Pragmatic Version Control" assert_response :success assert_equal "Found 1 product(s).", flash[:notice] assert_template "search/results" products = assigns(:products) assert_not_nil products assert_equal 1, products.size assert_equal "Pragmatic Version Control", products[0].title assert_tag :tag => "div", :attributes => { :class => "results" }, :children => { :count => 1, :only => { :tag => "div", :attributes => { :class => "catalogentry" }}} end end search_controller.rb class SearchController < ApplicationController def search print(params[:title]) @products = Product.find(:all,:conditions=>[''title=?'',params[:title]]) if not @products.nil? flash[:notice] = sprintf(''Found %d product(s).'',@products.size) end print(flash[:notice]) #redirect_to(:action=>''results'') render(:action=>''results'') end def results end def index end end Ruby on rails开发从头来(windows)(二十七)- 测试驱动开发(5)时间:2011-12-02 博客园 CureViews下有三个文件:index.rhtml,results.rhtml,search.rhtml index.rhtml: <html><%= form_tag(:action=>''search'',:id=>@products) %> <table> <tr> <td>Book title:</td> <td><%=text_field("title","")%></td> </tr> <tr> <td><input type="submit" value="SEARCH" /></td> </tr> </table><%= end_form_tag %></html> results.rhtml: <h1>Search#results</h1><p>Find me in app/views/search/results.rhtml</p><div class="results"> <div class = "catalogentry"> <table cellpadding=& |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |