在我的RSpec测试中,我需要模拟对索引操作的
AJAX GET请求,并且一直在使用Rails文档和RSpec书中描述的代码:
xhr :get,:index
但总是会失败,因为测试试图加载show动作(没有任何参数)而不是指定的索引动作.
控制器动作是:
def index @contacts = Contact.all respond_to do |format| format.html format.js { render :update do |page| page.replace_html :contact_search_results,:partial => 'contacts' end } end end
ActionView::TemplateError in 'ContactsController as an administrator user when showing the index of contacts' as an AJAX request should render results into the contact_search_results element' contact_url Failed to generate from {:action=>"show",:controller=>"contacts",:id=>#<Contact id: nil,first_name: nil,....>}
有谁知道如何在测试中模拟AJAX调用索引操作?
谢谢!