hello: An action needed to test is: def register @user=User.new(params[:user]) if params[:user] && @user.save # if province=="北京"...,set the city attr''value the same as province province=params[:user][:province] if province=="北京" || province=="天津" || province=="重庆" || province=="上海" || province=="香港" || province=="澳门" @user.city=-DM5jFyC636MdNQYTog8Nmw@public.gmane.org @user.save end session[:login]=-37LZGFau30o@public.gmane.org flash[:register]="#{@user.name}已创建" redirect_to :action=>"upanel" else render :action=>"register" end end ######################### The test is : require File.dirname(__FILE__) + ''/../test_helper'' require ''login_controller'' class LoginControllerTest < ActionController::TestCase # Replace this with your real tests. def setup @login_instance=LoginController.new @request=ActionController::TestRequest.new @response=ActionController::TestResponse.new end def test_truth assert true end def test_register_suc post :register,:user=>{:id=>1, :photo=>"/images/users/fan_hong.jpg", :ball_kind=>"篮球", :name=>"范宏", :password=>"3338179", :password_confirmation=>"3338179", :age=>"30", :sex=>"男", :education=>"本科", :career=>"工程师", :province=>"北京", :section=>"朝阳区", :email=>"fh-9Onoh4P/yGk@public.gmane.org", :qq=>"369963"} assert_response :success assert_redirected_to :action=>"upanel" assert_equal 1,session[:login] assert_equal "范宏已创建",flash[:register] assert_equal "北京",assigns(:user).city end end ############# when i run the test,there is one fail,which says like this: expected 1 or "范宏已创建"or "北京",but is nil. it seems that this test does not call the method register.But in reality,the register method work fine when i submit the form.I do not know where is wrong in my test code.please help me! thank you! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
who can help me? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Fri, 2008-07-25 at 17:21 +0200, Guo Yangguang wrote:> hello: > > An action needed to test is: > def register > @user=User.new(params[:user]) > > if params[:user] && @user.save > # if province=="北京"...,set the city attr''value the same as > province > province=params[:user][:province] > if province=="北京" || province=="天津" || province=="重庆" || > province=="上海" || province=="香港" || province=="澳门" > @user.city=-DM5jFyC636MdNQYTog8Nmw@public.gmane.org > @user.save > end > session[:login]=-37LZGFau30o@public.gmane.org > flash[:register]="#{@user.name}已创建" > redirect_to :action=>"upanel" > else > render :action=>"register" > end > end > > ######################### > The test is : > require File.dirname(__FILE__) + ''/../test_helper'' > require ''login_controller'' > class LoginControllerTest < ActionController::TestCase > # Replace this with your real tests. > def setup > @login_instance=LoginController.new > @request=ActionController::TestRequest.new > @response=ActionController::TestResponse.new > end > def test_truth > assert true > end > def test_register_suc > post :register,:user=>{:id=>1, > :photo=>"/images/users/fan_hong.jpg", > :ball_kind=>"篮球", > :name=>"范宏", > :password=>"3338179", > :password_confirmation=>"3338179", > :age=>"30", > :sex=>"男", > :education=>"本科", > :career=>"工程师", > :province=>"北京", > :section=>"朝阳区", > :email=>"fh-9Onoh4P/yGk@public.gmane.org", > :qq=>"369963"} > assert_response :success > assert_redirected_to :action=>"upanel" > assert_equal 1,session[:login] > assert_equal "范宏已创建",flash[:register] > assert_equal "北京",assigns(:user).city > end > end > > ############# > when i run the test,there is one fail,which says like this: > expected 1 or "范宏已创建"or "北京",but is nil. > it seems that this test does not call the method register.But in > reality,the register method work fine when i submit the form.I do not > know where is wrong in my test code.please help me! thank you!---- look in your test.log - the answer should be there. Craig --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---