From b7e871cb466d317f39c45329564d49ad8402c6e4 Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 31 Oct 2018 20:01:01 +0100 Subject: [PATCH 1/1] Rename comment to create --- .../changeset_comments_controller.rb | 12 ++++++------ config/routes.rb | 2 +- .../changeset_comments_controller_test.rb | 18 +++++++++--------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/controllers/changeset_comments_controller.rb b/app/controllers/changeset_comments_controller.rb index 31e152560..21bd58e65 100644 --- a/app/controllers/changeset_comments_controller.rb +++ b/app/controllers/changeset_comments_controller.rb @@ -1,12 +1,12 @@ class ChangesetCommentsController < ApplicationController before_action :authorize_web, :only => [:comments_feed] before_action :set_locale, :only => [:comments_feed] - before_action :authorize, :only => [:comment, :hide_comment, :unhide_comment] + 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 => [:comment, :hide_comment, :unhide_comment] - before_action :require_public_data, :only => [:comment] - before_action :check_api_writable, :only => [:comment, :hide_comment, :unhide_comment] - before_action :check_api_readable, :except => [:comment, :comments_feed] + before_action :require_allow_write_api, :only => [:create, :hide_comment, :unhide_comment] + before_action :require_public_data, :only => [:create] + before_action :check_api_writable, :only => [:create, :hide_comment, :unhide_comment] + before_action :check_api_readable, :except => [:create, :comments_feed] before_action(:only => [:comments_feed]) { |c| c.check_database_readable(true) } around_action :api_call_handle_error, :except => [:comments_feed] around_action :api_call_timeout, :except => [:comments_feed] @@ -14,7 +14,7 @@ class ChangesetCommentsController < ApplicationController ## # Add a comment to a changeset - def comment + def create # Check the arguments are sane raise OSM::APIBadUserInput, "No id was given" unless params[:id] raise OSM::APIBadUserInput, "No text was given" if params[:text].blank? diff --git a/config/routes.rb b/config/routes.rb index 38ce38aa2..cf4fefcda 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,7 +16,7 @@ OpenStreetMap::Application.routes.draw do put "changeset/:id" => "changeset#update", :id => /\d+/ put "changeset/:id/close" => "changeset#close", :id => /\d+/ get "changesets" => "changeset#query" - post "changeset/:id/comment" => "changeset_comments#comment", :as => :changeset_comment, :id => /\d+/ + 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+/ diff --git a/test/controllers/changeset_comments_controller_test.rb b/test/controllers/changeset_comments_controller_test.rb index 215f45957..ed15d34a8 100644 --- a/test/controllers/changeset_comments_controller_test.rb +++ b/test/controllers/changeset_comments_controller_test.rb @@ -6,7 +6,7 @@ class ChangesetCommentsControllerTest < ActionController::TestCase def test_routes assert_routing( { :path => "/api/0.6/changeset/1/comment", :method => :post }, - { :controller => "changeset_comments", :action => "comment", :id => "1" } + { :controller => "changeset_comments", :action => "create", :id => "1" } ) assert_routing( { :path => "/api/0.6/changeset/comment/1/hide", :method => :post }, @@ -41,7 +41,7 @@ class ChangesetCommentsControllerTest < ActionController::TestCase assert_difference "ChangesetComment.count", 1 do assert_no_difference "ActionMailer::Base.deliveries.size" do perform_enqueued_jobs do - post :comment, :params => { :id => private_user_closed_changeset.id, :text => "This is a comment" } + post :create, :params => { :id => private_user_closed_changeset.id, :text => "This is a comment" } end end end @@ -56,7 +56,7 @@ class ChangesetCommentsControllerTest < ActionController::TestCase assert_difference "ChangesetComment.count", 1 do assert_difference "ActionMailer::Base.deliveries.size", 1 do perform_enqueued_jobs do - post :comment, :params => { :id => changeset.id, :text => "This is a comment" } + post :create, :params => { :id => changeset.id, :text => "This is a comment" } end end end @@ -74,7 +74,7 @@ class ChangesetCommentsControllerTest < ActionController::TestCase assert_difference "ChangesetComment.count", 1 do assert_difference "ActionMailer::Base.deliveries.size", 2 do perform_enqueued_jobs do - post :comment, :params => { :id => changeset.id, :text => "This is a comment" } + post :create, :params => { :id => changeset.id, :text => "This is a comment" } end end end @@ -97,32 +97,32 @@ class ChangesetCommentsControllerTest < ActionController::TestCase # create comment fail def test_create_comment_fail # unauthorized - post :comment, :params => { :id => create(:changeset, :closed).id, :text => "This is a comment" } + post :create, :params => { :id => create(:changeset, :closed).id, :text => "This is a comment" } assert_response :unauthorized basic_authorization create(:user).email, "test" # bad changeset id assert_no_difference "ChangesetComment.count" do - post :comment, :params => { :id => 999111, :text => "This is a comment" } + post :create, :params => { :id => 999111, :text => "This is a comment" } end assert_response :not_found # not closed changeset assert_no_difference "ChangesetComment.count" do - post :comment, :params => { :id => create(:changeset).id, :text => "This is a comment" } + post :create, :params => { :id => create(:changeset).id, :text => "This is a comment" } end assert_response :conflict # no text assert_no_difference "ChangesetComment.count" do - post :comment, :params => { :id => create(:changeset, :closed).id } + post :create, :params => { :id => create(:changeset, :closed).id } end assert_response :bad_request # empty text assert_no_difference "ChangesetComment.count" do - post :comment, :params => { :id => create(:changeset, :closed).id, :text => "" } + post :create, :params => { :id => create(:changeset, :closed).id, :text => "" } end assert_response :bad_request end -- 2.43.2