agile with rails 一書中詳細的描述了如何進行測試,
但是在開發中,我們或許會遇到下面的情況:
使用者必須登陸系統才能進行其他工作;
使用者資訊儲存在 session 裡;
登陸工作是在 單獨的 controller裡(如 logincontroller).
這樣的情況下, 當我們想對 searchcontroller 進行功能測試的時候,
會遇到沒有許可權訪問action的情況.
但是我們又不能在 searchcontrller_test 裡呼叫 logincontroller_test,
那麼如何處理呢?
以下是我的解決辦法:
[code]
def setup
@controller = reportcontroller.new
@request = actioncontroller::testrequest.new
@response = actioncontroller::testresponse.new
test_user
enddef test_user
# 這個 @tom 是 fixtures 中的資料
@user = user.find(:first, :conditions=>['id=?', @tom.id])
assert_not_nil @user
enddef test_index
assert_response :success
end[/code]
方法很簡單,就是 在 get(post) 方法裡,設定 session的數值.
如果還有更好的辦法希望能共享出來, thanks!
Linux下shell(獻給初學者)
shell下的控制結構 一 if condition 執行第一段程式 else 執行第二段程式 fi fi為結束 if 條件 then 執行 elif 條件2 then 執行 else 執行 fi二 case 變數名稱 in 第乙個變數的內容 程式一 第二變數的內容 其他程式段 exit 1 esa...
事件委託的優勢 獻給初學者
比如說大量的迴圈 要求為1000個li標籤新增事件,如果利用迴圈給li繫結事件可想而知。遍歷的基數越大,效能開銷也越大。這是就要應該用事件委託來解決此事。var oul document.getelementbyid oul oul.nclick function ev tagname nodena...
獻給彙編初學者 函式呼叫堆疊變化分析
標 題 獻給彙編初學者 函式呼叫堆疊變化分析 作 者 墮落天才 時 間 2007 01 19,19 20 鏈 接 http bbs.pediy.com showthread.php?threadid 38234 跟乙個朋友談堆疊的時候 就寫下了這段文字,順便發到這裡給需要的看看吧 彙編初學者比較頭痛...