From 04afeeb32fae6ba52810db72d22449e548994de0 Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 7 Nov 2018 10:51:43 +0100 Subject: [PATCH 1/1] Rename hide_comment and unhide_comment to destroy and restore This preserves the API endpoints and HTTP methods, which could be changed in the next API version --- .../changeset_comments_controller.rb | 12 +++++----- config/routes.rb | 4 ++-- .../changeset_comments_controller_test.rb | 24 +++++++++---------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/controllers/changeset_comments_controller.rb b/app/controllers/changeset_comments_controller.rb index 856b12f20..6a563f9b2 100644 --- a/app/controllers/changeset_comments_controller.rb +++ b/app/controllers/changeset_comments_controller.rb @@ -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] diff --git a/config/routes.rb b/config/routes.rb index 20c3e253c..7c3bf0b94 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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+/ diff --git a/test/controllers/changeset_comments_controller_test.rb b/test/controllers/changeset_comments_controller_test.rb index 67df9aa88..10dfb1f88 100644 --- a/test/controllers/changeset_comments_controller_test.rb +++ b/test/controllers/changeset_comments_controller_test.rb @@ -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 -- 2.43.2