]> git.openstreetmap.org Git - rails.git/commitdiff
Return an updated copy of the note from the delete call
authorTom Hughes <tom@compton.nu>
Mon, 8 Apr 2013 20:48:06 +0000 (21:48 +0100)
committerTom Hughes <tom@compton.nu>
Mon, 8 Apr 2013 21:00:26 +0000 (22:00 +0100)
app/controllers/notes_controller.rb
test/functional/notes_controller_test.rb

index e79be2e8d31b4605ccaebff60c2a3ca5fa644c42..36236ef106e780a87c766a45f9e3e65babc7fbad 100644 (file)
@@ -198,20 +198,23 @@ class NotesController < ApplicationController
     comment = params[:text]
 
     # Find the note and check it is valid
-    note = Note.find(id)
-    raise OSM::APINotFoundError unless note
-    raise OSM::APIAlreadyDeletedError.new("note", note.id) unless note.visible?
+    @note = Note.find(id)
+    raise OSM::APINotFoundError unless @note
+    raise OSM::APIAlreadyDeletedError.new("note", @note.id) unless @note.visible?
 
     # Mark the note as hidden
     Note.transaction do
-      note.status = "hidden"
-      note.save
+      @note.status = "hidden"
+      @note.save
 
-      add_comment(note, comment, "hidden")
+      add_comment(@note, comment, "hidden")
     end
 
-    # Render the result
-    render :text => "ok\n", :content_type => "text/html" 
+    # Return a copy of the updated note
+    respond_to do |format|
+      format.xml { render :action => :show }
+      format.json { render :action => :show }
+    end
   end
 
   ##
index bfea295925f35efe00a1de152b523d166cd4f83a..4bd0aa6cf418b09b6997c640d93ab12107796dbe 100644 (file)
@@ -343,38 +343,47 @@ class NotesControllerTest < ActionController::TestCase
   end
 
   def test_note_delete_success
-    delete :destroy, {:id => notes(:open_note_with_comment).id}
+    delete :destroy, {:id => notes(:open_note_with_comment).id, :text => "This is a hide comment", :format => "json"}
     assert_response :unauthorized
 
     basic_authorization(users(:public_user).email, "test")
 
-    delete :destroy, {:id => notes(:open_note_with_comment).id}
+    delete :destroy, {:id => notes(:open_note_with_comment).id, :text => "This is a hide comment", :format => "json"}
     assert_response :forbidden
 
     basic_authorization(users(:moderator_user).email, "test")
 
-    delete :destroy, {:id => notes(:open_note_with_comment).id}
+    delete :destroy, {:id => notes(:open_note_with_comment).id, :text => "This is a hide comment", :format => "json"}
     assert_response :success
+    js = ActiveSupport::JSON.decode(@response.body)
+    assert_not_nil js
+    assert_equal "Feature", js["type"]
+    assert_equal notes(:open_note_with_comment).id, js["properties"]["id"]
+    assert_equal "hidden", js["properties"]["status"]
+    assert_equal 3, js["properties"]["comments"].count
+    assert_equal "hidden", js["properties"]["comments"].last["action"]
+    assert_equal "This is a hide comment", js["properties"]["comments"].last["text"]
+    assert_equal "moderator", js["properties"]["comments"].last["user"]
 
     get :show, {:id => notes(:open_note_with_comment).id, :format => 'json'}
     assert_response :gone
   end
 
   def test_note_delete_fail
-    delete :destroy, {:id => 12345}
+    delete :destroy, {:id => 12345, :format => "json"}
     assert_response :unauthorized
 
     basic_authorization(users(:public_user).email, "test")
 
-    delete :destroy, {:id => 12345}
+    delete :destroy, {:id => 12345, :format => "json"}
     assert_response :forbidden
 
     basic_authorization(users(:moderator_user).email, "test")
 
-    delete :destroy, {:id => 12345}
+    delete :destroy, {:id => 12345, :format => "json"}
     assert_response :not_found
 
-    delete :destroy, {:id => notes(:hidden_note_with_comment).id}
+    delete :destroy, {:id => notes(:hidden_note_with_comment).id, :format => "json"}
     assert_response :gone
   end