Patch #22356 » update_attachment_api_with_tests.diff
| app/controllers/attachments_controller.rb | ||
|---|---|---|
| 22 | 22 | before_filter :delete_authorize, :only => :destroy | 
| 23 | 23 | before_filter :authorize_global, :only => :upload | 
| 24 | 24 | |
| 25 | accept_api_auth :show, :download, :thumbnail, :upload, :destroy | |
| 25 |   accept_api_auth :show, :download, :thumbnail, :upload, :update, :destroy | |
| 26 | 26 | |
| 27 | 27 | def show | 
| 28 | 28 | respond_to do |format| | 
| ... | ... | |
| 109 | 109 | def update | 
| 110 | 110 | if params[:attachments].is_a?(Hash) | 
| 111 | 111 | if Attachment.update_attachments(@attachments, params[:attachments]) | 
| 112 | redirect_back_or_default home_path | |
| 113 | return | |
| 112 | respond_to do |format| | |
| 113 |           format.html { redirect_back_or_default home_path } | |
| 114 |           format.api { render_api_ok } | |
| 115 | end | |
| 116 | return | |
| 114 | 117 | end | 
| 115 | 118 | end | 
| 116 | render :action => 'edit' | |
| 119 | respond_to do |format| | |
| 120 |       format.html { render :action => 'edit' } | |
| 121 |       format.api { render_validation_errors(@attachments) } | |
| 122 | end | |
| 117 | 123 | end | 
| 118 | 124 | |
| 119 | 125 | def destroy | 
| test/integration/api_test/attachments_test.rb | ||
|---|---|---|
| 99 | 99 | assert_nil Attachment.find_by_id(7) | 
| 100 | 100 | end | 
| 101 | 101 | |
| 102 | test "PATCH /attachments/issues/:id.json should return ok and updated Attachment" do | |
| 103 |     token = json_upload('File content 1', credentials('jsmith')) | |
| 104 |  | |
| 105 | payload = <<-JSON | |
| 106 | { | |
| 107 |   "issue": { | |
| 108 | "project_id": "1", | |
| 109 | "tracker_id": "1", | |
| 110 | "subject": "Issue with attachment", | |
| 111 | "uploads": [ | |
| 112 |       {"token": "#{token}", "filename": "test1.txt", "description": "test1"} | |
| 113 | ] | |
| 114 | } | |
| 115 | } | |
| 116 | JSON | |
| 117 | ||
| 118 | assert_difference 'Issue.count' do | |
| 119 |       post '/issues.json', payload, {"CONTENT_TYPE" => 'application/json'}.merge(credentials('jsmith')) | |
| 120 | assert_response :created | |
| 121 | end | |
| 122 |  | |
| 123 |     issue = Issue.order('id DESC').first | |
| 124 | assert_equal 1, issue.attachments.count | |
| 125 |  | |
| 126 | attachment = issue.attachments.first | |
| 127 | attachment.filename = "test1_updated.txt" | |
| 128 | attachment.description = "test1_updated" | |
| 129 |  | |
| 130 | 	data = {:attachments => {attachment.id => {:filename => attachment.filename, :description => attachment.description}}} | |
| 131 |     patch "/attachments/issues/#{issue.id}.json", data, credentials('jsmith') | |
| 132 | assert_response :ok | |
| 133 |  | |
| 134 | updatedIssue = Issue.find(issue.id) | |
| 135 | updatedAttachment = updatedIssue.attachments.first; | |
| 136 |  | |
| 137 | assert_equal "Issue with attachment", updatedIssue.subject | |
| 138 | assert_equal "test1_updated.txt", updatedAttachment.filename | |
| 139 | assert_equal "test1_updated", updatedAttachment.description | |
| 140 | end | |
| 141 |  | |
| 102 | 142 | test "POST /uploads.xml should return the token" do | 
| 103 | 143 | set_tmp_attachments_directory | 
| 104 | 144 | assert_difference 'Attachment.count' do | 
- « Previous
- 1
- 2
- Next »