]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/2280'
authorTom Hughes <tom@compton.nu>
Wed, 26 Jun 2019 18:57:12 +0000 (19:57 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 26 Jun 2019 18:57:12 +0000 (19:57 +0100)
app/abilities/api_ability.rb
app/controllers/api/versions_controller.rb [new file with mode: 0644]
app/views/api/versions/show.builder [new file with mode: 0644]
config/routes.rb
test/controllers/api/versions_controller_test.rb [new file with mode: 0644]

index 9fc3cdd9cdb78fa659ef8234b6cae9483d3b64a5..80245eeaa34882e6acd71d3930436b5d9d13f4d1 100644 (file)
@@ -9,6 +9,7 @@ class ApiAbility
     can :index, :map
     can :show, :permission
     can [:search_all, :search_nodes, :search_ways, :search_relations], :search
+    can :show, :version
 
     if Settings.status != "database_offline"
       can [:show, :download, :query], Changeset
diff --git a/app/controllers/api/versions_controller.rb b/app/controllers/api/versions_controller.rb
new file mode 100644 (file)
index 0000000..7de3350
--- /dev/null
@@ -0,0 +1,15 @@
+module Api
+  class VersionsController < ApiController
+    authorize_resource :class => false
+
+    around_action :api_call_handle_error, :api_call_timeout
+
+    # Show the list of available API versions. This will replace the global
+    # unversioned capabilities call in due course.
+    # Currently we only support deploying one version at a time, but this will
+    # hopefully change soon.
+    def show
+      @versions = [Settings.api_version]
+    end
+  end
+end
diff --git a/app/views/api/versions/show.builder b/app/views/api/versions/show.builder
new file mode 100644 (file)
index 0000000..ed20915
--- /dev/null
@@ -0,0 +1,8 @@
+xml.instruct! :xml, :version => "1.0"
+xml.osm(OSM::API.new.xml_root_attributes.except("version")) do |osm|
+  osm.api do |api|
+    @versions.each do |version|
+      api.version version
+    end
+  end
+end
index 7689b506da0a9dad5a16827684f33c7dc0113894..002ee58ea3347c1b730cbe8e0792b2de6f6d2d15 100644 (file)
@@ -1,7 +1,8 @@
 OpenStreetMap::Application.routes.draw do
   # API
   namespace :api do
-    get "capabilities" => "capabilities#show"
+    get "capabilities" => "capabilities#show" # Deprecated, remove when 0.6 support is removed
+    get "versions" => "versions#show"
   end
 
   scope "api/0.6" do
diff --git a/test/controllers/api/versions_controller_test.rb b/test/controllers/api/versions_controller_test.rb
new file mode 100644 (file)
index 0000000..f7f5140
--- /dev/null
@@ -0,0 +1,34 @@
+require "test_helper"
+
+module Api
+  class VersionsControllerTest < ActionController::TestCase
+    ##
+    # test all routes which lead to this controller
+    def test_routes
+      assert_routing(
+        { :path => "/api/versions", :method => :get },
+        { :controller => "api/versions", :action => "show" }
+      )
+      assert_recognizes(
+        { :controller => "api/versions", :action => "show" },
+        { :path => "/api/versions", :method => :get }
+      )
+    end
+
+    def test_versions
+      get :show
+      assert_response :success
+      assert_select "osm[generator='#{Settings.generator}']", :count => 1 do
+        assert_select "api", :count => 1 do
+          assert_select "version", Settings.api_version
+        end
+      end
+    end
+
+    def test_no_version_in_root_element
+      get :show
+      assert_response :success
+      assert_select "osm[version]", :count => 0
+    end
+  end
+end