我是使用 RSpec 测试的新手,非常感谢您的帮助。
这是我在控制器内的索引操作,我需要对其进行测试,以查看视图内的链接选择是否按预期运行。我会很感激你能提供给我的任何代码,因为我什至不知道从哪里开始。
def index
respond_to do |format|
format.html
format.json do
if params[:s_id].blank? && !params[:f_id].blank?
@fp_for_dropdown = Model.where(:f_id => params[:f_id])
elsif !params[:s_id].blank? && params[:f_id].blank?
@fp_for_dropdown = Model.where(:s_id => params[:s_id])
elsif !params[:s_id].blank? && !params[:f_id].blank?
@fp_for_dropdown = Model.where(:s_id => params[:s_id], :f_id => params[:f_id])
else
@fp_for_dropdown = Hash[]
end
render :json => Hash["" => ""].merge(Hash[@fp_for_dropdown.map { |i| [i.id, i.name] }])
end
end
结尾