我正在尝试测试 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?