]> git.openstreetmap.org Git - rails.git/commitdiff
Rename hide_comment and unhide_comment to destroy and restore
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 7 Nov 2018 09:51:43 +0000 (10:51 +0100)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 7 Nov 2018 09:51:43 +0000 (10:51 +0100)
This preserves the API endpoints and HTTP methods, which could be changed in the next API version

app/controllers/changeset_comments_controller.rb
config/routes.rb
test/controllers/changeset_comments_controller_test.rb

index 856b12f20e587063c24f80271e41d31c012c6c66..6a563f9b2c5cb92393260a77baedf3aa96b99f79 100644 (file)
@@ -1,11 +1,11 @@
 class ChangesetCommentsController < ApplicationController
   before_action :authorize_web, :only => [:index]
   before_action :set_locale, :only => [:index]
-  before_action :authorize, :only => [:create, :hide_comment, :unhide_comment]
-  before_action :require_moderator, :only => [:hide_comment, :unhide_comment]
-  before_action :require_allow_write_api, :only => [:create, :hide_comment, :unhide_comment]
+  before_action :authorize, :only => [:create, :destroy, :restore]
+  before_action :require_moderator, :only => [:destroy, :restore]
+  before_action :require_allow_write_api, :only => [:create, :destroy, :restore]
   before_action :require_public_data, :only => [:create]
-  before_action :check_api_writable, :only => [:create, :hide_comment, :unhide_comment]
+  before_action :check_api_writable, :only => [:create, :destroy, :restore]
   before_action :check_api_readable, :except => [:create, :index]
   before_action(:only => [:index]) { |c| c.check_database_readable(true) }
   around_action :api_call_handle_error, :except => [:index]
@@ -46,7 +46,7 @@ class ChangesetCommentsController < ApplicationController
 
   ##
   # Sets visible flag on comment to false
-  def hide_comment
+  def destroy
     # Check the arguments are sane
     raise OSM::APIBadUserInput, "No id was given" unless params[:id]
 
@@ -65,7 +65,7 @@ class ChangesetCommentsController < ApplicationController
 
   ##
   # Sets visible flag on comment to true
-  def unhide_comment
+  def restore
     # Check the arguments are sane
     raise OSM::APIBadUserInput, "No id was given" unless params[:id]
 
index 20c3e253c71e53394c366a002482271ae0def588..7c3bf0b94a28d1bcb22121c6d9565054e8fb743d 100644 (file)
@@ -17,8 +17,8 @@ OpenStreetMap::Application.routes.draw do
     put "changeset/:id/close" => "changeset#close", :id => /\d+/
     get "changesets" => "changeset#query"
     post "changeset/:id/comment" => "changeset_comments#create", :as => :changeset_comment, :id => /\d+/
-    post "changeset/comment/:id/hide" => "changeset_comments#hide_comment", :as => :changeset_comment_hide, :id => /\d+/
-    post "changeset/comment/:id/unhide" => "changeset_comments#unhide_comment", :as => :changeset_comment_unhide, :id => /\d+/
+    post "changeset/comment/:id/hide" => "changeset_comments#destroy", :as => :changeset_comment_hide, :id => /\d+/
+    post "changeset/comment/:id/unhide" => "changeset_comments#restore", :as => :changeset_comment_unhide, :id => /\d+/
 
     put "node/create" => "node#create"
     get "node/:id/ways" => "way#ways_for_node", :id => /\d+/
index 67df9aa882f7910875190afa4bcec860138bf243..10dfb1f88514547df8a108c56c8047f9dc17d2a6 100644 (file)
@@ -10,11 +10,11 @@ class ChangesetCommentsControllerTest < ActionController::TestCase
     )
     assert_routing(
       { :path => "/api/0.6/changeset/comment/1/hide", :method => :post },
-      { :controller => "changeset_comments", :action => "hide_comment", :id => "1" }
+      { :controller => "changeset_comments", :action => "destroy", :id => "1" }
     )
     assert_routing(
       { :path => "/api/0.6/changeset/comment/1/unhide", :method => :post },
-      { :controller => "changeset_comments", :action => "unhide_comment", :id => "1" }
+      { :controller => "changeset_comments", :action => "restore", :id => "1" }
     )
     assert_routing(
       { :path => "/changeset/1/comments/feed", :method => :get },
@@ -129,26 +129,26 @@ class ChangesetCommentsControllerTest < ActionController::TestCase
 
   ##
   # test hide comment fail
-  def test_hide_comment_fail
+  def test_destroy_comment_fail
     # unauthorized
     comment = create(:changeset_comment)
     assert_equal true, comment.visible
 
-    post :hide_comment, :params => { :id => comment.id }
+    post :destroy, :params => { :id => comment.id }
     assert_response :unauthorized
     assert_equal true, comment.reload.visible
 
     basic_authorization create(:user).email, "test"
 
     # not a moderator
-    post :hide_comment, :params => { :id => comment.id }
+    post :destroy, :params => { :id => comment.id }
     assert_response :forbidden
     assert_equal true, comment.reload.visible
 
     basic_authorization create(:moderator_user).email, "test"
 
     # bad comment id
-    post :hide_comment, :params => { :id => 999111 }
+    post :destroy, :params => { :id => 999111 }
     assert_response :not_found
     assert_equal true, comment.reload.visible
   end
@@ -161,33 +161,33 @@ class ChangesetCommentsControllerTest < ActionController::TestCase
 
     basic_authorization create(:moderator_user).email, "test"
 
-    post :hide_comment, :params => { :id => comment.id }
+    post :destroy, :params => { :id => comment.id }
     assert_response :success
     assert_equal false, comment.reload.visible
   end
 
   ##
   # test unhide comment fail
-  def test_unhide_comment_fail
+  def test_restore_comment_fail
     # unauthorized
     comment = create(:changeset_comment, :visible => false)
     assert_equal false, comment.visible
 
-    post :unhide_comment, :params => { :id => comment.id }
+    post :restore, :params => { :id => comment.id }
     assert_response :unauthorized
     assert_equal false, comment.reload.visible
 
     basic_authorization create(:user).email, "test"
 
     # not a moderator
-    post :unhide_comment, :params => { :id => comment.id }
+    post :restore, :params => { :id => comment.id }
     assert_response :forbidden
     assert_equal false, comment.reload.visible
 
     basic_authorization create(:moderator_user).email, "test"
 
     # bad comment id
-    post :unhide_comment, :params => { :id => 999111 }
+    post :restore, :params => { :id => 999111 }
     assert_response :not_found
     assert_equal false, comment.reload.visible
   end
@@ -200,7 +200,7 @@ class ChangesetCommentsControllerTest < ActionController::TestCase
 
     basic_authorization create(:moderator_user).email, "test"
 
-    post :unhide_comment, :params => { :id => comment.id }
+    post :restore, :params => { :id => comment.id }
     assert_response :success
     assert_equal true, comment.reload.visible
   end