From 05117aa92835a65118754da4c0aa6f36096634ae Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 7 Nov 2018 15:53:04 +0100 Subject: [PATCH] Pluralize nodes, ways and relations controllers --- .rubocop_todo.yml | 2 +- ...node_controller.rb => nodes_controller.rb} | 2 +- ..._controller.rb => relations_controller.rb} | 2 +- .../{way_controller.rb => ways_controller.rb} | 2 +- app/views/browse/feature.html.erb | 2 +- config/routes.rb | 42 +++++++++---------- test/controllers/changeset_controller_test.rb | 8 ++-- ...oller_test.rb => nodes_controller_test.rb} | 12 +++--- test/controllers/old_node_controller_test.rb | 10 ++--- .../old_relation_controller_test.rb | 2 +- test/controllers/old_way_controller_test.rb | 2 +- ...r_test.rb => relations_controller_test.rb} | 21 +++++----- ...roller_test.rb => ways_controller_test.rb} | 15 ++++--- 13 files changed, 60 insertions(+), 62 deletions(-) rename app/controllers/{node_controller.rb => nodes_controller.rb} (98%) rename app/controllers/{relation_controller.rb => relations_controller.rb} (99%) rename app/controllers/{way_controller.rb => ways_controller.rb} (98%) rename test/controllers/{node_controller_test.rb => nodes_controller_test.rb} (98%) rename test/controllers/{relation_controller_test.rb => relations_controller_test.rb} (98%) rename test/controllers/{way_controller_test.rb => ways_controller_test.rb} (98%) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7d2c583eb..e6ecfdb4a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -177,7 +177,7 @@ Style/FrozenStringLiteralComment: # Cop supports --auto-correct. Style/IfUnlessModifier: Exclude: - - 'app/controllers/way_controller.rb' + - 'app/controllers/ways_controller.rb' # Offense count: 70 # Cop supports --auto-correct. diff --git a/app/controllers/node_controller.rb b/app/controllers/nodes_controller.rb similarity index 98% rename from app/controllers/node_controller.rb rename to app/controllers/nodes_controller.rb index 84b814a34..baa6d8195 100644 --- a/app/controllers/node_controller.rb +++ b/app/controllers/nodes_controller.rb @@ -1,6 +1,6 @@ # The NodeController is the RESTful interface to Node objects -class NodeController < ApplicationController +class NodesController < ApplicationController require "xml/libxml" skip_before_action :verify_authenticity_token diff --git a/app/controllers/relation_controller.rb b/app/controllers/relations_controller.rb similarity index 99% rename from app/controllers/relation_controller.rb rename to app/controllers/relations_controller.rb index 059fb8d7e..b9108cea1 100644 --- a/app/controllers/relation_controller.rb +++ b/app/controllers/relations_controller.rb @@ -1,4 +1,4 @@ -class RelationController < ApplicationController +class RelationsController < ApplicationController require "xml/libxml" skip_before_action :verify_authenticity_token diff --git a/app/controllers/way_controller.rb b/app/controllers/ways_controller.rb similarity index 98% rename from app/controllers/way_controller.rb rename to app/controllers/ways_controller.rb index e48073e10..39129ebf3 100644 --- a/app/controllers/way_controller.rb +++ b/app/controllers/ways_controller.rb @@ -1,4 +1,4 @@ -class WayController < ApplicationController +class WaysController < ApplicationController require "xml/libxml" skip_before_action :verify_authenticity_token diff --git a/app/views/browse/feature.html.erb b/app/views/browse/feature.html.erb index 38657f4d1..c3fadbe31 100644 --- a/app/views/browse/feature.html.erb +++ b/app/views/browse/feature.html.erb @@ -8,7 +8,7 @@ <%= render :partial => @type, :object => @feature %>
- <%= link_to(t('browse.download_xml'), :controller => @type, :action => "read") %> + <%= link_to(t('browse.download_xml'), :controller => @type.pluralize, :action => "read") %> · <%= link_to(t('browse.view_history'), :action => "#{@type}_history") %>
diff --git a/config/routes.rb b/config/routes.rb index 7d9c8dbec..235ffdba3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,38 +20,38 @@ OpenStreetMap::Application.routes.draw do post "changeset/comment/:id/hide" => "changeset#hide_comment", :as => :changeset_comment_hide, :id => /\d+/ post "changeset/comment/:id/unhide" => "changeset#unhide_comment", :as => :changeset_comment_unhide, :id => /\d+/ - put "node/create" => "node#create" - get "node/:id/ways" => "way#ways_for_node", :id => /\d+/ - get "node/:id/relations" => "relation#relations_for_node", :id => /\d+/ + put "node/create" => "nodes#create" + get "node/:id/ways" => "ways#ways_for_node", :id => /\d+/ + get "node/:id/relations" => "relations#relations_for_node", :id => /\d+/ get "node/:id/history" => "old_node#history", :id => /\d+/ post "node/:id/:version/redact" => "old_node#redact", :version => /\d+/, :id => /\d+/ get "node/:id/:version" => "old_node#version", :id => /\d+/, :version => /\d+/ - get "node/:id" => "node#read", :id => /\d+/ - put "node/:id" => "node#update", :id => /\d+/ - delete "node/:id" => "node#delete", :id => /\d+/ - get "nodes" => "node#nodes" + get "node/:id" => "nodes#read", :id => /\d+/ + put "node/:id" => "nodes#update", :id => /\d+/ + delete "node/:id" => "nodes#delete", :id => /\d+/ + get "nodes" => "nodes#nodes" - put "way/create" => "way#create" + put "way/create" => "ways#create" get "way/:id/history" => "old_way#history", :id => /\d+/ - get "way/:id/full" => "way#full", :id => /\d+/ - get "way/:id/relations" => "relation#relations_for_way", :id => /\d+/ + get "way/:id/full" => "ways#full", :id => /\d+/ + get "way/:id/relations" => "relations#relations_for_way", :id => /\d+/ post "way/:id/:version/redact" => "old_way#redact", :version => /\d+/, :id => /\d+/ get "way/:id/:version" => "old_way#version", :id => /\d+/, :version => /\d+/ - get "way/:id" => "way#read", :id => /\d+/ - put "way/:id" => "way#update", :id => /\d+/ - delete "way/:id" => "way#delete", :id => /\d+/ - get "ways" => "way#ways" + get "way/:id" => "ways#read", :id => /\d+/ + put "way/:id" => "ways#update", :id => /\d+/ + delete "way/:id" => "ways#delete", :id => /\d+/ + get "ways" => "ways#ways" - put "relation/create" => "relation#create" - get "relation/:id/relations" => "relation#relations_for_relation", :id => /\d+/ + put "relation/create" => "relations#create" + get "relation/:id/relations" => "relations#relations_for_relation", :id => /\d+/ get "relation/:id/history" => "old_relation#history", :id => /\d+/ - get "relation/:id/full" => "relation#full", :id => /\d+/ + get "relation/:id/full" => "relations#full", :id => /\d+/ post "relation/:id/:version/redact" => "old_relation#redact", :version => /\d+/, :id => /\d+/ get "relation/:id/:version" => "old_relation#version", :id => /\d+/, :version => /\d+/ - get "relation/:id" => "relation#read", :id => /\d+/ - put "relation/:id" => "relation#update", :id => /\d+/ - delete "relation/:id" => "relation#delete", :id => /\d+/ - get "relations" => "relation#relations" + get "relation/:id" => "relations#read", :id => /\d+/ + put "relation/:id" => "relations#update", :id => /\d+/ + delete "relation/:id" => "relations#delete", :id => /\d+/ + get "relations" => "relations#relations" get "map" => "api#map" diff --git a/test/controllers/changeset_controller_test.rb b/test/controllers/changeset_controller_test.rb index fdb689978..472ebb259 100644 --- a/test/controllers/changeset_controller_test.rb +++ b/test/controllers/changeset_controller_test.rb @@ -1528,7 +1528,7 @@ CHANGESET changeset_id = @response.body.to_i # add a single node to it - with_controller(NodeController.new) do + with_controller(NodesController.new) do content "" put :create assert_response :success, "Couldn't create node." @@ -1543,7 +1543,7 @@ CHANGESET assert_select "osm>changeset[max_lat='2.0000000']", 1 # add another node to it - with_controller(NodeController.new) do + with_controller(NodesController.new) do content "" put :create assert_response :success, "Couldn't create second node." @@ -1558,7 +1558,7 @@ CHANGESET assert_select "osm>changeset[max_lat='2.0000000']", 1 # add (delete) a way to it, which contains a point at (3,3) - with_controller(WayController.new) do + with_controller(WaysController.new) do content update_changeset(way.to_xml, changeset_id) put :delete, :params => { :id => way.id } assert_response :success, "Couldn't delete a way." @@ -1838,7 +1838,7 @@ CHANGESET changeset.num_changes = Changeset::MAX_ELEMENTS - offset changeset.save! - with_controller(NodeController.new) do + with_controller(NodesController.new) do # create a new node content "" put :create diff --git a/test/controllers/node_controller_test.rb b/test/controllers/nodes_controller_test.rb similarity index 98% rename from test/controllers/node_controller_test.rb rename to test/controllers/nodes_controller_test.rb index 5f737f798..3cd4244e1 100644 --- a/test/controllers/node_controller_test.rb +++ b/test/controllers/nodes_controller_test.rb @@ -1,28 +1,28 @@ require "test_helper" -class NodeControllerTest < ActionController::TestCase +class NodesControllerTest < ActionController::TestCase ## # test all routes which lead to this controller def test_routes assert_routing( { :path => "/api/0.6/node/create", :method => :put }, - { :controller => "node", :action => "create" } + { :controller => "nodes", :action => "create" } ) assert_routing( { :path => "/api/0.6/node/1", :method => :get }, - { :controller => "node", :action => "read", :id => "1" } + { :controller => "nodes", :action => "read", :id => "1" } ) assert_routing( { :path => "/api/0.6/node/1", :method => :put }, - { :controller => "node", :action => "update", :id => "1" } + { :controller => "nodes", :action => "update", :id => "1" } ) assert_routing( { :path => "/api/0.6/node/1", :method => :delete }, - { :controller => "node", :action => "delete", :id => "1" } + { :controller => "nodes", :action => "delete", :id => "1" } ) assert_routing( { :path => "/api/0.6/nodes", :method => :get }, - { :controller => "node", :action => "nodes" } + { :controller => "nodes", :action => "nodes" } ) end diff --git a/test/controllers/old_node_controller_test.rb b/test/controllers/old_node_controller_test.rb index 346634f7d..0d8db0589 100644 --- a/test/controllers/old_node_controller_test.rb +++ b/test/controllers/old_node_controller_test.rb @@ -59,7 +59,7 @@ class OldNodeControllerTest < ActionController::TestCase # move the node somewhere else xml_node["lat"] = precision(rand * 180 - 90).to_s xml_node["lon"] = precision(rand * 360 - 180).to_s - with_controller(NodeController.new) do + with_controller(NodesController.new) do content xml_doc put :update, :params => { :id => nodeid } assert_response :forbidden, "Should have rejected node update" @@ -75,7 +75,7 @@ class OldNodeControllerTest < ActionController::TestCase xml_tag["k"] = random_string xml_tag["v"] = random_string xml_node << xml_tag - with_controller(NodeController.new) do + with_controller(NodesController.new) do content xml_doc put :update, :params => { :id => nodeid } assert_response :forbidden, @@ -109,7 +109,7 @@ class OldNodeControllerTest < ActionController::TestCase # move the node somewhere else xml_node["lat"] = precision(rand * 180 - 90).to_s xml_node["lon"] = precision(rand * 360 - 180).to_s - with_controller(NodeController.new) do + with_controller(NodesController.new) do content xml_doc put :update, :params => { :id => nodeid } assert_response :success @@ -125,7 +125,7 @@ class OldNodeControllerTest < ActionController::TestCase xml_tag["k"] = random_string xml_tag["v"] = random_string xml_node << xml_tag - with_controller(NodeController.new) do + with_controller(NodesController.new) do content xml_doc put :update, :params => { :id => nodeid } assert_response :success, @@ -390,7 +390,7 @@ class OldNodeControllerTest < ActionController::TestCase def check_current_version(node_id) # get the current version of the node - current_node = with_controller(NodeController.new) do + current_node = with_controller(NodesController.new) do get :read, :params => { :id => node_id } assert_response :success, "cant get current node #{node_id}" Node.from_xml(@response.body) diff --git a/test/controllers/old_relation_controller_test.rb b/test/controllers/old_relation_controller_test.rb index be91962f8..c6f43dbdc 100644 --- a/test/controllers/old_relation_controller_test.rb +++ b/test/controllers/old_relation_controller_test.rb @@ -225,7 +225,7 @@ class OldRelationControllerTest < ActionController::TestCase # version which we're getting from the versions call. def check_current_version(relation_id) # get the current version - current_relation = with_controller(RelationController.new) do + current_relation = with_controller(RelationsController.new) do get :read, :params => { :id => relation_id } assert_response :success, "can't get current relation #{relation_id}" Relation.from_xml(@response.body) diff --git a/test/controllers/old_way_controller_test.rb b/test/controllers/old_way_controller_test.rb index 1fff79187..168ce87dd 100644 --- a/test/controllers/old_way_controller_test.rb +++ b/test/controllers/old_way_controller_test.rb @@ -265,7 +265,7 @@ class OldWayControllerTest < ActionController::TestCase # version which we're getting from the versions call. def check_current_version(way_id) # get the current version - current_way = with_controller(WayController.new) do + current_way = with_controller(WaysController.new) do get :read, :params => { :id => way_id } assert_response :success, "can't get current way #{way_id}" Way.from_xml(@response.body) diff --git a/test/controllers/relation_controller_test.rb b/test/controllers/relations_controller_test.rb similarity index 98% rename from test/controllers/relation_controller_test.rb rename to test/controllers/relations_controller_test.rb index 8a7e8b2fe..be0f6c1d7 100644 --- a/test/controllers/relation_controller_test.rb +++ b/test/controllers/relations_controller_test.rb @@ -1,46 +1,45 @@ require "test_helper" -require "relation_controller" -class RelationControllerTest < ActionController::TestCase +class RelationsControllerTest < ActionController::TestCase ## # test all routes which lead to this controller def test_routes assert_routing( { :path => "/api/0.6/relation/create", :method => :put }, - { :controller => "relation", :action => "create" } + { :controller => "relations", :action => "create" } ) assert_routing( { :path => "/api/0.6/relation/1/full", :method => :get }, - { :controller => "relation", :action => "full", :id => "1" } + { :controller => "relations", :action => "full", :id => "1" } ) assert_routing( { :path => "/api/0.6/relation/1", :method => :get }, - { :controller => "relation", :action => "read", :id => "1" } + { :controller => "relations", :action => "read", :id => "1" } ) assert_routing( { :path => "/api/0.6/relation/1", :method => :put }, - { :controller => "relation", :action => "update", :id => "1" } + { :controller => "relations", :action => "update", :id => "1" } ) assert_routing( { :path => "/api/0.6/relation/1", :method => :delete }, - { :controller => "relation", :action => "delete", :id => "1" } + { :controller => "relations", :action => "delete", :id => "1" } ) assert_routing( { :path => "/api/0.6/relations", :method => :get }, - { :controller => "relation", :action => "relations" } + { :controller => "relations", :action => "relations" } ) assert_routing( { :path => "/api/0.6/node/1/relations", :method => :get }, - { :controller => "relation", :action => "relations_for_node", :id => "1" } + { :controller => "relations", :action => "relations_for_node", :id => "1" } ) assert_routing( { :path => "/api/0.6/way/1/relations", :method => :get }, - { :controller => "relation", :action => "relations_for_way", :id => "1" } + { :controller => "relations", :action => "relations_for_way", :id => "1" } ) assert_routing( { :path => "/api/0.6/relation/1/relations", :method => :get }, - { :controller => "relation", :action => "relations_for_relation", :id => "1" } + { :controller => "relations", :action => "relations_for_relation", :id => "1" } ) end diff --git a/test/controllers/way_controller_test.rb b/test/controllers/ways_controller_test.rb similarity index 98% rename from test/controllers/way_controller_test.rb rename to test/controllers/ways_controller_test.rb index 3d466de8b..1199e5d94 100644 --- a/test/controllers/way_controller_test.rb +++ b/test/controllers/ways_controller_test.rb @@ -1,33 +1,32 @@ require "test_helper" -require "way_controller" -class WayControllerTest < ActionController::TestCase +class WaysControllerTest < ActionController::TestCase ## # test all routes which lead to this controller def test_routes assert_routing( { :path => "/api/0.6/way/create", :method => :put }, - { :controller => "way", :action => "create" } + { :controller => "ways", :action => "create" } ) assert_routing( { :path => "/api/0.6/way/1/full", :method => :get }, - { :controller => "way", :action => "full", :id => "1" } + { :controller => "ways", :action => "full", :id => "1" } ) assert_routing( { :path => "/api/0.6/way/1", :method => :get }, - { :controller => "way", :action => "read", :id => "1" } + { :controller => "ways", :action => "read", :id => "1" } ) assert_routing( { :path => "/api/0.6/way/1", :method => :put }, - { :controller => "way", :action => "update", :id => "1" } + { :controller => "ways", :action => "update", :id => "1" } ) assert_routing( { :path => "/api/0.6/way/1", :method => :delete }, - { :controller => "way", :action => "delete", :id => "1" } + { :controller => "ways", :action => "delete", :id => "1" } ) assert_routing( { :path => "/api/0.6/ways", :method => :get }, - { :controller => "way", :action => "ways" } + { :controller => "ways", :action => "ways" } ) end -- 2.43.2