no route matches in rspec test
I have the following test:
it "should respond with a json 开发者_JAVA百科object" do
xhr :post, :create, :upload => @attr_upload, :format => :json
end
Here is my routes:
resources :uploads, :except =>[:new, :show]
I have a form that a user can upload images using the jquery-file-upload plugin:
<%= 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 %>
In my controller I load the file and generate a json response:
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
When I run my test I am getting the following:
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>}
Can anyone help me get this test working? I am submitting to the create action so why is it trying to go to the update action?
Any help would be appreciated I have been working on this for two days.
The request goes on update action, not create, so double check your templates with generated forms, their URLs
精彩评论