1
我試圖測試Rspec的一個搜索功能的搜索概念,
這是我到目前爲止,如何測試在rspec的
def product_search
filter = ""
filter = filter + " and B.sku like '#{params[:sku]}%'" if params[:sku] && params[:sku] != ""
filter = filter + " and A.name like '#{params[:name]}%'" if params[:name] && params[:name] != ""
filter = filter + " and D.name like '#{params[:store_name]}%'" if params[:store_name] && params[:store_name] != ""
if params[:approved] == "0"
filter= filter + "and (A.is_approved = false And A.approved_by is NULL) "
elsif params[:approved] == "1"
filter= filter + "and A.is_approved = true "
elsif params[:approved] == "2"
filter= filter + " and (A.is_approved = false And A.approved_by is NOT NULL) "
end
@products=Product.seller_product_search(filter,current_user.store.id).paginate(:page => params[:page], :per_page => 10)
respond_to do |format|
format.html
format.js
end
end
我應該怎麼寫RSpec的這段代碼?
我不知道如何測試 – Swathi 2012-04-11 03:37:32
如果這是你的問題,那麼看看網上提供的所有資源:http://railscasts.com/?tag_id=7 http://guides.rubyonrails.org /testing.html等... – phoet 2012-04-11 07:04:58
嘿@phoet我做了一些工作,就像你在回答中說的,現在混淆開始測試,你可以請你看看那個測試你輸入有史以來? – Awais 2014-07-03 10:44:48