1
匹配我有以下测试:没有路由中的RSpec测试
it "should respond with a json object" do
xhr :post, :create, :upload => @attr_upload, :format => :json
end
这里是我的路线:
resources :uploads, :except =>[:new, :show]
我有一个表格,用户可以使用jQuery的文件 - 上传图片上传插件:
<%= form_for @upload, :html => { :multipart => true } do |f| %>
<div class="fileupload-buttonbar">
<label class="fileinput-button">
<span>Add files... or drop them to upload</span>
<%= f.file_field :photo, :id => "upload_photo" %>
</label>
</div>
<% end %>
在我控制我加载该文件,并生成一个JSON响应:
def create
@upload = Upload.new(params[:upload])
respond_to do |format|
if @upload.save
set_current_upload(@upload)
format.json {render :json => [ @upload.to_jq_upload ].to_json}
else
format.json {render :json => [ @upload.to_jq_upload.merge({ :error => "custom_failure" }) ].to_json}
end
end
end
当我运行我的测试,我得到以下几点:
No route matches {:action=>"update", :controller=>"uploads", :id=>#<Upload id: nil, created_at: nil, updated_at: nil, photo_file_name: nil, photo_content_type: nil, photo_file_size: nil, photo_updated_at: nil, uploadable_id: nil, uploadable_type: nil>}
谁能帮我把这个测试工作? 我正在提交到创建操作,所以它为什么试图去更新操作?
任何帮助,将不胜感激我一直在为此工作了两天。
感谢米哈伊洛夫有在会话的对象,这是造成其递交给更新。 – chell