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==“澳门”
@[email protected]
@user.save
end
session[:login][email protected]
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=>“[email protected]”,
: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!