]> git.openstreetmap.org Git - rails.git/blob - test/controllers/api/capabilities_controller_test.rb
aa8e21938b149ffe13ca0f0a7e03fb107c3786d1
[rails.git] / test / controllers / api / capabilities_controller_test.rb
1 require "test_helper"
2
3 module Api
4   class CapabilitiesControllerTest < ActionDispatch::IntegrationTest
5     ##
6     # test all routes which lead to this controller
7     def test_routes
8       assert_routing(
9         { :path => "/api/capabilities", :method => :get },
10         { :controller => "api/capabilities", :action => "show" }
11       )
12       assert_routing(
13         { :path => "/api/capabilities.json", :method => :get },
14         { :controller => "api/capabilities", :action => "show", :format => "json" }
15       )
16       assert_recognizes(
17         { :controller => "api/capabilities", :action => "show" },
18         { :path => "/api/0.6/capabilities", :method => :get }
19       )
20       assert_recognizes(
21         { :controller => "api/capabilities", :action => "show", :format => "json" },
22         { :path => "/api/0.6/capabilities.json", :method => :get }
23       )
24     end
25
26     def test_capabilities
27       get api_capabilities_path
28       assert_response :success
29       assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
30         assert_select "api", :count => 1 do
31           assert_select "version[minimum='#{Settings.api_version}'][maximum='#{Settings.api_version}']", :count => 1
32           assert_select "area[maximum='#{Settings.max_request_area}']", :count => 1
33           assert_select "note_area[maximum='#{Settings.max_note_request_area}']", :count => 1
34           assert_select "tracepoints[per_page='#{Settings.tracepoints_per_page}']", :count => 1
35           assert_select "changesets[maximum_elements='#{Changeset::MAX_ELEMENTS}']", :count => 1
36           assert_select "relationmembers[maximum='#{Settings.max_number_of_relation_members}']", :count => 1
37           assert_select "status[database='online']", :count => 1
38           assert_select "status[api='online']", :count => 1
39           assert_select "status[gpx='online']", :count => 1
40         end
41       end
42     end
43
44     def test_capabilities_json
45       get api_capabilities_path, :params => { :format => "json" }
46       assert_response :success
47       js = ActiveSupport::JSON.decode(@response.body)
48       assert_not_nil js
49
50       assert_equal Settings.api_version, js["version"]
51       assert_equal Settings.generator, js["generator"]
52       assert_equal Settings.api_version, js["api"]["version"]["minimum"]
53       assert_equal Settings.api_version, js["api"]["version"]["maximum"]
54       assert_equal Settings.max_request_area, js["api"]["area"]["maximum"]
55       assert_equal Settings.max_note_request_area, js["api"]["note_area"]["maximum"]
56       assert_equal Settings.tracepoints_per_page, js["api"]["tracepoints"]["per_page"]
57       assert_equal Changeset::MAX_ELEMENTS, js["api"]["changesets"]["maximum_elements"]
58       assert_equal Settings.default_changeset_query_limit, js["api"]["changesets"]["default_query_limit"]
59       assert_equal Settings.max_changeset_query_limit, js["api"]["changesets"]["maximum_query_limit"]
60       assert_equal Settings.max_number_of_relation_members, js["api"]["relationmembers"]["maximum"]
61       assert_equal "online", js["api"]["status"]["database"]
62       assert_equal "online", js["api"]["status"]["api"]
63       assert_equal "online", js["api"]["status"]["gpx"]
64       assert_equal Settings.imagery_blacklist.length, js["policy"]["imagery"]["blacklist"].length
65     end
66   end
67 end