Merge remote-tracking branch 'upstream/pull/2280'
This commit is contained in:
commit
a66c34991a
5 changed files with 60 additions and 1 deletions
|
@ -9,6 +9,7 @@ class ApiAbility
|
||||||
can :index, :map
|
can :index, :map
|
||||||
can :show, :permission
|
can :show, :permission
|
||||||
can [:search_all, :search_nodes, :search_ways, :search_relations], :search
|
can [:search_all, :search_nodes, :search_ways, :search_relations], :search
|
||||||
|
can :show, :version
|
||||||
|
|
||||||
if Settings.status != "database_offline"
|
if Settings.status != "database_offline"
|
||||||
can [:show, :download, :query], Changeset
|
can [:show, :download, :query], Changeset
|
||||||
|
|
15
app/controllers/api/versions_controller.rb
Normal file
15
app/controllers/api/versions_controller.rb
Normal file
|
@ -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
|
8
app/views/api/versions/show.builder
Normal file
8
app/views/api/versions/show.builder
Normal file
|
@ -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
|
|
@ -1,7 +1,8 @@
|
||||||
OpenStreetMap::Application.routes.draw do
|
OpenStreetMap::Application.routes.draw do
|
||||||
# API
|
# API
|
||||||
namespace :api do
|
namespace :api do
|
||||||
get "capabilities" => "capabilities#show"
|
get "capabilities" => "capabilities#show" # Deprecated, remove when 0.6 support is removed
|
||||||
|
get "versions" => "versions#show"
|
||||||
end
|
end
|
||||||
|
|
||||||
scope "api/0.6" do
|
scope "api/0.6" do
|
||||||
|
|
34
test/controllers/api/versions_controller_test.rb
Normal file
34
test/controllers/api/versions_controller_test.rb
Normal file
|
@ -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
|
Loading…
Add table
Reference in a new issue