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
しかし、アサーションは主に「アーカイブ」テンプレートのレンダリングに関係しており、その拡張については気にしないようです。これを特定するためのより良い方法がある場合、私が間違っていることについて何か考えはありますか?
見てくれてありがとう!