I have a controller action that should only respond to AJAX calls:
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
I want to test that with something like:
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
and
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
But it seems like the assertions are mainly concerned with rendering the ‘archive’ template and doesn’t care about it’s extension. Any ideas what I’m doing wrong if there’s a better way to spec this?
Thanks for looking!
try with
also, you can refactor your model a little doing
or