2

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

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

見てくれてありがとう!

4

1 に答える 1

-3

で試してみてください

response.should_not render_template 'asi/events/archive.html'

また、モデルを少しリファクタリングすることもできます

@success = @model.update_attributes(params[:model])

また

@success = @model.update_attributes(params[:model]) === true
于 2012-10-06T23:26:48.707 に答える