我有一个应该只响应 AJAX 调用的控制器操作:
def archive
@model = MyEngine::MyModel.find(params[:id])
if @model.update_attributes(params[:model])
@success = true
else
@success = false
end
respond_to do |format|
format.js
end
end
我想用类似的东西来测试它:
it "should respond with javascript" do
xhr :post, :archive, {:id => @model.to_param, :use_route => :my_engine}, valid_session
response.should render_template('asi/events/archive', :format => 'js')
end
和
it "should not respond with html" do
xhr :post, :archive, {:id => @event1.to_param, :use_route => :asi}, valid_session
response.should_not render_template('asi/events/archive', :format => 'html')
end
但似乎断言主要与渲染“存档”模板有关,并不关心它的扩展。如果有更好的方法来规范这个,有什么想法我做错了吗?
感谢您的关注!