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